Skip to repository content

tenant.openagents/omega

No repository description is available.

OpenAgents Git authority 2026-07-28T04:38:45.031Z Public web read
NIP-34 coordinate30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omega
MaintainersHidden in public view
References2 branches · 1 tag
Read-only clonegit clone https://openagents.com/git/tenant.openagents/omega.git
Browse files

settings.rs

257 lines · 10.3 KB · rust
1use ui::{
2    ActiveTheme as _, AnyElement, ButtonSize, Checkbox, Context, ContextMenu, DropdownMenu,
3    ElementId, IntoElement as _, ParentElement as _, Styled as _, ToggleState, Tooltip, Window,
4    div, h_flex,
5};
6
7use crate::{
8    CsvPreviewView,
9    settings::{FilterSortOrder, VerticalAlignment},
10};
11
12///// Settings related /////
13impl CsvPreviewView {
14    /// Render settings panel above the table
15    pub(crate) fn render_settings_panel(
16        &self,
17        window: &mut Window,
18        cx: &mut Context<Self>,
19    ) -> AnyElement {
20        let current_alignment_text = match self.settings.vertical_alignment {
21            VerticalAlignment::Top => "Top",
22            VerticalAlignment::Center => "Center",
23        };
24
25        let current_filter_sort_text = match self.settings.filter_sort_order {
26            FilterSortOrder::AlphaThenCount => "A-Z, then Count",
27            FilterSortOrder::CountThenAlpha => "Count, then A-Z",
28        };
29
30        let view = cx.entity();
31        let alignment_dropdown_menu = ContextMenu::build(window, cx, |menu, _window, _cx| {
32            menu.entry("Top", None, {
33                let view = view.clone();
34                move |_window, cx| {
35                    view.update(cx, |this, cx| {
36                        this.settings.vertical_alignment = VerticalAlignment::Top;
37                        cx.notify();
38                    });
39                }
40            })
41            .entry("Center", None, {
42                let view = view.clone();
43                move |_window, cx| {
44                    view.update(cx, |this, cx| {
45                        this.settings.vertical_alignment = VerticalAlignment::Center;
46                        cx.notify();
47                    });
48                }
49            })
50        });
51
52        let filter_sort_dropdown_menu = ContextMenu::build(window, cx, |menu, _window, _cx| {
53            menu.entry("A-Z, then Count", None, {
54                let view = view.clone();
55                move |_window, cx| {
56                    view.update(cx, |this, cx| {
57                        this.settings.filter_sort_order = FilterSortOrder::AlphaThenCount;
58                        cx.notify();
59                    });
60                }
61            })
62            .entry("Count, then A-Z", None, {
63                let view = view.clone();
64                move |_window, cx| {
65                    view.update(cx, |this, cx| {
66                        this.settings.filter_sort_order = FilterSortOrder::CountThenAlpha;
67                        cx.notify();
68                    });
69                }
70            })
71        });
72
73        let panel = h_flex()
74            .gap_4()
75            .p_2()
76            .bg(cx.theme().colors().surface_background)
77            .border_b_1()
78            .border_color(cx.theme().colors().border)
79            .flex_wrap()
80            .child(
81                h_flex()
82                    .gap_2()
83                    .items_center()
84                    .child(
85                        div()
86                            .text_sm()
87                            .text_color(cx.theme().colors().text_muted)
88                            .child("Text Alignment:"),
89                    )
90                    .child(
91                        DropdownMenu::new(
92                            ElementId::Name("vertical-alignment-dropdown".into()),
93                            current_alignment_text,
94                            alignment_dropdown_menu,
95                        )
96                        .trigger_size(ButtonSize::Compact)
97                        .trigger_tooltip(Tooltip::text(
98                            "Choose vertical text alignment within cells",
99                        )),
100                    ),
101            )
102            .child(
103                h_flex()
104                    .gap_2()
105                    .items_center()
106                    .child(
107                        div()
108                            .text_sm()
109                            .text_color(cx.theme().colors().text_muted)
110                            .child("Filter Sort:"),
111                    )
112                    .child(
113                        DropdownMenu::new(
114                            ElementId::Name("filter-sort-order-dropdown".into()),
115                            current_filter_sort_text,
116                            filter_sort_dropdown_menu,
117                        )
118                        .trigger_size(ButtonSize::Compact)
119                        .trigger_tooltip(Tooltip::text(
120                            "Choose how filter values are sorted in the filter menu",
121                        )),
122                    ),
123            );
124
125        let multiline_enabled = self.settings.multiline_cells_enabled;
126        let panel = panel.child({
127            let view = view.clone();
128            Checkbox::new(
129                ElementId::Name("multiline-rows-checkbox".into()),
130                if multiline_enabled {
131                    ToggleState::Selected
132                } else {
133                    ToggleState::Unselected
134                },
135            )
136            .label("Display multiline rows")
137            .tooltip(Tooltip::text(
138                "When enabled, row height grows to show all content. \
139                 When disabled, only the first line is visible — hover a cell to see the rest.",
140            ))
141            .on_click(move |_state, _window, cx| {
142                view.update(cx, |this, cx| {
143                    this.settings.multiline_cells_enabled = !this.settings.multiline_cells_enabled;
144                    cx.notify();
145                });
146            })
147        });
148
149        #[cfg(feature = "dev-tools")]
150        let panel = panel.child(
151            h_flex()
152                .gap_2()
153                .items_center()
154                .child(
155                    div()
156                        .text_sm()
157                        .text_color(cx.theme().colors().text_muted)
158                        .child("Dev-only:"),
159                )
160                .child(create_dev_only_popover_menu(cx)),
161        );
162
163        panel.into_any_element()
164    }
165}
166
167#[cfg(feature = "dev-tools")]
168fn create_dev_only_popover_menu(
169    cx: &mut Context<'_, CsvPreviewView>,
170) -> ui::PopoverMenu<ContextMenu> {
171    use crate::settings::RowRenderMechanism;
172    use ui::{IconButton, IconName, IconPosition, IconSize, PopoverMenu};
173
174    PopoverMenu::new("debug-options-menu")
175        .trigger_with_tooltip(
176            IconButton::new("debug-options-trigger", IconName::Settings).icon_size(IconSize::Small),
177            Tooltip::text(
178                "Dev-only section used for debugging purposes.\nWill be removed on public release of CSV feature"
179            ),
180        )
181        .menu({
182            let view_entity = cx.entity();
183            move |window, cx| {
184                let view = view_entity.read(cx);
185                let settings = view.settings.clone();
186                Some(ContextMenu::build(window, cx, |menu, _, _| {
187                    menu.header("Rendering Mode")
188                        .toggleable_entry(
189                            "Variable Height",
190                            settings.rendering_with == RowRenderMechanism::VariableList,
191                            IconPosition::Start,
192                            None,
193                            {
194                                let view_entity = view_entity.clone();
195                                move |_w, cx| {
196                                    view_entity.update(cx, |view, cx| {
197                                        view.settings.rendering_with =
198                                            RowRenderMechanism::VariableList;
199                                        cx.notify();
200                                    })
201                                }
202                            },
203                        )
204                        .toggleable_entry(
205                            "Uniform Height",
206                            settings.rendering_with == RowRenderMechanism::UniformList,
207                            IconPosition::Start,
208                            None,
209                            {
210                                let view_entity = view_entity.clone();
211                                move |_w, cx| {
212                                    view_entity.update(cx, |view, cx| {
213                                        view.settings.rendering_with =
214                                            RowRenderMechanism::UniformList;
215                                        cx.notify();
216                                    })
217                                }
218                            },
219                        )
220                        .separator()
221                        .toggleable_entry(
222                            "Show perf metrics",
223                            settings.show_perf_metrics_overlay,
224                            IconPosition::Start,
225                            None,
226                            {
227                                let view_entity = view_entity.clone();
228                                move |_w, cx| {
229                                    view_entity.update(cx, |view, cx| {
230                                        view.settings.show_perf_metrics_overlay =
231                                            !view.settings.show_perf_metrics_overlay;
232                                        cx.notify();
233                                    })
234                                }
235                            },
236                        )
237                        .toggleable_entry(
238                            "Show cell positions",
239                            settings.show_debug_info,
240                            IconPosition::Start,
241                            None,
242                            {
243                                let view_entity = view_entity.clone();
244                                move |_, cx| {
245                                    view_entity.update(cx, |view, cx| {
246                                        view.settings.show_debug_info =
247                                            !view.settings.show_debug_info;
248                                        cx.notify();
249                                    })
250                                }
251                            },
252                        )
253                }))
254            }
255        })
256}
257
Served at tenant.openagents/omega Member data and write actions are omitted.