New UI buffer thing
This commit is contained in:
@@ -3,12 +3,16 @@
|
|||||||
|
|
||||||
Use session 1:
|
Use session 1:
|
||||||
- OpenCommand in command window freezes the app
|
- OpenCommand in command window freezes the app
|
||||||
- Shift + backspace should delete normally
|
|
||||||
- SDL popups are not working on linux ...
|
- SDL popups are not working on linux ...
|
||||||
|
- CloseAll idea: should create a buffer interface with list of buffers, user would be able to select which buffers to save and which not, then button UICloseAll
|
||||||
- Creating files more efficiently
|
- Creating files more efficiently
|
||||||
- Dialog popup on save? Or ctrl-shift-s?
|
- Dialog popup on save? Or ctrl-shift-s?
|
||||||
- Maybe rename in bar and do :Rename
|
- Maybe rename in bar and do :Rename
|
||||||
|
|
||||||
|
New UI Session
|
||||||
|
- Cleanup String16/String with Open and EvalCommands after lua refactor
|
||||||
|
- Rename GotoBackward and others to Jump
|
||||||
|
|
||||||
- Open with seek string (open at pattern) filename:32 filename:/^Window$/
|
- Open with seek string (open at pattern) filename:32 filename:/^Window$/
|
||||||
- build console window
|
- build console window
|
||||||
- Show what process/coroutines are running and allow to kill (active process buffer?)
|
- Show what process/coroutines are running and allow to kill (active process buffer?)
|
||||||
|
|||||||
@@ -829,6 +829,52 @@ void Command_CloseAll() {
|
|||||||
}
|
}
|
||||||
} RegisterCommand(Command_CloseAll, "");
|
} RegisterCommand(Command_CloseAll, "");
|
||||||
|
|
||||||
|
void Command_ForceClose() {
|
||||||
|
BSet active = GetBSet(ActiveWindowID);
|
||||||
|
Close(active.buffer->id);
|
||||||
|
Close(active.view->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// @todo: make these uneditable?
|
||||||
|
// @todo: maybe turn this into a coroutine???
|
||||||
|
String BufferIDea = R"==(
|
||||||
|
Do you want to save buffer? [C:/Programming/text_editor/build.sh]
|
||||||
|
|
||||||
|
:Yes :No
|
||||||
|
)==";
|
||||||
|
void Command_TestUIIdea() {
|
||||||
|
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||||
|
JumpGarbageBuffer(&main, "ui");
|
||||||
|
NextActiveWindowID = main.window->id;
|
||||||
|
|
||||||
|
Add(&main.view->hooks, {"Yes", "enter", [](){
|
||||||
|
BSet active = GetBSet(ActiveWindowID);
|
||||||
|
Caret a = FindNext(active.buffer, u"[", MakeCaret(0));
|
||||||
|
Caret b = FindNext(active.buffer, u"]", MakeCaret(0));
|
||||||
|
if (GetSize(a) == 0 || GetSize(b) == 0) {
|
||||||
|
ReportWarningf("Failed to save, '[' or ']' not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Scratch scratch;
|
||||||
|
String16 string16 = GetString(active.buffer, {a.range.max, b.range.min});
|
||||||
|
String string = ToString(scratch, string16);
|
||||||
|
Buffer *buffer = GetBuffer(string, NULL);
|
||||||
|
if (buffer) {
|
||||||
|
SaveBuffer(buffer);
|
||||||
|
} else {
|
||||||
|
ReportWarningf("Failed to save, buffer not found: %S", string);
|
||||||
|
}
|
||||||
|
|
||||||
|
Close(active.buffer->id);
|
||||||
|
Close(active.view->id);
|
||||||
|
}, ParseKey(Perm, "enter", "Command_TestUIIdea_Yes")}); // @todo: fix memory leak
|
||||||
|
Add(&main.view->hooks, {"No", "escape", Command_ForceClose, ParseKeyCached("escape")});
|
||||||
|
RawAppend(main.buffer, BufferIDea);
|
||||||
|
main.view->carets[0] = FindNext(main.buffer, u":Yes", MakeCaret(0));
|
||||||
|
main.view->carets[0].range.min = main.view->carets[0].range.max;
|
||||||
|
} RegisterCommand(Command_TestUIIdea, "");
|
||||||
|
|
||||||
void Command_GotoBackward() {
|
void Command_GotoBackward() {
|
||||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||||
main.window->skip_checkpoint = true;
|
main.window->skip_checkpoint = true;
|
||||||
@@ -1084,7 +1130,7 @@ void Command_DeleteBoundary() {
|
|||||||
void Command_DeleteForward() {
|
void Command_DeleteForward() {
|
||||||
BSet active = GetBSet(ActiveWindowID);
|
BSet active = GetBSet(ActiveWindowID);
|
||||||
Delete(active.view, DIR_RIGHT);
|
Delete(active.view, DIR_RIGHT);
|
||||||
} RegisterCommand(Command_DeleteForward, "delete");
|
} RegisterCommand(Command_DeleteForward, "shift-delete | delete");
|
||||||
|
|
||||||
void Command_DeleteForwardBoundary() {
|
void Command_DeleteForwardBoundary() {
|
||||||
BSet active = GetBSet(ActiveWindowID);
|
BSet active = GetBSet(ActiveWindowID);
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ String Intern(InternTable *table, String string) {
|
|||||||
// optimize worst offenders (like event text)
|
// optimize worst offenders (like event text)
|
||||||
InternTable GlobalInternTable;
|
InternTable GlobalInternTable;
|
||||||
|
|
||||||
Function *LastExecutedCommand;
|
Function *LastExecutedManualCommand;
|
||||||
Array<CommandData> CommandFunctions;
|
Array<CommandData> CommandFunctions;
|
||||||
Array<FunctionData> TestFunctions;
|
Array<FunctionData> TestFunctions;
|
||||||
Array<Variable> Variables;
|
Array<Variable> Variables;
|
||||||
|
|||||||
@@ -386,11 +386,24 @@ void OnCommand(Event event) {
|
|||||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||||
BSet active = GetBSet(ActiveWindowID);
|
BSet active = GetBSet(ActiveWindowID);
|
||||||
|
|
||||||
|
bool executed = false;
|
||||||
|
For (active.view->hooks) {
|
||||||
|
if (it.trigger && MatchEvent(it.trigger, &event)) {
|
||||||
|
ProfileScopeEx(it.name);
|
||||||
|
it.function();
|
||||||
|
LastExecutedManualCommand = it.function;
|
||||||
|
executed = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (executed == false) {
|
||||||
For (CommandFunctions) {
|
For (CommandFunctions) {
|
||||||
if (it.trigger && MatchEvent(it.trigger, &event)) {
|
if (it.trigger && MatchEvent(it.trigger, &event)) {
|
||||||
ProfileScopeEx(it.name);
|
ProfileScopeEx(it.name);
|
||||||
it.function();
|
it.function();
|
||||||
LastExecutedCommand = it.function;
|
LastExecutedManualCommand = it.function;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -476,8 +489,7 @@ void GarbageCollect() {
|
|||||||
|
|
||||||
RawAppendf(GCInfoBuffer, "View %d %S\n", (int)it->id.id, buffer->name);
|
RawAppendf(GCInfoBuffer, "View %d %S\n", (int)it->id.id, buffer->name);
|
||||||
remove_item = true;
|
remove_item = true;
|
||||||
Dealloc(&it->carets);
|
Dealloc(it);
|
||||||
Dealloc(sys_allocator, it);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IterRemove(Buffers) {
|
IterRemove(Buffers) {
|
||||||
|
|||||||
@@ -8,11 +8,18 @@ API View *CreateView(BufferID active_buffer) {
|
|||||||
view->id = AllocViewID(view);
|
view->id = AllocViewID(view);
|
||||||
view->active_buffer = active_buffer;
|
view->active_buffer = active_buffer;
|
||||||
view->carets.allocator = al;
|
view->carets.allocator = al;
|
||||||
|
view->hooks.allocator = al;
|
||||||
Add(&view->carets, {0, 0});
|
Add(&view->carets, {0, 0});
|
||||||
Add(&Views, view);
|
Add(&Views, view);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Dealloc(View *view) {
|
||||||
|
Dealloc(&view->carets);
|
||||||
|
Dealloc(&view->hooks);
|
||||||
|
Dealloc(view->carets.allocator, view);
|
||||||
|
}
|
||||||
|
|
||||||
API View *FindView(ViewID view_id, View *default_view) {
|
API View *FindView(ViewID view_id, View *default_view) {
|
||||||
For(Views) {
|
For(Views) {
|
||||||
if (it->id == view_id) {
|
if (it->id == view_id) {
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
struct View;
|
struct View;
|
||||||
struct ViewID { Int id; View *o; };
|
struct ViewID { Int id; View *o; };
|
||||||
|
|
||||||
|
typedef void Function();
|
||||||
|
struct FunctionData { String name; Function *function; };
|
||||||
|
struct CommandData { String name; String binding; Function *function; struct Trigger *trigger; };
|
||||||
|
|
||||||
struct View {
|
struct View {
|
||||||
ViewID id;
|
ViewID id;
|
||||||
BufferID active_buffer;
|
BufferID active_buffer;
|
||||||
@@ -11,6 +15,7 @@ struct View {
|
|||||||
Caret main_caret_on_begin_frame;
|
Caret main_caret_on_begin_frame;
|
||||||
bool update_scroll;
|
bool update_scroll;
|
||||||
|
|
||||||
|
Array<CommandData> hooks;
|
||||||
String16 prev_search_line;
|
String16 prev_search_line;
|
||||||
struct {
|
struct {
|
||||||
unsigned close : 1;
|
unsigned close : 1;
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ struct Window {
|
|||||||
uint32_t lose_focus_on_escape : 1;
|
uint32_t lose_focus_on_escape : 1;
|
||||||
uint32_t lose_visibility_on_escape : 1;
|
uint32_t lose_visibility_on_escape : 1;
|
||||||
uint32_t jump_history : 1;
|
uint32_t jump_history : 1;
|
||||||
uint32_t eval_command : 1;
|
|
||||||
uint32_t skip_checkpoint : 1;
|
uint32_t skip_checkpoint : 1;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ void CommandWindowUpdate() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Command_ShowCommands() {
|
void Command_ShowCommands() {
|
||||||
if (ActiveWindowID == CommandWindowID && LastExecutedCommand == Command_ShowCommands) {
|
if (ActiveWindowID == CommandWindowID && LastExecutedManualCommand == Command_ShowCommands) {
|
||||||
NextActiveWindowID = LastActiveLayoutWindowID;
|
NextActiveWindowID = LastActiveLayoutWindowID;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -118,18 +118,20 @@ void Command_ShowCommands() {
|
|||||||
|
|
||||||
BSet command_bar = GetBSet(CommandWindowID);
|
BSet command_bar = GetBSet(CommandWindowID);
|
||||||
command_bar.window->visible = true;
|
command_bar.window->visible = true;
|
||||||
command_bar.window->eval_command = true;
|
|
||||||
NextActiveWindowID = command_bar.window->id;
|
NextActiveWindowID = command_bar.window->id;
|
||||||
ResetBuffer(command_bar.buffer);
|
ResetBuffer(command_bar.buffer);
|
||||||
For(CommandFunctions) {
|
For (CommandFunctions) {
|
||||||
RawAppendf(command_bar.buffer, "\n%S", it.name);
|
if (it.name == "OpenCommand") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
RawAppendf(command_bar.buffer, "\n:%S", it.name);
|
||||||
}
|
}
|
||||||
command_bar.view->update_scroll = true;
|
command_bar.view->update_scroll = true;
|
||||||
SelectRange(command_bar.view, GetBufferBeginAsRange(command_bar.buffer));
|
SelectRange(command_bar.view, GetBufferBeginAsRange(command_bar.buffer));
|
||||||
} RegisterCommand(Command_ShowCommands, "ctrl-shift-p");
|
} RegisterCommand(Command_ShowCommands, "ctrl-shift-p");
|
||||||
|
|
||||||
void Command_ShowDebugBufferList() {
|
void Command_ShowDebugBufferList() {
|
||||||
if (ActiveWindowID == CommandWindowID && LastExecutedCommand == Command_ShowDebugBufferList) {
|
if (ActiveWindowID == CommandWindowID && LastExecutedManualCommand == Command_ShowDebugBufferList) {
|
||||||
NextActiveWindowID = LastActiveLayoutWindowID;
|
NextActiveWindowID = LastActiveLayoutWindowID;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -137,7 +139,6 @@ void Command_ShowDebugBufferList() {
|
|||||||
|
|
||||||
BSet command_bar = GetBSet(CommandWindowID);
|
BSet command_bar = GetBSet(CommandWindowID);
|
||||||
command_bar.window->visible = true;
|
command_bar.window->visible = true;
|
||||||
command_bar.window->eval_command = false;
|
|
||||||
NextActiveWindowID = command_bar.window->id;
|
NextActiveWindowID = command_bar.window->id;
|
||||||
ResetBuffer(command_bar.buffer);
|
ResetBuffer(command_bar.buffer);
|
||||||
For (Buffers) {
|
For (Buffers) {
|
||||||
@@ -148,7 +149,7 @@ void Command_ShowDebugBufferList() {
|
|||||||
} RegisterCommand(Command_ShowDebugBufferList, "");
|
} RegisterCommand(Command_ShowDebugBufferList, "");
|
||||||
|
|
||||||
void Command_ShowBufferList() {
|
void Command_ShowBufferList() {
|
||||||
if (ActiveWindowID == CommandWindowID && LastExecutedCommand == Command_ShowBufferList) {
|
if (ActiveWindowID == CommandWindowID && LastExecutedManualCommand == Command_ShowBufferList) {
|
||||||
NextActiveWindowID = LastActiveLayoutWindowID;
|
NextActiveWindowID = LastActiveLayoutWindowID;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -156,7 +157,6 @@ void Command_ShowBufferList() {
|
|||||||
|
|
||||||
BSet command_bar = GetBSet(CommandWindowID);
|
BSet command_bar = GetBSet(CommandWindowID);
|
||||||
command_bar.window->visible = true;
|
command_bar.window->visible = true;
|
||||||
command_bar.window->eval_command = false;
|
|
||||||
NextActiveWindowID = command_bar.window->id;
|
NextActiveWindowID = command_bar.window->id;
|
||||||
ResetBuffer(command_bar.buffer);
|
ResetBuffer(command_bar.buffer);
|
||||||
For (Buffers) {
|
For (Buffers) {
|
||||||
@@ -178,20 +178,10 @@ void OpenCommand(BSet active) {
|
|||||||
if (line == 0) {
|
if (line == 0) {
|
||||||
line = ClampTop(1ll, active.buffer->line_starts.len - 1ll);
|
line = ClampTop(1ll, active.buffer->line_starts.len - 1ll);
|
||||||
}
|
}
|
||||||
|
|
||||||
string = GetLineStringWithoutNL(active.buffer, line);
|
string = GetLineStringWithoutNL(active.buffer, line);
|
||||||
Int idx = 0;
|
|
||||||
if (Seek(string, u"||", &idx)) {
|
|
||||||
string = Skip(string, idx + 3);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (active.window->eval_command) {
|
|
||||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
|
||||||
NextActiveWindowID = main.window->id;
|
|
||||||
EvalCommand(string);
|
|
||||||
} else {
|
|
||||||
Open(string);
|
Open(string);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Command_OpenCommand() {
|
void Command_OpenCommand() {
|
||||||
@@ -199,5 +189,7 @@ void Command_OpenCommand() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BSet active = GetBSet(ActiveWindowID);
|
BSet active = GetBSet(ActiveWindowID);
|
||||||
|
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||||
|
NextActiveWindowID = main.window->id;
|
||||||
OpenCommand(active);
|
OpenCommand(active);
|
||||||
} RegisterCommand(Command_OpenCommand, "ctrl-q | enter");
|
} RegisterCommand(Command_OpenCommand, "ctrl-q | enter");
|
||||||
Reference in New Issue
Block a user