X-Git-Url: https://git.sven.stormbind.net/?a=blobdiff_plain;f=macros%2Fmacros.vys;h=441957026e0f245a5b42e3362fb88d0e0177885f;hb=HEAD;hp=77087a28ba51f2a7994739a373a25d1a0cf2f39d;hpb=91d5bdcaff9c6ccbf8a4e2154bfda353e382d057;p=sven%2Fvym.git

diff --git a/macros/macros.vys b/macros/macros.vys
index 77087a2..f60b1d7 100644
--- a/macros/macros.vys
+++ b/macros/macros.vys
@@ -1,28 +1,59 @@
 // vim:syntax=javascript
 
-// Helper function to toggle frame
-function toggle_frame(map)
+// Macros called when function keys are pressed
+
+
+//! Helper function to toggle frame
+function toggle_frame_branch(map)
 {
-    if (map.getFrameType() == "NoFrame" ) {
-        map.setFrameType ("RoundedRectangle");
+    map = vym.currentMap();
+    b = map.selectedBranch();
+
+    if (b.getFrameType(true) == "NoFrame" ) {
+        b.setFrameType (true, "RoundedRectangle");
     } else
-        map.setFrameType ("NoFrame");
+        b.setFrameType (true, "NoFrame");
+}
+
+function toggle_frame_subtree(map)
+{
+    map = vym.currentMap();
+    b = map.selectedBranch();
+
+    if (b.getFrameType(false) == "NoFrame" ) {
+        b.setFrameType (false, "RoundedRectangle");
+    } else
+        b.setFrameType (false, "NoFrame");
+}
+
+
+function colorBranchWithQuickColor(n)
+{
+    map = vym.currentMap();
+    vym.selectQuickColor(n);
+    c = vym.currentColor();
+
+    b = map.selectedBranch();
+    b.colorBranch(c);
 }
+
 function colorSubtreeWithQuickColor(n)
 {
     map = vym.currentMap();
     vym.selectQuickColor(n);
     c = vym.currentColor();
-    map.colorSubtree (c);
+
+    b = map.selectedBranch();
+    b.colorSubtree (c);
 }
 
-// Macro F1: Color subtree red
+//! Macro F1: Color subtree red
 function macro_f1()
 {
     colorSubtreeWithQuickColor(0);
 }
 
-// Macro F2: Color subtree orange
+//! Macro F2: Color subtree orange
 function macro_f2()
 {
     colorSubtreeWithQuickColor(1);
@@ -32,63 +63,63 @@ function macro_f2()
     // vym.editHeading();
 }
 
-// Macro F3: Color subtree green
+//! Macro F3: Color subtree green
 function macro_f3()
 {
     colorSubtreeWithQuickColor(2);
 }
 
 
-// Macro F4: Color subtree purple
+//! Macro F4: Color subtree purple
 function macro_f4()
 {
     colorSubtreeWithQuickColor(3);
 }
 
-// Macro F5: Color subtree blue
+//! Macro F5: Color subtree blue
 function macro_f5()
 {
     colorSubtreeWithQuickColor(4);
 }
 
-// Macro F6: Color subtree blue
+//! Macro F6: Color subtree blue
 function macro_f6()
 {
     colorSubtreeWithQuickColor(5);
 }
 
-// Macro F7: Color subtree black
+//! Macro F7: Color subtree black
 function macro_f7()
 {
     colorSubtreeWithQuickColor(6);
 }
 
-// Macro F8: Color subtree dark gray
+//! Macro F8: Color subtree dark gray
 function macro_f8()
 {
     colorSubtreeWithQuickColor(7);
 }
 
-// Macro F9: Color subtree light gray
+//! Macro F9: Color subtree light gray
 function macro_f9()
 {
     colorSubtreeWithQuickColor(8);
 }
 
-// Macro F10: Color subtree light white
+//! Macro F10: Color subtree light white
 function macro_f10()
 {
     colorSubtreeWithQuickColor(9);
 }
 
-// Macro F11: Repeat last command
+//! Macro F11: Repeat last command
 function macro_f11()
 {
     map = vym.currentMap();
     map.repeatLastCommand();
 }
 
-// Macro F12: toggle high prio task
+//! Macro F12: toggle high prio task
 function macro_f12()
 {
 	// Assuming 3 states, which are cycled:
@@ -96,144 +127,154 @@ function macro_f12()
 	// 1 - high prio task with arrows
 	// 2 - done task without arrows, but green hook
     map = vym.currentMap();
-    if (map.hasTask() ) {
+    b = map.selectedBranch();
+    if (b.hasTask() ) {
         // Switch to state 2 
-        map.toggleTask();
-        map.unsetFlagByName("2arrow-up");
-        map.unsetFlagByName("stopsign");
-        map.setFlagByName("hook-green");
-        map.colorBranch("#0000ff");
+        b.toggleTask();
+        b.unsetFlagByName("2arrow-up");
+        b.unsetFlagByName("stopsign");
+        b.setFlagByName("hook-green");
+        if (vym.usesDarkTheme())
+            colorBranchWithQuickColor(5);
+        else
+            colorBranchWithQuickColor(3);
     } else {
-        if (map.hasActiveFlag("hook-green")) {
+        if (b.hasActiveFlag("hook-green")) {
             // Switch to state 0
-            map.unsetFlagByName("hook-green");
+            b.unsetFlagByName("hook-green");
         } else {
             // Switch to state 1
-            map.setFlagByName("2arrow-up");
-            map.toggleTask();
+            b.setFlagByName("2arrow-up");
+            b.toggleTask();
         }
     }
 }
 
 
-// Macro Shift + F1: Frame background light red
+//! Macro Shift + F1: Frame background light red
 function macro_shift_f1()
 {
     map = vym.currentMap();
+    b = map.selectedBranch();
     status = "Background off";
-    if (map.getFrameType() == "NoFrame") {
+    if (b.getFrameType(true) == "NoFrame") {
         status = "Background light red";
     }
-    toggle_frame ( map );
-    map.setFrameBrushColor("#ffb3b4");
-    statusMessage(status);
+    toggle_frame_branch ( map );
+    b.setFrameBrushColor(true, "#ffb3b4");
+    vym.statusMessage(status);
 }
 
-// Macro Shift + F2: Frame background light green
+//! Macro Shift + F2: Frame background light green
 function macro_shift_f2()
 {
     map = vym.currentMap();
+    b = map.selectedBranch();
     status = "Background off";
-    if (map.getFrameType() == "NoFrame") {
+    if (b.getFrameType(true) == "NoFrame") {
         status = "Background light green";
     }
-    toggle_frame ( map );
-    map.setFrameBrushColor("#bdffd6");
-    statusMessage(status);
+    toggle_frame_branch ( map );
+    b.setFrameBrushColor(true, "#bdffd6");
+    vym.statusMessage(status);
 }
 
-// Macro Shift + F3: Frame background light yellow
+//! Macro Shift + F3: Frame background light yellow
 function macro_shift_f3()
 {
     map = vym.currentMap();
+    b = map.selectedBranch();
     status = "Background off";
-    if (map.getFrameType() == "NoFrame") {
+    if (b.getFrameType(true) == "NoFrame") {
         status = "Background light yellow";
     }
-    toggle_frame ( map );
-    map.setFrameBrushColor("#efefb3");
-    statusMessage(status);
+    toggle_frame_branch ( map );
+    b.setFrameBrushColor(true, "#efefb3");
+    vym.statusMessage(status);
 }
 
-// Macro Shift + F4: Frame background light blue
+//! Macro Shift + F4: Frame background light blue
 function macro_shift_f4()
 {
     map = vym.currentMap();
+    b = map.selectedBranch();
     status = "Background off";
-    if (map.getFrameType() == "NoFrame") {
+    if (b.getFrameType(true) == "NoFrame") {
         status = "Background light blue";
     }
-    toggle_frame ( map );
-    map.setFrameBrushColor("#e2e6ff");
-    statusMessage(status);
+    toggle_frame_branch ( map );
+    b.setFrameBrushColor(true, "#e2e6ff");
+    vym.statusMessage(status);
 }
 
-// Macro Shift + F5: Frame background light grey
+//! Macro Shift + F5: Frame background light grey
 function macro_shift_f5()
 {
     map = vym.currentMap();
+    b = map.selectedBranch();
     status = "Background off";
-    if (map.getFrameType() == "NoFrame") {
+    if (b.getFrameType(true) == "NoFrame") {
         status = "Background light grey";
     }
-    toggle_frame ( map );
-    map.setFrameBrushColor("#d6d6d6");
-    statusMessage(status);
+    toggle_frame_branch ( map );
+    b.setFrameBrushColor(true, "#d6d6d6");
+    vym.statusMessage(status);
 }
 
-// Macro Shift + F6: Frame background purple
+//! Macro Shift + F6: Frame background purple
 function macro_shift_f6()
 {
     map = vym.currentMap();
+    b = map.selectedBranch();
     status = "Background off";
-    if (map.getFrameType() == "NoFrame") {
+    if (b.getFrameType(true) == "NoFrame") {
         status = "Background purple";
     }
-    toggle_frame ( map );
-    map.setFrameBrushColor("#ffaaff");
-    statusMessage(status);
+    toggle_frame_branch ( map );
+    b.setFrameBrushColor(true, "#ffaaff");
+    vym.statusMessage(status);
 }
 
-// Macro Shift + F7: Frame background white
+//! Macro Shift + F7: Frame background white
 function macro_shift_f7()
 {
     map = vym.currentMap();
+    b = map.selectedBranch();
     status = "Background off";
-    if (map.getFrameType() == "NoFrame") {
+    if (b.getFrameType() == "NoFrame") {
         status = "Background white";
     }
-    toggle_frame ( map );
-    map.setFrameBrushColor("#ffffff");
-    statusMessage(status);
+    toggle_frame_branch ( map );
+    b.setFrameBrushColor("#ffffff");
+    vym.statusMessage(status);
 }
 
-// Macro Shift + F8: Frame background black
+//! Macro Shift + F8: Frame background black
 function macro_shift_f8()
 {
     map = vym.currentMap();
+    b = map.selectedBranch();
     status = "Background off";
-    if (map.getFrameType() == "NoFrame") {
+    if (b.getFrameType(true) == "NoFrame") {
         status = "Background black";
     }
-    toggle_frame ( map );
-    map.setFrameBrushColor("#000000");
-    statusMessage(status);
+    toggle_frame_branch ( map );
+    b.setFrameBrushColor(true, "#000000");
+    vym.statusMessage(status);
 }
 
-// Macro Shift + F9: Toggle frame to include children
+// Macro Shift + F9:
 function macro_shift_f9()
 {
-    map = vym.currentMap();
-    map.toggleFrameIncludeChildren();
 }
 
-// Macro Shift + F10: 
+//! Macro Shift + F10: 
 // Useful for timestamps created on last entry
 function macro_shift_f10()
-{   
+{
 }
 
-// Macro Shift + F11: Replace "@..." by mutt aliases
+//! Macro Shift + F11: Replace "@..." by mutt aliases
 function macro_shift_f11()
 {
 	map     = vym.currentMap();
@@ -272,68 +313,219 @@ function macro_shift_f11()
 	}
 }
 
-// Macro Shift + F12: Strip URLs from confluence and generate readable heading
+//! Macro Shift + F12:
 function macro_shift_f12()
 {
-    vym.clearConsole();
-    m1 = vym.currentMap();
+    vym.statusMessage("Macro F12 + Shift triggered");
+}
 
-    if (vym.isConfluenceAgentAvailable() ) {
-        m1.setHeadingConfluencePageName();
-        statusMessage("Contacting Confluence...");
-        return;
-    } 
 
-    org = m1.getURL();
+// New /////////////////////////////////////
+//! Macro Ctrl + F1: Subtree background light red
+function macro_ctrl_f1()
+{
+    map = vym.currentMap();
+    b = map.selectedBranch();
+    status = "Subtree background off";
+    if (b.getFrameType(false) == "NoFrame") {
+        status = "Subtree background light red";
+    }
+    toggle_frame_subtree ( map );
+    b.setFrameBrushColor(false, "#ffb3b4");
+    vym.statusMessage(status);
+}
 
-    if (org.length == 0) {
-		// No URL yet
-		org = m1.getHeadingPlainText();
-		print ("No URL yet");
-		print ("org: " + org);
-		m1.setURL(org);
-	}
-    print ("Original:");
-    print (org);
+//! Macro Ctrl + F2: Subtree background light green
 
-    s = org;
+function macro_ctrl_f2()
+{
+    map = vym.currentMap();
+    b = map.selectedBranch();
+    status = "Subtree background off";
+    if (b.getFrameType(true) == "NoFrame") {
+        status = "Subtree background light green";
+    }
+    toggle_frame_branch ( map );
+    b.setFrameBrushColor(true, "#bdffd6");
+    vym.statusMessage(status);
+}
 
-    // Chop trailing "/"
-    if (s[s.length-1] == '/') {
-      s = s.slice(0, s.length - 1);
+//! Macro Ctrl + F3: Subtree background light yellow
+function macro_ctrl_f3()
+{
+    map = vym.currentMap();
+    b = map.selectedBranch();
+    status = "Subtree background off";
+    if (b.getFrameType(true) == "NoFrame") {
+        status = "SUbtree background light yellow";
     }
+    toggle_frame_branch ( map );
+    b.setFrameBrushColor(true, "#efefb3");
+    vym.statusMessage(status);
+}
 
-    // Remove confluence parts
-    if (s.indexOf("infohub") != -1) {
-      print("Found infohub page");
-      if (s.indexOf("spaceKey") != -1) {
-        s = s.replace(/^.*spaceKey=/g, "");
-        s = s.replace(/(&title=)/g, ": ");
-      } else
-      {
-        s = s.replace(/^.*display\//g, "");
-        s = s.replace(/\//g, ": ");
-      }
-    } else // no infohub page
-    {
-      // remove path
-      s = s.replace(/^.*\//g, "");
+//! Macro Ctrl + F4: Subtree background light blue
+function macro_ctrl_f4()
+{
+    map = vym.currentMap();
+    b = map.selectedBranch();
+    status = "Subtree background off";
+    if (b.getFrameType(true) == "NoFrame") {
+        status = "SUbtree background light yellow";
     }
+    toggle_frame_branch ( map );
+    b.setFrameBrushColor(true, "#efefb3");
+    vym.statusMessage(status);
+}
 
-    print (s);
+//! Macro Ctrl + F5: Subtree  background light grey
+function macro_ctrl_f5()
+{
+    map = vym.currentMap();
+    b = map.selectedBranch();
+    status = "Subtree background off";
+    if (b.getType(true) == "NoFrame") {
+        status = "Subtree background light grey";
+    }
+    toggle_frame_branch ( map );
+    b.setFrameBrushColor(true, "#d6d6d6");
+    vym.statusMessage(status);
+}
 
-    // Replace "+" and "-"
-    s = s.replace(/\+/g, " ");
-    s = s.replace(/%3A/g, "");
-    print ("After replacing:");
-    print (s);
+//! Macro Ctrl + F6: Subtree background purple
+function macro_ctrl_f6()
+{
+    map = vym.currentMap();
+    b = map.selectedBranch();
+    status = "Subtree background off";
+    if (b.getFrameType(true) == "NoFrame") {
+        status = "Subtree background purple";
+    }
+    toggle_frame_branch ( map );
+    b.setFrameBrushColor(true, "#ffaaff");
+    vym.statusMessage(status);
+}
 
-    // Write new header
-    m1.setHeadingPlainText(s);
+//! Macro Ctrl + F7: Subtree background white
+function macro_ctrl_f7()
+{
+    map = vym.currentMap();
+    b = map.selectedBranch();
+    status = "Subtree background off";
+    if (b.getFrameType() == "NoFrame") {
+        status = "Subtree background white";
+    }
+    toggle_frame_branch ( map );
+    b.setFrameBrushColor("#ffffff");
+    vym.statusMessage(status);
+}
 
-    if ( org == s ) {
-      statusMessage ("Heading not changed.");
-    } else {
-      statusMessage("Changed heading: " + org + " -> " + s);
+//! Macro Ctrl + F8: Subtree background black
+function macro_ctrl_f8()
+{
+    map = vym.currentMap();
+    b = map.selectedBranch();
+    status = "Subtree background off";
+    if (b.getFrameType(true) == "NoFrame") {
+        status = "Subtree background black";
     }
+    toggle_frame_branch ( map );
+    b.setFrameBrushColor(true, "#000000");
+    vym.statusMessage(status);
+}
+
+//! Macro Ctrl + F9:
+function macro_ctrl_f9()
+{
+    vym.statusMessage("Macro F9 + Ctrl triggered");
+}
+
+//! Macro Ctrl + F10: 
+function macro_ctrl_f10()
+{
+    vym.statusMessage("Macro F10 + Ctrl triggered");
+}
+
+//! Macro Ctrl + F11:
+function macro_ctrl_f11()
+{
+    vym.statusMessage("Macro F11 + Ctrl triggered");
+}
+
+//! Macro Ctrl + F12:
+function macro_ctrl_f12()
+{
+    vym.statusMessage("Macro F12 + Ctrl triggered");
+}
+
+//! Macro Ctrl + Shift + F1:
+function macro_ctrl_shift_f1()
+{
+    vym.statusMessage("Macro F1 + Ctrl + Shift triggered");
+}
+
+//! Macro Ctrl + Shift + F2:
+function macro_ctrl_shift_f2()
+{
+    vym.statusMessage("Macro F2 + Ctrl + Shift triggered");
+}
+
+//! Macro Ctrl + Shift + F3:
+function macro_ctrl_shift_f3()
+{
+    vym.statusMessage("Macro F3 + Ctrl + Shift triggered");
+}
+
+//! Macro Ctrl + Shift + F4:
+function macro_ctrl_shift_f4()
+{
+    vym.statusMessage("Macro F4 + Ctrl + Shift triggered");
+}
+
+//! Macro Ctrl + Shift + F5:
+function macro_ctrl_shift_f5()
+{
+    vym.statusMessage("Macro F5 + Ctrl + Shift triggered");
+}
+
+//! Macro Ctrl + Shift + F6:
+function macro_ctrl_shift_f6()
+{
+    vym.statusMessage("Macro F6 + Ctrl + Shift triggered");
+}
+
+//! Macro Ctrl + Shift + F7:
+function macro_ctrl_shift_f7()
+{
+    vym.statusMessage("Macro F7 + Ctrl + Shift triggered");
+}
+
+//! Macro Ctrl + Shift + F8:
+function macro_ctrl_shift_f8()
+{
+    vym.statusMessage("Macro F8 + Ctrl + Shift triggered");
+}
+
+//! Macro Ctrl + Shift + F9:
+function macro_ctrl_shift_f9()
+{
+    vym.statusMessage("Macro F9 + Ctrl + Shift triggered");
+}
+
+//! Macro Ctrl + Shift + F10: 
+function macro_ctrl_shift_f10()
+{
+    vym.statusMessage("Macro F10 + Ctrl + Shift triggered");
+}
+
+//! Macro Ctrl + Shift + F11:
+function macro_ctrl_shift_f11()
+{
+    vym.statusMessage("Macro F11 + Ctrl + Shift triggered");
+}
+
+//! Macro Ctrl + Shift + F12:
+function macro_ctrl_shift_f12()
+{
+    vym.statusMessage("Macro F12 + Ctrl + Shift triggered");
 }
\ No newline at end of file