Skip to content
Newer
Older
100644 62 lines (49 sloc) 2.43 KB
ceb6a35 snapshot save
megaannum authored Aug 21, 2012
1 # Command
2
3 ## Basics
4
5 Some interactive Glyphs can take either an Action or a Command.
6 A Command is a String that is executed on the command line.
7 Since the command line is not available while running a Forms Form,
8 when the Forms run-time system encounters a command, control is
9 passed up to the top-level Viewer which, in fact, is also the top-level
10 Form and, as part of this Form exiting its 'run()' method, the
11 command String is executed.
12
13 A Glyph that can have a Command has a 'command' attribute. Generally, such
14 a Glyph at any one time can support either an Action or a Command; never
15 both at the same time. When such a Glyph has an Action and the Glyph is
16 selected, the Action executes and control is returned to the calling
17 Viewer. However, as described above, with a Command, the flow is different.
18 The Glyph places a 'Command' Event at the front of the Input Queue and
19 the Viewer then gets the next Event, sees that its a 'Command' Event and,
20 if its not the top-level Viewer, it places the 'Command' Event back on
21 the front of the Input Queue and the Viewer exits returning control
22 to the next higher Viewer. This stops at the top-level Viewer (which
23 is actually a Form - remember a Form is a sub-type of Viewer) and
24 it is this top-level Viewer/Form that extracts the command String
25 from the 'Command' Event and executes it.
26
27 ## Simple Command-line
28
29 The following is a Button which, when selected, cause Vim so save the
30 buffers it was working on and exit.
31
32 let label = forms#newLabel({'text': 'Save-Exit'})
33 let attrs = { 'body': label,
34 \ 'command': ':wqa'
35 \ }
36 let button = forms#newButton(attrs)
37
38 ## Call Function
39
40 The following is adapted from the menu.vim example code. Here, a Button
41 when selected will launch Forms' FileBrowser dialog (which will be a
42 sub-Form) and, it the FileBrowser returns a filename, then the 'e', edit,
43 command is executed giving the command that filename.
44
45 function! BrowserAction(title, cmd)
46 " call Forms' FileBrowser dialog
47 let f = forms#dialog#filebrowser#Make(a:title)
48 if f != ''
49 execute ':'.a:cmd." ".f
50 endif
51 endfunction
52
53 let label = forms#newLabel({'text': 'Edit File'})
54 let attrs = { 'body': label,
55 \ 'command': ":call BrowserAction('Edit File', 'e')"
56 \ }
57 let button = forms#newButton(attrs)
58
59 Using techniques like these, all of the GVim MenuBar and Popup Menu
60 have been duplicated with the Forms library.
61
Something went wrong with that request. Please try again.