From: Michael D. Lowis Date: Sat, 19 Nov 2016 23:36:27 +0000 (-0500) Subject: added middle click execution logic for tags X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=7d5a22ce09c457a2c33a26cef1764b4e20e603f7;p=projs%2Ftide.git added middle click execution logic for tags --- diff --git a/Makefile b/Makefile index 3208b11..59f1c1e 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ test: unittests ./unittests xedit: xedit.o libx.a libedit.a -xpick: xpick.o libx.a libedit.a +#xpick: xpick.o libx.a libedit.a libedit.a: $(LIBEDIT_OBJS) $(AR) $(ARFLAGS) $@ $^ diff --git a/inc/edit.h b/inc/edit.h index 7113db2..aaa9e45 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -156,6 +156,7 @@ void view_setcursor(View* view, size_t row, size_t col); void view_selext(View* view, size_t row, size_t col); void view_selword(View* view, size_t row, size_t col); void view_select(View* view, size_t row, size_t col); +char* view_fetch(View* view, size_t row, size_t col); void view_find(View* view, size_t row, size_t col); void view_insert(View* view, Rune rune); void view_delete(View* view); @@ -228,6 +229,12 @@ typedef struct { View view; } Region; +typedef struct { + char* tag; + void (*action)(void); +} Tag; + + /* Configuration *****************************************************************************/ enum { diff --git a/libedit/view.c b/libedit/view.c index 428e09e..8398daf 100644 --- a/libedit/view.c +++ b/libedit/view.c @@ -307,6 +307,22 @@ void view_select(View* view, size_t row, size_t col) { view->selection = sel; } +char* view_fetch(View* view, size_t row, size_t col) { + char* str = NULL; + size_t off = getoffset(view, row, col); + if (off != SIZE_MAX) { + Sel sel = { .beg = off, .end = off }; + if (in_selection(view->selection, off)) { + sel = view->selection; + } else { + selcontext(view, &sel); + sel.end++; + } + str = view_getstr(view, &sel); + } + return str; +} + void view_find(View* view, size_t row, size_t col) { size_t off = getoffset(view, row, col); if (off != SIZE_MAX) { diff --git a/xedit b/xedit new file mode 100755 index 0000000..b04166f Binary files /dev/null and b/xedit differ diff --git a/xedit.c b/xedit.c index fd44d89..8740686 100644 --- a/xedit.c +++ b/xedit.c @@ -64,6 +64,7 @@ static enum RegionId getregion(size_t x, size_t y) { } return NREGIONS; } + /* UI Callbacks *****************************************************************************/ static void delete(void) { @@ -104,15 +105,9 @@ static void page_dn(void) { static void change_focus(void) { if (Focused == TAGS) { - if (TagWinExpanded) { - TagWinExpanded = false; - Focused = EDIT; - } else { - TagWinExpanded = true; - } + Focused = EDIT; } else { Focused = TAGS; - TagWinExpanded = true; } } @@ -160,6 +155,30 @@ static void paste(void) { free(str); } +/* Builtin Tags + *****************************************************************************/ +Tag Builtins[] = { + { "Quit", quit }, + { "Save", save }, + { "Cut", cut }, + { "Copy", copy }, + { "Paste", paste }, + //{ "Find", NULL }, + { NULL, NULL } +}; + +static void tagexec(char* cmd) { + Tag* tags = Builtins; + while (tags->tag) { + if (!strcmp(tags->tag, cmd)) { + Focused = EDIT; + tags->action(); + break; + } + tags++; + } +} + /* Mouse Handling *****************************************************************************/ static void mouse_left(enum RegionId id, size_t count, size_t row, size_t col) { @@ -175,9 +194,11 @@ static void mouse_left(enum RegionId id, size_t count, size_t row, size_t col) { static void mouse_middle(enum RegionId id, size_t count, size_t row, size_t col) { if (MouseBtns[MOUSE_BTN_LEFT].pressed) cut(); - else - puts("exec"); - // view_exec(getview(id), row, col); + else { + char* str = view_fetch(getview(id), row, col); + tagexec(str); + free(str); + } } static void mouse_right(enum RegionId id, size_t count, size_t row, size_t col) { @@ -188,11 +209,11 @@ static void mouse_right(enum RegionId id, size_t count, size_t row, size_t col) } static void mouse_wheelup(enum RegionId id, size_t count, size_t row, size_t col) { - view_scroll(getview(id), -1); + view_scroll(getview(id), -ScrollLines); } static void mouse_wheeldn(enum RegionId id, size_t count, size_t row, size_t col) { - view_scroll(getview(id), 1); + view_scroll(getview(id), +ScrollLines); } void (*MouseActs[MOUSE_BTN_COUNT])(enum RegionId id, size_t count, size_t row, size_t col) = {