ruber 0.0.5 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. data/CHANGES +25 -0
  2. data/bin/ruber +0 -0
  3. data/data/share/apps/ruber/ruberui.rc +15 -1
  4. data/data/share/icons/{ruber.png → ruber-old.pgn} +0 -0
  5. data/lib/ruber/application/application.rb +216 -73
  6. data/lib/ruber/application/plugin.yaml +2 -2
  7. data/lib/ruber/document_project.rb +25 -5
  8. data/lib/ruber/documents/document_list.rb +11 -15
  9. data/lib/ruber/editor/document.rb +106 -50
  10. data/lib/ruber/editor/editor_view.rb +4 -2
  11. data/lib/ruber/external_program_plugin.rb +8 -0
  12. data/lib/ruber/kde_config_option_backend.rb +12 -4
  13. data/lib/ruber/kde_sugar.rb +35 -1
  14. data/lib/ruber/main_window/choose_plugins_dlg.rb +10 -10
  15. data/lib/ruber/main_window/hint_solver.rb +263 -0
  16. data/lib/ruber/main_window/main_window.rb +462 -206
  17. data/lib/ruber/main_window/main_window_actions.rb +228 -62
  18. data/lib/ruber/main_window/main_window_internal.rb +169 -115
  19. data/lib/ruber/main_window/plugin.yaml +13 -3
  20. data/lib/ruber/main_window/save_modified_files_dlg.rb +1 -1
  21. data/lib/ruber/main_window/ui/choose_plugins_widget.rb +1 -1
  22. data/lib/ruber/main_window/ui/main_window_settings_widget.rb +1 -1
  23. data/lib/ruber/main_window/ui/new_project_widget.rb +1 -1
  24. data/lib/ruber/main_window/ui/open_file_in_project_dlg.rb +1 -1
  25. data/lib/ruber/main_window/ui/output_color_widget.rb +1 -1
  26. data/lib/ruber/main_window/ui/workspace_settings_widget.rb +51 -0
  27. data/lib/ruber/main_window/ui/workspace_settings_widget.ui +28 -0
  28. data/lib/ruber/main_window/view_manager.rb +418 -0
  29. data/lib/ruber/main_window/workspace.png +0 -0
  30. data/lib/ruber/output_widget.rb +43 -37
  31. data/lib/ruber/pane.rb +621 -0
  32. data/lib/ruber/plugin_specification_reader.rb +8 -1
  33. data/lib/ruber/projects/project_files_list.rb +6 -0
  34. data/lib/ruber/projects/ui/project_files_rule_chooser_widget.rb +1 -1
  35. data/lib/ruber/projects/ui/project_files_widget.rb +1 -1
  36. data/lib/ruber/qt_sugar.rb +94 -4
  37. data/lib/ruber/utils.rb +16 -7
  38. data/lib/ruber/version.rb +2 -2
  39. data/plugins/autosave/autosave.rb +62 -1
  40. data/plugins/autosave/plugin.yaml +1 -0
  41. data/plugins/autosave/ui/autosave_config_widget.rb +37 -14
  42. data/plugins/autosave/ui/autosave_config_widget.ui +62 -12
  43. data/plugins/find_in_files/find_in_files_widgets.rb +1 -3
  44. data/plugins/find_in_files/ui/config_widget.rb +1 -1
  45. data/plugins/find_in_files/ui/find_in_files_widget.rb +1 -1
  46. data/plugins/rake/plugin.yaml +1 -1
  47. data/plugins/rake/ui/add_quick_task_widget.rb +1 -1
  48. data/plugins/rake/ui/choose_task_widget.rb +1 -1
  49. data/plugins/rake/ui/config_widget.rb +1 -1
  50. data/plugins/rake/ui/project_widget.rb +1 -1
  51. data/plugins/rspec/rspec.rb +14 -22
  52. data/plugins/rspec/ruber_rspec_formatter.rb +4 -1
  53. data/plugins/rspec/ui/rspec_project_widget.rb +1 -1
  54. data/plugins/ruby_development/plugin.yaml +7 -2
  55. data/plugins/ruby_development/ruby_development.rb +134 -13
  56. data/plugins/ruby_development/ui/config_widget.rb +66 -0
  57. data/plugins/ruby_development/ui/config_widget.ui +58 -0
  58. data/plugins/ruby_development/ui/project_widget.rb +1 -1
  59. data/plugins/ruby_runner/plugin.yaml +2 -2
  60. data/plugins/ruby_runner/ruby_runner.rb +15 -3
  61. data/plugins/ruby_runner/ui/config_widget.rb +1 -1
  62. data/plugins/ruby_runner/ui/project_widget.rb +1 -1
  63. data/plugins/ruby_runner/ui/ruby_runnner_plugin_option_widget.rb +1 -1
  64. data/plugins/state/plugin.yaml +6 -2
  65. data/plugins/state/state.rb +305 -81
  66. data/plugins/state/ui/config_widget.rb +1 -1
  67. data/spec/common.rb +11 -3
  68. data/spec/document_list_spec.rb +8 -8
  69. data/spec/document_project_spec.rb +98 -25
  70. data/spec/document_spec.rb +178 -152
  71. data/spec/editor_view_spec.rb +26 -5
  72. data/spec/framework.rb +5 -0
  73. data/spec/hint_solver_spec.rb +450 -0
  74. data/spec/kde_sugar_spec.rb +73 -6
  75. data/spec/output_widget_spec.rb +172 -156
  76. data/spec/pane_spec.rb +1165 -0
  77. data/spec/plugin_specification_reader_spec.rb +37 -1
  78. data/spec/project_files_list_spec.rb +30 -20
  79. data/spec/qt_sugar_spec.rb +269 -0
  80. data/spec/state_spec.rb +566 -353
  81. data/spec/utils_spec.rb +1 -1
  82. data/spec/view_manager_spec.rb +71 -0
  83. metadata +16 -4
