-
-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: context menu for basic actions (#861)
* Recognize longpress and rightclick * Move gesture recognition to canvas wrapper * Create contextmenu and remove right-click gesture * Move properties to .ui * Apply formatting * Store last context menu position * Correctly position clipboard content * Qualify gdk::Rectangle * Add comment to top of imports * Extract paste functionality into it's own function and create separate actions for the context menu paste * fix: add new files to meson.build * fix: change size of rectangle to (4, 4) * refactor: replace glib::MainContext::default().spawn_local with glib::spawn_future_local
- Loading branch information
Showing
11 changed files
with
350 additions
and
174 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -195,4 +195,4 @@ | |
</child> | ||
</object> | ||
</template> | ||
</interface> | ||
</interface> |
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,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<interface> | ||
<template class="RnContextMenu" parent="GtkWidget"> | ||
<child> | ||
<object class="GtkPopoverMenu" id="popover"> | ||
<property name="menu-model">menu_model</property> | ||
<property name="has-arrow">false</property> | ||
<menu id="menu_model"> | ||
<item> | ||
<attribute name="label" translatable="yes">_Copy</attribute> | ||
<attribute name="action">win.clipboard-copy</attribute> | ||
</item> | ||
<item> | ||
<attribute name="label" translatable="yes">C_ut</attribute> | ||
<attribute name="action">win.clipboard-cut</attribute> | ||
</item> | ||
<item> | ||
<attribute name="label" translatable="yes">_Paste</attribute> | ||
<attribute name="action">win.clipboard-paste-contextmenu</attribute> | ||
</item> | ||
</menu> | ||
</object> | ||
</child> | ||
</template> | ||
</interface> |
Large diffs are not rendered by default.
Oops, something went wrong.
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,69 @@ | ||
// Imports | ||
use gtk4::{glib, prelude::*, subclass::prelude::*, CompositeTemplate, PopoverMenu, Widget}; | ||
|
||
mod imp { | ||
use super::*; | ||
|
||
#[derive(Default, Debug, CompositeTemplate)] | ||
#[template(resource = "/com/github/flxzt/rnote/ui/contextmenu.ui")] | ||
pub(crate) struct RnContextMenu { | ||
#[template_child] | ||
pub(crate) popover: TemplateChild<PopoverMenu>, | ||
} | ||
|
||
#[glib::object_subclass] | ||
impl ObjectSubclass for RnContextMenu { | ||
const NAME: &'static str = "RnContextMenu"; | ||
type Type = super::RnContextMenu; | ||
type ParentType = gtk4::Widget; | ||
|
||
fn class_init(klass: &mut Self::Class) { | ||
Self::bind_template(klass); | ||
} | ||
|
||
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) { | ||
obj.init_template(); | ||
} | ||
} | ||
|
||
impl ObjectImpl for RnContextMenu { | ||
fn constructed(&self) { | ||
self.parent_constructed(); | ||
} | ||
|
||
fn dispose(&self) { | ||
self.dispose_template(); | ||
while let Some(child) = self.obj().first_child() { | ||
child.unparent(); | ||
} | ||
} | ||
} | ||
|
||
impl WidgetImpl for RnContextMenu { | ||
fn size_allocate(&self, width: i32, height: i32, baseline: i32) { | ||
self.parent_size_allocate(width, height, baseline); | ||
self.popover.get().present(); | ||
} | ||
} | ||
} | ||
|
||
glib::wrapper! { | ||
pub(crate) struct RnContextMenu(ObjectSubclass<imp::RnContextMenu>) | ||
@extends Widget; | ||
} | ||
|
||
impl Default for RnContextMenu { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
impl RnContextMenu { | ||
pub(crate) fn new() -> Self { | ||
glib::Object::new() | ||
} | ||
|
||
pub(crate) fn popover(&self) -> PopoverMenu { | ||
self.imp().popover.get() | ||
} | ||
} |
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