onboarding: Show indication that settings have already been imported (#35615)
Co-Authored-By: Danilo <danilo@zed.dev> Co-Authored-By: Anthony <anthony@zed.dev> Release Notes: - N/A
This commit is contained in:
parent
e1d0e3fc34
commit
06226e1cbd
5 changed files with 192 additions and 90 deletions
|
@ -30,6 +30,7 @@ itertools.workspace = true
|
|||
language.workspace = true
|
||||
language_model.workspace = true
|
||||
menu.workspace = true
|
||||
notifications.workspace = true
|
||||
project.workspace = true
|
||||
schemars.workspace = true
|
||||
serde.workspace = true
|
||||
|
|
|
@ -12,7 +12,7 @@ use ui::{
|
|||
ToggleButtonGroupStyle, ToggleButtonSimple, ToggleState, Tooltip, prelude::*,
|
||||
};
|
||||
|
||||
use crate::{ImportCursorSettings, ImportVsCodeSettings};
|
||||
use crate::{ImportCursorSettings, ImportVsCodeSettings, SettingsImportState};
|
||||
|
||||
fn read_show_mini_map(cx: &App) -> ShowMinimap {
|
||||
editor::EditorSettings::get_global(cx).minimap.show
|
||||
|
@ -165,7 +165,71 @@ fn write_format_on_save(format_on_save: bool, cx: &mut App) {
|
|||
});
|
||||
}
|
||||
|
||||
fn render_import_settings_section() -> impl IntoElement {
|
||||
fn render_setting_import_button(
|
||||
label: SharedString,
|
||||
icon_name: IconName,
|
||||
action: &dyn Action,
|
||||
imported: bool,
|
||||
) -> impl IntoElement {
|
||||
let action = action.boxed_clone();
|
||||
h_flex().w_full().child(
|
||||
ButtonLike::new(label.clone())
|
||||
.full_width()
|
||||
.style(ButtonStyle::Outlined)
|
||||
.size(ButtonSize::Large)
|
||||
.child(
|
||||
h_flex()
|
||||
.w_full()
|
||||
.justify_between()
|
||||
.child(
|
||||
h_flex()
|
||||
.gap_1p5()
|
||||
.px_1()
|
||||
.child(
|
||||
Icon::new(icon_name)
|
||||
.color(Color::Muted)
|
||||
.size(IconSize::XSmall),
|
||||
)
|
||||
.child(Label::new(label)),
|
||||
)
|
||||
.when(imported, |this| {
|
||||
this.child(
|
||||
h_flex()
|
||||
.gap_1p5()
|
||||
.child(
|
||||
Icon::new(IconName::Check)
|
||||
.color(Color::Success)
|
||||
.size(IconSize::XSmall),
|
||||
)
|
||||
.child(Label::new("Imported").size(LabelSize::Small)),
|
||||
)
|
||||
}),
|
||||
)
|
||||
.on_click(move |_, window, cx| window.dispatch_action(action.boxed_clone(), cx)),
|
||||
)
|
||||
}
|
||||
|
||||
fn render_import_settings_section(cx: &App) -> impl IntoElement {
|
||||
let import_state = SettingsImportState::global(cx);
|
||||
let imports: [(SharedString, IconName, &dyn Action, bool); 2] = [
|
||||
(
|
||||
"VS Code".into(),
|
||||
IconName::EditorVsCode,
|
||||
&ImportVsCodeSettings { skip_prompt: false },
|
||||
import_state.vscode,
|
||||
),
|
||||
(
|
||||
"Cursor".into(),
|
||||
IconName::EditorCursor,
|
||||
&ImportCursorSettings { skip_prompt: false },
|
||||
import_state.cursor,
|
||||
),
|
||||
];
|
||||
|
||||
let [vscode, cursor] = imports.map(|(label, icon_name, action, imported)| {
|
||||
render_setting_import_button(label, icon_name, action, imported)
|
||||
});
|
||||
|
||||
v_flex()
|
||||
.gap_4()
|
||||
.child(
|
||||
|
@ -176,63 +240,7 @@ fn render_import_settings_section() -> impl IntoElement {
|
|||
.color(Color::Muted),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
h_flex()
|
||||
.w_full()
|
||||
.gap_4()
|
||||
.child(
|
||||
h_flex().w_full().child(
|
||||
ButtonLike::new("import_vs_code")
|
||||
.full_width()
|
||||
.style(ButtonStyle::Outlined)
|
||||
.size(ButtonSize::Large)
|
||||
.child(
|
||||
h_flex()
|
||||
.w_full()
|
||||
.gap_1p5()
|
||||
.px_1()
|
||||
.child(
|
||||
Icon::new(IconName::EditorVsCode)
|
||||
.color(Color::Muted)
|
||||
.size(IconSize::XSmall),
|
||||
)
|
||||
.child(Label::new("VS Code")),
|
||||
)
|
||||
.on_click(|_, window, cx| {
|
||||
window.dispatch_action(
|
||||
ImportVsCodeSettings::default().boxed_clone(),
|
||||
cx,
|
||||
)
|
||||
}),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
h_flex().w_full().child(
|
||||
ButtonLike::new("import_cursor")
|
||||
.full_width()
|
||||
.style(ButtonStyle::Outlined)
|
||||
.size(ButtonSize::Large)
|
||||
.child(
|
||||
h_flex()
|
||||
.w_full()
|
||||
.gap_1p5()
|
||||
.px_1()
|
||||
.child(
|
||||
Icon::new(IconName::EditorCursor)
|
||||
.color(Color::Muted)
|
||||
.size(IconSize::XSmall),
|
||||
)
|
||||
.child(Label::new("Cursor")),
|
||||
)
|
||||
.on_click(|_, window, cx| {
|
||||
window.dispatch_action(
|
||||
ImportCursorSettings::default().boxed_clone(),
|
||||
cx,
|
||||
)
|
||||
}),
|
||||
),
|
||||
),
|
||||
)
|
||||
.child(h_flex().w_full().gap_4().child(vscode).child(cursor))
|
||||
}
|
||||
|
||||
fn render_font_customization_section(window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
|
@ -457,6 +465,6 @@ fn render_popular_settings_section(window: &mut Window, cx: &mut App) -> impl In
|
|||
pub(crate) fn render_editing_page(window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
v_flex()
|
||||
.gap_4()
|
||||
.child(render_import_settings_section())
|
||||
.child(render_import_settings_section(cx))
|
||||
.child(render_popular_settings_section(window, cx))
|
||||
}
|
||||
|
|
|
@ -6,9 +6,10 @@ use feature_flags::{FeatureFlag, FeatureFlagViewExt as _};
|
|||
use fs::Fs;
|
||||
use gpui::{
|
||||
Action, AnyElement, App, AppContext, AsyncWindowContext, Context, Entity, EventEmitter,
|
||||
FocusHandle, Focusable, IntoElement, KeyContext, Render, SharedString, Subscription, Task,
|
||||
WeakEntity, Window, actions,
|
||||
FocusHandle, Focusable, Global, IntoElement, KeyContext, Render, SharedString, Subscription,
|
||||
Task, WeakEntity, Window, actions,
|
||||
};
|
||||
use notifications::status_toast::{StatusToast, ToastIcon};
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
use settings::{SettingsStore, VsCodeSettingsSource};
|
||||
|
@ -137,9 +138,12 @@ pub fn init(cx: &mut App) {
|
|||
let fs = <dyn Fs>::global(cx);
|
||||
let action = *action;
|
||||
|
||||
let workspace = cx.weak_entity();
|
||||
|
||||
window
|
||||
.spawn(cx, async move |cx: &mut AsyncWindowContext| {
|
||||
handle_import_vscode_settings(
|
||||
workspace,
|
||||
VsCodeSettingsSource::VsCode,
|
||||
action.skip_prompt,
|
||||
fs,
|
||||
|
@ -154,9 +158,12 @@ pub fn init(cx: &mut App) {
|
|||
let fs = <dyn Fs>::global(cx);
|
||||
let action = *action;
|
||||
|
||||
let workspace = cx.weak_entity();
|
||||
|
||||
window
|
||||
.spawn(cx, async move |cx: &mut AsyncWindowContext| {
|
||||
handle_import_vscode_settings(
|
||||
workspace,
|
||||
VsCodeSettingsSource::Cursor,
|
||||
action.skip_prompt,
|
||||
fs,
|
||||
|
@ -555,6 +562,7 @@ impl Item for Onboarding {
|
|||
}
|
||||
|
||||
pub async fn handle_import_vscode_settings(
|
||||
workspace: WeakEntity<Workspace>,
|
||||
source: VsCodeSettingsSource,
|
||||
skip_prompt: bool,
|
||||
fs: Arc<dyn Fs>,
|
||||
|
@ -595,14 +603,73 @@ pub async fn handle_import_vscode_settings(
|
|||
}
|
||||
};
|
||||
|
||||
cx.update(|_, cx| {
|
||||
let Ok(result_channel) = cx.update(|_, cx| {
|
||||
let source = vscode_settings.source;
|
||||
let path = vscode_settings.path.clone();
|
||||
cx.global::<SettingsStore>()
|
||||
let result_channel = cx
|
||||
.global::<SettingsStore>()
|
||||
.import_vscode_settings(fs, vscode_settings);
|
||||
zlog::info!("Imported {source} settings from {}", path.display());
|
||||
})
|
||||
.ok();
|
||||
result_channel
|
||||
}) else {
|
||||
return;
|
||||
};
|
||||
|
||||
let result = result_channel.await;
|
||||
workspace
|
||||
.update_in(cx, |workspace, _, cx| match result {
|
||||
Ok(_) => {
|
||||
let confirmation_toast = StatusToast::new(
|
||||
format!("Your {} settings were successfully imported.", source),
|
||||
cx,
|
||||
|this, _| {
|
||||
this.icon(ToastIcon::new(IconName::Check).color(Color::Success))
|
||||
.dismiss_button(true)
|
||||
},
|
||||
);
|
||||
SettingsImportState::update(cx, |state, _| match source {
|
||||
VsCodeSettingsSource::VsCode => {
|
||||
state.vscode = true;
|
||||
}
|
||||
VsCodeSettingsSource::Cursor => {
|
||||
state.cursor = true;
|
||||
}
|
||||
});
|
||||
workspace.toggle_status_toast(confirmation_toast, cx);
|
||||
}
|
||||
Err(_) => {
|
||||
let error_toast = StatusToast::new(
|
||||
"Failed to import settings. See log for details",
|
||||
cx,
|
||||
|this, _| {
|
||||
this.icon(ToastIcon::new(IconName::X).color(Color::Error))
|
||||
.action("Open Log", |window, cx| {
|
||||
window.dispatch_action(workspace::OpenLog.boxed_clone(), cx)
|
||||
})
|
||||
.dismiss_button(true)
|
||||
},
|
||||
);
|
||||
workspace.toggle_status_toast(error_toast, cx);
|
||||
}
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
|
||||
#[derive(Default, Copy, Clone)]
|
||||
pub struct SettingsImportState {
|
||||
pub cursor: bool,
|
||||
pub vscode: bool,
|
||||
}
|
||||
|
||||
impl Global for SettingsImportState {}
|
||||
|
||||
impl SettingsImportState {
|
||||
pub fn global(cx: &App) -> Self {
|
||||
cx.try_global().cloned().unwrap_or_default()
|
||||
}
|
||||
pub fn update<R>(cx: &mut App, f: impl FnOnce(&mut Self, &mut App) -> R) -> R {
|
||||
cx.update_default_global(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl workspace::SerializableItem for Onboarding {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue