Skip to content
Closed
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
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,17 @@ primary-highlighter = "block"
# Disable notifications
disable-notifications = false
# Actions to trigger on right click (order is important)
# [possible values: save-to-clipboard, save-to-file, save-to-file-as, copy-filepath-to-clipboard, exit]
# [possible values: save-to-clipboard, save-to-file, save-to-file-as, copy-filepath-to-clipboard, exit, undo, undo-or-exit]
actions-on-right-click = []
# Actions to trigger on Enter key (order is important)
# [possible values: save-to-clipboard, save-to-file, save-to-file-as, copy-filepath-to-clipboard, exit]
# [possible values: save-to-clipboard, save-to-file, save-to-file-as, copy-filepath-to-clipboard, exit, undo, undo-or-exit]
actions-on-enter = ["save-to-clipboard"]
# Actions to trigger on Escape key (order is important)
# [possible values: save-to-clipboard, save-to-file, save-to-file-as, copy-filepath-to-clipboard, exit]
# [possible values: save-to-clipboard, save-to-file, save-to-file-as, copy-filepath-to-clipboard, exit, undo, undo-or-exit]
actions-on-escape = ["exit"]
# experimental: Actions to trigger on double-click (order is important)
# [possible values: save-to-clipboard, save-to-file, save-to-file-as, copy-filepath-to-clipboard, exit, undo, undo-or-exit]
actions-on-double-click = []
# Action to perform when the Enter key is pressed [possible values: save-to-clipboard, save-to-file]
# Deprecated: use actions-on-enter instead
action-on-enter = "save-to-clipboard"
Expand Down Expand Up @@ -276,11 +279,13 @@ Options:
--auto-copy
Automatically copy to clipboard after every annotation change (NEXTRELEASE)
--actions-on-enter <ACTIONS_ON_ENTER>
Actions to perform when pressing Enter [possible values: save-to-clipboard, save-to-file, save-to-file-as, copy-filepath-to-clipboard, exit]
Actions to perform when pressing Enter [possible values: save-to-clipboard, save-to-file, save-to-file-as, copy-filepath-to-clipboard, exit, undo, undo-or-exit]
--actions-on-escape <ACTIONS_ON_ESCAPE>
Actions to perform when pressing Escape [possible values: save-to-clipboard, save-to-file, save-to-file-as, copy-filepath-to-clipboard, exit]
Actions to perform when pressing Escape [possible values: save-to-clipboard, save-to-file, save-to-file-as, copy-filepath-to-clipboard, exit, undo, undo-or-exit]
--actions-on-right-click <ACTIONS_ON_RIGHT_CLICK>
Actions to perform when hitting the copy Button [possible values: save-to-clipboard, save-to-file, save-to-file-as, copy-filepath-to-clipboard, exit]
Actions to perform when hitting the copy Button [possible values: save-to-clipboard, save-to-file, save-to-file-as, copy-filepath-to-clipboard, exit, undo, undo-or-exit]
--actions-on-double-click <ACTIONS_ON_DOUBLE_CLICK>
Experimental (NEXTRELEASE): Actions to perform on double-click [possible values: save-to-clipboard, save-to-file, save-to-file-as, copy-filepath-to-clipboard, exit, undo, undo-or-exit]
-d, --default-hide-toolbars
Hide toolbars by default
--focus-toggles-toolbars
Expand Down Expand Up @@ -316,7 +321,7 @@ Options:
--right-click-copy
Right click to copy. Preferably use the `action_on_right_click` option instead
--action-on-enter <ACTION_ON_ENTER>
Action to perform when pressing Enter. Preferably use the `actions_on_enter` option instead [possible values: save-to-clipboard, save-to-file, save-to-file-as, copy-filepath-to-clipboard, exit]
Action to perform when pressing Enter. Preferably use the `actions_on_enter` option instead [possible values: save-to-clipboard, save-to-file, save-to-file-as, copy-filepath-to-clipboard, exit, undo, undo-or-exit]
-h, --help
Print help
-V, --version
Expand Down
6 changes: 6 additions & 0 deletions cli/src/command_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ pub struct CommandLine {
#[arg(long, value_delimiter = ',')]
pub actions_on_right_click: Option<Vec<Action>>,

/// Experimental (NEXTRELEASE): Actions to perform on double-click
#[arg(long, value_delimiter = ',')]
pub actions_on_double_click: Option<Vec<Action>>,

/// Hide toolbars by default
#[arg(short, long)]
pub default_hide_toolbars: bool,
Expand Down Expand Up @@ -232,6 +236,8 @@ pub enum Action {
SaveToFileAs,
CopyFilepathToClipboard,
Exit,
Undo,
UndoOrExit,
}

#[derive(Debug, Clone, Copy, Default, ValueEnum)]
Expand Down
9 changes: 6 additions & 3 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@ primary-highlighter = "block"
# Disable notifications
disable-notifications = false
# Actions to trigger on right click (order is important)
# [possible values: save-to-clipboard, save-to-file, exit]
# [possible values: save-to-clipboard, save-to-file, save-to-file-as, copy-filepath-to-clipboard, exit, undo, undo-or-exit]
actions-on-right-click = []
# Actions to trigger on Enter key (order is important)
# [possible values: save-to-clipboard, save-to-file, exit]
# [possible values: save-to-clipboard, save-to-file, save-to-file-as, copy-filepath-to-clipboard, exit, undo, undo-or-exit]
actions-on-enter = ["save-to-clipboard"]
# Actions to trigger on Escape key (order is important)
# [possible values: save-to-clipboard, save-to-file, exit]
# [possible values: save-to-clipboard, save-to-file, save-to-file-as, copy-filepath-to-clipboard, exit, undo, undo-or-exit]
actions-on-escape = ["exit"]
# experimental: Actions to trigger on double-click (order is important)
# [possible values: save-to-clipboard, save-to-file, save-to-file-as, copy-filepath-to-clipboard, exit, undo, undo-or-exit]
actions-on-double-click = []
# Action to perform when the Enter key is pressed [possible values: save-to-clipboard, save-to-file]
# Deprecated: use actions-on-enter instead
action-on-enter = "save-to-clipboard"
Expand Down
17 changes: 17 additions & 0 deletions src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub struct Configuration {
actions_on_enter: Vec<Action>,
actions_on_escape: Vec<Action>,
actions_on_right_click: Vec<Action>,
actions_on_double_click: Vec<Action>,
color_palette: ColorPalette,
default_hide_toolbars: bool,
focus_toggles_toolbars: bool,
Expand Down Expand Up @@ -232,6 +233,8 @@ pub enum Action {
SaveToFileAs,
CopyFilepathToClipboard,
Exit,
Undo,
UndoOrExit,
}

impl From<CommandLineAction> for Action {
Expand All @@ -242,6 +245,8 @@ impl From<CommandLineAction> for Action {
CommandLineAction::SaveToFileAs => Self::SaveToFileAs,
CommandLineAction::CopyFilepathToClipboard => Self::CopyFilepathToClipboard,
CommandLineAction::Exit => Self::Exit,
CommandLineAction::Undo => Self::Undo,
CommandLineAction::UndoOrExit => Self::UndoOrExit,
}
}
}
Expand Down Expand Up @@ -321,6 +326,9 @@ impl Configuration {
if let Some(v) = general.actions_on_right_click {
self.actions_on_right_click = v;
}
if let Some(v) = general.actions_on_double_click {
self.actions_on_double_click = v;
}
if let Some(v) = general.default_hide_toolbars {
self.default_hide_toolbars = v;
}
Expand Down Expand Up @@ -457,6 +465,9 @@ impl Configuration {
if let Some(v) = command_line.actions_on_right_click {
self.actions_on_right_click = v.iter().cloned().map(Into::into).collect();
}
if let Some(v) = command_line.actions_on_double_click {
self.actions_on_double_click = v.iter().cloned().map(Into::into).collect();
}
if let Some(v) = command_line.font_family {
self.font.family = Some(v);
}
Expand Down Expand Up @@ -587,6 +598,10 @@ impl Configuration {
self.actions_on_right_click.clone()
}

pub fn actions_on_double_click(&self) -> Vec<Action> {
self.actions_on_double_click.clone()
}

pub fn color_palette(&self) -> &ColorPalette {
&self.color_palette
}
Expand Down Expand Up @@ -677,6 +692,7 @@ impl Default for Configuration {
actions_on_enter: vec![],
actions_on_escape: vec![Action::Exit],
actions_on_right_click: vec![],
actions_on_double_click: vec![],
color_palette: ColorPalette::default(),
default_hide_toolbars: false,
focus_toggles_toolbars: false,
Expand Down Expand Up @@ -765,6 +781,7 @@ struct ConfigurationFileGeneral {
actions_on_enter: Option<Vec<Action>>,
actions_on_escape: Option<Vec<Action>>,
actions_on_right_click: Option<Vec<Action>>,
actions_on_double_click: Option<Vec<Action>>,
default_hide_toolbars: Option<bool>,
focus_toggles_toolbars: Option<bool>,
default_fill_shapes: Option<bool>,
Expand Down
66 changes: 56 additions & 10 deletions src/sketch_board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,9 @@ impl InputEvent {
if let InputEvent::Mouse(me) = self {
match me.type_ {
MouseEventType::Click => {
if me.button == MouseButton::Secondary {
renderer.request_render(&APP_CONFIG.read().actions_on_right_click());
None
} else {
None
}
// Right-click is handled in update() where
// we have access to handle_undo() and full SketchBoard state.
None
}
MouseEventType::EndDrag | MouseEventType::UpdateDrag => {
if me.button == MouseButton::Middle {
Expand Down Expand Up @@ -285,6 +282,32 @@ impl SketchBoard {
rv
}

fn process_actions(&mut self, actions: &[Action]) -> ToolUpdateResult {
let mut render_actions = Vec::new();
let mut result = ToolUpdateResult::Unmodified;
for action in actions {
match action {
Action::Undo => {
if !matches!(self.handle_undo(), ToolUpdateResult::Unmodified) {
result = ToolUpdateResult::Redraw;
}
}
Action::UndoOrExit => {
if matches!(self.handle_undo(), ToolUpdateResult::Unmodified) {
self.handle_exit();
return result;
}
result = ToolUpdateResult::Redraw;
}
other => render_actions.push(*other),
}
}
if !render_actions.is_empty() {
self.renderer.request_render(&render_actions);
}
result
}

fn handle_render_result_with_pixbuf(
&self,
pix_buf: Option<Pixbuf>,
Expand Down Expand Up @@ -1079,9 +1102,10 @@ impl Component for SketchBoard {
} else {
APP_CONFIG.read().actions_on_enter()
};
self.renderer.request_render(&actions);
};
active_tool_result
self.process_actions(&actions)
} else {
active_tool_result
}
} else {
active_tool_result
}
Expand All @@ -1100,7 +1124,29 @@ impl Component for SketchBoard {
ToolUpdateResult::StopPropagation
| ToolUpdateResult::RedrawAndStopPropagation => active_tool_result,
_ => {
if let Some(result) = ie.handle_mouse_event(&self.renderer) {
if let InputEvent::Mouse(ref me) = ie {
if me.type_ == MouseEventType::Click
&& me.button == MouseButton::Secondary
{
self.process_actions(
&APP_CONFIG.read().actions_on_right_click(),
)
} else if me.type_ == MouseEventType::Click
&& me.button == MouseButton::Primary
&& me.n_pressed >= 2
{
let actions = APP_CONFIG.read().actions_on_double_click();
if !actions.is_empty() {
self.process_actions(&actions)
} else {
active_tool_result
}
} else if let Some(result) = ie.handle_mouse_event(&self.renderer) {
result
} else {
active_tool_result
}
} else if let Some(result) = ie.handle_mouse_event(&self.renderer) {
result
} else {
active_tool_result
Expand Down
Loading