Add git: open modified files
action (#32347)
Ported over a vscode/cursor command that I like using : ) Release Notes: - Added "open modified files" command
This commit is contained in:
parent
0ee6a90912
commit
c13be165cd
4 changed files with 35 additions and 1 deletions
|
@ -10,7 +10,7 @@ use git::{
|
|||
status::{FileStatus, StatusCode, UnmergedStatus, UnmergedStatusCode},
|
||||
};
|
||||
use git_panel_settings::GitPanelSettings;
|
||||
use gpui::{Action, App, FocusHandle, actions};
|
||||
use gpui::{Action, App, Context, FocusHandle, Window, actions};
|
||||
use onboarding::GitOnboardingModal;
|
||||
use project_diff::ProjectDiff;
|
||||
use ui::prelude::*;
|
||||
|
@ -142,10 +142,41 @@ pub fn init(cx: &mut App) {
|
|||
panel.git_init(window, cx);
|
||||
});
|
||||
});
|
||||
workspace.register_action(|workspace, _: &git::OpenModifiedFiles, window, cx| {
|
||||
open_modified_files(workspace, window, cx);
|
||||
});
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
|
||||
fn open_modified_files(
|
||||
workspace: &mut Workspace,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Workspace>,
|
||||
) {
|
||||
let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
|
||||
return;
|
||||
};
|
||||
let modified_paths: Vec<_> = panel.update(cx, |panel, cx| {
|
||||
let Some(repo) = panel.active_repository.as_ref() else {
|
||||
return Vec::new();
|
||||
};
|
||||
let repo = repo.read(cx);
|
||||
repo.cached_status()
|
||||
.filter_map(|entry| {
|
||||
if entry.status.is_modified() {
|
||||
repo.repo_path_to_project_path(&entry.repo_path, cx)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
});
|
||||
for path in modified_paths {
|
||||
workspace.open_path(path, None, true, window, cx).detach();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn git_status_icon(status: FileStatus) -> impl IntoElement {
|
||||
GitStatusIcon::new(status)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue