summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Untitled2
-rw-r--r--colors.h8
-rw-r--r--command.c9
-rw-r--r--main.c14
-rw-r--r--menu.c8
-rw-r--r--ted.cfg2
-rw-r--r--util.c10
7 files changed, 42 insertions, 11 deletions
diff --git a/Untitled b/Untitled
index f2a5887..74aaf7e 100644
--- a/Untitled
+++ b/Untitled
@@ -1,2 +1,2 @@
-a 1 2 3 4
+aa 1 2 3 4
56 78 910 1112
diff --git a/colors.h b/colors.h
index 87feaf1..60aeaf3 100644
--- a/colors.h
+++ b/colors.h
@@ -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"}
diff --git a/command.c b/command.c
index beb4d9d..1acca2f 100644
--- a/command.c
+++ b/command.c
@@ -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);
}
diff --git a/main.c b/main.c
index 5b903aa..eab78ba 100644
--- a/main.c
+++ b/main.c
@@ -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));
}
diff --git a/menu.c b/menu.c
index 3013920..891d97e 100644
--- a/menu.c
+++ b/menu.c
@@ -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;
}
diff --git a/ted.cfg b/ted.cfg
index 5bdd43d..0906df4 100644
--- a/ted.cfg
+++ b/ted.cfg
@@ -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.
diff --git a/util.c b/util.c
index 4a5340b..59ece04 100644
--- a/util.c
+++ b/util.c
@@ -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;
+}