Remove 2 suffix for language_tools, search, terminal_view, auto_update
Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
+729
-724
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,7 @@
|
||||
use gpui::Action;
|
||||
use gpui::{Action, SharedString};
|
||||
|
||||
use crate::{ActivateRegexMode, ActivateSemanticMode, ActivateTextMode};
|
||||
|
||||
// TODO: Update the default search mode to get from config
|
||||
#[derive(Copy, Clone, Debug, Default, PartialEq)]
|
||||
pub enum SearchMode {
|
||||
@@ -10,12 +11,6 @@ pub enum SearchMode {
|
||||
Regex,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
pub(crate) enum Side {
|
||||
Left,
|
||||
Right,
|
||||
}
|
||||
|
||||
impl SearchMode {
|
||||
pub(crate) fn label(&self) -> &'static str {
|
||||
match self {
|
||||
@@ -24,28 +19,14 @@ impl SearchMode {
|
||||
SearchMode::Regex => "Regex",
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn region_id(&self) -> usize {
|
||||
match self {
|
||||
SearchMode::Text => 3,
|
||||
SearchMode::Semantic => 4,
|
||||
SearchMode::Regex => 5,
|
||||
}
|
||||
pub(crate) fn tooltip(&self) -> SharedString {
|
||||
format!("Activate {} Mode", self.label()).into()
|
||||
}
|
||||
|
||||
pub(crate) fn tooltip_text(&self) -> &'static str {
|
||||
pub(crate) fn action(&self) -> Box<dyn Action> {
|
||||
match self {
|
||||
SearchMode::Text => "Activate Text Search",
|
||||
SearchMode::Semantic => "Activate Semantic Search",
|
||||
SearchMode::Regex => "Activate Regex Search",
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn activate_action(&self) -> Box<dyn Action> {
|
||||
match self {
|
||||
SearchMode::Text => Box::new(ActivateTextMode),
|
||||
SearchMode::Semantic => Box::new(ActivateSemanticMode),
|
||||
SearchMode::Regex => Box::new(ActivateRegexMode),
|
||||
SearchMode::Text => ActivateTextMode.boxed_clone(),
|
||||
SearchMode::Semantic => ActivateSemanticMode.boxed_clone(),
|
||||
SearchMode::Regex => ActivateRegexMode.boxed_clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1437
-1310
File diff suppressed because it is too large
Load Diff
+31
-63
@@ -1,16 +1,11 @@
|
||||
use bitflags::bitflags;
|
||||
pub use buffer_search::BufferSearchBar;
|
||||
use gpui::{
|
||||
actions,
|
||||
elements::{Component, SafeStylable, TooltipStyle},
|
||||
Action, AnyElement, AppContext, Element, View,
|
||||
};
|
||||
use gpui::{actions, Action, AppContext, IntoElement};
|
||||
pub use mode::SearchMode;
|
||||
use project::search::SearchQuery;
|
||||
pub use project_search::{ProjectSearchBar, ProjectSearchView};
|
||||
use theme::components::{
|
||||
action_button::Button, svg::Svg, ComponentExt, IconButtonStyle, ToggleIconButtonStyle,
|
||||
};
|
||||
pub use project_search::ProjectSearchView;
|
||||
use ui::{prelude::*, Tooltip};
|
||||
use ui::{ButtonStyle, IconButton};
|
||||
|
||||
pub mod buffer_search;
|
||||
mod history;
|
||||
@@ -19,6 +14,7 @@ pub mod project_search;
|
||||
pub(crate) mod search_bar;
|
||||
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
menu::init();
|
||||
buffer_search::init(cx);
|
||||
project_search::init(cx);
|
||||
}
|
||||
@@ -57,28 +53,28 @@ bitflags! {
|
||||
impl SearchOptions {
|
||||
pub fn label(&self) -> &'static str {
|
||||
match *self {
|
||||
Self::WHOLE_WORD => "Match Whole Word",
|
||||
Self::CASE_SENSITIVE => "Match Case",
|
||||
Self::INCLUDE_IGNORED => "Include Ignored",
|
||||
_ => panic!("{self:?} is not a named SearchOption"),
|
||||
SearchOptions::WHOLE_WORD => "Match Whole Word",
|
||||
SearchOptions::CASE_SENSITIVE => "Match Case",
|
||||
SearchOptions::INCLUDE_IGNORED => "Include ignored",
|
||||
_ => panic!("{:?} is not a named SearchOption", self),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn icon(&self) -> &'static str {
|
||||
pub fn icon(&self) -> ui::Icon {
|
||||
match *self {
|
||||
Self::WHOLE_WORD => "icons/word_search.svg",
|
||||
Self::CASE_SENSITIVE => "icons/case_insensitive.svg",
|
||||
Self::INCLUDE_IGNORED => "icons/case_insensitive.svg",
|
||||
_ => panic!("{self:?} is not a named SearchOption"),
|
||||
SearchOptions::WHOLE_WORD => ui::Icon::WholeWord,
|
||||
SearchOptions::CASE_SENSITIVE => ui::Icon::CaseSensitive,
|
||||
SearchOptions::INCLUDE_IGNORED => ui::Icon::FileGit,
|
||||
_ => panic!("{:?} is not a named SearchOption", self),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_toggle_action(&self) -> Box<dyn Action> {
|
||||
pub fn to_toggle_action(&self) -> Box<dyn Action + Sync + Send + 'static> {
|
||||
match *self {
|
||||
Self::WHOLE_WORD => Box::new(ToggleWholeWord),
|
||||
Self::CASE_SENSITIVE => Box::new(ToggleCaseSensitive),
|
||||
Self::INCLUDE_IGNORED => Box::new(ToggleIncludeIgnored),
|
||||
_ => panic!("{self:?} is not a named SearchOption"),
|
||||
SearchOptions::WHOLE_WORD => Box::new(ToggleWholeWord),
|
||||
SearchOptions::CASE_SENSITIVE => Box::new(ToggleCaseSensitive),
|
||||
SearchOptions::INCLUDE_IGNORED => Box::new(ToggleIncludeIgnored),
|
||||
_ => panic!("{:?} is not a named SearchOption", self),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,47 +90,19 @@ impl SearchOptions {
|
||||
options
|
||||
}
|
||||
|
||||
pub fn as_button<V: View>(
|
||||
pub fn as_button(
|
||||
&self,
|
||||
active: bool,
|
||||
tooltip_style: TooltipStyle,
|
||||
button_style: ToggleIconButtonStyle,
|
||||
) -> AnyElement<V> {
|
||||
Button::dynamic_action(self.to_toggle_action())
|
||||
.with_tooltip(format!("Toggle {}", self.label()), tooltip_style)
|
||||
.with_contents(Svg::new(self.icon()))
|
||||
.toggleable(active)
|
||||
.with_style(button_style)
|
||||
.element()
|
||||
.into_any()
|
||||
action: impl Fn(&gpui::ClickEvent, &mut WindowContext) + 'static,
|
||||
) -> impl IntoElement {
|
||||
IconButton::new(self.label(), self.icon())
|
||||
.on_click(action)
|
||||
.style(ButtonStyle::Subtle)
|
||||
.when(active, |button| button.style(ButtonStyle::Filled))
|
||||
.tooltip({
|
||||
let action = self.to_toggle_action();
|
||||
let label: SharedString = format!("Toggle {}", self.label()).into();
|
||||
move |cx| Tooltip::for_action(label.clone(), &*action, cx)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn toggle_replace_button<V: View>(
|
||||
active: bool,
|
||||
tooltip_style: TooltipStyle,
|
||||
button_style: ToggleIconButtonStyle,
|
||||
) -> AnyElement<V> {
|
||||
Button::dynamic_action(Box::new(ToggleReplace))
|
||||
.with_tooltip("Toggle Replace", tooltip_style)
|
||||
.with_contents(theme::components::svg::Svg::new("icons/replace.svg"))
|
||||
.toggleable(active)
|
||||
.with_style(button_style)
|
||||
.element()
|
||||
.into_any()
|
||||
}
|
||||
|
||||
fn replace_action<V: View>(
|
||||
action: impl Action,
|
||||
name: &'static str,
|
||||
icon_path: &'static str,
|
||||
tooltip_style: TooltipStyle,
|
||||
button_style: IconButtonStyle,
|
||||
) -> AnyElement<V> {
|
||||
Button::dynamic_action(Box::new(action))
|
||||
.with_tooltip(name, tooltip_style)
|
||||
.with_contents(theme::components::svg::Svg::new(icon_path))
|
||||
.with_style(button_style)
|
||||
.element()
|
||||
.into_any()
|
||||
}
|
||||
|
||||
+14
-170
@@ -1,174 +1,18 @@
|
||||
use std::borrow::Cow;
|
||||
use gpui::{Action, IntoElement};
|
||||
use ui::IconButton;
|
||||
use ui::{prelude::*, Tooltip};
|
||||
|
||||
use gpui::{
|
||||
elements::{Label, MouseEventHandler, Svg},
|
||||
platform::{CursorStyle, MouseButton},
|
||||
scene::{CornerRadii, MouseClick},
|
||||
Action, AnyElement, Element, EventContext, View, ViewContext,
|
||||
};
|
||||
use workspace::searchable::Direction;
|
||||
|
||||
use crate::{
|
||||
mode::{SearchMode, Side},
|
||||
SelectNextMatch, SelectPrevMatch,
|
||||
};
|
||||
|
||||
pub(super) fn render_nav_button<V: View>(
|
||||
icon: &'static str,
|
||||
direction: Direction,
|
||||
pub(super) fn render_nav_button(
|
||||
icon: ui::Icon,
|
||||
active: bool,
|
||||
on_click: impl Fn(MouseClick, &mut V, &mut EventContext<V>) + 'static,
|
||||
cx: &mut ViewContext<V>,
|
||||
) -> AnyElement<V> {
|
||||
let action: Box<dyn Action>;
|
||||
let tooltip;
|
||||
|
||||
match direction {
|
||||
Direction::Prev => {
|
||||
action = Box::new(SelectPrevMatch);
|
||||
tooltip = "Select Previous Match";
|
||||
}
|
||||
Direction::Next => {
|
||||
action = Box::new(SelectNextMatch);
|
||||
tooltip = "Select Next Match";
|
||||
}
|
||||
};
|
||||
let tooltip_style = theme::current(cx).tooltip.clone();
|
||||
let cursor_style = if active {
|
||||
CursorStyle::PointingHand
|
||||
} else {
|
||||
CursorStyle::default()
|
||||
};
|
||||
enum NavButton {}
|
||||
MouseEventHandler::new::<NavButton, _>(direction as usize, cx, |state, cx| {
|
||||
let theme = theme::current(cx);
|
||||
let style = theme
|
||||
.search
|
||||
.nav_button
|
||||
.in_state(active)
|
||||
.style_for(state)
|
||||
.clone();
|
||||
let mut container_style = style.container.clone();
|
||||
let label = Label::new(icon, style.label.clone()).aligned().contained();
|
||||
container_style.corner_radii = match direction {
|
||||
Direction::Prev => CornerRadii {
|
||||
bottom_right: 0.,
|
||||
top_right: 0.,
|
||||
..container_style.corner_radii
|
||||
},
|
||||
Direction::Next => CornerRadii {
|
||||
bottom_left: 0.,
|
||||
top_left: 0.,
|
||||
..container_style.corner_radii
|
||||
},
|
||||
};
|
||||
if direction == Direction::Prev {
|
||||
// Remove right border so that when both Next and Prev buttons are
|
||||
// next to one another, there's no double border between them.
|
||||
container_style.border.right = false;
|
||||
}
|
||||
label.with_style(container_style)
|
||||
})
|
||||
.on_click(MouseButton::Left, on_click)
|
||||
.with_cursor_style(cursor_style)
|
||||
.with_tooltip::<NavButton>(
|
||||
direction as usize,
|
||||
tooltip.to_string(),
|
||||
Some(action),
|
||||
tooltip_style,
|
||||
cx,
|
||||
tooltip: &'static str,
|
||||
action: &'static dyn Action,
|
||||
) -> impl IntoElement {
|
||||
IconButton::new(
|
||||
SharedString::from(format!("search-nav-button-{}", action.name())),
|
||||
icon,
|
||||
)
|
||||
.into_any()
|
||||
}
|
||||
|
||||
pub(crate) fn render_search_mode_button<V: View>(
|
||||
mode: SearchMode,
|
||||
side: Option<Side>,
|
||||
is_active: bool,
|
||||
on_click: impl Fn(MouseClick, &mut V, &mut EventContext<V>) + 'static,
|
||||
cx: &mut ViewContext<V>,
|
||||
) -> AnyElement<V> {
|
||||
let tooltip_style = theme::current(cx).tooltip.clone();
|
||||
enum SearchModeButton {}
|
||||
MouseEventHandler::new::<SearchModeButton, _>(mode.region_id(), cx, |state, cx| {
|
||||
let theme = theme::current(cx);
|
||||
let style = theme
|
||||
.search
|
||||
.mode_button
|
||||
.in_state(is_active)
|
||||
.style_for(state)
|
||||
.clone();
|
||||
|
||||
let mut container_style = style.container;
|
||||
if let Some(button_side) = side {
|
||||
if button_side == Side::Left {
|
||||
container_style.border.left = true;
|
||||
container_style.corner_radii = CornerRadii {
|
||||
bottom_right: 0.,
|
||||
top_right: 0.,
|
||||
..container_style.corner_radii
|
||||
};
|
||||
} else {
|
||||
container_style.border.left = false;
|
||||
container_style.corner_radii = CornerRadii {
|
||||
bottom_left: 0.,
|
||||
top_left: 0.,
|
||||
..container_style.corner_radii
|
||||
};
|
||||
}
|
||||
} else {
|
||||
container_style.border.left = false;
|
||||
container_style.corner_radii = CornerRadii::default();
|
||||
}
|
||||
|
||||
Label::new(mode.label(), style.text)
|
||||
.aligned()
|
||||
.contained()
|
||||
.with_style(container_style)
|
||||
.constrained()
|
||||
.with_height(theme.search.search_bar_row_height)
|
||||
})
|
||||
.on_click(MouseButton::Left, on_click)
|
||||
.with_cursor_style(CursorStyle::PointingHand)
|
||||
.with_tooltip::<SearchModeButton>(
|
||||
mode.region_id(),
|
||||
mode.tooltip_text().to_owned(),
|
||||
Some(mode.activate_action()),
|
||||
tooltip_style,
|
||||
cx,
|
||||
)
|
||||
.into_any()
|
||||
}
|
||||
|
||||
pub(crate) fn render_option_button_icon<V: View>(
|
||||
is_active: bool,
|
||||
icon: &'static str,
|
||||
id: usize,
|
||||
label: impl Into<Cow<'static, str>>,
|
||||
action: Box<dyn Action>,
|
||||
on_click: impl Fn(MouseClick, &mut V, &mut EventContext<V>) + 'static,
|
||||
cx: &mut ViewContext<V>,
|
||||
) -> AnyElement<V> {
|
||||
let tooltip_style = theme::current(cx).tooltip.clone();
|
||||
MouseEventHandler::new::<V, _>(id, cx, |state, cx| {
|
||||
let theme = theme::current(cx);
|
||||
let style = theme
|
||||
.search
|
||||
.option_button
|
||||
.in_state(is_active)
|
||||
.style_for(state);
|
||||
Svg::new(icon)
|
||||
.with_color(style.color.clone())
|
||||
.constrained()
|
||||
.with_width(style.icon_width)
|
||||
.contained()
|
||||
.with_style(style.container)
|
||||
.constrained()
|
||||
.with_height(theme.search.option_button_height)
|
||||
.with_width(style.button_width)
|
||||
})
|
||||
.on_click(MouseButton::Left, on_click)
|
||||
.with_cursor_style(CursorStyle::PointingHand)
|
||||
.with_tooltip::<V>(id, label, Some(action), tooltip_style, cx)
|
||||
.into_any()
|
||||
.on_click(|_, cx| cx.dispatch_action(action.boxed_clone()))
|
||||
.tooltip(move |cx| Tooltip::for_action(tooltip, action, cx))
|
||||
.disabled(!active)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user