Implement welcome view in zed2. (#3599)

Still needs styling.
This commit is contained in:
Max Brunsfeld
2023-12-11 14:54:03 -08:00
committed by GitHub
2 changed files with 159 additions and 184 deletions
+157 -181
View File
@@ -1,15 +1,16 @@
mod base_keymap_picker; mod base_keymap_picker;
mod base_keymap_setting; mod base_keymap_setting;
use client::TelemetrySettings;
use db::kvp::KEY_VALUE_STORE; use db::kvp::KEY_VALUE_STORE;
use gpui::{ use gpui::{
div, red, AnyElement, AppContext, Div, EventEmitter, FocusHandle, Focusable, FocusableView, div, svg, AnyElement, AppContext, Div, EventEmitter, FocusHandle, Focusable, FocusableView,
InteractiveElement, ParentElement, Render, Styled, Subscription, View, ViewContext, InteractiveElement, ParentElement, Render, Styled, Subscription, View, ViewContext,
VisualContext, WeakView, WindowContext, VisualContext, WeakView, WindowContext,
}; };
use settings::{Settings, SettingsStore}; use settings::{Settings, SettingsStore};
use std::sync::Arc; use std::sync::Arc;
use ui::prelude::*; use ui::{prelude::*, Checkbox};
use workspace::{ use workspace::{
dock::DockPosition, dock::DockPosition,
item::{Item, ItemEvent}, item::{Item, ItemEvent},
@@ -34,7 +35,7 @@ pub fn init(cx: &mut AppContext) {
base_keymap_picker::init(cx); base_keymap_picker::init(cx);
} }
pub fn show_welcome_experience(app_state: &Arc<AppState>, cx: &mut AppContext) { pub fn show_welcome_view(app_state: &Arc<AppState>, cx: &mut AppContext) {
open_new(&app_state, cx, |workspace, cx| { open_new(&app_state, cx, |workspace, cx| {
workspace.toggle_dock(DockPosition::Left, cx); workspace.toggle_dock(DockPosition::Left, cx);
let welcome_page = cx.build_view(|cx| WelcomePage::new(workspace, cx)); let welcome_page = cx.build_view(|cx| WelcomePage::new(workspace, cx));
@@ -58,186 +59,140 @@ pub struct WelcomePage {
impl Render for WelcomePage { impl Render for WelcomePage {
type Element = Focusable<Div>; type Element = Focusable<Div>;
fn render(&mut self, _cx: &mut gpui::ViewContext<Self>) -> Self::Element { fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> Self::Element {
// todo!(welcome_ui)
// let self_handle = cx.handle();
// let theme = cx.theme();
// let width = theme.welcome.page_width;
// let telemetry_settings = TelemetrySettings::get(None, cx);
// let vim_mode_setting = VimModeSettings::get(cx);
div() div()
.full()
.track_focus(&self.focus_handle) .track_focus(&self.focus_handle)
.child(div().size_full().bg(red()).child("Welcome!")) .relative()
//todo!() .child(
// PaneBackdrop::new( v_stack()
// self_handle.id(), .w_96()
// Flex::column() .mx_auto()
// .with_child( .child(
// Flex::column() svg()
// .with_child( .path("icons/logo_96.svg")
// theme::ui::svg(&theme.welcome.logo) .text_color(gpui::white())
// .aligned() .w(px(96.))
// .contained() .h(px(96.))
// .aligned(), .mx_auto(),
// ) )
// .with_child( .child(Label::new("Code at the speed of thought"))
// Label::new( .child(
// "Code at the speed of thought", Button::new("choose-theme", "Choose a theme")
// theme.welcome.logo_subheading.text.clone(), .full_width()
// ) .on_click(cx.listener(|this, _, cx| {
// .aligned() this.workspace
// .contained() .update(cx, |workspace, cx| {
// .with_style(theme.welcome.logo_subheading.container), theme_selector::toggle(workspace, &Default::default(), cx)
// ) })
// .contained() .ok();
// .with_style(theme.welcome.heading_group) })),
// .constrained() )
// .with_width(width), .child(
// ) Button::new("choose-keymap", "Choose a keymap")
// .with_child( .full_width()
// Flex::column() .on_click(cx.listener(|this, _, cx| {
// .with_child(theme::ui::cta_button::<theme_selector::Toggle, _, _, _>( this.workspace
// "Choose a theme", .update(cx, |workspace, cx| {
// width, base_keymap_picker::toggle(
// &theme.welcome.button, workspace,
// cx, &Default::default(),
// |_, this, cx| { cx,
// if let Some(workspace) = this.workspace.upgrade(cx) { )
// workspace.update(cx, |workspace, cx| { })
// theme_selector::toggle(workspace, &Default::default(), cx) .ok();
// }) })),
// } )
// }, .child(
// )) Button::new("install-cli", "Install the CLI")
// .with_child(theme::ui::cta_button::<ToggleBaseKeymapSelector, _, _, _>( .full_width()
// "Choose a keymap", .on_click(cx.listener(|_, _, cx| {
// width, cx.app_mut()
// &theme.welcome.button, .spawn(|cx| async move { install_cli::install_cli(&cx).await })
// cx, .detach_and_log_err(cx);
// |_, this, cx| { })),
// if let Some(workspace) = this.workspace.upgrade(cx) { )
// workspace.update(cx, |workspace, cx| { .child(
// base_keymap_picker::toggle( v_stack()
// workspace, .bg(cx.theme().colors().elevated_surface_background)
// &Default::default(), .child(
// cx, // todo!("vim setting")
// ) h_stack()
// }) .child(
// } Checkbox::new(
// }, "enable-vim",
// )) if false
// .with_child(theme::ui::cta_button::<install_cli::Install, _, _, _>( /* VimSettings::get_global(cx).enabled */
// "Install the CLI", {
// width, ui::Selection::Selected
// &theme.welcome.button, } else {
// cx, ui::Selection::Unselected
// |_, _, cx| { },
// cx.app_context() ),
// .spawn(|cx| async move { install_cli::install_cli(&cx).await }) // .on_click(cx.listener(
// .detach_and_log_err(cx); // move |this, selection, cx| {
// }, // this.update_settings::<VimSettings>(
// )) // selection,
// .contained() // cx,
// .with_style(theme.welcome.button_group) // |settings, value| settings.enabled = value,
// .constrained() // );
// .with_width(width), // },
// ) // )),
// .with_child( )
// Flex::column() .child("Enable vim mode"),
// .with_child( )
// theme::ui::checkbox::<Diagnostics, Self, _>( .child(
// "Enable vim mode", h_stack()
// &theme.welcome.checkbox, .child(
// vim_mode_setting, Checkbox::new(
// 0, "enable-telemetry",
// cx, if TelemetrySettings::get_global(cx).metrics {
// |this, checked, cx| { ui::Selection::Selected
// if let Some(workspace) = this.workspace.upgrade(cx) { } else {
// let fs = workspace.read(cx).app_state().fs.clone(); ui::Selection::Unselected
// update_settings_file::<VimModeSetting>( },
// fs, )
// cx, .on_click(
// move |setting| *setting = Some(checked), cx.listener(move |this, selection, cx| {
// ) this.update_settings::<TelemetrySettings>(
// } selection,
// }, cx,
// ) |settings, value| {
// .contained() settings.metrics = Some(value)
// .with_style(theme.welcome.checkbox_container), },
// ) );
// .with_child( }),
// theme::ui::checkbox_with_label::<Metrics, _, Self, _>( ),
// Flex::column() )
// .with_child( .child("Send usage data"),
// Label::new( )
// "Send anonymous usage data", .child(
// theme.welcome.checkbox.label.text.clone(), h_stack()
// ) .child(
// .contained() Checkbox::new(
// .with_style(theme.welcome.checkbox.label.container), "enable-crash",
// ) if TelemetrySettings::get_global(cx).diagnostics {
// .with_child( ui::Selection::Selected
// Label::new( } else {
// "Help > View Telemetry", ui::Selection::Unselected
// theme.welcome.usage_note.text.clone(), },
// ) )
// .contained() .on_click(
// .with_style(theme.welcome.usage_note.container), cx.listener(move |this, selection, cx| {
// ), this.update_settings::<TelemetrySettings>(
// &theme.welcome.checkbox, selection,
// telemetry_settings.metrics, cx,
// 0, |settings, value| {
// cx, settings.diagnostics = Some(value)
// |this, checked, cx| { },
// if let Some(workspace) = this.workspace.upgrade(cx) { );
// let fs = workspace.read(cx).app_state().fs.clone(); }),
// update_settings_file::<TelemetrySettings>( ),
// fs, )
// cx, .child("Send crash reports"),
// move |setting| setting.metrics = Some(checked), ),
// ) ),
// } )
// },
// )
// .contained()
// .with_style(theme.welcome.checkbox_container),
// )
// .with_child(
// theme::ui::checkbox::<Diagnostics, Self, _>(
// "Send crash reports",
// &theme.welcome.checkbox,
// telemetry_settings.diagnostics,
// 1,
// cx,
// |this, checked, cx| {
// if let Some(workspace) = this.workspace.upgrade(cx) {
// let fs = workspace.read(cx).app_state().fs.clone();
// update_settings_file::<TelemetrySettings>(
// fs,
// cx,
// move |setting| setting.diagnostics = Some(checked),
// )
// }
// },
// )
// .contained()
// .with_style(theme.welcome.checkbox_container),
// )
// .contained()
// .with_style(theme.welcome.checkbox_group)
// .constrained()
// .with_width(width),
// )
// .constrained()
// .with_max_width(width)
// .contained()
// .with_uniform_padding(10.)
// .aligned()
// .into_any(),
// )
// .into_any_named("welcome page")
} }
} }
@@ -249,6 +204,27 @@ impl WelcomePage {
_settings_subscription: cx.observe_global::<SettingsStore>(move |_, cx| cx.notify()), _settings_subscription: cx.observe_global::<SettingsStore>(move |_, cx| cx.notify()),
} }
} }
fn update_settings<T: Settings>(
&mut self,
selection: &Selection,
cx: &mut ViewContext<Self>,
callback: impl 'static + Send + Fn(&mut T::FileContent, bool),
) {
if let Some(workspace) = self.workspace.upgrade() {
let fs = workspace.read(cx).app_state().fs.clone();
let selection = *selection;
settings::update_settings_file::<T>(fs, cx, move |settings| {
let value = match selection {
Selection::Unselected => false,
Selection::Selected => true,
_ => return,
};
callback(settings, value)
});
}
}
} }
impl EventEmitter<ItemEvent> for WelcomePage {} impl EventEmitter<ItemEvent> for WelcomePage {}
+2 -3
View File
@@ -47,7 +47,7 @@ use util::{
paths, ResultExt, paths, ResultExt,
}; };
use uuid::Uuid; use uuid::Uuid;
use welcome::{show_welcome_experience, FIRST_OPEN}; use welcome::{show_welcome_view, FIRST_OPEN};
use workspace::{AppState, WorkspaceStore}; use workspace::{AppState, WorkspaceStore};
use zed2::{ use zed2::{
app_menus, build_window_options, ensure_only_instance, handle_cli_connection, app_menus, build_window_options, ensure_only_instance, handle_cli_connection,
@@ -366,8 +366,7 @@ async fn restore_or_create_workspace(app_state: &Arc<AppState>, mut cx: AsyncApp
.await .await
.log_err(); .log_err();
} else if matches!(KEY_VALUE_STORE.read_kvp(FIRST_OPEN), Ok(None)) { } else if matches!(KEY_VALUE_STORE.read_kvp(FIRST_OPEN), Ok(None)) {
cx.update(|cx| show_welcome_experience(app_state, cx)) cx.update(|cx| show_welcome_view(app_state, cx)).log_err();
.log_err();
} else { } else {
cx.update(|cx| { cx.update(|cx| {
workspace::open_new(app_state, cx, |workspace, cx| { workspace::open_new(app_state, cx, |workspace, cx| {