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)]
15pub struct OpenBrowser {
16 pub url: String,
17}
18
19#[derive(Clone, PartialEq, Deserialize, JsonSchema)]
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 schemars::JsonSchema;
69 use serde::Deserialize;
70
71 #[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema)]
72 pub struct Toggle {
73 /// A list of theme names to filter the theme selector down to.
74 pub themes_filter: Option<Vec<String>>,
75 }
76
77 impl_actions!(theme_selector, [Toggle]);
78}
79
80pub mod icon_theme_selector {
81 use gpui::impl_actions;
82 use schemars::JsonSchema;
83 use serde::Deserialize;
84
85 #[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema)]
86 pub struct Toggle {
87 /// A list of icon theme names to filter the theme selector down to.
88 pub themes_filter: Option<Vec<String>>,
89 }
90
91 impl_actions!(icon_theme_selector, [Toggle]);
92}
93
94pub mod assistant {
95 use gpui::{actions, impl_actions};
96 use schemars::JsonSchema;
97 use serde::Deserialize;
98
99 actions!(assistant, [ToggleFocus, DeployPromptLibrary]);
100
101 #[derive(Clone, Default, Deserialize, PartialEq, JsonSchema)]
102 pub struct InlineAssist {
103 pub prompt: Option<String>,
104 }
105
106 impl_actions!(assistant, [InlineAssist]);
107}
108
109#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
110pub struct OpenRecent {
111 #[serde(default)]
112 pub create_new_window: bool,
113}
114
115impl_actions!(projects, [OpenRecent]);
116actions!(projects, [OpenRemote]);
117
118/// Where to spawn the task in the UI.
119#[derive(Default, Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
120#[serde(rename_all = "snake_case")]
121pub enum RevealTarget {
122 /// In the central pane group, "main" editor area.
123 Center,
124 /// In the terminal dock, "regular" terminal items' place.
125 #[default]
126 Dock,
127}
128
129/// Spawn a task with name or open tasks modal.
130#[derive(Debug, PartialEq, Clone, Deserialize, JsonSchema)]
131#[serde(untagged)]
132pub enum Spawn {
133 /// Spawns a task by the name given.
134 ByName {
135 task_name: String,
136 #[serde(default)]
137 reveal_target: Option<RevealTarget>,
138 },
139 /// Spawns a task via modal's selection.
140 ViaModal {
141 /// Selected task's `reveal_target` property override.
142 #[serde(default)]
143 reveal_target: Option<RevealTarget>,
144 },
145}
146
147impl Spawn {
148 pub fn modal() -> Self {
149 Self::ViaModal {
150 reveal_target: None,
151 }
152 }
153}
154
155/// Rerun the last task.
156#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
157pub struct Rerun {
158 /// Controls whether the task context is reevaluated prior to execution of a task.
159 /// 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
160 /// If it is, these variables will be updated to reflect current state of editor at the time task::Rerun is executed.
161 /// default: false
162 #[serde(default)]
163 pub reevaluate_context: bool,
164 /// Overrides `allow_concurrent_runs` property of the task being reran.
165 /// Default: null
166 #[serde(default)]
167 pub allow_concurrent_runs: Option<bool>,
168 /// Overrides `use_new_terminal` property of the task being reran.
169 /// Default: null
170 #[serde(default)]
171 pub use_new_terminal: Option<bool>,
172
173 /// If present, rerun the task with this ID, otherwise rerun the last task.
174 #[serde(skip)]
175 pub task_id: Option<String>,
176}
177
178impl_actions!(task, [Spawn, Rerun]);
179
180pub mod outline {
181 use std::sync::OnceLock;
182
183 use gpui::{action_as, AnyView, App, Window};
184
185 action_as!(outline, ToggleOutline as Toggle);
186 /// A pointer to outline::toggle function, exposed here to sewer the breadcrumbs <-> outline dependency.
187 pub static TOGGLE_OUTLINE: OnceLock<fn(AnyView, &mut Window, &mut App)> = OnceLock::new();
188}