From c53d8509d17d1eece18bc1ac527c1abe3cb702e5 Mon Sep 17 00:00:00 2001 From: Cameron Date: Sun, 23 Oct 2022 15:41:54 +0100 Subject: [PATCH] Add ability to open file/file diff from source control context menu (#1590) * open file/diff from source control context menu * update changelog * use matches macro --- CHANGELOG.md | 3 ++- lapce-ui/src/source_control.rs | 40 ++++++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ebd931e..499cd362 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,9 @@ ### Features/Changes +- [#1590](https://github.com/lapce/lapce/pull/1590): Added ability to open file and file diff from source control context menu - [#1570](https://github.com/lapce/lapce/pull/1570): Added a basic tab context menu with common close actions -- [#1560](https://github.com/lapce/lapce/pull/1560): Added ability to copy active editor remote file path to clipboard. +- [#1560](https://github.com/lapce/lapce/pull/1560): Added ability to copy active editor remote file path to clipboard - [#1510](https://github.com/lapce/lapce/1510): Added support to discard changes to a file - [#1459](https://github.com/lapce/lapce/pull/1459): Implement icon theme system - **This is a breaking change for colour themes!** diff --git a/lapce-ui/src/source_control.rs b/lapce-ui/src/source_control.rs index 41dda726..8a0511fa 100644 --- a/lapce-ui/src/source_control.rs +++ b/lapce-ui/src/source_control.rs @@ -182,10 +182,46 @@ fn event( let source_control = data.source_control.clone(); let target_file_diff = source_control.file_diffs[target_line].0.clone(); + let target_file_path = target_file_diff.path().clone(); let mut menu = druid::Menu::::new(""); - let item = druid::MenuItem::new("Discard Changes") + let mut item = druid::MenuItem::new("Open Changes").command( + Command::new( + LAPCE_UI_COMMAND, + LapceUICommand::OpenFileDiff( + source_control.file_diffs[target_line] + .0 + .path() + .clone(), + "head".to_string(), + ), + Target::Auto, + ), + ); + menu = menu.entry(item); + + let enable_open_file = + !matches!(target_file_diff, FileDiff::Deleted(_)); + + item = druid::MenuItem::new("Open File") + .enabled(enable_open_file) + .on_activate(move |ctx, _, _| { + ctx.submit_command(Command::new( + LAPCE_UI_COMMAND, + LapceUICommand::OpenFile( + target_file_path.clone(), + true, + ), + Target::Auto, + )); + }); + + menu = menu.entry(item); + + menu = menu.separator(); + + item = druid::MenuItem::new("Discard Changes") .on_activate(move |ctx, _, _| { ctx.submit_command(Command::new( LAPCE_COMMAND, @@ -193,7 +229,7 @@ fn event( kind: CommandKind::Workbench( LapceWorkbenchCommand::SourceControlDiscardTargetFileChanges ), - data: Some(serde_json::json!(target_file_diff)) + data: Some(serde_json::json!(target_file_diff.clone())) }, Target::Auto, ));