lib.rs

  1use gpui::{actions, impl_actions};
  2use serde::Deserialize;
  3
  4// If the zed binary doesn't use anything in this crate, it will be optimized away
  5// and the actions won't initialize. So we just provide an empty initialization function
  6// to be called from main.
  7//
  8// These may provide relevant context:
  9// https://github.com/rust-lang/rust/issues/47384
 10// https://github.com/mmastrac/rust-ctor/issues/280
 11pub fn init() {}
 12
 13#[derive(Clone, PartialEq, Deserialize)]
 14pub struct OpenBrowser {
 15    pub url: String,
 16}
 17
 18#[derive(Clone, PartialEq, Deserialize)]
 19pub struct OpenZedUrl {
 20    pub url: String,
 21}
 22
 23impl_actions!(zed, [OpenBrowser, OpenZedUrl]);
 24
 25actions!(
 26    zed,
 27    [
 28        OpenSettings,
 29        OpenDefaultKeymap,
 30        OpenAccountSettings,
 31        OpenServerSettings,
 32        Quit,
 33        OpenKeymap,
 34        About,
 35        Extensions,
 36        OpenLicenses,
 37        OpenTelemetryLog,
 38        DecreaseBufferFontSize,
 39        IncreaseBufferFontSize,
 40        ResetBufferFontSize,
 41        DecreaseUiFontSize,
 42        IncreaseUiFontSize,
 43        ResetUiFontSize
 44    ]
 45);
 46
 47pub mod branches {
 48    use gpui::actions;
 49
 50    actions!(branches, [OpenRecent]);
 51}
 52
 53pub mod command_palette {
 54    use gpui::actions;
 55
 56    actions!(command_palette, [Toggle]);
 57}
 58
 59pub mod feedback {
 60    use gpui::actions;
 61
 62    actions!(feedback, [GiveFeedback]);
 63}
 64
 65pub mod theme_selector {
 66    use gpui::impl_actions;
 67    use serde::Deserialize;
 68
 69    #[derive(PartialEq, Clone, Default, Debug, Deserialize)]
 70    pub struct Toggle {
 71        /// A list of theme names to filter the theme selector down to.
 72        pub themes_filter: Option<Vec<String>>,
 73    }
 74
 75    impl_actions!(theme_selector, [Toggle]);
 76}
 77
 78#[derive(Clone, Default, Deserialize, PartialEq)]
 79pub struct InlineAssist {
 80    pub prompt: Option<String>,
 81}
 82
 83impl_actions!(assistant, [InlineAssist]);
 84
 85#[derive(PartialEq, Clone, Deserialize, Default)]
 86pub struct OpenRecent {
 87    #[serde(default)]
 88    pub create_new_window: bool,
 89}
 90gpui::impl_actions!(projects, [OpenRecent]);
 91gpui::actions!(projects, [OpenRemote]);
 92
 93#[derive(PartialEq, Eq, Clone, Copy, Deserialize, Default, Debug)]
 94#[serde(rename_all = "snake_case")]
 95pub enum TaskSpawnTarget {
 96    Center,
 97    #[default]
 98    Dock,
 99}
100
101/// Spawn a task with name or open tasks modal
102#[derive(PartialEq, Clone, Deserialize, Default)]
103pub struct Spawn {
104    #[serde(default)]
105    /// Name of the task to spawn.
106    /// If it is not set, a modal with a list of available tasks is opened instead.
107    /// Defaults to None.
108    pub task_name: Option<String>,
109    /// Which part of the UI the task should be spawned in.
110    /// Defaults to Dock.
111    #[serde(default)]
112    pub target: Option<TaskSpawnTarget>,
113}
114
115impl Spawn {
116    pub fn modal() -> Self {
117        Self {
118            task_name: None,
119            target: None,
120        }
121    }
122}
123
124/// Rerun last task
125#[derive(PartialEq, Clone, Deserialize, Default)]
126pub struct Rerun {
127    /// Controls whether the task context is reevaluated prior to execution of a task.
128    /// If it is not, environment variables such as ZED_COLUMN, ZED_FILE are gonna be the same as in the last execution of a task
129    /// If it is, these variables will be updated to reflect current state of editor at the time task::Rerun is executed.
130    /// default: false
131    #[serde(default)]
132    pub reevaluate_context: bool,
133    /// Overrides `allow_concurrent_runs` property of the task being reran.
134    /// Default: null
135    #[serde(default)]
136    pub allow_concurrent_runs: Option<bool>,
137    /// Overrides `use_new_terminal` property of the task being reran.
138    /// Default: null
139    #[serde(default)]
140    pub use_new_terminal: Option<bool>,
141
142    /// If present, rerun the task with this ID, otherwise rerun the last task.
143    pub task_id: Option<String>,
144}
145
146impl_actions!(task, [Spawn, Rerun]);