@@ -1,4 +1,4 @@
1
- require 'spec/common'
1
+ require './spec/common'
2
2
 
3
3
  require 'tempfile'
4
4
  require 'fileutils'
@@ -33,7 +33,7 @@ describe Ruber::EditorView do
33
33
  res += ($1 || '')+')'
34
34
  res
35
35
  end
36
- it "should emit the \"#{sig}\" signal in response to the underlying KTextEditor::View #{o_sig} signal" do
36
+ it "emits the \"#{sig}\" signal in response to the underlying KTextEditor::View #{o_sig} signal" do
37
37
  prc = lambda do
38
38
  mock = flexmock('mock')
39
39
  if has_view_arg
@@ -75,6 +75,14 @@ describe Ruber::EditorView do
75
75
  after do
76
76
  @view.disconnect
77
77
  end
78
+
79
+ describe 'when created' do
80
+
81
+ it 'has the Qt::WA_DeleteOnClose attribute' do
82
+ @view.test_attribute(Qt::WA_DeleteOnClose).should be_true
83
+ end
84
+
85
+ end
78
86
 
79
87
  test_auto_signal 'context_menu_about_to_show(QMenu*, @)', 'Qt::Menu.new'
80
88
  test_auto_signal 'focus_in(@)'
@@ -87,7 +95,7 @@ describe Ruber::EditorView do
87
95
  test_auto_signal 'text_inserted(KTextEditor::Cursor, QString, @)', ['KTextEditor::Cursor.new(0,0)', '"test text"']
88
96
  test_auto_signal 'vertical_scroll_position_changed(KTextEditor::Cursor, @)', 'KTextEditor::Cursor.new()'
89
97
 
90
- it "should emit the \"selection_mode_changed(bool, QWidget*)\" signal when the selection mode changes" do
98
+ it "emits the \"selection_mode_changed(bool, QWidget*)\" signal when the selection mode changes" do
91
99
  mock = flexmock('mock')
92
100
  mock.should_receive(:block_mode_on).globally.ordered.once.with(@view.object_id)
93
101
  mock.should_receive(:block_mode_off).globally.ordered.once.with(@view.object_id)
@@ -98,7 +106,7 @@ describe Ruber::EditorView do
98
106
  @view.block_selection = false
99
107
  end
100
108
 
101
- it "should emit the \"edit_mode_changed(KTextEditor::View::EditoMode, QWidget*)\" signal in response to the underlying KTextEditor::View viewEditModeChanged(KTextEditor::View, KTextEditor::View::EditMode) signal" do
109
+ it "emits the \"edit_mode_changed(KTextEditor::View::EditoMode, QWidget*)\" signal in response to the underlying KTextEditor::View viewEditModeChanged(KTextEditor::View, KTextEditor::View::EditMode) signal" do
102
110
  mock = flexmock('mock')
