From 1c35db7e97997dea0f0c59201ebbab1ff63c91a2 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Mon, 14 Aug 2023 12:20:59 +0200 Subject: [PATCH] project_search: style filters button like the rest of the buttons --- crates/search/src/buffer_search.rs | 4 ++- crates/search/src/project_search.rs | 51 ++++++++++------------------- crates/search/src/search_bar.rs | 18 +++++----- 3 files changed, 28 insertions(+), 45 deletions(-) diff --git a/crates/search/src/buffer_search.rs b/crates/search/src/buffer_search.rs index 5c02874f97..585672c45b 100644 --- a/crates/search/src/buffer_search.rs +++ b/crates/search/src/buffer_search.rs @@ -174,7 +174,9 @@ impl View for BufferSearchBar { crate::search_bar::render_option_button_icon::( 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); }, diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs index 7389faf031..de0c424e7b 100644 --- a/crates/search/src/project_search.rs +++ b/crates/search/src/project_search.rs @@ -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::::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::( - 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| { 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); }, diff --git a/crates/search/src/search_bar.rs b/crates/search/src/search_bar.rs index 10f1a984b5..0cd63922ef 100644 --- a/crates/search/src/search_bar.rs +++ b/crates/search/src/search_bar.rs @@ -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( @@ -160,12 +162,14 @@ pub(crate) fn render_search_mode_button( pub(crate) fn render_option_button_icon( is_active: bool, icon: &'static str, - option: SearchOptions, + id: usize, + label: impl Into>, + action: Box, on_click: impl Fn(MouseClick, &mut V, &mut EventContext) + 'static, cx: &mut ViewContext, ) -> AnyElement { let tooltip_style = theme::current(cx).tooltip.clone(); - MouseEventHandler::::new(option.bits as usize, cx, |state, cx| { + MouseEventHandler::::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( }) .on_click(MouseButton::Left, on_click) .with_cursor_style(CursorStyle::PointingHand) - .with_tooltip::( - option.bits as usize, - format!("Toggle {}", option.label()), - Some(option.to_toggle_action()), - tooltip_style, - cx, - ) + .with_tooltip::(id, label, Some(action), tooltip_style, cx) .into_any() }