Class: Ruber::MainWindow::ViewManager
- Defined in:
- lib/ruber/main_window/view_manager.rb
Overview
this class is only for internal use by Ruber::MainWindow. Its API is likely to change and the whole class may disappear in the future. So, *do not* use it outside of Ruber::MainWindow
Class which manages the views in the tab widget
It takes care of activating a view when it gets focus, removing a tab when the last view in it is closed, and so on.
Instance Attribute Summary collapse
-
#activation_order ⇒ Array<EditorView>
readonly
A list of all the editors in all tabs, in activation order, from more recently activated to less recently activated.
-
#active_editor ⇒ EditorView?
readonly
The active editor (that is, the editor whose GUI is merged with the main window GUI) or nil if no main window exists.
-
#auto_activate_editors ⇒ Boolean
Whether to automatically activate an editor when it is created.
-
#part_manager ⇒ KDE::PartManager
readonly
The part manager which manages the document parts.
Instance Method Summary collapse
-
#deactivate_editor(view) ⇒ nil
Deactivates the given editor.
-
#editor_for(doc, hints) ⇒ EditorView
Returns an editor associated with the given document, creating it if needed.
-
#focus_editor?(editor, tab = nil) ⇒ Object
Whether the given view is a focus editor.
-
#initialize(tabs, parent) ⇒ ViewManager
constructor
A new instance of ViewManager.
-
#label_for_editor(ed) ⇒ String
The label to use for an editor.
-
#make_editor_active(editor) ⇒ EditorView
Makes the given editor active.
-
#tab(arg) ⇒ Object
The toplevel pane corresponding to the given index or widget.
-
#without_activating { ... } ⇒ Object
Executes a block without automatically activating editors.
Constructor Details
#initialize(tabs, parent) ⇒ ViewManager
Returns a new instance of ViewManager.
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/ruber/main_window/view_manager.rb', line 81 def initialize tabs, parent super parent @tabs = tabs @focus_editors = [] @part_manager = KParts::PartManager.new parent, self @activation_order = [] @active_editor = nil @solver = MainWindow::HintSolver.new @tabs, @part_manager, @activation_order @auto_activate_editors = true connect @tabs, SIGNAL('currentChanged(int)'), self, SLOT('current_tab_changed(int)') end |
Instance Attribute Details
#activation_order ⇒ Array<EditorView> (readonly)
Returns a list of all the editors in all tabs, in activation order, from more recently activated to less recently activated.
55 56 57 |
# File 'lib/ruber/main_window/view_manager.rb', line 55 def activation_order @activation_order end |
#active_editor ⇒ EditorView? (readonly)
Returns the active editor (that is, the editor whose GUI is merged with the main window GUI) or nil if no main window exists.
49 50 51 |
# File 'lib/ruber/main_window/view_manager.rb', line 49 def active_editor @active_editor end |
#auto_activate_editors ⇒ Boolean
Returns whether to automatically activate an editor when it is created.
60 61 62 |
# File 'lib/ruber/main_window/view_manager.rb', line 60 def auto_activate_editors @auto_activate_editors end |
#part_manager ⇒ KDE::PartManager (readonly)
Returns the part manager which manages the document parts.
43 44 45 |
# File 'lib/ruber/main_window/view_manager.rb', line 43 def part_manager @part_manager end |
Instance Method Details
#deactivate_editor(view) ⇒ nil
Deactivates the given editor
To deactivate the editor, its GUI is removed from the main window’s and the corresponding document is deactivated.
If the given editor wasn’t the active one, nothing is done
173 174 175 176 177 178 179 |
# File 'lib/ruber/main_window/view_manager.rb', line 173 def deactivate_editor view return unless @active_editor and view == @active_editor @active_editor.document.deactivate parent.gui_factory.remove_client view.send(:internal) @active_editor = nil nil end |
#editor_for(doc, hints) ⇒ EditorView
Returns an editor associated with the given document, creating it if needed
It works as Ruber::MainWindow#editor_for!.
hints may contain the same values as in Ruber::MainWindow#editor_for!. It may also contain another value, @:close_starting_document@
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/ruber/main_window/view_manager.rb', line 107 def editor_for doc, hints editor = @solver.find_editor doc, hints if !editor and hints[:create_if_needed] editor = create_editor doc if hints[:show] @activation_order << editor view = @solver.place_editor hints if view dir = Qt.const_get hints[:split].to_s.capitalize # tab(view).split view, editor, dir view.parent.split view, editor, dir else if hints[:close_starting_document] if @tabs.count == 1 and @tabs.(0).single_view? doc_to_close = @tabs.(0).view.document end end add_tab editor, doc.icon, doc.document_name doc_to_close.close if doc_to_close end editor.parent.label = label_for_editor editor end end editor end |
#focus_editor?(editor) ⇒ Boolean #focus_editor?(editor, tab) ⇒ Boolean
Whether the given view is a focus editor
249 250 251 252 253 254 255 |
# File 'lib/ruber/main_window/view_manager.rb', line 249 def focus_editor? editor, tab = nil if tab tab = @tabs.index_of(tab) unless tab.is_a? Integer @focus_editors[tab] == editor else @focus_editors.any?{|k, v| v == editor} end end |
#label_for_editor(ed) ⇒ String
The label to use for an editor
263 264 265 266 267 268 |
# File 'lib/ruber/main_window/view_manager.rb', line 263 def label_for_editor ed url = ed.document.url if url.valid? then url.local_file? ? url.path : url.pretty_url else ed.document.document_name end end |
#make_editor_active(editor) ⇒ EditorView
Makes the given editor active
Besides merging the editor’s GUI with the main window’s, this method also deactivates the previously active editor, updates the activation order, activates the document associated with the new active editor, updates the tab where the new editor is and emits the #active_editor_changed signal.
Nothing is done if the given editor was already active
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/ruber/main_window/view_manager.rb', line 145 def make_editor_active editor return if editor and @active_editor == editor deactivate_editor @active_editor @active_editor = editor if editor parent.gui_factory.add_client editor.send(:internal) @activation_order.delete editor @activation_order.insert 0, editor editor_tab = tab(editor) tab_idx = @tabs.index_of editor_tab @focus_editors[tab_idx] = editor update_tab editor_tab editor.document.activate end emit active_editor_changed @active_editor @active_editor end |
#tab(idx) ⇒ Pane #tab(editor) ⇒ Pane? #tab(pane) ⇒ Pane?
The toplevel pane corresponding to the given index or widget
221 222 223 224 225 226 227 228 229 |
# File 'lib/ruber/main_window/view_manager.rb', line 221 def tab arg if arg.is_a? Integer then @tabs. arg else pane = arg.is_a?(Pane) ? arg : arg.parent return unless pane pane = pane.parent_pane while pane.parent_pane pane end end |
#without_activating { ... } ⇒ Object
Executes a block without automatically activating editors
Usually, whenever a tab becomes active, one of the editors it contains becomes active. Sometimes, you don’t want this to happen (for example, when opening multiple documents in sequence). To do so, do what you need from a block passed to this method.
After the block has been executed, the last activated method in the current tab becomes active.
194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/ruber/main_window/view_manager.rb', line 194 def without_activating begin @auto_activate_editors = false yield ensure @auto_activate_editors = true if @tabs.current_index < 0 then make_editor_active nil else make_editor_active @focus_editors[@tabs.current_index] end end end |