1mod base_keymap_picker;
2mod base_keymap_setting;
3
4use db::kvp::KEY_VALUE_STORE;
5use gpui::{
6 div, red, AnyElement, AppContext, Div, Element, EventEmitter, FocusHandle, Focusable,
7 FocusableView, InteractiveElement, ParentElement, Render, Styled, Subscription, View,
8 ViewContext, VisualContext, WeakView, WindowContext,
9};
10use settings::{Settings, SettingsStore};
11use std::sync::Arc;
12use workspace::{
13 dock::DockPosition,
14 item::{Item, ItemEvent},
15 open_new, AppState, Welcome, Workspace, WorkspaceId,
16};
17
18pub use base_keymap_setting::BaseKeymap;
19
20pub const FIRST_OPEN: &str = "first_open";
21
22pub fn init(cx: &mut AppContext) {
23 BaseKeymap::register(cx);
24
25 cx.observe_new_views(|workspace: &mut Workspace, _cx| {
26 workspace.register_action(|workspace, _: &Welcome, cx| {
27 let welcome_page = cx.build_view(|cx| WelcomePage::new(workspace, cx));
28 workspace.add_item(Box::new(welcome_page), cx)
29 });
30 })
31 .detach();
32
33 base_keymap_picker::init(cx);
34}
35
36pub fn show_welcome_experience(app_state: &Arc<AppState>, cx: &mut AppContext) {
37 open_new(&app_state, cx, |workspace, cx| {
38 workspace.toggle_dock(DockPosition::Left, cx);
39 let welcome_page = cx.build_view(|cx| WelcomePage::new(workspace, cx));
40 workspace.add_item_to_center(Box::new(welcome_page.clone()), cx);
41 cx.focus_view(&welcome_page);
42 cx.notify();
43 })
44 .detach();
45
46 db::write_and_log(cx, || {
47 KEY_VALUE_STORE.write_kvp(FIRST_OPEN.to_string(), "false".to_string())
48 });
49}
50
51pub struct WelcomePage {
52 workspace: WeakView<Workspace>,
53 focus_handle: FocusHandle,
54 _settings_subscription: Subscription,
55}
56
57impl Render for WelcomePage {
58 type Element = Focusable<Div>;
59
60 fn render(&mut self, _cx: &mut gpui::ViewContext<Self>) -> Self::Element {
61 // todo!(welcome_ui)
62 // let self_handle = cx.handle();
63 // let theme = cx.theme();
64 // let width = theme.welcome.page_width;
65
66 // let telemetry_settings = TelemetrySettings::get(None, cx);
67 // let vim_mode_setting = VimModeSettings::get(cx);
68
69 div()
70 .track_focus(&self.focus_handle)
71 .child(div().size_full().bg(red()).child("Welcome!"))
72 //todo!()
73 // PaneBackdrop::new(
74 // self_handle.id(),
75 // Flex::column()
76 // .with_child(
77 // Flex::column()
78 // .with_child(
79 // theme::ui::svg(&theme.welcome.logo)
80 // .aligned()
81 // .contained()
82 // .aligned(),
83 // )
84 // .with_child(
85 // Label::new(
86 // "Code at the speed of thought",
87 // theme.welcome.logo_subheading.text.clone(),
88 // )
89 // .aligned()
90 // .contained()
91 // .with_style(theme.welcome.logo_subheading.container),
92 // )
93 // .contained()
94 // .with_style(theme.welcome.heading_group)
95 // .constrained()
96 // .with_width(width),
97 // )
98 // .with_child(
99 // Flex::column()
100 // .with_child(theme::ui::cta_button::<theme_selector::Toggle, _, _, _>(
101 // "Choose a theme",
102 // width,
103 // &theme.welcome.button,
104 // cx,
105 // |_, this, cx| {
106 // if let Some(workspace) = this.workspace.upgrade(cx) {
107 // workspace.update(cx, |workspace, cx| {
108 // theme_selector::toggle(workspace, &Default::default(), cx)
109 // })
110 // }
111 // },
112 // ))
113 // .with_child(theme::ui::cta_button::<ToggleBaseKeymapSelector, _, _, _>(
114 // "Choose a keymap",
115 // width,
116 // &theme.welcome.button,
117 // cx,
118 // |_, this, cx| {
119 // if let Some(workspace) = this.workspace.upgrade(cx) {
120 // workspace.update(cx, |workspace, cx| {
121 // base_keymap_picker::toggle(
122 // workspace,
123 // &Default::default(),
124 // cx,
125 // )
126 // })
127 // }
128 // },
129 // ))
130 // .with_child(theme::ui::cta_button::<install_cli::Install, _, _, _>(
131 // "Install the CLI",
132 // width,
133 // &theme.welcome.button,
134 // cx,
135 // |_, _, cx| {
136 // cx.app_context()
137 // .spawn(|cx| async move { install_cli::install_cli(&cx).await })
138 // .detach_and_log_err(cx);
139 // },
140 // ))
141 // .contained()
142 // .with_style(theme.welcome.button_group)
143 // .constrained()
144 // .with_width(width),
145 // )
146 // .with_child(
147 // Flex::column()
148 // .with_child(
149 // theme::ui::checkbox::<Diagnostics, Self, _>(
150 // "Enable vim mode",
151 // &theme.welcome.checkbox,
152 // vim_mode_setting,
153 // 0,
154 // cx,
155 // |this, checked, cx| {
156 // if let Some(workspace) = this.workspace.upgrade(cx) {
157 // let fs = workspace.read(cx).app_state().fs.clone();
158 // update_settings_file::<VimModeSetting>(
159 // fs,
160 // cx,
161 // move |setting| *setting = Some(checked),
162 // )
163 // }
164 // },
165 // )
166 // .contained()
167 // .with_style(theme.welcome.checkbox_container),
168 // )
169 // .with_child(
170 // theme::ui::checkbox_with_label::<Metrics, _, Self, _>(
171 // Flex::column()
172 // .with_child(
173 // Label::new(
174 // "Send anonymous usage data",
175 // theme.welcome.checkbox.label.text.clone(),
176 // )
177 // .contained()
178 // .with_style(theme.welcome.checkbox.label.container),
179 // )
180 // .with_child(
181 // Label::new(
182 // "Help > View Telemetry",
183 // theme.welcome.usage_note.text.clone(),
184 // )
185 // .contained()
186 // .with_style(theme.welcome.usage_note.container),
187 // ),
188 // &theme.welcome.checkbox,
189 // telemetry_settings.metrics,
190 // 0,
191 // cx,
192 // |this, checked, cx| {
193 // if let Some(workspace) = this.workspace.upgrade(cx) {
194 // let fs = workspace.read(cx).app_state().fs.clone();
195 // update_settings_file::<TelemetrySettings>(
196 // fs,
197 // cx,
198 // move |setting| setting.metrics = Some(checked),
199 // )
200 // }
201 // },
202 // )
203 // .contained()
204 // .with_style(theme.welcome.checkbox_container),
205 // )
206 // .with_child(
207 // theme::ui::checkbox::<Diagnostics, Self, _>(
208 // "Send crash reports",
209 // &theme.welcome.checkbox,
210 // telemetry_settings.diagnostics,
211 // 1,
212 // cx,
213 // |this, checked, cx| {
214 // if let Some(workspace) = this.workspace.upgrade(cx) {
215 // let fs = workspace.read(cx).app_state().fs.clone();
216 // update_settings_file::<TelemetrySettings>(
217 // fs,
218 // cx,
219 // move |setting| setting.diagnostics = Some(checked),
220 // )
221 // }
222 // },
223 // )
224 // .contained()
225 // .with_style(theme.welcome.checkbox_container),
226 // )
227 // .contained()
228 // .with_style(theme.welcome.checkbox_group)
229 // .constrained()
230 // .with_width(width),
231 // )
232 // .constrained()
233 // .with_max_width(width)
234 // .contained()
235 // .with_uniform_padding(10.)
236 // .aligned()
237 // .into_any(),
238 // )
239 // .into_any_named("welcome page")
240 }
241}
242
243impl WelcomePage {
244 pub fn new(workspace: &Workspace, cx: &mut ViewContext<Self>) -> Self {
245 WelcomePage {
246 focus_handle: cx.focus_handle(),
247 workspace: workspace.weak_handle(),
248 _settings_subscription: cx.observe_global::<SettingsStore>(move |_, cx| cx.notify()),
249 }
250 }
251}
252
253impl EventEmitter<ItemEvent> for WelcomePage {}
254
255impl FocusableView for WelcomePage {
256 fn focus_handle(&self, _: &AppContext) -> gpui::FocusHandle {
257 self.focus_handle.clone()
258 }
259}
260
261impl Item for WelcomePage {
262 fn tab_content(&self, _: Option<usize>, _: &WindowContext) -> AnyElement {
263 "Welcome to Zed!".into_any()
264 }
265
266 fn show_toolbar(&self) -> bool {
267 false
268 }
269
270 fn clone_on_split(
271 &self,
272 _workspace_id: WorkspaceId,
273 cx: &mut ViewContext<Self>,
274 ) -> Option<View<Self>> {
275 Some(cx.build_view(|cx| WelcomePage {
276 focus_handle: cx.focus_handle(),
277 workspace: self.workspace.clone(),
278 _settings_subscription: cx.observe_global::<SettingsStore>(move |_, cx| cx.notify()),
279 }))
280 }
281}