103
111
  mock.should_receive(:test).globally.ordered.once.with(1, @view.object_id)
104
112
  mock.should_receive(:test).globally.ordered.once.with(0, @view.object_id)
@@ -110,7 +118,7 @@ describe Ruber::EditorView do
110
118
  v.instance_eval{emit viewEditModeChanged(self, KTextEditor::View::EditInsert)}
111
119
  end
112
120
 
113
- it "should emit the \"view_mode_changed(QString, QWidget*)\" signal in response to the underlying KTextEditor::View viewModeChanged(KTextEditor::View*) signal" do
121
+ it "emits the \"view_mode_changed(QString, QWidget*)\" signal in response to the underlying KTextEditor::View viewModeChanged(KTextEditor::View*) signal" do
114
122
  mock = flexmock('mock')
115
123
  mock.should_receive(:test).once.with("INS", @view.object_id)
116
124
  @view.connect(SIGNAL('view_mode_changed(QString, QWidget*)')) do |m, v|
@@ -127,6 +135,19 @@ describe Ruber::EditorView do
127
135
  end
128
136
 
129
137
  end
138
+
139
+ describe '#close' do
140
+
141
+ it 'emits the closing(QWidget*) signal passing self as argument when the close method is called' do
142
+ mock = flexmock('mock')
143
+ mock.should_receive(:test).once.with(@view)
144
+ @view.connect(SIGNAL('closing(QWidget*)')) do |v|
145
+ mock.test v
146
+ end
147
+ @view.close
148
+ end
149
+
150
+ end
130
151
 
131
152
  end
132
153
 
