Remove titlebar modification, small refactor

This commit is contained in:
Krzosa Karol
2024-08-13 09:09:48 +02:00
parent da80e2c731
commit b3e95a705f
10 changed files with 22 additions and 70 deletions

View File

@@ -289,7 +289,7 @@ end
function MatchWindowsPath(_s)
local s, file_path, drive = SkipPath(_s)
if not drive then
local d = GetActiveMainWindowBufferName()
local d = GetActiveMainWindowBufferDir()
file_path = d..'/'..file_path
end
local line, col, s = SkipLineAndColumn(s)

View File

@@ -324,7 +324,7 @@ bool GlobalCommand(Event event) {
if (!window->visible) continue;
bool mouse_in_document = CheckCollisionPointRec(mouse, window->document_rect);
if (mouse_in_document) {
SetActiveWindow(window->id);
ActiveWindow = window->id;
break;
}
}
@@ -472,17 +472,17 @@ bool GlobalCommand(Event event) {
if (Ctrl(SDLK_1)) {
Window *window = GetLayoutWindow(0);
if (window) SetActiveWindow(window->id);
if (window) ActiveWindow = window->id;
run_window_command = false;
}
if (Ctrl(SDLK_2)) {
Window *window = GetLayoutWindow(1);
if (window) SetActiveWindow(window->id);
if (window) ActiveWindow = window->id;
run_window_command = false;
}
if (Ctrl(SDLK_3)) {
Window *window = GetLayoutWindow(2);
if (window) SetActiveWindow(window->id);
if (window) ActiveWindow = window->id;
run_window_command = false;
}
@@ -561,5 +561,5 @@ void ReportWarningf(const char *fmt, ...) {
}
CheckpointBeforeGoto(window->id);
window->active_view = NullViewID;
SetActiveWindow(window->id);
ActiveWindow = window->id;
}

View File

@@ -682,7 +682,7 @@ void WindowCommand(Event event, Window *window, View *view) {
if (Press(SDLK_ESCAPE)) {
if (window->deactivate_on_escape) {
SetActiveWindow(GetActiveMainWindowID());
ActiveWindow = GetActiveMainWindowID();
} else {
view->carets.len = 1;
}
@@ -890,7 +890,7 @@ void WindowCommand(Event event, Window *window, View *view) {
Window *titlebar = GetTitlebarWindow(window->id);
View *titlebar_view = GetView(titlebar->active_view);
Buffer *titlebar_buffer = GetBuffer(titlebar_view->active_buffer);
SetActiveWindow(titlebar->id);
ActiveWindow = titlebar->id;
String16 buffer_string = GetString(*titlebar_buffer);
if (Seek(buffer_string, L" |", &buffer_string.len)) {
@@ -908,7 +908,7 @@ void WindowCommand(Event event, Window *window, View *view) {
Window *titlebar = GetTitlebarWindow(window->id);
View *titlebar_view = GetView(titlebar->active_view);
Buffer *titlebar_buffer = GetBuffer(titlebar_view->active_buffer);
SetActiveWindow(titlebar->id);
ActiveWindow = titlebar->id;
}
if (CtrlShift(SDLK_W)) {

View File

@@ -178,7 +178,7 @@ end
function MatchWindowsPath(_s)
local s, file_path, drive = SkipPath(_s)
if not drive then
local d = GetActiveMainWindowBufferName()
local d = GetActiveMainWindowBufferDir()
file_path = d..'/'..file_path
end
local line, col, s = SkipLineAndColumn(s)

View File

@@ -37,7 +37,7 @@ void ExecInNewBuffer(String cmd, String working_dir) {
Buffer *buffer = GetBuffer(view->active_buffer);
view->carets[0] = MakeCaret({});
Exec(view->id, false, cmd, working_dir);
SetActiveWindow(window->id);
ActiveWindow = window->id;
}
void Open(String path) {
@@ -69,7 +69,7 @@ void Open(String path) {
view->carets[0] = MakeCaret(pos);
}
UpdateScroll(window, true);
SetActiveWindow(window->id);
ActiveWindow = window->id;
} else if (FieldString(LuaState, "kind") == "exec") {
String cmd = FieldString(LuaState, "cmd");
String working_dir = FieldString(LuaState, "working_dir");

View File

@@ -126,11 +126,6 @@ View *CreateView(BufferID active_buffer) {
return view;
}
// @todo: remove function
void SetActiveWindow(WindowID window) {
ActiveWindow = window;
}
View *FindView(BufferID buffer_id) {
For(Views) {
View *view = it.o;

View File

@@ -100,6 +100,12 @@ struct Scroller {
Int line_count;
};
struct ActiveSet {
Window *window;
View *view;
Buffer *buffer;
};
// @WARNING: be careful about using this, should only be used for debugging
// the problem with this is that we want events to be reproducible.
// We eat as many events as we can in a frame, we abstract the frame and so on.

View File

@@ -57,59 +57,10 @@ void UpdateDebugBuffer() {
// Append(buffer, ToString16(scratch, window_list));
}
void ApplyTitleBarChangesToWindow(Window *window, View *view, Buffer *buffer) {
String16 buffer_string = GetString(*buffer);
Range replace_range = {0, buffer->len};
if (Seek(buffer_string, L" |", &replace_range.max)) {
}
buffer_string = GetString(*buffer, replace_range);
buffer_string = Trim(buffer_string);
Int column = ChopNumber(&buffer_string);
if (column == -1) return;
Int line = ChopNumber(&buffer_string);
if (line == -1) {
line = column;
column = 0;
}
Window *last_window = GetWindow(window->title_bar_window);
View *last_view = GetActiveView(last_window);
Buffer *last_buffer = GetBuffer(last_view->active_buffer);
Scratch scratch;
String filepath = ToString(scratch, buffer_string);
if (filepath != last_buffer->name && !BufferNameExists(filepath)) {
filepath = GetAbsolutePath(scratch, filepath);
Buffer *find_buffer = GetBufferStrict(filepath);
if (find_buffer) {
ReportWarningf("couldn't set name for buffer: %.*s, there is already buffer with that name", FmtString(filepath));
} else {
String new_name = Intern(&GlobalInternTable, filepath);
last_buffer->name = new_name;
}
}
Int buffer_pos = XYToPos(*last_buffer, {column, line});
Caret &caret = last_view->carets[0];
if (GetFront(caret) != buffer_pos) {
caret = MakeCaret(buffer_pos);
}
window->title_bar_last_buffer_change_id = buffer->change_id;
}
void ReplaceTitleBarData(Window *window) {
View *view = GetView(window->active_view);
view->scroll.y = 0;
View *view = GetView(window->active_view);
Buffer *buffer = GetBuffer(view->active_buffer);
if (IsActive(window)) {
if (buffer->change_id != window->title_bar_last_buffer_change_id) {
ApplyTitleBarChangesToWindow(window, view, buffer);
}
}
view->scroll.y = 0;
Window *last_window = GetWindow(window->title_bar_window);
View *last_view = GetActiveView(last_window);

View File

@@ -1,6 +1,6 @@
- garbage collect the buffers, views - store them in free list on destroy
- adding items to directory should create files on save - it should ask the user (syntax: dir/ | file)
- refresh the directory - whem opening up again?
- refresh the directory - when opening up again?
- refresh the file content, periodically check file timestamp for changes and update if neccessary
- ask user if he really wants to quit even though he has an unsaved buffer - popup window
- add plumb rules for some web stuff

View File

@@ -179,7 +179,7 @@ void InitWindows() {
SetVisibility(window_id, false);
}
SetActiveWindow({0});
ActiveWindow = {0};
}
void LayoutWindows() {