diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2021-01-29 17:51:49 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2021-01-29 17:51:49 -0500 |
commit | a0b84cc8f40e19a506332be3a05222b87e6ed617 (patch) | |
tree | 68607facee3bb655cfe2166d4a578db9e91bdf1f | |
parent | 565b5e619ed64f459f1b38b5b94bb72b5b9a714f (diff) |
better tab bar, default to "save as" on Ctrl+S with starting buffer
-rw-r--r-- | Untitled | 2 | ||||
-rw-r--r-- | colors.h | 8 | ||||
-rw-r--r-- | command.c | 9 | ||||
-rw-r--r-- | main.c | 14 | ||||
-rw-r--r-- | menu.c | 8 | ||||
-rw-r--r-- | ted.cfg | 2 | ||||
-rw-r--r-- | util.c | 10 |
7 files changed, 42 insertions, 11 deletions
@@ -1,2 +1,2 @@ -a 1 2 3 4 +aa 1 2 3 4 56 78 910 1112 @@ -1,11 +1,12 @@ ENUM_U16 { COLOR_UNKNOWN, + COLOR_TEXT, COLOR_BG, + COLOR_HL, COLOR_CURSOR, COLOR_CURSOR_LINE_BG, COLOR_BORDER, - COLOR_TEXT, COLOR_TEXT_FOLDER, COLOR_TEXT_OTHER, COLOR_SELECTION_BG, @@ -15,6 +16,7 @@ ENUM_U16 { COLOR_ERROR_TEXT, COLOR_ERROR_BG, COLOR_ERROR_BORDER, + COLOR_ACTIVE_TAB_HL, COLOR_YES, COLOR_NO, @@ -30,11 +32,12 @@ typedef struct { static ColorName const color_names[COLOR_COUNT] = { {COLOR_UNKNOWN, "unknown"}, + {COLOR_TEXT, "text"}, {COLOR_BG, "bg"}, + {COLOR_HL, "hl"}, {COLOR_CURSOR, "cursor"}, {COLOR_CURSOR_LINE_BG, "cursor-line-bg"}, {COLOR_BORDER, "border"}, - {COLOR_TEXT, "text"}, {COLOR_TEXT_FOLDER, "text-folder"}, {COLOR_TEXT_OTHER, "text-other"}, {COLOR_SELECTION_BG, "selection-bg"}, @@ -44,6 +47,7 @@ static ColorName const color_names[COLOR_COUNT] = { {COLOR_ERROR_TEXT, "error-text"}, {COLOR_ERROR_BG, "error-bg"}, {COLOR_ERROR_BORDER, "error-border"}, + {COLOR_ACTIVE_TAB_HL, "active-tab-hl"}, {COLOR_YES, "yes"}, {COLOR_NO, "no"}, {COLOR_CANCEL, "cancel"} @@ -141,9 +141,16 @@ void command_execute(Ted *ted, Command c, i64 argument) { menu_open(ted, MENU_OPEN); break; case CMD_SAVE: - if (buffer) buffer_save(buffer); + if (buffer) { + if (buffer->filename && streq(buffer->filename, "Untitled")) { + // don't worry, this won't catch files called "Untitled"; buffer->filename is the full path. + goto save_as; + } + buffer_save(buffer); + } break; case CMD_SAVE_AS: + save_as: if (buffer && !buffer->is_line_buffer) { menu_open(ted, MENU_SAVE_AS); } @@ -75,6 +75,7 @@ static Rect error_box_rect(Ted *ted) { static void node_render(Ted *ted, Node *node, Rect r) { if (node->tabs) { + bool is_active = node == ted->active_node; Settings const *settings = &ted->settings; u32 const *colors = settings->colors; Font *font = ted->font; @@ -91,13 +92,19 @@ static void node_render(Ted *ted, Node *node, Rect r) { for (u16 i = 0; i < ntabs; ++i) { TextBuffer *buffer = &ted->buffers[node->tabs[i]]; char tab_title[256]; - char const *filename = buffer_get_filename(buffer); + char const *path = buffer_get_filename(buffer); + char const *filename = path_filename(path); Rect tab_rect = rect(V2(r.pos.x + tab_width * i, r.pos.y), V2(tab_width, tab_bar_height)); glBegin(GL_QUADS); gl_color_rgba(colors[COLOR_BORDER]); // tab border rect_render_border(tab_rect, 1); + if (i == node->active_tab) { + // highlight active tab + gl_color_rgba(colors[is_active ? COLOR_ACTIVE_TAB_HL : COLOR_HL]); + rect_render(tab_rect); + } glEnd(); // tab title @@ -118,7 +125,7 @@ static void node_render(Ted *ted, Node *node, Rect r) { } else { #if 0 - // @TODO: test + // @TODO: test this // this node is a split Node *a = &ted->nodes[node->split_a]; Node *b = &ted->nodes[node->split_b]; @@ -316,6 +323,7 @@ int main(int argc, char **argv) { u16 node_index = (u16)ted_new_node(ted); assert(node_index == 0); Node *node = ted->active_node = &ted->nodes[node_index]; + ted->root = node; node->tabs = NULL; arr_add(node->tabs, 0); @@ -531,7 +539,7 @@ int main(int argc, char **argv) { { float x1 = 50, y1 = 50, x2 = window_width-50, y2 = window_height-50; - Node *node = ted->active_node; + Node *node = ted->root; node_render(ted, node, rect4(x1, y1, x2, y2)); } @@ -125,11 +125,11 @@ static void menu_render(Ted *ted, Menu menu) { glEnd(); if (*ted->warn_overwrite) { - char const *filename = ted->warn_overwrite; + char const *path = ted->warn_overwrite; + char const *filename = path_filename(path); char title[32] = {0}, body[256] = {0}; - char const *last_path_sep = strrchr(filename, PATH_SEPARATOR); - strbuf_printf(title, "Overwrite %s?", last_path_sep ? last_path_sep + 1 : filename); - strbuf_printf(body, "Are you sure you want to overwrite %s?", ted->warn_overwrite); + strbuf_printf(title, "Overwrite %s?", filename); + strbuf_printf(body, "Are you sure you want to overwrite %s?", path); popup_render(ted, title, body); return; } @@ -79,9 +79,11 @@ Escape = :escape [colors] border = #a77 +active-tab-hl = #a77a cursor-line-bg = #222 cursor = #3ff selection-bg = #36aa +hl = #ccc text = #fff # For example, in the open menu it is nice to have a visual distinction between folders and files. # This is the color used for folders. @@ -204,3 +204,13 @@ static void qsort_with_context(void *base, size_t nmemb, size_t size, int (*comp qsort_ctx_cmp = compar; qsort(base, nmemb, size, qsort_with_context_cmp); } + +// the actual file name part of the path; get rid of the containing directory. +// NOTE: the returned string is part of path, so you don't need to free it or anything. +static char const *path_filename(char const *path) { + char const *last_path_sep = strrchr(path, PATH_SEPARATOR); + if (last_path_sep) + return last_path_sep + 1; + // (a relative path with no path separators) + return path; +} |