1use gpui::Action;
2
3use crate::{ActivateRegexMode, ActivateTextMode};
4// TODO: Update the default search mode to get from config
5#[derive(Copy, Clone, Debug, Default, PartialEq)]
6pub enum SearchMode {
7 #[default]
8 Text,
9 Regex,
10}
11
12#[derive(Copy, Clone, Debug, PartialEq)]
13pub(crate) enum Side {
14 Left,
15 Right,
16}
17
18impl SearchMode {
19 pub(crate) fn label(&self) -> &'static str {
20 match self {
21 SearchMode::Text => "Text",
22 SearchMode::Regex => "Regex",
23 }
24 }
25
26 pub(crate) fn region_id(&self) -> usize {
27 match self {
28 SearchMode::Text => 3,
29 SearchMode::Regex => 5,
30 }
31 }
32
33 pub(crate) fn tooltip_text(&self) -> &'static str {
34 match self {
35 SearchMode::Text => "Activate Text Search",
36 SearchMode::Regex => "Activate Regex Search",
37 }
38 }
39
40 pub(crate) fn activate_action(&self) -> Box<dyn Action> {
41 match self {
42 SearchMode::Text => Box::new(ActivateTextMode),
43 SearchMode::Regex => Box::new(ActivateRegexMode),
44 }
45 }
46
47 pub(crate) fn border_right(&self) -> bool {
48 match self {
49 SearchMode::Regex => true,
50 SearchMode::Text => true,
51 }
52 }
53
54 pub(crate) fn border_left(&self) -> bool {
55 match self {
56 SearchMode::Text => true,
57 _ => false,
58 }
59 }
60
61 pub(crate) fn button_side(&self) -> Option<Side> {
62 match self {
63 SearchMode::Text => Some(Side::Left),
64 SearchMode::Regex => Some(Side::Right),
65 }
66 }
67}
68
69pub(crate) fn next_mode(mode: &SearchMode) -> SearchMode {
70 match mode {
71 SearchMode::Text => SearchMode::Regex,
72 SearchMode::Regex => SearchMode::Text,
73 }
74}