Polish clipboard row actions
This commit is contained in:
@@ -61,7 +61,7 @@ Each bounded iteration must:
|
||||
|
||||
- [ ] Make popup close hide the window while the background process continues (code path added; desktop verification pending).
|
||||
- [ ] Center the popup on the configured/active monitor.
|
||||
- [x] Keep the X11 popup above other windows and apply 40% opacity while it is
|
||||
- [x] Keep the X11 popup above other windows and apply 60% opacity while it is
|
||||
inactive, returning to full opacity when focused; request `_NET_WM_STATE_ABOVE`
|
||||
through the EWMH client-message protocol as well as the property, and repeat
|
||||
the request after mapping (27 X11-feature tests and Docker
|
||||
@@ -74,6 +74,7 @@ Each bounded iteration must:
|
||||
tests and Docker GTK/X11/package build, 2026-09-12); live GUI acceptance is
|
||||
still pending.
|
||||
- [ ] Ensure copy, paste, pin, delete, clear, pause, and resume have consistent UI feedback.
|
||||
- [x] Add icon-only copy, paste, and delete controls to every history row, with matching icon prefixes on toolbar actions (27 X11-feature tests, Docker GTK/X11/package build, 2026-09-12); live GUI acceptance remains pending.
|
||||
- [x] Surface actionable status text for keyboard and toolbar action failures, including successful clipboard writes with failed history updates (Docker GTK/X11 build, 2026-09-10).
|
||||
- [x] Replace the conflict-prone `Ctrl+R` pause shortcut with `Ctrl+Alt+R`, and expose the configured global shortcut in the window title/status (Docker GTK/X11 build; live tray/capture verified, 2026-09-10).
|
||||
- [x] Use the Mint-friendly `Ctrl+Alt+V` as the default global popup shortcut;
|
||||
|
||||
148
src/gui.rs
148
src/gui.rs
@@ -51,6 +51,20 @@ struct PendingClipboardAction {
|
||||
paste: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct RowActions {
|
||||
copy: Button,
|
||||
paste: Button,
|
||||
delete: Button,
|
||||
}
|
||||
|
||||
const COPY_ICON: &str = "📋";
|
||||
const PASTE_ICON: &str = "↪";
|
||||
const DELETE_ICON: &str = "🗑";
|
||||
const PIN_ICON: &str = "📌";
|
||||
const CLEAR_ICON: &str = "🧹";
|
||||
const PAUSE_ICON: &str = "⏸";
|
||||
|
||||
pub fn run(
|
||||
config: Config,
|
||||
database: Database,
|
||||
@@ -145,12 +159,17 @@ fn build_window(
|
||||
root.append(&search_box);
|
||||
root.append(&scroll);
|
||||
let actions = GtkBox::new(Orientation::Horizontal, 6);
|
||||
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 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 row_actions = RowActions {
|
||||
copy: copy_button.clone(),
|
||||
paste: paste_button.clone(),
|
||||
delete: delete_button.clone(),
|
||||
};
|
||||
let hotkey_status = if state.borrow().hotkey.is_some() {
|
||||
format!("global shortcut: {}", config.global_shortcut)
|
||||
} else {
|
||||
@@ -199,21 +218,28 @@ fn build_window(
|
||||
glib::Propagation::Stop
|
||||
});
|
||||
window.set_visible(show_on_start);
|
||||
refresh_list(&list, &state.borrow().entries, "");
|
||||
refresh_list(&list, &state.borrow().entries, "", Some(&row_actions));
|
||||
let pinned_limit = config.pinned_limit;
|
||||
let pause_button_for_keys = pause_button.clone();
|
||||
let status_for_keys = status.clone();
|
||||
|
||||
let list_for_search = list.clone();
|
||||
let state_for_search = Rc::clone(&state);
|
||||
let row_actions_for_search = row_actions.clone();
|
||||
search_box.connect_changed(move |entry| {
|
||||
let mut state = state_for_search.borrow_mut();
|
||||
state.search_query = entry.text().to_string();
|
||||
refresh_list(&list_for_search, &state.entries, &state.search_query);
|
||||
refresh_list(
|
||||
&list_for_search,
|
||||
&state.entries,
|
||||
&state.search_query,
|
||||
Some(&row_actions_for_search),
|
||||
);
|
||||
});
|
||||
let state_for_keys = Rc::clone(&state);
|
||||
let list_for_keys = list.clone();
|
||||
let window_for_keys = window.clone();
|
||||
let row_actions_for_keys = row_actions.clone();
|
||||
let keys = gtk4::EventControllerKey::new();
|
||||
keys.set_propagation_phase(gtk4::PropagationPhase::Capture);
|
||||
keys.connect_key_pressed(move |_, key, _, modifiers| {
|
||||
@@ -241,11 +267,12 @@ fn build_window(
|
||||
{
|
||||
let mut state = state_for_keys.borrow_mut();
|
||||
state.recording = !state.recording;
|
||||
pause_button_for_keys.set_label(if state.recording {
|
||||
"Pause Recording"
|
||||
let pause_label = if state.recording {
|
||||
format!("{PAUSE_ICON} Pause Recording")
|
||||
} else {
|
||||
"Resume Recording"
|
||||
});
|
||||
format!("{PAUSE_ICON} Resume Recording")
|
||||
};
|
||||
pause_button_for_keys.set_label(&pause_label);
|
||||
status_for_keys.set_text(if state.recording {
|
||||
"Recording clipboard changes"
|
||||
} else {
|
||||
@@ -264,7 +291,12 @@ fn build_window(
|
||||
match state.database.clear_history() {
|
||||
Ok(()) => {
|
||||
state.entries.retain(|entry| entry.pinned);
|
||||
refresh_list(&list_for_keys, &state.entries, &state.search_query);
|
||||
refresh_list(
|
||||
&list_for_keys,
|
||||
&state.entries,
|
||||
&state.search_query,
|
||||
Some(&row_actions_for_keys),
|
||||
);
|
||||
}
|
||||
Err(error) => {
|
||||
tracing::error!(%error, "failed to clear unpinned clipboard history");
|
||||
@@ -327,7 +359,12 @@ fn build_window(
|
||||
status_for_keys.set_text("Could not update pin state");
|
||||
}
|
||||
}
|
||||
refresh_list(&list_for_keys, &state.entries, &state.search_query);
|
||||
refresh_list(
|
||||
&list_for_keys,
|
||||
&state.entries,
|
||||
&state.search_query,
|
||||
Some(&row_actions_for_keys),
|
||||
);
|
||||
return glib::Propagation::Stop;
|
||||
}
|
||||
if key == gtk4::gdk::Key::Delete {
|
||||
@@ -335,7 +372,12 @@ fn build_window(
|
||||
match state.database.delete(id) {
|
||||
Ok(()) => {
|
||||
state.entries.retain(|entry| entry.id != id);
|
||||
refresh_list(&list_for_keys, &state.entries, &state.search_query);
|
||||
refresh_list(
|
||||
&list_for_keys,
|
||||
&state.entries,
|
||||
&state.search_query,
|
||||
Some(&row_actions_for_keys),
|
||||
);
|
||||
}
|
||||
Err(error) => {
|
||||
tracing::error!(%error, "failed to delete clipboard entry");
|
||||
@@ -411,6 +453,7 @@ fn build_window(
|
||||
let list_for_pin = list.clone();
|
||||
let pinned_list = list.clone();
|
||||
let status_for_pin = status.clone();
|
||||
let row_actions_for_pin = row_actions.clone();
|
||||
pin_button.connect_clicked(move |_| {
|
||||
if let Some(id) = selected_id(&list_for_pin) {
|
||||
let mut state = state_for_pin.borrow_mut();
|
||||
@@ -419,7 +462,12 @@ fn build_window(
|
||||
if let Some(entry) = state.entries.iter_mut().find(|entry| entry.id == id) {
|
||||
entry.pinned = pinned;
|
||||
}
|
||||
refresh_list(&pinned_list, &state.entries, &state.search_query);
|
||||
refresh_list(
|
||||
&pinned_list,
|
||||
&state.entries,
|
||||
&state.search_query,
|
||||
Some(&row_actions_for_pin),
|
||||
);
|
||||
}
|
||||
Err(error) => {
|
||||
tracing::error!(%error, "failed to pin clipboard entry");
|
||||
@@ -433,13 +481,19 @@ fn build_window(
|
||||
let list_for_delete = list.clone();
|
||||
let deleted_list = list.clone();
|
||||
let status_for_delete = status.clone();
|
||||
let row_actions_for_delete = row_actions.clone();
|
||||
delete_button.connect_clicked(move |_| {
|
||||
if let Some(id) = selected_id(&list_for_delete) {
|
||||
let mut state = state_for_delete.borrow_mut();
|
||||
match state.database.delete(id) {
|
||||
Ok(()) => {
|
||||
state.entries.retain(|entry| entry.id != id);
|
||||
refresh_list(&deleted_list, &state.entries, &state.search_query);
|
||||
refresh_list(
|
||||
&deleted_list,
|
||||
&state.entries,
|
||||
&state.search_query,
|
||||
Some(&row_actions_for_delete),
|
||||
);
|
||||
}
|
||||
Err(error) => {
|
||||
tracing::error!(%error, "failed to delete clipboard entry");
|
||||
@@ -452,12 +506,18 @@ fn build_window(
|
||||
let state_for_clear = Rc::clone(&state);
|
||||
let cleared_list = list.clone();
|
||||
let status_for_clear = status.clone();
|
||||
let row_actions_for_clear = row_actions.clone();
|
||||
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);
|
||||
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");
|
||||
@@ -471,11 +531,12 @@ fn build_window(
|
||||
pause_button.connect_clicked(move |button| {
|
||||
let mut state = state_for_pause.borrow_mut();
|
||||
state.recording = !state.recording;
|
||||
button.set_label(if state.recording {
|
||||
"Pause Recording"
|
||||
let pause_label = if state.recording {
|
||||
format!("{PAUSE_ICON} Pause Recording")
|
||||
} else {
|
||||
"Resume Recording"
|
||||
});
|
||||
format!("{PAUSE_ICON} Resume Recording")
|
||||
};
|
||||
button.set_label(&pause_label);
|
||||
status_for_pause.set_text(if state.recording {
|
||||
"Recording clipboard changes"
|
||||
} else {
|
||||
@@ -490,6 +551,7 @@ fn build_window(
|
||||
let state_for_watch = Rc::clone(&state);
|
||||
let list_for_watch = list.clone();
|
||||
let config_for_watch = config.clone();
|
||||
let row_actions_for_watch = row_actions.clone();
|
||||
let window_for_events = window.clone();
|
||||
let search_for_events = search_box.clone();
|
||||
let status_for_events = status.clone();
|
||||
@@ -515,7 +577,13 @@ fn build_window(
|
||||
}
|
||||
if let Some(result) = state.clipboard_reader.try_result() {
|
||||
state.clipboard_read_pending = false;
|
||||
process_clipboard_result(&mut state, result, &list_for_watch, &config_for_watch);
|
||||
process_clipboard_result(
|
||||
&mut state,
|
||||
result,
|
||||
&list_for_watch,
|
||||
&config_for_watch,
|
||||
&row_actions_for_watch,
|
||||
);
|
||||
}
|
||||
if let Some(result) = state.clipboard_worker.try_result() {
|
||||
match result {
|
||||
@@ -565,6 +633,7 @@ fn build_window(
|
||||
&list_for_watch,
|
||||
&state.entries,
|
||||
&state.search_query,
|
||||
Some(&row_actions_for_watch),
|
||||
);
|
||||
}
|
||||
status_for_events.set_text(history_status);
|
||||
@@ -609,6 +678,7 @@ fn process_clipboard_result(
|
||||
result: Result<Option<String>>,
|
||||
list: &ListBox,
|
||||
config: &Config,
|
||||
actions: &RowActions,
|
||||
) {
|
||||
match result {
|
||||
Ok(Some(content))
|
||||
@@ -623,7 +693,7 @@ fn process_clipboard_result(
|
||||
}
|
||||
state.entries.retain(|candidate| candidate.id != entry.id);
|
||||
state.entries.push(entry);
|
||||
refresh_list(list, &state.entries, &state.search_query);
|
||||
refresh_list(list, &state.entries, &state.search_query, Some(actions));
|
||||
}
|
||||
Err(error) => {
|
||||
tracing::error!(%error, "failed to store clipboard entry");
|
||||
@@ -647,7 +717,12 @@ fn request_focus(state: &mut UiState) {
|
||||
}
|
||||
}
|
||||
|
||||
fn refresh_list(list: &ListBox, entries: &[crate::core::Entry], query: &str) {
|
||||
fn refresh_list(
|
||||
list: &ListBox,
|
||||
entries: &[crate::core::Entry],
|
||||
query: &str,
|
||||
actions: Option<&RowActions>,
|
||||
) {
|
||||
let selected = selected_id(list);
|
||||
while let Some(child) = list.first_child() {
|
||||
list.remove(&child);
|
||||
@@ -671,7 +746,28 @@ fn refresh_list(list: &ListBox, entries: &[crate::core::Entry], query: &str) {
|
||||
label.set_margin_start(8);
|
||||
label.set_margin_end(8);
|
||||
let row = ListBoxRow::new();
|
||||
row.set_child(Some(&label));
|
||||
let content = GtkBox::new(Orientation::Horizontal, 4);
|
||||
label.set_hexpand(true);
|
||||
content.append(&label);
|
||||
if let Some(actions) = actions {
|
||||
for (icon, tooltip, action) in [
|
||||
(COPY_ICON, "Copy entry", actions.copy.clone()),
|
||||
(PASTE_ICON, "Paste entry", actions.paste.clone()),
|
||||
(DELETE_ICON, "Delete entry", actions.delete.clone()),
|
||||
] {
|
||||
let button = Button::with_label(icon);
|
||||
button.set_tooltip_text(Some(tooltip));
|
||||
button.set_focus_on_click(false);
|
||||
let row_for_action = row.clone();
|
||||
let list_for_action = list.clone();
|
||||
button.connect_clicked(move |_| {
|
||||
list_for_action.select_row(Some(&row_for_action));
|
||||
action.emit_clicked();
|
||||
});
|
||||
content.append(&button);
|
||||
}
|
||||
}
|
||||
row.set_child(Some(&content));
|
||||
row.set_tooltip_text(Some(&entry.id.to_string()));
|
||||
list.append(&row);
|
||||
if selected == Some(entry.id) {
|
||||
|
||||
@@ -9,7 +9,7 @@ use x11rb::{
|
||||
};
|
||||
|
||||
const ACTIVE_OPACITY: f64 = 1.0;
|
||||
const INACTIVE_OPACITY: f64 = 0.40;
|
||||
const INACTIVE_OPACITY: f64 = 0.60;
|
||||
|
||||
pub fn configure(window: &ApplicationWindow) {
|
||||
set_active_opacity(window);
|
||||
|
||||
Reference in New Issue
Block a user