feat: use libcosmic's context_menu widget for the terminal context menu
This commit is contained in:
parent
4cd8f8d605
commit
120b4fdb12
3 changed files with 95 additions and 316 deletions
|
|
@ -112,7 +112,7 @@ pub struct TerminalBox<'a, Message> {
|
|||
show_headerbar: bool,
|
||||
pane_border_radius: Option<Radius>,
|
||||
click_timing: Duration,
|
||||
context_menu: Option<Point>,
|
||||
context_menu_open: bool,
|
||||
on_context_menu: Option<Box<dyn Fn(Option<MenuState>) -> Message + 'a>>,
|
||||
on_mouse_enter: Option<Box<dyn Fn() -> Message + 'a>>,
|
||||
opacity: Option<f32>,
|
||||
|
|
@ -139,7 +139,7 @@ where
|
|||
show_headerbar: true,
|
||||
pane_border_radius: None,
|
||||
click_timing: Duration::from_millis(500),
|
||||
context_menu: None,
|
||||
context_menu_open: false,
|
||||
on_context_menu: None,
|
||||
on_mouse_enter: None,
|
||||
opacity: None,
|
||||
|
|
@ -184,8 +184,8 @@ where
|
|||
self
|
||||
}
|
||||
|
||||
pub fn context_menu(mut self, position: Point) -> Self {
|
||||
self.context_menu = Some(position);
|
||||
pub fn context_menu_open(mut self, open: bool) -> Self {
|
||||
self.context_menu_open = open;
|
||||
self
|
||||
}
|
||||
|
||||
|
|
@ -249,7 +249,7 @@ where
|
|||
if !state.is_focused {
|
||||
return InputMethod::Disabled;
|
||||
}
|
||||
if self.context_menu.is_some() {
|
||||
if self.context_menu_open {
|
||||
return InputMethod::Disabled;
|
||||
}
|
||||
|
||||
|
|
@ -1353,11 +1353,11 @@ where
|
|||
}
|
||||
// Update context menu state
|
||||
if let Some(on_context_menu) = &self.on_context_menu {
|
||||
match self.context_menu {
|
||||
Some(_) => {
|
||||
match self.context_menu_open {
|
||||
true => {
|
||||
shell.publish(on_context_menu(None));
|
||||
}
|
||||
None => {
|
||||
false => {
|
||||
if *button == Button::Right {
|
||||
let x = p.x - self.padding.left;
|
||||
let y = p.y - self.padding.top;
|
||||
|
|
@ -1375,15 +1375,7 @@ where
|
|||
None,
|
||||
);
|
||||
let link = get_hyperlink(&terminal, location);
|
||||
let abs = cosmic::iced::Point::new(
|
||||
layout.bounds().x + p.x,
|
||||
layout.bounds().y + p.y,
|
||||
);
|
||||
shell.publish(on_context_menu(Some(MenuState {
|
||||
position: Some(abs),
|
||||
local_position: Some(p),
|
||||
link,
|
||||
})));
|
||||
shell.publish(on_context_menu(Some(MenuState { link })));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue