Merge lp:~artem-anufrij/granite/granite-modebutton-clear-selected into lp:~elementary-pantheon/granite/granite

Proposed by Artem Anufrij
Status: Superseded
Proposed branch: lp:~artem-anufrij/granite/granite-modebutton-clear-selected
Merge into: lp:~elementary-pantheon/granite/granite
Diff against target: 51 lines (+22/-1)
2 files modified
demo/GraniteDemo.vala (+7/-1)
lib/Widgets/ModeButton.vala (+15/-0)
To merge this branch: bzr merge lp:~artem-anufrij/granite/granite-modebutton-clear-selected
Reviewer Review Type Date Requested Status
xapantu (community) Needs Fixing
Review via email: mp+270432@code.launchpad.net

This proposal has been superseded by a proposal from 2015-10-05.

Commit message

'selected = -1' clear selected items in ModeButton

Description of the change

all selected items will be unselected

To post a comment you must log in.
876. By Artem Anufrij

check if button is selected

Revision history for this message
xapantu (xapantu) wrote :

Could a foreach be used in clear_selected ()? It does not look very clean with the manual iteration (and it is slower, even if it is not noticeable on a modebutton with less than a thousand choices…).

review: Needs Fixing
877. By Artem Anufrij

for -> foreach

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'demo/GraniteDemo.vala'
--- demo/GraniteDemo.vala 2015-08-30 10:10:29 +0000
+++ demo/GraniteDemo.vala 2015-10-04 10:41:06 +0000
@@ -220,10 +220,16 @@
220 expandable_grid_start.expand = true;220 expandable_grid_start.expand = true;
221 var expandable_grid_end = new Gtk.Grid ();221 var expandable_grid_end = new Gtk.Grid ();
222 expandable_grid_end.expand = true;222 expandable_grid_end.expand = true;
223 var clear_button = new Gtk.Button.with_label("Clear Selected");
224 clear_button.clicked.connect (() => {
225 icon_mode.selected = -1;
226 text_mode.selected = -1;
227 });
223 grid.attach (expandable_grid_start, 0, 0, 1, 1);228 grid.attach (expandable_grid_start, 0, 0, 1, 1);
224 grid.attach (expandable_grid_end, 2, 3, 1, 1);229 grid.attach (expandable_grid_end, 2, 4, 1, 1);
225 grid.attach (icon_mode, 1, 1, 1, 1);230 grid.attach (icon_mode, 1, 1, 1, 1);
226 grid.attach (text_mode, 1, 2, 1, 1);231 grid.attach (text_mode, 1, 2, 1, 1);
232 grid.attach (clear_button, 1, 3, 1 ,1);
227 main_stack.add_named (grid, "modebutton");233 main_stack.add_named (grid, "modebutton");
228 }234 }
229235
230236
=== modified file 'lib/Widgets/ModeButton.vala'
--- lib/Widgets/ModeButton.vala 2015-08-23 16:13:24 +0000
+++ lib/Widgets/ModeButton.vala 2015-10-04 10:41:06 +0000
@@ -136,11 +136,26 @@
136 }136 }
137137
138 /**138 /**
139 * Clear selected items
140 */
141 private void clear_selected () {
142 foreach (var item in item_map.values) {
143 if (item != null && item.active)
144 item.set_active (false);
145 }
146 }
147
148 /**
139 * Sets item of given index's activity149 * Sets item of given index's activity
140 *150 *
141 * @param new_active_index index of changed item151 * @param new_active_index index of changed item
142 */152 */
143 public void set_active (int new_active_index) {153 public void set_active (int new_active_index) {
154 if (new_active_index == -1) {
155 clear_selected ();
156 return;
157 }
158
144 return_if_fail (item_map.has_key (new_active_index));159 return_if_fail (item_map.has_key (new_active_index));
145 var new_item = item_map[new_active_index] as Item;160 var new_item = item_map[new_active_index] as Item;
146161

Subscribers

People subscribed via source and target branches