Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 118 lines (110 sloc) 5.018 kb
4c5e6d4c » megaannum
2012-07-27 first commit
1
2 " ------------------------------------------------------------
3 " forms#dialog#input#Make:
4 " A form that display information, provides line editor
5 " and submit/cancel buttons.
6 " The form has:
7 " Text
8 " VariableLengthField
9 " Submit and Cancel buttons
10 " Example:
11 " ┌──────────────────────────────────────────────────────────────┐
12 " │ Enter a command or word to find help on: │
13 " │ │
14 " │ Prepend i_ for Input mode commands (e.g.: i_CTRL-X) │
15 " │ Prepend c_ for command-line editing commands (e.g.: c_<Del>)│
16 " │ Prepend ' for an option name (e.g.: 'shiftwidth') │
17 " │┌────────────────────────────────────────────────────────────┐│
18 " ││ ││
19 " │└────────────────────────────────────────────────────────────┘│
20 " │──────────────────────────────────────────────────────────────│
21 " │ Ok Cancel│
22 " └──────────────────────────────────────────────────────────────┘
23
24 " parameters:
25 " texlines : List of static text to be displayed
26 " or string with text separated by '\n'
27 " initialtext : optional initial text value
28 " ------------------------------------------------------------
29 " forms#dialog#input#Make: {{{1
30 function! forms#dialog#input#Make(textlines, ...)
31 " call forms#log("forms#dialog#input#Make")
32 if type(a:textlines) == g:self#LIST_TYPE
33 let textlines = a:textlines
34 elseif type(a:textlines) == g:self#STRING_TYPE
35 let textlines = split(a:textlines, '\n')
36 else
37 throw "forms#dialog#input#Make: textlines parameter must be list of text: " . string(a:textlines)
38 endif
39 let outputtag = 'output'
40 let text = forms#newText({'textlines': textlines })
41 let size = 20
42 for line in textlines
43 let len = len(line)
44 if len > size
45 let size = len
46 endif
47 endfor
48 let vfield = forms#newVariableLengthField({'size': size,
49 \ 'tag': outputtag
50 \ })
51 function! vfield.purpose() dict
52 return [
53 \ "Enter the requested information."
54 \ ]
55 endfunction
56 if a:0 > 0 && a:1 != ''
57 call vfield.setText(a:1)
58 endif
59
60 let box = forms#newBox({ 'body': vfield} )
61 let char = (&encoding == 'utf-8')
663261ff » megaannum
2012-10-27 made all character variables globals rather than per-buffer.
62 \ ? g:forms_BDLightHorizontal
63 \ : g:forms_horz
4c5e6d4c » megaannum
2012-07-27 first commit
64 let hline = forms#newHLine({'char': char})
65
66 let oklabel = forms#newLabel({'text': "Ok"})
67 let ok = forms#newButton({
68 \ 'tag': 'submit',
69 \ 'body': oklabel,
70 \ 'action': g:forms#submitAction})
71 function! ok.purpose() dict
72 return [
73 \ "Accept the entered information."
74 \ ]
75 endfunction
76 let hspace = forms#newHSpace({'size': 1})
77 let cancellabel = forms#newLabel({'text': "Cancel"})
78 let cancel = forms#newButton({
79 \ 'tag': 'cancel',
80 \ 'body': cancellabel,
81 \ 'action': g:forms#cancelAction})
82 function! cancel.purpose() dict
83 return [
84 \ "Cancel the operation, nothing is returned."
85 \ ]
86 endfunction
87 let buttons = forms#newHPoly({ 'children': [ok, hspace, cancel]})
88
89 let vpoly = forms#newVPoly({ 'children': [text, box, hline, buttons], 'alignment': 'R' })
90
91 let b = forms#newBox({ 'body': vpoly })
92 let bg = forms#newBackground({ 'body': b} )
93 let form = forms#newForm({'body': bg })
94 function! form.purpose() dict
95 return [
96 \ "Request input from the user."
97 \ ]
98 endfunction
99 let results = form.run()
100 " call forms#log("forms#dialog#input#Make: results=".string(results))
101 if exists("results.output")
102 return results.output
103 else
104 return ''
105 endif
106 endfunction
107
ee21b40b » megaannum
2012-08-13 Better support for both 'light' and 'dard' backgrounds.
108 " forms#dialog#input#MakeTest: {{{1
109 function! forms#dialog#input#MakeTest()
110 call forms#AppendInput({'type': 'Sleep', 'time': 5})
111 call forms#AppendInput({'type': 'Exit'})
112 let textlines = "User should add requested input.\n\nCan be on multiple lines."
113 call forms#dialog#input#Make(textlines, 'some initial text')
114 endfunction
115
4c5e6d4c » megaannum
2012-07-27 first commit
116 " Modelines: {{{1
117 " ================
118 " vim: ts=4 fdm=marker
Something went wrong with that request. Please try again.