Merge lp:~artem-anufrij/webby-browser/reload-apps-after-added-new-app into lp:webby-browser

Proposed by Artem Anufrij on 2015-10-11
Status: Merged
Approved by: Erasmo Marín on 2015-10-12
Approved revision: 14
Merged at revision: 13
Proposed branch: lp:~artem-anufrij/webby-browser/reload-apps-after-added-new-app
Merge into: lp:webby-browser
Diff against target: 207 lines (+66/-39)
4 files modified
src/AppWindow.vala (+35/-18)
src/ApplicationsView.vala (+23/-10)
src/Assistant.vala (+5/-7)
src/DesktopFile.vala (+3/-4)
To merge this branch: bzr merge lp:~artem-anufrij/webby-browser/reload-apps-after-added-new-app
Reviewer Review Type Date Requested Status
Erasmo Marín code & functionality 2015-10-11 Pending
Review via email: mp+274070@code.launchpad.net

This proposal supersedes a proposal from 2015-10-07.

Commit message

Reload preview after adding a new app.

Description of the change

Reload preview after adding a new app.

To post a comment you must log in.
Erasmo Marín (erasmo-marin) wrote : Posted in a previous version of this proposal

This is great, just 2 details:

1) Can you explicitly declare the new attributes as private please?
2) Would be cool if the new added app is selected when you are back to the icon view.

Thanks! :)

review: Needs Fixing (code & functionality)
Artem Anufrij (artem-anufrij) wrote : Posted in a previous version of this proposal

1) done
2) done

Erasmo Marín (erasmo-marin) wrote :

