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

Proposed by Artem Anufrij
Status: Merged
Approved by: Erasmo Marín
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 Approve
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.
Revision history for this message
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
=== modified file 'src/AppWindow.vala'
--- src/AppWindow.vala 2015-10-11 13:32:10 +0000
+++ src/AppWindow.vala 2015-10-12 21:56:20 +0000
@@ -4,6 +4,8 @@
4 private Gtk.HeaderBar headerbar;4 private Gtk.HeaderBar headerbar;
5 private Gtk.Button back_button;5 private Gtk.Button back_button;
66
7 private WebbyAssistant assistant;
8
7 public AppWindow () {9 public AppWindow () {
810
9 set_default_size (700, 500);11 set_default_size (700, 500);
@@ -19,7 +21,7 @@
19 back_button.get_style_context().add_class("back-button");21 back_button.get_style_context().add_class("back-button");
2022
21 var apps_view = new ApplicationsView();23 var apps_view = new ApplicationsView();
22 var assistant = new WebbyAssistant();24 assistant = new WebbyAssistant();
23 stack = new Gtk.Stack ();25 stack = new Gtk.Stack ();
24 stack.set_transition_duration (500);26 stack.set_transition_duration (500);
2527
@@ -33,12 +35,21 @@
33 show_assistant ();35 show_assistant ();
34 });36 });
3537
38 apps_view.edit_request.connect ((desktop_file) => {
39 show_assistant (desktop_file);
40 });
41
36 assistant.application_created.connect ((new_file) => {42 assistant.application_created.connect ((new_file) => {
37 show_apps_view ();43 show_apps_view ();
38 apps_view.add_button (new_file);44 apps_view.add_button (new_file);
39 apps_view.select_last_item ();45 apps_view.select_last_item ();
40 });46 });
4147
48 assistant.application_edited.connect ((edited_file) => {
49 show_apps_view ();
50 apps_view.update_button (edited_file);
51 });
52
42 back_button.clicked.connect (() => {53 back_button.clicked.connect (() => {
43 show_apps_view ();54 show_apps_view ();
44 });55 });
@@ -46,18 +57,22 @@
46 this.destroy.connect (Gtk.main_quit);57 this.destroy.connect (Gtk.main_quit);
47 }58 }
4859
49 private void show_assistant () {60 private void show_assistant (DesktopFile? desktop_file = null) {
50 stack.set_transition_type (Gtk.StackTransitionType.SLIDE_LEFT);61 stack.set_transition_type (Gtk.StackTransitionType.SLIDE_LEFT);
51 stack.set_visible_child_name("assistant");62 stack.set_visible_child_name("assistant");
52 headerbar.pack_start (back_button);63 headerbar.pack_start (back_button);
53 back_button.show_all ();64 back_button.show_all ();
54 //fix ugly border at the bottom of headerbar65 //fix ugly border at the bottom of headerbar
55 queue_draw ();66 queue_draw ();
67
68 if (desktop_file != null)
69 assistant.edit_desktop_file (desktop_file);
56 }70 }
5771
58 private void show_apps_view () {72 private void show_apps_view () {
59 stack.set_transition_type (Gtk.StackTransitionType.SLIDE_RIGHT);73 stack.set_transition_type (Gtk.StackTransitionType.SLIDE_RIGHT);
60 stack.set_visible_child_name("apps_view");74 stack.set_visible_child_name("apps_view");
61 headerbar.remove (back_button);75 headerbar.remove (back_button);
76 assistant.reset_fields ();
62 }77 }
63}78}
6479
=== modified file 'src/ApplicationsView.vala'
--- src/ApplicationsView.vala 2015-10-11 13:32:10 +0000
+++ src/ApplicationsView.vala 2015-10-12 21:56:20 +0000
@@ -1,6 +1,7 @@
1public class ApplicationsView : Gtk.Box {1public class ApplicationsView : Gtk.Box {
22
3 public signal void add_request();3 public signal void add_request();
4 public signal void edit_request(DesktopFile desktop_file);
45
5 private Gtk.FlowBox icon_view;6 private Gtk.FlowBox icon_view;
6 private Gee.HashMap<string, GLib.DesktopAppInfo> applications;7 private Gee.HashMap<string, GLib.DesktopAppInfo> applications;
@@ -51,10 +52,14 @@
51 }52 }
5253
53 public void add_button (GLib.DesktopAppInfo app) {54 public void add_button (GLib.DesktopAppInfo app) {
54 var image = new ApplicationIcon(app.get_icon ().to_string (), app.get_display_name ());55 var image = new ApplicationIcon (app);
55 var desktop_file = new DesktopFile.from_desktopappinfo (app);56 image.edit_request.connect ((desktop_file) => {
56 image.delete_request.connect (()=>{57 edit_request (desktop_file);
57 desktop_file.delete_file();58 icon_view.unselect_all ();
59 });
60 image.deleted.connect ((parent) => {
61 this.icon_view.remove (parent);
62 this.select_first_item ();
58 });63 });
59 icon_view.add (image);64 icon_view.add (image);
60 icon_view.show_all ();65 icon_view.show_all ();
@@ -63,6 +68,24 @@
63 public void select_last_item () {68 public void select_last_item () {
64 icon_view.select_child (icon_view.get_child_at_index ((int)icon_view.get_children ().length () - 1));69 icon_view.select_child (icon_view.get_child_at_index ((int)icon_view.get_children ().length () - 1));
65 }70 }
71
72 public void select_first_item () {
73 icon_view.select_child (icon_view.get_child_at_index (0));
74 }
75
76 public void update_button (GLib.DesktopAppInfo app) {
77 foreach (var item in icon_view.get_children ()) {
78 if ((item as Gtk.FlowBoxChild).get_child () is ApplicationIcon) {
79 var app_icon = (item as Gtk.FlowBoxChild).get_child () as ApplicationIcon;
80
81 if (app_icon.desktop_file.name == app.get_display_name ()) {
82 app_icon.set_new_desktopfile (new DesktopFile.from_desktopappinfo (app));
83 icon_view.select_child (item as Gtk.FlowBoxChild);
84 break;
85 }
86 }
87 }
88 }
66}89}
6790
6891
@@ -74,14 +97,63 @@
74 Gtk.Box box;97 Gtk.Box box;
75 Gtk.ActionGroup action_group;98 Gtk.ActionGroup action_group;
7699
77 public signal void delete_request ();100 internal DesktopFile desktop_file { get; private set; }
78101
79 public ApplicationIcon (string icon, string label_str) {102 public signal void deleted (Gtk.Container? parent);
103 public signal void edit_request (DesktopFile desktop_file);
104
105 public ApplicationIcon (GLib.DesktopAppInfo app) {
106 this.desktop_file = new DesktopFile.from_desktopappinfo (app);
107
80 hexpand = false;108 hexpand = false;
81 vexpand = false;109 vexpand = false;
82110
83 label = new Gtk.Label (label_str);111 label = new Gtk.Label (this.desktop_file.name);
84112
113 set_icon (this.desktop_file.icon);
114
115 this.margin = 6;
116 this.margin_start = 20;
117 this.margin_end = 20;
118
119 var menu = new ActionMenu ();
120 menu.halign = Gtk.Align.CENTER;
121 menu.delete_clicked.connect (() => { remove_application (); });
122 menu.edit_clicked.connect (() => { edit_request (desktop_file); });
123
124 box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
125 box.pack_start (image, false, false, 0);
126 box.pack_start (label, false, false, 0);
127 box.pack_start (menu, false, false, 0);
128
129 box.hexpand = false;
130 box.vexpand = false;
131
132 var event_box = new Gtk.EventBox ();
133 event_box.add (box);
134 event_box.events |= Gdk.EventMask.ENTER_NOTIFY_MASK|Gdk.EventMask.LEAVE_NOTIFY_MASK;
135
136 event_box.enter_notify_event.connect ((event) => {
137 menu.set_reveal_child (true);
138 return false;
139 });
140
141 event_box.leave_notify_event.connect ((event) => {
142 if (event.detail == Gdk.NotifyType.INFERIOR)
143 return false;
144 menu.set_reveal_child (false);
145 return false;
146 });
147
148 this.add (event_box);
149 }
150
151 public void set_new_desktopfile (DesktopFile desktop_file) {
152 this.desktop_file = desktop_file;
153 set_icon (this.desktop_file.icon);
154 }
155
156 private void set_icon (string icon) {
85 if (File.new_for_path (icon).query_exists ()) {157 if (File.new_for_path (icon).query_exists ()) {
86 var pix = new Gdk.Pixbuf.from_file (icon);158 var pix = new Gdk.Pixbuf.from_file (icon);
87159
@@ -97,7 +169,11 @@
97 new_height = new_height * pix.height / pix.width;169 new_height = new_height * pix.height / pix.width;
98 margin_vertical = (new_width - new_height) / 2;170 margin_vertical = (new_width - new_height) / 2;
99 }171 }
100 image = new Gtk.Image.from_pixbuf (pix.scale_simple (new_width, new_height, Gdk.InterpType.BILINEAR));172 if (image == null)
173 image = new Gtk.Image.from_pixbuf (pix.scale_simple (new_width, new_height, Gdk.InterpType.BILINEAR));
174 else
175 image.set_from_pixbuf (pix.scale_simple (new_width, new_height, Gdk.InterpType.BILINEAR));
176
101 image.margin_top = margin_vertical;177 image.margin_top = margin_vertical;
102 image.margin_bottom = margin_vertical;178 image.margin_bottom = margin_vertical;
103 image.margin_right = margin_horizontal;179 image.margin_right = margin_horizontal;
@@ -107,48 +183,38 @@
107 image.icon_name = icon;183 image.icon_name = icon;
108 image.pixel_size = 64;184 image.pixel_size = 64;
109 }185 }
110
111 this.margin = 5;
112 this.margin_start = 20;
113 this.margin_end = 20;
114
115 box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
116 box.pack_start (image, false, false, 0);
117 box.pack_start (label, false, false, 0);
118 box.hexpand = false;
119 box.vexpand = false;
120
121 conf_btn = new Gtk.MenuButton();
122 conf_btn.valign = Gtk.Align.START;
123 conf_btn.halign = Gtk.Align.END;
124 conf_btn.get_style_context ().remove_class ("button");
125 conf_btn.get_style_context ().add_class ("titlebutton");
126 conf_btn.set_image (new Gtk.Image.from_icon_name("document-properties", Gtk.IconSize.MENU));
127
128 build_menu ();
129
130 this.add (box);
131 this.add_overlay (conf_btn);
132 }186 }
133187
134 private void remove_application () {188 private void remove_application () {
135 delete_request ();189 desktop_file.delete_file ();
136 this.get_parent().get_parent().remove(this.get_parent());190 deleted (this.get_parent());
137 this.destroy ();191 this.destroy ();
138 }192 }
139193}
140 private void build_menu () {194
141195public class ActionMenu : Gtk.Revealer {
142 Gtk.Menu menu = new Gtk.Menu ();196
143197 public signal void delete_clicked ();
144 Gtk.MenuItem remove_app = new Gtk.MenuItem.with_label (_("Remove Application"));198 public signal void edit_clicked ();
145 menu.add (remove_app);199
146200 public ActionMenu () {
147 remove_app.activate.connect( () => {201 var delete_button = new Gtk.Button.from_icon_name ("edit-delete-symbolic", Gtk.IconSize.BUTTON);
148 remove_application ();202 delete_button.tooltip_text = _("Delete Webapp");
149 });203 delete_button.relief = Gtk.ReliefStyle.NONE;
150204 delete_button.clicked.connect (() => { delete_clicked (); });
151 menu.show_all();205
152 conf_btn.set_popup (menu);206 var edit_button = new Gtk.Button.from_icon_name ("edit-symbolic", Gtk.IconSize.BUTTON);
207 edit_button.tooltip_text = _("Edit Webapp Properties");
208 edit_button.relief = Gtk.ReliefStyle.NONE;
209 edit_button.clicked.connect (() => { edit_clicked (); });
210
211 var buttons = new Gtk.Grid ();
212 buttons.orientation = Gtk.Orientation.HORIZONTAL;
213 buttons.add (edit_button);
214 buttons.add (delete_button);
215 buttons.opacity = 0.5;
216
217 this.transition_type = Gtk.RevealerTransitionType.CROSSFADE;
218 this.add (buttons);
153 }219 }
154}220}
155221
=== modified file 'src/Assistant.vala'
--- src/Assistant.vala 2015-10-07 20:47:50 +0000
+++ src/Assistant.vala 2015-10-12 21:56:20 +0000
@@ -1,6 +1,9 @@
1public class WebbyAssistant : Gtk.Box {1public class WebbyAssistant : Gtk.Box {
22
3 public enum assistant_mode { new_app, edit_app }
4
3 public signal void application_created (GLib.DesktopAppInfo? new_file);5 public signal void application_created (GLib.DesktopAppInfo? new_file);
6 public signal void application_edited (GLib.DesktopAppInfo? new_file);
47
5 private Gtk.Label message;8 private Gtk.Label message;
6 private Gtk.Button icon_button;9 private Gtk.Button icon_button;
@@ -22,6 +25,8 @@
22 private bool app_url_valid = false;25 private bool app_url_valid = false;
23 private bool app_icon_valid = true;26 private bool app_icon_valid = true;
2427
28 private assistant_mode mode { get; set; default = assistant_mode.new_app; }
29
25 public WebbyAssistant () {30 public WebbyAssistant () {
2631
27 GLib.Object (orientation: Gtk.Orientation.VERTICAL);32 GLib.Object (orientation: Gtk.Orientation.VERTICAL);
@@ -102,7 +107,7 @@
102107
103108
104 //create button109 //create button
105 accept_button = new Gtk.Button.with_label(_("Create app"));110 accept_button = new Gtk.Button.with_label(_("Save app"));
106 accept_button.halign = Gtk.Align.END;111 accept_button.halign = Gtk.Align.END;
107 accept_button.get_style_context ().add_class ("suggested-action");112 accept_button.get_style_context ().add_class ("suggested-action");
108 accept_button.set_sensitive (false);113 accept_button.set_sensitive (false);
@@ -134,7 +139,7 @@
134 });139 });
135140
136 app_name_entry.changed.connect (()=>{141 app_name_entry.changed.connect (()=>{
137 if (DesktopFile.get_applications().has_key (app_name_entry.get_text()) ) {142 if (mode == assistant_mode.new_app && DesktopFile.get_applications().has_key (app_name_entry.get_text()) ) {
138 app_name_entry.get_style_context ().add_class ("error");143 app_name_entry.get_style_context ().add_class ("error");
139 app_name_entry.set_icon_from_icon_name (Gtk.EntryIconPosition.SECONDARY, "dialog-information");144 app_name_entry.set_icon_from_icon_name (Gtk.EntryIconPosition.SECONDARY, "dialog-information");
140 app_name_entry.set_icon_tooltip_text (Gtk.EntryIconPosition.SECONDARY, _("App already exist"));145 app_name_entry.set_icon_tooltip_text (Gtk.EntryIconPosition.SECONDARY, _("App already exist"));
@@ -247,13 +252,15 @@
247 }252 }
248253
249254
250 private void reset_fields () {255 public void reset_fields () {
251 icon_name_entry.set_text ("");256 icon_name_entry.set_text ("");
252 app_name_entry.set_text ("");257 app_name_entry.set_text ("");
258 app_name_entry.set_sensitive (true);
253 app_url_entry.set_text ("");259 app_url_entry.set_text ("");
254 app_name_entry.get_style_context ().remove_class ("error");260 app_name_entry.get_style_context ().remove_class ("error");
255 app_url_entry.get_style_context ().remove_class ("error");261 app_url_entry.get_style_context ().remove_class ("error");
256 icon_button.set_image (new Gtk.Image.from_icon_name (default_app_icon, Gtk.IconSize.DIALOG) );262 icon_button.set_image (new Gtk.Image.from_icon_name (default_app_icon, Gtk.IconSize.DIALOG) );
263 mode = assistant_mode.new_app;
257 }264 }
258265
259 private void on_accept () {266 private void on_accept () {
@@ -267,8 +274,23 @@
267274
268 if (app_icon_valid && app_name_valid && app_url_valid) {275 if (app_icon_valid && app_name_valid && app_url_valid) {
269 var desktop_file = new DesktopFile (name, url, icon);276 var desktop_file = new DesktopFile (name, url, icon);
270 reset_fields ();277 switch (mode) {
271 application_created (desktop_file.save_to_file ());278 case assistant_mode.new_app:
279 application_created (desktop_file.save_to_file ());
280 break;
281 case assistant_mode.edit_app:
282 application_edited (desktop_file.save_to_file ());
283 break;
284 }
272 }285 }
273 }286 }
287
288 public void edit_desktop_file (DesktopFile desktop_file) {
289 mode = assistant_mode.edit_app;
290 app_name_entry.text = desktop_file.name;
291 app_name_entry.set_sensitive (false);
292 app_url_entry.text = desktop_file.url;
293 icon_name_entry.text = desktop_file.icon;
294 update_app_icon ();
295 }
274}296}
275297
=== modified file 'src/DesktopFile.vala'
--- src/DesktopFile.vala 2015-10-07 20:47:50 +0000
+++ src/DesktopFile.vala 2015-10-12 21:56:20 +0000
@@ -19,7 +19,15 @@
1919
20 private GLib.KeyFile file;20 private GLib.KeyFile file;
2121
22 public string name { get; private set; }
23 public string url { get; private set; }
24 public string icon { get; private set; }
25
22 public DesktopFile (string name, string url, string icon) {26 public DesktopFile (string name, string url, string icon) {
27 this.name = name;
28 this.url = url;
29 this.icon = icon;
30
23 file = new GLib.KeyFile();31 file = new GLib.KeyFile();
24 file.load_from_data (template, -1, GLib.KeyFileFlags.NONE);32 file.load_from_data (template, -1, GLib.KeyFileFlags.NONE);
25 //TODO: Category33 //TODO: Category
@@ -34,6 +42,9 @@
34 public DesktopFile.from_desktopappinfo(GLib.DesktopAppInfo info) {42 public DesktopFile.from_desktopappinfo(GLib.DesktopAppInfo info) {
35 file = new GLib.KeyFile();43 file = new GLib.KeyFile();
36 file.load_from_file (info.filename, KeyFileFlags.NONE);44 file.load_from_file (info.filename, KeyFileFlags.NONE);
45 this.name = info.get_display_name ();
46 this.icon = info.get_icon ().to_string ();
47 this.url = file.get_string ("Desktop Entry", "Exec").substring (6);
37 }48 }
3849
39 public bool edit_propertie (string propertie, string val) {50 public bool edit_propertie (string propertie, string val) {

Subscribers

People subscribed via source and target branches

to all changes: