Forego using dispatch_action for click handlers
This commit is contained in:
parent
38d844ab66
commit
66e0650f75
1 changed files with 52 additions and 32 deletions
|
@ -1748,9 +1748,9 @@ impl Render for ProjectSearchBar {
|
||||||
.tooltip(|cx| {
|
.tooltip(|cx| {
|
||||||
Tooltip::for_action("Toggle filters", &ToggleFilters, cx)
|
Tooltip::for_action("Toggle filters", &ToggleFilters, cx)
|
||||||
})
|
})
|
||||||
.on_click(|_, cx| {
|
.on_click(cx.listener(|this, _, cx| {
|
||||||
cx.dispatch_action(ToggleFilters.boxed_clone())
|
this.toggle_filters(cx);
|
||||||
})
|
}))
|
||||||
.selected(
|
.selected(
|
||||||
self.active_project_search
|
self.active_project_search
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
@ -1771,9 +1771,14 @@ impl Render for ProjectSearchBar {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.selected(self.is_option_enabled(SearchOptions::CASE_SENSITIVE, cx))
|
.selected(self.is_option_enabled(SearchOptions::CASE_SENSITIVE, cx))
|
||||||
.on_click(|_, cx| {
|
.on_click(cx.listener(
|
||||||
cx.dispatch_action(ToggleCaseSensitive.boxed_clone())
|
|this, _, cx| {
|
||||||
}),
|
this.toggle_search_option(
|
||||||
|
SearchOptions::CASE_SENSITIVE,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
)),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
IconButton::new("project-search-whole-word", Icon::WholeWord)
|
IconButton::new("project-search-whole-word", Icon::WholeWord)
|
||||||
|
@ -1785,9 +1790,9 @@ impl Render for ProjectSearchBar {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.selected(self.is_option_enabled(SearchOptions::WHOLE_WORD, cx))
|
.selected(self.is_option_enabled(SearchOptions::WHOLE_WORD, cx))
|
||||||
.on_click(|_, cx| {
|
.on_click(cx.listener(|this, _, cx| {
|
||||||
cx.dispatch_action(ToggleWholeWord.boxed_clone())
|
this.toggle_search_option(SearchOptions::WHOLE_WORD, cx);
|
||||||
}),
|
})),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.border_2()
|
.border_2()
|
||||||
|
@ -1823,9 +1828,9 @@ impl Render for ProjectSearchBar {
|
||||||
.child(
|
.child(
|
||||||
Button::new("project-search-text-button", "Text")
|
Button::new("project-search-text-button", "Text")
|
||||||
.selected(search.current_mode == SearchMode::Text)
|
.selected(search.current_mode == SearchMode::Text)
|
||||||
.on_click(|_, cx| {
|
.on_click(cx.listener(|this, _, cx| {
|
||||||
cx.dispatch_action(ActivateTextMode.boxed_clone())
|
this.activate_search_mode(SearchMode::Text, cx)
|
||||||
})
|
}))
|
||||||
.tooltip(|cx| {
|
.tooltip(|cx| {
|
||||||
Tooltip::for_action("Toggle text search", &ActivateTextMode, cx)
|
Tooltip::for_action("Toggle text search", &ActivateTextMode, cx)
|
||||||
}),
|
}),
|
||||||
|
@ -1833,9 +1838,9 @@ impl Render for ProjectSearchBar {
|
||||||
.child(
|
.child(
|
||||||
Button::new("project-search-regex-button", "Regex")
|
Button::new("project-search-regex-button", "Regex")
|
||||||
.selected(search.current_mode == SearchMode::Regex)
|
.selected(search.current_mode == SearchMode::Regex)
|
||||||
.on_click(|_, cx| {
|
.on_click(cx.listener(|this, _, cx| {
|
||||||
cx.dispatch_action(ActivateRegexMode.boxed_clone())
|
this.activate_search_mode(SearchMode::Regex, cx)
|
||||||
})
|
}))
|
||||||
.tooltip(|cx| {
|
.tooltip(|cx| {
|
||||||
Tooltip::for_action(
|
Tooltip::for_action(
|
||||||
"Toggle regular expression search",
|
"Toggle regular expression search",
|
||||||
|
@ -1847,9 +1852,9 @@ impl Render for ProjectSearchBar {
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
IconButton::new("project-search-toggle-replace", Icon::Replace)
|
IconButton::new("project-search-toggle-replace", Icon::Replace)
|
||||||
.on_click(|_, cx| {
|
.on_click(cx.listener(|this, _, cx| {
|
||||||
cx.dispatch_action(ToggleReplace.boxed_clone());
|
this.toggle_replace(&ToggleReplace, cx);
|
||||||
})
|
}))
|
||||||
.tooltip(|cx| Tooltip::for_action("Toggle replace", &ToggleReplace, cx)),
|
.tooltip(|cx| Tooltip::for_action("Toggle replace", &ToggleReplace, cx)),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -1869,37 +1874,52 @@ impl Render for ProjectSearchBar {
|
||||||
.when(search.replace_enabled, |this| {
|
.when(search.replace_enabled, |this| {
|
||||||
this.children([
|
this.children([
|
||||||
IconButton::new("project-search-replace-next", Icon::ReplaceNext)
|
IconButton::new("project-search-replace-next", Icon::ReplaceNext)
|
||||||
.on_click(|_, cx| {
|
.on_click(cx.listener(|this, _, cx| {
|
||||||
cx.dispatch_action(ReplaceNext.boxed_clone());
|
if let Some(search) = this.active_project_search.as_ref() {
|
||||||
})
|
search.update(cx, |this, cx| {
|
||||||
|
this.replace_next(&ReplaceNext, cx);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}))
|
||||||
.tooltip(|cx| Tooltip::for_action("Replace next match", &ReplaceNext, cx)),
|
.tooltip(|cx| Tooltip::for_action("Replace next match", &ReplaceNext, cx)),
|
||||||
IconButton::new("project-search-replace-all", Icon::ReplaceAll)
|
IconButton::new("project-search-replace-all", Icon::ReplaceAll)
|
||||||
.on_click(|_, cx| {
|
.on_click(cx.listener(|this, _, cx| {
|
||||||
cx.dispatch_action(ReplaceAll.boxed_clone());
|
if let Some(search) = this.active_project_search.as_ref() {
|
||||||
})
|
search.update(cx, |this, cx| {
|
||||||
|
this.replace_all(&ReplaceAll, cx);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}))
|
||||||
.tooltip(|cx| Tooltip::for_action("Replace all matches", &ReplaceAll, cx)),
|
.tooltip(|cx| Tooltip::for_action("Replace all matches", &ReplaceAll, cx)),
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
.when_some(search.active_match_index, |this, index| {
|
.when_some(search.active_match_index, |this, index| {
|
||||||
let match_quantity = search.model.read(cx).match_ranges.len();
|
let match_quantity = search.model.read(cx).match_ranges.len();
|
||||||
debug_assert!(match_quantity > index);
|
debug_assert!(match_quantity > index);
|
||||||
this.child(
|
this.child(Label::new(format!("{index}/{match_quantity}")))
|
||||||
IconButton::new("project-search-select-all", Icon::SelectAll)
|
|
||||||
.on_click(|_, cx| cx.dispatch_action(SelectAll.boxed_clone()))
|
|
||||||
.tooltip(|cx| Tooltip::for_action("Select all matches", &SelectAll, cx)),
|
|
||||||
)
|
|
||||||
.child(Label::new(format!("{index}/{match_quantity}")))
|
|
||||||
})
|
})
|
||||||
.children([
|
.children([
|
||||||
IconButton::new("project-search-prev-match", Icon::ChevronLeft)
|
IconButton::new("project-search-prev-match", Icon::ChevronLeft)
|
||||||
.disabled(search.active_match_index.is_none())
|
.disabled(search.active_match_index.is_none())
|
||||||
.on_click(|_, cx| cx.dispatch_action(SelectPrevMatch.boxed_clone()))
|
.on_click(cx.listener(|this, _, cx| {
|
||||||
|
if let Some(search) = this.active_project_search.as_ref() {
|
||||||
|
search.update(cx, |this, cx| {
|
||||||
|
this.select_match(Direction::Prev, cx);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}))
|
||||||
.tooltip(|cx| {
|
.tooltip(|cx| {
|
||||||
Tooltip::for_action("Go to previous match", &SelectPrevMatch, cx)
|
Tooltip::for_action("Go to previous match", &SelectPrevMatch, cx)
|
||||||
}),
|
}),
|
||||||
IconButton::new("project-search-next-match", Icon::ChevronRight)
|
IconButton::new("project-search-next-match", Icon::ChevronRight)
|
||||||
.disabled(search.active_match_index.is_none())
|
.disabled(search.active_match_index.is_none())
|
||||||
.on_click(|_, cx| cx.dispatch_action(SelectNextMatch.boxed_clone()))
|
.on_click(cx.listener(|this, _, cx| {
|
||||||
|
if let Some(search) = this.active_project_search.as_ref() {
|
||||||
|
search.update(cx, |this, cx| {
|
||||||
|
this.select_match(Direction::Next, cx);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}))
|
||||||
.tooltip(|cx| Tooltip::for_action("Go to next match", &SelectNextMatch, cx)),
|
.tooltip(|cx| Tooltip::for_action("Go to next match", &SelectNextMatch, cx)),
|
||||||
]);
|
]);
|
||||||
h_stack()
|
h_stack()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue