Merge lp:~tintou/slingshot/gtk+-3.10 into lp:~elementary-pantheon/slingshot/trunk
- gtk+-3.10
- Merge into trunk
Proposed by
Corentin Noël
Status: | Merged | ||||||||
---|---|---|---|---|---|---|---|---|---|
Approved by: | Cody Garver | ||||||||
Approved revision: | 410 | ||||||||
Merged at revision: | 409 | ||||||||
Proposed branch: | lp:~tintou/slingshot/gtk+-3.10 | ||||||||
Merge into: | lp:~elementary-pantheon/slingshot/trunk | ||||||||
Diff against target: |
1367 lines (+318/-452) 8 files modified
CMakeLists.txt (+3/-3) src/Backend/AppSystem.vala (+6/-3) src/SlingshotView.vala (+86/-188) src/Widgets/AppEntry.vala (+1/-35) src/Widgets/CategoryView.vala (+5/-99) src/Widgets/Grid.vala (+93/-38) src/Widgets/SearchView.vala (+20/-11) src/Widgets/Switcher.vala (+104/-75) |
||||||||
To merge this branch: | bzr merge lp:~tintou/slingshot/gtk+-3.10 | ||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Rico Tzschichholz | Needs Fixing | ||
Review via email: mp+208011@code.launchpad.net |
Commit message
Port forward to Gtk 3.10 for improved page switching and other benefits
Description of the change
Now using Gtk 3.10 !
To post a comment you must log in.
Revision history for this message
Cody Garver (codygarver) wrote : | # |
Revision history for this message
Rico Tzschichholz (ricotz) wrote : | # |
Please don't make changes unrelated to using new Gtk wigets.
Meaning no codes-style-changes or refactoring.
If crashes or at least results in a hash-table critical here.
review:
Needs Fixing
lp:~tintou/slingshot/gtk+-3.10
updated
- 410. By Corentin Noël
-
Removed code-style changes
Revision history for this message
Corentin Noël (tintou) wrote : | # |
HashTable critical errors are also present into trunk
Revision history for this message
David Gomes (davidgomes) wrote : | # |
I have the same problem as Cody.
Revision history for this message
David Gomes (davidgomes) wrote : | # |
Seems this was merged and I get a transparent Slingshot.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'CMakeLists.txt' | |||
2 | --- CMakeLists.txt 2014-02-23 19:56:35 +0000 | |||
3 | +++ CMakeLists.txt 2014-03-01 15:19:46 +0000 | |||
4 | @@ -55,14 +55,14 @@ | |||
5 | 55 | endif () | 55 | endif () |
6 | 56 | 56 | ||
7 | 57 | set (CORE_DEPS "gobject-2.0;glib-2.0;gio-2.0;gio-unix-2.0;gee-0.8;libgnome-menu-3.0;libwnck-3.0;gdk-x11-3.0;${UNITY_DEPS};") | 57 | set (CORE_DEPS "gobject-2.0;glib-2.0;gio-2.0;gio-unix-2.0;gee-0.8;libgnome-menu-3.0;libwnck-3.0;gdk-x11-3.0;${UNITY_DEPS};") |
9 | 58 | set (UI_DEPS "gtk+-3.0>=3.2.0;granite;${ZEITGEIST_DEPS};") | 58 | set (UI_DEPS "gtk+-3.0>=3.10.0;granite;${ZEITGEIST_DEPS};") |
10 | 59 | 59 | ||
11 | 60 | find_package (PkgConfig) | 60 | find_package (PkgConfig) |
12 | 61 | pkg_check_modules (DEPS REQUIRED "${CORE_DEPS}${UI_DEPS}" gthread-2.0) | 61 | pkg_check_modules (DEPS REQUIRED "${CORE_DEPS}${UI_DEPS}" gthread-2.0) |
13 | 62 | 62 | ||
14 | 63 | find_package (Vala REQUIRED) | 63 | find_package (Vala REQUIRED) |
15 | 64 | include (ValaVersion) | 64 | include (ValaVersion) |
17 | 65 | ensure_vala_version ("0.18.0" MINIMUM) | 65 | ensure_vala_version ("0.22.0" MINIMUM) |
18 | 66 | 66 | ||
19 | 67 | include (ValaPrecompile) | 67 | include (ValaPrecompile) |
20 | 68 | vala_precompile (VALA_C ${APPNAME} | 68 | vala_precompile (VALA_C ${APPNAME} |
21 | @@ -114,4 +114,4 @@ | |||
22 | 114 | add_schema ("org.pantheon.desktop.slingshot.gschema.xml") | 114 | add_schema ("org.pantheon.desktop.slingshot.gschema.xml") |
23 | 115 | 115 | ||
24 | 116 | # Translations | 116 | # Translations |
26 | 117 | add_subdirectory (po) | 117 | add_subdirectory (po) |
27 | 118 | \ No newline at end of file | 118 | \ No newline at end of file |
28 | 119 | 119 | ||
29 | === modified file 'src/Backend/AppSystem.vala' | |||
30 | --- src/Backend/AppSystem.vala 2013-01-10 16:53:50 +0000 | |||
31 | +++ src/Backend/AppSystem.vala 2014-03-01 15:19:46 +0000 | |||
32 | @@ -51,8 +51,11 @@ | |||
33 | 51 | #if HAVE_ZEITGEIST | 51 | #if HAVE_ZEITGEIST |
34 | 52 | rl_service.refresh_popularity (); | 52 | rl_service.refresh_popularity (); |
35 | 53 | #endif | 53 | #endif |
38 | 54 | 54 | try { | |
39 | 55 | apps_menu.load_sync (); | 55 | apps_menu.load_sync (); |
40 | 56 | } catch (Error e) { | ||
41 | 57 | warning (e.message); | ||
42 | 58 | } | ||
43 | 56 | 59 | ||
44 | 57 | update_categories_index (); | 60 | update_categories_index (); |
45 | 58 | update_apps (); | 61 | update_apps (); |
46 | @@ -224,4 +227,4 @@ | |||
47 | 224 | 227 | ||
48 | 225 | } | 228 | } |
49 | 226 | 229 | ||
51 | 227 | } | 230 | } |
52 | 228 | \ No newline at end of file | 231 | \ No newline at end of file |
53 | 229 | 232 | ||
54 | === modified file 'src/SlingshotView.vala' | |||
55 | --- src/SlingshotView.vala 2013-12-26 00:08:04 +0000 | |||
56 | +++ src/SlingshotView.vala 2014-03-01 15:19:46 +0000 | |||
57 | @@ -27,9 +27,8 @@ | |||
58 | 27 | public class SlingshotView : Granite.Widgets.PopOver { | 27 | public class SlingshotView : Granite.Widgets.PopOver { |
59 | 28 | 28 | ||
60 | 29 | // Widgets | 29 | // Widgets |
64 | 30 | public Granite.Widgets.SearchBar searchbar; | 30 | public Gtk.SearchEntry search_entry; |
65 | 31 | public Gtk.Layout view_manager; | 31 | public Gtk.Stack stack; |
63 | 32 | public Widgets.Switcher page_switcher; | ||
66 | 33 | public Granite.Widgets.ModeButton view_selector; | 32 | public Granite.Widgets.ModeButton view_selector; |
67 | 34 | 33 | ||
68 | 35 | // Views | 34 | // Views |
69 | @@ -39,7 +38,6 @@ | |||
70 | 39 | 38 | ||
71 | 40 | public Gtk.Grid top; | 39 | public Gtk.Grid top; |
72 | 41 | public Gtk.Grid center; | 40 | public Gtk.Grid center; |
73 | 42 | public Gtk.Grid bottom; | ||
74 | 43 | public Gtk.Grid container; | 41 | public Gtk.Grid container; |
75 | 44 | public Gtk.Box content_area; | 42 | public Gtk.Box content_area; |
76 | 45 | private Gtk.EventBox event_box; | 43 | private Gtk.EventBox event_box; |
77 | @@ -156,56 +154,43 @@ | |||
78 | 156 | else | 154 | else |
79 | 157 | view_selector.selected = 0; | 155 | view_selector.selected = 0; |
80 | 158 | 156 | ||
85 | 159 | searchbar = new Granite.Widgets.SearchBar (_("Search Apps…")); | 157 | search_entry = new Gtk.SearchEntry (); |
86 | 160 | searchbar.pause_delay = 200; | 158 | search_entry.placeholder_text = _("Search Apps…"); |
87 | 161 | searchbar.width_request = 250; | 159 | search_entry.width_request = 250; |
88 | 162 | searchbar.button_press_event.connect ((e) => {return e.button == 3;}); | 160 | search_entry.button_press_event.connect ((e) => {return e.button == 3;}); |
89 | 163 | 161 | ||
90 | 164 | if (Slingshot.settings.show_category_filter) { | 162 | if (Slingshot.settings.show_category_filter) { |
91 | 165 | top.attach (view_selector, 0, 0, 1, 1); | 163 | top.attach (view_selector, 0, 0, 1, 1); |
92 | 166 | } | 164 | } |
93 | 167 | top.attach (top_separator, 1, 0, 1, 1); | 165 | top.attach (top_separator, 1, 0, 1, 1); |
95 | 168 | top.attach (searchbar, 2, 0, 1, 1); | 166 | top.attach (search_entry, 2, 0, 1, 1); |
96 | 169 | 167 | ||
97 | 170 | center = new Gtk.Grid (); | 168 | center = new Gtk.Grid (); |
102 | 171 | // Create the layout which works like view_manager | 169 | |
103 | 172 | view_manager = new Gtk.Layout (null, null); | 170 | stack = new Gtk.Stack (); |
104 | 173 | view_manager.set_size_request (default_columns * 130, default_rows * 145); | 171 | stack.set_size_request (default_columns * 130, default_rows * 145); |
105 | 174 | center.attach (view_manager, 0, 0, 1, 1); | 172 | center.attach (stack, 0, 0, 1, 1); |
106 | 175 | 173 | ||
107 | 176 | // Create the "NORMAL_VIEW" | 174 | // Create the "NORMAL_VIEW" |
108 | 175 | var scrolled_normal = new Gtk.ScrolledWindow (null, null); | ||
109 | 177 | grid_view = new Widgets.Grid (default_rows, default_columns); | 176 | grid_view = new Widgets.Grid (default_rows, default_columns); |
111 | 178 | view_manager.put (grid_view, 0, 0); | 177 | scrolled_normal.add_with_viewport (grid_view); |
112 | 178 | stack.add_named (scrolled_normal, "normal"); | ||
113 | 179 | 179 | ||
114 | 180 | // Create the "SEARCH_VIEW" | 180 | // Create the "SEARCH_VIEW" |
115 | 181 | search_view = new Widgets.SearchView (this); | 181 | search_view = new Widgets.SearchView (this); |
116 | 182 | |||
117 | 182 | foreach (Gee.ArrayList<Backend.App> app_list in apps.values) { | 183 | foreach (Gee.ArrayList<Backend.App> app_list in apps.values) { |
118 | 183 | search_view.add_apps (app_list); | 184 | search_view.add_apps (app_list); |
119 | 184 | } | 185 | } |
121 | 185 | view_manager.put (search_view, -columns * 130, 0); | 186 | stack.add_named (search_view, "search"); |
122 | 186 | 187 | ||
123 | 187 | // Create the "CATEGORY_VIEW" | 188 | // Create the "CATEGORY_VIEW" |
124 | 188 | category_view = new Widgets.CategoryView (this); | 189 | category_view = new Widgets.CategoryView (this); |
141 | 189 | view_manager.put (category_view, -columns * 130, 0); | 190 | stack.add_named (category_view, "category"); |
126 | 190 | |||
127 | 191 | // Create the page switcher | ||
128 | 192 | page_switcher = new Widgets.Switcher (); | ||
129 | 193 | |||
130 | 194 | // A bottom widget to keep the page switcher center | ||
131 | 195 | bottom = new Gtk.Grid (); | ||
132 | 196 | |||
133 | 197 | |||
134 | 198 | var bottom_separator1 = new Gtk.Label (""); // A fake label | ||
135 | 199 | bottom_separator1.set_hexpand (true); | ||
136 | 200 | var bottom_separator2 = new Gtk.Label (""); // A fake label | ||
137 | 201 | bottom_separator2.set_hexpand (true); | ||
138 | 202 | bottom.attach (bottom_separator1, 0, 0, 1, 1); // A fake label | ||
139 | 203 | bottom.attach (page_switcher, 1, 0, 1, 1); | ||
140 | 204 | bottom.attach (bottom_separator2, 2, 0, 1, 1); // A fake label | ||
142 | 205 | 191 | ||
143 | 206 | container.attach (Utils.set_padding (top, 12, 12, 12, 12), 0, 0, 1, 1); | 192 | container.attach (Utils.set_padding (top, 12, 12, 12, 12), 0, 0, 1, 1); |
144 | 207 | container.attach (Utils.set_padding (center, 0, 12, 12, 12), 0, 1, 1, 1); | 193 | container.attach (Utils.set_padding (center, 0, 12, 12, 12), 0, 1, 1, 1); |
145 | 208 | container.attach (Utils.set_padding (bottom, 0, 24, 12, 24), 0, 2, 1, 1); | ||
146 | 209 | 194 | ||
147 | 210 | event_box = new Gtk.EventBox (); | 195 | event_box = new Gtk.EventBox (); |
148 | 211 | event_box.add (container); | 196 | event_box.add (container); |
149 | @@ -277,17 +262,15 @@ | |||
150 | 277 | private void connect_signals () { | 262 | private void connect_signals () { |
151 | 278 | 263 | ||
152 | 279 | this.focus_in_event.connect (() => { | 264 | this.focus_in_event.connect (() => { |
154 | 280 | searchbar.grab_focus (); | 265 | search_entry.grab_focus (); |
155 | 281 | return false; | 266 | return false; |
156 | 282 | }); | 267 | }); |
157 | 283 | 268 | ||
158 | 284 | //view_manager.draw.connect (this.draw_background); | ||
159 | 285 | |||
160 | 286 | event_box.key_press_event.connect (on_key_press); | 269 | event_box.key_press_event.connect (on_key_press); |
163 | 287 | searchbar.text_changed_pause.connect ((text) => this.search.begin (text)); | 270 | search_entry.search_changed.connect (() => this.search.begin (search_entry.text)); |
164 | 288 | searchbar.grab_focus (); | 271 | search_entry.grab_focus (); |
165 | 289 | 272 | ||
167 | 290 | searchbar.activate.connect (() => { | 273 | search_entry.activate.connect (() => { |
168 | 291 | if (modality == Modality.SEARCH_VIEW) { | 274 | if (modality == Modality.SEARCH_VIEW) { |
169 | 292 | search_view.launch_selected (); | 275 | search_view.launch_selected (); |
170 | 293 | hide (); | 276 | hide (); |
171 | @@ -300,15 +283,8 @@ | |||
172 | 300 | search_view.app_launched.connect (() => hide ()); | 283 | search_view.app_launched.connect (() => hide ()); |
173 | 301 | 284 | ||
174 | 302 | // This function must be after creating the page switcher | 285 | // This function must be after creating the page switcher |
175 | 303 | grid_view.new_page.connect (page_switcher.append); | ||
176 | 304 | populate_grid_view (); | 286 | populate_grid_view (); |
177 | 305 | 287 | ||
178 | 306 | page_switcher.active_changed.connect (() => { | ||
179 | 307 | |||
180 | 308 | move_page (page_switcher.active - page_switcher.old_active); | ||
181 | 309 | searchbar.grab_focus (); //avoid focus is not on current page | ||
182 | 310 | }); | ||
183 | 311 | |||
184 | 312 | view_selector.mode_changed.connect (() => { | 288 | view_selector.mode_changed.connect (() => { |
185 | 313 | 289 | ||
186 | 314 | set_modality ((Modality) view_selector.selected); | 290 | set_modality ((Modality) view_selector.selected); |
187 | @@ -383,7 +359,7 @@ | |||
188 | 383 | when an input method is in use (Gtk3 bug?). Key press events are | 359 | when an input method is in use (Gtk3 bug?). Key press events are |
189 | 384 | captured by an Event Box and passed to this function instead. | 360 | captured by an Event Box and passed to this function instead. |
190 | 385 | 361 | ||
192 | 386 | Events not dealt with here are propagated to the searchbar by the | 362 | Events not dealt with here are propagated to the search_entry by the |
193 | 387 | usual mechanism. | 363 | usual mechanism. |
194 | 388 | */ | 364 | */ |
195 | 389 | public bool on_key_press (Gdk.EventKey event) { | 365 | public bool on_key_press (Gdk.EventKey event) { |
196 | @@ -408,8 +384,8 @@ | |||
197 | 408 | break; | 384 | break; |
198 | 409 | 385 | ||
199 | 410 | case "Escape": | 386 | case "Escape": |
202 | 411 | if (searchbar.text.length > 0) { | 387 | if (search_entry.text.length > 0) { |
203 | 412 | searchbar.text = ""; | 388 | search_entry.text = ""; |
204 | 413 | } else { | 389 | } else { |
205 | 414 | hide (); | 390 | hide (); |
206 | 415 | } | 391 | } |
207 | @@ -443,25 +419,25 @@ | |||
208 | 443 | case "7": | 419 | case "7": |
209 | 444 | case "8": | 420 | case "8": |
210 | 445 | case "9": | 421 | case "9": |
212 | 446 | int page = int.parse (key) - 1; | 422 | int page = int.parse (key); |
213 | 447 | 423 | ||
214 | 448 | if (event.state != Gdk.ModifierType.MOD1_MASK) | 424 | if (event.state != Gdk.ModifierType.MOD1_MASK) |
215 | 449 | return false; | 425 | return false; |
216 | 450 | 426 | ||
217 | 451 | if (modality == Modality.NORMAL_VIEW) { | 427 | if (modality == Modality.NORMAL_VIEW) { |
220 | 452 | if (page < 0 || page == 8) | 428 | if (page < 0 || page == 9) |
221 | 453 | page_switcher.set_active (grid_view.get_n_pages () - 1); | 429 | grid_view.go_to_last (); |
222 | 454 | else | 430 | else |
224 | 455 | page_switcher.set_active (page); | 431 | grid_view.go_to_number (page); |
225 | 456 | } else if (modality == Modality.CATEGORY_VIEW) { | 432 | } else if (modality == Modality.CATEGORY_VIEW) { |
228 | 457 | if (page < 0 || page == 8) | 433 | if (page < 0 || page == 9) |
229 | 458 | category_view.switcher.set_active (category_view.switcher.size - 1); | 434 | category_view.app_view.go_to_last (); |
230 | 459 | else | 435 | else |
232 | 460 | category_view.switcher.set_active (page); | 436 | category_view.app_view.go_to_number (page); |
233 | 461 | } else { | 437 | } else { |
234 | 462 | return false; | 438 | return false; |
235 | 463 | } | 439 | } |
237 | 464 | searchbar.grab_focus (); | 440 | search_entry.grab_focus (); |
238 | 465 | break; | 441 | break; |
239 | 466 | 442 | ||
240 | 467 | case "Tab": | 443 | case "Tab": |
241 | @@ -480,14 +456,15 @@ | |||
242 | 480 | 456 | ||
243 | 481 | case "Left": | 457 | case "Left": |
244 | 482 | if (modality == Modality.NORMAL_VIEW) { | 458 | if (modality == Modality.NORMAL_VIEW) { |
248 | 483 | if (event.state == Gdk.ModifierType.SHIFT_MASK) // Shift + Left | 459 | if (event.state == Gdk.ModifierType.SHIFT_MASK) {// Shift + Left |
249 | 484 | page_switcher.set_active (page_switcher.active - 1); | 460 | grid_view.go_to_previous (); |
250 | 485 | else | 461 | } else { |
251 | 486 | normal_move_focus (-1, 0); | 462 | normal_move_focus (-1, 0); |
252 | 463 | } | ||
253 | 487 | } else if (modality == Modality.CATEGORY_VIEW) { | 464 | } else if (modality == Modality.CATEGORY_VIEW) { |
254 | 488 | if (event.state == Gdk.ModifierType.SHIFT_MASK) // Shift + Left | 465 | if (event.state == Gdk.ModifierType.SHIFT_MASK) // Shift + Left |
257 | 489 | category_view.switcher.set_active (category_view.switcher.active - 1); | 466 | category_view.app_view.go_to_previous (); |
258 | 490 | else if (!searchbar.has_focus) {//the user has already selected an AppEntry | 467 | else if (!search_entry.has_focus) {//the user has already selected an AppEntry |
259 | 491 | category_move_focus (-1, 0); | 468 | category_move_focus (-1, 0); |
260 | 492 | } | 469 | } |
261 | 493 | } else | 470 | } else |
262 | @@ -497,13 +474,13 @@ | |||
263 | 497 | case "Right": | 474 | case "Right": |
264 | 498 | if (modality == Modality.NORMAL_VIEW) { | 475 | if (modality == Modality.NORMAL_VIEW) { |
265 | 499 | if (event.state == Gdk.ModifierType.SHIFT_MASK) // Shift + Right | 476 | if (event.state == Gdk.ModifierType.SHIFT_MASK) // Shift + Right |
267 | 500 | page_switcher.set_active (page_switcher.active + 1); | 477 | grid_view.go_to_next (); |
268 | 501 | else | 478 | else |
269 | 502 | normal_move_focus (+1, 0); | 479 | normal_move_focus (+1, 0); |
270 | 503 | } else if (modality == Modality.CATEGORY_VIEW) { | 480 | } else if (modality == Modality.CATEGORY_VIEW) { |
271 | 504 | if (event.state == Gdk.ModifierType.SHIFT_MASK) // Shift + Right | 481 | if (event.state == Gdk.ModifierType.SHIFT_MASK) // Shift + Right |
274 | 505 | category_view.switcher.set_active (category_view.switcher.active + 1); | 482 | category_view.app_view.go_to_next (); |
275 | 506 | else if (searchbar.has_focus) // there's no AppEntry selected, the user is switching category | 483 | else if (search_entry.has_focus) // there's no AppEntry selected, the user is switching category |
276 | 507 | top_left_focus (); | 484 | top_left_focus (); |
277 | 508 | else //the user has already selected an AppEntry | 485 | else //the user has already selected an AppEntry |
278 | 509 | category_move_focus (+1, 0); | 486 | category_move_focus (+1, 0); |
279 | @@ -521,14 +498,13 @@ | |||
280 | 521 | category_view.category_switcher.selected--; | 498 | category_view.category_switcher.selected--; |
281 | 522 | top_left_focus (); | 499 | top_left_focus (); |
282 | 523 | } | 500 | } |
284 | 524 | } else if (searchbar.has_focus) { | 501 | } else if (search_entry.has_focus) { |
285 | 525 | category_view.category_switcher.selected--; | 502 | category_view.category_switcher.selected--; |
286 | 526 | } else { | 503 | } else { |
287 | 527 | category_move_focus (0, -1); | 504 | category_move_focus (0, -1); |
288 | 528 | } | 505 | } |
289 | 529 | } else if (modality == Modality.SEARCH_VIEW) { | 506 | } else if (modality == Modality.SEARCH_VIEW) { |
290 | 530 | search_view.selected--; | 507 | search_view.selected--; |
291 | 531 | search_view_up (); | ||
292 | 532 | } | 508 | } |
293 | 533 | break; | 509 | break; |
294 | 534 | 510 | ||
295 | @@ -539,23 +515,19 @@ | |||
296 | 539 | if (event.state == Gdk.ModifierType.SHIFT_MASK) { // Shift + Down | 515 | if (event.state == Gdk.ModifierType.SHIFT_MASK) { // Shift + Down |
297 | 540 | category_view.category_switcher.selected++; | 516 | category_view.category_switcher.selected++; |
298 | 541 | top_left_focus (); | 517 | top_left_focus (); |
300 | 542 | } else if (searchbar.has_focus) { | 518 | } else if (search_entry.has_focus) { |
301 | 543 | category_view.category_switcher.selected++; | 519 | category_view.category_switcher.selected++; |
302 | 544 | } else { // the user has already selected an AppEntry | 520 | } else { // the user has already selected an AppEntry |
303 | 545 | category_move_focus (0, +1); | 521 | category_move_focus (0, +1); |
304 | 546 | } | 522 | } |
305 | 547 | } else if (modality == Modality.SEARCH_VIEW) { | 523 | } else if (modality == Modality.SEARCH_VIEW) { |
306 | 548 | search_view.selected++; | 524 | search_view.selected++; |
307 | 549 | if (search_view.selected > 7) | ||
308 | 550 | search_view_down (); | ||
309 | 551 | } | 525 | } |
310 | 552 | break; | 526 | break; |
311 | 553 | 527 | ||
312 | 554 | case "Page_Up": | 528 | case "Page_Up": |
313 | 555 | if (modality == Modality.NORMAL_VIEW) { | 529 | if (modality == Modality.NORMAL_VIEW) { |
317 | 556 | page_switcher.set_active (page_switcher.active - 1); | 530 | grid_view.go_to_previous (); |
315 | 557 | if (page_switcher.active != 0) // we don't wanna lose focus if we don't actually change page | ||
316 | 558 | searchbar.grab_focus (); // this is because otherwise focus isn't the current page | ||
318 | 559 | } else if (modality == Modality.CATEGORY_VIEW) { | 531 | } else if (modality == Modality.CATEGORY_VIEW) { |
319 | 560 | category_view.category_switcher.selected--; | 532 | category_view.category_switcher.selected--; |
320 | 561 | top_left_focus (); | 533 | top_left_focus (); |
321 | @@ -564,9 +536,7 @@ | |||
322 | 564 | 536 | ||
323 | 565 | case "Page_Down": | 537 | case "Page_Down": |
324 | 566 | if (modality == Modality.NORMAL_VIEW) { | 538 | if (modality == Modality.NORMAL_VIEW) { |
328 | 567 | page_switcher.set_active (page_switcher.active + 1); | 539 | grid_view.go_to_next (); |
326 | 568 | if (page_switcher.active != grid_view.get_n_pages () - 1) // we don't wanna lose focus if we don't actually change page | ||
327 | 569 | searchbar.grab_focus (); //this is because otherwise focus isn't the current page | ||
329 | 570 | } else if (modality == Modality.CATEGORY_VIEW) { | 540 | } else if (modality == Modality.CATEGORY_VIEW) { |
330 | 571 | category_view.category_switcher.selected++; | 541 | category_view.category_switcher.selected++; |
331 | 572 | top_left_focus (); | 542 | top_left_focus (); |
332 | @@ -575,23 +545,23 @@ | |||
333 | 575 | 545 | ||
334 | 576 | case "BackSpace": | 546 | case "BackSpace": |
335 | 577 | if (event.state == Gdk.ModifierType.SHIFT_MASK) { // Shift + Delete | 547 | if (event.state == Gdk.ModifierType.SHIFT_MASK) { // Shift + Delete |
338 | 578 | searchbar.text = ""; | 548 | search_entry.text = ""; |
339 | 579 | } else if (searchbar.has_focus) { | 549 | } else if (search_entry.has_focus) { |
340 | 580 | return false; | 550 | return false; |
341 | 581 | } else { | 551 | } else { |
344 | 582 | searchbar.grab_focus (); | 552 | search_entry.grab_focus (); |
345 | 583 | searchbar.move_cursor (Gtk.MovementStep.BUFFER_ENDS, 0, false); | 553 | search_entry.move_cursor (Gtk.MovementStep.BUFFER_ENDS, 0, false); |
346 | 584 | return false; | 554 | return false; |
347 | 585 | } | 555 | } |
348 | 586 | break; | 556 | break; |
349 | 587 | 557 | ||
350 | 588 | case "Home": | 558 | case "Home": |
352 | 589 | if (searchbar.text.length > 0) { | 559 | if (search_entry.text.length > 0) { |
353 | 590 | return false; | 560 | return false; |
354 | 591 | } | 561 | } |
355 | 592 | 562 | ||
356 | 593 | if (modality == Modality.NORMAL_VIEW) { | 563 | if (modality == Modality.NORMAL_VIEW) { |
358 | 594 | page_switcher.set_active (0); | 564 | grid_view.go_to_number (1); |
359 | 595 | } else if (modality == Modality.CATEGORY_VIEW) { | 565 | } else if (modality == Modality.CATEGORY_VIEW) { |
360 | 596 | category_view.category_switcher.selected = 0; | 566 | category_view.category_switcher.selected = 0; |
361 | 597 | top_left_focus (); | 567 | top_left_focus (); |
362 | @@ -599,12 +569,12 @@ | |||
363 | 599 | break; | 569 | break; |
364 | 600 | 570 | ||
365 | 601 | case "End": | 571 | case "End": |
367 | 602 | if (searchbar.text.length > 0) { | 572 | if (search_entry.text.length > 0) { |
368 | 603 | return false; | 573 | return false; |
369 | 604 | } | 574 | } |
370 | 605 | 575 | ||
371 | 606 | if (modality == Modality.NORMAL_VIEW) { | 576 | if (modality == Modality.NORMAL_VIEW) { |
373 | 607 | page_switcher.set_active (grid_view.get_n_pages () - 1); | 577 | grid_view.go_to_last (); |
374 | 608 | } else if (modality == Modality.CATEGORY_VIEW) { | 578 | } else if (modality == Modality.CATEGORY_VIEW) { |
375 | 609 | category_view.category_switcher.selected = category_view.category_switcher.cat_size - 1; | 579 | category_view.category_switcher.selected = category_view.category_switcher.cat_size - 1; |
376 | 610 | top_left_focus (); | 580 | top_left_focus (); |
377 | @@ -614,14 +584,14 @@ | |||
378 | 614 | case "v": | 584 | case "v": |
379 | 615 | case "V": | 585 | case "V": |
380 | 616 | if ((event.state & (Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.SHIFT_MASK)) != 0) { | 586 | if ((event.state & (Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.SHIFT_MASK)) != 0) { |
382 | 617 | searchbar.paste_clipboard (); | 587 | search_entry.paste_clipboard (); |
383 | 618 | } | 588 | } |
384 | 619 | break; | 589 | break; |
385 | 620 | 590 | ||
386 | 621 | default: | 591 | default: |
390 | 622 | if (!searchbar.has_focus) { | 592 | if (!search_entry.has_focus) { |
391 | 623 | searchbar.grab_focus (); | 593 | search_entry.grab_focus (); |
392 | 624 | searchbar.move_cursor (Gtk.MovementStep.BUFFER_ENDS, 0, false); | 594 | search_entry.move_cursor (Gtk.MovementStep.BUFFER_ENDS, 0, false); |
393 | 625 | } | 595 | } |
394 | 626 | return false; | 596 | return false; |
395 | 627 | 597 | ||
396 | @@ -637,20 +607,16 @@ | |||
397 | 637 | case "GDK_SCROLL_UP": | 607 | case "GDK_SCROLL_UP": |
398 | 638 | case "GDK_SCROLL_LEFT": | 608 | case "GDK_SCROLL_LEFT": |
399 | 639 | if (modality == Modality.NORMAL_VIEW) | 609 | if (modality == Modality.NORMAL_VIEW) |
405 | 640 | page_switcher.set_active (page_switcher.active - 1); | 610 | grid_view.go_to_previous (); |
406 | 641 | else if (modality == Modality.SEARCH_VIEW) | 611 | else if (modality == Modality.CATEGORY_VIEW) |
407 | 642 | search_view_up (); | 612 | category_view.app_view.go_to_previous (); |
403 | 643 | else | ||
404 | 644 | category_view.switcher.set_active (category_view.switcher.active - 1); | ||
408 | 645 | break; | 613 | break; |
409 | 646 | case "GDK_SCROLL_DOWN": | 614 | case "GDK_SCROLL_DOWN": |
410 | 647 | case "GDK_SCROLL_RIGHT": | 615 | case "GDK_SCROLL_RIGHT": |
411 | 648 | if (modality == Modality.NORMAL_VIEW) | 616 | if (modality == Modality.NORMAL_VIEW) |
417 | 649 | page_switcher.set_active (page_switcher.active + 1); | 617 | grid_view.go_to_next (); |
418 | 650 | else if (modality == Modality.SEARCH_VIEW) | 618 | else if (modality == Modality.CATEGORY_VIEW) |
419 | 651 | search_view_down (); | 619 | category_view.app_view.go_to_next (); |
415 | 652 | else | ||
416 | 653 | category_view.switcher.set_active (category_view.switcher.active + 1); | ||
420 | 654 | break; | 620 | break; |
421 | 655 | 621 | ||
422 | 656 | } | 622 | } |
423 | @@ -661,14 +627,14 @@ | |||
424 | 661 | 627 | ||
425 | 662 | public void show_slingshot () { | 628 | public void show_slingshot () { |
426 | 663 | 629 | ||
428 | 664 | searchbar.text = ""; | 630 | search_entry.text = ""; |
429 | 665 | 631 | ||
430 | 666 | reposition (); | 632 | reposition (); |
431 | 667 | show_all (); | 633 | show_all (); |
432 | 668 | present (); | 634 | present (); |
433 | 669 | 635 | ||
434 | 670 | set_focus(null); | 636 | set_focus(null); |
436 | 671 | searchbar.grab_focus (); | 637 | search_entry.grab_focus (); |
437 | 672 | set_modality ((Modality) view_selector.selected); | 638 | set_modality ((Modality) view_selector.selected); |
438 | 673 | 639 | ||
439 | 674 | while (Gtk.events_pending ()) | 640 | while (Gtk.events_pending ()) |
440 | @@ -681,56 +647,6 @@ | |||
441 | 681 | w.activate (Gdk.x11_get_server_time (this.get_window ())); | 647 | w.activate (Gdk.x11_get_server_time (this.get_window ())); |
442 | 682 | } | 648 | } |
443 | 683 | 649 | ||
444 | 684 | private void move_page (int step) { | ||
445 | 685 | |||
446 | 686 | debug ("Moving: step = " + step.to_string ()); | ||
447 | 687 | |||
448 | 688 | if (step == 0) | ||
449 | 689 | return; | ||
450 | 690 | if (step < 0 && current_position >= 0) //Left border | ||
451 | 691 | return; | ||
452 | 692 | if (step > 0 && (-current_position) >= ((grid_view.get_n_pages () - 1) * grid_view.get_page_columns () * 130)) //Right border | ||
453 | 693 | return; | ||
454 | 694 | |||
455 | 695 | int count = 0; | ||
456 | 696 | int increment = -step * 130 * columns / 10; | ||
457 | 697 | Timeout.add (30 / columns, () => { | ||
458 | 698 | |||
459 | 699 | if (count >= 10) { | ||
460 | 700 | current_position += -step * 130 * columns - 10 * increment; //We adjust to end of the page | ||
461 | 701 | view_manager.move (grid_view, current_position, 0); | ||
462 | 702 | return false; | ||
463 | 703 | } | ||
464 | 704 | |||
465 | 705 | current_position += increment; | ||
466 | 706 | view_manager.move (grid_view, current_position, 0); | ||
467 | 707 | count++; | ||
468 | 708 | return true; | ||
469 | 709 | |||
470 | 710 | }, Priority.DEFAULT_IDLE); | ||
471 | 711 | } | ||
472 | 712 | |||
473 | 713 | private void search_view_down () { | ||
474 | 714 | |||
475 | 715 | if (search_view.apps_showed < default_rows * 3) | ||
476 | 716 | return; | ||
477 | 717 | |||
478 | 718 | if ((search_view_position) > -(search_view.apps_showed * 48)) { | ||
479 | 719 | view_manager.move (search_view, 0, search_view_position - 2 * 38); | ||
480 | 720 | search_view_position -= 2 * 38; | ||
481 | 721 | } | ||
482 | 722 | |||
483 | 723 | } | ||
484 | 724 | |||
485 | 725 | private void search_view_up () { | ||
486 | 726 | |||
487 | 727 | if (search_view_position < 0) { | ||
488 | 728 | view_manager.move (search_view, 0, search_view_position + 2 * 38); | ||
489 | 729 | search_view_position += 2 * 38; | ||
490 | 730 | } | ||
491 | 731 | |||
492 | 732 | } | ||
493 | 733 | |||
494 | 734 | private void set_modality (Modality new_modality) { | 650 | private void set_modality (Modality new_modality) { |
495 | 735 | 651 | ||
496 | 736 | modality = new_modality; | 652 | modality = new_modality; |
497 | @@ -740,57 +656,42 @@ | |||
498 | 740 | 656 | ||
499 | 741 | if (Slingshot.settings.use_category) | 657 | if (Slingshot.settings.use_category) |
500 | 742 | Slingshot.settings.use_category = false; | 658 | Slingshot.settings.use_category = false; |
501 | 743 | bottom.show (); | ||
502 | 744 | view_selector.show_all (); | 659 | view_selector.show_all (); |
508 | 745 | page_switcher.show_all (); | 660 | stack.set_visible_child_name ("normal"); |
504 | 746 | category_view.show_page_switcher (false); | ||
505 | 747 | view_manager.move (search_view, - 130 * columns, 0); | ||
506 | 748 | view_manager.move (category_view, 130 * columns, 0); | ||
507 | 749 | view_manager.move (grid_view, current_position, 0); | ||
509 | 750 | 661 | ||
510 | 751 | // change the paddings/margins back to normal | 662 | // change the paddings/margins back to normal |
511 | 752 | get_content_area ().set_margin_left (PADDINGS.left + SHADOW_SIZE + 5); | 663 | get_content_area ().set_margin_left (PADDINGS.left + SHADOW_SIZE + 5); |
512 | 753 | center.set_margin_left (12); | 664 | center.set_margin_left (12); |
513 | 754 | top.set_margin_left (12); | 665 | top.set_margin_left (12); |
515 | 755 | view_manager.set_size_request (default_columns * 130, default_rows * 145); | 666 | stack.set_size_request (default_columns * 130, default_rows * 145); |
516 | 756 | break; | 667 | break; |
517 | 757 | 668 | ||
518 | 758 | case Modality.CATEGORY_VIEW: | 669 | case Modality.CATEGORY_VIEW: |
519 | 759 | 670 | ||
520 | 760 | if (!Slingshot.settings.use_category) | 671 | if (!Slingshot.settings.use_category) |
521 | 761 | Slingshot.settings.use_category = true; | 672 | Slingshot.settings.use_category = true; |
522 | 762 | bottom.show (); | ||
523 | 763 | view_selector.show_all (); | 673 | view_selector.show_all (); |
529 | 764 | page_switcher.hide (); | 674 | stack.set_visible_child_name ("category"); |
525 | 765 | category_view.show_page_switcher (true); | ||
526 | 766 | view_manager.move (grid_view, (columns + 1) * 130, 0); // plus 1 is needed because otherwise grid_view may appear in category view | ||
527 | 767 | view_manager.move (search_view, -columns * 130, 0); | ||
528 | 768 | view_manager.move (category_view, 0, 0); | ||
530 | 769 | 675 | ||
531 | 770 | // remove the padding/margin on the left | 676 | // remove the padding/margin on the left |
532 | 771 | get_content_area ().set_margin_left (PADDINGS.left + SHADOW_SIZE); | 677 | get_content_area ().set_margin_left (PADDINGS.left + SHADOW_SIZE); |
533 | 772 | center.set_margin_left (0); | 678 | center.set_margin_left (0); |
534 | 773 | top.set_margin_left (17); | 679 | top.set_margin_left (17); |
536 | 774 | view_manager.set_size_request (default_columns * 130 + 17, default_rows * 145); | 680 | stack.set_size_request (default_columns * 130 + 17, default_rows * 145); |
537 | 775 | break; | 681 | break; |
538 | 776 | 682 | ||
539 | 777 | case Modality.SEARCH_VIEW: | 683 | case Modality.SEARCH_VIEW: |
540 | 778 | view_selector.hide (); | 684 | view_selector.hide (); |
545 | 779 | bottom.hide (); // Hide the switcher | 685 | stack.set_visible_child_name ("search"); |
542 | 780 | view_manager.move (grid_view, columns * 130, 0); // Move the grid_view away | ||
543 | 781 | view_manager.move (category_view, columns * 130, 0); | ||
544 | 782 | view_manager.move (search_view, 0, 0); // Show the searchview | ||
546 | 783 | 686 | ||
547 | 784 | // change the paddings/margins back to normal | 687 | // change the paddings/margins back to normal |
548 | 785 | get_content_area ().set_margin_left (PADDINGS.left + SHADOW_SIZE + 5); | 688 | get_content_area ().set_margin_left (PADDINGS.left + SHADOW_SIZE + 5); |
549 | 786 | center.set_margin_left (12); | 689 | center.set_margin_left (12); |
550 | 787 | top.set_margin_left (12); | 690 | top.set_margin_left (12); |
552 | 788 | view_manager.set_size_request (default_columns * 130, default_rows * 145); | 691 | stack.set_size_request (default_columns * 130, default_rows * 145); |
553 | 789 | break; | 692 | break; |
554 | 790 | 693 | ||
555 | 791 | } | 694 | } |
556 | 792 | //searchbar.grab_focus (); | ||
557 | 793 | |||
558 | 794 | } | 695 | } |
559 | 795 | 696 | ||
560 | 796 | private async void search (string text) { | 697 | private async void search (string text) { |
561 | @@ -805,7 +706,6 @@ | |||
562 | 805 | if (modality != Modality.SEARCH_VIEW) | 706 | if (modality != Modality.SEARCH_VIEW) |
563 | 806 | set_modality (Modality.SEARCH_VIEW); | 707 | set_modality (Modality.SEARCH_VIEW); |
564 | 807 | search_view_position = 0; | 708 | search_view_position = 0; |
565 | 808 | view_manager.move (search_view, 0, search_view_position); | ||
566 | 809 | search_view.hide_all (); | 709 | search_view.hide_all (); |
567 | 810 | 710 | ||
568 | 811 | var filtered = yield app_system.search_results (stripped); | 711 | var filtered = yield app_system.search_results (stripped); |
569 | @@ -820,12 +720,8 @@ | |||
570 | 820 | 720 | ||
571 | 821 | public void populate_grid_view () { | 721 | public void populate_grid_view () { |
572 | 822 | 722 | ||
573 | 823 | page_switcher.clear_children (); | ||
574 | 824 | grid_view.clear (); | 723 | grid_view.clear (); |
575 | 825 | 724 | ||
576 | 826 | page_switcher.append ("1"); | ||
577 | 827 | page_switcher.set_active (0); | ||
578 | 828 | |||
579 | 829 | foreach (Backend.App app in app_system.get_apps_by_name ()) { | 725 | foreach (Backend.App app in app_system.get_apps_by_name ()) { |
580 | 830 | 726 | ||
581 | 831 | var app_entry = new Widgets.AppEntry (app); | 727 | var app_entry = new Widgets.AppEntry (app); |
582 | @@ -834,7 +730,7 @@ | |||
583 | 834 | app_entry.show_all (); | 730 | app_entry.show_all (); |
584 | 835 | } | 731 | } |
585 | 836 | 732 | ||
587 | 837 | view_manager.move (grid_view, 0, 0); | 733 | stack.set_visible_child_name ("normal"); |
588 | 838 | current_position = 0; | 734 | current_position = 0; |
589 | 839 | 735 | ||
590 | 840 | } | 736 | } |
591 | @@ -861,7 +757,6 @@ | |||
592 | 861 | height_request = default_rows * 145 + 180; | 757 | height_request = default_rows * 145 + 180; |
593 | 862 | 758 | ||
594 | 863 | category_view.app_view.resize (default_rows, default_columns); | 759 | category_view.app_view.resize (default_rows, default_columns); |
595 | 864 | category_view.set_size_request (columns * 130 + 17, view_height); | ||
596 | 865 | category_view.show_filtered_apps (category_view.category_ids.get (category_view.category_switcher.selected)); | 760 | category_view.show_filtered_apps (category_view.category_ids.get (category_view.category_switcher.selected)); |
597 | 866 | } | 761 | } |
598 | 867 | 762 | ||
599 | @@ -869,6 +764,8 @@ | |||
600 | 869 | 764 | ||
601 | 870 | private void normal_move_focus (int delta_column, int delta_row) { | 765 | private void normal_move_focus (int delta_column, int delta_row) { |
602 | 871 | if (get_focus () as Widgets.AppEntry != null) { // we check if any AppEntry has focus. If it does, we move | 766 | if (get_focus () as Widgets.AppEntry != null) { // we check if any AppEntry has focus. If it does, we move |
603 | 767 | if (column_focus + delta_column < 0 || row_focus + delta_row < 0) | ||
604 | 768 | return; | ||
605 | 872 | var new_focus = grid_view.get_child_at (column_focus + delta_column, row_focus + delta_row); // we check if the new widget exists | 769 | var new_focus = grid_view.get_child_at (column_focus + delta_column, row_focus + delta_row); // we check if the new widget exists |
606 | 873 | if (new_focus == null) { | 770 | if (new_focus == null) { |
607 | 874 | if (delta_column <= 0) | 771 | if (delta_column <= 0) |
608 | @@ -883,14 +780,15 @@ | |||
609 | 883 | column_focus += delta_column; | 780 | column_focus += delta_column; |
610 | 884 | row_focus += delta_row; | 781 | row_focus += delta_row; |
611 | 885 | if (delta_column > 0 && column_focus % grid_view.get_page_columns () == 0 ) //check if we need to change page | 782 | if (delta_column > 0 && column_focus % grid_view.get_page_columns () == 0 ) //check if we need to change page |
613 | 886 | page_switcher.set_active (page_switcher.active + 1); | 783 | grid_view.go_to_next (); |
614 | 887 | else if (delta_column < 0 && (column_focus + 1) % grid_view.get_page_columns () == 0) //check if we need to change page | 784 | else if (delta_column < 0 && (column_focus + 1) % grid_view.get_page_columns () == 0) //check if we need to change page |
616 | 888 | page_switcher.set_active (page_switcher.active - 1); | 785 | grid_view.go_to_previous (); |
617 | 889 | new_focus.grab_focus (); | 786 | new_focus.grab_focus (); |
618 | 890 | } | 787 | } |
619 | 891 | else { // we move to the first app in the top left corner of the current page | 788 | else { // we move to the first app in the top left corner of the current page |
622 | 892 | grid_view.get_child_at (page_switcher.active * grid_view.get_page_columns (), 0).grab_focus (); | 789 | column_focus = (grid_view.get_current_page ()-1) * grid_view.get_page_columns (); |
623 | 893 | column_focus = page_switcher.active * grid_view.get_page_columns (); | 790 | if (column_focus >= 0) |
624 | 791 | grid_view.get_child_at (column_focus, 0).grab_focus (); | ||
625 | 894 | row_focus = 0; | 792 | row_focus = 0; |
626 | 895 | } | 793 | } |
627 | 896 | } | 794 | } |
628 | @@ -909,13 +807,13 @@ | |||
629 | 909 | return; | 807 | return; |
630 | 910 | } | 808 | } |
631 | 911 | else if (delta_column > 0 && (category_column_focus + delta_column) % category_view.app_view.get_page_columns () == 0 | 809 | else if (delta_column > 0 && (category_column_focus + delta_column) % category_view.app_view.get_page_columns () == 0 |
634 | 912 | && category_view.switcher.active + 1 != category_view.app_view.get_n_pages ()) { | 810 | && category_view.app_view.get_current_page ()+ 1 != category_view.app_view.get_n_pages ()) { |
635 | 913 | category_view.switcher.set_active (category_view.switcher.active + 1); | 811 | category_view.app_view.go_to_next (); |
636 | 914 | top_left_focus (); | 812 | top_left_focus (); |
637 | 915 | return; | 813 | return; |
638 | 916 | } | 814 | } |
639 | 917 | else if (category_column_focus == 0 && delta_column < 0) { | 815 | else if (category_column_focus == 0 && delta_column < 0) { |
641 | 918 | searchbar.grab_focus (); | 816 | search_entry.grab_focus (); |
642 | 919 | category_column_focus = 0; | 817 | category_column_focus = 0; |
643 | 920 | category_row_focus = 0; | 818 | category_row_focus = 0; |
644 | 921 | return; | 819 | return; |
645 | @@ -926,11 +824,11 @@ | |||
646 | 926 | category_column_focus += delta_column; | 824 | category_column_focus += delta_column; |
647 | 927 | category_row_focus += delta_row; | 825 | category_row_focus += delta_row; |
648 | 928 | if (delta_column > 0 && category_column_focus % category_view.app_view.get_page_columns () == 0 ) { // check if we need to change page | 826 | if (delta_column > 0 && category_column_focus % category_view.app_view.get_page_columns () == 0 ) { // check if we need to change page |
650 | 929 | category_view.switcher.set_active (category_view.switcher.active + 1); | 827 | category_view.app_view.go_to_next (); |
651 | 930 | } | 828 | } |
652 | 931 | else if (delta_column < 0 && (category_column_focus + 1) % category_view.app_view.get_page_columns () == 0) { | 829 | else if (delta_column < 0 && (category_column_focus + 1) % category_view.app_view.get_page_columns () == 0) { |
653 | 932 | // check if we need to change page | 830 | // check if we need to change page |
655 | 933 | category_view.switcher.set_active (category_view.switcher.active - 1); | 831 | category_view.app_view.go_to_previous (); |
656 | 934 | } | 832 | } |
657 | 935 | new_focus.grab_focus (); | 833 | new_focus.grab_focus (); |
658 | 936 | } | 834 | } |
659 | @@ -938,10 +836,10 @@ | |||
660 | 938 | // this method moves focus to the first AppEntry in the top left corner of the current page. Works in CategoryView only | 836 | // this method moves focus to the first AppEntry in the top left corner of the current page. Works in CategoryView only |
661 | 939 | private void top_left_focus () { | 837 | private void top_left_focus () { |
662 | 940 | // this is the first column of the current page | 838 | // this is the first column of the current page |
664 | 941 | int first_column = category_view.switcher.active * category_view.app_view.get_page_columns (); | 839 | int first_column = (grid_view.get_current_page ()-1) * category_view.app_view.get_page_columns (); |
665 | 942 | category_view.app_view.get_child_at (first_column, 0).grab_focus (); | 840 | category_view.app_view.get_child_at (first_column, 0).grab_focus (); |
666 | 943 | category_column_focus = first_column; | 841 | category_column_focus = first_column; |
668 | 944 | category_row_focus = 0; | 842 | category_row_focus = 1; |
669 | 945 | } | 843 | } |
670 | 946 | 844 | ||
671 | 947 | public void reset_category_focus () { | 845 | public void reset_category_focus () { |
672 | 948 | 846 | ||
673 | === modified file 'src/Widgets/AppEntry.vala' | |||
674 | --- src/Widgets/AppEntry.vala 2013-12-26 00:08:04 +0000 | |||
675 | +++ src/Widgets/AppEntry.vala 2014-03-01 15:19:46 +0000 | |||
676 | @@ -104,42 +104,8 @@ | |||
677 | 104 | 104 | ||
678 | 105 | } | 105 | } |
679 | 106 | 106 | ||
680 | 107 | public void fade_out () { | ||
681 | 108 | |||
682 | 109 | Timeout.add (20, () => { | ||
683 | 110 | |||
684 | 111 | if (alpha <= 0.3) { | ||
685 | 112 | queue_draw (); | ||
686 | 113 | return false; | ||
687 | 114 | } | ||
688 | 115 | |||
689 | 116 | alpha -= 0.05; | ||
690 | 117 | queue_draw (); | ||
691 | 118 | return true; | ||
692 | 119 | |||
693 | 120 | }); | ||
694 | 121 | |||
695 | 122 | } | ||
696 | 123 | |||
697 | 124 | public void fade_in () { | ||
698 | 125 | |||
699 | 126 | Timeout.add (20, () => { | ||
700 | 127 | |||
701 | 128 | if (alpha == 1.0) { | ||
702 | 129 | queue_draw (); | ||
703 | 130 | return false; | ||
704 | 131 | } | ||
705 | 132 | |||
706 | 133 | alpha += 0.05; | ||
707 | 134 | queue_draw (); | ||
708 | 135 | return true; | ||
709 | 136 | |||
710 | 137 | }); | ||
711 | 138 | |||
712 | 139 | } | ||
713 | 140 | |||
714 | 141 | public void launch_app () { | 107 | public void launch_app () { |
715 | 142 | application.launch (); | 108 | application.launch (); |
716 | 143 | app_launched (); | 109 | app_launched (); |
717 | 144 | } | 110 | } |
719 | 145 | } | 111 | } |
720 | 146 | \ No newline at end of file | 112 | \ No newline at end of file |
721 | 147 | 113 | ||
722 | === modified file 'src/Widgets/CategoryView.vala' | |||
723 | --- src/Widgets/CategoryView.vala 2013-12-26 00:08:04 +0000 | |||
724 | +++ src/Widgets/CategoryView.vala 2014-03-01 15:19:46 +0000 | |||
725 | @@ -22,17 +22,13 @@ | |||
726 | 22 | public Sidebar category_switcher; | 22 | public Sidebar category_switcher; |
727 | 23 | public Gtk.Separator separator; | 23 | public Gtk.Separator separator; |
728 | 24 | public Widgets.Grid app_view; | 24 | public Widgets.Grid app_view; |
729 | 25 | private Gtk.Layout layout; | ||
730 | 26 | public Switcher switcher; | ||
731 | 27 | private SlingshotView view; | 25 | private SlingshotView view; |
732 | 28 | private Gtk.Label empty_cat_label; | ||
733 | 29 | 26 | ||
734 | 30 | private Gtk.Grid page_switcher; | 27 | private Gtk.Grid page_switcher; |
735 | 31 | 28 | ||
736 | 32 | private const string ALL_APPLICATIONS = _("All Applications"); | 29 | private const string ALL_APPLICATIONS = _("All Applications"); |
737 | 33 | private const string NEW_FILTER = _("Create a new Filter"); | 30 | private const string NEW_FILTER = _("Create a new Filter"); |
738 | 34 | private int current_position = 0; | 31 | private int current_position = 0; |
739 | 35 | private bool from_category = false; | ||
740 | 36 | 32 | ||
741 | 37 | public Gee.HashMap<int, string> category_ids = new Gee.HashMap<int, string> (); | 33 | public Gee.HashMap<int, string> category_ids = new Gee.HashMap<int, string> (); |
742 | 38 | 34 | ||
743 | @@ -53,30 +49,11 @@ | |||
744 | 53 | container = new Gtk.Grid (); | 49 | container = new Gtk.Grid (); |
745 | 54 | separator = new Gtk.Separator (Gtk.Orientation.VERTICAL); | 50 | separator = new Gtk.Separator (Gtk.Orientation.VERTICAL); |
746 | 55 | 51 | ||
747 | 56 | layout = new Gtk.Layout (null, null); | ||
748 | 57 | |||
749 | 58 | app_view = new Widgets.Grid (view.rows, view.columns - 1); | 52 | app_view = new Widgets.Grid (view.rows, view.columns - 1); |
768 | 59 | layout.put (app_view, 0, 0); | 53 | app_view.margin_left = 5; |
751 | 60 | empty_cat_label = new Gtk.Label (""); | ||
752 | 61 | layout.put (empty_cat_label, view.columns*130, view.rows * 130 / 2); | ||
753 | 62 | layout.set_hexpand (true); | ||
754 | 63 | layout.set_vexpand (true); | ||
755 | 64 | |||
756 | 65 | // Create the page switcher | ||
757 | 66 | switcher = new Switcher (); | ||
758 | 67 | |||
759 | 68 | // A bottom widget to keep the page switcher center | ||
760 | 69 | page_switcher = new Gtk.Grid (); | ||
761 | 70 | var bottom_separator1 = new Gtk.Label (""); // A fake label | ||
762 | 71 | bottom_separator1.set_hexpand(true); | ||
763 | 72 | var bottom_separator2 = new Gtk.Label (""); // A fake label | ||
764 | 73 | bottom_separator2.set_hexpand(true); | ||
765 | 74 | page_switcher.attach (bottom_separator1, 0, 0, 1, 1); | ||
766 | 75 | page_switcher.attach (switcher, 1, 0, 1, 1); | ||
767 | 76 | page_switcher.attach (bottom_separator2, 2, 0, 1, 1); | ||
769 | 77 | 54 | ||
770 | 78 | container.attach (separator, 1, 0, 1, 2); | 55 | container.attach (separator, 1, 0, 1, 2); |
772 | 79 | container.attach (layout, 2, 0, 1, 1); | 56 | container.attach (app_view, 2, 0, 1, 1); |
773 | 80 | 57 | ||
774 | 81 | add (container); | 58 | add (container); |
775 | 82 | 59 | ||
776 | @@ -112,40 +89,6 @@ | |||
777 | 112 | 89 | ||
778 | 113 | private void connect_events () { | 90 | private void connect_events () { |
779 | 114 | 91 | ||
780 | 115 | layout.scroll_event.connect ((event) => { | ||
781 | 116 | switch (event.direction.to_string ()) { | ||
782 | 117 | case "GDK_SCROLL_UP": | ||
783 | 118 | case "GDK_SCROLL_LEFT": | ||
784 | 119 | switcher.set_active (switcher.active - 1); | ||
785 | 120 | break; | ||
786 | 121 | case "GDK_SCROLL_DOWN": | ||
787 | 122 | case "GDK_SCROLL_RIGHT": | ||
788 | 123 | switcher.set_active (switcher.active + 1); | ||
789 | 124 | break; | ||
790 | 125 | } | ||
791 | 126 | return false; | ||
792 | 127 | }); | ||
793 | 128 | |||
794 | 129 | app_view.new_page.connect ((page) => { | ||
795 | 130 | |||
796 | 131 | if (switcher.size == 0) | ||
797 | 132 | switcher.append ("1"); | ||
798 | 133 | switcher.append (page); | ||
799 | 134 | |||
800 | 135 | /* Prevents pages from changing */ | ||
801 | 136 | from_category = true; | ||
802 | 137 | }); | ||
803 | 138 | |||
804 | 139 | switcher.active_changed.connect (() => { | ||
805 | 140 | if (from_category || switcher.active - switcher.old_active == 0) { | ||
806 | 141 | from_category = false; | ||
807 | 142 | return; | ||
808 | 143 | } | ||
809 | 144 | |||
810 | 145 | move_page (switcher.active - switcher.old_active); | ||
811 | 146 | view.searchbar.grab_focus (); // this is because otherwise focus isn't the current page | ||
812 | 147 | }); | ||
813 | 148 | |||
814 | 149 | category_switcher.selected = 0; //Must be after everything else | 92 | category_switcher.selected = 0; //Must be after everything else |
815 | 150 | } | 93 | } |
816 | 151 | 94 | ||
817 | @@ -154,55 +97,20 @@ | |||
818 | 154 | var app_entry = new AppEntry (app); | 97 | var app_entry = new AppEntry (app); |
819 | 155 | app_entry.app_launched.connect (() => view.hide ()); | 98 | app_entry.app_launched.connect (() => view.hide ()); |
820 | 156 | app_view.append (app_entry); | 99 | app_view.append (app_entry); |
822 | 157 | app_entry.show_all (); | 100 | app_view.show_all (); |
823 | 158 | 101 | ||
824 | 159 | } | 102 | } |
825 | 160 | 103 | ||
826 | 161 | public void show_filtered_apps (string category) { | 104 | public void show_filtered_apps (string category) { |
827 | 162 | 105 | ||
828 | 163 | switcher.clear_children (); | ||
829 | 164 | app_view.clear (); | 106 | app_view.clear (); |
830 | 165 | |||
831 | 166 | layout.move (empty_cat_label, view.columns*130, view.rows*130 / 2); | ||
832 | 167 | foreach (Backend.App app in view.apps[category]) | 107 | foreach (Backend.App app in view.apps[category]) |
833 | 168 | add_app (app); | 108 | add_app (app); |
834 | 169 | 109 | ||
835 | 170 | switcher.set_active (0); | ||
836 | 171 | |||
837 | 172 | layout.move (app_view, 0, 0); | ||
838 | 173 | current_position = 0; | 110 | current_position = 0; |
839 | 174 | 111 | ||
840 | 175 | } | 112 | } |
841 | 176 | 113 | ||
842 | 177 | public void move_page (int step) { | ||
843 | 178 | |||
844 | 179 | debug ("Moving: step = " + step.to_string ()); | ||
845 | 180 | |||
846 | 181 | if (step == 0) | ||
847 | 182 | return; | ||
848 | 183 | if (step < 0 && current_position >= 0) //Left border | ||
849 | 184 | return; | ||
850 | 185 | if (step > 0 && (-current_position) >= ((app_view.get_n_pages () - 1) * app_view.get_page_columns () * 130)) //Right border | ||
851 | 186 | return; | ||
852 | 187 | |||
853 | 188 | int count = 0; | ||
854 | 189 | int increment = -step*130*(view.columns-1)/10; | ||
855 | 190 | Timeout.add (30/(view.columns-1), () => { | ||
856 | 191 | |||
857 | 192 | if (count >= 10) { | ||
858 | 193 | current_position += -step*130*(view.columns-1) - 10*increment; //We adjust to end of the page | ||
859 | 194 | layout.move (app_view, current_position, 0); | ||
860 | 195 | return false; | ||
861 | 196 | } | ||
862 | 197 | |||
863 | 198 | current_position += increment; | ||
864 | 199 | layout.move (app_view, current_position, 0); | ||
865 | 200 | count++; | ||
866 | 201 | return true; | ||
867 | 202 | |||
868 | 203 | }, Priority.DEFAULT_IDLE); | ||
869 | 204 | } | ||
870 | 205 | |||
871 | 206 | public void show_page_switcher (bool show) { | 114 | public void show_page_switcher (bool show) { |
872 | 207 | 115 | ||
873 | 208 | if (page_switcher.get_parent () == null) | 116 | if (page_switcher.get_parent () == null) |
874 | @@ -210,14 +118,12 @@ | |||
875 | 210 | 118 | ||
876 | 211 | if (show) { | 119 | if (show) { |
877 | 212 | page_switcher.show_all (); | 120 | page_switcher.show_all (); |
878 | 213 | view.bottom.hide (); | ||
879 | 214 | } | 121 | } |
880 | 215 | else | 122 | else |
881 | 216 | page_switcher.hide (); | 123 | page_switcher.hide (); |
882 | 217 | 124 | ||
884 | 218 | view.searchbar.grab_focus (); | 125 | view.search_entry.grab_focus (); |
885 | 219 | 126 | ||
886 | 220 | } | 127 | } |
887 | 221 | 128 | ||
890 | 222 | } | 129 | } |
889 | 223 | |||
891 | 224 | \ No newline at end of file | 130 | \ No newline at end of file |
892 | 225 | 131 | ||
893 | === modified file 'src/Widgets/Grid.vala' | |||
894 | --- src/Widgets/Grid.vala 2013-12-26 00:08:04 +0000 | |||
895 | +++ src/Widgets/Grid.vala 2014-03-01 15:19:46 +0000 | |||
896 | @@ -21,40 +21,70 @@ | |||
897 | 21 | struct Page { | 21 | struct Page { |
898 | 22 | public uint rows; | 22 | public uint rows; |
899 | 23 | public uint columns; | 23 | public uint columns; |
901 | 24 | public uint number; | 24 | public int number; |
902 | 25 | } | 25 | } |
903 | 26 | 26 | ||
907 | 27 | public class Grid : Gtk.Grid { | 27 | public class Grid : Gtk.Box { |
908 | 28 | 28 | public int row_spacing = 20; | |
909 | 29 | public signal void new_page (string page_num); | 29 | public Widgets.Switcher page_switcher; |
910 | 30 | |||
911 | 31 | private Gtk.Stack stack; | ||
912 | 32 | private Gtk.Grid current_grid; | ||
913 | 33 | private Gee.HashMap<int, Gtk.Grid> grids; | ||
914 | 30 | 34 | ||
915 | 31 | private uint current_row = 0; | 35 | private uint current_row = 0; |
916 | 32 | private uint current_col = 0; | 36 | private uint current_col = 0; |
917 | 33 | private Page page; | 37 | private Page page; |
918 | 34 | 38 | ||
919 | 35 | public Grid (int rows, int columns) { | 39 | public Grid (int rows, int columns) { |
921 | 36 | 40 | page.rows = rows; | |
922 | 41 | page.columns = columns; | ||
923 | 42 | page.number = 1; | ||
924 | 43 | var main_grid = new Gtk.Grid (); | ||
925 | 44 | main_grid.orientation = Gtk.Orientation.VERTICAL; | ||
926 | 45 | stack = new Gtk.Stack (); | ||
927 | 46 | stack.transition_type = Gtk.StackTransitionType.SLIDE_LEFT_RIGHT; | ||
928 | 47 | page_switcher = new Widgets.Switcher (); | ||
929 | 48 | page_switcher.set_stack (stack); | ||
930 | 49 | var fake_grid = new Gtk.Grid (); | ||
931 | 50 | fake_grid.hexpand = true; | ||
932 | 51 | var stack_layout = new Gtk.Layout (); | ||
933 | 52 | stack_layout.expand = true; | ||
934 | 53 | stack_layout.add (stack); | ||
935 | 54 | |||
936 | 55 | main_grid.add (stack_layout); | ||
937 | 56 | main_grid.add (fake_grid); | ||
938 | 57 | main_grid.add (page_switcher); | ||
939 | 58 | add (main_grid); | ||
940 | 59 | |||
941 | 60 | grids = new Gee.HashMap<int, Gtk.Grid> (null, null); | ||
942 | 61 | create_new_grid (); | ||
943 | 62 | go_to_number (1); | ||
944 | 63 | } | ||
945 | 64 | |||
946 | 65 | private void create_new_grid () { | ||
947 | 37 | // Grid properties | 66 | // Grid properties |
958 | 38 | row_homogeneous = true; | 67 | current_grid = new Gtk.Grid (); |
959 | 39 | column_homogeneous = true; | 68 | current_grid.expand = true; |
960 | 40 | 69 | current_grid.row_homogeneous = true; | |
961 | 41 | row_spacing = 20; | 70 | current_grid.column_homogeneous = true; |
962 | 42 | column_spacing = 0; | 71 | |
963 | 43 | 72 | current_grid.row_spacing = row_spacing; | |
964 | 44 | page.rows = rows; | 73 | current_grid.column_spacing = 0; |
965 | 45 | page.columns = columns; | 74 | grids.set (page.number, current_grid); |
966 | 46 | page.number = 1; | 75 | stack.add_titled (current_grid, page.number.to_string (), page.number.to_string ()); |
967 | 47 | 76 | ||
968 | 77 | // Fake grids in case there are not enough apps to fill the grid | ||
969 | 78 | current_grid.attach (new Gtk.Grid (), 0, 0, (int)page.columns, (int)page.rows); | ||
970 | 48 | } | 79 | } |
971 | 49 | 80 | ||
972 | 50 | public void append (Gtk.Widget widget) { | 81 | public void append (Gtk.Widget widget) { |
973 | 51 | 82 | ||
974 | 52 | update_position (); | 83 | update_position (); |
975 | 53 | 84 | ||
979 | 54 | var col = current_col + page.columns * (page.number - 1); | 85 | current_grid.attach (widget, (int)current_col, (int)current_row, 1, 1); |
977 | 55 | |||
978 | 56 | this.attach (widget, (int)col, (int)current_row, 1, 1); | ||
980 | 57 | current_col++; | 86 | current_col++; |
981 | 87 | current_grid.show (); | ||
982 | 58 | } | 88 | } |
983 | 59 | 89 | ||
984 | 60 | private void update_position () { | 90 | private void update_position () { |
985 | @@ -66,7 +96,7 @@ | |||
986 | 66 | 96 | ||
987 | 67 | if (current_row == page.rows) { | 97 | if (current_row == page.rows) { |
988 | 68 | page.number++; | 98 | page.number++; |
990 | 69 | new_page (page.number.to_string ()); | 99 | create_new_grid (); |
991 | 70 | current_row = 0; | 100 | current_row = 0; |
992 | 71 | } | 101 | } |
993 | 72 | 102 | ||
994 | @@ -74,16 +104,27 @@ | |||
995 | 74 | 104 | ||
996 | 75 | public void clear () { | 105 | public void clear () { |
997 | 76 | 106 | ||
1002 | 77 | foreach (Gtk.Widget widget in get_children ()) { | 107 | foreach (Gtk.Grid grid in grids.values) { |
1003 | 78 | if (widget.get_parent () != null) | 108 | foreach (Gtk.Widget widget in grid.get_children ()) { |
1004 | 79 | remove (widget); | 109 | widget.destroy (); |
1005 | 80 | widget.destroy (); | 110 | } |
1006 | 111 | grid.destroy (); | ||
1007 | 81 | } | 112 | } |
1008 | 113 | grids.clear (); | ||
1009 | 82 | 114 | ||
1010 | 83 | current_row = 0; | 115 | current_row = 0; |
1011 | 84 | current_col = 0; | 116 | current_col = 0; |
1012 | 85 | page.number = 1; | 117 | page.number = 1; |
1014 | 86 | 118 | create_new_grid (); | |
1015 | 119 | stack.set_visible_child (current_grid); | ||
1016 | 120 | |||
1017 | 121 | } | ||
1018 | 122 | |||
1019 | 123 | public Gtk.Widget get_child_at (int column, int row) { | ||
1020 | 124 | var col = ((int)(column/page.columns))+1; | ||
1021 | 125 | |||
1022 | 126 | var grid = grids.get (col); | ||
1023 | 127 | return grid.get_child_at (column - (int)page.columns*(col-1), row); | ||
1024 | 87 | } | 128 | } |
1025 | 88 | 129 | ||
1026 | 89 | public int get_page_columns () { | 130 | public int get_page_columns () { |
1027 | @@ -104,20 +145,34 @@ | |||
1028 | 104 | 145 | ||
1029 | 105 | } | 146 | } |
1030 | 106 | 147 | ||
1045 | 107 | public void fade_all_out () { | 148 | public int get_current_page () { |
1046 | 108 | 149 | return int.parse (stack.get_visible_child_name ()); | |
1047 | 109 | foreach (Gtk.Widget widget in get_children ()) { | 150 | } |
1048 | 110 | ((AppEntry) widget).fade_out (); | 151 | |
1049 | 111 | } | 152 | public void go_to_next () { |
1050 | 112 | 153 | int page_number = get_current_page ()+1; | |
1051 | 113 | } | 154 | if (page_number <= get_n_pages ()) |
1052 | 114 | 155 | stack.set_visible_child_name ("%d".printf (page_number)); | |
1053 | 115 | public void fade_all_in () { | 156 | |
1054 | 116 | 157 | page_switcher.update_selected (); | |
1055 | 117 | foreach (Gtk.Widget widget in get_children ()) { | 158 | } |
1056 | 118 | ((AppEntry) widget).fade_in (); | 159 | |
1057 | 119 | } | 160 | public void go_to_previous () { |
1058 | 120 | 161 | int page_number = get_current_page ()-1; | |
1059 | 162 | if (page_number > 0) | ||
1060 | 163 | stack.set_visible_child_name ("%d".printf (page_number)); | ||
1061 | 164 | |||
1062 | 165 | page_switcher.update_selected (); | ||
1063 | 166 | } | ||
1064 | 167 | |||
1065 | 168 | public void go_to_last () { | ||
1066 | 169 | stack.set_visible_child_name ("%d".printf (get_n_pages ())); | ||
1067 | 170 | page_switcher.update_selected (); | ||
1068 | 171 | } | ||
1069 | 172 | |||
1070 | 173 | public void go_to_number (int number) { | ||
1071 | 174 | stack.set_visible_child_name ("%d".printf (number)); | ||
1072 | 175 | page_switcher.update_selected (); | ||
1073 | 121 | } | 176 | } |
1074 | 122 | 177 | ||
1075 | 123 | public void resize (int rows, int columns) { | 178 | public void resize (int rows, int columns) { |
1076 | 124 | 179 | ||
1077 | === modified file 'src/Widgets/SearchView.vala' | |||
1078 | --- src/Widgets/SearchView.vala 2013-12-26 00:08:04 +0000 | |||
1079 | +++ src/Widgets/SearchView.vala 2014-03-01 15:19:46 +0000 | |||
1080 | @@ -27,11 +27,12 @@ | |||
1081 | 27 | 27 | ||
1082 | 28 | } | 28 | } |
1083 | 29 | 29 | ||
1085 | 30 | public class SearchView : Gtk.Box { | 30 | public class SearchView : Gtk.ScrolledWindow { |
1086 | 31 | 31 | ||
1087 | 32 | private Gee.HashMap<Backend.App, SearchItem> items; | 32 | private Gee.HashMap<Backend.App, SearchItem> items; |
1088 | 33 | private SeparatorItem separator; | 33 | private SeparatorItem separator; |
1089 | 34 | private SearchItem selected_app = null; | 34 | private SearchItem selected_app = null; |
1090 | 35 | private Gtk.Box main_box; | ||
1091 | 35 | 36 | ||
1092 | 36 | private int _selected = 0; | 37 | private int _selected = 0; |
1093 | 37 | public int selected { | 38 | public int selected { |
1094 | @@ -63,17 +64,23 @@ | |||
1095 | 63 | private SlingshotView view; | 64 | private SlingshotView view; |
1096 | 64 | 65 | ||
1097 | 65 | public SearchView (SlingshotView parent) { | 66 | public SearchView (SlingshotView parent) { |
1102 | 66 | orientation = Gtk.Orientation.VERTICAL; | 67 | main_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); |
1103 | 67 | 68 | main_box.can_focus = true; | |
1104 | 68 | can_focus = true; | 69 | main_box.homogeneous = false; |
1101 | 69 | homogeneous = false; | ||
1105 | 70 | 70 | ||
1106 | 71 | this.view = parent; | 71 | this.view = parent; |
1108 | 72 | width_request = view.columns * 130; | 72 | main_box. width_request = view.columns * 130; |
1109 | 73 | 73 | ||
1110 | 74 | items = new Gee.HashMap<Backend.App, SearchItem> (); | 74 | items = new Gee.HashMap<Backend.App, SearchItem> (); |
1111 | 75 | separator = new SeparatorItem (); | 75 | separator = new SeparatorItem (); |
1112 | 76 | 76 | ||
1113 | 77 | var expand_grid = new Gtk.Grid (); | ||
1114 | 78 | expand_grid.expand = true; | ||
1115 | 79 | var search_grid = new Gtk.Grid (); | ||
1116 | 80 | search_grid.orientation = Gtk.Orientation.VERTICAL; | ||
1117 | 81 | search_grid.add (main_box); | ||
1118 | 82 | search_grid.add (expand_grid); | ||
1119 | 83 | add_with_viewport (search_grid); | ||
1120 | 77 | } | 84 | } |
1121 | 78 | 85 | ||
1122 | 79 | public void add_apps (Gee.ArrayList<Backend.App> apps) { | 86 | public void add_apps (Gee.ArrayList<Backend.App> apps) { |
1123 | @@ -111,7 +118,7 @@ | |||
1124 | 111 | } | 118 | } |
1125 | 112 | 119 | ||
1126 | 113 | if (!(items[app].in_box)) { | 120 | if (!(items[app].in_box)) { |
1128 | 114 | pack_start (items[app], true, true, 0); | 121 | main_box.pack_start (items[app], true, true, 0); |
1129 | 115 | items[app].in_box = true; | 122 | items[app].in_box = true; |
1130 | 116 | items[app].icon_size = 48; | 123 | items[app].icon_size = 48; |
1131 | 117 | items[app].queue_draw (); | 124 | items[app].queue_draw (); |
1132 | @@ -143,10 +150,12 @@ | |||
1133 | 143 | foreach (SearchItem app in items.values) { | 150 | foreach (SearchItem app in items.values) { |
1134 | 144 | app.hide (); | 151 | app.hide (); |
1135 | 145 | if (app.in_box) { | 152 | if (app.in_box) { |
1137 | 146 | remove (app); | 153 | main_box.remove (app); |
1138 | 147 | app.in_box = false; | 154 | app.in_box = false; |
1139 | 148 | } | 155 | } |
1140 | 149 | } | 156 | } |
1141 | 157 | |||
1142 | 158 | vadjustment.value = vadjustment.lower; | ||
1143 | 150 | apps_showed = 0; | 159 | apps_showed = 0; |
1144 | 151 | } | 160 | } |
1145 | 152 | 161 | ||
1146 | @@ -163,7 +172,7 @@ | |||
1147 | 163 | private void show_separator () { | 172 | private void show_separator () { |
1148 | 164 | 173 | ||
1149 | 165 | if (!(separator.in_box)) { | 174 | if (!(separator.in_box)) { |
1151 | 166 | pack_start (separator, true, true, 3); | 175 | main_box.pack_start (separator, true, true, 3); |
1152 | 167 | separator.in_box = true; | 176 | separator.in_box = true; |
1153 | 168 | } | 177 | } |
1154 | 169 | separator.show_all (); | 178 | separator.show_all (); |
1155 | @@ -174,7 +183,7 @@ | |||
1156 | 174 | 183 | ||
1157 | 175 | separator.hide (); | 184 | separator.hide (); |
1158 | 176 | if (separator.in_box) { | 185 | if (separator.in_box) { |
1160 | 177 | remove (separator); | 186 | main_box.remove (separator); |
1161 | 178 | separator.in_box = false; | 187 | separator.in_box = false; |
1162 | 179 | } | 188 | } |
1163 | 180 | 189 | ||
1164 | @@ -185,7 +194,7 @@ | |||
1165 | 185 | if (selected_app != null) | 194 | if (selected_app != null) |
1166 | 186 | selected_app.unset_state_flags (Gtk.StateFlags.PRELIGHT); | 195 | selected_app.unset_state_flags (Gtk.StateFlags.PRELIGHT); |
1167 | 187 | 196 | ||
1169 | 188 | selected_app = (SearchItem) get_children ().nth_data (index); | 197 | selected_app = (SearchItem) main_box.get_children ().nth_data (index); |
1170 | 189 | selected_app.set_state_flags (Gtk.StateFlags.PRELIGHT, false); | 198 | selected_app.set_state_flags (Gtk.StateFlags.PRELIGHT, false); |
1171 | 190 | 199 | ||
1172 | 191 | } | 200 | } |
1173 | 192 | 201 | ||
1174 | === modified file 'src/Widgets/Switcher.vala' | |||
1175 | --- src/Widgets/Switcher.vala 2013-03-10 12:58:37 +0000 | |||
1176 | +++ src/Widgets/Switcher.vala 2014-03-01 15:19:46 +0000 | |||
1177 | @@ -1,6 +1,7 @@ | |||
1178 | 1 | // -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*- | 1 | // -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*- |
1179 | 2 | // | 2 | // |
1180 | 3 | // Copyright (C) 2011-2012 Giulio Collura | 3 | // Copyright (C) 2011-2012 Giulio Collura |
1181 | 4 | // Copyright (C) 2014 Corentin Noël <tintou@mailoo.org> | ||
1182 | 4 | // | 5 | // |
1183 | 5 | // This program is free software: you can redistribute it and/or modify | 6 | // This program is free software: you can redistribute it and/or modify |
1184 | 6 | // it under the terms of the GNU General Public License as published by | 7 | // it under the terms of the GNU General Public License as published by |
1185 | @@ -16,78 +17,106 @@ | |||
1186 | 16 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | 17 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
1187 | 17 | // | 18 | // |
1188 | 18 | 19 | ||
1264 | 19 | using Gtk; | 20 | public class Slingshot.Widgets.Switcher : Gtk.Box { |
1265 | 20 | 21 | ||
1266 | 21 | namespace Slingshot.Widgets { | 22 | public int size { |
1267 | 22 | 23 | get { | |
1268 | 23 | public class Switcher : HBox { | 24 | return (int) buttons.size; |
1269 | 24 | 25 | } | |
1270 | 25 | public signal void active_changed (int active); | 26 | } |
1271 | 26 | 27 | ||
1272 | 27 | public int size { | 28 | private Gtk.Stack stack; |
1273 | 28 | get { | 29 | private Gee.HashMap<Gtk.Widget, Gtk.ToggleButton> buttons; |
1274 | 29 | return (int) get_children ().length (); | 30 | |
1275 | 30 | } | 31 | public Switcher () { |
1276 | 31 | } | 32 | orientation = Gtk.Orientation.HORIZONTAL; |
1277 | 32 | 33 | spacing = 2; | |
1278 | 33 | public int active = -1; | 34 | can_focus = false; |
1279 | 34 | public int old_active = -1; | 35 | buttons = new Gee.HashMap<Gtk.Widget, Gtk.ToggleButton> (null, null); |
1280 | 35 | 36 | pack_start (new Gtk.Grid (), true, true, 0); | |
1281 | 36 | public Switcher (bool with_padding = true) { | 37 | pack_end (new Gtk.Grid (), true, true, 0); |
1282 | 37 | 38 | } | |
1283 | 38 | homogeneous = true; | 39 | |
1284 | 39 | spacing = 2; | 40 | public void set_stack (Gtk.Stack stack) { |
1285 | 40 | 41 | if (this.stack != null) { | |
1286 | 41 | can_focus = false; | 42 | clear_children (); |
1287 | 42 | 43 | } | |
1288 | 43 | } | 44 | this.stack = stack; |
1289 | 44 | 45 | populate_switcher (); | |
1290 | 45 | public void append (string label) { | 46 | connect_stack_signals (); |
1291 | 46 | 47 | update_selected (); | |
1292 | 47 | var button = new ToggleButton.with_label (label); | 48 | } |
1293 | 48 | button.width_request = 30; | 49 | |
1294 | 49 | button.can_focus = false; | 50 | private void add_child (Gtk.Widget widget) { |
1295 | 50 | button.get_style_context ().add_class ("switcher"); | 51 | var button = new Gtk.ToggleButton.with_label ((buttons.size +1).to_string ()); |
1296 | 51 | 52 | button.width_request = 30; | |
1297 | 52 | button.button_release_event.connect (() => { | 53 | button.can_focus = false; |
1298 | 53 | 54 | button.get_style_context ().add_class ("switcher"); | |
1299 | 54 | int select = get_children ().index (button); | 55 | button.button_release_event.connect (() => { |
1300 | 55 | set_active (select); | 56 | foreach (var entry in buttons.entries) { |
1301 | 56 | return true; | 57 | if (entry.value == button) |
1302 | 57 | 58 | on_button_clicked (entry.key); | |
1303 | 58 | }); | 59 | entry.value.active = false; |
1304 | 59 | 60 | } | |
1305 | 60 | add (button); | 61 | button.active = true; |
1306 | 61 | button.show_all (); | 62 | return true; |
1307 | 62 | 63 | }); | |
1308 | 63 | } | 64 | |
1309 | 64 | 65 | add (button); | |
1310 | 65 | public void set_active (int new_active) { | 66 | buttons.set (widget, button); |
1311 | 66 | 67 | if (buttons.size == 1) | |
1312 | 67 | if (new_active >= get_children ().length ()) | 68 | button.active = true; |
1313 | 68 | return; | 69 | } |
1314 | 69 | 70 | ||
1315 | 70 | if (active >= 0) | 71 | public override void show () { |
1316 | 71 | ((ToggleButton) get_children ().nth_data (active)).set_active (false); | 72 | base.show (); |
1317 | 72 | 73 | if (buttons.size <= 1) | |
1318 | 73 | old_active = active; | 74 | hide (); |
1319 | 74 | active = new_active; | 75 | } |
1320 | 75 | active_changed (new_active); | 76 | |
1321 | 76 | ((ToggleButton) get_children ().nth_data (active)).set_active (true); | 77 | |
1322 | 77 | 78 | public override void show_all () { | |
1323 | 78 | } | 79 | base.show_all (); |
1324 | 79 | 80 | if (buttons.size <= 1) | |
1325 | 80 | public void clear_children () { | 81 | hide (); |
1326 | 81 | 82 | } | |
1327 | 82 | foreach (weak Widget button in get_children ()) { | 83 | |
1328 | 83 | button.hide (); | 84 | private void on_button_clicked (Gtk.Widget widget) { |
1329 | 84 | if (button.get_parent () != null) | 85 | stack.set_visible_child (widget); |
1330 | 85 | remove (button); | 86 | } |
1331 | 86 | } | 87 | |
1332 | 87 | 88 | private void populate_switcher () { | |
1333 | 88 | old_active = 0; | 89 | foreach (var child in stack.get_children ()) { |
1334 | 89 | active = 0; | 90 | add_child (child); |
1335 | 90 | 91 | } | |
1336 | 91 | } | 92 | } |
1337 | 92 | } | 93 | |
1338 | 93 | } | 94 | private void on_stack_child_removed (Gtk.Widget widget) { |
1339 | 95 | var button = buttons.get (widget); | ||
1340 | 96 | remove (button); | ||
1341 | 97 | buttons.unset (widget); | ||
1342 | 98 | } | ||
1343 | 99 | |||
1344 | 100 | private void connect_stack_signals () { | ||
1345 | 101 | stack.add.connect_after (add_child); | ||
1346 | 102 | stack.remove.connect_after (on_stack_child_removed); | ||
1347 | 103 | } | ||
1348 | 104 | |||
1349 | 105 | public void clear_children () { | ||
1350 | 106 | foreach (weak Gtk.Widget button in get_children ()) { | ||
1351 | 107 | button.hide (); | ||
1352 | 108 | if (button.get_parent () != null) | ||
1353 | 109 | remove (button); | ||
1354 | 110 | } | ||
1355 | 111 | } | ||
1356 | 112 | |||
1357 | 113 | public void update_selected () { | ||
1358 | 114 | foreach (var entry in buttons.entries) { | ||
1359 | 115 | if (entry.key == stack.get_visible_child ()) { | ||
1360 | 116 | entry.value.active = true; | ||
1361 | 117 | } else { | ||
1362 | 118 | entry.value.active = false; | ||
1363 | 119 | } | ||
1364 | 120 | } | ||
1365 | 121 | } | ||
1366 | 122 | } | ||
1367 | 94 | \ No newline at end of file | 123 | \ No newline at end of file |
It's like this all the time for me: http:// i.imgur. com/NhJH5Mm. png