Class: Ruber::World::HintSolver
- Defined in:
- lib/ruber/world/hint_solver.rb
Overview
Helper class used by MainWindow#editor_for and friends to find out which editor should use or where the new editor should be placed according to the hints given them
Instance Method Summary collapse
-
#find_editor(doc, hints) ⇒ EditorView?
Finds the editor to use for a document according to the given hints.
-
#initialize(tabs, manager, view_order) ⇒ HintSolver
constructor
A new instance of HintSolver.
-
#place_editor(hints) ⇒ EditorView?
Finds out where a new editor should respect the given hints.
Constructor Details
#initialize(tabs, manager, view_order) ⇒ HintSolver
Returns a new instance of HintSolver.
43 44 45 46 47 |
# File 'lib/ruber/world/hint_solver.rb', line 43 def initialize tabs, manager, view_order @tabs = tabs @part_manager = manager @view_order = view_order end |
Instance Method Details
#find_editor(doc, hints) ⇒ EditorView?
Finds the editor to use for a document according to the given hints
If no editor associated with the document and respecting the given hints exists, nil is returned. This always happens if the @:existing@ hint is @:never@.
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ruber/world/hint_solver.rb', line 60 def find_editor doc, hints views = [] case hints[:existing] when :never then return nil when :current_tab views = @tabs..select{|v| v.document == doc} else @tabs.each{|t| views += t.select{|v| v.document == doc} } end choose_editor doc, views, hints end |
#place_editor(hints) ⇒ EditorView?
Finds out where a new editor should respect the given hints
The return value tells where the new editor should be placed. If the return value is nil then the editor should be placed in a new tab; if it’s an EditorView then the editor should be placed in the pane containing the view, splitting it at the view values it can contain. Only the @:newand entry is used
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/ruber/world/hint_solver.rb', line 84 def place_editor hints case hints[:new] when :new_tab then nil when :current then @view_order[0] when :current_tab current = @tabs. current.each_view.to_a[0] if current when Integer pane = @tabs. hints[:new] pane.each_view.to_a[0] if pane when EditorView then view = hints[:new] view.parent.is_a?(Pane) ? view : nil end end |