]> git.mdlowis.com Git - projs/tide.git/commitdiff
added middle click execution logic for tags
authorMichael D. Lowis <mike@mdlowis.com>
Sat, 19 Nov 2016 23:36:27 +0000 (18:36 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Sat, 19 Nov 2016 23:36:27 +0000 (18:36 -0500)
Makefile
inc/edit.h
libedit/view.c
xedit [new file with mode: 0755]
xedit.c

index 3208b11eee82264d5636df5c4b13c0aa11a43bea..59f1c1ebc239ec68ac3af1fe6b09e011eebb4052 100644 (file)
--- 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) $@ $^
index 7113db2457deac96d97ebfe857bcc1a4008ccbca..aaa9e452019a152222a41eedd634040a3d2dfc5c 100644 (file)
@@ -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 {
index 428e09e4439a91e40963a802bc498969528b6d5e..8398dafe3a97b2b0d1e58ce41570fda33dfc692c 100644 (file)
@@ -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 (executable)
index 0000000..b04166f
Binary files /dev/null and b/xedit differ
diff --git a/xedit.c b/xedit.c
index fd44d89350b3f92731b0d6e09e901200329f3da9..874068641a3112eb85893984dd12dabb8d7c06a4 100644 (file)
--- 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) = {