2023-07-24 15:37:48 +00:00
|
|
|
use gpui::{elements::Label, AnyElement, Element, Entity, View, ViewContext};
|
2023-07-20 18:32:27 +00:00
|
|
|
use workspace::{item::ItemHandle, StatusItemView};
|
|
|
|
|
2023-07-24 15:37:48 +00:00
|
|
|
use crate::state::Mode;
|
2023-07-20 18:32:27 +00:00
|
|
|
|
|
|
|
pub struct ModeIndicator {
|
2023-07-24 15:37:48 +00:00
|
|
|
pub mode: Mode,
|
2023-07-20 18:32:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl ModeIndicator {
|
2023-07-24 15:37:48 +00:00
|
|
|
pub fn new(mode: Mode) -> Self {
|
|
|
|
Self { mode }
|
2023-07-20 18:32:27 +00:00
|
|
|
}
|
|
|
|
|
2023-07-24 15:37:48 +00:00
|
|
|
pub fn set_mode(&mut self, mode: Mode, cx: &mut ViewContext<Self>) {
|
2023-07-20 18:32:27 +00:00
|
|
|
if mode != self.mode {
|
|
|
|
self.mode = mode;
|
|
|
|
cx.notify();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Entity for ModeIndicator {
|
|
|
|
type Event = ();
|
|
|
|
}
|
|
|
|
|
|
|
|
impl View for ModeIndicator {
|
|
|
|
fn ui_name() -> &'static str {
|
2023-07-24 15:37:48 +00:00
|
|
|
"ModeIndicatorView"
|
2023-07-20 18:32:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
|
2023-07-24 15:37:48 +00:00
|
|
|
let theme = &theme::current(cx).workspace.status_bar;
|
|
|
|
// we always choose text to be 12 monospace characters
|
|
|
|
// so that as the mode indicator changes, the rest of the
|
|
|
|
// UI stays still.
|
|
|
|
let text = match self.mode {
|
|
|
|
Mode::Normal => "-- NORMAL --",
|
|
|
|
Mode::Insert => "-- INSERT --",
|
|
|
|
Mode::Visual { line: false } => "-- VISUAL --",
|
|
|
|
Mode::Visual { line: true } => "VISUAL LINE ",
|
|
|
|
};
|
2023-07-25 16:58:44 +00:00
|
|
|
Label::new(text, theme.vim_mode_indicator.text.clone())
|
|
|
|
.contained()
|
|
|
|
.with_style(theme.vim_mode_indicator.container)
|
|
|
|
.into_any()
|
2023-07-20 18:32:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl StatusItemView for ModeIndicator {
|
|
|
|
fn set_active_pane_item(
|
|
|
|
&mut self,
|
|
|
|
_active_pane_item: Option<&dyn ItemHandle>,
|
|
|
|
_cx: &mut ViewContext<Self>,
|
|
|
|
) {
|
|
|
|
// nothing to do.
|
|
|
|
}
|
|
|
|
}
|