Merge lp:~tintou/slingshot/gtk+-3.10 into lp:~elementary-pantheon/slingshot/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
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 :

It's like this all the time for me: http://i.imgur.com/NhJH5Mm.png

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
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2014-02-23 19:56:35 +0000
+++ CMakeLists.txt 2014-03-01 15:19:46 +0000
@@ -55,14 +55,14 @@
55endif ()55endif ()
5656
57set (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};")57set (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};")
58set (UI_DEPS "gtk+-3.0>=3.2.0;granite;${ZEITGEIST_DEPS};")58set (UI_DEPS "gtk+-3.0>=3.10.0;granite;${ZEITGEIST_DEPS};")
5959
60find_package (PkgConfig)60find_package (PkgConfig)
61pkg_check_modules (DEPS REQUIRED "${CORE_DEPS}${UI_DEPS}" gthread-2.0)61pkg_check_modules (DEPS REQUIRED "${CORE_DEPS}${UI_DEPS}" gthread-2.0)
6262
63find_package (Vala REQUIRED)63find_package (Vala REQUIRED)
64include (ValaVersion)64include (ValaVersion)
65ensure_vala_version ("0.18.0" MINIMUM)65ensure_vala_version ("0.22.0" MINIMUM)
6666
67include (ValaPrecompile)67include (ValaPrecompile)
68vala_precompile (VALA_C ${APPNAME}68vala_precompile (VALA_C ${APPNAME}
@@ -114,4 +114,4 @@
114add_schema ("org.pantheon.desktop.slingshot.gschema.xml")114add_schema ("org.pantheon.desktop.slingshot.gschema.xml")
115115
116# Translations116# Translations
117add_subdirectory (po)117add_subdirectory (po)
118\ No newline at end of file118\ No newline at end of file
119119
=== modified file 'src/Backend/AppSystem.vala'
--- src/Backend/AppSystem.vala 2013-01-10 16:53:50 +0000
+++ src/Backend/AppSystem.vala 2014-03-01 15:19:46 +0000
@@ -51,8 +51,11 @@
51#if HAVE_ZEITGEIST51#if HAVE_ZEITGEIST
52 rl_service.refresh_popularity ();52 rl_service.refresh_popularity ();
53#endif53#endif
5454 try {
55 apps_menu.load_sync ();55 apps_menu.load_sync ();
56 } catch (Error e) {
57 warning (e.message);
58 }
5659
57 update_categories_index ();60 update_categories_index ();
58 update_apps ();61 update_apps ();
@@ -224,4 +227,4 @@
224227
225 }228 }
226229
227}230}
228\ No newline at end of file231\ No newline at end of file
229232
=== modified file 'src/SlingshotView.vala'
--- src/SlingshotView.vala 2013-12-26 00:08:04 +0000
+++ src/SlingshotView.vala 2014-03-01 15:19:46 +0000
@@ -27,9 +27,8 @@
27 public class SlingshotView : Granite.Widgets.PopOver {27 public class SlingshotView : Granite.Widgets.PopOver {
2828
29 // Widgets29 // Widgets
30 public Granite.Widgets.SearchBar searchbar;30 public Gtk.SearchEntry search_entry;
31 public Gtk.Layout view_manager;31 public Gtk.Stack stack;
32 public Widgets.Switcher page_switcher;
33 public Granite.Widgets.ModeButton view_selector;32 public Granite.Widgets.ModeButton view_selector;
3433
35 // Views34 // Views
@@ -39,7 +38,6 @@
3938
40 public Gtk.Grid top;39 public Gtk.Grid top;
41 public Gtk.Grid center;40 public Gtk.Grid center;
42 public Gtk.Grid bottom;
43 public Gtk.Grid container;41 public Gtk.Grid container;
44 public Gtk.Box content_area;42 public Gtk.Box content_area;
45 private Gtk.EventBox event_box;43 private Gtk.EventBox event_box;
@@ -156,56 +154,43 @@
156 else154 else
157 view_selector.selected = 0;155 view_selector.selected = 0;
158156
159 searchbar = new Granite.Widgets.SearchBar (_("Search Apps…"));157 search_entry = new Gtk.SearchEntry ();
160 searchbar.pause_delay = 200;158 search_entry.placeholder_text = _("Search Apps…");
161 searchbar.width_request = 250;159 search_entry.width_request = 250;
162 searchbar.button_press_event.connect ((e) => {return e.button == 3;});160 search_entry.button_press_event.connect ((e) => {return e.button == 3;});
163161
164 if (Slingshot.settings.show_category_filter) {162 if (Slingshot.settings.show_category_filter) {
165 top.attach (view_selector, 0, 0, 1, 1);163 top.attach (view_selector, 0, 0, 1, 1);
166 }164 }
167 top.attach (top_separator, 1, 0, 1, 1);165 top.attach (top_separator, 1, 0, 1, 1);
168 top.attach (searchbar, 2, 0, 1, 1);166 top.attach (search_entry, 2, 0, 1, 1);
169167
170 center = new Gtk.Grid ();168 center = new Gtk.Grid ();
171 // Create the layout which works like view_manager169
172 view_manager = new Gtk.Layout (null, null);170 stack = new Gtk.Stack ();
173 view_manager.set_size_request (default_columns * 130, default_rows * 145);171 stack.set_size_request (default_columns * 130, default_rows * 145);
174 center.attach (view_manager, 0, 0, 1, 1);172 center.attach (stack, 0, 0, 1, 1);
175173
176 // Create the "NORMAL_VIEW"174 // Create the "NORMAL_VIEW"
175 var scrolled_normal = new Gtk.ScrolledWindow (null, null);
177 grid_view = new Widgets.Grid (default_rows, default_columns);176 grid_view = new Widgets.Grid (default_rows, default_columns);
178 view_manager.put (grid_view, 0, 0);177 scrolled_normal.add_with_viewport (grid_view);
178 stack.add_named (scrolled_normal, "normal");
179179
180 // Create the "SEARCH_VIEW"180 // Create the "SEARCH_VIEW"
181 search_view = new Widgets.SearchView (this);181 search_view = new Widgets.SearchView (this);
182
182 foreach (Gee.ArrayList<Backend.App> app_list in apps.values) {183 foreach (Gee.ArrayList<Backend.App> app_list in apps.values) {
183 search_view.add_apps (app_list);184 search_view.add_apps (app_list);
184 }185 }
185 view_manager.put (search_view, -columns * 130, 0);186 stack.add_named (search_view, "search");
186187
187 // Create the "CATEGORY_VIEW"188 // Create the "CATEGORY_VIEW"
188 category_view = new Widgets.CategoryView (this);189 category_view = new Widgets.CategoryView (this);
189 view_manager.put (category_view, -columns * 130, 0);190 stack.add_named (category_view, "category");
190
191 // Create the page switcher
192 page_switcher = new Widgets.Switcher ();
193
194 // A bottom widget to keep the page switcher center
195 bottom = new Gtk.Grid ();
196
197
198 var bottom_separator1 = new Gtk.Label (""); // A fake label
199 bottom_separator1.set_hexpand (true);
200 var bottom_separator2 = new Gtk.Label (""); // A fake label
201 bottom_separator2.set_hexpand (true);
202 bottom.attach (bottom_separator1, 0, 0, 1, 1); // A fake label
203 bottom.attach (page_switcher, 1, 0, 1, 1);
204 bottom.attach (bottom_separator2, 2, 0, 1, 1); // A fake label
205191
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);
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);
208 container.attach (Utils.set_padding (bottom, 0, 24, 12, 24), 0, 2, 1, 1);
209194
210 event_box = new Gtk.EventBox ();195 event_box = new Gtk.EventBox ();
211 event_box.add (container);196 event_box.add (container);
@@ -277,17 +262,15 @@
277 private void connect_signals () {262 private void connect_signals () {
278263
279 this.focus_in_event.connect (() => {264 this.focus_in_event.connect (() => {
280 searchbar.grab_focus ();265 search_entry.grab_focus ();
281 return false;266 return false;
282 });267 });
283268
284 //view_manager.draw.connect (this.draw_background);
285
286 event_box.key_press_event.connect (on_key_press);269 event_box.key_press_event.connect (on_key_press);
287 searchbar.text_changed_pause.connect ((text) => this.search.begin (text));270 search_entry.search_changed.connect (() => this.search.begin (search_entry.text));
288 searchbar.grab_focus ();271 search_entry.grab_focus ();
289272
290 searchbar.activate.connect (() => {273 search_entry.activate.connect (() => {
291 if (modality == Modality.SEARCH_VIEW) {274 if (modality == Modality.SEARCH_VIEW) {
292 search_view.launch_selected ();275 search_view.launch_selected ();
293 hide ();276 hide ();
@@ -300,15 +283,8 @@
300 search_view.app_launched.connect (() => hide ());283 search_view.app_launched.connect (() => hide ());
301284
302 // This function must be after creating the page switcher285 // This function must be after creating the page switcher
303 grid_view.new_page.connect (page_switcher.append);
304 populate_grid_view ();286 populate_grid_view ();
305287
306 page_switcher.active_changed.connect (() => {
307
308 move_page (page_switcher.active - page_switcher.old_active);
309 searchbar.grab_focus (); //avoid focus is not on current page
310 });
311
312 view_selector.mode_changed.connect (() => {288 view_selector.mode_changed.connect (() => {
313289
314 set_modality ((Modality) view_selector.selected);290 set_modality ((Modality) view_selector.selected);
@@ -383,7 +359,7 @@
383 when an input method is in use (Gtk3 bug?). Key press events are359 when an input method is in use (Gtk3 bug?). Key press events are
384 captured by an Event Box and passed to this function instead.360 captured by an Event Box and passed to this function instead.
385361
386 Events not dealt with here are propagated to the searchbar by the362 Events not dealt with here are propagated to the search_entry by the
387 usual mechanism.363 usual mechanism.
388 */364 */
389 public bool on_key_press (Gdk.EventKey event) {365 public bool on_key_press (Gdk.EventKey event) {
@@ -408,8 +384,8 @@
408 break;384 break;
409385
410 case "Escape":386 case "Escape":
411 if (searchbar.text.length > 0) {387 if (search_entry.text.length > 0) {
412 searchbar.text = "";388 search_entry.text = "";
413 } else {389 } else {
414 hide ();390 hide ();
415 }391 }
@@ -443,25 +419,25 @@
443 case "7":419 case "7":
444 case "8":420 case "8":
445 case "9":421 case "9":
446 int page = int.parse (key) - 1;422 int page = int.parse (key);
447423
448 if (event.state != Gdk.ModifierType.MOD1_MASK)424 if (event.state != Gdk.ModifierType.MOD1_MASK)
449 return false;425 return false;
450426
451 if (modality == Modality.NORMAL_VIEW) {427 if (modality == Modality.NORMAL_VIEW) {
452 if (page < 0 || page == 8)428 if (page < 0 || page == 9)
453 page_switcher.set_active (grid_view.get_n_pages () - 1);429 grid_view.go_to_last ();
454 else430 else
455 page_switcher.set_active (page);431 grid_view.go_to_number (page);
456 } else if (modality == Modality.CATEGORY_VIEW) {432 } else if (modality == Modality.CATEGORY_VIEW) {
457 if (page < 0 || page == 8)433 if (page < 0 || page == 9)
458 category_view.switcher.set_active (category_view.switcher.size - 1);434 category_view.app_view.go_to_last ();
459 else435 else
460 category_view.switcher.set_active (page);436 category_view.app_view.go_to_number (page);
461 } else {437 } else {
462 return false;438 return false;
463 }439 }
464 searchbar.grab_focus ();440 search_entry.grab_focus ();
465 break;441 break;
466442
467 case "Tab":443 case "Tab":
@@ -480,14 +456,15 @@
480456
481 case "Left":457 case "Left":
482 if (modality == Modality.NORMAL_VIEW) {458 if (modality == Modality.NORMAL_VIEW) {
483 if (event.state == Gdk.ModifierType.SHIFT_MASK) // Shift + Left459 if (event.state == Gdk.ModifierType.SHIFT_MASK) {// Shift + Left
484 page_switcher.set_active (page_switcher.active - 1);460 grid_view.go_to_previous ();
485 else461 } else {
486 normal_move_focus (-1, 0);462 normal_move_focus (-1, 0);
463 }
487 } else if (modality == Modality.CATEGORY_VIEW) {464 } else if (modality == Modality.CATEGORY_VIEW) {
488 if (event.state == Gdk.ModifierType.SHIFT_MASK) // Shift + Left465 if (event.state == Gdk.ModifierType.SHIFT_MASK) // Shift + Left
489 category_view.switcher.set_active (category_view.switcher.active - 1);466 category_view.app_view.go_to_previous ();
490 else if (!searchbar.has_focus) {//the user has already selected an AppEntry467 else if (!search_entry.has_focus) {//the user has already selected an AppEntry
491 category_move_focus (-1, 0);468 category_move_focus (-1, 0);
492 }469 }
493 } else470 } else
@@ -497,13 +474,13 @@
497 case "Right":474 case "Right":
498 if (modality == Modality.NORMAL_VIEW) {475 if (modality == Modality.NORMAL_VIEW) {
499 if (event.state == Gdk.ModifierType.SHIFT_MASK) // Shift + Right476 if (event.state == Gdk.ModifierType.SHIFT_MASK) // Shift + Right
500 page_switcher.set_active (page_switcher.active + 1);477 grid_view.go_to_next ();
501 else478 else
502 normal_move_focus (+1, 0);479 normal_move_focus (+1, 0);
503 } else if (modality == Modality.CATEGORY_VIEW) {480 } else if (modality == Modality.CATEGORY_VIEW) {
504 if (event.state == Gdk.ModifierType.SHIFT_MASK) // Shift + Right481 if (event.state == Gdk.ModifierType.SHIFT_MASK) // Shift + Right
505 category_view.switcher.set_active (category_view.switcher.active + 1);482 category_view.app_view.go_to_next ();
506 else if (searchbar.has_focus) // there's no AppEntry selected, the user is switching category483 else if (search_entry.has_focus) // there's no AppEntry selected, the user is switching category
507 top_left_focus ();484 top_left_focus ();
508 else //the user has already selected an AppEntry485 else //the user has already selected an AppEntry
509 category_move_focus (+1, 0);486 category_move_focus (+1, 0);
@@ -521,14 +498,13 @@
521 category_view.category_switcher.selected--;498 category_view.category_switcher.selected--;
522 top_left_focus ();499 top_left_focus ();
523 }500 }
524 } else if (searchbar.has_focus) {501 } else if (search_entry.has_focus) {
525 category_view.category_switcher.selected--;502 category_view.category_switcher.selected--;
526 } else {503 } else {
527 category_move_focus (0, -1);504 category_move_focus (0, -1);
528 }505 }
529 } else if (modality == Modality.SEARCH_VIEW) {506 } else if (modality == Modality.SEARCH_VIEW) {
530 search_view.selected--;507 search_view.selected--;
531 search_view_up ();
532 }508 }
533 break;509 break;
534510
@@ -539,23 +515,19 @@
539 if (event.state == Gdk.ModifierType.SHIFT_MASK) { // Shift + Down515 if (event.state == Gdk.ModifierType.SHIFT_MASK) { // Shift + Down
540 category_view.category_switcher.selected++;516 category_view.category_switcher.selected++;
541 top_left_focus ();517 top_left_focus ();
542 } else if (searchbar.has_focus) {518 } else if (search_entry.has_focus) {
543 category_view.category_switcher.selected++;519 category_view.category_switcher.selected++;
544 } else { // the user has already selected an AppEntry520 } else { // the user has already selected an AppEntry
545 category_move_focus (0, +1);521 category_move_focus (0, +1);
546 }522 }
547 } else if (modality == Modality.SEARCH_VIEW) {523 } else if (modality == Modality.SEARCH_VIEW) {
548 search_view.selected++;524 search_view.selected++;
549 if (search_view.selected > 7)
550 search_view_down ();
551 }525 }
552 break;526 break;
553527
554 case "Page_Up":528 case "Page_Up":
555 if (modality == Modality.NORMAL_VIEW) {529 if (modality == Modality.NORMAL_VIEW) {
556 page_switcher.set_active (page_switcher.active - 1);530 grid_view.go_to_previous ();
557 if (page_switcher.active != 0) // we don't wanna lose focus if we don't actually change page
558 searchbar.grab_focus (); // this is because otherwise focus isn't the current page
559 } else if (modality == Modality.CATEGORY_VIEW) {531 } else if (modality == Modality.CATEGORY_VIEW) {
560 category_view.category_switcher.selected--;532 category_view.category_switcher.selected--;
561 top_left_focus ();533 top_left_focus ();
@@ -564,9 +536,7 @@
564536
565 case "Page_Down":537 case "Page_Down":
566 if (modality == Modality.NORMAL_VIEW) {538 if (modality == Modality.NORMAL_VIEW) {
567 page_switcher.set_active (page_switcher.active + 1);539 grid_view.go_to_next ();
568 if (page_switcher.active != grid_view.get_n_pages () - 1) // we don't wanna lose focus if we don't actually change page
569 searchbar.grab_focus (); //this is because otherwise focus isn't the current page
570 } else if (modality == Modality.CATEGORY_VIEW) {540 } else if (modality == Modality.CATEGORY_VIEW) {
571 category_view.category_switcher.selected++;541 category_view.category_switcher.selected++;
572 top_left_focus ();542 top_left_focus ();
@@ -575,23 +545,23 @@
575545
576 case "BackSpace":546 case "BackSpace":
577 if (event.state == Gdk.ModifierType.SHIFT_MASK) { // Shift + Delete547 if (event.state == Gdk.ModifierType.SHIFT_MASK) { // Shift + Delete
578 searchbar.text = "";548 search_entry.text = "";
579 } else if (searchbar.has_focus) {549 } else if (search_entry.has_focus) {
580 return false;550 return false;
581 } else {551 } else {
582 searchbar.grab_focus ();552 search_entry.grab_focus ();
583 searchbar.move_cursor (Gtk.MovementStep.BUFFER_ENDS, 0, false);553 search_entry.move_cursor (Gtk.MovementStep.BUFFER_ENDS, 0, false);
584 return false;554 return false;
585 }555 }
586 break;556 break;
587557
588 case "Home":558 case "Home":
589 if (searchbar.text.length > 0) {559 if (search_entry.text.length > 0) {
590 return false;560 return false;
591 }561 }
592562
593 if (modality == Modality.NORMAL_VIEW) {563 if (modality == Modality.NORMAL_VIEW) {
594 page_switcher.set_active (0);564 grid_view.go_to_number (1);
595 } else if (modality == Modality.CATEGORY_VIEW) {565 } else if (modality == Modality.CATEGORY_VIEW) {
596 category_view.category_switcher.selected = 0;566 category_view.category_switcher.selected = 0;
597 top_left_focus ();567 top_left_focus ();
@@ -599,12 +569,12 @@
599 break;569 break;
600570
601 case "End":571 case "End":
602 if (searchbar.text.length > 0) {572 if (search_entry.text.length > 0) {
603 return false;573 return false;
604 }574 }
605575
606 if (modality == Modality.NORMAL_VIEW) {576 if (modality == Modality.NORMAL_VIEW) {
607 page_switcher.set_active (grid_view.get_n_pages () - 1);577 grid_view.go_to_last ();
608 } else if (modality == Modality.CATEGORY_VIEW) {578 } else if (modality == Modality.CATEGORY_VIEW) {
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;
610 top_left_focus ();580 top_left_focus ();
@@ -614,14 +584,14 @@
614 case "v":584 case "v":
615 case "V":585 case "V":
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) {
617 searchbar.paste_clipboard ();587 search_entry.paste_clipboard ();
618 }588 }
619 break;589 break;
620590
621 default:591 default:
622 if (!searchbar.has_focus) {592 if (!search_entry.has_focus) {
623 searchbar.grab_focus ();593 search_entry.grab_focus ();
624 searchbar.move_cursor (Gtk.MovementStep.BUFFER_ENDS, 0, false);594 search_entry.move_cursor (Gtk.MovementStep.BUFFER_ENDS, 0, false);
625 }595 }
626 return false;596 return false;
627597
@@ -637,20 +607,16 @@
637 case "GDK_SCROLL_UP":607 case "GDK_SCROLL_UP":
638 case "GDK_SCROLL_LEFT":608 case "GDK_SCROLL_LEFT":
639 if (modality == Modality.NORMAL_VIEW)609 if (modality == Modality.NORMAL_VIEW)
640 page_switcher.set_active (page_switcher.active - 1);610 grid_view.go_to_previous ();
641 else if (modality == Modality.SEARCH_VIEW)611 else if (modality == Modality.CATEGORY_VIEW)
642 search_view_up ();612 category_view.app_view.go_to_previous ();
643 else
644 category_view.switcher.set_active (category_view.switcher.active - 1);
645 break;613 break;
646 case "GDK_SCROLL_DOWN":614 case "GDK_SCROLL_DOWN":
647 case "GDK_SCROLL_RIGHT":615 case "GDK_SCROLL_RIGHT":
648 if (modality == Modality.NORMAL_VIEW)616 if (modality == Modality.NORMAL_VIEW)
649 page_switcher.set_active (page_switcher.active + 1);617 grid_view.go_to_next ();
650 else if (modality == Modality.SEARCH_VIEW)618 else if (modality == Modality.CATEGORY_VIEW)
651 search_view_down ();619 category_view.app_view.go_to_next ();
652 else
653 category_view.switcher.set_active (category_view.switcher.active + 1);
654 break;620 break;
655621
656 }622 }
@@ -661,14 +627,14 @@
661627
662 public void show_slingshot () {628 public void show_slingshot () {
663629
664 searchbar.text = "";630 search_entry.text = "";
665631
666 reposition ();632 reposition ();
667 show_all ();633 show_all ();
668 present ();634 present ();
669635
670 set_focus(null);636 set_focus(null);
671 searchbar.grab_focus ();637 search_entry.grab_focus ();
672 set_modality ((Modality) view_selector.selected);638 set_modality ((Modality) view_selector.selected);
673639
674 while (Gtk.events_pending ())640 while (Gtk.events_pending ())
@@ -681,56 +647,6 @@
681 w.activate (Gdk.x11_get_server_time (this.get_window ()));647 w.activate (Gdk.x11_get_server_time (this.get_window ()));
682 }648 }
683649
684 private void move_page (int step) {
685
686 debug ("Moving: step = " + step.to_string ());
687
688 if (step == 0)
689 return;
690 if (step < 0 && current_position >= 0) //Left border
691 return;
692 if (step > 0 && (-current_position) >= ((grid_view.get_n_pages () - 1) * grid_view.get_page_columns () * 130)) //Right border
693 return;
694
695 int count = 0;
696 int increment = -step * 130 * columns / 10;
697 Timeout.add (30 / columns, () => {
698
699 if (count >= 10) {
700 current_position += -step * 130 * columns - 10 * increment; //We adjust to end of the page
701 view_manager.move (grid_view, current_position, 0);
702 return false;
703 }
704
705 current_position += increment;
706 view_manager.move (grid_view, current_position, 0);
707 count++;
708 return true;
709
710 }, Priority.DEFAULT_IDLE);
711 }
712
713 private void search_view_down () {
714
715 if (search_view.apps_showed < default_rows * 3)
716 return;
717
718 if ((search_view_position) > -(search_view.apps_showed * 48)) {
719 view_manager.move (search_view, 0, search_view_position - 2 * 38);
720 search_view_position -= 2 * 38;
721 }
722
723 }
724
725 private void search_view_up () {
726
727 if (search_view_position < 0) {
728 view_manager.move (search_view, 0, search_view_position + 2 * 38);
729 search_view_position += 2 * 38;
730 }
731
732 }
733
734 private void set_modality (Modality new_modality) {650 private void set_modality (Modality new_modality) {
735651
736 modality = new_modality;652 modality = new_modality;
@@ -740,57 +656,42 @@
740656
741 if (Slingshot.settings.use_category)657 if (Slingshot.settings.use_category)
742 Slingshot.settings.use_category = false;658 Slingshot.settings.use_category = false;
743 bottom.show ();
744 view_selector.show_all ();659 view_selector.show_all ();
745 page_switcher.show_all ();660 stack.set_visible_child_name ("normal");
746 category_view.show_page_switcher (false);
747 view_manager.move (search_view, - 130 * columns, 0);
748 view_manager.move (category_view, 130 * columns, 0);
749 view_manager.move (grid_view, current_position, 0);
750661
751 // change the paddings/margins back to normal662 // change the paddings/margins back to normal
752 get_content_area ().set_margin_left (PADDINGS.left + SHADOW_SIZE + 5);663 get_content_area ().set_margin_left (PADDINGS.left + SHADOW_SIZE + 5);
753 center.set_margin_left (12);664 center.set_margin_left (12);
754 top.set_margin_left (12);665 top.set_margin_left (12);
755 view_manager.set_size_request (default_columns * 130, default_rows * 145);666 stack.set_size_request (default_columns * 130, default_rows * 145);
756 break;667 break;
757668
758 case Modality.CATEGORY_VIEW:669 case Modality.CATEGORY_VIEW:
759670
760 if (!Slingshot.settings.use_category)671 if (!Slingshot.settings.use_category)
761 Slingshot.settings.use_category = true;672 Slingshot.settings.use_category = true;
762 bottom.show ();
763 view_selector.show_all ();673 view_selector.show_all ();
764 page_switcher.hide ();674 stack.set_visible_child_name ("category");
765 category_view.show_page_switcher (true);
766 view_manager.move (grid_view, (columns + 1) * 130, 0); // plus 1 is needed because otherwise grid_view may appear in category view
767 view_manager.move (search_view, -columns * 130, 0);
768 view_manager.move (category_view, 0, 0);
769675
770 // remove the padding/margin on the left676 // remove the padding/margin on the left
771 get_content_area ().set_margin_left (PADDINGS.left + SHADOW_SIZE);677 get_content_area ().set_margin_left (PADDINGS.left + SHADOW_SIZE);
772 center.set_margin_left (0);678 center.set_margin_left (0);
773 top.set_margin_left (17);679 top.set_margin_left (17);
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);
775 break;681 break;
776682
777 case Modality.SEARCH_VIEW:683 case Modality.SEARCH_VIEW:
778 view_selector.hide ();684 view_selector.hide ();
779 bottom.hide (); // Hide the switcher685 stack.set_visible_child_name ("search");
780 view_manager.move (grid_view, columns * 130, 0); // Move the grid_view away
781 view_manager.move (category_view, columns * 130, 0);
782 view_manager.move (search_view, 0, 0); // Show the searchview
783686
784 // change the paddings/margins back to normal687 // change the paddings/margins back to normal
785 get_content_area ().set_margin_left (PADDINGS.left + SHADOW_SIZE + 5);688 get_content_area ().set_margin_left (PADDINGS.left + SHADOW_SIZE + 5);
786 center.set_margin_left (12);689 center.set_margin_left (12);
787 top.set_margin_left (12);690 top.set_margin_left (12);
788 view_manager.set_size_request (default_columns * 130, default_rows * 145);691 stack.set_size_request (default_columns * 130, default_rows * 145);
789 break;692 break;
790693
791 }694 }
792 //searchbar.grab_focus ();
793
794 }695 }
795696
796 private async void search (string text) {697 private async void search (string text) {
@@ -805,7 +706,6 @@
805 if (modality != Modality.SEARCH_VIEW)706 if (modality != Modality.SEARCH_VIEW)
806 set_modality (Modality.SEARCH_VIEW);707 set_modality (Modality.SEARCH_VIEW);
807 search_view_position = 0;708 search_view_position = 0;
808 view_manager.move (search_view, 0, search_view_position);
809 search_view.hide_all ();709 search_view.hide_all ();
810710
811 var filtered = yield app_system.search_results (stripped);711 var filtered = yield app_system.search_results (stripped);
@@ -820,12 +720,8 @@
820720
821 public void populate_grid_view () {721 public void populate_grid_view () {
822722
823 page_switcher.clear_children ();
824 grid_view.clear ();723 grid_view.clear ();
825724
826 page_switcher.append ("1");
827 page_switcher.set_active (0);
828
829 foreach (Backend.App app in app_system.get_apps_by_name ()) {725 foreach (Backend.App app in app_system.get_apps_by_name ()) {
830726
831 var app_entry = new Widgets.AppEntry (app);727 var app_entry = new Widgets.AppEntry (app);
@@ -834,7 +730,7 @@
834 app_entry.show_all ();730 app_entry.show_all ();
835 }731 }
836732
837 view_manager.move (grid_view, 0, 0);733 stack.set_visible_child_name ("normal");
838 current_position = 0;734 current_position = 0;
839735
840 }736 }
@@ -861,7 +757,6 @@
861 height_request = default_rows * 145 + 180;757 height_request = default_rows * 145 + 180;
862758
863 category_view.app_view.resize (default_rows, default_columns);759 category_view.app_view.resize (default_rows, default_columns);
864 category_view.set_size_request (columns * 130 + 17, view_height);
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));
866 }761 }
867762
@@ -869,6 +764,8 @@
869764
870 private void normal_move_focus (int delta_column, int delta_row) {765 private void normal_move_focus (int delta_column, int delta_row) {
871 if (get_focus () as Widgets.AppEntry != null) { // we check if any AppEntry has focus. If it does, we move766 if (get_focus () as Widgets.AppEntry != null) { // we check if any AppEntry has focus. If it does, we move
767 if (column_focus + delta_column < 0 || row_focus + delta_row < 0)
768 return;
872 var new_focus = grid_view.get_child_at (column_focus + delta_column, row_focus + delta_row); // we check if the new widget exists769 var new_focus = grid_view.get_child_at (column_focus + delta_column, row_focus + delta_row); // we check if the new widget exists
873 if (new_focus == null) {770 if (new_focus == null) {
874 if (delta_column <= 0)771 if (delta_column <= 0)
@@ -883,14 +780,15 @@
883 column_focus += delta_column;780 column_focus += delta_column;
884 row_focus += delta_row;781 row_focus += delta_row;
885 if (delta_column > 0 && column_focus % grid_view.get_page_columns () == 0 ) //check if we need to change page782 if (delta_column > 0 && column_focus % grid_view.get_page_columns () == 0 ) //check if we need to change page
886 page_switcher.set_active (page_switcher.active + 1);783 grid_view.go_to_next ();
887 else if (delta_column < 0 && (column_focus + 1) % grid_view.get_page_columns () == 0) //check if we need to change page784 else if (delta_column < 0 && (column_focus + 1) % grid_view.get_page_columns () == 0) //check if we need to change page
888 page_switcher.set_active (page_switcher.active - 1);785 grid_view.go_to_previous ();
889 new_focus.grab_focus ();786 new_focus.grab_focus ();
890 }787 }
891 else { // we move to the first app in the top left corner of the current page788 else { // we move to the first app in the top left corner of the current page
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 ();
893 column_focus = page_switcher.active * grid_view.get_page_columns ();790 if (column_focus >= 0)
791 grid_view.get_child_at (column_focus, 0).grab_focus ();
894 row_focus = 0;792 row_focus = 0;
895 }793 }
896 }794 }
@@ -909,13 +807,13 @@
909 return;807 return;
910 }808 }
911 else if (delta_column > 0 && (category_column_focus + delta_column) % category_view.app_view.get_page_columns () == 0809 else if (delta_column > 0 && (category_column_focus + delta_column) % category_view.app_view.get_page_columns () == 0
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 ()) {
913 category_view.switcher.set_active (category_view.switcher.active + 1);811 category_view.app_view.go_to_next ();
914 top_left_focus ();812 top_left_focus ();
915 return;813 return;
916 }814 }
917 else if (category_column_focus == 0 && delta_column < 0) {815 else if (category_column_focus == 0 && delta_column < 0) {
918 searchbar.grab_focus ();816 search_entry.grab_focus ();
919 category_column_focus = 0;817 category_column_focus = 0;
920 category_row_focus = 0;818 category_row_focus = 0;
921 return;819 return;
@@ -926,11 +824,11 @@
926 category_column_focus += delta_column;824 category_column_focus += delta_column;
927 category_row_focus += delta_row;825 category_row_focus += delta_row;
928 if (delta_column > 0 && category_column_focus % category_view.app_view.get_page_columns () == 0 ) { // check if we need to change page826 if (delta_column > 0 && category_column_focus % category_view.app_view.get_page_columns () == 0 ) { // check if we need to change page
929 category_view.switcher.set_active (category_view.switcher.active + 1);827 category_view.app_view.go_to_next ();
930 }828 }
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) {
932 // check if we need to change page830 // check if we need to change page
933 category_view.switcher.set_active (category_view.switcher.active - 1);831 category_view.app_view.go_to_previous ();
934 }832 }
935 new_focus.grab_focus ();833 new_focus.grab_focus ();
936 }834 }
@@ -938,10 +836,10 @@
938 // this method moves focus to the first AppEntry in the top left corner of the current page. Works in CategoryView only836 // this method moves focus to the first AppEntry in the top left corner of the current page. Works in CategoryView only
939 private void top_left_focus () {837 private void top_left_focus () {
940 // this is the first column of the current page838 // this is the first column of the current page
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 ();
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 ();
943 category_column_focus = first_column;841 category_column_focus = first_column;
944 category_row_focus = 0;842 category_row_focus = 1;
945 }843 }
946844
947 public void reset_category_focus () {845 public void reset_category_focus () {
948846
=== modified file 'src/Widgets/AppEntry.vala'
--- src/Widgets/AppEntry.vala 2013-12-26 00:08:04 +0000
+++ src/Widgets/AppEntry.vala 2014-03-01 15:19:46 +0000
@@ -104,42 +104,8 @@
104104
105 }105 }
106106
107 public void fade_out () {
108
109 Timeout.add (20, () => {
110
111 if (alpha <= 0.3) {
112 queue_draw ();
113 return false;
114 }
115
116 alpha -= 0.05;
117 queue_draw ();
118 return true;
119
120 });
121
122 }
123
124 public void fade_in () {
125
126 Timeout.add (20, () => {
127
128 if (alpha == 1.0) {
129 queue_draw ();
130 return false;
131 }
132
133 alpha += 0.05;
134 queue_draw ();
135 return true;
136
137 });
138
139 }
140
141 public void launch_app () {107 public void launch_app () {
142 application.launch ();108 application.launch ();
143 app_launched ();109 app_launched ();
144 }110 }
145}111}
146\ No newline at end of file112\ No newline at end of file
147113
=== modified file 'src/Widgets/CategoryView.vala'
--- src/Widgets/CategoryView.vala 2013-12-26 00:08:04 +0000
+++ src/Widgets/CategoryView.vala 2014-03-01 15:19:46 +0000
@@ -22,17 +22,13 @@
22 public Sidebar category_switcher;22 public Sidebar category_switcher;
23 public Gtk.Separator separator;23 public Gtk.Separator separator;
24 public Widgets.Grid app_view;24 public Widgets.Grid app_view;
25 private Gtk.Layout layout;
26 public Switcher switcher;
27 private SlingshotView view;25 private SlingshotView view;
28 private Gtk.Label empty_cat_label;
2926
30 private Gtk.Grid page_switcher;27 private Gtk.Grid page_switcher;
3128
32 private const string ALL_APPLICATIONS = _("All Applications");29 private const string ALL_APPLICATIONS = _("All Applications");
33 private const string NEW_FILTER = _("Create a new Filter");30 private const string NEW_FILTER = _("Create a new Filter");
34 private int current_position = 0;31 private int current_position = 0;
35 private bool from_category = false;
3632
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> ();
3834
@@ -53,30 +49,11 @@
53 container = new Gtk.Grid ();49 container = new Gtk.Grid ();
54 separator = new Gtk.Separator (Gtk.Orientation.VERTICAL);50 separator = new Gtk.Separator (Gtk.Orientation.VERTICAL);
5551
56 layout = new Gtk.Layout (null, null);
57
58 app_view = new Widgets.Grid (view.rows, view.columns - 1);52 app_view = new Widgets.Grid (view.rows, view.columns - 1);
59 layout.put (app_view, 0, 0);53 app_view.margin_left = 5;
60 empty_cat_label = new Gtk.Label ("");
61 layout.put (empty_cat_label, view.columns*130, view.rows * 130 / 2);
62 layout.set_hexpand (true);
63 layout.set_vexpand (true);
64
65 // Create the page switcher
66 switcher = new Switcher ();
67
68 // A bottom widget to keep the page switcher center
69 page_switcher = new Gtk.Grid ();
70 var bottom_separator1 = new Gtk.Label (""); // A fake label
71 bottom_separator1.set_hexpand(true);
72 var bottom_separator2 = new Gtk.Label (""); // A fake label
73 bottom_separator2.set_hexpand(true);
74 page_switcher.attach (bottom_separator1, 0, 0, 1, 1);
75 page_switcher.attach (switcher, 1, 0, 1, 1);
76 page_switcher.attach (bottom_separator2, 2, 0, 1, 1);
7754
78 container.attach (separator, 1, 0, 1, 2);55 container.attach (separator, 1, 0, 1, 2);
79 container.attach (layout, 2, 0, 1, 1);56 container.attach (app_view, 2, 0, 1, 1);
8057
81 add (container);58 add (container);
8259
@@ -112,40 +89,6 @@
11289
113 private void connect_events () {90 private void connect_events () {
11491
115 layout.scroll_event.connect ((event) => {
116 switch (event.direction.to_string ()) {
117 case "GDK_SCROLL_UP":
118 case "GDK_SCROLL_LEFT":
119 switcher.set_active (switcher.active - 1);
120 break;
121 case "GDK_SCROLL_DOWN":
122 case "GDK_SCROLL_RIGHT":
123 switcher.set_active (switcher.active + 1);
124 break;
125 }
126 return false;
127 });
128
129 app_view.new_page.connect ((page) => {
130
131 if (switcher.size == 0)
132 switcher.append ("1");
133 switcher.append (page);
134
135 /* Prevents pages from changing */
136 from_category = true;
137 });
138
139 switcher.active_changed.connect (() => {
140 if (from_category || switcher.active - switcher.old_active == 0) {
141 from_category = false;
142 return;
143 }
144
145 move_page (switcher.active - switcher.old_active);
146 view.searchbar.grab_focus (); // this is because otherwise focus isn't the current page
147 });
148
149 category_switcher.selected = 0; //Must be after everything else92 category_switcher.selected = 0; //Must be after everything else
150 }93 }
15194
@@ -154,55 +97,20 @@
154 var app_entry = new AppEntry (app);97 var app_entry = new AppEntry (app);
155 app_entry.app_launched.connect (() => view.hide ());98 app_entry.app_launched.connect (() => view.hide ());
156 app_view.append (app_entry);99 app_view.append (app_entry);
157 app_entry.show_all ();100 app_view.show_all ();
158101
159 }102 }
160103
161 public void show_filtered_apps (string category) {104 public void show_filtered_apps (string category) {
162105
163 switcher.clear_children ();
164 app_view.clear ();106 app_view.clear ();
165
166 layout.move (empty_cat_label, view.columns*130, view.rows*130 / 2);
167 foreach (Backend.App app in view.apps[category])107 foreach (Backend.App app in view.apps[category])
168 add_app (app);108 add_app (app);
169109
170 switcher.set_active (0);
171
172 layout.move (app_view, 0, 0);
173 current_position = 0;110 current_position = 0;
174111
175 }112 }
176113
177 public void move_page (int step) {
178
179 debug ("Moving: step = " + step.to_string ());
180
181 if (step == 0)
182 return;
183 if (step < 0 && current_position >= 0) //Left border
184 return;
185 if (step > 0 && (-current_position) >= ((app_view.get_n_pages () - 1) * app_view.get_page_columns () * 130)) //Right border
186 return;
187
188 int count = 0;
189 int increment = -step*130*(view.columns-1)/10;
190 Timeout.add (30/(view.columns-1), () => {
191
192 if (count >= 10) {
193 current_position += -step*130*(view.columns-1) - 10*increment; //We adjust to end of the page
194 layout.move (app_view, current_position, 0);
195 return false;
196 }
197
198 current_position += increment;
199 layout.move (app_view, current_position, 0);
200 count++;
201 return true;
202
203 }, Priority.DEFAULT_IDLE);
204 }
205
206 public void show_page_switcher (bool show) {114 public void show_page_switcher (bool show) {
207115
208 if (page_switcher.get_parent () == null)116 if (page_switcher.get_parent () == null)
@@ -210,14 +118,12 @@
210118
211 if (show) {119 if (show) {
212 page_switcher.show_all ();120 page_switcher.show_all ();
213 view.bottom.hide ();
214 }121 }
215 else122 else
216 page_switcher.hide ();123 page_switcher.hide ();
217124
218 view.searchbar.grab_focus ();125 view.search_entry.grab_focus ();
219126
220 }127 }
221128
222}129}
223
224\ No newline at end of file130\ No newline at end of file
225131
=== modified file 'src/Widgets/Grid.vala'
--- src/Widgets/Grid.vala 2013-12-26 00:08:04 +0000
+++ src/Widgets/Grid.vala 2014-03-01 15:19:46 +0000
@@ -21,40 +21,70 @@
21 struct Page {21 struct Page {
22 public uint rows;22 public uint rows;
23 public uint columns;23 public uint columns;
24 public uint number;24 public int number;
25 }25 }
2626
27 public class Grid : Gtk.Grid {27 public class Grid : Gtk.Box {
2828 public int row_spacing = 20;
29 public signal void new_page (string page_num);29 public Widgets.Switcher page_switcher;
30
31 private Gtk.Stack stack;
32 private Gtk.Grid current_grid;
33 private Gee.HashMap<int, Gtk.Grid> grids;
3034
31 private uint current_row = 0;35 private uint current_row = 0;
32 private uint current_col = 0;36 private uint current_col = 0;
33 private Page page;37 private Page page;
3438
35 public Grid (int rows, int columns) {39 public Grid (int rows, int columns) {
3640 page.rows = rows;
41 page.columns = columns;
42 page.number = 1;
43 var main_grid = new Gtk.Grid ();
44 main_grid.orientation = Gtk.Orientation.VERTICAL;
45 stack = new Gtk.Stack ();
46 stack.transition_type = Gtk.StackTransitionType.SLIDE_LEFT_RIGHT;
47 page_switcher = new Widgets.Switcher ();
48 page_switcher.set_stack (stack);
49 var fake_grid = new Gtk.Grid ();
50 fake_grid.hexpand = true;
51 var stack_layout = new Gtk.Layout ();
52 stack_layout.expand = true;
53 stack_layout.add (stack);
54
55 main_grid.add (stack_layout);
56 main_grid.add (fake_grid);
57 main_grid.add (page_switcher);
58 add (main_grid);
59
60 grids = new Gee.HashMap<int, Gtk.Grid> (null, null);
61 create_new_grid ();
62 go_to_number (1);
63 }
64
65 private void create_new_grid () {
37 // Grid properties66 // Grid properties
38 row_homogeneous = true;67 current_grid = new Gtk.Grid ();
39 column_homogeneous = true;68 current_grid.expand = true;
4069 current_grid.row_homogeneous = true;
41 row_spacing = 20;70 current_grid.column_homogeneous = true;
42 column_spacing = 0;71
4372 current_grid.row_spacing = row_spacing;
44 page.rows = rows;73 current_grid.column_spacing = 0;
45 page.columns = columns;74 grids.set (page.number, current_grid);
46 page.number = 1;75 stack.add_titled (current_grid, page.number.to_string (), page.number.to_string ());
4776
77 // Fake grids in case there are not enough apps to fill the grid
78 current_grid.attach (new Gtk.Grid (), 0, 0, (int)page.columns, (int)page.rows);
48 }79 }
4980
50 public void append (Gtk.Widget widget) {81 public void append (Gtk.Widget widget) {
5182
52 update_position ();83 update_position ();
5384
54 var col = current_col + page.columns * (page.number - 1);85 current_grid.attach (widget, (int)current_col, (int)current_row, 1, 1);
55
56 this.attach (widget, (int)col, (int)current_row, 1, 1);
57 current_col++;86 current_col++;
87 current_grid.show ();
58 }88 }
5989
60 private void update_position () {90 private void update_position () {
@@ -66,7 +96,7 @@
6696
67 if (current_row == page.rows) {97 if (current_row == page.rows) {
68 page.number++;98 page.number++;
69 new_page (page.number.to_string ());99 create_new_grid ();
70 current_row = 0;100 current_row = 0;
71 }101 }
72102
@@ -74,16 +104,27 @@
74104
75 public void clear () {105 public void clear () {
76106
77 foreach (Gtk.Widget widget in get_children ()) {107 foreach (Gtk.Grid grid in grids.values) {
78 if (widget.get_parent () != null)108 foreach (Gtk.Widget widget in grid.get_children ()) {
79 remove (widget);109 widget.destroy ();
80 widget.destroy ();110 }
111 grid.destroy ();
81 }112 }
113 grids.clear ();
82114
83 current_row = 0;115 current_row = 0;
84 current_col = 0;116 current_col = 0;
85 page.number = 1;117 page.number = 1;
86118 create_new_grid ();
119 stack.set_visible_child (current_grid);
120
121 }
122
123 public Gtk.Widget get_child_at (int column, int row) {
124 var col = ((int)(column/page.columns))+1;
125
126 var grid = grids.get (col);
127 return grid.get_child_at (column - (int)page.columns*(col-1), row);
87 }128 }
88129
89 public int get_page_columns () {130 public int get_page_columns () {
@@ -104,20 +145,34 @@
104145
105 }146 }
106147
107 public void fade_all_out () {148 public int get_current_page () {
108149 return int.parse (stack.get_visible_child_name ());
109 foreach (Gtk.Widget widget in get_children ()) {150 }
110 ((AppEntry) widget).fade_out ();151
111 }152 public void go_to_next () {
112153 int page_number = get_current_page ()+1;
113 }154 if (page_number <= get_n_pages ())
114155 stack.set_visible_child_name ("%d".printf (page_number));
115 public void fade_all_in () {156
116157 page_switcher.update_selected ();
117 foreach (Gtk.Widget widget in get_children ()) {158 }
118 ((AppEntry) widget).fade_in ();159
119 }160 public void go_to_previous () {
120161 int page_number = get_current_page ()-1;
162 if (page_number > 0)
163 stack.set_visible_child_name ("%d".printf (page_number));
164
165 page_switcher.update_selected ();
166 }
167
168 public void go_to_last () {
169 stack.set_visible_child_name ("%d".printf (get_n_pages ()));
170 page_switcher.update_selected ();
171 }
172
173 public void go_to_number (int number) {
174 stack.set_visible_child_name ("%d".printf (number));
175 page_switcher.update_selected ();
121 }176 }
122177
123 public void resize (int rows, int columns) {178 public void resize (int rows, int columns) {
124179
=== modified file 'src/Widgets/SearchView.vala'
--- src/Widgets/SearchView.vala 2013-12-26 00:08:04 +0000
+++ src/Widgets/SearchView.vala 2014-03-01 15:19:46 +0000
@@ -27,11 +27,12 @@
2727
28 }28 }
2929
30 public class SearchView : Gtk.Box {30 public class SearchView : Gtk.ScrolledWindow {
3131
32 private Gee.HashMap<Backend.App, SearchItem> items;32 private Gee.HashMap<Backend.App, SearchItem> items;
33 private SeparatorItem separator;33 private SeparatorItem separator;
34 private SearchItem selected_app = null;34 private SearchItem selected_app = null;
35 private Gtk.Box main_box;
3536
36 private int _selected = 0;37 private int _selected = 0;
37 public int selected {38 public int selected {
@@ -63,17 +64,23 @@
63 private SlingshotView view;64 private SlingshotView view;
6465
65 public SearchView (SlingshotView parent) {66 public SearchView (SlingshotView parent) {
66 orientation = Gtk.Orientation.VERTICAL;67 main_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
6768 main_box.can_focus = true;
68 can_focus = true;69 main_box.homogeneous = false;
69 homogeneous = false;
7070
71 this.view = parent;71 this.view = parent;
72 width_request = view.columns * 130;72 main_box. width_request = view.columns * 130;
7373
74 items = new Gee.HashMap<Backend.App, SearchItem> ();74 items = new Gee.HashMap<Backend.App, SearchItem> ();
75 separator = new SeparatorItem ();75 separator = new SeparatorItem ();
7676
77 var expand_grid = new Gtk.Grid ();
78 expand_grid.expand = true;
79 var search_grid = new Gtk.Grid ();
80 search_grid.orientation = Gtk.Orientation.VERTICAL;
81 search_grid.add (main_box);
82 search_grid.add (expand_grid);
83 add_with_viewport (search_grid);
77 }84 }
7885
79 public void add_apps (Gee.ArrayList<Backend.App> apps) {86 public void add_apps (Gee.ArrayList<Backend.App> apps) {
@@ -111,7 +118,7 @@
111 }118 }
112119
113 if (!(items[app].in_box)) {120 if (!(items[app].in_box)) {
114 pack_start (items[app], true, true, 0);121 main_box.pack_start (items[app], true, true, 0);
115 items[app].in_box = true;122 items[app].in_box = true;
116 items[app].icon_size = 48;123 items[app].icon_size = 48;
117 items[app].queue_draw ();124 items[app].queue_draw ();
@@ -143,10 +150,12 @@
143 foreach (SearchItem app in items.values) {150 foreach (SearchItem app in items.values) {
144 app.hide ();151 app.hide ();
145 if (app.in_box) {152 if (app.in_box) {
146 remove (app);153 main_box.remove (app);
147 app.in_box = false;154 app.in_box = false;
148 }155 }
149 }156 }
157
158 vadjustment.value = vadjustment.lower;
150 apps_showed = 0;159 apps_showed = 0;
151 }160 }
152161
@@ -163,7 +172,7 @@
163 private void show_separator () {172 private void show_separator () {
164173
165 if (!(separator.in_box)) {174 if (!(separator.in_box)) {
166 pack_start (separator, true, true, 3);175 main_box.pack_start (separator, true, true, 3);
167 separator.in_box = true;176 separator.in_box = true;
168 }177 }
169 separator.show_all ();178 separator.show_all ();
@@ -174,7 +183,7 @@
174183
175 separator.hide ();184 separator.hide ();
176 if (separator.in_box) {185 if (separator.in_box) {
177 remove (separator);186 main_box.remove (separator);
178 separator.in_box = false;187 separator.in_box = false;
179 }188 }
180189
@@ -185,7 +194,7 @@
185 if (selected_app != null)194 if (selected_app != null)
186 selected_app.unset_state_flags (Gtk.StateFlags.PRELIGHT);195 selected_app.unset_state_flags (Gtk.StateFlags.PRELIGHT);
187196
188 selected_app = (SearchItem) get_children ().nth_data (index);197 selected_app = (SearchItem) main_box.get_children ().nth_data (index);
189 selected_app.set_state_flags (Gtk.StateFlags.PRELIGHT, false);198 selected_app.set_state_flags (Gtk.StateFlags.PRELIGHT, false);
190199
191 }200 }
192201
=== modified file 'src/Widgets/Switcher.vala'
--- src/Widgets/Switcher.vala 2013-03-10 12:58:37 +0000
+++ src/Widgets/Switcher.vala 2014-03-01 15:19:46 +0000
@@ -1,6 +1,7 @@
1// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-1// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-
2//2//
3// Copyright (C) 2011-2012 Giulio Collura3// Copyright (C) 2011-2012 Giulio Collura
4// Copyright (C) 2014 Corentin Noël <tintou@mailoo.org>
4//5//
5// This program is free software: you can redistribute it and/or modify6// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by7// it under the terms of the GNU General Public License as published by
@@ -16,78 +17,106 @@
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/>.
17//18//
1819
19using Gtk;20public class Slingshot.Widgets.Switcher : Gtk.Box {
2021
21namespace Slingshot.Widgets {22 public int size {
2223 get {
23 public class Switcher : HBox {24 return (int) buttons.size;
2425 }
25 public signal void active_changed (int active);26 }
2627
27 public int size {28 private Gtk.Stack stack;
28 get {29 private Gee.HashMap<Gtk.Widget, Gtk.ToggleButton> buttons;
29 return (int) get_children ().length ();30
30 }31 public Switcher () {
31 }32 orientation = Gtk.Orientation.HORIZONTAL;
3233 spacing = 2;
33 public int active = -1;34 can_focus = false;
34 public int old_active = -1;35 buttons = new Gee.HashMap<Gtk.Widget, Gtk.ToggleButton> (null, null);
3536 pack_start (new Gtk.Grid (), true, true, 0);
36 public Switcher (bool with_padding = true) {37 pack_end (new Gtk.Grid (), true, true, 0);
3738 }
38 homogeneous = true;39
39 spacing = 2;40 public void set_stack (Gtk.Stack stack) {
4041 if (this.stack != null) {
41 can_focus = false;42 clear_children ();
4243 }
43 }44 this.stack = stack;
4445 populate_switcher ();
45 public void append (string label) {46 connect_stack_signals ();
4647 update_selected ();
47 var button = new ToggleButton.with_label (label);48 }
48 button.width_request = 30;49
49 button.can_focus = false;50 private void add_child (Gtk.Widget widget) {
50 button.get_style_context ().add_class ("switcher");51 var button = new Gtk.ToggleButton.with_label ((buttons.size +1).to_string ());
5152 button.width_request = 30;
52 button.button_release_event.connect (() => {53 button.can_focus = false;
5354 button.get_style_context ().add_class ("switcher");
54 int select = get_children ().index (button);55 button.button_release_event.connect (() => {
55 set_active (select);56 foreach (var entry in buttons.entries) {
56 return true;57 if (entry.value == button)
5758 on_button_clicked (entry.key);
58 });59 entry.value.active = false;
5960 }
60 add (button);61 button.active = true;
61 button.show_all ();62 return true;
6263 });
63 }64
6465 add (button);
65 public void set_active (int new_active) {66 buttons.set (widget, button);
66 67 if (buttons.size == 1)
67 if (new_active >= get_children ().length ())68 button.active = true;
68 return;69 }
6970
70 if (active >= 0)71 public override void show () {
71 ((ToggleButton) get_children ().nth_data (active)).set_active (false);72 base.show ();
7273 if (buttons.size <= 1)
73 old_active = active;74 hide ();
74 active = new_active;75 }
75 active_changed (new_active);76
76 ((ToggleButton) get_children ().nth_data (active)).set_active (true);77
77 78 public override void show_all () {
78 }79 base.show_all ();
7980 if (buttons.size <= 1)
80 public void clear_children () {81 hide ();
8182 }
82 foreach (weak Widget button in get_children ()) {83
83 button.hide ();84 private void on_button_clicked (Gtk.Widget widget) {
84 if (button.get_parent () != null)85 stack.set_visible_child (widget);
85 remove (button);86 }
86 }87
8788 private void populate_switcher () {
88 old_active = 0;89 foreach (var child in stack.get_children ()) {
89 active = 0;90 add_child (child);
9091 }
91 }92 }
92 }93
93}94 private void on_stack_child_removed (Gtk.Widget widget) {
95 var button = buttons.get (widget);
96 remove (button);
97 buttons.unset (widget);
98 }
99
100 private void connect_stack_signals () {
101 stack.add.connect_after (add_child);
102 stack.remove.connect_after (on_stack_child_removed);
103 }
104
105 public void clear_children () {
106 foreach (weak Gtk.Widget button in get_children ()) {
107 button.hide ();
108 if (button.get_parent () != null)
109 remove (button);
110 }
111 }
112
113 public void update_selected () {
114 foreach (var entry in buttons.entries) {
115 if (entry.key == stack.get_visible_child ()) {
116 entry.value.active = true;
117 } else {
118 entry.value.active = false;
119 }
120 }
121 }
122}
94\ No newline at end of file123\ No newline at end of file

Subscribers

People subscribed via source and target branches