foxguib 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/changelog.txt +128 -0
  4. data/doc/www/index.html +173 -0
  5. data/doc/www/upload.rb +9 -0
  6. data/examples/event_handler.rb +67 -0
  7. data/examples/event_handlers.rbin +0 -0
  8. data/examples/guib_testdialog.rb +31 -0
  9. data/examples/testdialog.rb +29 -0
  10. data/exe/foxguib +1 -0
  11. data/foxGUIb-debug.rb +37 -0
  12. data/foxGUIb.rb +88 -0
  13. data/foxGUIb_win32.rbw +1 -0
  14. data/foxguib.gemspec +26 -0
  15. data/license.txt +49 -0
  16. data/readme.txt +1 -0
  17. data/release_notes.txt +68 -0
  18. data/src/assert.rb +8 -0
  19. data/src/cfgman.rb +27 -0
  20. data/src/code-gen/code-generator.rb +171 -0
  21. data/src/code-gen/property-generators.rb +65 -0
  22. data/src/code-gen/widget-generator.rb +22 -0
  23. data/src/convert.rb +60 -0
  24. data/src/direct_widget_manipulation.rb +343 -0
  25. data/src/docman.rb +260 -0
  26. data/src/document.rb +405 -0
  27. data/src/event_categories.yaml +85 -0
  28. data/src/event_listener.rb +57 -0
  29. data/src/events.yaml +77 -0
  30. data/src/events_docu.yaml +228 -0
  31. data/src/get_events.rb +64 -0
  32. data/src/gui/ArrowButton.tga +0 -0
  33. data/src/gui/BoxMinus.tga +0 -0
  34. data/src/gui/BoxPlus.tga +0 -0
  35. data/src/gui/Button.tga +0 -0
  36. data/src/gui/CheckButton.tga +0 -0
  37. data/src/gui/ComboBox.tga +0 -0
  38. data/src/gui/Dial.tga +0 -0
  39. data/src/gui/GroupBox.tga +0 -0
  40. data/src/gui/HorizontalFrame.tga +0 -0
  41. data/src/gui/HorizontalSeparator.tga +0 -0
  42. data/src/gui/Label.tga +0 -0
  43. data/src/gui/MDIChild.tga +0 -0
  44. data/src/gui/MDIClient.tga +0 -0
  45. data/src/gui/Matrix.tga +0 -0
  46. data/src/gui/MenuCaption.tga +0 -0
  47. data/src/gui/MenuCascade.tga +0 -0
  48. data/src/gui/MenuCheck.tga +0 -0
  49. data/src/gui/MenuCommand.tga +0 -0
  50. data/src/gui/MenuPane.tga +0 -0
  51. data/src/gui/MenuRadio.tga +0 -0
  52. data/src/gui/MenuSeparator.tga +0 -0
  53. data/src/gui/MenuTitle.tga +0 -0
  54. data/src/gui/Menubar.tga +0 -0
  55. data/src/gui/Packer.tga +0 -0
  56. data/src/gui/ProgressBar.tga +0 -0
  57. data/src/gui/RadioButton.tga +0 -0
  58. data/src/gui/RadioMutex.tga +0 -0
  59. data/src/gui/ScrollWindow.tga +0 -0
  60. data/src/gui/Scrollbar.tga +0 -0
  61. data/src/gui/Shutter.tga +0 -0
  62. data/src/gui/ShutterItem.tga +0 -0
  63. data/src/gui/Slider.tga +0 -0
  64. data/src/gui/Spinner.tga +0 -0
  65. data/src/gui/Splitter.tga +0 -0
  66. data/src/gui/StatusBar.tga +0 -0
  67. data/src/gui/Statusline.tga +0 -0
  68. data/src/gui/Switcher.tga +0 -0
  69. data/src/gui/TabBar.tga +0 -0
  70. data/src/gui/TabBook.tga +0 -0
  71. data/src/gui/TabItem.tga +0 -0
  72. data/src/gui/Text.tga +0 -0
  73. data/src/gui/TextField.tga +0 -0
  74. data/src/gui/ToggleButton.tga +0 -0
  75. data/src/gui/Toolbar.tga +0 -0
  76. data/src/gui/VerticalFrame.tga +0 -0
  77. data/src/gui/VerticalSeparator.tga +0 -0
  78. data/src/gui/_guib_event_editor.rb +185 -0
  79. data/src/gui/_guib_event_editor.rbin +0 -0
  80. data/src/gui/_guib_genruby.rb +414 -0
  81. data/src/gui/_guib_genruby.rbin +0 -0
  82. data/src/gui/_guib_mainwin.rb +574 -0
  83. data/src/gui/_guib_mainwin.rbin +0 -0
  84. data/src/gui/event_editor.rb +180 -0
  85. data/src/gui/genruby.rb +155 -0
  86. data/src/gui/guib__console.rb +265 -0
  87. data/src/gui/mainwin.rb +71 -0
  88. data/src/gui/ruby_console.rb +263 -0
  89. data/src/gui/svg/Matrix.svg +87 -0
  90. data/src/gui/svg/MenuCheck.svg +135 -0
  91. data/src/gui/svg/MenuRadio.svg +130 -0
  92. data/src/gui/svg/RadioMutex.svg +119 -0
  93. data/src/gui/textview.rb +101 -0
  94. data/src/gui/textview.rbin +0 -0
  95. data/src/minitest.rb +60 -0
  96. data/src/prop-lists.rb +323 -0
  97. data/src/prop-types.rb +606 -0
  98. data/src/properties.rb +119 -0
  99. data/src/propman.rb +88 -0
  100. data/src/relink_mechanisms.rb +95 -0
  101. data/src/serialize.rb +167 -0
  102. data/src/state_machine.rb +73 -0
  103. data/src/version.rb +6 -0
  104. data/src/widget-lists.rb +118 -0
  105. data/src/widget-selector.rb +85 -0
  106. data/src/widgettree-controls.rb +183 -0
  107. data.tar.gz.sig +0 -0
  108. metadata +236 -0
  109. metadata.gz.sig +0 -0
