1use gpui::{actions, impl_actions};
2use schemars::JsonSchema;
3use serde::{Deserialize, Serialize};
4
5// If the zed binary doesn't use anything in this crate, it will be optimized away
6// and the actions won't initialize. So we just provide an empty initialization function
7// to be called from main.
8//
9// These may provide relevant context:
10// https://github.com/rust-lang/rust/issues/47384
11// https://github.com/mmastrac/rust-ctor/issues/280
12pub fn init() {}
13
14#[derive(Clone, PartialEq, Deserialize)]
15pub struct OpenBrowser {
16 pub url: String,
17}
18
19#[derive(Clone, PartialEq, Deserialize)]
20pub struct OpenZedUrl {
21 pub url: String,
22}
23
24impl_actions!(zed, [OpenBrowser, OpenZedUrl]);
25
26actions!(
27 zed,
28 [
29 OpenSettings,
30 OpenDefaultKeymap,
31 OpenAccountSettings,
32 OpenServerSettings,
33 Quit,
34 OpenKeymap,
35 About,
36 Extensions,
37 OpenLicenses,
38 OpenTelemetryLog,
39 DecreaseBufferFontSize,
40 IncreaseBufferFontSize,
41 ResetBufferFontSize,
42 DecreaseUiFontSize,
43 IncreaseUiFontSize,
44 ResetUiFontSize
45 ]
46);
47
48pub mod branches {
49 use gpui::actions;
50
51 actions!(branches, [OpenRecent]);
52}
53
54pub mod command_palette {
55 use gpui::actions;
56
57 actions!(command_palette, [Toggle]);
58}
59
60pub mod feedback {
61 use gpui::actions;
62
63 actions!(feedback, [GiveFeedback]);
64}
65
66pub mod theme_selector {
67 use gpui::impl_actions;
68 use serde::Deserialize;
69
70 #[derive(PartialEq, Clone, Default, Debug, Deserialize)]
71 pub struct Toggle {
72 /// A list of theme names to filter the theme selector down to.
73 pub themes_filter: Option<Vec<String>>,
74 }
75
76 impl_actions!(theme_selector, [Toggle]);
77}
78
79#[derive(Clone, Default, Deserialize, PartialEq)]
80pub struct InlineAssist {
81 pub prompt: Option<String>,
82}
83
84impl_actions!(assistant, [InlineAssist]);
85
86#[derive(PartialEq, Clone, Deserialize, Default)]
87pub struct OpenRecent {
88 #[serde(default)]
89 pub create_new_window: bool,
90}
91gpui::impl_actions!(projects, [OpenRecent]);
92gpui::actions!(projects, [OpenRemote]);
93
94/// Where to spawn the task in the UI.
95#[derive(Default, Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
96#[serde(rename_all = "snake_case")]
97pub enum RevealTarget {
98 /// In the central pane group, "main" editor area.
99 Center,
100 /// In the terminal dock, "regular" terminal items' place.
101 #[default]
102 Dock,
103}
104
105/// Spawn a task with name or open tasks modal
106#[derive(Debug, PartialEq, Clone, Deserialize)]
107#[serde(untagged)]
108pub enum Spawn {
109 /// Spawns a task by the name given.
110 ByName {
111 task_name: String,
112 #[serde(default)]
113 reveal_target: Option<RevealTarget>,
114 },
115 /// Spawns a task via modal's selection.
116 ViaModal {
117 /// Selected task's `reveal_target` property override.
118 #[serde(default)]
119 reveal_target: Option<RevealTarget>,
120 },
121}
122
123impl Spawn {
124 pub fn modal() -> Self {
125 Self::ViaModal {
126 reveal_target: None,
127 }
128 }
129}
130
131/// Rerun last task
132#[derive(PartialEq, Clone, Deserialize, Default)]
133pub struct Rerun {
134 /// Controls whether the task context is reevaluated prior to execution of a task.
135 /// 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
136 /// If it is, these variables will be updated to reflect current state of editor at the time task::Rerun is executed.
137 /// default: false
138 #[serde(default)]
139 pub reevaluate_context: bool,
140 /// Overrides `allow_concurrent_runs` property of the task being reran.
141 /// Default: null
142 #[serde(default)]
143 pub allow_concurrent_runs: Option<bool>,
144 /// Overrides `use_new_terminal` property of the task being reran.
145 /// Default: null
146 #[serde(default)]
147 pub use_new_terminal: Option<bool>,
148
149 /// If present, rerun the task with this ID, otherwise rerun the last task.
150 pub task_id: Option<String>,
151}
152
153impl_actions!(task, [Spawn, Rerun]);
154
155pub mod outline {
156 use std::sync::OnceLock;
157
158 use gpui::{action_as, AnyView, WindowContext};
159
160 action_as!(outline, ToggleOutline as Toggle);
161 /// A pointer to outline::toggle function, exposed here to sewer the breadcrumbs <-> outline dependency.
162 pub static TOGGLE_OUTLINE: OnceLock<fn(AnyView, &mut WindowContext<'_>)> = OnceLock::new();
163}