1
1
public class ApplicationsView : Gtk.Box {
3
3
public signal void add_request();
4
public signal void edit_request(DesktopFile desktop_file);
5
6
private Gtk.FlowBox icon_view;
6
7
private Gee.HashMap<string, GLib.DesktopAppInfo> applications;
53
54
public void add_button (GLib.DesktopAppInfo app) {
54
var image = new ApplicationIcon(app.get_icon ().to_string (), app.get_display_name ());
55
var desktop_file = new DesktopFile.from_desktopappinfo (app);
56
image.delete_request.connect (()=>{
57
desktop_file.delete_file();
55
var image = new ApplicationIcon (app);
56
image.edit_request.connect ((desktop_file) => {
57
edit_request (desktop_file);
58
icon_view.unselect_all ();
60
image.deleted.connect ((parent) => {
61
this.icon_view.remove (parent);
62
this.select_first_item ();
59
64
icon_view.add (image);
60
65
icon_view.show_all ();
63
68
public void select_last_item () {
64
69
icon_view.select_child (icon_view.get_child_at_index ((int)icon_view.get_children ().length () - 1));
72
public void select_first_item () {
73
icon_view.select_child (icon_view.get_child_at_index (0));
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;
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);
75
98
Gtk.ActionGroup action_group;
77
public signal void delete_request ();
79
public ApplicationIcon (string icon, string label_str) {
100
internal DesktopFile desktop_file { get; private set; }
102
public signal void deleted (Gtk.Container? parent);
103
public signal void edit_request (DesktopFile desktop_file);
105
public ApplicationIcon (GLib.DesktopAppInfo app) {
106
this.desktop_file = new DesktopFile.from_desktopappinfo (app);
83
label = new Gtk.Label (label_str);
111
label = new Gtk.Label (this.desktop_file.name);
113
set_icon (this.desktop_file.icon);
116
this.margin_start = 20;
117
this.margin_end = 20;
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); });
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);
132
var event_box = new Gtk.EventBox ();
134
event_box.events |= Gdk.EventMask.ENTER_NOTIFY_MASK|Gdk.EventMask.LEAVE_NOTIFY_MASK;
136
event_box.enter_notify_event.connect ((event) => {
137
menu.set_reveal_child (true);
141
event_box.leave_notify_event.connect ((event) => {
142
if (event.detail == Gdk.NotifyType.INFERIOR)
144
menu.set_reveal_child (false);
148
this.add (event_box);
151
public void set_new_desktopfile (DesktopFile desktop_file) {
152
this.desktop_file = desktop_file;
153
set_icon (this.desktop_file.icon);
156
private void set_icon (string icon) {
85
157
if (File.new_for_path (icon).query_exists ()) {
86
158
var pix = new Gdk.Pixbuf.from_file (icon);
97
169
new_height = new_height * pix.height / pix.width;
98
170
margin_vertical = (new_width - new_height) / 2;
100
image = new Gtk.Image.from_pixbuf (pix.scale_simple (new_width, new_height, Gdk.InterpType.BILINEAR));
173
image = new Gtk.Image.from_pixbuf (pix.scale_simple (new_width, new_height, Gdk.InterpType.BILINEAR));
175
image.set_from_pixbuf (pix.scale_simple (new_width, new_height, Gdk.InterpType.BILINEAR));
101
177
image.margin_top = margin_vertical;
102
178
image.margin_bottom = margin_vertical;
103
179
image.margin_right = margin_horizontal;
107
183
image.icon_name = icon;
108
184
image.pixel_size = 64;
112
this.margin_start = 20;
113
this.margin_end = 20;
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);
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));
131
this.add_overlay (conf_btn);
134
188
private void remove_application () {
136
this.get_parent().get_parent().remove(this.get_parent());
189
desktop_file.delete_file ();
190
deleted (this.get_parent());
140
private void build_menu () {
142
Gtk.Menu menu = new Gtk.Menu ();
144
Gtk.MenuItem remove_app = new Gtk.MenuItem.with_label (_("Remove Application"));
145
menu.add (remove_app);
147
remove_app.activate.connect( () => {
148
remove_application ();
152
conf_btn.set_popup (menu);
195
public class ActionMenu : Gtk.Revealer {
197
public signal void delete_clicked ();
198
public signal void edit_clicked ();
200
public ActionMenu () {
201
var delete_button = new Gtk.Button.from_icon_name ("edit-delete-symbolic", Gtk.IconSize.BUTTON);
202
delete_button.tooltip_text = _("Delete Webapp");
203
delete_button.relief = Gtk.ReliefStyle.NONE;
204
delete_button.clicked.connect (() => { delete_clicked (); });
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 (); });
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;
217
this.transition_type = Gtk.RevealerTransitionType.CROSSFADE;