]> git.sven.stormbind.net Git - sven/vym.git/blob - macros/macros.vys
New upstream version 2.9.22
[sven/vym.git] / macros / macros.vys
1 // vim:syntax=javascript
2
3 // Helper function to toggle frame
4 function toggle_frame(map)
5 {
6     if (map.getFrameType() == "NoFrame" ) {
7         map.setFrameType ("RoundedRectangle");
8     } else
9         map.setFrameType ("NoFrame");
10 }
11 function colorSubtreeWithQuickColor(n)
12 {
13     map = vym.currentMap();
14     vym.selectQuickColor(n);
15     c = vym.currentColor();
16     map.colorSubtree (c);
17 }
18
19 // Macro F1: Color subtree red
20 function macro_f1()
21 {
22     colorSubtreeWithQuickColor(0);
23 }
24
25 // Macro F2: Color subtree orange
26 function macro_f2()
27 {
28     colorSubtreeWithQuickColor(1);
29
30     // Or if you prefer to edit the heading of a branch using "F2"-key,
31     // you can use below instead of above:
32     // vym.editHeading();
33 }
34
35 // Macro F3: Color subtree green
36 function macro_f3()
37 {
38     colorSubtreeWithQuickColor(2);
39 }
40
41
42 // Macro F4: Color subtree purple
43 function macro_f4()
44 {
45     colorSubtreeWithQuickColor(3);
46 }
47
48 // Macro F5: Color subtree blue
49 function macro_f5()
50 {
51     colorSubtreeWithQuickColor(4);
52 }
53
54 // Macro F6: Color subtree blue
55 function macro_f6()
56 {
57     colorSubtreeWithQuickColor(5);
58 }
59
60 // Macro F7: Color subtree black
61 function macro_f7()
62 {
63     colorSubtreeWithQuickColor(6);
64 }
65
66 // Macro F8: Color subtree dark gray
67 function macro_f8()
68 {
69     colorSubtreeWithQuickColor(7);
70 }
71
72 // Macro F9: Color subtree light gray
73 function macro_f9()
74 {
75     colorSubtreeWithQuickColor(8);
76 }
77
78 // Macro F10: Color subtree light white
79 function macro_f10()
80 {
81     colorSubtreeWithQuickColor(9);
82 }
83
84 // Macro F11: Repeat last command
85 function macro_f11()
86 {
87     map = vym.currentMap();
88     map.repeatLastCommand();
89 }
90
91 // Macro F12: toggle high prio task
92 function macro_f12()
93 {
94         // Assuming 3 states, which are cycled:
95         // 0 - nothing set
96         // 1 - high prio task with arrows
97         // 2 - done task without arrows, but green hook
98     map = vym.currentMap();
99     if (map.hasTask() ) {
100         // Switch to state 2 
101         map.toggleTask();
102         map.unsetFlagByName("2arrow-up");
103         map.unsetFlagByName("stopsign");
104         map.setFlagByName("hook-green");
105         map.colorBranch("#0000ff");
106     } else {
107         if (map.hasActiveFlag("hook-green")) {
108             // Switch to state 0
109             map.unsetFlagByName("hook-green");
110         } else {
111             // Switch to state 1
112             map.setFlagByName("2arrow-up");
113             map.toggleTask();
114         }
115     }
116 }
117
118
119 // Macro Shift + F1: Frame background light red
120 function macro_shift_f1()
121 {
122     map = vym.currentMap();
123     status = "Background off";
124     if (map.getFrameType() == "NoFrame") {
125         status = "Background light red";
126     }
127     toggle_frame ( map );
128     map.setFrameBrushColor("#ffb3b4");
129     statusMessage(status);
130 }
131
132 // Macro Shift + F2: Frame background light green
133 function macro_shift_f2()
134 {
135     map = vym.currentMap();
136     status = "Background off";
137     if (map.getFrameType() == "NoFrame") {
138         status = "Background light green";
139     }
140     toggle_frame ( map );
141     map.setFrameBrushColor("#bdffd6");
142     statusMessage(status);
143 }
144
145 // Macro Shift + F3: Frame background light yellow
146 function macro_shift_f3()
147 {
148     map = vym.currentMap();
149     status = "Background off";
150     if (map.getFrameType() == "NoFrame") {
151         status = "Background light yellow";
152     }
153     toggle_frame ( map );
154     map.setFrameBrushColor("#efefb3");
155     statusMessage(status);
156 }
157
158 // Macro Shift + F4: Frame background light blue
159 function macro_shift_f4()
160 {
161     map = vym.currentMap();
162     status = "Background off";
163     if (map.getFrameType() == "NoFrame") {
164         status = "Background light blue";
165     }
166     toggle_frame ( map );
167     map.setFrameBrushColor("#e2e6ff");
168     statusMessage(status);
169 }
170
171 // Macro Shift + F5: Frame background light grey
172 function macro_shift_f5()
173 {
174     map = vym.currentMap();
175     status = "Background off";
176     if (map.getFrameType() == "NoFrame") {
177         status = "Background light grey";
178     }
179     toggle_frame ( map );
180     map.setFrameBrushColor("#d6d6d6");
181     statusMessage(status);
182 }
183
184 // Macro Shift + F6: Frame background purple
185 function macro_shift_f6()
186 {
187     map = vym.currentMap();
188     status = "Background off";
189     if (map.getFrameType() == "NoFrame") {
190         status = "Background purple";
191     }
192     toggle_frame ( map );
193     map.setFrameBrushColor("#ffaaff");
194     statusMessage(status);
195 }
196
197 // Macro Shift + F7: Frame background white
198 function macro_shift_f7()
199 {
200     map = vym.currentMap();
201     status = "Background off";
202     if (map.getFrameType() == "NoFrame") {
203         status = "Background white";
204     }
205     toggle_frame ( map );
206     map.setFrameBrushColor("#ffffff");
207     statusMessage(status);
208 }
209
210 // Macro Shift + F8: Frame background black
211 function macro_shift_f8()
212 {
213     map = vym.currentMap();
214     status = "Background off";
215     if (map.getFrameType() == "NoFrame") {
216         status = "Background black";
217     }
218     toggle_frame ( map );
219     map.setFrameBrushColor("#000000");
220     statusMessage(status);
221 }
222
223 // Macro Shift + F9: Toggle frame to include children
224 function macro_shift_f9()
225 {
226     map = vym.currentMap();
227     map.toggleFrameIncludeChildren();
228 }
229
230 // Macro Shift + F10: 
231 // Useful for timestamps created on last entry
232 function macro_shift_f10()
233 {   
234 }
235
236 // Macro Shift + F11: Replace "@..." by mutt aliases
237 function macro_shift_f11()
238 {
239         map     = vym.currentMap();
240         lines   = vym.loadFile("/home/uwe/.mutt/eb-aliases").split('\n');
241
242
243         if (map.getHeadingPlainText() == "parts") {
244                 map.setHeadingPlainText("Participants");
245         }
246
247         map.initIterator("foobar");
248
249         while (map.nextIterator("foobar") ) {
250                 heading = map.getHeadingPlainText();
251
252                 // Search for "@alias" at beginning of heading
253                 if (heading.search(/^@\w/) == 0) {
254                         alias_map = heading.replace(/@/,"");
255
256                         for(var i = 0;i < lines.length;i++){
257                                 if (lines[i].search(/^alias/) == 0) {
258                                         if (lines[i].search(alias_map) == 6) {
259                                                 name = lines[i].replace(/^.+?\"/, "");
260                                                 name = name.replace(/\".+/, "");
261
262                                                 email = lines[i].replace(/^.+?</, "");
263                                                 email = email.replace(/>.*/, "");
264
265                                                 map.setHeadingPlainText(name);
266                                         }
267                                 }
268                         }
269                 } else {
270                         print ("No alias found");
271         }
272         }
273 }
274
275 // Macro Shift + F12: Strip URLs from confluence and generate readable heading
276 function macro_shift_f12()
277 {
278     vym.clearConsole();
279     m1 = vym.currentMap();
280
281     if (vym.isConfluenceAgentAvailable() ) {
282         m1.setHeadingConfluencePageName();
283         statusMessage("Contacting Confluence...");
284         return;
285     } 
286
287     org = m1.getURL();
288
289     if (org.length == 0) {
290                 // No URL yet
291                 org = m1.getHeadingPlainText();
292                 print ("No URL yet");
293                 print ("org: " + org);
294                 m1.setURL(org);
295         }
296     print ("Original:");
297     print (org);
298
299     s = org;
300
301     // Chop trailing "/"
302     if (s[s.length-1] == '/') {
303       s = s.slice(0, s.length - 1);
304     }
305
306     // Remove confluence parts
307     if (s.indexOf("infohub") != -1) {
308       print("Found infohub page");
309       if (s.indexOf("spaceKey") != -1) {
310         s = s.replace(/^.*spaceKey=/g, "");
311         s = s.replace(/(&title=)/g, ": ");
312       } else
313       {
314         s = s.replace(/^.*display\//g, "");
315         s = s.replace(/\//g, ": ");
316       }
317     } else // no infohub page
318     {
319       // remove path
320       s = s.replace(/^.*\//g, "");
321     }
322
323     print (s);
324
325     // Replace "+" and "-"
326     s = s.replace(/\+/g, " ");
327     s = s.replace(/%3A/g, "");
328     print ("After replacing:");
329     print (s);
330
331     // Write new header
332     m1.setHeadingPlainText(s);
333
334     if ( org == s ) {
335       statusMessage ("Heading not changed.");
336     } else {
337       statusMessage("Changed heading: " + org + " -> " + s);
338     }
339 }