-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a context menu in the main history view
Currently it allows one to copy the path to the screenshot or the screenshot itself, but it can be expanded. Related: Better history widgets #17
- Loading branch information
Showing
9 changed files
with
152 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mod context_menu; | ||
|
||
pub use context_menu::context_menu; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
using Gtk 4.0; | ||
|
||
menu history_context_menu { | ||
item (_("Copy image"), "ctx_menu.copy_image") | ||
item (_("Copy path"), "ctx_menu.copy_path") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use gtk4::{gdk, gio, prelude::*}; | ||
|
||
use crate::historymodel::RowData; | ||
|
||
/// Creates a context menu with the usual operations you'd expect from a context menu on a history entry | ||
pub fn context_menu(data: RowData, parent: >k4::Widget) -> gtk4::PopoverMenu { | ||
let builder = gtk4::Builder::from_resource("/kc/kcshot/ui/history/context_menu.ui"); | ||
let model = builder | ||
.object::<gio::MenuModel>("history_context_menu") | ||
.unwrap(); | ||
|
||
let menu = gtk4::PopoverMenu::builder() | ||
.menu_model(&model) | ||
.autohide(true) | ||
.has_arrow(false) | ||
.halign(gtk4::Align::Start) | ||
.build(); | ||
menu.set_parent(parent); | ||
|
||
let actions = gio::SimpleActionGroup::new(); | ||
menu.insert_action_group("ctx_menu", Some(&actions)); | ||
|
||
let copy_path = gio::SimpleAction::new("copy_path", None); | ||
let path = data.path(); | ||
copy_path.connect_activate({ | ||
let menu = menu.clone(); | ||
move |_, _| { | ||
menu.popdown(); | ||
if let Some(path) = &path { | ||
clipboard().set_text(path); | ||
} | ||
} | ||
}); | ||
actions.add_action(©_path); | ||
|
||
let copy_image = gio::SimpleAction::new("copy_image", None); | ||
let path = data.path(); | ||
copy_image.connect_activate({ | ||
let menu = menu.clone(); | ||
move |_, _| { | ||
menu.popdown(); | ||
if let Some(path) = &path { | ||
clipboard() | ||
.set_texture(&gdk::Texture::from_file(&gio::File::for_path(path)).unwrap()); | ||
} | ||
} | ||
}); | ||
actions.add_action(©_image); | ||
|
||
menu | ||
} | ||
|
||
#[track_caller] | ||
fn clipboard() -> gdk::Clipboard { | ||
gdk::Display::default().unwrap().clipboard() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters