~voldyman/slingshot/fixes-1263999

« back to all changes in this revision

Viewing changes to src/SlingshotView.vala

  • Committer: RabbitBot
  • Author(s): Corentin Noël
  • Date: 2014-01-14 13:05:03 UTC
  • mfrom: (396.1.1 slingshot)
  • Revision ID: rabbitbot-20140114130503-vl01yvhtdlu0dvs4
* Removed every using statement
* Changed VWidgets and HWidgets to Widgets with the corresponding orientation (Gtk deprecation)
* Ported Zeitgeist parts to version 2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
17
//
18
18
 
19
 
using Gtk;
20
 
using Gdk;
21
 
using Gee;
22
 
using Cairo;
23
 
using Granite.Widgets;
24
 
using GMenu;
25
 
 
26
 
using Slingshot.Widgets;
27
 
using Slingshot.Backend;
28
 
 
29
19
namespace Slingshot {
30
20
 
31
21
    public enum Modality {
34
24
        SEARCH_VIEW
35
25
    }
36
26
 
37
 
    public class SlingshotView : PopOver {
 
27
    public class SlingshotView : Granite.Widgets.PopOver {
38
28
 
39
29
        // Widgets
40
30
        public Granite.Widgets.SearchBar searchbar;
41
 
        public Layout view_manager;
42
 
        public Switcher page_switcher;
43
 
        public ModeButton view_selector;
 
31
        public Gtk.Layout view_manager;
 
32
        public Widgets.Switcher page_switcher;
 
33
        public Granite.Widgets.ModeButton view_selector;
44
34
 
45
35
        // Views
46
36
        private Widgets.Grid grid_view;
47
 
        private SearchView search_view;
48
 
        private CategoryView category_view;
 
37
        private Widgets.SearchView search_view;
 
38
        private Widgets.CategoryView category_view;
49
39
 
50
40
        public Gtk.Grid top;
51
41
        public Gtk.Grid center;
54
44
        public Gtk.Box content_area;
55
45
        private Gtk.EventBox event_box;
56
46
 
57
 
        public AppSystem app_system;
58
 
        private ArrayList<TreeDirectory> categories;
59
 
        public HashMap<string, ArrayList<App>> apps;
 
47
        public Backend.AppSystem app_system;
 
48
        private Gee.ArrayList<GMenu.TreeDirectory> categories;
 
49
        public Gee.HashMap<string, Gee.ArrayList<Backend.App>> apps;
60
50
 
61
51
        private int current_position = 0;
62
52
        private int search_view_position = 0;
100
90
            // Have the window in the right place
101
91
            read_settings (true);
102
92
 
103
 
            Slingshot.icon_theme = IconTheme.get_default ();
 
93
            Slingshot.icon_theme = Gtk.IconTheme.get_default ();
104
94
 
105
 
            app_system = new AppSystem ();
 
95
            app_system = new Backend.AppSystem ();
106
96
 
107
97
            categories = app_system.get_categories ();
108
98
            apps = app_system.get_apps ();
148
138
            // Add top bar
149
139
            top = new Gtk.Grid ();
150
140
 
151
 
            var top_separator = new Label (""); // A fake label
 
141
            var top_separator = new Gtk.Label (""); // A fake label
152
142
            top_separator.set_hexpand(true);
153
143
 
154
 
            view_selector = new ModeButton ();
 
144
            view_selector = new Granite.Widgets.ModeButton ();
155
145
 
156
 
            var image = new Image.from_icon_name ("view-grid-symbolic", IconSize.MENU);
 
146
            var image = new Gtk.Image.from_icon_name ("view-grid-symbolic", Gtk.IconSize.MENU);
157
147
            image.tooltip_text = _("View as Grid");
158
148
            view_selector.append (image);
159
149
 
160
 
            image = new Image.from_icon_name ("view-filter-symbolic", IconSize.MENU);
 
150
            image = new Gtk.Image.from_icon_name ("view-filter-symbolic", Gtk.IconSize.MENU);
161
151
            image.tooltip_text = _("View by Category");
162
152
            view_selector.append (image);
163
153
 
179
169
 
180
170
            center = new Gtk.Grid ();
181
171
            // Create the layout which works like view_manager
182
 
            view_manager = new Layout (null, null);
 
172
            view_manager = new Gtk.Layout (null, null);
183
173
            view_manager.set_size_request (default_columns * 130, default_rows * 145);
184
174
            center.attach (view_manager, 0, 0, 1, 1);
185
175
 
188
178
            view_manager.put (grid_view, 0, 0);
189
179
 
190
180
            // Create the "SEARCH_VIEW"
191
 
            search_view = new SearchView (this);
192
 
