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>( crate::search_bar::render_option_button_icon::<Self>(
is_active, is_active,
icon, icon,
option, option.bits as usize,
format!("Toggle {}", option.label()),
option.to_toggle_action(),
move |_, this, cx| { move |_, this, cx| {
this.toggle_search_option(option, cx); this.toggle_search_option(option, cx);
}, },

View file

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

View file

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