Skip to content

Commit

Permalink
Restore git panel header (#26354)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mikayla-maki authored Mar 10, 2025
1 parent d732b8b commit 230e2e4
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
47 changes: 45 additions & 2 deletions crates/git_ui/src/git_panel.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::askpass_modal::AskPassModal;
use crate::commit_modal::CommitModal;
use crate::git_panel_settings::StatusStyle;
use crate::project_diff::Diff;
use crate::remote_output_toast::{RemoteAction, RemoteOutputToast};
use crate::repository_selector::filtered_repository_entries;
use crate::{branch_picker, render_remote_button};
Expand Down Expand Up @@ -231,6 +232,7 @@ pub struct GitPanel {
fs: Arc<dyn Fs>,
hide_scrollbar_task: Option<Task<()>>,
new_count: usize,
entry_count: usize,
new_staged_count: usize,
pending: Vec<PendingOperation>,
pending_commit: Option<Task<()>>,
Expand Down Expand Up @@ -381,6 +383,7 @@ impl GitPanel {
context_menu: None,
workspace,
modal_open: false,
entry_count: 0,
};
git_panel.schedule_update(false, window, cx);
git_panel.show_scrollbar = git_panel.should_show_scrollbar(cx);
Expand Down Expand Up @@ -1078,7 +1081,7 @@ impl GitPanel {
});
}

fn stage_all(&mut self, _: &StageAll, _window: &mut Window, cx: &mut Context<Self>) {
pub fn stage_all(&mut self, _: &StageAll, _window: &mut Window, cx: &mut Context<Self>) {
let entries = self
.entries
.iter()
Expand All @@ -1089,7 +1092,7 @@ impl GitPanel {
self.change_file_stage(true, entries, cx);
}

fn unstage_all(&mut self, _: &UnstageAll, _window: &mut Window, cx: &mut Context<Self>) {
pub fn unstage_all(&mut self, _: &UnstageAll, _window: &mut Window, cx: &mut Context<Self>) {
let entries = self
.entries
.iter()
Expand Down Expand Up @@ -2137,10 +2140,12 @@ impl GitPanel {
self.tracked_count = 0;
self.new_staged_count = 0;
self.tracked_staged_count = 0;
self.entry_count = 0;
for entry in &self.entries {
let Some(status_entry) = entry.status_entry() else {
continue;
};
self.entry_count += 1;
if repo.has_conflict(&status_entry.repo_path) {
self.conflicted_count += 1;
if self.entry_staging(status_entry).has_staged() {
Expand Down Expand Up @@ -2402,6 +2407,43 @@ impl GitPanel {
})
}

fn render_panel_header(&self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let text;
let action;
let tooltip;
if self.total_staged_count() == self.entry_count {
text = "Unstage All";
action = git::UnstageAll.boxed_clone();
tooltip = "git reset";
} else {
text = "Stage All";
action = git::StageAll.boxed_clone();
tooltip = "git add --all ."
}

self.panel_header_container(window, cx)
.child(
Button::new("diff", "Open diff")
.tooltip(Tooltip::for_action_title("Open diff", &Diff))
.on_click(|_, _, cx| {
cx.defer(|cx| {
cx.dispatch_action(&Diff);
})
}),
)
.child(div().flex_grow()) // spacer
.child(
Button::new("stage-unstage-all", text)
.tooltip(Tooltip::for_action_title(tooltip, action.as_ref()))
.on_click(move |_, _, cx| {
let action = action.boxed_clone();
cx.defer(move |cx| {
cx.dispatch_action(action.as_ref());
})
}),
)
}

pub fn render_footer(
&self,
window: &mut Window,
Expand Down Expand Up @@ -3166,6 +3208,7 @@ impl Render for GitPanel {
.child(
v_flex()
.size_full()
.child(self.render_panel_header(window, cx))
.map(|this| {
if has_entries {
this.child(self.render_entries(has_write_access, window, cx))
Expand Down
16 changes: 16 additions & 0 deletions crates/git_ui/src/git_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@ pub fn init(cx: &mut App) {
panel.pull(window, cx);
});
});
workspace.register_action(|workspace, action: &git::StageAll, window, cx| {
let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
return;
};
panel.update(cx, |panel, cx| {
panel.stage_all(action, window, cx);
});
});
workspace.register_action(|workspace, action: &git::UnstageAll, window, cx| {
let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
return;
};
panel.update(cx, |panel, cx| {
panel.unstage_all(action, window, cx);
});
});
})
.detach();
}
Expand Down

0 comments on commit 230e2e4

Please sign in to comment.