CreateProject OpenProject
This commit is contained in:
2
build.sh
2
build.sh
@@ -3,7 +3,7 @@
|
||||
mkdir build
|
||||
cd build
|
||||
|
||||
FLAGS="-Wall -Wno-missing-braces -Wno-writable-strings -nostdlib++ -fsanitize=address -fno-exceptions -fdiagnostics-absolute-paths -g -Wno-writable-strings -I../src -DDEBUG_BUILD=1"
|
||||
FLAGS="-Wall -Wno-missing-braces -Wno-writable-strings -nostdlib++ -fsanitize=address -fno-exceptions -fdiagnostics-absolute-paths -g -I../src -DDEBUG_BUILD=1"
|
||||
I="-I../src/external/SDL/include -I../src/external/lua/src -I../src/external/glad"
|
||||
clang -o te $FLAGS ../src/text_editor/text_editor.cpp $I -lSDL3 -lm -lbacktrace
|
||||
|
||||
|
||||
1
project.te
Normal file
1
project.te
Normal file
@@ -0,0 +1 @@
|
||||
:OpenCode
|
||||
@@ -98,6 +98,7 @@ Array<FuzzyPair> FuzzySearchLines(Allocator allocator, Buffer *buffer, Int line_
|
||||
}
|
||||
|
||||
void UpdateFuzzySearchView() {
|
||||
ProfileFunction();
|
||||
Scratch scratch;
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
String16 line_string = GetLineStringWithoutNL(active.buffer, 0);
|
||||
@@ -108,7 +109,7 @@ void UpdateFuzzySearchView() {
|
||||
|
||||
Buffer *scratch_buff = CreateScratchBuffer(scratch, active.buffer->cap);
|
||||
RawAppend(scratch_buff, line_string);
|
||||
For(IterateInReverse(&ratings)) {
|
||||
For (IterateInReverse(&ratings)) {
|
||||
String16 s = GetLineStringWithoutNL(active.buffer, it.index);
|
||||
if (s.len == 0) continue;
|
||||
RawAppend(scratch_buff, u"\n");
|
||||
|
||||
@@ -60,10 +60,10 @@ void CMD_RunFile() {
|
||||
SaveBuffer(primary.buffer);
|
||||
|
||||
if (OS_WINDOWS) {
|
||||
String cmd = Format(scratch, "cl %S -Fe:cfile.exe /Zi /FC /nologo /WX /W3 /wd4200 /wd4334 /diagnostics:column && cfile.exe", primary.buffer->name);
|
||||
String cmd = Format(scratch, "cl %S -Fe:cfile.exe /Zi /FC /nologo /WX /W3 /wd4200 /wd4334 /diagnostics:column && cfile.exe && del cfile.*", primary.buffer->name);
|
||||
ExecBuild(cmd, GetDirectory(primary.buffer));
|
||||
} else {
|
||||
String cmd = Format(scratch, "bash <<EOF\nclang %S -o cfile.exe -g -Wall -Wno-missing-braces -Wno-writable-strings -Wno-writable-strings -fsanitize=address -fdiagnostics-absolute-paths -lm \n ./cfile.exe\nEOF", primary.buffer->name);
|
||||
String cmd = Format(scratch, "bash <<EOF\nclang %S -o cfile.exe -g -Wall -Wno-missing-braces -Wno-writable-strings -Wno-writable-strings -fsanitize=address -fdiagnostics-absolute-paths -lm \n./cfile.exe \nrm cfile.exe\nEOF", primary.buffer->name);
|
||||
ExecBuild(cmd, GetDirectory(primary.buffer));
|
||||
}
|
||||
build.window->visible = true;
|
||||
|
||||
@@ -18,8 +18,46 @@ void InsertDirectoryNavigation(Buffer *buffer) {
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateDirectoryNavigation() {
|
||||
#if 0
|
||||
ProfileFunction();
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
Buffer *buffer = active.buffer;
|
||||
|
||||
Scratch scratch;
|
||||
Array<String> existing_lines = Split(scratch, AllocCharString(scratch, buffer), "\n");
|
||||
bool modified = false;
|
||||
for (FileIter it = IterateFiles(scratch, buffer->name); IsValid(it); Advance(&it)) {
|
||||
bool found = false;
|
||||
ForItem (existing, existing_lines) {
|
||||
if (existing == it.filename) {
|
||||
found = true;
|
||||
UnorderedRemove(&existing_lines, existing);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found == false) {
|
||||
modified = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (existing_lines.len > 1) {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (modified) {
|
||||
ReopenBuffer(buffer);
|
||||
}
|
||||
|
||||
UpdateFuzzySearchView();
|
||||
#endif
|
||||
}
|
||||
|
||||
void OpenDirectoryNavigation(View *view) {
|
||||
SetFuzzy(view);
|
||||
// view->update_hook = UpdateDirectoryNavigation;
|
||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||
InsertDirectoryNavigation(buffer);
|
||||
SelectRange(view, GetBufferBeginAsRange(buffer));
|
||||
|
||||
@@ -55,9 +55,7 @@ void CO_OpenCode(mco_coro *co) {
|
||||
data->dont_wait_until_resolved = true;
|
||||
);
|
||||
|
||||
void CMD_SetProjectHere() {
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
String directory = GetDirectory(main.buffer);
|
||||
void OpenProject(String directory) {
|
||||
SetProjectDirectory(directory);
|
||||
#if PLUGIN_CONFIG
|
||||
Scratch scratch;
|
||||
@@ -67,18 +65,72 @@ void CMD_SetProjectHere() {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
} RegisterCommand(CMD_SetProjectHere, "", "Sets the project directory, opens the project file etc.");
|
||||
}
|
||||
|
||||
void CMD_OpenProject() {
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
String directory = GetDirectory(main.buffer);
|
||||
OpenProject(directory);
|
||||
} RegisterCommand(CMD_OpenProject, "", "Sets the project directory, opens the project file etc.");
|
||||
|
||||
String16 CreateProjectBuildBat = uR"==(@echo off
|
||||
mkdir build
|
||||
pushd build
|
||||
cl ../src/main.cpp /Zi /FC /nologo /WX /W3 /wd4200 /wd4334 /diagnostics:column
|
||||
popd
|
||||
)==";
|
||||
|
||||
String16 CreateProjectBuildSh = uR"==(#!/usr/bin/bash
|
||||
mkdir build
|
||||
cd build
|
||||
clang ../src/main.cpp -g -Wall -Wno-missing-braces -Wno-writable-strings -fdiagnostics-absolute-paths
|
||||
)==";
|
||||
|
||||
String16 CreateProjectMain = uR"==(#include <stdio.h>
|
||||
int main() {
|
||||
printf("hello world!\n");
|
||||
return 0;
|
||||
}
|
||||
)==";
|
||||
|
||||
void CO_CreateProject(mco_coro *co) {
|
||||
String16 project_name16 = QueryUserString(co, "Please tell me, how would you like to name your project?");
|
||||
String directory = GetPrimaryDirectory();
|
||||
|
||||
// - project_directory
|
||||
// - project.te
|
||||
// - build.bat
|
||||
// - build.sh
|
||||
// - src
|
||||
// - main.c
|
||||
{
|
||||
Scratch scratch;
|
||||
String project_name = ToString(scratch, project_name16);
|
||||
String name = Format(scratch, "%S/%S", directory, project_name);
|
||||
MakeDir(name);
|
||||
Open(name);
|
||||
String project_dir = Format(scratch, "%S/%S", directory, project_name);
|
||||
String src_dir = Format(scratch, "%S/src", project_dir);
|
||||
MakeDir(project_dir);
|
||||
MakeDir(src_dir);
|
||||
SetProjectDirectory(project_dir);
|
||||
|
||||
Buffer *project = BufferOpenFile(Format(scratch, "%S/project.te", project_dir));
|
||||
RawAppendf(project, ":OpenCode\n:Set BinaryUnderDebug '%S/build/main.exe'\n", project_dir);
|
||||
SaveBuffer(project);
|
||||
|
||||
Buffer *build_bat = BufferOpenFile(Format(scratch, "%S/build.bat", project_dir));
|
||||
RawAppend(build_bat, CreateProjectBuildBat);
|
||||
SaveBuffer(build_bat);
|
||||
|
||||
Buffer *build_sh = BufferOpenFile(Format(scratch, "%S/build.sh", project_dir));
|
||||
RawAppend(build_sh, CreateProjectBuildSh);
|
||||
SaveBuffer(build_sh);
|
||||
|
||||
Buffer *main_file = BufferOpenFile(Format(scratch, "%S/main.cpp", src_dir));
|
||||
RawAppend(main_file, CreateProjectMain);
|
||||
SaveBuffer(main_file);
|
||||
|
||||
OpenProject(project_dir);
|
||||
Open(main_file->name);
|
||||
}
|
||||
|
||||
|
||||
CO_OpenCode(co);
|
||||
} RegisterCoroutineCommand(CO_CreateProject, "", "Creates a project in current buffer directory with template files and all that, asks user for input etc.");
|
||||
@@ -48,6 +48,8 @@ void UpdateSearchOpenBuffersView() {
|
||||
if (active.view->prev_search_line_hash != hash) {
|
||||
active.view->prev_search_line_hash = hash;
|
||||
if (line_string.len > 0) {
|
||||
// @todo: somehow reintroduce history but manual, do the UndoKinds EditKind or something
|
||||
// and implement EditKind_ExactBufferContent just save the
|
||||
Caret caret = active.view->carets[0];
|
||||
SelectEntireBuffer(active.view);
|
||||
Replace(active.view, line_string);
|
||||
@@ -76,6 +78,7 @@ void CMD_SearchOpenBuffers() {
|
||||
|
||||
NextActiveWindowID = main.window->id;
|
||||
JumpTempBuffer(&main);
|
||||
main.buffer->no_history = true;
|
||||
AddCommand(&main.view->commands, "Open", OpenKeySet, []() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
|
||||
Reference in New Issue
Block a user