Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/HistoryWidget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class Clipboard.HistoryWidget : Gtk.Box {
private uint wait_timeout = 0;

public signal void close_request ();
public signal void changed ();

construct {
clipboard_text_set = new Gee.HashSet<string> ();
Expand Down Expand Up @@ -52,6 +53,7 @@ public class Clipboard.HistoryWidget : Gtk.Box {
clipboard_item_list.prepend (new_item);
clipboard_item_list.select_row (new_item);
clipboard_item_list.show_all ();
changed ();
}
});
}
Expand Down Expand Up @@ -97,5 +99,20 @@ public class Clipboard.HistoryWidget : Gtk.Box {

add (label);
}

}

public uint get_n_items () {
return clipboard_text_set.size;
}


public void clear_history () {
clipboard_text_set.clear ();
clipboard_item_list.@foreach ((child) => {
child.destroy ();
});

changed ();
}
}
59 changes: 52 additions & 7 deletions src/Indicator.vala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class Clipboard.Indicator : Wingpanel.Indicator {
private static GLib.Settings settings;
private Gtk.Image panel_icon;
private Gtk.Widget display_widget;
private HistoryWidget history_widget;

public Wingpanel.IndicatorManager.ServerType server_type { get; construct set; }
Expand All @@ -26,20 +26,43 @@ public class Clipboard.Indicator : Wingpanel.Indicator {
}

public override Gtk.Widget get_display_widget () {
if (panel_icon == null) {
panel_icon = new Gtk.Image.from_icon_name ("edit-copy-symbolic", Gtk.IconSize.SMALL_TOOLBAR);
if (display_widget == null) {
var panel_icon = new Gtk.Image.from_icon_name (
"edit-copy-symbolic",
Gtk.IconSize.SMALL_TOOLBAR
);

display_widget = new Gtk.EventBox () {
child = panel_icon
};

display_widget.events = BUTTON_PRESS_MASK;


if (server_type == Wingpanel.IndicatorManager.ServerType.GREETER) {
this.visible = false;
} else {
// var visible_settings = new Settings ("io.elementary.desktop.wingpanel.clipboard");
// visible_settings.bind ("show-indicator", this, "visible", SettingsBindFlags.DEFAULT);
this.visible = true;
}

get_widget (); // Initialize history widget
history_widget.changed.connect (update_tooltip);

// EventController does not work?
display_widget.button_press_event.connect ((event) => {
if (event.button == 3) {
history_widget.clear_history ();
return true;
}

return false;
});

display_widget.show_all ();
update_tooltip ();
}

get_widget ();
return panel_icon;
return display_widget;
}

public override Gtk.Widget? get_widget () {
Expand All @@ -60,6 +83,28 @@ public class Clipboard.Indicator : Wingpanel.Indicator {

public override void closed () {
}

private void update_tooltip () {
uint n_items = history_widget.get_n_items ();
string description;
if (n_items > 0) {
description = ngettext (
_("Clipboard Manager: %u item"),
_("Clipboard Manager: %u items"),
n_items
).printf (n_items);
} else {
description = _("Clipboard Manager: Empty");
}

if (n_items > 0) {
string accel_label = n_items > 0 ? _("Middle-click to clear") : "";
accel_label = Granite.TOOLTIP_SECONDARY_TEXT_MARKUP.printf (accel_label);
display_widget.tooltip_markup = "%s\n%s".printf (description, accel_label);
} else {
display_widget.tooltip_markup = "%s".printf (description);
}
}
}

public Wingpanel.Indicator? get_indicator (Module module, Wingpanel.IndicatorManager.ServerType server_type) {
Expand Down