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