Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement confirmation dialog for deleting items #110

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
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
35 changes: 32 additions & 3 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ let ENABLE_KEYBINDING;
let PRIVATE_MODE;
let NOTIFY_ON_COPY;
let CONFIRM_ON_CLEAR;
let CONFIRM_REMOVE_FAVORITE;
let CONFIRM_REMOVE_NON_FAVORITE;
let MAX_TOPBAR_LENGTH;
let TOPBAR_DISPLAY_MODE; // 0 - only icon, 1 - only clipboard content, 2 - both, 3 - none
let DISABLE_DOWN_ARROW;
Expand Down Expand Up @@ -565,6 +567,27 @@ class ClipboardIndicator extends PanelMenu.Button {
}
}

_confirmRemoveEntry(entry, fullyDelete, humanGenerated) {
if ((entry.favorite && CONFIRM_REMOVE_FAVORITE ) || (!entry.favorite && CONFIRM_REMOVE_NON_FAVORITE)) {
const title = _('Delete Entry?');
const message = _('Are you sure you want to delete this entry?');
const sub_message = _('\n'+this._truncated(entry.text, MAX_VISIBLE_CHARS)+'\n\nThis operation cannot be undone.');

ConfirmDialog.openConfirmDialog(
title,
message,
sub_message,
_('Delete'),
_('Cancel'),
() => {
this._removeEntry(entry, fullyDelete, humanGenerated);
},
);
} else {
this._removeEntry(entry, fullyDelete, humanGenerated);
}
}

_pruneOldestEntries() {
let entry = this.entries.head;
while (
Expand All @@ -573,7 +596,7 @@ class ClipboardIndicator extends PanelMenu.Button {
this.entries.bytes > MAX_BYTES)
) {
const next = entry.next;
this._removeEntry(entry, true);
this._confirmRemoveEntry(entry, true);
entry = next;
}

Expand Down Expand Up @@ -847,7 +870,7 @@ class ClipboardIndicator extends PanelMenu.Button {
last.text.endsWith(text) ||
last.text.startsWith(text))
) {
this._removeEntry(last, true);
this._confirmRemoveEntry(last, true);
}
});
}
Expand Down Expand Up @@ -981,7 +1004,7 @@ class ClipboardIndicator extends PanelMenu.Button {
}

_deleteEntryAndRestoreLatest(entry) {
this._removeEntry(entry, true, true);
this._confirmRemoveEntry(entry, true, true);

if (!this.currentlySelectedEntry) {
const nextEntry = this.entries.last();
Expand Down Expand Up @@ -1060,6 +1083,12 @@ class ClipboardIndicator extends PanelMenu.Button {
CONFIRM_ON_CLEAR = Prefs.Settings.get_boolean(
Prefs.Fields.CONFIRM_ON_CLEAR,
);
CONFIRM_REMOVE_FAVORITE = Prefs.Settings.get_boolean(
Prefs.Fields.CONFIRM_REMOVE_FAVORITE,
);
CONFIRM_REMOVE_NON_FAVORITE = Prefs.Settings.get_boolean(
Prefs.Fields.CONFIRM_REMOVE_NON_FAVORITE,
);
ENABLE_KEYBINDING = Prefs.Settings.get_boolean(
Prefs.Fields.ENABLE_KEYBINDING,
);
Expand Down
28 changes: 28 additions & 0 deletions prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ var Fields = {
CACHE_ONLY_FAVORITES: 'cache-only-favorites',
NOTIFY_ON_COPY: 'notify-on-copy',
CONFIRM_ON_CLEAR: 'confirm-clear',
CONFIRM_REMOVE_FAVORITE: 'confirm-remove-favorite',
CONFIRM_REMOVE_NON_FAVORITE: 'confirm-remove-non-favorite',
MOVE_ITEM_FIRST: 'move-item-first',
ENABLE_KEYBINDING: 'enable-keybindings',
TOPBAR_PREVIEW_SIZE: 'topbar-preview-size',
Expand Down Expand Up @@ -84,6 +86,8 @@ class Prefs extends GObject.Object {
this.field_cache_disable = new Gtk.Switch();
this.field_notification_toggle = new Gtk.Switch();
this.field_confirm_clear_toggle = new Gtk.Switch();
this.field_confirm_remove_favorite_toggle = new Gtk.Switch();
this.field_confirm_remove_non_favorite_toggle = new Gtk.Switch();
this.field_strip_text = new Gtk.Switch();
this.field_paste_on_selection = new Gtk.Switch();
this.field_process_primary_selection = new Gtk.Switch();
Expand Down Expand Up @@ -155,6 +159,16 @@ class Prefs extends GObject.Object {
hexpand: true,
halign: Gtk.Align.START,
});
let confirmRemoveFavoriteLabel = new Gtk.Label({
label: _('Ask for confirmation before removing favorite entry'),
hexpand: true,
halign: Gtk.Align.START,
});
let confirmRemoveNonFavoriteLabel = new Gtk.Label({
label: _('Ask for confirmation before removing non-favorite entry'),
hexpand: true,
halign: Gtk.Align.START,
});
let moveFirstLabel = new Gtk.Label({
label: _('Move previously copied items to the top'),
hexpand: true,
Expand Down Expand Up @@ -232,6 +246,8 @@ class Prefs extends GObject.Object {
addRow(topbarPreviewLabel, this.field_topbar_preview_size);
addRow(notificationLabel, this.field_notification_toggle);
addRow(confirmClearLabel, this.field_confirm_clear_toggle);
addRow(confirmRemoveFavoriteLabel, this.field_confirm_remove_favorite_toggle);
addRow(confirmRemoveNonFavoriteLabel, this.field_confirm_remove_non_favorite_toggle);
addRow(keybindingLabel, this.field_keybinding_activation);
addRow(null, this.field_keybinding);

Expand Down Expand Up @@ -271,6 +287,18 @@ class Prefs extends GObject.Object {
'active',
Gio.SettingsBindFlags.DEFAULT,
);
Settings.bind(
Fields.CONFIRM_REMOVE_FAVORITE,
this.field_confirm_remove_favorite_toggle,
'active',
Gio.SettingsBindFlags.DEFAULT,
);
Settings.bind(
Fields.CONFIRM_REMOVE_NON_FAVORITE,
this.field_confirm_remove_non_favorite_toggle,
'active',
Gio.SettingsBindFlags.DEFAULT,
);
Settings.bind(
Fields.MOVE_ITEM_FIRST,
this.field_move_item_first,
Expand Down
16 changes: 16 additions & 0 deletions schemas/org.gnome.shell.extensions.clipboard-indicator.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@
</description>
</key>

<key name="confirm-remove-favorite" type="b">
<default>true</default>
<summary>Show confirmation dialog on removal of favorite entry</summary>
<description>
If true, a confirmation dialog is shown when attempting to remove a favorite entry.
</description>
</key>

<key name="confirm-remove-non-favorite" type="b">
<default>true</default>
<summary>Show confirmation dialog on removal of non-favorite entry</summary>
<description>
If true, a confirmation dialog is shown when attempting to remove a non-favorite entry.
</description>
</key>

<key name="strip-text" type="b">
<default>false</default>
<summary>Remove whitespace around copied plaintext items</summary>
Expand Down