X-Git-Url: https://git.sven.stormbind.net/?a=blobdiff_plain;f=macros%2Fmacros.vys;fp=macros%2Fmacros.vys;h=77087a28ba51f2a7994739a373a25d1a0cf2f39d;hb=d483bd8e6523c23c6f1d8908a2e0611c2bc9ff4f;hp=0000000000000000000000000000000000000000;hpb=7dfa3fe589d1722d49681f42cdb0bf1e6efb5223;p=sven%2Fvym.git diff --git a/macros/macros.vys b/macros/macros.vys new file mode 100644 index 0000000..77087a2 --- /dev/null +++ b/macros/macros.vys @@ -0,0 +1,339 @@ +// vim:syntax=javascript + +// Helper function to toggle frame +function toggle_frame(map) +{ + if (map.getFrameType() == "NoFrame" ) { + map.setFrameType ("RoundedRectangle"); + } else + map.setFrameType ("NoFrame"); +} +function colorSubtreeWithQuickColor(n) +{ + map = vym.currentMap(); + vym.selectQuickColor(n); + c = vym.currentColor(); + map.colorSubtree (c); +} + +// Macro F1: Color subtree red +function macro_f1() +{ + colorSubtreeWithQuickColor(0); +} + +// Macro F2: Color subtree orange +function macro_f2() +{ + colorSubtreeWithQuickColor(1); + + // Or if you prefer to edit the heading of a branch using "F2"-key, + // you can use below instead of above: + // vym.editHeading(); +} + +// Macro F3: Color subtree green +function macro_f3() +{ + colorSubtreeWithQuickColor(2); +} + + +// Macro F4: Color subtree purple +function macro_f4() +{ + colorSubtreeWithQuickColor(3); +} + +// Macro F5: Color subtree blue +function macro_f5() +{ + colorSubtreeWithQuickColor(4); +} + +// Macro F6: Color subtree blue +function macro_f6() +{ + colorSubtreeWithQuickColor(5); +} + +// Macro F7: Color subtree black +function macro_f7() +{ + colorSubtreeWithQuickColor(6); +} + +// Macro F8: Color subtree dark gray +function macro_f8() +{ + colorSubtreeWithQuickColor(7); +} + +// Macro F9: Color subtree light gray +function macro_f9() +{ + colorSubtreeWithQuickColor(8); +} + +// Macro F10: Color subtree light white +function macro_f10() +{ + colorSubtreeWithQuickColor(9); +} + +// Macro F11: Repeat last command +function macro_f11() +{ + map = vym.currentMap(); + map.repeatLastCommand(); +} + +// Macro F12: toggle high prio task +function macro_f12() +{ + // Assuming 3 states, which are cycled: + // 0 - nothing set + // 1 - high prio task with arrows + // 2 - done task without arrows, but green hook + map = vym.currentMap(); + if (map.hasTask() ) { + // Switch to state 2 + map.toggleTask(); + map.unsetFlagByName("2arrow-up"); + map.unsetFlagByName("stopsign"); + map.setFlagByName("hook-green"); + map.colorBranch("#0000ff"); + } else { + if (map.hasActiveFlag("hook-green")) { + // Switch to state 0 + map.unsetFlagByName("hook-green"); + } else { + // Switch to state 1 + map.setFlagByName("2arrow-up"); + map.toggleTask(); + } + } +} + + +// Macro Shift + F1: Frame background light red +function macro_shift_f1() +{ + map = vym.currentMap(); + status = "Background off"; + if (map.getFrameType() == "NoFrame") { + status = "Background light red"; + } + toggle_frame ( map ); + map.setFrameBrushColor("#ffb3b4"); + statusMessage(status); +} + +// Macro Shift + F2: Frame background light green +function macro_shift_f2() +{ + map = vym.currentMap(); + status = "Background off"; + if (map.getFrameType() == "NoFrame") { + status = "Background light green"; + } + toggle_frame ( map ); + map.setFrameBrushColor("#bdffd6"); + statusMessage(status); +} + +// Macro Shift + F3: Frame background light yellow +function macro_shift_f3() +{ + map = vym.currentMap(); + status = "Background off"; + if (map.getFrameType() == "NoFrame") { + status = "Background light yellow"; + } + toggle_frame ( map ); + map.setFrameBrushColor("#efefb3"); + statusMessage(status); +} + +// Macro Shift + F4: Frame background light blue +function macro_shift_f4() +{ + map = vym.currentMap(); + status = "Background off"; + if (map.getFrameType() == "NoFrame") { + status = "Background light blue"; + } + toggle_frame ( map ); + map.setFrameBrushColor("#e2e6ff"); + statusMessage(status); +} + +// Macro Shift + F5: Frame background light grey +function macro_shift_f5() +{ + map = vym.currentMap(); + status = "Background off"; + if (map.getFrameType() == "NoFrame") { + status = "Background light grey"; + } + toggle_frame ( map ); + map.setFrameBrushColor("#d6d6d6"); + statusMessage(status); +} + +// Macro Shift + F6: Frame background purple +function macro_shift_f6() +{ + map = vym.currentMap(); + status = "Background off"; + if (map.getFrameType() == "NoFrame") { + status = "Background purple"; + } + toggle_frame ( map ); + map.setFrameBrushColor("#ffaaff"); + statusMessage(status); +} + +// Macro Shift + F7: Frame background white +function macro_shift_f7() +{ + map = vym.currentMap(); + status = "Background off"; + if (map.getFrameType() == "NoFrame") { + status = "Background white"; + } + toggle_frame ( map ); + map.setFrameBrushColor("#ffffff"); + statusMessage(status); +} + +// Macro Shift + F8: Frame background black +function macro_shift_f8() +{ + map = vym.currentMap(); + status = "Background off"; + if (map.getFrameType() == "NoFrame") { + status = "Background black"; + } + toggle_frame ( map ); + map.setFrameBrushColor("#000000"); + statusMessage(status); +} + +// Macro Shift + F9: Toggle frame to include children +function macro_shift_f9() +{ + map = vym.currentMap(); + map.toggleFrameIncludeChildren(); +} + +// Macro Shift + F10: +// Useful for timestamps created on last entry +function macro_shift_f10() +{ +} + +// Macro Shift + F11: Replace "@..." by mutt aliases +function macro_shift_f11() +{ + map = vym.currentMap(); + lines = vym.loadFile("/home/uwe/.mutt/eb-aliases").split('\n'); + + + if (map.getHeadingPlainText() == "parts") { + map.setHeadingPlainText("Participants"); + } + + map.initIterator("foobar"); + + while (map.nextIterator("foobar") ) { + heading = map.getHeadingPlainText(); + + // Search for "@alias" at beginning of heading + if (heading.search(/^@\w/) == 0) { + alias_map = heading.replace(/@/,""); + + for(var i = 0;i < lines.length;i++){ + if (lines[i].search(/^alias/) == 0) { + if (lines[i].search(alias_map) == 6) { + name = lines[i].replace(/^.+?\"/, ""); + name = name.replace(/\".+/, ""); + + email = lines[i].replace(/^.+?.*/, ""); + + map.setHeadingPlainText(name); + } + } + } + } else { + print ("No alias found"); + } + } +} + +// Macro Shift + F12: Strip URLs from confluence and generate readable heading +function macro_shift_f12() +{ + vym.clearConsole(); + m1 = vym.currentMap(); + + if (vym.isConfluenceAgentAvailable() ) { + m1.setHeadingConfluencePageName(); + statusMessage("Contacting Confluence..."); + return; + } + + org = m1.getURL(); + + if (org.length == 0) { + // No URL yet + org = m1.getHeadingPlainText(); + print ("No URL yet"); + print ("org: " + org); + m1.setURL(org); + } + print ("Original:"); + print (org); + + s = org; + + // Chop trailing "/" + if (s[s.length-1] == '/') { + s = s.slice(0, s.length - 1); + } + + // 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, ""); + } + + print (s); + + // Replace "+" and "-" + s = s.replace(/\+/g, " "); + s = s.replace(/%3A/g, ""); + print ("After replacing:"); + print (s); + + // Write new header + m1.setHeadingPlainText(s); + + if ( org == s ) { + statusMessage ("Heading not changed."); + } else { + statusMessage("Changed heading: " + org + " -> " + s); + } +} \ No newline at end of file