Merge lp:~artem-anufrij/webby-browser/edit-functionality into lp:webby-browser

Proposed by Artem Anufrij on 2015-10-12
Status: Merged
Approved by: Erasmo Marín on 2015-10-12
Approved revision: 14
Merged at revision: 14
Proposed branch: lp:~artem-anufrij/webby-browser/edit-functionality
Merge into: lp:webby-browser
Diff against target: 396 lines (+169/-55)
4 files modified
src/AppWindow.vala (+17/-2)
src/ApplicationsView.vala (+114/-48)
src/Assistant.vala (+27/-5)
src/DesktopFile.vala (+11/-0)
To merge this branch: bzr merge lp:~artem-anufrij/webby-browser/edit-functionality
Reviewer Review Type Date Requested Status
Erasmo Marín all 2015-10-12 Approve on 2015-10-12
Review via email: mp+274189@code.launchpad.net

Commit message

edit functionality was implemented

Description of the change

edit functionality was implemented

To post a comment you must log in.
Erasmo Marín (erasmo-marin) wrote :

I like your approach with enum

review: Approve (all)

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-10-11 13:32:10 +0000
3+++ src/AppWindow.vala 2015-10-12 21:56:20 +0000
4@@ -4,6 +4,8 @@
5 private Gtk.HeaderBar headerbar;
6 private Gtk.Button back_button;
7
8+ private WebbyAssistant assistant;
9+
10 public AppWindow () {
11
12 set_default_size (700, 500);
13@@ -19,7 +21,7 @@
14 back_button.get_style_context().add_class("back-button");
15
16 var apps_view = new ApplicationsView();
17- var assistant = new WebbyAssistant();
18+ assistant = new WebbyAssistant();
19 stack = new Gtk.Stack ();
20 stack.set_transition_duration (500);
21
22@@ -33,12 +35,21 @@
23 show_assistant ();
24 });
25
26+ apps_view.edit_request.connect ((desktop_file) => {
27+ show_assistant (desktop_file);
28+ });
29+
30 assistant.application_created.connect ((new_file) => {
31 show_apps_view ();
32 apps_view.add_button (new_file);
33 apps_view.select_last_item ();
34 });
35
36+ assistant.application_edited.connect ((edited_file) => {
37+ show_apps_view ();
38+ apps_view.update_button (edited_file);
39+ });
40+
41 back_button.clicked.connect (() => {
42 show_apps_view ();
43 });
44@@ -46,18 +57,22 @@
45 this.destroy.connect (Gtk.main_quit);
46 }
47
48- private void show_assistant () {
49+ private void show_assistant (DesktopFile? desktop_file = null) {
50 stack.set_transition_type (Gtk.StackTransitionType.SLIDE_LEFT);
51 stack.set_visible_child_name("assistant");
52 headerbar.pack_start (back_button);
53 back_button.show_all ();
54 //fix ugly border at the bottom of headerbar
55 queue_draw ();
56+
57+ if (desktop_file != null)
58+ assistant.edit_desktop_file (desktop_file);
59 }
60
61 private void show_apps_view () {
62 stack.set_transition_type (Gtk.StackTransitionType.SLIDE_RIGHT);
63 stack.set_visible_child_name("apps_view");
64 headerbar.remove (back_button);
65+ assistant.reset_fields ();
66 }
67 }
68
69=== modified file 'src/ApplicationsView.vala'
70--- src/ApplicationsView.vala 2015-10-11 13:32:10 +0000
71+++ src/ApplicationsView.vala 2015-10-12 21:56:20 +0000
72@@ -1,6 +1,7 @@
73 public class ApplicationsView : Gtk.Box {
74
75 public signal void add_request();
76+ public signal void edit_request(DesktopFile desktop_file);
77
78 private Gtk.FlowBox icon_view;
79 private Gee.HashMap<string, GLib.DesktopAppInfo> applications;
80@@ -51,10 +52,14 @@
81 }
82
83 public void add_button (GLib.DesktopAppInfo app) {
84- var image = new ApplicationIcon(app.get_icon ().to_string (), app.get_display_name ());
85- var desktop_file = new DesktopFile.from_desktopappinfo (app);
86- image.delete_request.connect (()=>{
87- desktop_file.delete_file();
88+ var image = new ApplicationIcon (app);
89+ image.edit_request.connect ((desktop_file) => {
90+ edit_request (desktop_file);
91+ icon_view.unselect_all ();
92+ });
93+ image.deleted.connect ((parent) => {
94+ this.icon_view.remove (parent);
95+ this.select_first_item ();
96 });
97 icon_view.add (image);
98 icon_view.show_all ();
99@@ -63,6 +68,24 @@
100 public void select_last_item () {
101 icon_view.select_child (icon_view.get_child_at_index ((int)icon_view.get_children ().length () - 1));
102 }
103+
104+ public void select_first_item () {
105+ icon_view.select_child (icon_view.get_child_at_index (0));
106+ }
107+
108+ public void update_button (GLib.DesktopAppInfo app) {
109+ foreach (var item in icon_view.get_children ()) {
110+ if ((item as Gtk.FlowBoxChild).get_child () is ApplicationIcon) {
111+ var app_icon = (item as Gtk.FlowBoxChild).get_child () as ApplicationIcon;
112+
113+ if (app_icon.desktop_file.name == app.get_display_name ()) {
114+ app_icon.set_new_desktopfile (new DesktopFile.from_desktopappinfo (app));
115+ icon_view.select_child (item as Gtk.FlowBoxChild);
116+ break;
117+ }
118+ }
119+ }
120+ }
121 }
122
123
124@@ -74,14 +97,63 @@
125 Gtk.Box box;
126 Gtk.ActionGroup action_group;
127
128- public signal void delete_request ();
129-
130- public ApplicationIcon (string icon, string label_str) {
131+ internal DesktopFile desktop_file { get; private set; }
132+
133+ public signal void deleted (Gtk.Container? parent);
134+ public signal void edit_request (DesktopFile desktop_file);
135+
136+ public ApplicationIcon (GLib.DesktopAppInfo app) {
137+ this.desktop_file = new DesktopFile.from_desktopappinfo (app);
138+
139 hexpand = false;
140 vexpand = false;
141
142- label = new Gtk.Label (label_str);
143-
144+ label = new Gtk.Label (this.desktop_file.name);
145+
146+ set_icon (this.desktop_file.icon);
147+
148+ this.margin = 6;
149+ this.margin_start = 20;
150+ this.margin_end = 20;
151+
152+ var menu = new ActionMenu ();
153+ menu.halign = Gtk.Align.CENTER;
154+ menu.delete_clicked.connect (() => { remove_application (); });
155+ menu.edit_clicked.connect (() => { edit_request (desktop_file); });
156+
157+ box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
158+ box.pack_start (image, false, false, 0);
159+ box.pack_start (label, false, false, 0);
160+ box.pack_start (menu, false, false, 0);
161+
162+ box.hexpand = false;
163+ box.vexpand = false;
164+
165+ var event_box = new Gtk.EventBox ();
166+ event_box.add (box);
167+ event_box.events |= Gdk.EventMask.ENTER_NOTIFY_MASK|Gdk.EventMask.LEAVE_NOTIFY_MASK;
168+
169+ event_box.enter_notify_event.connect ((event) => {
170+ menu.set_reveal_child (true);
171+ return false;
172+ });
173+
174+ event_box.leave_notify_event.connect ((event) => {
175+ if (event.detail == Gdk.NotifyType.INFERIOR)
176+ return false;
177+ menu.set_reveal_child (false);
178+ return false;
179+ });
180+
181+ this.add (event_box);
182+ }
183+
184+ public void set_new_desktopfile (DesktopFile desktop_file) {
185+ this.desktop_file = desktop_file;
186+ set_icon (this.desktop_file.icon);
187+ }
188+
189+ private void set_icon (string icon) {
190 if (File.new_for_path (icon).query_exists ()) {
191 var pix = new Gdk.Pixbuf.from_file (icon);
192
193@@ -97,7 +169,11 @@
194 new_height = new_height * pix.height / pix.width;
195 margin_vertical = (new_width - new_height) / 2;
196 }
197- image = new Gtk.Image.from_pixbuf (pix.scale_simple (new_width, new_height, Gdk.InterpType.BILINEAR));
198+ if (image == null)
199+ image = new Gtk.Image.from_pixbuf (pix.scale_simple (new_width, new_height, Gdk.InterpType.BILINEAR));
200+ else
201+ image.set_from_pixbuf (pix.scale_simple (new_width, new_height, Gdk.InterpType.BILINEAR));
202+
203 image.margin_top = margin_vertical;
204 image.margin_bottom = margin_vertical;
205 image.margin_right = margin_horizontal;
206@@ -107,48 +183,38 @@
207 image.icon_name = icon;
208 image.pixel_size = 64;
209 }
210-
211- this.margin = 5;
212- this.margin_start = 20;
213- this.margin_end = 20;
214-
215- box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
216- box.pack_start (image, false, false, 0);
217- box.pack_start (label, false, false, 0);
218- box.hexpand = false;
219- box.vexpand = false;
220-
221- conf_btn = new Gtk.MenuButton();
222- conf_btn.valign = Gtk.Align.START;
223- conf_btn.halign = Gtk.Align.END;
224- conf_btn.get_style_context ().remove_class ("button");
225- conf_btn.get_style_context ().add_class ("titlebutton");
226- conf_btn.set_image (new Gtk.Image.from_icon_name("document-properties", Gtk.IconSize.MENU));
227-
228- build_menu ();
229-
230- this.add (box);
231- this.add_overlay (conf_btn);
232 }
233
234 private void remove_application () {
235- delete_request ();
236- this.get_parent().get_parent().remove(this.get_parent());
237+ desktop_file.delete_file ();
238+ deleted (this.get_parent());
239 this.destroy ();
240 }
241-
242- private void build_menu () {
243-
244- Gtk.Menu menu = new Gtk.Menu ();
245-
246- Gtk.MenuItem remove_app = new Gtk.MenuItem.with_label (_("Remove Application"));
247- menu.add (remove_app);
248-
249- remove_app.activate.connect( () => {
250- remove_application ();
251- });
252-
253- menu.show_all();
254- conf_btn.set_popup (menu);
255+}
256+
257+public class ActionMenu : Gtk.Revealer {
258+
259+ public signal void delete_clicked ();
260+ public signal void edit_clicked ();
261+
262+ public ActionMenu () {
263+ var delete_button = new Gtk.Button.from_icon_name ("edit-delete-symbolic", Gtk.IconSize.BUTTON);
264+ delete_button.tooltip_text = _("Delete Webapp");
265+ delete_button.relief = Gtk.ReliefStyle.NONE;
266+ delete_button.clicked.connect (() => { delete_clicked (); });
267+
268+ var edit_button = new Gtk.Button.from_icon_name ("edit-symbolic", Gtk.IconSize.BUTTON);
269+ edit_button.tooltip_text = _("Edit Webapp Properties");
270+ edit_button.relief = Gtk.ReliefStyle.NONE;
271+ edit_button.clicked.connect (() => { edit_clicked (); });
272+
273+ var buttons = new Gtk.Grid ();
274+ buttons.orientation = Gtk.Orientation.HORIZONTAL;
275+ buttons.add (edit_button);
276+ buttons.add (delete_button);
277+ buttons.opacity = 0.5;
278+
279+ this.transition_type = Gtk.RevealerTransitionType.CROSSFADE;
280+ this.add (buttons);
281 }
282 }
283
284=== modified file 'src/Assistant.vala'
285--- src/Assistant.vala 2015-10-07 20:47:50 +0000
286+++ src/Assistant.vala 2015-10-12 21:56:20 +0000
287@@ -1,6 +1,9 @@
288 public class WebbyAssistant : Gtk.Box {
289
290+ public enum assistant_mode { new_app, edit_app }
291+
292 public signal void application_created (GLib.DesktopAppInfo? new_file);
293+ public signal void application_edited (GLib.DesktopAppInfo? new_file);
294
295 private Gtk.Label message;
296 private Gtk.Button icon_button;
297@@ -22,6 +25,8 @@
298 private bool app_url_valid = false;
299 private bool app_icon_valid = true;
300
301+ private assistant_mode mode { get; set; default = assistant_mode.new_app; }
302+
303 public WebbyAssistant () {
304
305 GLib.Object (orientation: Gtk.Orientation.VERTICAL);
306@@ -102,7 +107,7 @@
307
308
309 //create button
310- accept_button = new Gtk.Button.with_label(_("Create app"));
311+ accept_button = new Gtk.Button.with_label(_("Save app"));
312 accept_button.halign = Gtk.Align.END;
313 accept_button.get_style_context ().add_class ("suggested-action");
314 accept_button.set_sensitive (false);
315@@ -134,7 +139,7 @@
316 });
317
318 app_name_entry.changed.connect (()=>{
319- if (DesktopFile.get_applications().has_key (app_name_entry.get_text()) ) {
320+ if (mode == assistant_mode.new_app && DesktopFile.get_applications().has_key (app_name_entry.get_text()) ) {
321 app_name_entry.get_style_context ().add_class ("error");
322 app_name_entry.set_icon_from_icon_name (Gtk.EntryIconPosition.SECONDARY, "dialog-information");
323 app_name_entry.set_icon_tooltip_text (Gtk.EntryIconPosition.SECONDARY, _("App already exist"));
324@@ -247,13 +252,15 @@
325 }
326
327
328- private void reset_fields () {
329+ public void reset_fields () {
330 icon_name_entry.set_text ("");
331 app_name_entry.set_text ("");
332+ app_name_entry.set_sensitive (true);
333 app_url_entry.set_text ("");
334 app_name_entry.get_style_context ().remove_class ("error");
335 app_url_entry.get_style_context ().remove_class ("error");
336 icon_button.set_image (new Gtk.Image.from_icon_name (default_app_icon, Gtk.IconSize.DIALOG) );
337+ mode = assistant_mode.new_app;
338 }
339
340 private void on_accept () {
341@@ -267,8 +274,23 @@
342
343 if (app_icon_valid && app_name_valid && app_url_valid) {
344 var desktop_file = new DesktopFile (name, url, icon);
345- reset_fields ();
346- application_created (desktop_file.save_to_file ());
347+ switch (mode) {
348+ case assistant_mode.new_app:
349+ application_created (desktop_file.save_to_file ());
350+ break;
351+ case assistant_mode.edit_app:
352+ application_edited (desktop_file.save_to_file ());
353+ break;
354+ }
355 }
356 }
357+
358+ public void edit_desktop_file (DesktopFile desktop_file) {
359+ mode = assistant_mode.edit_app;
360+ app_name_entry.text = desktop_file.name;
361+ app_name_entry.set_sensitive (false);
362+ app_url_entry.text = desktop_file.url;
363+ icon_name_entry.text = desktop_file.icon;
364+ update_app_icon ();
365+ }
366 }
367
368=== modified file 'src/DesktopFile.vala'
369--- src/DesktopFile.vala 2015-10-07 20:47:50 +0000
370+++ src/DesktopFile.vala 2015-10-12 21:56:20 +0000
371@@ -19,7 +19,15 @@
372
373 private GLib.KeyFile file;
374
375+ public string name { get; private set; }
376+ public string url { get; private set; }
377+ public string icon { get; private set; }
378+
379 public DesktopFile (string name, string url, string icon) {
380+ this.name = name;
381+ this.url = url;
382+ this.icon = icon;
383+
384 file = new GLib.KeyFile();
385 file.load_from_data (template, -1, GLib.KeyFileFlags.NONE);
386 //TODO: Category
387@@ -34,6 +42,9 @@
388 public DesktopFile.from_desktopappinfo(GLib.DesktopAppInfo info) {
389 file = new GLib.KeyFile();
390 file.load_from_file (info.filename, KeyFileFlags.NONE);
391+ this.name = info.get_display_name ();
392+ this.icon = info.get_icon ().to_string ();
393+ this.url = file.get_string ("Desktop Entry", "Exec").substring (6);
394 }
395
396 public bool edit_propertie (string propertie, string val) {

Subscribers

People subscribed via source and target branches

to all changes: