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, JsonSchema)]
15#[serde(deny_unknown_fields)]
16pub struct OpenBrowser {
17 pub url: String,
18}
19
20#[derive(Clone, PartialEq, Deserialize, JsonSchema)]
21#[serde(deny_unknown_fields)]
22pub struct OpenZedUrl {
23 pub url: String,
24}
25
26impl_actions!(zed, [OpenBrowser, OpenZedUrl]);
27
28actions!(
29 zed,
30 [
31 OpenSettings,
32 OpenDefaultKeymap,
33 OpenAccountSettings,
34 OpenServerSettings,
35 Quit,
36 OpenKeymap,
37 About,
38 OpenLicenses,
39 OpenTelemetryLog,
40 ]
41);
42
43#[derive(PartialEq, Clone, Copy, Debug, Deserialize, JsonSchema)]
44#[serde(rename_all = "snake_case")]
45pub enum ExtensionCategoryFilter {
46 Themes,
47 IconThemes,
48 Languages,
49 Grammars,
50 LanguageServers,
51 ContextServers,
52 SlashCommands,
53 IndexedDocsProviders,
54 Snippets,
55}
56
57#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema)]
58pub struct Extensions {
59 /// Filters the extensions page down to extensions that are in the specified category.
60 #[serde(default)]
61 pub category_filter: Option<ExtensionCategoryFilter>,
62}
63
64#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema)]
65pub struct DecreaseBufferFontSize {
66 #[serde(default)]
67 pub persist: bool,
68}
69
70#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema)]
71pub struct IncreaseBufferFontSize {
72 #[serde(default)]
73 pub persist: bool,
74}
75
76#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema)]
77pub struct ResetBufferFontSize {
78 #[serde(default)]
79 pub persist: bool,
80}
81
82#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema)]
83pub struct DecreaseUiFontSize {
84 #[serde(default)]
85 pub persist: bool,
86}
87
88#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema)]
89pub struct IncreaseUiFontSize {
90 #[serde(default)]
91 pub persist: bool,
92}
93
94#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema)]
95pub struct ResetUiFontSize {
96 #[serde(default)]
97 pub persist: bool,
98}
99
100impl_actions!(
101 zed,
102 [
103 Extensions,
104 DecreaseBufferFontSize,
105 IncreaseBufferFontSize,
106 ResetBufferFontSize,
107 DecreaseUiFontSize,
108 IncreaseUiFontSize,
109 ResetUiFontSize,
110 ]
111);
112
113pub mod workspace {
114 use gpui::action_with_deprecated_aliases;
115
116 action_with_deprecated_aliases!(
117 workspace,
118 CopyPath,
119 [
120 "editor::CopyPath",
121 "outline_panel::CopyPath",
122 "project_panel::CopyPath"
123 ]
124 );
125
126 action_with_deprecated_aliases!(
127 workspace,
128 CopyRelativePath,
129 [
130 "editor::CopyRelativePath",
131 "outline_panel::CopyRelativePath",
132 "project_panel::CopyRelativePath"
133 ]
134 );
135}
136
137pub mod git {
138 use gpui::{action_with_deprecated_aliases, actions};
139
140 actions!(git, [CheckoutBranch, Switch, SelectRepo]);
141 action_with_deprecated_aliases!(git, Branch, ["branches::OpenRecent"]);
142}
143
144pub mod command_palette {
145 use gpui::actions;
146
147 actions!(command_palette, [Toggle]);
148}
149
150pub mod feedback {
151 use gpui::actions;
152
153 actions!(feedback, [GiveFeedback]);
154}
155
156pub mod theme_selector {
157 use gpui::impl_actions;
158 use schemars::JsonSchema;
159 use serde::Deserialize;
160
161 #[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema)]
162 #[serde(deny_unknown_fields)]
163 pub struct Toggle {
164 /// A list of theme names to filter the theme selector down to.
165 pub themes_filter: Option<Vec<String>>,
166 }
167
168 impl_actions!(theme_selector, [Toggle]);
169}
170
171pub mod icon_theme_selector {
172 use gpui::impl_actions;
173 use schemars::JsonSchema;
174 use serde::Deserialize;
175
176 #[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema)]
177 #[serde(deny_unknown_fields)]
178 pub struct Toggle {
179 /// A list of icon theme names to filter the theme selector down to.
180 pub themes_filter: Option<Vec<String>>,
181 }
182
183 impl_actions!(icon_theme_selector, [Toggle]);
184}
185
186pub mod assistant {
187 use gpui::{actions, impl_actions};
188 use schemars::JsonSchema;
189 use serde::Deserialize;
190
191 actions!(assistant, [ToggleFocus, OpenPromptLibrary]);
192
193 #[derive(Clone, Default, Deserialize, PartialEq, JsonSchema)]
194 #[serde(deny_unknown_fields)]
195 pub struct InlineAssist {
196 pub prompt: Option<String>,
197 }
198
199 impl_actions!(assistant, [InlineAssist]);
200}
201
202#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
203#[serde(deny_unknown_fields)]
204pub struct OpenRecent {
205 #[serde(default)]
206 pub create_new_window: bool,
207}
208
209impl_actions!(projects, [OpenRecent]);
210actions!(projects, [OpenRemote]);
211
212/// Where to spawn the task in the UI.
213#[derive(Default, Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
214#[serde(rename_all = "snake_case")]
215pub enum RevealTarget {
216 /// In the central pane group, "main" editor area.
217 Center,
218 /// In the terminal dock, "regular" terminal items' place.
219 #[default]
220 Dock,
221}
222
223/// Spawn a task with name or open tasks modal.
224#[derive(Debug, PartialEq, Clone, Deserialize, JsonSchema)]
225#[serde(untagged)]
226pub enum Spawn {
227 /// Spawns a task by the name given.
228 ByName {
229 task_name: String,
230 #[serde(default)]
231 reveal_target: Option<RevealTarget>,
232 },
233 /// Spawns a task via modal's selection.
234 ViaModal {
235 /// Selected task's `reveal_target` property override.
236 #[serde(default)]
237 reveal_target: Option<RevealTarget>,
238 },
239}
240
241impl Spawn {
242 pub fn modal() -> Self {
243 Self::ViaModal {
244 reveal_target: None,
245 }
246 }
247}
248
249/// Rerun the last task.
250#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
251#[serde(deny_unknown_fields)]
252pub struct Rerun {
253 /// Controls whether the task context is reevaluated prior to execution of a task.
254 /// 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
255 /// If it is, these variables will be updated to reflect current state of editor at the time task::Rerun is executed.
256 /// default: false
257 #[serde(default)]
258 pub reevaluate_context: bool,
259 /// Overrides `allow_concurrent_runs` property of the task being reran.
260 /// Default: null
261 #[serde(default)]
262 pub allow_concurrent_runs: Option<bool>,
263 /// Overrides `use_new_terminal` property of the task being reran.
264 /// Default: null
265 #[serde(default)]
266 pub use_new_terminal: Option<bool>,
267
268 /// If present, rerun the task with this ID, otherwise rerun the last task.
269 #[serde(skip)]
270 pub task_id: Option<String>,
271}
272
273impl_actions!(task, [Spawn, Rerun]);
274
275pub mod outline {
276 use std::sync::OnceLock;
277
278 use gpui::{AnyView, App, Window, action_as};
279
280 action_as!(outline, ToggleOutline as Toggle);
281 /// A pointer to outline::toggle function, exposed here to sewer the breadcrumbs <-> outline dependency.
282 pub static TOGGLE_OUTLINE: OnceLock<fn(AnyView, &mut Window, &mut App)> = OnceLock::new();
283}
284
285actions!(zed_predict_onboarding, [OpenZedPredictOnboarding]);
286actions!(git_onboarding, [OpenGitIntegrationOnboarding]);