Files
ElyOffice/apps/ely-mark/src/keys.rs
T
ZacharyZhang-NYandClaude Opus 5.5 1f2920020a ElyMark: the file in MarkdownDocument, no web page
The view holds the component library's MarkdownDocument: the file's text
is the document's text, saved as read when unedited. Find, tables,
attachments, the look and export, which ran in the page, go until their
own tasks rebuild them natively. The window scripts that drove the page
go with it; gpui window tests cover the view.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-12 02:37:53 -04:00

91 lines
3.1 KiB
Rust

//! Modes, menus and keys (MARK-01, MARK-02).
use ely_ui::{commands, i18n::text};
use gpui::{App, KeyBinding, Menu, MenuItem, actions};
use crate::view::Mode;
actions!(mark, [VisualMode, SourceMode, PreviewMode, CheckDisk]);
pub fn bind(cx: &mut App) {
let at = Some(commands::CONTEXT);
cx.bind_keys([
KeyBinding::new("secondary-1", VisualMode, at),
KeyBinding::new("secondary-2", SourceMode, at),
KeyBinding::new("secondary-3", PreviewMode, at),
KeyBinding::new("secondary-shift-f", crate::look::FocusMode, at),
KeyBinding::new("secondary-=", crate::look::Larger, at),
KeyBinding::new("secondary--", crate::look::Smaller, at),
KeyBinding::new("secondary-0", crate::look::ActualSize, at),
]);
}
/// The label of `mode`.
pub fn label(mode: Mode, cx: &App) -> gpui::SharedString {
text(cx, &format!("mark.mode.{}", mode.name()), &[])
}
pub fn menus(look: &crate::look::Look, cx: &App) -> Vec<Menu> {
use crate::look::{self, Font, Width};
let checked = |key: &str, action: Box<dyn gpui::Action>, checked: bool| MenuItem::Action {
name: text(cx, key, &[]),
action,
os_action: None,
checked,
disabled: false,
};
let item = |key: &str, action: Box<dyn gpui::Action>| checked(key, action, false);
vec![
Menu::new(text(cx, "menu.view", &[])).items([
MenuItem::action(label(Mode::Visual, cx), VisualMode),
MenuItem::action(label(Mode::Source, cx), SourceMode),
MenuItem::action(label(Mode::Preview, cx), PreviewMode),
MenuItem::separator(),
checked("mark.look.focus", Box::new(look::FocusMode), look.focus),
checked(
"mark.look.typewriter",
Box::new(look::Typewriter),
look.typewriter,
),
MenuItem::separator(),
checked(
"mark.look.narrow",
Box::new(look::Narrow),
look.width == Width::Narrow,
),
checked(
"mark.look.medium",
Box::new(look::Medium),
look.width == Width::Medium,
),
checked(
"mark.look.wide",
Box::new(look::Wide),
look.width == Width::Wide,
),
MenuItem::separator(),
checked(
"mark.look.sans",
Box::new(look::Sans),
look.font == Font::Sans,
),
checked(
"mark.look.serif",
Box::new(look::Serif),
look.font == Font::Serif,
),
checked(
"mark.look.mono",
Box::new(look::Mono),
look.font == Font::Mono,
),
MenuItem::separator(),
item("mark.look.larger", Box::new(look::Larger)),
item("mark.look.smaller", Box::new(look::Smaller)),
item("mark.look.actual", Box::new(look::ActualSize)),
MenuItem::separator(),
item("mark.outside.check", Box::new(CheckDisk)),
]),
]
}