Class: Ruber::World::Environment
Defined Under Namespace
Classes: ViewList
Constant Summary
collapse
- DEFAULT_HINTS =
The default hints used by methods like #editor_for and #editor_for!
{
:exisiting => :always,
:strategy => [:current, :current_tab, :first],
:new => :new_tab,
:split => :horizontal,
:show => true,
:create_if_needed => true
}.freeze
Instance Attribute Summary collapse
Attributes included from Extension
#plugin
Instance Method Summary
collapse
Methods included from Extension
#save_settings, #shutdown
Methods included from Activable
#activate, #active=, #active?, #deactivate
Constructor Details
#initialize(prj, parent = nil) ⇒ Environment
Returns a new instance of Environment.
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/ruber/world/environment.rb', line 109
def initialize prj, parent = nil
super parent
@project = prj
@tab_widget = KDE::TabWidget.new{self.document_mode = true}
@tab_widget.tabs_closable = true if Ruber[:config][:workspace, :close_buttons]
connect @tab_widget, SIGNAL('currentChanged(int)'), self, SLOT('current_tab_changed(int)')
connect @tab_widget, SIGNAL('tabCloseRequested(int)'), self, SLOT('close_tab(int)')
@views = ViewList.new
@hint_solver = HintSolver.new @tab_widget, nil, @views.by_activation
@documents = MutableDocumentList.new
@active_editor = nil
@active = false
@focus_on_editors = true
unless prj
@default_document = Ruber[:world].new_document
@default_document.object_name = 'default_document'
@default_document.connect(SIGNAL('closing(QObject*)')){@default_document = nil}
editor_for! @default_document
end
end
|
Instance Attribute Details
Returns the active editor or nil if no active editor exists.
107
108
109
|
# File 'lib/ruber/world/environment.rb', line 107
def active_editor
@active_editor
end
|
Returns the project associated with the environment or nil if the environment is not associated with a project.
96
97
98
|
# File 'lib/ruber/world/environment.rb', line 96
def project
@project
end
|
Returns the tab widget containing the views contained in the environment.
102
103
104
|
# File 'lib/ruber/world/environment.rb', line 102
def tab_widget
@tab_widget
end
|
Instance Method Details
#activate_editor(view) ⇒ Object
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
# File 'lib/ruber/world/environment.rb', line 174
def activate_editor view
return view if @active_editor == view
deactivate_editor @active_editor
if view
if active?
Ruber[:main_window].gui_factory.add_client view.send(:internal)
@active_editor = view
end
@views.move_to_front view
view_tab = tab(view)
idx = @tab_widget.index_of view_tab
@tab_widget.set_tab_text idx, view.document.document_name
@tab_widget.set_tab_icon idx, view.document.icon
@tab_widget.current_index = idx
end
if active?
emit active_editor_changed(view)
view.document.activate if view
end
view.set_focus if view and focus_on_editors?
view
end
|
#active_document ⇒ Object
198
199
200
|
# File 'lib/ruber/world/environment.rb', line 198
def active_document
@active_editor ? @active_editor.document : nil
end
|
#close(mode = :save) ⇒ Object
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
# File 'lib/ruber/world/environment.rb', line 209
def close mode = :save
if @project then @project.close mode == :save
else
docs_to_close = @views.by_document.to_a.select{|d, v| (d.views - v).empty?}
docs_to_close.map!{|d| d[0]}
if mode == :save
return false unless Ruber[:main_window].save_documents docs_to_close
end
emit closing(self)
self.active = false
docs_to_close.each{|d| d.close false}
@views.by_activation.dup.each{|v| v.close}
delete_later
true
end
end
|
#close_editor(editor, ask = true) ⇒ Object
202
203
204
205
206
207
|
# File 'lib/ruber/world/environment.rb', line 202
def close_editor editor, ask = true
doc = editor.document
if doc.views.count > 1 then editor.close
else doc.close ask
end
end
|
#close_editors(editors, ask = true) ⇒ Object
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
# File 'lib/ruber/world/environment.rb', line 235
def close_editors editors, ask = true
editors_by_doc = editors.group_by &:document
docs = editors_by_doc.keys
to_close = docs.select{|doc| (doc.views - editors_by_doc[doc]).empty?}
if ask
return unless Ruber[:main_window].save_documents to_close
end
to_close.each do |doc|
doc.close false
editors_by_doc.delete doc
end
editors_by_doc.each_value do |a|
a.each &:close
end
end
|
#display_document(doc, hints = {}) ⇒ Object
227
228
229
230
231
232
233
|
# File 'lib/ruber/world/environment.rb', line 227
def display_document doc, hints = {}
ed = editor_for! doc, hints
activate_editor ed
line = hints[:line]
ed.go_to line, hints[:column] || 0 if hints[:line]
ed
end
|
#documents ⇒ Object
151
152
153
|
# File 'lib/ruber/world/environment.rb', line 151
def documents
DocumentList.new @documents
end
|
#editor_for!(doc, hints = DEFAULT_HINTS) ⇒ Object
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
# File 'lib/ruber/world/environment.rb', line 130
def editor_for! doc, hints = DEFAULT_HINTS
doc = Ruber[:world].document doc unless doc.is_a? Document
hints = DEFAULT_HINTS.merge hints
editor = @hint_solver.find_editor doc, hints
unless editor
return nil unless hints[:create_if_needed]
view_to_split = @hint_solver.place_editor hints
editor = doc.create_view
if view_to_split
orientation = hints[:split] == :vertical ? Qt::Vertical : Qt::Horizontal
view_to_split.parent.split view_to_split, editor, orientation
else
new_pane = create_tab(editor)
add_editor editor, new_pane
@tab_widget.add_tab new_pane, doc.icon, doc.document_name
new_pane.label = label_for_document doc
end
end
editor
end
|
#focus_on_editors? ⇒ Boolean
266
267
268
|
# File 'lib/ruber/world/environment.rb', line 266
def focus_on_editors?
@views.tabs.empty? || @focus_on_editors
end
|
#query_close ⇒ Object
270
271
272
273
274
275
276
|
# File 'lib/ruber/world/environment.rb', line 270
def query_close
if Ruber[:app].status != :asking_to_quit
docs = @views.by_document.select{|d, v| (d.views - v).empty?}
Ruber[:main_window].save_documents docs.map{|a| a[0]}
else true
end
end
|
#remove_from_project ⇒ Object
278
279
280
281
282
283
284
285
|
# File 'lib/ruber/world/environment.rb', line 278
def remove_from_project
raise "environment not associated with a project" unless @project
emit closing(self)
self.active = false
docs_to_close = @views.by_document.select{|d, v| (d.views - v).empty?}
docs_to_close.each{|d| d[0].close false}
@views.dup.by_activation.each{|v| v.close}
end
|
#replace_editor(old, new) ⇒ Object
251
252
253
254
255
256
257
258
259
260
261
262
263
264
|
# File 'lib/ruber/world/environment.rb', line 251
def replace_editor old, new
if new.is_a? Document
new = new.create_view
elsif new.is_a? String or new.is_a? KDE::Url
new = Ruber[:world].document(new).create_view
end
if old.document.views.count == 1
return unless old.document.query_close
close_doc = true
end
old.parent.replace_view old, new
close_editor old, false
new
end
|
163
164
165
166
167
168
169
170
171
172
|
# File 'lib/ruber/world/environment.rb', line 163
def tab arg
if arg.is_a?(Pane)
pane = arg
while parent = pane.parent_pane
pane = parent
end
@tab_widget.index_of(pane) > -1 ? pane : nil
else @views.tabs[arg]
end
end
|
155
156
157
|
# File 'lib/ruber/world/environment.rb', line 155
def tabs
@tab_widget.to_a
end
|
#views(doc = nil) ⇒ Object
159
160
161
|
# File 'lib/ruber/world/environment.rb', line 159
def views doc = nil
doc ? @views.by_document[doc].dup : @views.by_activation.dup
end
|