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