@@ -0,0 +1,5 @@
1
+ def init_ruber_core
2
+ require './lib/ruber/component_manager'
3
+ manager = Ruber::ComponentManager.new
4
+ manager.load_component 'application'
5
+ end
@@ -0,0 +1,450 @@
1
+ require './spec/common'
2
+ require 'ruber/main_window/hint_solver'
3
+ require 'ruber/editor/document'
4
+ require 'ruber/pane'
5
+
6
+ describe Ruber::MainWindow::HintSolver do
7
+
8
+ class HintSolverSpecComponentManager < Qt::Object
9
+ extend Forwardable
10
+ signals 'component_loaded(QObject*)', 'unloading_component(QObject*)'
11
+ def_delegators :@data, :[], :<<
12
+ def_delegator :@data, :each, :each_component
13
+
14
+ def initialize parent = nil
15
+ super
16
+ @data = []
17
+ end
18
+
19
+ end
20
+
21
+ before do
22
+ @main_window = Qt::Widget.new
23
+ flexmock(Ruber).should_receive(:[]).with(:main_window).and_return(@main_window).by_default
24
+ flexmock(Ruber).should_receive(:[]).with(:components).and_return(HintSolverSpecComponentManager.new).by_default
25
+ @doc = Ruber::Document.new
26
+ end
27
+
28
+ context 'when created' do
29
+
30
+ it 'takes the tab widget as argument' do
31
+ tabs = KDE::TabWidget.new
32
+ lambda{Ruber::MainWindow::HintSolver.new tabs, KParts::PartManager.new(@main_window), []}.should_not raise_error
33
+ end
34
+
35
+ end
36
+
37
+ describe '#find_editor' do
38
+
39
+ before do
40
+ @tabs = KDE::TabWidget.new
41
+ @solver = Ruber::MainWindow::HintSolver.new @tabs, KParts::PartManager.new(@main_window), []
42
+ @doc = Ruber::Document.new nil
43
+ end
44
+
45
+ context 'when the tab widget contains no tabs' do
46
+
47
+ it 'returns nil' do
48
+ @solver.find_editor(@doc, {}).should be_nil
49
+ end
50
+
51
+ end
52
+
53
+ context 'if the tab widget doesn\'t contain any editor for the given document' do
54
+
55
+ before do
56
+ other_doc = Ruber::Document.new nil
57
+ views = 3.times.map{other_doc.create_view}
58
+ pane1 = Ruber::Pane.new views[0]
59
+ pane1.split views[0], views[1], Qt::Vertical
60
+ @tabs.add_tab pane1, '1'
61
+ pane2 = Ruber::Pane.new views[2]
62
+ @tabs.add_tab pane2, '2'
63
+ end
64
+
65
+ it 'returns nil' do
66
+ @solver.find_editor(@doc, {}).should be_nil
67
+ end
68
+
69
+ end
70
+
71
+ context 'if the existing hint is never' do
72
+
73
+ it 'always returns nil' do
74
+ @solver.find_editor(@doc, :existing => :never).should be_nil
75
+ view = @doc.create_view
76
+ @tabs.add_tab Ruber::Pane.new(view), '1'
77
+ @solver.find_editor(@doc, :existing => :never).should be_nil
78
+ end
79
+
80
+ end
81
+
82
+ context 'when an editor already exists for the document' do
83
+
84
+ context 'if the existing hint is :always' do
85
+
86
+ before do
87
+ @view = @doc.create_view
88
+ other_doc = Ruber::Document.new nil
89
+ views = 3.times.map{other_doc.create_view}
90
+ pane1 = Ruber::Pane.new views[0]
91
+ pane1.split views[0], views[1], Qt::Vertical
92
+ @tabs.add_tab pane1, '1'
93
+ pane2 = Ruber::Pane.new views[2]
94
+ pane2.split views[2], @view, Qt::Vertical
95
+ @tabs.add_tab pane2, '2'
96
+ end
97
+
98
+ it 'returns the existing view if it is in the current tab' do
99
+ @tabs.current_index = 1
100
+ @solver.find_editor(@doc, :existing => :always).should == @view
101
+ end
102
+
103
+ it 'returns the existing view if it is not in the current tab' do
104
+ @tabs.current_index = 0
105
+ @solver.find_editor(@doc, :existing => :always).should == @view
106
+ end
107
+
108
+ end
109
+
110
+ context 'if the existing hint is :current_tab' do
111
+
112
+ before do
113
+ @view = @doc.create_view
114
+ other_doc = Ruber::Document.new nil
115
+ views = 3.times.map{other_doc.create_view}
116
+ pane1 = Ruber::Pane.new views[0]
117
+ pane1.object_name = '1'
118
+ pane1.split views[0], views[1], Qt::Vertical
119
+ @tabs.add_tab pane1, '1'
120
+ pane2 = Ruber::Pane.new views[2]
121
+ pane2.split views[2], @view, Qt::Vertical
122
+ pane2.object_name = '2'
123
+ @tabs.add_tab pane2, '2'
124
+ end
125
+
126
+ it 'returns the existing view if it is in the current tab' do
127
+ @tabs.current_index = 1
128
+ @solver.find_editor(@doc, :existing => :current_tab).should == @view
129
+ end
130
+
131
+ it 'returns nil if the existing view is not in the current tab' do
132
+ @tabs.current_index = 0
133
+ @solver.find_editor(@doc, :existing => :current_tab).should be_nil
134
+ end
135
+
136
+ end
137
+
138
+ end
139
+
140
+ context 'if only one editor respects the existing hint' do
141
+
142
+ it 'returns that editor, regardless of the strategy hint' do
143
+ view = @doc.create_view
144
+ other_doc = Ruber::Document.new
145
+ other_view = other_doc.create_view
146
+ pane = Ruber::Pane.new other_view
147
+ pane.split other_view, view, Qt::Vertical
148
+ @tabs.add_tab pane, 'x'
149
+ @solver.find_editor(@doc, :strategy => :current).should == view
150
+ end
151
+
152
+ end
153
+
154
+ context 'if more than an editor exists for the given document' do
155
+
156
+ before do
157
+ @views = 3.times.map{@doc.create_view}
158
+ other_doc = Ruber::Document.new nil
159
+ @other_views = 3.times.map{other_doc.create_view}
160
+ pane1 = Ruber::Pane.new @other_views[0]
161
+ pane1.object_name = '1'
162
+ pane1.split @other_views[0], @other_views[1], Qt::Vertical
163
+ pane1.split @other_views[1], @views[0], Qt::Horizontal
164
+ @tabs.add_tab pane1, '1'
165
+ pane2 = Ruber::Pane.new @other_views[2]
166
+ pane2.split @other_views[2], @views[1], Qt::Vertical
167
+ pane2.object_name = '2'
168
+ @tabs.add_tab pane2, '2'
169
+ @view_order = @solver.instance_variable_get(:@view_order)
170
+ end
171
+
172
+ context 'if the first entry in the strategy hint is :current' do
173
+
174
+ it 'returns the current editor, if it is associated with the document' do
175
+ @view_order << @views[1] << @other_views[2] << @other_views[1] << @views[0] << @views[2] << @other_views[0]
176
+ @solver.find_editor( @doc, :existing => :always, :strategy => [:current]).should == @views[1]
177
+ end
178
+
179
+ it 'doesn\'t return the current editor if it\'s not associated with the document' do
180
+ flexmock(@pm).should_receive(:active_part).and_return(@other_views[1].send(:internal))
181
+ @view_order << @other_views[1] << @other_views[2] << @views[1] << @views[0] << @views[2] << @other_views[0]
182
+ @solver.find_editor( @doc, :existing => :always, :strategy => [:current]).should_not == @other_views[1]
183
+ end
184
+
185
+ end
186
+
187
+ context 'if the first entry in the strategy hint is :current_tab' do
188
+
189
+ it 'returns the first editor in the current tab which corresponds to the document, if any' do
190
+ flexmock(@pm).should_receive(:active_part).and_return(@views[1].send(:internal))
191
+ @tabs.current_index = 0
192
+ view = @doc.create_view
193
+ @tabs.current_widget.split @views[0], view, Qt::Horizontal, :before
194
+ @solver.find_editor( @doc, :existing => :always, :strategy => [:current_tab]).should == view
195
+ end
196
+
197
+ end
198
+
199
+ context 'if the first entry in the strategy hint is :last_current_tab' do
200
+
201
+ it 'returns the last editor in the current tab associated with the document, if the tab contains more than one editor associated with it' do
202
+ @tabs.current_index = 0
203
+ view = @doc.create_view
204
+ @tabs.current_widget.split @views[0], view, Qt::Horizontal, :before
205
+ @solver.find_editor( @doc, :existing => :always, :strategy => [:last_current_tab]).should == @views[0]
206
+ end
207
+
208
+ it 'returns the editor associated with the document in the current tab if there\'s only one such editor' do
209
+ @tabs.current_index = 0
210
+ @solver.find_editor( @doc, :existing => :always, :strategy => [:last_current_tab]).should == @views[0]
211
+ end
212
+
213
+ end
214
+
215
+ context 'if the first entry in the strategy hint is :next' do
216
+
217
+ it 'returns the first editor in the current tab associated with the document, if any' do
218
+ @tabs.current_index = 0
219
+ view = @doc.create_view
220
+ @tabs.current_widget.split @views[0], view, Qt::Horizontal, :before
221
+ @solver.find_editor( @doc, :existing => :always, :strategy => [:next]).should == view
222
+ end
223
+
224
+ it 'returns the first editor associated with the document it finds, starting from the current tab if no editor for the document exists in the current tab' do
225
+ other_doc = Ruber::Document.new
226
+ other_view = other_doc.create_view
227
+ pane = Ruber::Pane.new other_view
228
+ @tabs.insert_tab 1, pane, 'new'
229
+ @tabs.current_index = 1
230
+ @tabs.widget(2).split @views[1], @views[2], Qt::Horizontal
231
+ @solver.find_editor(@doc, :existing => :always, :strategy => [:next]).should == @views[1]
232
+ end
233
+
234
+ it 'returns the first editor associated with the document starting from the first tab if no editor in or after the current tab is found' do
235
+ other_doc = Ruber::Document.new
236
+ other_view = other_doc.create_view
237
+ pane = Ruber::Pane.new other_view
238
+ @tabs.add_tab pane, 'new'
239
+ pane2 = Ruber::Pane.new other_doc.create_view
240
+ @tabs.add_tab pane2, 'new2'
241
+ @tabs.current_index = 2
242
+ @solver.find_editor(@doc, :existing => :always, :strategy => [:next]).should == @views[0]
243
+ end
244
+
245
+ end
246
+
247
+ context 'if the first entry in the strategy hint is :previous' do
248
+
249
+ it 'returns the first editor associated with the document it finds, starting from the tab before the current and going backwards tab' do
250
+ other_doc = Ruber::Document.new
251
+ other_view = other_doc.create_view
252
+ pane = Ruber::Pane.new other_view
253
+ @tabs.insert_tab 1, pane, 'new'
254
+ @tabs.widget(0).split @views[0], @views[2], Qt::Horizontal
255
+ @tabs.current_index = 1
256
+ @solver.find_editor(@doc, :existing => :always, :strategy => [:previous]).should == @views[2]
257
+ end
258
+
259
+ it 'returns the last editor associated with the document starting from the last tab if no editor before the current tab is found' do
260
+ other_doc = Ruber::Document.new
261
+ other_view = other_doc.create_view
262
+ pane = Ruber::Pane.new other_view
263
+ @tabs.insert_tab 1, pane, 'new'
264
+ pane2 = Ruber::Pane.new other_doc.create_view
265
+ @tabs.insert_tab 0, pane2, 'new2'
266
+ @tabs.current_index = 1
267
+ @solver.find_editor(@doc, :existing => :always, :strategy => [:previous]).should == @views[1]
268
+ end
269
+
270
+ end
271
+
272
+ context 'if the first entry in the strategy hint is :first' do
273
+
274
+ it 'returns the first editor associated with the document' do
275
+ @solver.find_editor(@doc, :existing => :always, :strategy => [:first]).should == @views[0]
276
+ end
277
+
278
+ end
279
+
280
+ context 'if the first entry in the strategy hint is :last' do
281
+
282
+ it 'returns the last editor associated with the document' do
283
+ @solver.find_editor(@doc, :existing => :always, :strategy => [:last]).should == @views[1]
284
+ end
285
+
286
+ end
287
+
288
+ context 'if the first entry in the strategy hint is :last_used' do
289
+
290
+ it 'returns the editor which respects the existing hint and comes first in the view_order list among those associated with the document' do
291
+ @tabs.clear
292
+ views = 3.times.map{@doc.create_view}
293
+ other_doc = Ruber::Document.new
294
+ other_views = 3.times.map{other_doc.create_view}
295
+ order = @solver.instance_variable_get(:@view_order)
296
+ order << other_views[1] << views[2] << other_views[0] << other_views[2] << views[0] << views[1]
297
+ pane1 = Ruber::Pane.new other_views[0]
298
+ pane1.split other_views[0], views[1], Qt::Vertical
299
+ @tabs.add_tab pane1, '1'
300
+ pane2 = Ruber::Pane.new views[0]
301
+ pane2.split views[0], views[2], Qt::Vertical
302
+ @tabs.add_tab pane2, '2'
303
+ pane3 = Ruber::Pane.new other_views[1]
304
+ pane3.split other_views[1], other_views[2], Qt::Vertical
305
+ @tabs.add_tab pane3, '3'
306
+ @solver.find_editor(@doc, :existing => :always, :strategy => [:last_used]).should == views[2]
307
+ end
308
+
309
+ end
310
+
311
+ it 'attempts all the listed strategies until one succeeds' do
312
+ other_doc = Ruber::Document.new
313
+ pane = Ruber::Pane.new other_doc.create_view
314
+ @tabs.add_tab pane, 'new'
315
+ @tabs.current_index = 2
316
+ @solver.find_editor(@doc, :existing => :always, :strategy => [:current, :last]).should == @views[1]
317
+ end
318
+
319
+ it 'uses :next as fallback strategy if all listed strategies fail' do
320
+ other_doc = Ruber::Document.new
321
+ pane = Ruber::Pane.new other_doc.create_view
322
+ @tabs.insert_tab 1, pane, 'new'
323
+ @tabs.current_index = 1
324
+ @solver.find_editor(@doc, :existing => :always, :strategy => :current).should == @views[1]
325
+ end
326
+
327
+ end
328
+
329
+ end
330
+
331
+ describe '#place_editor' do
332
+
333
+ before do
334
+ @tabs = KDE::TabWidget.new
335
+ @solver = Ruber::MainWindow::HintSolver.new @tabs, KParts::PartManager.new(@main_window), []
336
+ @doc = Ruber::Document.new nil
337
+ end
338
+
339
+ context 'when the new hint is :new_tab' do
340
+
341
+ it 'returns nil' do
342
+ @solver.place_editor(:new => :new_tab).should be_nil
343
+ end
344
+
345
+ end
346
+
347
+ context 'when the new hint is current' do
348
+
349
+ it 'returns the current view' do
350
+ views = 3.times.map{@doc.create_view}
351
+ pane1 = Ruber::Pane.new views[0]
352
+ pane2 = Ruber::Pane.new views[1]
353
+ pane2.split views[1], views[2], Qt::Horizontal
354
+ @tabs.add_tab pane1, '1'
355
+ @tabs.add_tab pane2, '2'
356
+ @tabs.current_index = 1
357
+ view_order = @solver.instance_variable_get(:@view_order)
358
+ view_order << views[2] << views[1] << views[0]
359
+ @solver.place_editor(:new => :current).should == views[2]
360
+ end
361
+
362
+ it 'returns nil if there\'s no tab' do
363
+ @solver.place_editor(:new => :current).should be_nil
364
+ end
365
+
366
+ it 'returns nil if the current view can\'t be found' do
367
+ views = 3.times.map{@doc.create_view}
368
+ pane1 = Ruber::Pane.new views[0]
369
+ pane2 = Ruber::Pane.new views[1]
370
+ pane2.split views[1], views[2], Qt::Horizontal
371
+ @tabs.add_tab pane1, '1'
372
+ @tabs.add_tab pane2, '2'
373
+ @tabs.current_index = 1
374
+ @solver.place_editor(:new => :current).should be_nil
375
+ end
376
+
377
+ end
378
+
379
+ context 'when the new hint is :current_tab' do
380
+
381
+ it 'returns the first view in the current tab' do
382
+ views = 3.times.map{@doc.create_view}
383
+ pane1 = Ruber::Pane.new views[0]
384
+ pane2 = Ruber::Pane.new views[1]
385
+ pane2.split views[1], views[2], Qt::Horizontal
386
+ @tabs.add_tab pane1, '1'
387
+ @tabs.add_tab pane2, '2'
388
+ @tabs.current_index = 1
389
+ @solver.place_editor(:new => :current_tab).should == views[1]
390
+ end
391
+
392
+ it 'returns nil if there\'s no tab' do
393
+ @solver.place_editor(:new => :current_tab).should be_nil
394
+ end
395
+
396
+ end
397
+
398
+ context 'when the new hint is an integer' do
399
+
400
+ it 'returns the first view in the tab with that index' do
401
+ views = 3.times.map{@doc.create_view}
402
+ pane1 = Ruber::Pane.new views[0]
403
+ pane2 = Ruber::Pane.new views[1]
404
+ pane2.split views[1], views[2], Qt::Horizontal
405
+ @tabs.add_tab pane1, '1'
406
+ @tabs.add_tab pane2, '2'
407
+ @tabs.current_index = 0
408
+ @solver.place_editor(:new => 1).should == views[1]
409
+ end
410
+
411
+ it 'returns nil if there\'s not a pane with that index' do
412
+ @solver.place_editor(:new => 1).should be_nil
413
+
414
+ views = 3.times.map{@doc.create_view}
415
+ pane1 = Ruber::Pane.new views[0]
416
+ pane2 = Ruber::Pane.new views[1]
417
+ pane2.split views[1], views[2], Qt::Horizontal
418
+ @tabs.add_tab pane1, '1'
419
+ @tabs.add_tab pane2, '2'
420
+ @tabs.current_index = 0
421
+ @solver.place_editor(:new => 5).should be_nil
422
+ end
423
+
424
+ end
425
+
426
+ context 'when the new hint is a view' do
427
+
428
+ it 'returns the view' do
429
+ views = 3.times.map{@doc.create_view}
430
+ pane1 = Ruber::Pane.new views[1]
431
+ pane1.split views[1], views[2], Qt::Vertical
432
+ pane2 = Ruber::Pane.new views[0]
433
+ @tabs.add_tab pane1, '1'
434
+ @tabs.add_tab pane2, '2'
435
+ @solver.place_editor(:new => views[2]).should == views[2]
436
+ end
437
+
438
+ it 'returns nil if the view\'s parent isn\'t a pane' do
439
+ view = @doc.create_view
440
+ @solver.place_editor(:new => view).should be_nil
441
+ w = Qt::Widget.new
442
+ view = @doc.create_view w
443
+ @solver.place_editor(:new => view).should be_nil
444
+ end
445
+
446
+ end
447
+
448
+ end
449
+
450
+ end