Class: CWM::UIState
- Inherits:
-
Object
- Object
- CWM::UIState
- Includes:
- Yast::I18n
- Defined in:
- library/cwm/src/lib/cwm/ui_state.rb
Overview
Singleton class to keep the position of the user in the UI and other similar information that needs to be rememberd across UI redraws to give the user a sense of continuity.
If you want to see it in action, have a look at yast2-storage-ng or yast2-firewall modules.
Instance Attribute Summary collapse
-
#candidate_nodes ⇒ Array<Integer, String>
protected
Where to place the user within the general tree in next redraw.
- #row_id ⇒ Object
-
#tab ⇒ String?
protected
Concrete tab within the current node to show in the next redraw.
Class Method Summary collapse
-
.create_instance ⇒ Object
Enforce a new clean instance.
-
.instance ⇒ Object
Singleton instance.
Instance Method Summary collapse
-
#find_tab(pages) ⇒ CWM::Page?
Select the tab to open within the node after a redraw.
-
#find_tree_node(pages) ⇒ CWM::Page?
Select the page to open in the general tree after a redraw.
-
#go_to_tree_node(page) ⇒ Object
Method to be called when the user decides to visit a given page by clicking in one node of the general tree.
-
#initialize ⇒ UIState
constructor
Constructor.
-
#matches?(page, candidate) ⇒ Boolean
protected
Whether the given page matches with the candidate tree node.
-
#select_row(row_id) ⇒ Object
Method to be called when the user operates in a row of a table.
-
#switch_to_tab(page) ⇒ Object
Method to be called when the user switches to a tab within a tree node.
Constructor Details
#initialize ⇒ UIState
Constructor
Called through create_instance, starts with a blank situation (which means default for each widget will be honored).
88 89 90 |
# File 'library/cwm/src/lib/cwm/ui_state.rb', line 88 def initialize @candidate_nodes = [] end |
Instance Attribute Details
#candidate_nodes ⇒ Array<Integer, String> (protected)
Where to place the user within the general tree in next redraw
163 164 165 |
# File 'library/cwm/src/lib/cwm/ui_state.rb', line 163 def candidate_nodes @candidate_nodes end |
#row_id ⇒ Object
155 156 157 |
# File 'library/cwm/src/lib/cwm/ui_state.rb', line 155 def row_id @row_id end |
#tab ⇒ String? (protected)
Concrete tab within the current node to show in the next redraw
167 168 169 |
# File 'library/cwm/src/lib/cwm/ui_state.rb', line 167 def tab @tab end |
Class Method Details
.create_instance ⇒ Object
Enforce a new clean instance
194 195 196 |
# File 'library/cwm/src/lib/cwm/ui_state.rb', line 194 def create_instance @instance = new end |
.instance ⇒ Object
Singleton instance
188 189 190 191 |
# File 'library/cwm/src/lib/cwm/ui_state.rb', line 188 def instance create_instance unless @instance @instance end |
Instance Method Details
#find_tab(pages) ⇒ CWM::Page?
Select the tab to open within the node after a redraw
146 147 148 149 150 |
# File 'library/cwm/src/lib/cwm/ui_state.rb', line 146 def find_tab(pages) return nil unless tab pages.find { |page| page.label == tab } end |
#find_tree_node(pages) ⇒ CWM::Page?
Select the page to open in the general tree after a redraw
128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'library/cwm/src/lib/cwm/ui_state.rb', line 128 def find_tree_node(pages) candidate_nodes.each.with_index do |candidate, idx| result = pages.find { |page| matches?(page, candidate) } if result # If we had to use one of the fallbacks, the tab name is not longer # trustworthy self.tab = nil unless idx.zero? return result end end self.tab = nil nil end |
#go_to_tree_node(page) ⇒ Object
Method to be called when the user decides to visit a given page by clicking in one node of the general tree.
It remembers the decision so the user is taken back to a sensible point of the tree (very often the last he decided to visit) after redrawing.
99 100 101 102 103 104 105 |
# File 'library/cwm/src/lib/cwm/ui_state.rb', line 99 def go_to_tree_node(page) self.candidate_nodes = [page.label] # Landing in a new node, so invalidate previous details about position # within a node, they no longer apply self.tab = nil end |
#matches?(page, candidate) ⇒ Boolean (protected)
Whether the given page matches with the candidate tree node
182 183 184 |
# File 'library/cwm/src/lib/cwm/ui_state.rb', line 182 def matches?(page, candidate) page.label == candidate end |
#select_row(row_id) ⇒ Object
Method to be called when the user operates in a row of a table.
120 121 122 |
# File 'library/cwm/src/lib/cwm/ui_state.rb', line 120 def select_row(row_id) self.row_id = row_id end |
#switch_to_tab(page) ⇒ Object
Method to be called when the user switches to a tab within a tree node.
It remembers the decision so the same tab is showed in case the user stays in the same node after redrawing.
113 114 115 |
# File 'library/cwm/src/lib/cwm/ui_state.rb', line 113 def switch_to_tab(page) self.tab = page.label end |