Skip to content

Commit a94dc74

Browse files
committed
Add switch
1 parent 7388a99 commit a94dc74

File tree

3 files changed

+70
-6
lines changed

3 files changed

+70
-6
lines changed

data/gschema.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,10 @@
66
<summary>Whether indicator is hidden and inactive</summary>
77
<description>Always hide indicator if set to true. While hidden the indicator does not monitor the clipboard.</description>
88
</key>
9+
<key name="active" type="b">
10+
<default>true</default>
11+
<summary>Whether indicator is active</summary>
12+
<description>Whether the indicator is monitoring and recording the clipboard contents</description>
13+
</key>
914
</schema>
1015
</schemalist>

src/HistoryWidget.vala

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ public class Clipboard.HistoryWidget : Gtk.Box {
1212
public signal void close_request ();
1313

1414
construct {
15+
orientation = VERTICAL;
16+
spacing = 6;
17+
18+
var active_switch = new Granite.SwitchModelButton (_("Clipboard Manager")) {
19+
description = _("Monitoring the clipboard contents")
20+
};
21+
22+
Clipboard.Indicator.settings.bind ("active", active_switch, "active", DEFAULT);
23+
1524
clipboard_text_set = new Gee.HashSet<string> ();
1625

1726
clipboard_item_list = new Gtk.ListBox () {
@@ -24,6 +33,7 @@ public class Clipboard.HistoryWidget : Gtk.Box {
2433
scroll_box.hscrollbar_policy = Gtk.PolicyType.NEVER;
2534
scroll_box.add (clipboard_item_list);
2635

36+
add (active_switch);
2737
add (scroll_box);
2838
show_all ();
2939

@@ -105,4 +115,52 @@ public class Clipboard.HistoryWidget : Gtk.Box {
105115
add (label);
106116
}
107117
}
118+
119+
// Taken from the Code project (https://github.com/elementary/code)
120+
private class SettingSwitch : Gtk.Grid {
121+
public string label { get; construct; }
122+
public string settings_key { get; construct; }
123+
public string description { get; construct; }
124+
125+
public SettingSwitch (string label, string settings_key, string description = "") {
126+
Object (
127+
description: description,
128+
label: label,
129+
settings_key: settings_key
130+
);
131+
}
132+
133+
construct {
134+
var switch_widget = new Gtk.Switch () {
135+
valign = CENTER
136+
};
137+
138+
var label_widget = new Gtk.Label (label) {
139+
halign = START,
140+
hexpand = true,
141+
mnemonic_widget = switch_widget
142+
};
143+
144+
column_spacing = 12;
145+
attach (label_widget, 0, 0);
146+
attach (switch_widget, 1, 0, 1, 2);
147+
148+
if (description != "") {
149+
var description_label = new Gtk.Label (description) {
150+
halign = START,
151+
wrap = true,
152+
xalign = 0
153+
};
154+
description_label.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL);
155+
description_label.get_style_context ().add_class (Granite.STYLE_CLASS_SMALL_LABEL);
156+
157+
attach (description_label, 0, 1);
158+
159+
switch_widget.get_accessible ().accessible_description = description;
160+
}
161+
162+
Clipboard.Indicator.settings.bind (settings_key, switch_widget, "active", DEFAULT);
163+
}
164+
}
165+
108166
}

src/Indicator.vala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
*/
55

66
public class Clipboard.Indicator : Wingpanel.Indicator {
7-
private static GLib.Settings settings;
7+
public static GLib.Settings settings;
88
private static GLib.Settings gnome_privacy_settings;
99
private const string NORMAL_ICON_NAME = "edit-copy-symbolic";
1010
private const string STOPPED_ICON_NAME = "task-past-due-symbolic";
1111
private Gtk.Image panel_icon;
1212
private HistoryWidget history_widget;
13-
private Gtk.Box inactive_widget;
13+
private Gtk.Box privacy_widget;
1414
public bool always_hide { get; set; }
1515
public bool privacy_on { get; set; }
1616

@@ -37,12 +37,12 @@ public class Clipboard.Indicator : Wingpanel.Indicator {
3737
label = Granite.TOOLTIP_SECONDARY_TEXT_MARKUP.printf (_("History is off in the Privacy and Security settings")),
3838
use_markup = true
3939
};
40-
inactive_widget = new Gtk.Box (VERTICAL, 0) {
40+
privacy_widget = new Gtk.Box (VERTICAL, 0) {
4141
margin_start = 6,
4242
margin_end = 6
4343
};
44-
inactive_widget.add (inactive_header_label);
45-
inactive_widget.add (inactive_subheader_label);
44+
privacy_widget.add (inactive_header_label);
45+
privacy_widget.add (inactive_subheader_label);
4646
// Ensure correct appearance before showing
4747
get_display_widget ();
4848
get_widget ();
@@ -74,13 +74,14 @@ public class Clipboard.Indicator : Wingpanel.Indicator {
7474
});
7575

7676
this.notify["privacy-on"].connect (update_appearance);
77+
// this.notify["privacy-on"].connect (get_widget);
7778
this.notify["always-hide"].connect (update_appearance);
7879
update_appearance ();
7980
}
8081

8182
// There doesn't seem to be a way of stopping Wingpanel showing the (blank) popover in the inactive state
8283
// So show informative label.
83-
return !privacy_on ? history_widget : inactive_widget;
84+
return !privacy_on ? history_widget : privacy_widget;
8485
}
8586

8687
public override void opened () {

0 commit comments

Comments
 (0)