Skip to main content

gitkraft_gui/features/
editor.rs

1//! Editor selector widget for the header toolbar.
2//!
3//! Provides a [`pick_list()`] drop-down that lets the user switch between
4//! all supported editors defined in `gitkraft_core` at runtime.
5
6use iced::widget::pick_list;
7use iced::{Element, Length};
8
9use crate::message::Message;
10
11/// All editor variants (including `None`) for the pick list.
12fn all_editors() -> Vec<gitkraft_core::Editor> {
13    use gitkraft_core::Editor;
14    vec![
15        Editor::None,
16        Editor::Helix,
17        Editor::Neovim,
18        Editor::Vim,
19        Editor::Nano,
20        Editor::Micro,
21        Editor::Emacs,
22        Editor::VSCode,
23        Editor::Zed,
24        Editor::Sublime,
25        Editor::RustRover,
26        Editor::IntelliJIdea,
27        Editor::WebStorm,
28        Editor::PyCharm,
29        Editor::GoLand,
30        Editor::CLion,
31        Editor::Fleet,
32        Editor::AndroidStudio,
33    ]
34}
35
36/// Create an editor selector [`pick_list()`] widget.
37///
38/// The widget displays the name of the current editor and, when opened, lists
39/// every editor returned by `all_editors`. Selecting a new entry emits
40/// [`Message::EditorChanged`] with the chosen [`gitkraft_core::Editor`].
41pub fn editor_selector(current: &gitkraft_core::Editor) -> Element<'static, Message> {
42    let choices = all_editors();
43    let selected = choices.iter().find(|e| *e == current).cloned();
44
45    pick_list(choices, selected, Message::EditorChanged)
46        .placeholder("Select editor")
47        .text_size(13.0)
48        .width(Length::Fixed(160.0))
49        .into()
50}