Merge lp:~julien-spautz/slingshot/1152844 into lp:~elementary-pantheon/slingshot/trunk

Proposed by Julien Spautz
Status: Merged
Approved by: Cody Garver
Approved revision: 350
Merged at revision: 359
Proposed branch: lp:~julien-spautz/slingshot/1152844
Merge into: lp:~elementary-pantheon/slingshot/trunk
Diff against target: 272 lines (+91/-44)
2 files modified
src/SlingshotView.vala (+89/-43)
src/Widgets/Switcher.vala (+2/-1)
To merge this branch: bzr merge lp:~julien-spautz/slingshot/1152844
Reviewer Review Type Date Requested Status
David Gomes (community) Needs Fixing
elementary UX Pending
Review via email: mp+152587@code.launchpad.net

Commit message

Fixes bug #1152844 by removing "KP_" from the key name and thus mapping keypad keys to their "normal" equivalent.

I also added support for Home and End, switching to the first/last page or category.

Alt + n switches to the nth page, Alt+0 to the last one. This might need some designer input, but I thinks it's a neat feature, and consistent with DynamicNotebook's behaviour.

Description of the change

Fixes bug #1152844 by removing "KP_" from the key name and thus mapping keypad keys to their "normal" equivalent.

I also added support for Home and End, switching to the first/last page or category.

Alt + n switches to the nth page, Alt+0 to the last one. This might need some designer input, but I thinks it's a neat feature, and consistent with DynamicNotebook's behaviour.

To post a comment you must log in.
Revision history for this message
David Gomes (davidgomes) wrote :

This needs some code style fixes, do you prefer if I fix them for you or if I list them so you fix them? If you prefer the first, change the branch owner to elementary-dev-community.

lp:~julien-spautz/slingshot/1152844 updated
348. By Julien Spautz

cuddled elses

Revision history for this message
Julien Spautz (julien-spautz) wrote :

I'll fix it, what do I have to change except for cuddled elses?

Revision history for this message
David Gomes (davidgomes) wrote :

Remove diff's newline 52 and that's it. Cuddled elses were really pretty much everything.

review: Needs Fixing
lp:~julien-spautz/slingshot/1152844 updated
349. By Julien Spautz

newline

Revision history for this message
David Gomes (davidgomes) wrote :

Alright, code is good now, I'll test this now.

Revision history for this message
David Gomes (davidgomes) wrote :

It works just fine, good job! One more thing, make it so that Alt+9 does the same thing as Home (even if there are more than 9 pages).

Alt+9 is standard for going to the last page.

review: Needs Fixing
lp:~julien-spautz/slingshot/1152844 updated
350. By Julien Spautz

