Copy file path (#1516)

* copy file path to click board
* update change log
* Add copy path info to command bar
This commit is contained in:
Antonio Yang 2023-02-12 18:06:56 +08:00 committed by GitHub
parent 0fca8befc8
commit aefc18d819
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 0 deletions

View file

@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* add no-verify option on commits to not run hooks [[@dam5h]](https://github.com/dam5h) ([#1374](https://github.com/extrawurst/gitui/issues/1374))
* allow `fetch` on status tab [[@alensiljak]](https://github.com/alensiljak) ([#1471](https://github.com/extrawurst/gitui/issues/1471))
* allow reset (soft,mixed,hard) from commit log ([#1500](https://github.com/extrawurst/gitui/issues/1500))
* allow `copy` file path on revision files and status tree [[@yanganto]](https://github.com/yanganto) ([#1516](https://github.com/extrawurst/gitui/pull/1516))
### Fixes
* commit msg history ordered the wrong way ([#1445](https://github.com/extrawurst/gitui/issues/1445))

0
flake.lock Normal file
View file

View file

@ -7,6 +7,7 @@ use crate::{
keys::{key_match, SharedKeyConfig},
queue::{InternalEvent, Queue, StackablePopupOpen},
strings::{self, order, symbol},
try_or_popup,
ui::{self, common_nav, style::SharedTheme},
AsyncAppNotification, AsyncNotification,
};
@ -447,6 +448,14 @@ impl Component for RevisionFilesComponent {
)
.order(order::RARE_ACTION),
);
out.push(
CommandInfo::new(
strings::commands::copy_path(&self.key_config),
self.tree.selected_file().is_some(),
true,
)
.order(order::RARE_ACTION),
);
tree_nav_cmds(&self.tree, &self.key_config, out);
} else {
self.current_file.commands(out, force_all);
@ -515,6 +524,15 @@ impl Component for RevisionFilesComponent {
);
return Ok(EventState::Consumed);
}
} else if key_match(key, self.key_config.keys.copy) {
if let Some(file) = self.selected_file_path() {
try_or_popup!(
self,
strings::POPUP_FAIL_COPY,
crate::clipboard::copy_string(&file)
);
}
return Ok(EventState::Consumed);
} else if !is_tree_focused {
return self.current_file.event(event);
}

View file

@ -302,6 +302,21 @@ impl StatusTreeComponent {
selection_offset_visible,
)
}
// Copy the real path of selected file to clickboard
fn copy_file_path(&self) {
if let Some(item) = self.selection() {
if crate::clipboard::copy_string(&item.info.full_path)
.is_err()
{
if let Some(queue) = &self.queue {
queue.push(InternalEvent::ShowErrorMsg(
strings::POPUP_FAIL_COPY.to_string(),
));
}
}
}
}
}
/// Used for drawing the `FileTreeComponent`
@ -430,6 +445,15 @@ impl Component for StatusTreeComponent {
.order(order::RARE_ACTION),
);
out.push(
CommandInfo::new(
strings::commands::copy_path(&self.key_config),
self.selection_file().is_some(),
self.focused || force_all,
)
.order(order::RARE_ACTION),
);
CommandBlocking::PassingOn
}
@ -481,6 +505,9 @@ impl Component for StatusTreeComponent {
}
}
Ok(EventState::Consumed)
} else if key_match(e, self.key_config.keys.copy) {
self.copy_file_path();
Ok(EventState::Consumed)
} else if key_match(e, self.key_config.keys.move_down)
{
Ok(self

View file

@ -558,6 +558,16 @@ pub mod commands {
CMD_GROUP_LOG,
)
}
pub fn copy_path(key_config: &SharedKeyConfig) -> CommandText {
CommandText::new(
format!(
"Copy Path [{}]",
key_config.get_hint(key_config.keys.copy),
),
"copy selected file path to clipboard",
CMD_GROUP_LOG,
)
}
pub fn push_tags(key_config: &SharedKeyConfig) -> CommandText {
CommandText::new(
format!(