project_search: style filters button like the rest of the buttons

This commit is contained in:
Piotr Osiewicz 2023-08-14 12:20:59 +02:00
parent d37ebe7841
commit 1c35db7e97
3 changed files with 28 additions and 45 deletions

View File

@ -174,7 +174,9 @@ impl View for BufferSearchBar {
crate::search_bar::render_option_button_icon::<Self>(
is_active,
icon,
option,
option.bits as usize,
format!("Toggle {}", option.label()),
option.to_toggle_action(),
move |_, this, cx| {
this.toggle_search_option(option, cx);
},

View File

@ -1,7 +1,7 @@
use crate::{
history::SearchHistory,
mode::SearchMode,
search_bar::{render_nav_button, render_search_mode_button},
search_bar::{render_nav_button, render_option_button_icon, render_search_mode_button},
ActivateRegexMode, CycleMode, NextHistoryQuery, PreviousHistoryQuery, SearchOptions,
SelectNextMatch, SelectPrevMatch, ToggleCaseSensitive, ToggleWholeWord,
};
@ -16,11 +16,9 @@ use futures::StreamExt;
use gpui::platform::PromptLevel;
use gpui::{
actions,
elements::*,
platform::{CursorStyle, MouseButton},
Action, AnyElement, AnyViewHandle, AppContext, Entity, ModelContext, ModelHandle, Subscription,
Task, View, ViewContext, ViewHandle, WeakModelHandle, WeakViewHandle,
actions, elements::*, platform::MouseButton, Action, AnyElement, AnyViewHandle, AppContext,
Entity, ModelContext, ModelHandle, Subscription, Task, View, ViewContext, ViewHandle,
WeakModelHandle, WeakViewHandle,
};
use menu::Confirm;
@ -1417,41 +1415,26 @@ impl View for ProjectSearchBar {
.flex(1.0, true);
let row_spacing = theme.workspace.toolbar.container.padding.bottom;
let search = _search.read(cx);
let filter_button = {
let tooltip_style = theme::current(cx).tooltip.clone();
let is_active = search.filters_enabled;
MouseEventHandler::<Self, _>::new(0, cx, |state, cx| {
let theme = theme::current(cx);
let style = theme
.search
.option_button
.in_state(is_active)
.style_for(state);
Svg::new("icons/filter_12.svg")
.with_color(style.text.color.clone())
.contained()
.with_style(style.container)
})
.on_click(MouseButton::Left, move |_, this, cx| {
let filter_button = render_option_button_icon(
search.filters_enabled,
"icons/filter_12.svg",
0,
"Toggle filters",
Box::new(ToggleFilters),
move |_, this, cx| {
this.toggle_filters(cx);
})
.with_cursor_style(CursorStyle::PointingHand)
.with_tooltip::<Self>(
0,
"Toggle filters",
Some(Box::new(ToggleFilters)),
tooltip_style,
cx,
)
.into_any()
};
},
cx,
);
let search = _search.read(cx);
let is_semantic_disabled = search.semantic_state.is_none();
let render_option_button_icon = |path, option, cx: &mut ViewContext<Self>| {
crate::search_bar::render_option_button_icon(
self.is_option_enabled(option, cx),
path,
option,
option.bits as usize,
format!("Toggle {}", option.label()),
option.to_toggle_action(),
move |_, this, cx| {
this.toggle_search_option(option, cx);
},

View File

@ -1,3 +1,5 @@
use std::borrow::Cow;
use gpui::{
elements::{Label, MouseEventHandler, Svg},
platform::{CursorStyle, MouseButton},
@ -8,7 +10,7 @@ use workspace::searchable::Direction;
use crate::{
mode::{SearchMode, Side},
SearchOptions, SelectNextMatch, SelectPrevMatch,
SelectNextMatch, SelectPrevMatch,
};
pub(super) fn render_close_button<V: View>(
@ -160,12 +162,14 @@ pub(crate) fn render_search_mode_button<V: View>(
pub(crate) fn render_option_button_icon<V: View>(
is_active: bool,
icon: &'static str,
option: SearchOptions,
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::<V, _>::new(option.bits as usize, cx, |state, cx| {
MouseEventHandler::<V, _>::new(id, cx, |state, cx| {
let theme = theme::current(cx);
let style = theme
.search
@ -181,12 +185,6 @@ pub(crate) fn render_option_button_icon<V: View>(
})
.on_click(MouseButton::Left, on_click)
.with_cursor_style(CursorStyle::PointingHand)
.with_tooltip::<V>(
option.bits as usize,
format!("Toggle {}", option.label()),
Some(option.to_toggle_action()),
tooltip_style,
cx,
)
.with_tooltip::<V>(id, label, Some(action), tooltip_style, cx)
.into_any()
}