Skip to content
Merged
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
6 changes: 5 additions & 1 deletion docs/modules/Clipboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Supports plain text and images.
| `truncate.mode` | `'start'` or `'middle'` or `'end'` or `off` | `off` | The location of the ellipses and where to truncate text from. Leave null to avoid truncating. |
| `truncate.length` | `integer` | `null` | The fixed width (in chars) of the widget. Leave blank to let GTK automatically handle. |
| `truncate.max_length` | `integer` | `null` | The maximum number of characters before truncating. Leave blank to let GTK automatically handle. |
| `show_clear_button` | `bool` | `true` | Enable "Clear All" button within the clipboard popup. |
| `clear_button_icon` | `string` or [image](images) | `🗑` | Icon to show on the clear button. |
| `clear_button_icon_size` | `integer` | `32` | Size to render icon at (image icons only). |

<details>
<summary>JSON</summary>
Expand Down Expand Up @@ -93,10 +96,11 @@ end:
| `.clipboard .btn .text-icon` | Clipboard widget button icon (textual only). |
| `.clipboard .btn .image` | Clipboard widget button icon (image only). |
| `.popup-clipboard` | Clipboard popup box. |
| `.popup-clipboard .btn-clear` | Clipboard "Clear All" button. |
| `.popup-clipboard .item` | Clipboard row item inside the popup. |
| `.popup-clipboard .item .btn` | Clipboard row item radio button. |
| `.popup-clipboard .item .btn.text` | Clipboard row item radio button (text values only). |
| `.popup-clipboard .item .btn.image` | Clipboard row item radio button (image values only). |
| `.popup-clipboard .item .btn-remove` | Clipboard row item remove button. |

For more information on styling, please see the [styling guide](styling-guide).
For more information on styling, please see the [styling guide](styling-guide).
55 changes: 55 additions & 0 deletions src/modules/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ pub struct ClipboardModule {
/// See [common options](module-level-options#common-options).
#[serde(flatten)]
pub common: Option<CommonConfig>,

/// Whether to show a clear button for the clipboard history.
show_clear_button: bool,

/// The icon to show on the clipboard clear button.
/// Supports [image](images) icons.
///
/// **Default**: `🗑`
clear_button_icon: String,

/// The size to render the icon at.
/// Note this only applies to image-type icons.
///
/// **Default**: `32`
clear_button_icon_size: i32,
}

impl Default for ClipboardModule {
Expand All @@ -76,6 +91,9 @@ impl Default for ClipboardModule {
truncate: None,
layout: LayoutConfig::default(),
common: Some(CommonConfig::default()),
show_clear_button: true,
clear_button_icon: "🗑".to_string(),
clear_button_icon_size: 32,
}
}
}
Expand All @@ -86,6 +104,7 @@ pub enum ControllerEvent {
Remove(usize),
Activate(usize),
Deactivate,
Clear,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -187,6 +206,26 @@ impl Module<Button> for ClipboardModule {
{
let container = gtk::Box::new(Orientation::Vertical, 10);

let clear_button = IconButton::new(
&self.clear_button_icon,
self.clear_button_icon_size,
&context.ironbar.image_provider(),
);
clear_button.add_css_class("btn-clear");
clear_button.set_tooltip_text(Some("Clear clipboard history."));
clear_button.set_visible(self.show_clear_button);

{
let tx = context.tx.clone();
clear_button.connect_clicked(move |_| {
debug!("Clearing clipboard history");
tx.send_update_spawn(ControllerEvent::Clear);
});
}

container.prepend(clear_button.deref());
let clear_button_ui = clear_button.clone();

let entries = gtk::Box::new(Orientation::Vertical, 5);
container.append(&entries);

Expand Down Expand Up @@ -294,6 +333,10 @@ impl Module<Button> for ClipboardModule {
entries.prepend(&row);

items.insert(id, (row, button));

if self.show_clear_button {
clear_button_ui.set_visible(true);
}
}
ControllerEvent::Remove(id) => {
debug!("Removing option with ID {id}");
Expand All @@ -305,6 +348,9 @@ impl Module<Button> for ClipboardModule {

entries.remove(&row);
}
if self.show_clear_button {
clear_button_ui.set_visible(!items.is_empty());
}
}
ControllerEvent::Activate(id) => {
debug!("Activating option with ID {id}");
Expand All @@ -319,6 +365,15 @@ impl Module<Button> for ClipboardModule {
debug!("Deactivating current option");
hidden_option.set_active(true);
}
ControllerEvent::Clear => {
for (id, (row, _button)) in items.drain() {
context.controller_tx.send_spawn(UIEvent::Remove(id));
entries.remove(&row);
}

hidden_option.set_active(true);
clear_button_ui.set_visible(false);
}
}
});

Expand Down
Loading