            foreach (ArrayList<App> app_list in apps.values) {
 
181
            search_view = new Widgets.SearchView (this);
 
182
            foreach (Gee.ArrayList<Backend.App> app_list in apps.values) {
193
183
                search_view.add_apps (app_list);
194
184
            }
195
185
            view_manager.put (search_view, -columns * 130, 0);
196
186
 
197
187
            // Create the "CATEGORY_VIEW"
198
 
            category_view = new CategoryView (this);
 
188
            category_view = new Widgets.CategoryView (this);
199
189
            view_manager.put (category_view, -columns * 130, 0);
200
190
 
201
191
            // Create the page switcher
202
 
            page_switcher = new Switcher ();
 
192
            page_switcher = new Widgets.Switcher ();
203
193
 
204
194
            // A bottom widget to keep the page switcher center
205
195
            bottom = new Gtk.Grid ();
206
196
 
207
197
 
208
 
            var bottom_separator1 = new Label (""); // A fake label
 
198
            var bottom_separator1 = new Gtk.Label (""); // A fake label
209
199
            bottom_separator1.set_hexpand (true);
210
 
            var bottom_separator2 = new Label (""); // A fake label
 
200
            var bottom_separator2 = new Gtk.Label (""); // A fake label
211
201
            bottom_separator2.set_hexpand (true);
212
202
            bottom.attach (bottom_separator1, 0, 0, 1, 1); // A fake label
213
203
            bottom.attach (page_switcher, 1, 0, 1, 1);
220
210
            event_box = new Gtk.EventBox ();
221
211
            event_box.add (container);
222
212
            // Add the container to the dialog's content area
223
 
            content_area = get_content_area () as Box;
 
213
            content_area = get_content_area () as Gtk.Box;
224
214
            content_area.pack_start (event_box);
225
215
 
226
216
            if (Slingshot.settings.use_category)
294
284
            //view_manager.draw.connect (this.draw_background);
295
285
 
296
286
            event_box.key_press_event.connect (on_key_press);
297
 
            searchbar.text_changed_pause.connect ((text) => this.search (text));
 
287
            searchbar.text_changed_pause.connect ((text) => this.search.begin (text));
298
288
            searchbar.grab_focus ();
299
289
 
300
290
            searchbar.activate.connect (() => {
302
292
                    search_view.launch_selected ();
303
293
                    hide ();
304
294
                } else {
305
 
                    if (get_focus () as AppEntry != null) // checking the selected widget is an AppEntry
306
 
                        ((AppEntry) get_focus ()).launch_app ();
 
295
                    if (get_focus () as Widgets.AppEntry != null) // checking the selected widget is an AppEntry
 
296
                        ((Widgets.AppEntry) get_focus ()).launch_app ();
307
297
                }
308
298
            });
309
299
 
433
423
                        search_view.launch_selected ();
434
424
                        hide ();
435
425
                    } else {
436
 
                        if (get_focus () as AppEntry != null) // checking the selected widget is an AppEntry
437
 
                            ((AppEntry)get_focus ()).launch_app ();
 
426
                        if (get_focus () as Widgets.AppEntry != null) // checking the selected widget is an AppEntry
 
427
                            ((Widgets.AppEntry)get_focus ()).launch_app ();
438
428
                    }
439
429
                    return true;
440
430
 
596
586
                    break;
597
587
 
598
588
                case "Home":
599
 
                    if (searchbar.text.size () > 0) {
 
589
                    if (searchbar.text.length > 0) {
600
590
                        return false;
601
591
                    }
602
592
 
609
599
                    break;
610
600
 
611
601
                case "End":
612
 
                    if (searchbar.text.size () > 0) {
 
602
                    if (searchbar.text.length > 0) {
613
603
                        return false;
614
604
                    }
615
605
 
641
631
 
642
632
        }
643
633
 
644
 
        public override bool scroll_event (EventScroll event) {
 
634
        public override bool scroll_event (Gdk.EventScroll event) {
645
635
 
646
636
            switch (event.direction.to_string ()) {
647
637
                case "GDK_SCROLL_UP":
820
810
 
821
811
            var filtered = yield app_system.search_results (stripped);
822
812
 
823
 
            foreach (App app in filtered) {
 
813
            foreach (Backend.App app in filtered) {
824
814
                search_view.show_app (app);
825
815
            }
826
816
 
836
826
            page_switcher.append ("1");
837
827
            page_switcher.set_active (0);
838
828
 
839
 
            foreach (App app in app_system.get_apps_by_name ()) {
 
829
            foreach (Backend.App app in app_system.get_apps_by_name ()) {
840
830
 
841
 
                var app_entry = new AppEntry (app);
 
831
                var app_entry = new Widgets.AppEntry (app);
842
832
                app_entry.app_launched.connect (() => hide ());
843
833
                grid_view.append (app_entry);
844
834
                app_entry.show_all ();
878
868
        }
879
869
 
880
870
        private void normal_move_focus (int delta_column, int delta_row) {
881
 
            if (get_focus () as AppEntry != null) { // we check if any AppEntry has focus. If it does, we move
 
871
            if (get_focus () as Widgets.AppEntry != null) { // we check if any AppEntry has focus. If it does, we move
882
872
                var new_focus = grid_view.get_child_at (column_focus + delta_column, row_focus + delta_row); // we check if the new widget exists
883
873
                if (new_focus == null) {
884
874
                    if (delta_column <= 0)
960
950
        }
961
951
    }
962
952
 
963
 
}
 
953
}
 
 
b'\\ No newline at end of file'