title bar renaming
This commit is contained in:
@@ -313,3 +313,29 @@ String16 SkipWhitespace(String16 *string) {
|
|||||||
return begin;
|
return begin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// chop this - :324
|
||||||
|
String16 ChopNumberEx(String16 *string) {
|
||||||
|
String16 col = {};
|
||||||
|
for (int64_t i = string->len - 1; i >= 0; i -= 1) {
|
||||||
|
if (IsDigit(string->data[i])) {
|
||||||
|
col.data = string->data + i;
|
||||||
|
col.len += 1;
|
||||||
|
} else if (string->data[i] == L':') {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*string = Chop(*string, col.len + 1);
|
||||||
|
return col;
|
||||||
|
}
|
||||||
|
|
||||||
|
Int ChopNumber(String16 *string) {
|
||||||
|
Scratch scratch;
|
||||||
|
String16 col = ChopNumberEx(string);
|
||||||
|
if (col.len == 0) return -1;
|
||||||
|
String num_string = ToString(scratch, col);
|
||||||
|
Int result = strtoll(num_string.data, NULL, 10) - 1;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
@@ -22,13 +22,58 @@ void UpdateDebugBuffer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ReplaceTitleBarData(Window *window) {
|
void ReplaceTitleBarData(Window *window) {
|
||||||
BSet title = GetBSet(window);
|
Scratch scratch;
|
||||||
|
BSet main = GetMainSet(window);
|
||||||
|
BSet title = GetBSet(window);
|
||||||
title.view->scroll.y = 0;
|
title.view->scroll.y = 0;
|
||||||
|
|
||||||
if (window->id == ActiveWindow) return;
|
String16 buffer_string = GetString(title.buffer);
|
||||||
|
Range replace_range = {0, title.buffer->len};
|
||||||
|
bool found_separator = Seek(buffer_string, u" |", &replace_range.max);
|
||||||
|
|
||||||
|
if (window->id == ActiveWindow) {
|
||||||
|
if (title.buffer->change_id == title.window->title_bar_last_buffer_change_id) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String16 buffer_name = GetString(title.buffer, replace_range);
|
||||||
|
buffer_name = Trim(buffer_name);
|
||||||
|
|
||||||
|
Int column = ChopNumber(&buffer_name);
|
||||||
|
if (column == -1) return;
|
||||||
|
|
||||||
|
Int line = ChopNumber(&buffer_name);
|
||||||
|
if (line == -1) {
|
||||||
|
line = column;
|
||||||
|
column = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
String name = ToString(scratch, buffer_name);
|
||||||
|
if (name != main.buffer->name) {
|
||||||
|
name = GetAbsolutePath(scratch, name);
|
||||||
|
if (GetBufferStrict(name)) {
|
||||||
|
title.window->title_bar_last_buffer_change_id = title.buffer->change_id;
|
||||||
|
ReportConsolef("there is already buffer with name: %.*s", FmtString(name));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
main.buffer->name = Intern(&GlobalInternTable, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
Int buffer_pos = XYToPos(main.buffer, {column, line});
|
||||||
|
|
||||||
|
Caret &caret = main.view->carets[0];
|
||||||
|
if (GetFront(caret) != buffer_pos) {
|
||||||
|
caret = MakeCaret(buffer_pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
title.window->title_bar_last_buffer_change_id = title.buffer->change_id;
|
||||||
|
main.buffer->file_mod_time = 0;
|
||||||
|
main.buffer->changed_on_disk = false;
|
||||||
|
main.buffer->dirty = true;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
BSet main = GetMainSet(window);
|
|
||||||
Scratch scratch;
|
|
||||||
Caret caret = main.view->carets[0];
|
Caret caret = main.view->carets[0];
|
||||||
XY xy = PosToXY(main.buffer, GetFront(caret));
|
XY xy = PosToXY(main.buffer, GetFront(caret));
|
||||||
|
|
||||||
@@ -38,14 +83,14 @@ void ReplaceTitleBarData(Window *window) {
|
|||||||
title.view->carets = caret_copy;
|
title.view->carets = caret_copy;
|
||||||
};
|
};
|
||||||
|
|
||||||
String16 buffer_string = GetString(title.buffer);
|
// add separator at the end of buffer
|
||||||
Range replace_range = {0, title.buffer->len};
|
if (!found_separator) {
|
||||||
if (!Seek(buffer_string, u" |", &replace_range.max)) {
|
|
||||||
Command_SelectRangeOneCursor(title.view, GetEndAsRange(title.buffer));
|
Command_SelectRangeOneCursor(title.view, GetEndAsRange(title.buffer));
|
||||||
Array<Edit> edits = Command_ReplaceEx(scratch, title.view, u" |");
|
Array<Edit> edits = Command_ReplaceEx(scratch, title.view, u" |");
|
||||||
AdjustCarets(edits, &caret_copy);
|
AdjustCarets(edits, &caret_copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// replace data up to separator with filename and stuff
|
||||||
char *reopen = main.buffer->changed_on_disk ? " Reopen()" : "";
|
char *reopen = main.buffer->changed_on_disk ? " Reopen()" : "";
|
||||||
String s = Format(scratch, "%.*s:%lld:%lld%s", FmtString(main.buffer->name), (long long)xy.line + 1ll, (long long)xy.col + 1ll, reopen);
|
String s = Format(scratch, "%.*s:%lld:%lld%s", FmtString(main.buffer->name), (long long)xy.line + 1ll, (long long)xy.col + 1ll, reopen);
|
||||||
String16 string = ToString16(scratch, s);
|
String16 string = ToString16(scratch, s);
|
||||||
|
|||||||
Reference in New Issue
Block a user