Thanks, it just need to get the focus now, but I will do that.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/AppWindow.vala'
2--- src/AppWindow.vala 2015-02-26 20:16:44 +0000
3+++ src/AppWindow.vala 2015-10-11 13:36:00 +0000
4@@ -1,23 +1,27 @@
5 public class AppWindow : Gtk.ApplicationWindow {
6
7+ private Gtk.Stack stack;
8+ private Gtk.HeaderBar headerbar;
9+ private Gtk.Button back_button;
10+
11 public AppWindow () {
12
13 set_default_size (700, 500);
14 set_wmclass("Webby", "Webby");
15
16 //headerbar
17- var headerbar = new Gtk.HeaderBar ();
18+ headerbar = new Gtk.HeaderBar ();
19 headerbar.show_close_button = true;
20 headerbar.title = "Webby";
21 this.set_titlebar (headerbar);
22
23- var back_button = new Gtk.Button.with_label(_("Applications"));
24+ back_button = new Gtk.Button.with_label(_("Applications"));
25 back_button.get_style_context().add_class("back-button");
26-
27+
28 var apps_view = new ApplicationsView();
29 var assistant = new WebbyAssistant();
30- var stack = new Gtk.Stack ();
31- stack.set_transition_duration (500);
32+ stack = new Gtk.Stack ();
33+ stack.set_transition_duration (500);
34
35 stack.add_named (apps_view, "apps_view");
36 stack.add_named (assistant, "assistant");
37@@ -25,22 +29,35 @@
38
39 add (stack);
40
41- apps_view.add_request.connect( () => {
42- stack.set_transition_type (Gtk.StackTransitionType.SLIDE_LEFT);
43- stack.set_visible_child_name("assistant");
44- headerbar.pack_start (back_button);
45- back_button.show_all ();
46- //fix ugly border at the bottom of headerbar
47- queue_draw ();
48- });
49-
50- back_button.clicked.connect ( () => {
51- stack.set_transition_type (Gtk.StackTransitionType.SLIDE_RIGHT);
52- stack.set_visible_child_name("apps_view");
53- headerbar.remove (back_button);
54+ apps_view.add_request.connect (() => {
55+ show_assistant ();
56+ });
57+
58+ assistant.application_created.connect ((new_file) => {
59+ show_apps_view ();
60+ apps_view.add_button (new_file);
61+ apps_view.select_last_item ();
62+ });
63+
64+ back_button.clicked.connect (() => {
65+ show_apps_view ();
66 });
67
68 this.destroy.connect (Gtk.main_quit);
69 }
70
71+ private void show_assistant () {
72+ stack.set_transition_type (Gtk.StackTransitionType.SLIDE_LEFT);
73+ stack.set_visible_child_name("assistant");
74+ headerbar.pack_start (back_button);
75+ back_button.show_all ();
76+ //fix ugly border at the bottom of headerbar
77+ queue_draw ();
78+ }
79+
80+ private void show_apps_view () {
81+ stack.set_transition_type (Gtk.StackTransitionType.SLIDE_RIGHT);
82+ stack.set_visible_child_name("apps_view");
83+ headerbar.remove (back_button);
84+ }
85 }
86
87=== modified file 'src/ApplicationsView.vala'
88--- src/ApplicationsView.vala 2015-03-23 21:19:58 +0000
89+++ src/ApplicationsView.vala 2015-10-11 13:36:00 +0000
90@@ -19,6 +19,14 @@
91 icon_view.row_spacing = 15;
92 icon_view.margin = 15;
93
94+ load_applications ();
95+
96+ scrolled.add(icon_view);
97+ this.pack_start(scrolled, true, true, 0);
98+
99+ }
100+
101+ public void load_applications () {
102
103 var add_button = new Gtk.Button ();
104 var add_image = new Gtk.Image();
105@@ -36,20 +44,25 @@
106 applications = DesktopFile.get_webby_applications();
107
108 foreach (GLib.DesktopAppInfo app in applications.values) {
109- var icon = app.get_icon ().to_string ();
110- var name = app.get_display_name ();
111- var image = new ApplicationIcon(icon, name);
112- var desktop_file = new DesktopFile.from_desktopappinfo (app);
113- image.delete_request.connect (()=>{
114- desktop_file.delete_file();
115- });
116- icon_view.add (image);
117+ this.add_button (app);
118 }
119
120- scrolled.add(icon_view);
121- this.pack_start(scrolled, true, true, 0);
122 this.show_all();
123 }
124+
125+ public void add_button (GLib.DesktopAppInfo app) {
126+ var image = new ApplicationIcon(app.get_icon ().to_string (), app.get_display_name ());
127+ var desktop_file = new DesktopFile.from_desktopappinfo (app);
128+ image.delete_request.connect (()=>{
129+ desktop_file.delete_file();
130+ });
131+ icon_view.add (image);
132+ icon_view.show_all ();
133+ }
134+
135+ public void select_last_item () {
136+ icon_view.select_child (icon_view.get_child_at_index ((int)icon_view.get_children ().length () - 1));
137+ }
138 }
139
140
141
142=== modified file 'src/Assistant.vala'
143--- src/Assistant.vala 2015-02-27 02:49:54 +0000
144+++ src/Assistant.vala 2015-10-11 13:36:00 +0000
145@@ -1,5 +1,7 @@
146 public class WebbyAssistant : Gtk.Box {
147
148+ public signal void application_created (GLib.DesktopAppInfo? new_file);
149+
150 private Gtk.Label message;
151 private Gtk.Button icon_button;
152 private Gtk.Entry app_name_entry;
153@@ -13,7 +15,7 @@
154 private Gtk.Button accept_button;
155 private GLib.Regex protocol_regex;
156 private Gee.HashMap<string, GLib.AppInfo> apps;
157-
158+
159 private string default_app_icon = "application-default-icon";
160
161 private bool app_name_valid = false;
162@@ -70,7 +72,7 @@
163 icon_chooser_button.grab_focus ();
164
165 icon_selector_popover.add (popover_box);
166-
167+
168 //TODO: categories
169 //combobox
170
171@@ -265,12 +267,8 @@
172
173 if (app_icon_valid && app_name_valid && app_url_valid) {
174 var desktop_file = new DesktopFile (name, url, icon);
175- desktop_file.save_to_file ();
176 reset_fields ();
177- print("dialog");
178- var dialog = new InfoDialog (_("App created"), _("The application shortcut was successfully created"), "dialog-information");
179- dialog.show_all ();
180- dialog.response.connect (()=>{dialog.destroy();});
181+ application_created (desktop_file.save_to_file ());
182 }
183 }
184 }
185
186=== modified file 'src/DesktopFile.vala'
187--- src/DesktopFile.vala 2015-02-26 20:16:44 +0000
188+++ src/DesktopFile.vala 2015-10-11 13:36:00 +0000
189@@ -41,15 +41,14 @@
190 file = new GLib.KeyFile();
191 file.load_from_file (filename, KeyFileFlags.NONE);
192 file.set_string ("Desktop Entry", propertie, val);
193- file.save_to_file (filename);
194- return true;
195+ return file.save_to_file (filename);
196 }
197
198- public bool save_to_file () {
199+ public GLib.DesktopAppInfo save_to_file () {
200 string filename = GLib.Environment.get_user_data_dir () + "/applications/" +file.get_string("Desktop Entry", "Name") + "-webby.desktop";
201 print("Desktop file created: " + filename);
202 file.save_to_file (filename);
203- return true;
204+ return new GLib.DesktopAppInfo.from_filename (filename);
205 }
206
207 public bool delete_file () {

Subscribers

People subscribed via source and target branches

to all changes: