Revert "Styling for Apply/Discard buttons (#21017)"
This reverts commit 884748038e
.
This commit is contained in:
parent
6dbe2ef10c
commit
64708527e7
9 changed files with 291 additions and 409 deletions
|
@ -5,11 +5,10 @@ use gpui::{AppContext, EventEmitter, FocusableView, Model, Render, Subscription,
|
|||
use language::{Buffer, BufferEvent, Capability};
|
||||
use multi_buffer::{ExcerptRange, MultiBuffer};
|
||||
use project::Project;
|
||||
use settings::Settings;
|
||||
use smol::stream::StreamExt;
|
||||
use std::{any::TypeId, ops::Range, rc::Rc, time::Duration};
|
||||
use text::ToOffset;
|
||||
use ui::{prelude::*, KeyBinding};
|
||||
use ui::{prelude::*, ButtonLike, KeyBinding};
|
||||
use workspace::{
|
||||
searchable::SearchableItemHandle, Item, ItemHandle as _, ToolbarItemEvent, ToolbarItemLocation,
|
||||
ToolbarItemView, Workspace,
|
||||
|
@ -35,11 +34,7 @@ struct BufferEntry {
|
|||
_subscription: Subscription,
|
||||
}
|
||||
|
||||
pub struct ProposedChangesToolbarControls {
|
||||
current_editor: Option<View<ProposedChangesEditor>>,
|
||||
}
|
||||
|
||||
pub struct ProposedChangesToolbar {
|
||||
pub struct ProposedChangesEditorToolbar {
|
||||
current_editor: Option<View<ProposedChangesEditor>>,
|
||||
}
|
||||
|
||||
|
@ -233,10 +228,6 @@ impl ProposedChangesEditor {
|
|||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn all_changes_accepted(&self) -> bool {
|
||||
false // In the future, we plan to compute this based on the current state of patches.
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for ProposedChangesEditor {
|
||||
|
@ -260,11 +251,7 @@ impl Item for ProposedChangesEditor {
|
|||
type Event = EditorEvent;
|
||||
|
||||
fn tab_icon(&self, _cx: &ui::WindowContext) -> Option<Icon> {
|
||||
if self.all_changes_accepted() {
|
||||
Some(Icon::new(IconName::Check).color(Color::Success))
|
||||
} else {
|
||||
Some(Icon::new(IconName::ZedAssistant))
|
||||
}
|
||||
Some(Icon::new(IconName::Diff))
|
||||
}
|
||||
|
||||
fn tab_content_text(&self, _cx: &WindowContext) -> Option<SharedString> {
|
||||
|
@ -330,7 +317,7 @@ impl Item for ProposedChangesEditor {
|
|||
}
|
||||
}
|
||||
|
||||
impl ProposedChangesToolbarControls {
|
||||
impl ProposedChangesEditorToolbar {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
current_editor: None,
|
||||
|
@ -346,97 +333,28 @@ impl ProposedChangesToolbarControls {
|
|||
}
|
||||
}
|
||||
|
||||
impl Render for ProposedChangesToolbarControls {
|
||||
impl Render for ProposedChangesEditorToolbar {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
if let Some(editor) = &self.current_editor {
|
||||
let focus_handle = editor.focus_handle(cx);
|
||||
let action = &ApplyAllDiffHunks;
|
||||
let keybinding = KeyBinding::for_action_in(action, &focus_handle, cx);
|
||||
let button_like = ButtonLike::new("apply-changes").child(Label::new("Apply All"));
|
||||
|
||||
let editor = editor.read(cx);
|
||||
match &self.current_editor {
|
||||
Some(editor) => {
|
||||
let focus_handle = editor.focus_handle(cx);
|
||||
let keybinding = KeyBinding::for_action_in(&ApplyAllDiffHunks, &focus_handle, cx)
|
||||
.map(|binding| binding.into_any_element());
|
||||
|
||||
let apply_all_button = if editor.all_changes_accepted() {
|
||||
None
|
||||
} else {
|
||||
Some(
|
||||
Button::new("apply-changes", "Apply All")
|
||||
.style(ButtonStyle::Filled)
|
||||
.key_binding(keybinding)
|
||||
.on_click(move |_event, cx| focus_handle.dispatch_action(action, cx)),
|
||||
)
|
||||
};
|
||||
|
||||
h_flex()
|
||||
.gap_1()
|
||||
.children([apply_all_button].into_iter().flatten())
|
||||
.into_any_element()
|
||||
} else {
|
||||
gpui::Empty.into_any_element()
|
||||
button_like.children(keybinding).on_click({
|
||||
move |_event, cx| focus_handle.dispatch_action(&ApplyAllDiffHunks, cx)
|
||||
})
|
||||
}
|
||||
None => button_like.disabled(true),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl EventEmitter<ToolbarItemEvent> for ProposedChangesToolbarControls {}
|
||||
impl EventEmitter<ToolbarItemEvent> for ProposedChangesEditorToolbar {}
|
||||
|
||||
impl ToolbarItemView for ProposedChangesToolbarControls {
|
||||
fn set_active_pane_item(
|
||||
&mut self,
|
||||
active_pane_item: Option<&dyn workspace::ItemHandle>,
|
||||
_cx: &mut ViewContext<Self>,
|
||||
) -> workspace::ToolbarItemLocation {
|
||||
self.current_editor =
|
||||
active_pane_item.and_then(|item| item.downcast::<ProposedChangesEditor>());
|
||||
self.get_toolbar_item_location()
|
||||
}
|
||||
}
|
||||
|
||||
impl ProposedChangesToolbar {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
current_editor: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn get_toolbar_item_location(&self) -> ToolbarItemLocation {
|
||||
if self.current_editor.is_some() {
|
||||
ToolbarItemLocation::PrimaryLeft
|
||||
} else {
|
||||
ToolbarItemLocation::Hidden
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for ProposedChangesToolbar {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
if let Some(editor) = &self.current_editor {
|
||||
let editor = editor.read(cx);
|
||||
let all_changes_accepted = editor.all_changes_accepted();
|
||||
let icon = if all_changes_accepted {
|
||||
Icon::new(IconName::Check).color(Color::Success)
|
||||
} else {
|
||||
Icon::new(IconName::ZedAssistant)
|
||||
};
|
||||
|
||||
h_flex()
|
||||
.gap_2p5()
|
||||
.font(theme::ThemeSettings::get_global(cx).buffer_font.clone())
|
||||
.child(icon.size(IconSize::Small))
|
||||
.child(
|
||||
Label::new(editor.title.clone())
|
||||
.color(Color::Muted)
|
||||
.single_line()
|
||||
.strikethrough(all_changes_accepted),
|
||||
)
|
||||
.into_any_element()
|
||||
} else {
|
||||
gpui::Empty.into_any_element()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl EventEmitter<ToolbarItemEvent> for ProposedChangesToolbar {}
|
||||
|
||||
impl ToolbarItemView for ProposedChangesToolbar {
|
||||
impl ToolbarItemView for ProposedChangesEditorToolbar {
|
||||
fn set_active_pane_item(
|
||||
&mut self,
|
||||
active_pane_item: Option<&dyn workspace::ItemHandle>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue