Skip to repository content

tenant.openagents/omega

No repository description is available.

OpenAgents Git authority 2026-07-28T03:11:02.616Z 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

line_ending_indicator.rs

81 lines · 2.7 KB · rust
1use editor::Editor;
2use gpui::{App, Entity, Subscription, WeakEntity};
3use language::LineEnding;
4use ui::{Tooltip, prelude::*};
5use workspace::{
6    HideStatusItem, StatusBarSettings, StatusItemView, item::ItemHandle, item::Settings,
7};
8
9use crate::{LineEndingSelector, Toggle};
10
11#[derive(Default)]
12pub struct LineEndingIndicator {
13    line_ending: Option<LineEnding>,
14    active_editor: Option<WeakEntity<Editor>>,
15    _observe_active_editor: Option<Subscription>,
16}
17
18impl LineEndingIndicator {
19    fn update(&mut self, editor: Entity<Editor>, _: &mut Window, cx: &mut Context<Self>) {
20        self.line_ending = None;
21        self.active_editor = None;
22
23        if let Some(buffer) = editor.read(cx).active_buffer(cx) {
24            let line_ending = buffer.read(cx).line_ending();
25            self.line_ending = Some(line_ending);
26            self.active_editor = Some(editor.downgrade());
27        }
28
29        cx.notify();
30    }
31}
32
33impl Render for LineEndingIndicator {
34    fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
35        if !StatusBarSettings::get_global(cx).line_endings_button {
36            return div();
37        }
38
39        div().when_some(self.line_ending.as_ref(), |el, line_ending| {
40            el.child(
41                Button::new("change-line-ending", line_ending.label())
42                    .label_size(LabelSize::Small)
43                    .tab_index(0isize)
44                    .on_click(cx.listener(|this, _, window, cx| {
45                        if let Some(editor) = this.active_editor.as_ref() {
46                            LineEndingSelector::toggle(editor, window, cx);
47                        }
48                    }))
49                    .tooltip(|_window, cx| Tooltip::for_action("Select Line Ending", &Toggle, cx)),
50            )
51        })
52    }
53}
54
55impl StatusItemView for LineEndingIndicator {
56    fn set_active_pane_item(
57        &mut self,
58        active_pane_item: Option<&dyn ItemHandle>,
59        window: &mut Window,
60        cx: &mut Context<Self>,
61    ) {
62        if let Some(editor) = active_pane_item.and_then(|item| item.downcast::<Editor>()) {
63            self._observe_active_editor = Some(cx.observe_in(&editor, window, Self::update));
64            self.update(editor, window, cx);
65        } else {
66            self.line_ending = None;
67            self._observe_active_editor = None;
68        }
69        cx.notify();
70    }
71
72    fn hide_setting(&self, _: &App) -> Option<HideStatusItem> {
73        Some(HideStatusItem::new(|settings| {
74            settings
75                .status_bar
76                .get_or_insert_default()
77                .line_endings_button = Some(false);
78        }))
79    }
80}
81
Served at tenant.openagents/omega Member data and write actions are omitted.