|
|
|
|
@@ -12,13 +12,13 @@ use std::{
|
|
|
|
|
use anyhow::{Context, Result};
|
|
|
|
|
use gtk4::prelude::*;
|
|
|
|
|
use gtk4::{
|
|
|
|
|
Application, ApplicationWindow, Box as GtkBox, Button, CheckButton, Entry, Label, ListBox,
|
|
|
|
|
ListBoxRow, Orientation, ResponseType, Scale, ScrolledWindow, SpinButton, TextView,
|
|
|
|
|
Application, ApplicationWindow, Box as GtkBox, Button, CheckButton, ComboBoxText, Entry, Label,
|
|
|
|
|
ListBox, ListBoxRow, Orientation, ResponseType, Scale, ScrolledWindow, SpinButton, TextView,
|
|
|
|
|
};
|
|
|
|
|
use zeroize::Zeroizing;
|
|
|
|
|
|
|
|
|
|
use crate::{
|
|
|
|
|
config::Config,
|
|
|
|
|
config::{Config, Theme},
|
|
|
|
|
core::{highlight_ranges, search},
|
|
|
|
|
lifecycle::InstanceGuard,
|
|
|
|
|
platform::{
|
|
|
|
|
@@ -61,15 +61,14 @@ struct RowActions {
|
|
|
|
|
delete: Button,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const COPY_ICON: &str = "📋";
|
|
|
|
|
const PASTE_ICON: &str = "↪";
|
|
|
|
|
const DELETE_ICON: &str = "🗑";
|
|
|
|
|
const PIN_ICON: &str = "📌";
|
|
|
|
|
const UNPIN_ICON: &str = "📍";
|
|
|
|
|
const CLEAR_ICON: &str = "🧹";
|
|
|
|
|
const PAUSE_ICON: &str = "⏸";
|
|
|
|
|
const PLAY_ICON: &str = "▶";
|
|
|
|
|
const HELP_ICON: &str = "❓";
|
|
|
|
|
const COPY_ICON: &str = "edit-copy-symbolic";
|
|
|
|
|
const PASTE_ICON: &str = "edit-paste-symbolic";
|
|
|
|
|
const DELETE_ICON: &str = "user-trash-symbolic";
|
|
|
|
|
const PIN_ICON: &str = "view-pin-symbolic";
|
|
|
|
|
const UNPIN_ICON: &str = "edit-undo-symbolic";
|
|
|
|
|
const CLEAR_ICON: &str = "edit-clear-all-symbolic";
|
|
|
|
|
const PAUSE_ICON: &str = "media-playback-pause-symbolic";
|
|
|
|
|
const HELP_ICON: &str = "help-about-symbolic";
|
|
|
|
|
|
|
|
|
|
pub fn run(config: Config, instance: InstanceGuard, show_on_start: bool) -> Result<()> {
|
|
|
|
|
let database_path = Database::default_path();
|
|
|
|
|
@@ -315,15 +314,30 @@ fn build_window(
|
|
|
|
|
root.append(&search_box);
|
|
|
|
|
root.append(&scroll);
|
|
|
|
|
let actions = GtkBox::new(Orientation::Horizontal, 6);
|
|
|
|
|
let copy_button = Button::with_label(&format!("{COPY_ICON} Copy"));
|
|
|
|
|
let paste_button = Button::with_label(&format!("{PASTE_ICON} Paste"));
|
|
|
|
|
let pin_button = Button::with_label(&format!("{PIN_ICON} Pin / Unpin"));
|
|
|
|
|
let delete_button = Button::with_label(&format!("{DELETE_ICON} Delete"));
|
|
|
|
|
let clear_button = Button::with_label(&format!("{CLEAR_ICON} Clear History"));
|
|
|
|
|
let pause_button = Button::with_label(&format!("{PAUSE_ICON} Pause Recording"));
|
|
|
|
|
let help_button = Button::with_label(&format!("{HELP_ICON} Help"));
|
|
|
|
|
let change_passphrase_button = Button::with_label("Change passphrase");
|
|
|
|
|
actions.add_css_class("footer");
|
|
|
|
|
let copy_button = Button::with_label("Copy");
|
|
|
|
|
let paste_button = Button::with_label("Paste");
|
|
|
|
|
let pin_button = Button::with_label("Pin / Unpin");
|
|
|
|
|
let delete_button = Button::with_label("Delete");
|
|
|
|
|
let clear_button = Button::with_label("Clear History");
|
|
|
|
|
let pause_button = Button::with_label("Pause Recording");
|
|
|
|
|
let help_button = Button::from_icon_name(HELP_ICON);
|
|
|
|
|
help_button.set_tooltip_text(Some("Help"));
|
|
|
|
|
let settings_button = Button::with_label("Settings");
|
|
|
|
|
copy_button.set_tooltip_text(Some("Copy selected entry"));
|
|
|
|
|
paste_button.set_tooltip_text(Some("Paste selected entry"));
|
|
|
|
|
pin_button.set_tooltip_text(Some("Pin or unpin selected entry"));
|
|
|
|
|
delete_button.set_tooltip_text(Some("Delete selected entry"));
|
|
|
|
|
clear_button.set_tooltip_text(Some("Clear unpinned clipboard history"));
|
|
|
|
|
pause_button.set_tooltip_text(Some("Pause or resume clipboard recording"));
|
|
|
|
|
settings_button.set_tooltip_text(Some("Open settings"));
|
|
|
|
|
copy_button.set_icon_name(COPY_ICON);
|
|
|
|
|
paste_button.set_icon_name(PASTE_ICON);
|
|
|
|
|
pin_button.set_icon_name(PIN_ICON);
|
|
|
|
|
delete_button.set_icon_name(DELETE_ICON);
|
|
|
|
|
clear_button.set_icon_name(CLEAR_ICON);
|
|
|
|
|
pause_button.set_icon_name(PAUSE_ICON);
|
|
|
|
|
settings_button.set_icon_name("emblem-system-symbolic");
|
|
|
|
|
let row_actions = RowActions {
|
|
|
|
|
copy: copy_button.clone(),
|
|
|
|
|
paste: paste_button.clone(),
|
|
|
|
|
@@ -340,15 +354,31 @@ fn build_window(
|
|
|
|
|
&status,
|
|
|
|
|
&format!("Recording clipboard changes · {hotkey_status}"),
|
|
|
|
|
);
|
|
|
|
|
actions.append(©_button);
|
|
|
|
|
actions.append(&paste_button);
|
|
|
|
|
actions.append(&pin_button);
|
|
|
|
|
actions.append(&delete_button);
|
|
|
|
|
actions.append(&clear_button);
|
|
|
|
|
actions.append(&pause_button);
|
|
|
|
|
actions.append(&help_button);
|
|
|
|
|
actions.append(&change_passphrase_button);
|
|
|
|
|
actions.append(&settings_button);
|
|
|
|
|
let entry_actions = GtkBox::new(Orientation::Horizontal, 6);
|
|
|
|
|
entry_actions.append(&pin_button);
|
|
|
|
|
entry_actions.append(©_button);
|
|
|
|
|
entry_actions.append(&paste_button);
|
|
|
|
|
entry_actions.append(&delete_button);
|
|
|
|
|
|
|
|
|
|
let history_actions = GtkBox::new(Orientation::Horizontal, 6);
|
|
|
|
|
history_actions.append(&pause_button);
|
|
|
|
|
history_actions.append(&clear_button);
|
|
|
|
|
|
|
|
|
|
let utility_actions = GtkBox::new(Orientation::Horizontal, 6);
|
|
|
|
|
utility_actions.append(&help_button);
|
|
|
|
|
utility_actions.append(&settings_button);
|
|
|
|
|
|
|
|
|
|
let left_spacer = GtkBox::new(Orientation::Horizontal, 0);
|
|
|
|
|
left_spacer.set_hexpand(true);
|
|
|
|
|
let right_spacer = GtkBox::new(Orientation::Horizontal, 0);
|
|
|
|
|
right_spacer.set_hexpand(true);
|
|
|
|
|
actions.append(&entry_actions);
|
|
|
|
|
actions.append(&left_spacer);
|
|
|
|
|
actions.append(&history_actions);
|
|
|
|
|
actions.append(&right_spacer);
|
|
|
|
|
actions.append(&utility_actions);
|
|
|
|
|
delete_button.add_css_class("destructive-action");
|
|
|
|
|
clear_button.add_css_class("destructive-action");
|
|
|
|
|
root.append(&actions);
|
|
|
|
|
root.append(&status);
|
|
|
|
|
let window = ApplicationWindow::builder()
|
|
|
|
|
@@ -361,10 +391,60 @@ fn build_window(
|
|
|
|
|
let inactive_opacity = Rc::new(std::cell::Cell::new(config.inactive_opacity));
|
|
|
|
|
let always_on_top = Rc::new(std::cell::Cell::new(config.always_on_top));
|
|
|
|
|
let clear_search_on_reopen = Rc::new(std::cell::Cell::new(config.clear_search_on_reopen));
|
|
|
|
|
let show_timestamps = Rc::new(std::cell::Cell::new(config.show_timestamps));
|
|
|
|
|
let runtime_config = Rc::new(RefCell::new(config.clone()));
|
|
|
|
|
let css = gtk4::CssProvider::new();
|
|
|
|
|
css.load_from_data(
|
|
|
|
|
"button.paused { background-color: #f3a6a6; color: #3d0000; font-weight: bold; } row.pinned { background-color: rgba(79, 107, 237, 0.10); border-radius: 6px; }",
|
|
|
|
|
"\
|
|
|
|
|
box.footer { border-top: 1px solid alpha(@theme_fg_color, 0.18); padding-top: 8px; }\
|
|
|
|
|
.theme-dark box.footer { border-top-color: alpha(#f0f3f6, 0.18); }\
|
|
|
|
|
.theme-light { color: #1f2328; background-color: #ffffff; }\
|
|
|
|
|
.theme-light entry, .theme-light textview, .theme-light button { color: #1f2328; background-color: #f6f8fa; }\
|
|
|
|
|
.theme-light button:hover { background-color: #eaeef2; }\
|
|
|
|
|
.theme-dark { color: #f0f3f6; background-color: #202124; }\
|
|
|
|
|
.theme-dark entry, .theme-dark textview, .theme-dark button { color: #f0f3f6; background-color: #2b2d31; }\
|
|
|
|
|
.theme-dark button:hover { background-color: #3a3d43; }\
|
|
|
|
|
button.suggested-action { background: @theme_selected_bg_color; color: @theme_selected_fg_color; }\
|
|
|
|
|
button.suggested-action:hover { background: shade(@theme_selected_bg_color, 1.08); }\
|
|
|
|
|
button.suggested-action:active { background: shade(@theme_selected_bg_color, 0.90); }\
|
|
|
|
|
button.destructive-action { background-color: @theme_bg_color; color: #c62828; }\
|
|
|
|
|
button.destructive-action:hover { background: alpha(#c62828, 0.12); }\
|
|
|
|
|
button.destructive-action:active { background: alpha(#c62828, 0.22); }\
|
|
|
|
|
.theme-dark button.destructive-action { background-color: #2b2d31; color: #ff8a80; }\
|
|
|
|
|
.theme-dark button.destructive-action:hover { background: alpha(#ff8a80, 0.16); }\
|
|
|
|
|
button:disabled { opacity: 0.55; }\
|
|
|
|
|
button:focus, entry:focus, spinbutton:focus, combobox:focus { outline: none; box-shadow: none; }\
|
|
|
|
|
button.paused { background: #f3a6a6; color: #3d0000; font-weight: bold; }\
|
|
|
|
|
button.paused:hover { background: #f7bcbc; }\
|
|
|
|
|
.theme-dark button.paused { background: #8a3b12; color: #fff4e5; }\
|
|
|
|
|
.theme-dark button.paused:hover { background: #a34a19; }\
|
|
|
|
|
row.pinned { background: #fff4cc; border-left: 3px solid #c58a00; border-radius: 6px; }\
|
|
|
|
|
.theme-dark row.pinned { background: #3b321f; border-left-color: #e0ad3f; }\
|
|
|
|
|
.theme-dark list, .theme-dark listbox, .theme-dark listbox row, .theme-dark listbox row label { background-color: #202124; color: #f0f3f6; }\
|
|
|
|
|
.theme-light list, .theme-light listbox, .theme-light listbox row, .theme-light listbox row label { background-color: #ffffff; color: #1f2328; }\
|
|
|
|
|
.theme-dark listbox row.pinned { background-color: #3b321f; border-left-color: #e0ad3f; }\
|
|
|
|
|
.theme-light listbox row.pinned { background-color: #fff4cc; border-left-color: #c58a00; }\
|
|
|
|
|
.theme-light listbox row:selected, .theme-dark listbox row:selected { background-color: #2f6fed; color: #ffffff; border-left-color: #8db4ff; }\
|
|
|
|
|
.theme-light listbox row:selected label, .theme-dark listbox row:selected label { color: #ffffff; }\
|
|
|
|
|
.theme-light listbox row.pinned:selected, .theme-dark listbox row.pinned:selected { background-color: #2f6fed; color: #ffffff; border-left-color: #e0ad3f; }\
|
|
|
|
|
.theme-light listbox row.pinned:selected > box, .theme-dark listbox row.pinned:selected > box { background-color: #2f6fed; color: #ffffff; }\
|
|
|
|
|
.theme-light listbox row.pinned:selected label, .theme-dark listbox row.pinned:selected label { color: #ffffff; }\
|
|
|
|
|
listbox row:selected { background-color: #2f6fed; color: #ffffff; border-left-color: #8db4ff; }\
|
|
|
|
|
listbox row:selected label { color: #ffffff; }\
|
|
|
|
|
listbox row.pinned:selected { background-color: #2f6fed; color: #ffffff; border-left-color: #e0ad3f; }\
|
|
|
|
|
listbox row.pinned:selected > box { background-color: #2f6fed; color: #ffffff; }\
|
|
|
|
|
listbox row.pinned:selected label { color: #ffffff; }\
|
|
|
|
|
row.selected-entry, row.selected-entry > box, box.selected-entry { background-color: #2f6fed; color: #ffffff; }\
|
|
|
|
|
row.selected-entry label { color: #ffffff; }\
|
|
|
|
|
row.pinned.selected-entry { border-left-color: #e0ad3f; }\
|
|
|
|
|
label.status { padding: 4px 8px; border-radius: 6px; color: @theme_unfocused_fg_color; }\
|
|
|
|
|
label.status.success { color: #16803c; }\
|
|
|
|
|
label.status.warning { color: #a15c00; }\
|
|
|
|
|
label.status.error { color: #c62828; }\
|
|
|
|
|
.theme-dark label.status.success { color: #72d492; }\
|
|
|
|
|
.theme-dark label.status.warning { color: #ffbf69; }\
|
|
|
|
|
.theme-dark label.status.error { color: #ff8a80; }\
|
|
|
|
|
",
|
|
|
|
|
);
|
|
|
|
|
if let Some(display) = gtk4::gdk::Display::default() {
|
|
|
|
|
gtk4::style_context_add_provider_for_display(
|
|
|
|
|
@@ -373,6 +453,7 @@ fn build_window(
|
|
|
|
|
gtk4::STYLE_PROVIDER_PRIORITY_APPLICATION,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
apply_theme(&root, &config.theme);
|
|
|
|
|
let window_for_opacity = window.clone();
|
|
|
|
|
let inactive_opacity_for_realize = Rc::clone(&inactive_opacity);
|
|
|
|
|
let always_on_top_for_realize = Rc::clone(&always_on_top);
|
|
|
|
|
@@ -426,7 +507,28 @@ fn build_window(
|
|
|
|
|
});
|
|
|
|
|
window.set_visible(show_on_start);
|
|
|
|
|
list.set_activate_on_single_click(false);
|
|
|
|
|
refresh_list(&list, &state.borrow().entries, "", Some(&row_actions));
|
|
|
|
|
let clear_selection_click = gtk4::GestureClick::new();
|
|
|
|
|
clear_selection_click.set_button(0);
|
|
|
|
|
let list_for_clear_selection = list.clone();
|
|
|
|
|
clear_selection_click.connect_pressed(move |_, _, _, y| {
|
|
|
|
|
if list_for_clear_selection.row_at_y(y as i32).is_none() {
|
|
|
|
|
list_for_clear_selection.select_row(None::<&ListBoxRow>);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
list.add_controller(clear_selection_click);
|
|
|
|
|
refresh_list(
|
|
|
|
|
&list,
|
|
|
|
|
&state.borrow().entries,
|
|
|
|
|
"",
|
|
|
|
|
show_timestamps.get(),
|
|
|
|
|
Some(&row_actions),
|
|
|
|
|
);
|
|
|
|
|
update_action_sensitivity(&list, &row_actions);
|
|
|
|
|
let actions_for_selection = row_actions.clone();
|
|
|
|
|
list.connect_selected_rows_changed(move |list| {
|
|
|
|
|
update_action_sensitivity(list, &actions_for_selection);
|
|
|
|
|
update_selection_visuals(list);
|
|
|
|
|
});
|
|
|
|
|
let window_for_details = window.clone();
|
|
|
|
|
let state_for_details = Rc::clone(&state);
|
|
|
|
|
list.connect_row_activated(move |_, row| {
|
|
|
|
|
@@ -452,6 +554,7 @@ fn build_window(
|
|
|
|
|
let list_for_search = list.clone();
|
|
|
|
|
let state_for_search = Rc::clone(&state);
|
|
|
|
|
let row_actions_for_search = row_actions.clone();
|
|
|
|
|
let show_timestamps_for_search = Rc::clone(&show_timestamps);
|
|
|
|
|
search_box.connect_changed(move |entry| {
|
|
|
|
|
let mut state = state_for_search.borrow_mut();
|
|
|
|
|
state.search_query = entry.text().to_string();
|
|
|
|
|
@@ -459,6 +562,7 @@ fn build_window(
|
|
|
|
|
&list_for_search,
|
|
|
|
|
&state.entries,
|
|
|
|
|
&state.search_query,
|
|
|
|
|
show_timestamps_for_search.get(),
|
|
|
|
|
Some(&row_actions_for_search),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
@@ -466,6 +570,7 @@ fn build_window(
|
|
|
|
|
let list_for_keys = list.clone();
|
|
|
|
|
let window_for_keys = window.clone();
|
|
|
|
|
let row_actions_for_keys = row_actions.clone();
|
|
|
|
|
let show_timestamps_for_keys = Rc::clone(&show_timestamps);
|
|
|
|
|
let delete_button_for_keys = delete_button.clone();
|
|
|
|
|
let keys = gtk4::EventControllerKey::new();
|
|
|
|
|
keys.set_propagation_phase(gtk4::PropagationPhase::Capture);
|
|
|
|
|
@@ -526,6 +631,7 @@ fn build_window(
|
|
|
|
|
&list_for_keys,
|
|
|
|
|
&state.entries,
|
|
|
|
|
&state.search_query,
|
|
|
|
|
show_timestamps_for_keys.get(),
|
|
|
|
|
Some(&row_actions_for_keys),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
@@ -594,6 +700,7 @@ fn build_window(
|
|
|
|
|
&list_for_keys,
|
|
|
|
|
&state.entries,
|
|
|
|
|
&state.search_query,
|
|
|
|
|
show_timestamps_for_keys.get(),
|
|
|
|
|
Some(&row_actions_for_keys),
|
|
|
|
|
);
|
|
|
|
|
return glib::Propagation::Stop;
|
|
|
|
|
@@ -667,6 +774,7 @@ fn build_window(
|
|
|
|
|
let pinned_list = list.clone();
|
|
|
|
|
let status_for_pin = status.clone();
|
|
|
|
|
let row_actions_for_pin = row_actions.clone();
|
|
|
|
|
let show_timestamps_for_pin = Rc::clone(&show_timestamps);
|
|
|
|
|
pin_button.connect_clicked(move |_| {
|
|
|
|
|
if let Some(id) = selected_id(&list_for_pin) {
|
|
|
|
|
let mut state = state_for_pin.borrow_mut();
|
|
|
|
|
@@ -679,6 +787,7 @@ fn build_window(
|
|
|
|
|
&pinned_list,
|
|
|
|
|
&state.entries,
|
|
|
|
|
&state.search_query,
|
|
|
|
|
show_timestamps_for_pin.get(),
|
|
|
|
|
Some(&row_actions_for_pin),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
@@ -696,6 +805,7 @@ fn build_window(
|
|
|
|
|
let status_for_delete = status.clone();
|
|
|
|
|
let row_actions_for_delete = row_actions.clone();
|
|
|
|
|
let window_for_delete = window.clone();
|
|
|
|
|
let show_timestamps_for_delete = Rc::clone(&show_timestamps);
|
|
|
|
|
delete_button.connect_clicked(move |_| {
|
|
|
|
|
if let Some(id) = selected_id(&list_for_delete) {
|
|
|
|
|
confirm_delete(
|
|
|
|
|
@@ -705,6 +815,7 @@ fn build_window(
|
|
|
|
|
deleted_list.clone(),
|
|
|
|
|
status_for_delete.clone(),
|
|
|
|
|
row_actions_for_delete.clone(),
|
|
|
|
|
show_timestamps_for_delete.get(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
@@ -713,31 +824,26 @@ fn build_window(
|
|
|
|
|
let shortcut_for_help = config.global_shortcut.clone();
|
|
|
|
|
help_button.connect_clicked(move |_| show_help(&window_for_help, &shortcut_for_help));
|
|
|
|
|
|
|
|
|
|
let window_for_passphrase = window.clone();
|
|
|
|
|
let state_for_passphrase = Rc::clone(&state);
|
|
|
|
|
let status_for_passphrase = status.clone();
|
|
|
|
|
change_passphrase_button.connect_clicked(move |_| {
|
|
|
|
|
change_passphrase(
|
|
|
|
|
&window_for_passphrase,
|
|
|
|
|
Rc::clone(&state_for_passphrase),
|
|
|
|
|
&status_for_passphrase,
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let window_for_settings = window.clone();
|
|
|
|
|
let root_for_settings = root.clone();
|
|
|
|
|
let config_for_settings = Rc::clone(&runtime_config);
|
|
|
|
|
let status_for_settings = status.clone();
|
|
|
|
|
let inactive_opacity_for_settings = Rc::clone(&inactive_opacity);
|
|
|
|
|
let always_on_top_for_settings = Rc::clone(&always_on_top);
|
|
|
|
|
let clear_search_for_settings = Rc::clone(&clear_search_on_reopen);
|
|
|
|
|
let show_timestamps_for_settings = Rc::clone(&show_timestamps);
|
|
|
|
|
let state_for_settings = Rc::clone(&state);
|
|
|
|
|
settings_button.connect_clicked(move |_| {
|
|
|
|
|
show_settings(
|
|
|
|
|
&window_for_settings,
|
|
|
|
|
&root_for_settings,
|
|
|
|
|
Rc::clone(&config_for_settings),
|
|
|
|
|
Rc::clone(&state_for_settings),
|
|
|
|
|
&status_for_settings,
|
|
|
|
|
Rc::clone(&inactive_opacity_for_settings),
|
|
|
|
|
Rc::clone(&always_on_top_for_settings),
|
|
|
|
|
Rc::clone(&clear_search_for_settings),
|
|
|
|
|
Rc::clone(&show_timestamps_for_settings),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@@ -745,23 +851,17 @@ fn build_window(
|
|
|
|
|
let cleared_list = list.clone();
|
|
|
|
|
let status_for_clear = status.clone();
|
|
|
|
|
let row_actions_for_clear = row_actions.clone();
|
|
|
|
|
let window_for_clear = window.clone();
|
|
|
|
|
let show_timestamps_for_clear = Rc::clone(&show_timestamps);
|
|
|
|
|
clear_button.connect_clicked(move |_| {
|
|
|
|
|
let mut state = state_for_clear.borrow_mut();
|
|
|
|
|
match state.database.clear_history() {
|
|
|
|
|
Ok(()) => {
|
|
|
|
|
state.entries.retain(|entry| entry.pinned);
|
|
|
|
|
refresh_list(
|
|
|
|
|
&cleared_list,
|
|
|
|
|
&state.entries,
|
|
|
|
|
&state.search_query,
|
|
|
|
|
Some(&row_actions_for_clear),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
Err(error) => {
|
|
|
|
|
tracing::error!(%error, "failed to clear unpinned clipboard history");
|
|
|
|
|
set_status(&status_for_clear, "Could not clear clipboard history");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
confirm_clear_history(
|
|
|
|
|
&window_for_clear,
|
|
|
|
|
Rc::clone(&state_for_clear),
|
|
|
|
|
cleared_list.clone(),
|
|
|
|
|
status_for_clear.clone(),
|
|
|
|
|
row_actions_for_clear.clone(),
|
|
|
|
|
show_timestamps_for_clear.get(),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let state_for_pause = Rc::clone(&state);
|
|
|
|
|
@@ -944,7 +1044,13 @@ fn process_clipboard_result(
|
|
|
|
|
}
|
|
|
|
|
state.entries.retain(|candidate| candidate.id != entry.id);
|
|
|
|
|
state.entries.push(entry);
|
|
|
|
|
refresh_list(list, &state.entries, &state.search_query, Some(actions));
|
|
|
|
|
refresh_list(
|
|
|
|
|
list,
|
|
|
|
|
&state.entries,
|
|
|
|
|
&state.search_query,
|
|
|
|
|
config.show_timestamps,
|
|
|
|
|
Some(actions),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
Err(error) => {
|
|
|
|
|
tracing::error!(%error, "failed to store clipboard entry");
|
|
|
|
|
@@ -969,9 +1075,70 @@ fn request_focus(state: &mut UiState) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn set_status(label: &Label, message: &str) {
|
|
|
|
|
label.remove_css_class("success");
|
|
|
|
|
label.remove_css_class("warning");
|
|
|
|
|
label.remove_css_class("error");
|
|
|
|
|
let lower = message.to_ascii_lowercase();
|
|
|
|
|
if lower.contains("could not") || lower.contains("failed") || lower.contains("unavailable") {
|
|
|
|
|
label.add_css_class("error");
|
|
|
|
|
} else if lower.contains("paused") {
|
|
|
|
|
label.add_css_class("warning");
|
|
|
|
|
} else if lower.contains("saved")
|
|
|
|
|
|| lower.contains("copied")
|
|
|
|
|
|| lower.contains("pasted")
|
|
|
|
|
|| lower.contains("deleted")
|
|
|
|
|
|| lower.contains("successfully")
|
|
|
|
|
{
|
|
|
|
|
label.add_css_class("success");
|
|
|
|
|
}
|
|
|
|
|
label.set_text(&format!("[{}] {message}", now_local_human()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn update_action_sensitivity(list: &ListBox, actions: &RowActions) {
|
|
|
|
|
let enabled = selected_id(list).is_some();
|
|
|
|
|
actions.copy.set_sensitive(enabled);
|
|
|
|
|
actions.paste.set_sensitive(enabled);
|
|
|
|
|
actions.pin.set_sensitive(enabled);
|
|
|
|
|
actions.delete.set_sensitive(enabled);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn update_selection_visuals(list: &ListBox) {
|
|
|
|
|
let selected = selected_id(list);
|
|
|
|
|
let mut child = list.first_child();
|
|
|
|
|
while let Some(widget) = child {
|
|
|
|
|
child = widget.next_sibling();
|
|
|
|
|
let Ok(row) = widget.downcast::<ListBoxRow>() else {
|
|
|
|
|
continue;
|
|
|
|
|
};
|
|
|
|
|
let is_selected = row
|
|
|
|
|
.tooltip_text()
|
|
|
|
|
.and_then(|tooltip| tooltip.parse::<i64>().ok())
|
|
|
|
|
== selected;
|
|
|
|
|
if is_selected {
|
|
|
|
|
row.add_css_class("selected-entry");
|
|
|
|
|
} else {
|
|
|
|
|
row.remove_css_class("selected-entry");
|
|
|
|
|
}
|
|
|
|
|
if let Some(content) = row.child() {
|
|
|
|
|
if is_selected {
|
|
|
|
|
content.add_css_class("selected-entry");
|
|
|
|
|
} else {
|
|
|
|
|
content.remove_css_class("selected-entry");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn apply_theme(root: &GtkBox, theme: &Theme) {
|
|
|
|
|
root.remove_css_class("theme-light");
|
|
|
|
|
root.remove_css_class("theme-dark");
|
|
|
|
|
match theme {
|
|
|
|
|
Theme::Light => root.add_css_class("theme-light"),
|
|
|
|
|
Theme::Dark => root.add_css_class("theme-dark"),
|
|
|
|
|
Theme::System => {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn update_recording_visuals(
|
|
|
|
|
button: &Button,
|
|
|
|
|
window: &ApplicationWindow,
|
|
|
|
|
@@ -980,11 +1147,16 @@ fn update_recording_visuals(
|
|
|
|
|
tray: Option<&crate::tray::TrayHandle>,
|
|
|
|
|
) {
|
|
|
|
|
let button_label = if recording {
|
|
|
|
|
format!("{PAUSE_ICON} Pause Recording")
|
|
|
|
|
"Pause Recording".to_owned()
|
|
|
|
|
} else {
|
|
|
|
|
format!("{PLAY_ICON} Resume Recording")
|
|
|
|
|
"Resume Recording".to_owned()
|
|
|
|
|
};
|
|
|
|
|
button.set_label(&button_label);
|
|
|
|
|
button.set_icon_name(if recording {
|
|
|
|
|
PAUSE_ICON
|
|
|
|
|
} else {
|
|
|
|
|
"media-playback-start-symbolic"
|
|
|
|
|
});
|
|
|
|
|
if recording {
|
|
|
|
|
button.remove_css_class("paused");
|
|
|
|
|
} else {
|
|
|
|
|
@@ -1005,6 +1177,7 @@ fn refresh_list(
|
|
|
|
|
list: &ListBox,
|
|
|
|
|
entries: &[crate::core::Entry],
|
|
|
|
|
query: &str,
|
|
|
|
|
show_timestamps: bool,
|
|
|
|
|
actions: Option<&RowActions>,
|
|
|
|
|
) {
|
|
|
|
|
let selected = selected_id(list);
|
|
|
|
|
@@ -1018,12 +1191,21 @@ fn refresh_list(
|
|
|
|
|
} else {
|
|
|
|
|
preview
|
|
|
|
|
};
|
|
|
|
|
let pinned_prefix = if entry.pinned { "📌 " } else { "" };
|
|
|
|
|
let pinned_prefix = if entry.pinned { "Pinned · " } else { "" };
|
|
|
|
|
let ranges = highlight_ranges(&preview, query);
|
|
|
|
|
let timestamp = if show_timestamps {
|
|
|
|
|
format!(
|
|
|
|
|
"<span alpha=\"70%\"> · {}</span>",
|
|
|
|
|
local_human(entry.created_at)
|
|
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
String::new()
|
|
|
|
|
};
|
|
|
|
|
let markup = format!(
|
|
|
|
|
"{}{}",
|
|
|
|
|
"{}{}{}",
|
|
|
|
|
glib::markup_escape_text(pinned_prefix),
|
|
|
|
|
highlighted_markup(&preview, &ranges)
|
|
|
|
|
highlighted_markup(&preview, &ranges),
|
|
|
|
|
timestamp,
|
|
|
|
|
);
|
|
|
|
|
let label = Label::new(None);
|
|
|
|
|
label.set_markup(&markup);
|
|
|
|
|
@@ -1036,7 +1218,8 @@ fn refresh_list(
|
|
|
|
|
let row = ListBoxRow::new();
|
|
|
|
|
let content = GtkBox::new(Orientation::Horizontal, 4);
|
|
|
|
|
if let Some(actions) = actions {
|
|
|
|
|
let pin_button = Button::with_label(if entry.pinned { UNPIN_ICON } else { PIN_ICON });
|
|
|
|
|
let pin_button =
|
|
|
|
|
Button::from_icon_name(if entry.pinned { UNPIN_ICON } else { PIN_ICON });
|
|
|
|
|
pin_button.set_tooltip_text(Some(if entry.pinned {
|
|
|
|
|
"Unpin entry"
|
|
|
|
|
} else {
|
|
|
|
|
@@ -1060,7 +1243,7 @@ fn refresh_list(
|
|
|
|
|
(PASTE_ICON, "Paste entry", actions.paste.clone()),
|
|
|
|
|
(DELETE_ICON, "Delete entry", actions.delete.clone()),
|
|
|
|
|
] {
|
|
|
|
|
let button = Button::with_label(icon);
|
|
|
|
|
let button = Button::from_icon_name(icon);
|
|
|
|
|
button.set_tooltip_text(Some(tooltip));
|
|
|
|
|
button.set_focus_on_click(false);
|
|
|
|
|
let row_for_action = row.clone();
|
|
|
|
|
@@ -1089,6 +1272,7 @@ fn refresh_list(
|
|
|
|
|
empty.set_margin_start(8);
|
|
|
|
|
list.append(&empty);
|
|
|
|
|
}
|
|
|
|
|
update_selection_visuals(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn selected_id(list: &ListBox) -> Option<i64> {
|
|
|
|
|
@@ -1103,7 +1287,7 @@ fn highlighted_markup(text: &str, ranges: &[(usize, usize)]) -> String {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
markup.push_str(&glib::markup_escape_text(&text[cursor..start]));
|
|
|
|
|
markup.push_str("<span background=\"#ffe680\" foreground=\"#000000\">");
|
|
|
|
|
markup.push_str("<span weight=\"bold\" underline=\"single\">");
|
|
|
|
|
markup.push_str(&glib::markup_escape_text(&text[start..end]));
|
|
|
|
|
markup.push_str("</span>");
|
|
|
|
|
cursor = end;
|
|
|
|
|
@@ -1140,13 +1324,17 @@ fn show_text_dialog(window: &ApplicationWindow, title: &str, content: &str) {
|
|
|
|
|
dialog.present();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[allow(clippy::too_many_arguments)]
|
|
|
|
|
fn show_settings(
|
|
|
|
|
window: &ApplicationWindow,
|
|
|
|
|
root: &GtkBox,
|
|
|
|
|
config: Rc<RefCell<Config>>,
|
|
|
|
|
state: Rc<RefCell<UiState>>,
|
|
|
|
|
status: &Label,
|
|
|
|
|
inactive_opacity: Rc<std::cell::Cell<f64>>,
|
|
|
|
|
always_on_top: Rc<std::cell::Cell<bool>>,
|
|
|
|
|
clear_search_on_reopen: Rc<std::cell::Cell<bool>>,
|
|
|
|
|
show_timestamps: Rc<std::cell::Cell<bool>>,
|
|
|
|
|
) {
|
|
|
|
|
let current_config = config.borrow().clone();
|
|
|
|
|
let dialog = gtk4::Dialog::builder()
|
|
|
|
|
@@ -1169,6 +1357,24 @@ fn show_settings(
|
|
|
|
|
let clear_search = CheckButton::with_label("Clear the search field when reopening");
|
|
|
|
|
clear_search.set_active(clear_search_on_reopen.get());
|
|
|
|
|
content.append(&clear_search);
|
|
|
|
|
let timestamps = CheckButton::with_label("Show entry timestamps");
|
|
|
|
|
timestamps.set_active(current_config.show_timestamps);
|
|
|
|
|
content.append(×tamps);
|
|
|
|
|
let theme_label = Label::new(Some("Appearance"));
|
|
|
|
|
theme_label.set_xalign(0.0);
|
|
|
|
|
theme_label.add_css_class("heading");
|
|
|
|
|
content.append(&theme_label);
|
|
|
|
|
let theme = ComboBoxText::new();
|
|
|
|
|
theme.append(Some("system"), "System");
|
|
|
|
|
theme.append(Some("light"), "Light");
|
|
|
|
|
theme.append(Some("dark"), "Dark");
|
|
|
|
|
theme.set_active_id(Some(match ¤t_config.theme {
|
|
|
|
|
Theme::System => "system",
|
|
|
|
|
Theme::Light => "light",
|
|
|
|
|
Theme::Dark => "dark",
|
|
|
|
|
}));
|
|
|
|
|
theme.set_tooltip_text(Some("Choose whether Cliphoard follows the system theme"));
|
|
|
|
|
content.append(&theme);
|
|
|
|
|
let explanation = Label::new(Some(
|
|
|
|
|
"When disabled, Cliphoard starts in the tray after you enter the passphrase. You can still open the window with the global shortcut. Shortcut, autostart, and history-limit changes apply after restart.",
|
|
|
|
|
));
|
|
|
|
|
@@ -1215,18 +1421,39 @@ fn show_settings(
|
|
|
|
|
ignored_patterns.set_text(¤t_config.ignored_patterns.join(", "));
|
|
|
|
|
ignored_patterns.set_tooltip_text(Some("For example: password, secret-token"));
|
|
|
|
|
content.append(&ignored_patterns);
|
|
|
|
|
let change_passphrase_button = Button::with_label("Change passphrase");
|
|
|
|
|
change_passphrase_button.set_icon_name("dialog-password-symbolic");
|
|
|
|
|
change_passphrase_button.set_tooltip_text(Some("Change the database passphrase"));
|
|
|
|
|
content.append(&change_passphrase_button);
|
|
|
|
|
let window_for_passphrase = window.clone();
|
|
|
|
|
let state_for_passphrase = Rc::clone(&state);
|
|
|
|
|
let status_for_passphrase = status.clone();
|
|
|
|
|
change_passphrase_button.connect_clicked(move |_| {
|
|
|
|
|
change_passphrase(
|
|
|
|
|
&window_for_passphrase,
|
|
|
|
|
Rc::clone(&state_for_passphrase),
|
|
|
|
|
&status_for_passphrase,
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
dialog.content_area().append(&content);
|
|
|
|
|
dialog.add_button("Cancel", ResponseType::Cancel);
|
|
|
|
|
dialog.add_button("Save", ResponseType::Accept);
|
|
|
|
|
let config_for_response = Rc::clone(&config);
|
|
|
|
|
let status_for_response = status.clone();
|
|
|
|
|
let window_for_response = window.clone();
|
|
|
|
|
let root_for_response = root.clone();
|
|
|
|
|
dialog.connect_response(move |dialog, response| {
|
|
|
|
|
if response == ResponseType::Accept {
|
|
|
|
|
let mut updated_config = config_for_response.borrow().clone();
|
|
|
|
|
updated_config.show_window_after_unlock = show_window.is_active();
|
|
|
|
|
updated_config.always_on_top = keep_on_top.is_active();
|
|
|
|
|
updated_config.clear_search_on_reopen = clear_search.is_active();
|
|
|
|
|
updated_config.show_timestamps = timestamps.is_active();
|
|
|
|
|
updated_config.theme = match theme.active_id().as_deref() {
|
|
|
|
|
Some("light") => Theme::Light,
|
|
|
|
|
Some("dark") => Theme::Dark,
|
|
|
|
|
_ => Theme::System,
|
|
|
|
|
};
|
|
|
|
|
updated_config.inactive_opacity = opacity.value() / 100.0;
|
|
|
|
|
updated_config.global_shortcut = shortcut.text().to_string();
|
|
|
|
|
updated_config.autostart = autostart.is_active();
|
|
|
|
|
@@ -1253,6 +1480,8 @@ fn show_settings(
|
|
|
|
|
inactive_opacity.set(updated_config.inactive_opacity);
|
|
|
|
|
always_on_top.set(updated_config.always_on_top);
|
|
|
|
|
clear_search_on_reopen.set(updated_config.clear_search_on_reopen);
|
|
|
|
|
show_timestamps.set(updated_config.show_timestamps);
|
|
|
|
|
apply_theme(&root_for_response, &updated_config.theme);
|
|
|
|
|
crate::platform::linux::x11_window::set_active_opacity(
|
|
|
|
|
&window_for_response,
|
|
|
|
|
updated_config.inactive_opacity,
|
|
|
|
|
@@ -1369,6 +1598,49 @@ removal commands. The tray menu includes Quit Cliphoard.\n",
|
|
|
|
|
show_text_dialog(window, "Cliphoard help", &help);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn confirm_clear_history(
|
|
|
|
|
window: &ApplicationWindow,
|
|
|
|
|
state: Rc<RefCell<UiState>>,
|
|
|
|
|
list: ListBox,
|
|
|
|
|
status: Label,
|
|
|
|
|
actions: RowActions,
|
|
|
|
|
show_timestamps: bool,
|
|
|
|
|
) {
|
|
|
|
|
let dialog = gtk4::Dialog::builder()
|
|
|
|
|
.transient_for(window)
|
|
|
|
|
.modal(true)
|
|
|
|
|
.title("Clear clipboard history?")
|
|
|
|
|
.build();
|
|
|
|
|
let message = Label::new(Some(
|
|
|
|
|
"This permanently removes all unpinned clipboard entries. Pinned entries will be kept.",
|
|
|
|
|
));
|
|
|
|
|
message.set_wrap(true);
|
|
|
|
|
dialog.content_area().append(&message);
|
|
|
|
|
dialog.add_button("Cancel", ResponseType::Cancel);
|
|
|
|
|
let clear = dialog.add_button("Clear History", ResponseType::Accept);
|
|
|
|
|
clear.add_css_class("destructive-action");
|
|
|
|
|
dialog.connect_response(move |dialog, response| {
|
|
|
|
|
if response == ResponseType::Accept {
|
|
|
|
|
let mut state = state.borrow_mut();
|
|
|
|
|
match state.database.clear_history() {
|
|
|
|
|
Ok(()) => {
|
|
|
|
|
state.entries.retain(|entry| entry.pinned);
|
|
|
|
|
let entries = state.entries.clone();
|
|
|
|
|
let query = state.search_query.clone();
|
|
|
|
|
refresh_list(&list, &entries, &query, show_timestamps, Some(&actions));
|
|
|
|
|
set_status(&status, "Cleared unpinned clipboard history");
|
|
|
|
|
}
|
|
|
|
|
Err(error) => {
|
|
|
|
|
tracing::error!(%error, "failed to clear unpinned clipboard history");
|
|
|
|
|
set_status(&status, "Could not clear clipboard history");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
dialog.close();
|
|
|
|
|
});
|
|
|
|
|
dialog.present();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn confirm_delete(
|
|
|
|
|
window: &ApplicationWindow,
|
|
|
|
|
id: i64,
|
|
|
|
|
@@ -1376,6 +1648,7 @@ fn confirm_delete(
|
|
|
|
|
list: ListBox,
|
|
|
|
|
status: Label,
|
|
|
|
|
actions: RowActions,
|
|
|
|
|
show_timestamps: bool,
|
|
|
|
|
) {
|
|
|
|
|
let dialog = gtk4::Dialog::builder()
|
|
|
|
|
.transient_for(window)
|
|
|
|
|
@@ -1395,7 +1668,7 @@ fn confirm_delete(
|
|
|
|
|
state.entries.retain(|entry| entry.id != id);
|
|
|
|
|
let entries = state.entries.clone();
|
|
|
|
|
let query = state.search_query.clone();
|
|
|
|
|
refresh_list(&list, &entries, &query, Some(&actions));
|
|
|
|
|
refresh_list(&list, &entries, &query, show_timestamps, Some(&actions));
|
|
|
|
|
set_status(&status, "Deleted clipboard entry");
|
|
|
|
|
}
|
|
|
|
|
Err(error) => {
|
|
|
|
|
@@ -1417,7 +1690,11 @@ fn now() -> i64 {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn now_local_human() -> String {
|
|
|
|
|
let seconds = now() as libc::time_t;
|
|
|
|
|
local_human(now())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn local_human(timestamp: i64) -> String {
|
|
|
|
|
let seconds = timestamp as libc::time_t;
|
|
|
|
|
let mut local = std::mem::MaybeUninit::<libc::tm>::uninit();
|
|
|
|
|
if unsafe { libc::localtime_r(&seconds, local.as_mut_ptr()) }.is_null() {
|
|
|
|
|
return seconds.to_string();
|
|
|
|
|
|