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
1=== modified file 'demo/GraniteDemo.vala'
2--- demo/GraniteDemo.vala 2015-08-30 10:10:29 +0000
3+++ demo/GraniteDemo.vala 2015-10-04 10:41:06 +0000
4@@ -220,10 +220,16 @@
5 expandable_grid_start.expand = true;
6 var expandable_grid_end = new Gtk.Grid ();
7 expandable_grid_end.expand = true;
8+ var clear_button = new Gtk.Button.with_label("Clear Selected");
9+ clear_button.clicked.connect (() => {
10+ icon_mode.selected = -1;
11+ text_mode.selected = -1;
12+ });
13 grid.attach (expandable_grid_start, 0, 0, 1, 1);
14- grid.attach (expandable_grid_end, 2, 3, 1, 1);
15+ grid.attach (expandable_grid_end, 2, 4, 1, 1);
16 grid.attach (icon_mode, 1, 1, 1, 1);
17 grid.attach (text_mode, 1, 2, 1, 1);
18+ grid.attach (clear_button, 1, 3, 1 ,1);
19 main_stack.add_named (grid, "modebutton");
20 }
21
22
23=== modified file 'lib/Widgets/ModeButton.vala'
24--- lib/Widgets/ModeButton.vala 2015-08-23 16:13:24 +0000
25+++ lib/Widgets/ModeButton.vala 2015-10-04 10:41:06 +0000
26@@ -136,11 +136,26 @@
27 }
28
29 /**
30+ * Clear selected items
31+ */
32+ private void clear_selected () {
33+ foreach (var item in item_map.values) {
34+ if (item != null && item.active)
35+ item.set_active (false);
36+ }
37+ }
38+
39+ /**
40 * Sets item of given index's activity
41 *
42 * @param new_active_index index of changed item
43 */
44 public void set_active (int new_active_index) {
45+ if (new_active_index == -1) {
46+ clear_selected ();
47+ return;
48+ }
49+
50 return_if_fail (item_map.has_key (new_active_index));
51 var new_item = item_map[new_active_index] as Item;
52

Subscribers

People subscribed via source and target branches