Skip to content

Commit 230e2e4

Browse files
authored
Restore git panel header (#26354)
Let's play around with it. This should not be added to tomorrow's preview. Release Notes: - Git Beta: Added a panel header with an open diff and stage/unstage all buttons.
1 parent d732b8b commit 230e2e4

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

crates/git_ui/src/git_panel.rs

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::askpass_modal::AskPassModal;
22
use crate::commit_modal::CommitModal;
33
use crate::git_panel_settings::StatusStyle;
4+
use crate::project_diff::Diff;
45
use crate::remote_output_toast::{RemoteAction, RemoteOutputToast};
56
use crate::repository_selector::filtered_repository_entries;
67
use crate::{branch_picker, render_remote_button};
@@ -231,6 +232,7 @@ pub struct GitPanel {
231232
fs: Arc<dyn Fs>,
232233
hide_scrollbar_task: Option<Task<()>>,
233234
new_count: usize,
235+
entry_count: usize,
234236
new_staged_count: usize,
235237
pending: Vec<PendingOperation>,
236238
pending_commit: Option<Task<()>>,
@@ -381,6 +383,7 @@ impl GitPanel {
381383
context_menu: None,
382384
workspace,
383385
modal_open: false,
386+
entry_count: 0,
384387
};
385388
git_panel.schedule_update(false, window, cx);
386389
git_panel.show_scrollbar = git_panel.should_show_scrollbar(cx);
@@ -1078,7 +1081,7 @@ impl GitPanel {
10781081
});
10791082
}
10801083

1081-
fn stage_all(&mut self, _: &StageAll, _window: &mut Window, cx: &mut Context<Self>) {
1084+
pub fn stage_all(&mut self, _: &StageAll, _window: &mut Window, cx: &mut Context<Self>) {
10821085
let entries = self
10831086
.entries
10841087
.iter()
@@ -1089,7 +1092,7 @@ impl GitPanel {
10891092
self.change_file_stage(true, entries, cx);
10901093
}
10911094

1092-
fn unstage_all(&mut self, _: &UnstageAll, _window: &mut Window, cx: &mut Context<Self>) {
1095+
pub fn unstage_all(&mut self, _: &UnstageAll, _window: &mut Window, cx: &mut Context<Self>) {
10931096
let entries = self
10941097
.entries
10951098
.iter()
@@ -2137,10 +2140,12 @@ impl GitPanel {
21372140
self.tracked_count = 0;
21382141
self.new_staged_count = 0;
21392142
self.tracked_staged_count = 0;
2143+
self.entry_count = 0;
21402144
for entry in &self.entries {
21412145
let Some(status_entry) = entry.status_entry() else {
21422146
continue;
21432147
};
2148+
self.entry_count += 1;
21442149
if repo.has_conflict(&status_entry.repo_path) {
21452150
self.conflicted_count += 1;
21462151
if self.entry_staging(status_entry).has_staged() {
@@ -2402,6 +2407,43 @@ impl GitPanel {
24022407
})
24032408
}
24042409

2410+
fn render_panel_header(&self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
2411+
let text;
2412+
let action;
2413+
let tooltip;
2414+
if self.total_staged_count() == self.entry_count {
2415+
text = "Unstage All";
2416+
action = git::UnstageAll.boxed_clone();
2417+
tooltip = "git reset";
2418+
} else {
2419+
text = "Stage All";
2420+
action = git::StageAll.boxed_clone();
2421+
tooltip = "git add --all ."
2422+
}
2423+
2424+
self.panel_header_container(window, cx)
2425+
.child(
2426+
Button::new("diff", "Open diff")
2427+
.tooltip(Tooltip::for_action_title("Open diff", &Diff))
2428+
.on_click(|_, _, cx| {
2429+
cx.defer(|cx| {
2430+
cx.dispatch_action(&Diff);
2431+
})
2432+
}),
2433+
)
2434+
.child(div().flex_grow()) // spacer
2435+
.child(
2436+
Button::new("stage-unstage-all", text)
2437+
.tooltip(Tooltip::for_action_title(tooltip, action.as_ref()))
2438+
.on_click(move |_, _, cx| {
2439+
let action = action.boxed_clone();
2440+
cx.defer(move |cx| {
2441+
cx.dispatch_action(action.as_ref());
2442+
})
2443+
}),
2444+
)
2445+
}
2446+
24052447
pub fn render_footer(
24062448
&self,
24072449
window: &mut Window,
@@ -3166,6 +3208,7 @@ impl Render for GitPanel {
31663208
.child(
31673209
v_flex()
31683210
.size_full()
3211+
.child(self.render_panel_header(window, cx))
31693212
.map(|this| {
31703213
if has_entries {
31713214
this.child(self.render_entries(has_write_access, window, cx))

crates/git_ui/src/git_ui.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,22 @@ pub fn init(cx: &mut App) {
6464
panel.pull(window, cx);
6565
});
6666
});
67+
workspace.register_action(|workspace, action: &git::StageAll, window, cx| {
68+
let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
69+
return;
70+
};
71+
panel.update(cx, |panel, cx| {
72+
panel.stage_all(action, window, cx);
73+
});
74+
});
75+
workspace.register_action(|workspace, action: &git::UnstageAll, window, cx| {
76+
let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
77+
return;
78+
};
79+
panel.update(cx, |panel, cx| {
80+
panel.unstage_all(action, window, cx);
81+
});
82+
});
6783
})
6884
.detach();
6985
}

0 commit comments

Comments
 (0)