Add an informative tooltip to commit button when unable to commit (#25912)

Release Notes:

- N/A
This commit is contained in:
Mikayla Maki 2025-03-03 00:44:46 -08:00 committed by GitHub
parent 0a4ff2f475
commit 508b9d3b5d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1858,6 +1858,32 @@ impl GitPanel {
} }
} }
pub fn configure_commit_button(&self, cx: &Context<Self>) -> (bool, &'static str) {
if self.has_unstaged_conflicts() {
(false, "You must resolve conflicts before committing")
} else if !self.has_staged_changes() && !self.has_tracked_changes() {
(
false,
"You must have either staged changes or tracked files to commit",
)
} else if self.pending_commit.is_some() {
(false, "Commit in progress")
} else if self.commit_editor.read(cx).is_empty(cx) {
(false, "No commit message")
} else if !self.has_write_access(cx) {
(false, "You do not have write access to this project")
} else {
(
true,
if self.has_staged_changes() {
"Commit"
} else {
"Commit Tracked"
},
)
}
}
pub fn render_footer( pub fn render_footer(
&self, &self,
window: &mut Window, window: &mut Window,
@ -1868,19 +1894,10 @@ impl GitPanel {
let panel_editor_style = panel_editor_style(true, window, cx); let panel_editor_style = panel_editor_style(true, window, cx);
if let Some(active_repo) = active_repository { if let Some(active_repo) = active_repository {
let editor = self.commit_editor.clone(); let (can_commit, tooltip) = self.configure_commit_button(cx);
let can_commit = self.can_commit()
&& self.pending_commit.is_none()
&& !editor.read(cx).is_empty(cx)
&& self.has_write_access(cx);
let enable_coauthors = self.render_co_authors(cx); let enable_coauthors = self.render_co_authors(cx);
let tooltip = if self.has_staged_changes() {
"git commit"
} else {
"git commit --all"
};
let title = if self.has_staged_changes() { let title = if self.has_staged_changes() {
"Commit" "Commit"
} else { } else {
@ -1938,6 +1955,7 @@ impl GitPanel {
.child( .child(
panel_filled_button(title) panel_filled_button(title)
.tooltip(move |window, cx| { .tooltip(move |window, cx| {
if can_commit {
Tooltip::for_action_in( Tooltip::for_action_in(
tooltip, tooltip,
&Commit, &Commit,
@ -1945,6 +1963,9 @@ impl GitPanel {
window, window,
cx, cx,
) )
} else {
Tooltip::simple(tooltip, cx)
}
}) })
.disabled(!can_commit || self.modal_open) .disabled(!can_commit || self.modal_open)
.on_click({ .on_click({