Alt+9 switches to last page

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/SlingshotView.vala'
2--- src/SlingshotView.vala 2013-02-16 13:10:53 +0000
3+++ src/SlingshotView.vala 2013-03-11 16:33:20 +0000
4@@ -297,24 +297,63 @@
5
6 public override bool key_press_event (Gdk.EventKey event) {
7
8- switch (Gdk.keyval_name (event.keyval)) {
9+ var key = Gdk.keyval_name (event.keyval).replace ("KP_", "");
10+
11+ event.state &= (Gdk.ModifierType.SHIFT_MASK |
12+ Gdk.ModifierType.MOD1_MASK |
13+ Gdk.ModifierType.CONTROL_MASK);
14+
15+ switch (key) {
16
17 case "Escape":
18 hide ();
19 return true;
20-
21-
22+
23+ case "Enter": // "KP_Enter"
24 case "Return":
25 if (modality == Modality.SEARCH_VIEW) {
26 search_view.launch_selected ();
27 hide ();
28- }
29- else
30+ } else {
31 if (get_focus () as AppEntry != null) // checking the selected widget is an AppEntry
32 ((AppEntry)get_focus ()).launch_app ();
33+ }
34 return true;
35
36- case "Alt":
37+
38+ case "Alt_L":
39+ case "Alt_R":
40+ break;
41+
42+ case "0":
43+ case "1":
44+ case "2":
45+ case "3":
46+ case "4":
47+ case "5":
48+ case "6":
49+ case "7":
50+ case "8":
51+ case "9":
52+ int page = int.parse (key) - 1;
53+
54+ if (event.state != Gdk.ModifierType.MOD1_MASK)
55+ return base.key_press_event (event);
56+
57+ if (modality == Modality.NORMAL_VIEW) {
58+ if (page < 0 || page == 8)
59+ page_switcher.set_active (grid_view.get_n_pages () - 1);
60+ else
61+ page_switcher.set_active (page);
62+ } else if (modality == Modality.CATEGORY_VIEW) {
63+ if (page < 0 || page == 8)
64+ category_view.switcher.set_active (category_view.switcher.size - 1);
65+ else
66+ category_view.switcher.set_active (page);
67+ } else {
68+ return base.key_press_event (event);
69+ }
70+ searchbar.grab_focus ();
71 break;
72
73 case "Tab":
74@@ -323,91 +362,81 @@
75 var new_focus = category_view.app_view.get_child_at (category_column_focus, category_row_focus);
76 if (new_focus != null)
77 new_focus.grab_focus ();
78- }
79- else if (modality == Modality.CATEGORY_VIEW) {
80+ } else if (modality == Modality.CATEGORY_VIEW) {
81 view_selector.selected = 0;
82 var new_focus = grid_view.get_child_at (column_focus, row_focus);
83 if (new_focus != null)
84 new_focus.grab_focus ();
85 }
86 break;
87-
88+
89 case "Left":
90 if (modality == Modality.NORMAL_VIEW) {
91 if (event.state == Gdk.ModifierType.SHIFT_MASK) // Shift + Left
92 page_switcher.set_active (page_switcher.active - 1);
93 else
94 normal_move_focus (-1, 0);
95- }
96- else if (modality == Modality.CATEGORY_VIEW) {
97+ } else if (modality == Modality.CATEGORY_VIEW) {
98 if (event.state == Gdk.ModifierType.SHIFT_MASK) // Shift + Left
99 category_view.switcher.set_active (category_view.switcher.active - 1);
100 else if (!searchbar.has_focus) {//the user has already selected an AppEntry
101 category_move_focus (-1, 0);
102 }
103- }
104- else
105+ } else
106 return base.key_press_event (event);
107 break;
108-
109+
110 case "Right":
111 if (modality == Modality.NORMAL_VIEW) {
112 if (event.state == Gdk.ModifierType.SHIFT_MASK) // Shift + Right
113 page_switcher.set_active (page_switcher.active + 1);
114 else
115 normal_move_focus (+1, 0);
116- }
117- else if (modality == Modality.CATEGORY_VIEW) {
118+ } else if (modality == Modality.CATEGORY_VIEW) {
119 if (event.state == Gdk.ModifierType.SHIFT_MASK) // Shift + Right
120 category_view.switcher.set_active (category_view.switcher.active + 1);
121 else if (searchbar.has_focus) // there's no AppEntry selected, the user is switching category
122 top_left_focus ();
123 else //the user has already selected an AppEntry
124 category_move_focus (+1, 0);
125+ } else {
126+ return base.key_press_event (event);
127 }
128- else
129- return base.key_press_event (event);
130 break;
131-
132+
133 case "Up":
134 if (modality == Modality.NORMAL_VIEW) {
135 normal_move_focus (0, -1);
136- }
137- else if (modality == Modality.CATEGORY_VIEW) {
138+ } else if (modality == Modality.CATEGORY_VIEW) {
139 if (event.state == Gdk.ModifierType.SHIFT_MASK) { // Shift + Up
140 if (category_view.category_switcher.selected != 0) {
141 category_view.category_switcher.selected--;
142 top_left_focus ();
143 }
144- }
145- else if (searchbar.has_focus)
146+ } else if (searchbar.has_focus) {
147 category_view.category_switcher.selected--;
148- else
149+ } else {
150 category_move_focus (0, -1);
151- }
152- else if (modality == Modality.SEARCH_VIEW) {
153+ }
154+ } else if (modality == Modality.SEARCH_VIEW) {
155 search_view.selected--;
156 search_view_up ();
157 }
158 break;
159
160-
161 case "Down":
162 if (modality == Modality.NORMAL_VIEW) {
163 normal_move_focus (0, +1);
164- }
165- else if (modality == Modality.CATEGORY_VIEW) {
166+ } else if (modality == Modality.CATEGORY_VIEW) {
167 if (event.state == Gdk.ModifierType.SHIFT_MASK) { // Shift + Down
168 category_view.category_switcher.selected++;
169 top_left_focus ();
170- }
171- else if (searchbar.has_focus)
172+ } else if (searchbar.has_focus) {
173 category_view.category_switcher.selected++;
174- else { // the user has already selected an AppEntry
175+ } else { // the user has already selected an AppEntry
176 category_move_focus (0, +1);
177 }
178- }
179- else if (modality == Modality.SEARCH_VIEW) {
180+ } else if (modality == Modality.SEARCH_VIEW) {
181 search_view.selected++;
182 if (search_view.selected > 7)
183 search_view_down ();
184@@ -419,8 +448,7 @@
185 page_switcher.set_active (page_switcher.active - 1);
186 if (page_switcher.active != 0) // we don't wanna lose focus if we don't actually change page
187 searchbar.grab_focus (); // this is because otherwise focus isn't the current page
188- }
189- else if (modality == Modality.CATEGORY_VIEW) {
190+ } else if (modality == Modality.CATEGORY_VIEW) {
191 category_view.category_switcher.selected--;
192 top_left_focus ();
193 }
194@@ -431,24 +459,42 @@
195 page_switcher.set_active (page_switcher.active + 1);
196 if (page_switcher.active != grid_view.get_n_pages () - 1) // we don't wanna lose focus if we don't actually change page
197 searchbar.grab_focus (); //this is because otherwise focus isn't the current page
198- }
199- else if (modality == Modality.CATEGORY_VIEW) {
200+ } else if (modality == Modality.CATEGORY_VIEW) {
201 category_view.category_switcher.selected++;
202 top_left_focus ();
203 }
204 break;
205
206 case "BackSpace":
207- if (event.state == Gdk.ModifierType.SHIFT_MASK) // Shift + Delete
208- searchbar.set_text ("");
209- else if (searchbar.has_focus)
210+ if (event.state == Gdk.ModifierType.SHIFT_MASK) { // Shift + Delete
211+ searchbar.text = "";
212+ } else if (searchbar.has_focus) {
213 return base.key_press_event (event);
214- else {
215+ } else {
216 searchbar.grab_focus ();
217 searchbar.move_cursor (Gtk.MovementStep.BUFFER_ENDS, 0, false);
218 return base.key_press_event (event);
219 }
220 break;
221+
222+ case "Home":
223+ if (modality == Modality.NORMAL_VIEW) {
224+ page_switcher.set_active (0);
225+ } else if (modality == Modality.CATEGORY_VIEW) {
226+ category_view.category_switcher.selected = 0;
227+ top_left_focus ();
228+ }
229+ break;
230+
231+ case "End":
232+ if (modality == Modality.NORMAL_VIEW) {
233+ page_switcher.set_active (grid_view.get_n_pages () - 1);
234+ } else if (modality == Modality.CATEGORY_VIEW) {
235+ category_view.category_switcher.selected = category_view.category_switcher.cat_size - 1;
236+ top_left_focus ();
237+ }
238+ break;
239+
240 default:
241 if (!searchbar.has_focus) {
242 searchbar.grab_focus ();
243@@ -492,7 +538,7 @@
244
245 public void show_slingshot () {
246
247- searchbar.set_text ("");
248+ searchbar.text = "";
249
250 reposition ();
251 show_all ();
252
253=== modified file 'src/Widgets/Switcher.vala'
254--- src/Widgets/Switcher.vala 2013-02-13 21:20:15 +0000
255+++ src/Widgets/Switcher.vala 2013-03-11 16:33:20 +0000
256@@ -63,6 +63,7 @@
257 }
258
259 public void set_active (int new_active) {
260+
261 if (new_active >= get_children ().length ())
262 return;
263
264@@ -73,7 +74,7 @@
265 active = new_active;
266 active_changed (new_active);
267 ((ToggleButton) get_children ().nth_data (active)).set_active (true);
268-
269+
270 }
271
272 public void clear_children () {

Subscribers

People subscribed via source and target branches