Class: Redcar::ApplicationSWT::FilterListDialogController
- Inherits:
-
Object
- Object
- Redcar::ApplicationSWT::FilterListDialogController
show all
- Includes:
- ReentryHelpers
- Defined in:
- plugins/application_swt/lib/application_swt/dialogs/filter_list_dialog_controller.rb
Defined Under Namespace
Classes: FilterListDialog, KeyListener, ModifyListener, SelectionListener, ShellListener
Class Attribute Summary (collapse)
Instance Attribute Summary (collapse)
Class Method Summary
(collapse)
Instance Method Summary
(collapse)
#ignore, #ignore_changes
Constructor Details
A new instance of FilterListDialogController
76
77
78
79
80
81
82
83
84
85
|
# File 'plugins/application_swt/lib/application_swt/dialogs/filter_list_dialog_controller.rb', line 76
def initialize(model)
@model = model
@dialog = FilterListDialog.new(Redcar.app.focussed_window.controller.shell)
@dialog.controller = self
if FilterListDialogController.test_mode?
@dialog.setBlockOnOpen(false)
@dialog.setShellStyle(Swt::SWT::DIALOG_TRIM)
end
attach_model_listeners
end
|
Class Attribute Details
+ (Object) test_mode=(value)
when set, the FilterListDialog is non-modal for testing
8
9
10
|
# File 'plugins/application_swt/lib/application_swt/dialogs/filter_list_dialog_controller.rb', line 8
def test_mode=(value)
@test_mode = value
end
|
Instance Attribute Details
Returns the value of attribute dialog
74
75
76
|
# File 'plugins/application_swt/lib/application_swt/dialogs/filter_list_dialog_controller.rb', line 74
def dialog
@dialog
end
|
Returns the value of attribute model
74
75
76
|
# File 'plugins/application_swt/lib/application_swt/dialogs/filter_list_dialog_controller.rb', line 74
def model
@model
end
|
Class Method Details
66
67
68
69
70
71
72
|
# File 'plugins/application_swt/lib/application_swt/dialogs/filter_list_dialog_controller.rb', line 66
def self.storage
@storage ||= begin
storage = Plugin::Storage.new('filter_list_dialog_controller')
storage.set_default('pause_before_update_seconds', 0.25)
storage
end
end
|
+ (Boolean) test_mode?
9
|
# File 'plugins/application_swt/lib/application_swt/dialogs/filter_list_dialog_controller.rb', line 9
def test_mode?; @test_mode; end
|
Instance Method Details
- (Object) attach_listeners
130
131
132
133
134
|
# File 'plugins/application_swt/lib/application_swt/dialogs/filter_list_dialog_controller.rb', line 130
def attach_listeners
@dialog.text.add_modify_listener(ModifyListener.new(self))
@dialog.text.add_key_listener(KeyListener.new(self))
@dialog.list.add_selection_listener(SelectionListener.new(self))
end
|
- (Object) attach_model_listeners
87
88
89
90
|
# File 'plugins/application_swt/lib/application_swt/dialogs/filter_list_dialog_controller.rb', line 87
def attach_model_listeners
@model.add_listener(:open, &method(:open))
@model.add_listener(:close, &method(:close))
end
|
141
142
143
144
145
|
# File 'plugins/application_swt/lib/application_swt/dialogs/filter_list_dialog_controller.rb', line 141
def close
@dialog.close
ApplicationSWT.unregister_dialog(@dialog)
@dialog = nil
end
|
- (Object) key_pressed(key_event)
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
# File 'plugins/application_swt/lib/application_swt/dialogs/filter_list_dialog_controller.rb', line 206
def key_pressed(key_event)
case key_event.keyCode
when Swt::SWT::CR, Swt::SWT::LF
selected
false
when Swt::SWT::ARROW_DOWN
move_down
false
when Swt::SWT::ARROW_UP
move_up
false
else
true
end
end
|
- (Object) move_down
222
223
224
|
# File 'plugins/application_swt/lib/application_swt/dialogs/filter_list_dialog_controller.rb', line 222
def move_down
move_selection(1, @dialog.list.get_item_count - 1)
end
|
- (Object) move_selection(step, border)
230
231
232
233
234
235
236
|
# File 'plugins/application_swt/lib/application_swt/dialogs/filter_list_dialog_controller.rb', line 230
def move_selection(step, border)
curr_ix = @dialog.list.get_selection_index
new_ix = curr_ix + step
new_ix = border if (new_ix <=> border) == step
@dialog.list.set_selection(new_ix)
widget_selected
end
|
226
227
228
|
# File 'plugins/application_swt/lib/application_swt/dialogs/filter_list_dialog_controller.rb', line 226
def move_up
move_selection(-1, 0)
end
|
136
137
138
139
|
# File 'plugins/application_swt/lib/application_swt/dialogs/filter_list_dialog_controller.rb', line 136
def open
@dialog.open
@dialog = nil unless FilterListDialogController.test_mode?
end
|
- (Object) populate_list(contents)
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
# File 'plugins/application_swt/lib/application_swt/dialogs/filter_list_dialog_controller.rb', line 238
def populate_list(contents)
@list = contents
if @dialog
@dialog.list.remove_all
contents.each do |props|
if props.is_a?(String)
props = {:name => props}
end
props = {:name => ""}.merge(props)
item = Swt::Widgets::TableItem.new(@dialog.list, Swt::SWT::NONE)
item.text = props[:name]
image = ApplicationSWT::Icon.swt_image(props[:icon]) if props[:icon]
if image
item.image = image
end
end
end
end
|
- (Boolean) select_closest_match?
196
197
198
|
# File 'plugins/application_swt/lib/application_swt/dialogs/filter_list_dialog_controller.rb', line 196
def select_closest_match?
@dialog.list.get_selection_index == 0
end
|
- (Object) selected
200
201
202
203
204
|
# File 'plugins/application_swt/lib/application_swt/dialogs/filter_list_dialog_controller.rb', line 200
def selected
wait_for_search if select_closest_match?
ix = @dialog.list.get_selection_index
@model.selected(@list[ix], ix)
end
|
- (Object) text_focus
188
189
190
|
# File 'plugins/application_swt/lib/application_swt/dialogs/filter_list_dialog_controller.rb', line 188
def text_focus
@dialog.text.set_focus
end
|
- (Object) update_list
147
148
149
150
151
152
153
154
155
156
|
# File 'plugins/application_swt/lib/application_swt/dialogs/filter_list_dialog_controller.rb', line 147
def update_list
@last_keypress = Time.now
pause_time = FilterListDialogController.storage['pause_before_update_seconds']
Swt::Widgets::Display.getCurrent.timerExec(pause_time*1000, Swt::RRunnable.new {
if @last_keypress and (Time.now - @last_keypress + pause_time) > pause_time
@last_keypress = nil
update_list_sync
end
})
end
|
- (Object) update_list_sync
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
# File 'plugins/application_swt/lib/application_swt/dialogs/filter_list_dialog_controller.rb', line 158
def update_list_sync
if @dialog
s = Time.now
dialog = @dialog
this = self
Thread.new(@dialog.text.get_text) do |text|
begin
list = @model.update_list(text)
Redcar.update_gui do
this.populate_list(list)
if this.dialog
this.dialog.list.set_selection(0)
this.text_focus
end
end
rescue => e
puts e.message
puts e.backtrace
end
end
end
end
|
- (Object) wait_for_search
192
193
194
|
# File 'plugins/application_swt/lib/application_swt/dialogs/filter_list_dialog_controller.rb', line 192
def wait_for_search
@update_thread.join unless @update_thread.nil?
end
|
181
182
183
184
185
186
|
# File 'plugins/application_swt/lib/application_swt/dialogs/filter_list_dialog_controller.rb', line 181
def widget_selected
if @model.step?
ix = @dialog.list.get_selection_index
@model.moved_to(@list[ix], ix)
end
end
|