Skip to content

Copy file path #1516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 12, 2023
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,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))
Expand Down
Empty file added flake.lock
Empty file.
18 changes: 18 additions & 0 deletions src/components/revision_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
27 changes: 27 additions & 0 deletions src/components/status_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down