@@ -0,0 +1,343 @@
1
+ # Copyright (c) 2004-2006 by Henon (meinrad dot recheis at gmail dot com)
2
+
3
+ require "libGUIb16"
4
+ require "fox16"
5
+ require "state_machine"
6
+ require "event_listener"
7
+ require "relink_mechanisms"
8
+
9
+ module DirectWidgetManipulation
10
+ include Fox
11
+
12
+ KEY_MODS = {
13
+ "SHIFT" => 1,
14
+ "CAPSLOCK" => 2,
15
+ "CTRL" => 4,
16
+ "ALT" => 8,
17
+ "NUM" => 16,
18
+ "ROLL" => 224
19
+ }
20
+ KEY_CODES = {
21
+ "CURSOR_UP" => 65362,
22
+ "CURSOR_LEFT" => 65361,
23
+ "CURSOR_DOWN" => 65364,
24
+ "CURSOR_RIGHT" => 65363
25
+ }
26
+ KEY_CODES.each { |k, v| eval "#{k}=#{v}" }
27
+ KEY_MODS.each { |k, v| eval "#{k}=#{v}" }
28
+
29
+ __sends__ "event_MOTION", "event_LEAVE", "event_ENTER", "event_LEFTBUTTONPRESS", "event_LEFTBUTTONRELEASE"
30
+ __sends__ "event_KEYPRESS", "event_KEYRELEASE"
31
+ attr_accessor :do_hover, :do_relink, :do_select
32
+ $hovered_widgets = []
33
+ $selected_widgets = []
34
+ SELECT_COLOR = Fox::FXRGB(255, 0, 0)
35
+ CURSOR_COLOR = Fox::FXRGB(255, 0, 0)
36
+ HOVER_COLOR = Fox::FXRGB(100, 120, 255)
37
+ FRAMESTYLE_METHODS = {
38
+ "hiliteColor" => SELECT_COLOR,
39
+ "shadowColor" => SELECT_COLOR,
40
+ "borderColor" => SELECT_COLOR,
41
+ "frameStyle" => FRAME_LINE | FRAME_THICK
42
+ }
43
+ HOVER_METHODS = {
44
+ "backColor" => HOVER_COLOR
45
+ }
46
+
47
+ def setup_drag_statemachine
48
+ @do_hover = true
49
+ @do_relink = true
50
+ @do_select = true
51
+ @drag_SM = StateMachine.new
52
+ states = [
53
+ idle = State.new("IDLE"),
54
+ lmbdown = State.new("LMBDOWN"),
55
+ dragging = State.new("DRAGGING")
56
+ ]
57
+ @drag_SM.add_states(*states)
58
+ action = proc {|o, n| # puts "#{o}-->#{n}"
59
+ }
60
+ @drag_SM.state_transition(idle, lmbdown,
61
+ proc { |o, n| o.input["event_name"] == SEL_LEFTBUTTONPRESS },
62
+ action)
63
+ @drag_SM.state_transition(lmbdown, idle,
64
+ proc { |o, n| o.input["event_name"] == SEL_LEFTBUTTONRELEASE },
65
+ proc { |o, n| # puts "#{o}-->#{n}"
66
+ extended_select
67
+ })
68
+ @drag_SM.state_transition(lmbdown, dragging,
69
+ proc { |o, n| o.input["event_name"] == SEL_MOTION },
70
+ a = proc { |o, n| n[:last_time] = Time.now })
71
+ @drag_SM.state_transition(dragging, dragging,
72
+ proc { |o, n|
73
+ t = o[:last_time]
74
+ o.input["event_name"] == SEL_MOTION and (Time.now.to_f - t.to_f) > 0.1
75
+ },
76
+ proc { |o, n|
77
+ n[:last_time] = Time.now
78
+ break unless @do_relink
79
+ e = o.input["event"]
80
+ dest = shell.get_widget_at(translateCoordinatesTo(shell, e.win_x, e.win_y))
81
+ # p dest
82
+ dest.hover if RelinkMechanisms.mouse_relink_test(self, dest) and dest.respond_to? :hover
83
+ })
84
+ @drag_SM.state_transition(dragging, idle,
85
+ proc { |o, n| o.input["event_name"] == SEL_LEFTBUTTONRELEASE },
86
+ proc { |o, n|
87
+ n[:last_time] = Time.now
88
+ break unless @do_relink
89
+ e = o.input["event"]
90
+ dest = shell.get_widget_at(translateCoordinatesTo(shell, e.win_x, e.win_y))
91
+ # p dest
92
+ RelinkMechanisms.mouse_relink(self, dest)
93
+ })
94
+ @drag_SM.start
95
+ end
96
+
97
+ def hover(*args)
98
+ return if !@do_hover or @hovered
99
+ @hovered = true
100
+ $hovered_widgets.each { |w| w.unhover }
101
+ $hovered_widgets << self
102
+ HOVER_METHODS.each { |method, value|
103
+ eval "@_#{method}=self.#{method}" if respond_to? method
104
+ eval "self.#{method}=#{value}" if respond_to? method + "="
105
+ }
106
+ end
107
+
108
+ def unhover(*args)
109
+ return if !@do_hover or !@hovered or @drag_SM.state.to_s == "DRAGGING"
110
+ @hovered = false
111
+ $hovered_widgets.delete self
112
+ HOVER_METHODS.each { |method, value|
113
+ eval "self.#{method}=@_#{method}" if respond_to? method + "="
114
+ }
115
+ end
116
+
117
+ def deselect_all
118
+ $selected_widgets.dup.each { |w| w.deselect }
119
+ end
120
+
121
+ def extended_select
122
+ deselect_all unless $CTRL
123
+ @selected ? deselect(recursive: true) : select(recursive: true)
124
+ end
125
+
126
+ def select(params = {})
127
+ return if !@do_select or @selected
128
+ $selected_widgets << self
129
+ @selected = true
130
+ FRAMESTYLE_METHODS.each { |method, value|
131
+ eval "@_#{method}=self.#{method}" if respond_to? method
132
+ eval "self.#{method}=#{value}" if respond_to? method + "="
133
+ }
134
+ if $SHIFT and params[:recursive]
135
+ children.each { |w| w.select(params) if w.respond_to? :select }
136
+ end
137
+ end
138
+
139
+ def deselect(params = {})
140
+ return if !@do_select or !@selected
141
+ $selected_widgets.delete self
142
+ @selected = false
143
+ FRAMESTYLE_METHODS.each { |method, value|
144
+ eval "self.#{method}=@_#{method}" if respond_to? method + "="
145
+ }
146
+ if $SHIFT and params[:recursive]
147
+ children.each { |w| w.deselect(params) if w.respond_to? :deselect }
148
+ end
149
+ end
150
+
151
+ def edit_mode
152
+ multiplex_mouse_events!
153
+ observe_keymods!
154
+ self.enabled = true
155
+ setup_drag_statemachine
156
+ @em_leave = on_event_LEAVE { |sender, selector, event| unhover }
157
+ @em_motion = on_event_MOTION { |sender, selector, event|
158
+ hover
159
+ @drag_SM.input "event_name" => SEL_MOTION, "event" => event
160
+ }
161
+ @em_lbpress = on_event_LEFTBUTTONPRESS { |sender, selector, event|
162
+ @drag_SM.input "event_name" => SEL_LEFTBUTTONPRESS, "event" => event
163
+ }
164
+ @em_lbrelease = on_event_LEFTBUTTONRELEASE { |sender, selector, event|
165
+ @drag_SM.input "event_name" => SEL_LEFTBUTTONRELEASE, "event" => event
166
+ }
167
+ multiplex_keyboard_events!
168
+ @em_keypress = on_event_KEYPRESS { |sender, selector, event|
169
+ RelinkMechanisms.keyboard_relink($selected_widgets[0], event)
170
+ }
171
+ end
172
+
173
+ def disable_edit_mode
174
+ del_event_LEAVE @em_leave
175
+ del_event_MOTION @em_motion
176
+ del_event_LEFTBUTTONRELEASE @em_lbrelease
177
+ del_event_LEFTBUTTONPRESS @em_lbpress
178
+ del_event_KEYPRESS @em_keypress
179
+ $hovered_widgets.each { |w| w.unhover }
180
+ deselect_all
181
+ @drag_SM = nil
182
+ end
183
+
184
+ def insert_mode
185
+ self.enabled = true
186
+ multiplex_mouse_events!
187
+ observe_keymods!
188
+ @im_keypress = on_event_KEYPRESS { |sender, selector, event|
189
+ $insert_cursor.children[0].backColor = CURSOR_COLOR
190
+ RelinkMechanisms.keyboard_relink($insert_cursor, event)
191
+ update_cursor
192
+ }
193
+ @im_lbpress = on_event_LEFTBUTTONPRESS { |sender, selector, event|
194
+ $insert_cursor.children[0].backColor = CURSOR_COLOR
195
+ RelinkMechanisms.mouse_relink $insert_cursor, self
196
+ update_cursor
197
+ }
198
+ unless $insert_cursor
199
+ $insert_cursor = Fox::FXPacker.new(shell)
200
+ inside = Fox::FXFrame.new($insert_cursor)
201
+ $insert_cursor.create if $fxapp.created?
202
+ $insert_cursor.pad(2, 2, 2, 2)
203
+ inside.pad(1, 1, 1, 1)
204
+ inside.frameStyle = $insert_cursor.frameStyle = 0
205
+ timeout = proc { |sender, sel, data|
206
+ inside.backColor = if inside.backColor == CURSOR_COLOR
207
+ $insert_cursor.backColor
208
+ else
209
+ CURSOR_COLOR
210
+ end
211
+ $cursor_timer = $fxapp.addTimeout(500, &timeout)
212
+ }
213
+ $cursor_timer = $fxapp.addTimeout(500, &timeout)
214
+ update_cursor
215
+ end
216
+ end
217
+
218
+ def disable_insert_mode
219
+ del_event_LEFTBUTTONPRESS @im_lbpress
220
+ del_event_KEYPRESS @im_keypress
221
+ if $cursor_timer
222
+ $fxapp.removeTimeout($cursor_timer)
223
+ $cursor_timer = nil
224
+ end
225
+ if $insert_cursor
226
+ p = $insert_cursor.parent
227
+ $insert_cursor.destroy
228
+ p.recalc
229
+ end
230
+ $insert_cursor = nil
231
+ end
232
+
233
+ def update_cursor
234
+ $insert_cursor.children[0].layoutHints = $insert_cursor.layoutHints = $insert_cursor.parent.is_a? Fox::FXHorizontalFrame ?
235
+ LAYOUT_FILL_Y
236
+ :
237
+ LAYOUT_FILL_X
238
+
239
+ $insert_cursor.backColor = $insert_cursor.parent.backColor
240
+ end
241
+ # ~ def deactivate_mode
242
+ # ~ # maybe there is a better way to "unconnect"?
243
+ # ~ connect(SEL_MOTION){0}
244
+ # ~ connect(SEL_ENTER){0}
245
+ # ~ connect(SEL_LEAVE){0}
246
+ # ~ connect(SEL_LEFTBUTTONPRESS){0}
247
+ # ~ connect(SEL_LEFTBUTTONRELEASE){0}
248
+ # ~ connect(SEL_KEYPRESS){0}
249
+ # ~ connect(SEL_KEYRELEASE){0}
250
+ # ~ end
251
+ end
252
+
253
+ class Fox::FXWindow
254
+ include DirectWidgetManipulation
255
+ def get_widget_at pos
256
+ # puts "-\t#{self.class}"
257
+ child = getChildAt(*pos)
258
+ if child.nil?
259
+ self
260
+ elsif child.composite?
261
+ child.get_widget_at(translateCoordinatesTo(child, pos[0], pos[1]))
262
+ else
263
+ child
264
+ end
265
+ end
266
+
267
+ def multiplex_mouse_events!
268
+ connect(SEL_LEAVE) { |sender, selector, event|
269
+ event_LEAVE(sender, selector, event)
270
+ 0
271
+ }
272
+ connect(SEL_MOTION) { |sender, selector, event|
273
+ event_MOTION(sender, selector, event)
274
+ 0
275
+ }
276
+ connect(SEL_LEFTBUTTONPRESS) { |sender, selector, event|
277
+ event_LEFTBUTTONPRESS(sender, selector, event)
278
+ 0
279
+ }
280
+ connect(SEL_LEFTBUTTONRELEASE) { |sender, selector, event|
281
+ event_LEFTBUTTONRELEASE(sender, selector, event)
282
+ 0
283
+ }
284
+ end
285
+
286
+ def multiplex_keyboard_events!
287
+ connect(SEL_KEYPRESS) { |sender, selector, event|
288
+ event_KEYPRESS(sender, selector, event)
289
+ 1
290
+ }
291
+ connect(SEL_KEYRELEASE) { |sender, selector, event|
292
+ event_KEYRELEASE(sender, selector, event)
293
+ 1
294
+ }
295
+ end
296
+
297
+ # listen to keyboard modifiers such as CTRL, SHIFT, etc.
298
+ # and set flags: $CTRL, $SHIFT, etc
299
+ def observe_keymods!
300
+ multiplex_keyboard_events!
301
+ on_event_KEYPRESS { |sender, selector, event|
302
+ # puts event.state
303
+ KEY_MODS.each { |mod, value|
304
+ eval("$#{mod}=true if !$#{mod}") if event.state & value == value
305
+ }
306
+ # p [$CTRL, $SHIFT, $ALT]
307
+ }
308
+ on_event_KEYRELEASE { |sender, selector, event|
309
+ KEY_MODS.each { |mod, value|
310
+ eval("$#{mod}=nil if $#{mod}") if event.state & value == 0
311
+ }
312
+ }
313
+ end
314
+ end
315
+
316
+ if __FILE__ == $0
317
+ $stdout.sync = true
318
+ include Fox
319
+ #==================================
320
+ app = FX::App.new "", ""
321
+ mw = FX::MainWindow.new app
322
+ mw.pad(10, 10, 10, 10)
323
+ lb = FX::Label.new mw
324
+ hf = FX::HorizontalFrame.new mw, FRAME_LINE
325
+ btn = FX::Button.new hf
326
+ hf = FX::GroupBox.new hf
327
+ btn = FX::Button.new hf
328
+ mw.recursive { |w|
329
+ w.edit_mode
330
+ }
331
+ btn.connect(SEL_COMMAND) {
332
+ mw.recursive { |w|
333
+ w.disable_edit_mode
334
+ w.insert_mode
335
+ }
336
+ }
337
+ btn.text = "click to change to insert mode"
338
+ mw.show
339
+ mw.observe_keymods!
340
+ app.create
341
+ app.run
342
+ #==================================
343
+ end
data/src/docman.rb ADDED
@@ -0,0 +1,260 @@
1
+ # Copyright (c) 2004-2006 by Henon (meinrad dot recheis at gmail dot com)
2
+ require "singleton"
3
+ require "document"
4
+ require "genruby"
5
+ class DocMan
6
+ include Singleton
7
+ def initialize
8
+ @docs = []
9
+ @doc_hash = {}
10
+ @parent = MAINWIN.topwin
11
+ # @new_project_dlg.topwin.hide
12
+ @genruby_dlg = GenRubyDialog.new @parent
13
+ create_docman
14
+ update
15
+ end
16
+ attr_reader :current, :docs, :doc_hash
17
+ def ask_save
18
+ # TODO
19
+ end
20
+
21
+ def genruby
22
+ # puts "genruby_dlg"
23
+ @genruby_dlg.show
24
+ end
25
+
26
+ def set_wdir
27
+ dirdlg = FXDirDialog.new @parent, "select the working directory"
28
+ if dirdlg.execute == 1
29
+ wdir = dirdlg.directory.tr("\\", "/")
30
+ Dir.chdir wdir
31
+ puts "changed working dir to: " + wdir
32
+ end
33
+ end
34
+
35
+ def add_widget classname, where = "after"
36
+ @current.add_widget(classname, where) if @current
37
+ end
38
+
39
+ def create doctype
40
+ # ~ @current.dlg.hide if @current
41
+ # @current.topwin.hide if @current
42
+ doc = Document.new doctype
43
+ @docs << doc
44
+ doc.name = "unnamed_" + doctype + ".rbin"
45
+ tab = create_tab(doc)
46
+ switch_documents(nil, nil, tab.index)
47
+ update
48
+ doc.topwin.resize(500, 400)
49
+ end
50
+
51
+ def close_all
52
+ # TODO: ask save
53
+ @docs.each { |doc|
54
+ close(doc, true, false)
55
+ }
56
+ end
57
+
58
+ def close(doc = @current, save = true, update_gui = true)
59
+ return unless doc
60
+ # TODO: ask save if @current.dirty and save==true
61
+ doc.doclist_item.hide
62
+ @tabbar.recalc
63
+ @tabbar.forceRefresh
64
+ doc.doclist_item.destroy # tabitem removed
65
+ doc.topwin.destroy # dialog removed
66
+ MAINWIN.Switcher.children[doc.switcherIndex].destroy # treelist removed
67
+ @docs.delete doc # document removed
68
+ if update_gui
69
+ @current = @docs[@docs.size - 1]
70
+ switch
71
+ update
72
+ end
73
+ end
74
+
75
+ def switch
76
+ if @current
77
+ MAINWIN.Switcher.current = @current.switcherIndex
78
+ else
79
+ # MAINWIN.Switcher.current=0
80
+ # ???
81
+ end
82
+ return unless @current and @current.marked
83
+ # @genruby_dlg.topwin.hide
84
+ @genruby_dlg.show if @genruby_dlg.topwin.shown? # update genruby dlg
85
+ @current.marked.update_properties
86
+ EventEditor.instance.set_widget(@current.marked)
87
+ end
88
+
89
+ def switch_documents(*args)
90
+ index = args[2]
91
+ if index.is_a? Integer
92
+ tabitem = @tabbar.children[index]
93
+ e = @doc_hash[tabitem]
94
+ @current.topwin.hide if @current
95
+ e.topwin.show(0)
96
+ @current = e
97
+ # event_document_switched @current
98
+ end
99
+ switch
100
+ end
101
+
102
+ def load(filename=nil)
103
+ filename ||= SuperFileDialog.new(@parent, "", "load foxGUIb document").start
104
+ if filename
105
+ # ~ @current.dlg.hide if @current
106
+ # @current.topwin.hide if @current
107
+ doc = Document.new nil
108
+ doc.load filename
109
+ @docs << doc
110
+ # ~ @list.appendItem filename
111
+ # ~ @current.doclist_item=@list.numItems-1
112
+ tab = create_tab(doc)
113
+ switch_documents nil, nil, tab.index
114
+ end
115
+ update
116
+ end
117
+
118
+ def save
119
+ return unless @current
120
+ @current.save @current.name
121
+ end
122
+
123
+ def save_as
124
+ return unless @current
125
+ filename = SuperFileDialog.new(@parent, @current.name, "save foxGUIb document").start
126
+ return unless filename
127
+ @current.save filename
128
+ @current.doclist_item.text = filename
129
+ @current.name = filename
130
+ end
131
+
132
+ def save_all
133
+ @docs.each { |doc|
134
+ doc.save doc.name
135
+ }
136
+ end
137
+
138
+ def emergency_save
139
+ @docs.each { |doc|
140
+ doc.save doc.name + "_failsave.rbin"
141
+ }
142
+ end
143
+
144
+ def generate opts, classname, unittest
145
+ if opts == "ruby.class"
146
+ dlg = RubyFileDialog.new @parent, @current.name, "save generated ruby code"
147
+ filename = dlg.start
148
+ return unless filename
149
+ $fxapp.beginWaitCursor {
150
+ s = @current.generate_code opts, @current.fxtree.currentItem, classname, unittest
151
+ f = File.new(filename, "w")
152
+ f.puts s
153
+ f.close
154
+ }
155
+ end
156
+ end
157
+
158
+ def generate_code opts, item, classname = nil, unittest = true
159
+ return unless @current
160
+ # rd,wr=IO.pipe
161
+ @current.generate_code opts, item, classname, unittest
162
+ # wr.flush
163
+ # wr.close
164
+ # rd.read
165
+ end
166
+
167
+ def set_dirty e
168
+ item = e.doclist_item
169
+ return unless item
170
+ item.text += " *"
171
+ end
172
+
173
+ def create_docman
174
+ @tabbar = MAINWIN.project_TabBar
175
+ @tabbar.connect SEL_COMMAND, method(:switch_documents)
176
+ end
177
+
178
+ def update
179
+ MAINWIN.genruby.enabled = (!@docs.empty?)
180
+ MAINWIN.save_dialog.enabled = (!@docs.empty?)
181
+ MAINWIN.save_dialog_as.enabled = (!@docs.empty?)
182
+ MAINWIN.close_dialog.enabled = (!@docs.empty?)
183
+ MAINWIN.viewDialog.enabled = (!@docs.empty?)
184
+ # MAINWIN.hideDialog.enabled=(not @docs.empty?)
185
+ if @docs.empty? and PropMan.created?
186
+ PropMan.instance.reset_props
187
+ end
188
+ if @current
189
+ @tabbar.setCurrent(@tabbar.children.index(@current.doclist_item))
190
+ end
191
+ @current.topwin.shown = true if @current
192
+ end
193
+
194
+ def create_tab doc
195
+ tab = @tabbar.create_tab(doc.name)
196
+ tab.backColor = STD_BACK_COLOR
197
+ tab.frameStyle = FRAME_LINE
198
+ tab.hiliteColor = FXRGB(0, 0, 0)
199
+ tab.create
200
+ doc.doclist_item = tab # todo: eliminate doclist_item!
201
+ @doc_hash[tab] = doc
202
+ tab
203
+ end
204
+ end
205
+
206
+ class SuperFileDialog
207
+ def initialize p, filename = "", title = "no title"
208
+ @dialog = FXFileDialog.new(p, title)
209
+ @dialog.directory = Dir.getwd
210
+ generate_patterns
211
+ @dialog.patternList = @patterns
212
+ @dialog.currentPattern = @currentPattern
213
+ @dialog.filename = filename.to_s
214
+ end
215
+
216
+ def generate_patterns
217
+ @patterns = ["All Files (*)",
218
+ "Fox-GUIb Documents (*.pp,*.rbin)",
219
+ "PrettyPrint Documents (*.pp)",
220
+ "Binary Documents (*.rbin)"]
221
+ @currentPattern = 1
222
+ end
223
+
224
+ def start
225
+ if @dialog.execute != 0
226
+ return rel_path(Dir.getwd, @dialog.filename)
227
+ end
228
+ nil
229
+ end
230
+ end
231
+
232
+ class RubyFileDialog < SuperFileDialog
233
+ def generate_patterns
234
+ @patterns = ["All Files (*)",
235
+ "Ruby Source Files (*.rb,*.rbw)"]
236
+ @currentPattern = 1
237
+ end
238
+ end
239
+
240
+ class IconDialog < SuperFileDialog
241
+ def generate_patterns
242
+ @patterns = ["All Files (*)",
243
+ "Images (*.gif,*.bmp,*.xpm,*.pcx,*.ico,*.png,*.jpg,*.tif,*.tga)",
244
+ "GIF Image (*.gif)",
245
+ "BMP Image (*.bmp)",
246
+ "XPM Image (*.xpm)",
247
+ "PCX Image (*.pcx)",
248
+ "ICO Image (*.ico)",
249
+ "PNG Image (*.png)",
250
+ "JPEG Image (*.jpg)",
251
+ "TIFF Image (*.tif)",
252
+ "TARGA Image (*.tga)"]
253
+ @currentPattern = 1
254
+ end
255
+ end
256
+
257
+ if __FILE__ == $0
258
+ puts rel_path("F:/hilo/djdk/df", "F:/hilo/djdk/df\\fgdfg")
259
+ puts rel_path("F:/hilo/djdk/df", "F:/hilo/asdf")
260
+ end