Implement all but the UI

This commit is contained in:
Mikayla 2023-11-28 15:18:19 -08:00
parent 8faa1f6e58
commit d927c2f497
No known key found for this signature in database
11 changed files with 468 additions and 428 deletions

View file

@ -1,17 +1,17 @@
use collections::{CommandPaletteFilter, HashMap}; use collections::{CommandPaletteFilter, HashMap};
use fuzzy::{StringMatch, StringMatchCandidate}; use fuzzy::{StringMatch, StringMatchCandidate};
use gpui::{ use gpui::{
actions, div, prelude::*, Action, AppContext, DismissEvent, Div, EventEmitter, FocusHandle, actions, div, prelude::*, Action, AnyElement, AppContext, DismissEvent, Div, EventEmitter,
FocusableView, Keystroke, ParentElement, Render, Styled, View, ViewContext, VisualContext, FocusHandle, FocusableView, Keystroke, ParentElement, Render, Styled, View, ViewContext,
WeakView, VisualContext, WeakView,
}; };
use picker::{Picker, PickerDelegate}; use picker::{simple_picker_match, Picker, PickerDelegate};
use std::{ use std::{
cmp::{self, Reverse}, cmp::{self, Reverse},
sync::Arc, sync::Arc,
}; };
use theme::ActiveTheme;
use ui::{h_stack, v_stack, HighlightedLabel, KeyBinding, StyledExt}; use ui::{h_stack, v_stack, HighlightedLabel, KeyBinding};
use util::{ use util::{
channel::{parse_zed_link, ReleaseChannel, RELEASE_CHANNEL}, channel::{parse_zed_link, ReleaseChannel, RELEASE_CHANNEL},
ResultExt, ResultExt,
@ -141,8 +141,6 @@ impl CommandPaletteDelegate {
} }
impl PickerDelegate for CommandPaletteDelegate { impl PickerDelegate for CommandPaletteDelegate {
type ListItem = Div;
fn placeholder_text(&self) -> Arc<str> { fn placeholder_text(&self) -> Arc<str> {
"Execute a command...".into() "Execute a command...".into()
} }
@ -294,32 +292,24 @@ impl PickerDelegate for CommandPaletteDelegate {
ix: usize, ix: usize,
selected: bool, selected: bool,
cx: &mut ViewContext<Picker<Self>>, cx: &mut ViewContext<Picker<Self>>,
) -> Self::ListItem { ) -> AnyElement {
let colors = cx.theme().colors();
let Some(r#match) = self.matches.get(ix) else { let Some(r#match) = self.matches.get(ix) else {
return div(); return div().into_any();
}; };
let Some(command) = self.commands.get(r#match.candidate_id) else { let Some(command) = self.commands.get(r#match.candidate_id) else {
return div(); return div().into_any();
}; };
div() simple_picker_match(selected, cx, |cx| {
.px_1() h_stack()
.text_color(colors.text) .justify_between()
.text_ui() .child(HighlightedLabel::new(
.bg(colors.ghost_element_background) command.name.clone(),
.rounded_md() r#match.positions.clone(),
.when(selected, |this| this.bg(colors.ghost_element_selected)) ))
.hover(|this| this.bg(colors.ghost_element_hover)) .children(KeyBinding::for_action(&*command.action, cx))
.child( .into_any()
h_stack() })
.justify_between()
.child(HighlightedLabel::new(
command.name.clone(),
r#match.positions.clone(),
))
.children(KeyBinding::for_action(&*command.action, cx)),
)
} }
} }

View file

@ -2,9 +2,9 @@ use collections::HashMap;
use editor::{scroll::autoscroll::Autoscroll, Bias, Editor}; use editor::{scroll::autoscroll::Autoscroll, Bias, Editor};
use fuzzy::{CharBag, PathMatch, PathMatchCandidate}; use fuzzy::{CharBag, PathMatch, PathMatchCandidate};
use gpui::{ use gpui::{
actions, div, AppContext, DismissEvent, Div, EventEmitter, FocusHandle, FocusableView, actions, div, AnyElement, AppContext, DismissEvent, Div, Element, EventEmitter, FocusHandle,
InteractiveElement, IntoElement, Model, ParentElement, Render, Styled, Task, View, ViewContext, FocusableView, InteractiveElement, IntoElement, Model, ParentElement, Render, Styled, Task,
VisualContext, WeakView, View, ViewContext, VisualContext, WeakView,
}; };
use picker::{Picker, PickerDelegate}; use picker::{Picker, PickerDelegate};
use project::{PathMatchCandidateSet, Project, ProjectPath, WorktreeId}; use project::{PathMatchCandidateSet, Project, ProjectPath, WorktreeId};
@ -530,8 +530,6 @@ impl FileFinderDelegate {
} }
impl PickerDelegate for FileFinderDelegate { impl PickerDelegate for FileFinderDelegate {
type ListItem = Div;
fn placeholder_text(&self) -> Arc<str> { fn placeholder_text(&self) -> Arc<str> {
"Search project files...".into() "Search project files...".into()
} }
@ -711,7 +709,7 @@ impl PickerDelegate for FileFinderDelegate {
ix: usize, ix: usize,
selected: bool, selected: bool,
cx: &mut ViewContext<Picker<Self>>, cx: &mut ViewContext<Picker<Self>>,
) -> Self::ListItem { ) -> AnyElement {
let path_match = self let path_match = self
.matches .matches
.get(ix) .get(ix)
@ -735,6 +733,7 @@ impl PickerDelegate for FileFinderDelegate {
.child(HighlightedLabel::new(file_name, file_name_positions)) .child(HighlightedLabel::new(file_name, file_name_positions))
.child(HighlightedLabel::new(full_path, full_path_positions)), .child(HighlightedLabel::new(full_path, full_path_positions)),
) )
.into_any()
} }
} }

View file

@ -1,7 +1,8 @@
use editor::Editor; use editor::Editor;
use gpui::{ use gpui::{
div, prelude::*, uniform_list, AppContext, Div, FocusHandle, FocusableView, MouseButton, div, prelude::*, uniform_list, AnyElement, AppContext, Div, FocusHandle, FocusableView,
MouseDownEvent, Render, Task, UniformListScrollHandle, View, ViewContext, WindowContext, MouseButton, MouseDownEvent, Render, Task, UniformListScrollHandle, View, ViewContext,
WindowContext,
}; };
use std::{cmp, sync::Arc}; use std::{cmp, sync::Arc};
use ui::{prelude::*, v_stack, Color, Divider, Label}; use ui::{prelude::*, v_stack, Color, Divider, Label};
@ -15,8 +16,6 @@ pub struct Picker<D: PickerDelegate> {
} }
pub trait PickerDelegate: Sized + 'static { pub trait PickerDelegate: Sized + 'static {
type ListItem: IntoElement;
fn match_count(&self) -> usize; fn match_count(&self) -> usize;
fn selected_index(&self) -> usize; fn selected_index(&self) -> usize;
fn set_selected_index(&mut self, ix: usize, cx: &mut ViewContext<Picker<Self>>); fn set_selected_index(&mut self, ix: usize, cx: &mut ViewContext<Picker<Self>>);
@ -32,7 +31,7 @@ pub trait PickerDelegate: Sized + 'static {
ix: usize, ix: usize,
selected: bool, selected: bool,
cx: &mut ViewContext<Picker<Self>>, cx: &mut ViewContext<Picker<Self>>,
) -> Self::ListItem; ) -> AnyElement;
} }
impl<D: PickerDelegate> FocusableView for Picker<D> { impl<D: PickerDelegate> FocusableView for Picker<D> {
@ -257,3 +256,22 @@ impl<D: PickerDelegate> Render for Picker<D> {
}) })
} }
} }
pub fn simple_picker_match(
selected: bool,
cx: &mut WindowContext,
children: impl FnOnce(&mut WindowContext) -> AnyElement,
) -> AnyElement {
let colors = cx.theme().colors();
div()
.px_1()
.text_color(colors.text)
.text_ui()
.bg(colors.ghost_element_background)
.rounded_md()
.when(selected, |this| this.bg(colors.ghost_element_selected))
.hover(|this| this.bg(colors.ghost_element_hover))
.child((children)(cx))
.into_any()
}

View file

@ -1,6 +1,7 @@
use fuzzy::StringMatchCandidate; use fuzzy::StringMatchCandidate;
use gpui::{ use gpui::{
div, prelude::*, Div, KeyBinding, Render, SharedString, Styled, Task, View, WindowContext, div, prelude::*, AnyElement, Div, KeyBinding, Render, SharedString, Styled, Task, View,
WindowContext,
}; };
use picker::{Picker, PickerDelegate}; use picker::{Picker, PickerDelegate};
use std::sync::Arc; use std::sync::Arc;
@ -36,8 +37,6 @@ impl Delegate {
} }
impl PickerDelegate for Delegate { impl PickerDelegate for Delegate {
type ListItem = Div;
fn match_count(&self) -> usize { fn match_count(&self) -> usize {
self.candidates.len() self.candidates.len()
} }
@ -51,10 +50,10 @@ impl PickerDelegate for Delegate {
ix: usize, ix: usize,
selected: bool, selected: bool,
cx: &mut gpui::ViewContext<Picker<Self>>, cx: &mut gpui::ViewContext<Picker<Self>>,
) -> Self::ListItem { ) -> AnyElement {
let colors = cx.theme().colors(); let colors = cx.theme().colors();
let Some(candidate_ix) = self.matches.get(ix) else { let Some(candidate_ix) = self.matches.get(ix) else {
return div(); return div().into_any();
}; };
// TASK: Make StringMatchCandidate::string a SharedString // TASK: Make StringMatchCandidate::string a SharedString
let candidate = SharedString::from(self.candidates[*candidate_ix].string.clone()); let candidate = SharedString::from(self.candidates[*candidate_ix].string.clone());
@ -70,6 +69,7 @@ impl PickerDelegate for Delegate {
.text_color(colors.text_accent) .text_color(colors.text_accent)
}) })
.child(candidate) .child(candidate)
.into_any()
} }
fn selected_index(&self) -> usize { fn selected_index(&self) -> usize {

View file

@ -2,39 +2,49 @@ use feature_flags::FeatureFlagAppExt;
use fs::Fs; use fs::Fs;
use fuzzy::{match_strings, StringMatch, StringMatchCandidate}; use fuzzy::{match_strings, StringMatch, StringMatchCandidate};
use gpui::{ use gpui::{
actions, div, AppContext, Div, EventEmitter, FocusableView, Manager, Render, SharedString, actions, div, AnyElement, AppContext, DismissEvent, Element, EventEmitter, FocusableView,
View, ViewContext, VisualContext, InteractiveElement, IntoElement, ParentElement, Render, SharedString, Styled, View,
ViewContext, VisualContext, WeakView,
}; };
use picker::{Picker, PickerDelegate}; use picker::{Picker, PickerDelegate};
use settings::{update_settings_file, SettingsStore}; use settings::{update_settings_file, SettingsStore};
use std::sync::Arc; use std::sync::Arc;
use theme::{ActiveTheme, Theme, ThemeRegistry, ThemeSettings}; use theme::{ActiveTheme, Theme, ThemeRegistry, ThemeSettings};
use util::ResultExt; use util::ResultExt;
use workspace::{ui::HighlightedLabel, Workspace}; use workspace::{
ui::{HighlightedLabel, StyledExt},
Workspace,
};
actions!(Toggle, Reload); actions!(Toggle, Reload);
pub fn init(cx: &mut AppContext) { pub fn init(cx: &mut AppContext) {
cx.observe_new_views( cx.observe_new_views(
|workspace: &mut Workspace, cx: &mut ViewContext<Workspace>| { |workspace: &mut Workspace, _cx: &mut ViewContext<Workspace>| {
workspace.register_action(toggle); workspace.register_action(toggle);
}, },
); )
.detach();
} }
pub fn toggle(workspace: &mut Workspace, _: &Toggle, cx: &mut ViewContext<Workspace>) { pub fn toggle(workspace: &mut Workspace, _: &Toggle, cx: &mut ViewContext<Workspace>) {
let fs = workspace.app_state().fs.clone(); let fs = workspace.app_state().fs.clone();
workspace.toggle_modal(cx, |cx| { workspace.toggle_modal(cx, |cx| {
ThemeSelector::new(ThemeSelectorDelegate::new(fs, cx), cx) ThemeSelector::new(
ThemeSelectorDelegate::new(cx.view().downgrade(), fs, cx),
cx,
)
}); });
} }
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
pub fn reload(cx: &mut AppContext) { pub fn reload(cx: &mut AppContext) {
let current_theme_name = cx.theme().name.clone(); let current_theme_name = cx.theme().name.clone();
let registry = cx.global::<Arc<ThemeRegistry>>(); let current_theme = cx.update_global(|registry: &mut ThemeRegistry, _cx| {
registry.clear(); registry.clear();
match registry.get(&current_theme_name) { registry.get(&current_theme_name)
});
match current_theme {
Ok(theme) => { Ok(theme) => {
ThemeSelectorDelegate::set_theme(theme, cx); ThemeSelectorDelegate::set_theme(theme, cx);
log::info!("reloaded theme {}", current_theme_name); log::info!("reloaded theme {}", current_theme_name);
@ -49,7 +59,7 @@ pub struct ThemeSelector {
picker: View<Picker<ThemeSelectorDelegate>>, picker: View<Picker<ThemeSelectorDelegate>>,
} }
impl EventEmitter<Manager> for ThemeSelector {} impl EventEmitter<DismissEvent> for ThemeSelector {}
impl FocusableView for ThemeSelector { impl FocusableView for ThemeSelector {
fn focus_handle(&self, cx: &AppContext) -> gpui::FocusHandle { fn focus_handle(&self, cx: &AppContext) -> gpui::FocusHandle {
@ -60,7 +70,7 @@ impl FocusableView for ThemeSelector {
impl Render for ThemeSelector { impl Render for ThemeSelector {
type Element = View<Picker<ThemeSelectorDelegate>>; type Element = View<Picker<ThemeSelectorDelegate>>;
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element { fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element {
self.picker.clone() self.picker.clone()
} }
} }
@ -79,16 +89,22 @@ pub struct ThemeSelectorDelegate {
original_theme: Arc<Theme>, original_theme: Arc<Theme>,
selection_completed: bool, selection_completed: bool,
selected_index: usize, selected_index: usize,
view: WeakView<ThemeSelector>,
} }
impl ThemeSelectorDelegate { impl ThemeSelectorDelegate {
fn new(fs: Arc<dyn Fs>, cx: &mut ViewContext<ThemeSelector>) -> Self { fn new(
weak_view: WeakView<ThemeSelector>,
fs: Arc<dyn Fs>,
cx: &mut ViewContext<ThemeSelector>,
) -> Self {
let original_theme = cx.theme().clone(); let original_theme = cx.theme().clone();
let staff_mode = cx.is_staff(); let staff_mode = cx.is_staff();
let registry = cx.global::<Arc<ThemeRegistry>>(); let registry = cx.global::<Arc<ThemeRegistry>>();
let mut theme_names = registry.list(staff_mode).collect::<Vec<_>>(); let theme_names = registry.list(staff_mode).collect::<Vec<_>>();
theme_names.sort_unstable_by(|a, b| a.is_light.cmp(&b.is_light).then(a.name.cmp(&b.name))); //todo!(theme sorting)
// theme_names.sort_unstable_by(|a, b| a.is_light.cmp(&b.is_light).then(a.name.cmp(&b.name)));
let matches = theme_names let matches = theme_names
.iter() .iter()
.map(|meta| StringMatch { .map(|meta| StringMatch {
@ -105,12 +121,13 @@ impl ThemeSelectorDelegate {
original_theme: original_theme.clone(), original_theme: original_theme.clone(),
selected_index: 0, selected_index: 0,
selection_completed: false, selection_completed: false,
view: weak_view,
}; };
this.select_if_matching(&original_theme.meta.name); this.select_if_matching(&original_theme.name);
this this
} }
fn show_selected_theme(&mut self, cx: &mut ViewContext<ThemeSelector>) { fn show_selected_theme(&mut self, cx: &mut ViewContext<Picker<ThemeSelectorDelegate>>) {
if let Some(mat) = self.matches.get(self.selected_index) { if let Some(mat) = self.matches.get(self.selected_index) {
let registry = cx.global::<Arc<ThemeRegistry>>(); let registry = cx.global::<Arc<ThemeRegistry>>();
match registry.get(&mat.string) { match registry.get(&mat.string) {
@ -133,18 +150,16 @@ impl ThemeSelectorDelegate {
} }
fn set_theme(theme: Arc<Theme>, cx: &mut AppContext) { fn set_theme(theme: Arc<Theme>, cx: &mut AppContext) {
cx.update_global::<SettingsStore, _, _>(|store, cx| { cx.update_global(|store: &mut SettingsStore, cx| {
let mut theme_settings = store.get::<ThemeSettings>(None).clone(); let mut theme_settings = store.get::<ThemeSettings>(None).clone();
theme_settings.theme = theme; theme_settings.active_theme = theme;
store.override_global(theme_settings); store.override_global(theme_settings);
cx.refresh_windows(); cx.refresh();
}); });
} }
} }
impl PickerDelegate for ThemeSelectorDelegate { impl PickerDelegate for ThemeSelectorDelegate {
type ListItem = Div;
fn placeholder_text(&self) -> Arc<str> { fn placeholder_text(&self) -> Arc<str> {
"Select Theme...".into() "Select Theme...".into()
} }
@ -153,18 +168,22 @@ impl PickerDelegate for ThemeSelectorDelegate {
self.matches.len() self.matches.len()
} }
fn confirm(&mut self, _: bool, cx: &mut ViewContext<ThemeSelector>) { fn confirm(&mut self, _: bool, cx: &mut ViewContext<Picker<ThemeSelectorDelegate>>) {
self.selection_completed = true; self.selection_completed = true;
let theme_name = cx.theme().meta.name.clone(); let theme_name = cx.theme().name.clone();
update_settings_file::<ThemeSettings>(self.fs.clone(), cx, |settings| { update_settings_file::<ThemeSettings>(self.fs.clone(), cx, move |settings| {
settings.theme = Some(theme_name); settings.theme = Some(theme_name.to_string());
}); });
cx.emit(Manager::Dismiss); self.view
.update(cx, |_, cx| {
cx.emit(DismissEvent::Dismiss);
})
.ok();
} }
fn dismissed(&mut self, cx: &mut ViewContext<ThemeSelector>) { fn dismissed(&mut self, cx: &mut ViewContext<Picker<ThemeSelectorDelegate>>) {
if !self.selection_completed { if !self.selection_completed {
Self::set_theme(self.original_theme.clone(), cx); Self::set_theme(self.original_theme.clone(), cx);
self.selection_completed = true; self.selection_completed = true;
@ -175,7 +194,11 @@ impl PickerDelegate for ThemeSelectorDelegate {
self.selected_index self.selected_index
} }
fn set_selected_index(&mut self, ix: usize, cx: &mut ViewContext<ThemeSelector>) { fn set_selected_index(
&mut self,
ix: usize,
cx: &mut ViewContext<Picker<ThemeSelectorDelegate>>,
) {
self.selected_index = ix; self.selected_index = ix;
self.show_selected_theme(cx); self.show_selected_theme(cx);
} }
@ -183,17 +206,17 @@ impl PickerDelegate for ThemeSelectorDelegate {
fn update_matches( fn update_matches(
&mut self, &mut self,
query: String, query: String,
cx: &mut ViewContext<ThemeSelector>, cx: &mut ViewContext<Picker<ThemeSelectorDelegate>>,
) -> gpui::Task<()> { ) -> gpui::Task<()> {
let background = cx.background().clone(); let background = cx.background_executor().clone();
let candidates = self let candidates = self
.theme_names .theme_names
.iter() .iter()
.enumerate() .enumerate()
.map(|(id, meta)| StringMatchCandidate { .map(|(id, meta)| StringMatchCandidate {
id, id,
char_bag: meta.name.as_str().into(), char_bag: meta.as_ref().into(),
string: meta.name.clone(), string: meta.to_string(),
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
@ -222,18 +245,23 @@ impl PickerDelegate for ThemeSelectorDelegate {
}; };
this.update(&mut cx, |this, cx| { this.update(&mut cx, |this, cx| {
let delegate = this.delegate_mut(); this.delegate.matches = matches;
delegate.matches = matches; this.delegate.selected_index = this
delegate.selected_index = delegate .delegate
.selected_index .selected_index
.min(delegate.matches.len().saturating_sub(1)); .min(this.delegate.matches.len().saturating_sub(1));
delegate.show_selected_theme(cx); this.delegate.show_selected_theme(cx);
}) })
.log_err(); .log_err();
}) })
} }
fn render_match(&self, ix: usize, selected: bool, cx: &AppContext) -> Self::ListItem { fn render_match(
&self,
ix: usize,
selected: bool,
cx: &mut ViewContext<Picker<Self>>,
) -> AnyElement {
let theme = cx.theme(); let theme = cx.theme();
let colors = theme.colors(); let colors = theme.colors();
@ -250,5 +278,6 @@ impl PickerDelegate for ThemeSelectorDelegate {
theme_match.string.clone(), theme_match.string.clone(),
theme_match.positions.clone(), theme_match.positions.clone(),
)) ))
.into_any()
} }
} }

View file

@ -1,22 +1,23 @@
use super::base_keymap_setting::BaseKeymap; use super::base_keymap_setting::BaseKeymap;
use fuzzy::{match_strings, StringMatch, StringMatchCandidate}; use fuzzy::{match_strings, StringMatch, StringMatchCandidate};
use gpui::{ use gpui::{
actions, actions, AppContext, DismissEvent, EventEmitter, FocusableView, IntoElement, Render, Task,
elements::{Element as _, Label}, View, ViewContext, VisualContext, WeakView,
AppContext, Task, ViewContext,
}; };
use picker::{Picker, PickerDelegate, PickerEvent}; use picker::{simple_picker_match, Picker, PickerDelegate};
use project::Fs; use project::Fs;
use settings::update_settings_file; use settings::{update_settings_file, Settings};
use std::sync::Arc; use std::sync::Arc;
use util::ResultExt; use util::ResultExt;
use workspace::Workspace; use workspace::{ui::HighlightedLabel, Workspace};
actions!(welcome, [ToggleBaseKeymapSelector]); actions!(ToggleBaseKeymapSelector);
pub fn init(cx: &mut AppContext) { pub fn init(cx: &mut AppContext) {
cx.add_action(toggle); cx.observe_new_views(|workspace: &mut Workspace, _cx| {
BaseKeymapSelector::init(cx); workspace.register_action(toggle);
})
.detach();
} }
pub fn toggle( pub fn toggle(
@ -24,28 +25,70 @@ pub fn toggle(
_: &ToggleBaseKeymapSelector, _: &ToggleBaseKeymapSelector,
cx: &mut ViewContext<Workspace>, cx: &mut ViewContext<Workspace>,
) { ) {
workspace.toggle_modal(cx, |workspace, cx| { let fs = workspace.app_state().fs.clone();
let fs = workspace.app_state().fs.clone(); workspace.toggle_modal(cx, |cx| {
cx.add_view(|cx| BaseKeymapSelector::new(BaseKeymapSelectorDelegate::new(fs, cx), cx)) BaseKeymapSelector::new(
BaseKeymapSelectorDelegate::new(cx.view().downgrade(), fs, cx),
cx,
)
}); });
} }
pub type BaseKeymapSelector = Picker<BaseKeymapSelectorDelegate>; pub struct BaseKeymapSelector {
focus_handle: gpui::FocusHandle,
picker: View<Picker<BaseKeymapSelectorDelegate>>,
}
impl FocusableView for BaseKeymapSelector {
fn focus_handle(&self, _cx: &AppContext) -> gpui::FocusHandle {
self.focus_handle.clone()
}
}
impl EventEmitter<DismissEvent> for BaseKeymapSelector {}
impl BaseKeymapSelector {
pub fn new(
delegate: BaseKeymapSelectorDelegate,
cx: &mut ViewContext<BaseKeymapSelector>,
) -> Self {
let picker = cx.build_view(|cx| Picker::new(delegate, cx));
let focus_handle = cx.focus_handle();
Self {
focus_handle,
picker,
}
}
}
impl Render for BaseKeymapSelector {
type Element = View<Picker<BaseKeymapSelectorDelegate>>;
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element {
self.picker.clone()
}
}
pub struct BaseKeymapSelectorDelegate { pub struct BaseKeymapSelectorDelegate {
view: WeakView<BaseKeymapSelector>,
matches: Vec<StringMatch>, matches: Vec<StringMatch>,
selected_index: usize, selected_index: usize,
fs: Arc<dyn Fs>, fs: Arc<dyn Fs>,
} }
impl BaseKeymapSelectorDelegate { impl BaseKeymapSelectorDelegate {
fn new(fs: Arc<dyn Fs>, cx: &mut ViewContext<BaseKeymapSelector>) -> Self { fn new(
let base = settings::get::<BaseKeymap>(cx); weak_view: WeakView<BaseKeymapSelector>,
fs: Arc<dyn Fs>,
cx: &mut ViewContext<BaseKeymapSelector>,
) -> Self {
let base = BaseKeymap::get(None, cx);
let selected_index = BaseKeymap::OPTIONS let selected_index = BaseKeymap::OPTIONS
.iter() .iter()
.position(|(_, value)| value == base) .position(|(_, value)| value == base)
.unwrap_or(0); .unwrap_or(0);
Self { Self {
view: weak_view,
matches: Vec::new(), matches: Vec::new(),
selected_index, selected_index,
fs, fs,
@ -66,16 +109,20 @@ impl PickerDelegate for BaseKeymapSelectorDelegate {
self.selected_index self.selected_index
} }
fn set_selected_index(&mut self, ix: usize, _: &mut ViewContext<BaseKeymapSelector>) { fn set_selected_index(
&mut self,
ix: usize,
_: &mut ViewContext<Picker<BaseKeymapSelectorDelegate>>,
) {
self.selected_index = ix; self.selected_index = ix;
} }
fn update_matches( fn update_matches(
&mut self, &mut self,
query: String, query: String,
cx: &mut ViewContext<BaseKeymapSelector>, cx: &mut ViewContext<Picker<BaseKeymapSelectorDelegate>>,
) -> Task<()> { ) -> Task<()> {
let background = cx.background().clone(); let background = cx.background_executor().clone();
let candidates = BaseKeymap::names() let candidates = BaseKeymap::names()
.enumerate() .enumerate()
.map(|(id, name)| StringMatchCandidate { .map(|(id, name)| StringMatchCandidate {
@ -110,43 +157,44 @@ impl PickerDelegate for BaseKeymapSelectorDelegate {
}; };
this.update(&mut cx, |this, _| { this.update(&mut cx, |this, _| {
let delegate = this.delegate_mut(); this.delegate.matches = matches;
delegate.matches = matches; this.delegate.selected_index = this
delegate.selected_index = delegate .delegate
.selected_index .selected_index
.min(delegate.matches.len().saturating_sub(1)); .min(this.delegate.matches.len().saturating_sub(1));
}) })
.log_err(); .log_err();
}) })
} }
fn confirm(&mut self, _: bool, cx: &mut ViewContext<BaseKeymapSelector>) { fn confirm(&mut self, _: bool, cx: &mut ViewContext<Picker<BaseKeymapSelectorDelegate>>) {
if let Some(selection) = self.matches.get(self.selected_index) { if let Some(selection) = self.matches.get(self.selected_index) {
let base_keymap = BaseKeymap::from_names(&selection.string); let base_keymap = BaseKeymap::from_names(&selection.string);
update_settings_file::<BaseKeymap>(self.fs.clone(), cx, move |setting| { update_settings_file::<BaseKeymap>(self.fs.clone(), cx, move |setting| {
*setting = Some(base_keymap) *setting = Some(base_keymap)
}); });
} }
cx.emit(PickerEvent::Dismiss);
self.view
.update(cx, |_, cx| {
cx.emit(DismissEvent::Dismiss);
})
.ok();
} }
fn dismissed(&mut self, _cx: &mut ViewContext<BaseKeymapSelector>) {} fn dismissed(&mut self, _cx: &mut ViewContext<Picker<BaseKeymapSelectorDelegate>>) {}
fn render_match( fn render_match(
&self, &self,
ix: usize, ix: usize,
mouse_state: &mut gpui::MouseState,
selected: bool, selected: bool,
cx: &gpui::AppContext, cx: &mut gpui::ViewContext<Picker<Self>>,
) -> gpui::AnyElement<Picker<Self>> { ) -> gpui::AnyElement {
let theme = &theme::current(cx);
let keymap_match = &self.matches[ix]; let keymap_match = &self.matches[ix];
let style = theme.picker.item.in_state(selected).style_for(mouse_state);
Label::new(keymap_match.string.clone(), style.label.clone()) simple_picker_match(selected, cx, |_cx| {
.with_highlights(keymap_match.positions.clone()) HighlightedLabel::new(keymap_match.string.clone(), keymap_match.positions.clone())
.contained() .into_any_element()
.with_style(style.container) })
.into_any()
} }
} }

View file

@ -1,6 +1,6 @@
use schemars::JsonSchema; use schemars::JsonSchema;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use settings::Setting; use settings::Settings;
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq, Default)] #[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq, Default)]
pub enum BaseKeymap { pub enum BaseKeymap {
@ -44,7 +44,7 @@ impl BaseKeymap {
} }
} }
impl Setting for BaseKeymap { impl Settings for BaseKeymap {
const KEY: Option<&'static str> = Some("base_keymap"); const KEY: Option<&'static str> = Some("base_keymap");
type FileContent = Option<Self>; type FileContent = Option<Self>;
@ -52,7 +52,7 @@ impl Setting for BaseKeymap {
fn load( fn load(
default_value: &Self::FileContent, default_value: &Self::FileContent,
user_values: &[&Self::FileContent], user_values: &[&Self::FileContent],
_: &gpui::AppContext, _: &mut gpui::AppContext,
) -> anyhow::Result<Self> ) -> anyhow::Result<Self>
where where
Self: Sized, Self: Sized,

View file

@ -1,19 +1,18 @@
mod base_keymap_picker; mod base_keymap_picker;
mod base_keymap_setting; mod base_keymap_setting;
use crate::base_keymap_picker::ToggleBaseKeymapSelector;
use client::TelemetrySettings;
use db::kvp::KEY_VALUE_STORE; use db::kvp::KEY_VALUE_STORE;
use gpui::{ use gpui::{
elements::{Flex, Label, ParentElement}, div, red, AnyElement, AppContext, Div, Element, EventEmitter, FocusHandle, Focusable,
AnyElement, AppContext, Element, Entity, Subscription, View, ViewContext, WeakViewHandle, FocusableView, InteractiveElement, ParentElement, Render, Styled, Subscription, View,
ViewContext, VisualContext, WeakView, WindowContext,
}; };
use settings::{update_settings_file, SettingsStore}; use settings::{Settings, SettingsStore};
use std::{borrow::Cow, sync::Arc}; use std::sync::Arc;
use vim::VimModeSetting;
use workspace::{ use workspace::{
dock::DockPosition, item::Item, open_new, AppState, PaneBackdrop, Welcome, Workspace, dock::DockPosition,
WorkspaceId, item::{Item, ItemEvent},
open_new, AppState, Welcome, Workspace, WorkspaceId,
}; };
pub use base_keymap_setting::BaseKeymap; pub use base_keymap_setting::BaseKeymap;
@ -21,12 +20,15 @@ pub use base_keymap_setting::BaseKeymap;
pub const FIRST_OPEN: &str = "first_open"; pub const FIRST_OPEN: &str = "first_open";
pub fn init(cx: &mut AppContext) { pub fn init(cx: &mut AppContext) {
settings::register::<BaseKeymap>(cx); BaseKeymap::register(cx);
cx.add_action(|workspace: &mut Workspace, _: &Welcome, cx| { cx.observe_new_views(|workspace: &mut Workspace, _cx| {
let welcome_page = cx.add_view(|cx| WelcomePage::new(workspace, cx)); workspace.register_action(|workspace, _: &Welcome, cx| {
workspace.add_item(Box::new(welcome_page), cx) let welcome_page = cx.build_view(|cx| WelcomePage::new(workspace, cx));
}); workspace.add_item(Box::new(welcome_page), cx)
});
})
.detach();
base_keymap_picker::init(cx); base_keymap_picker::init(cx);
} }
@ -34,9 +36,9 @@ pub fn init(cx: &mut AppContext) {
pub fn show_welcome_experience(app_state: &Arc<AppState>, cx: &mut AppContext) { pub fn show_welcome_experience(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.add_view(|cx| WelcomePage::new(workspace, cx)); let welcome_page = cx.build_view(|cx| WelcomePage::new(workspace, cx));
workspace.add_item_to_center(Box::new(welcome_page.clone()), cx); workspace.add_item_to_center(Box::new(welcome_page.clone()), cx);
cx.focus(&welcome_page); cx.focus_view(&welcome_page);
cx.notify(); cx.notify();
}) })
.detach(); .detach();
@ -47,227 +49,217 @@ pub fn show_welcome_experience(app_state: &Arc<AppState>, cx: &mut AppContext) {
} }
pub struct WelcomePage { pub struct WelcomePage {
workspace: WeakViewHandle<Workspace>, workspace: WeakView<Workspace>,
focus_handle: FocusHandle,
_settings_subscription: Subscription, _settings_subscription: Subscription,
} }
impl Entity for WelcomePage { impl Render for WelcomePage {
type Event = (); type Element = Focusable<Div>;
}
impl View for WelcomePage { fn render(&mut self, _cx: &mut gpui::ViewContext<Self>) -> Self::Element {
fn ui_name() -> &'static str { // let self_handle = cx.handle();
"WelcomePage" // let theme = cx.theme();
} // let width = theme.welcome.page_width;
fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> AnyElement<Self> { // let telemetry_settings = TelemetrySettings::get(None, cx);
let self_handle = cx.handle(); // let vim_mode_setting = VimModeSettings::get(cx);
let theme = theme::current(cx);
let width = theme.welcome.page_width;
let telemetry_settings = *settings::get::<TelemetrySettings>(cx); div()
let vim_mode_setting = settings::get::<VimModeSetting>(cx).0; .track_focus(&self.focus_handle)
.child(div().size_full().bg(red()).child("Welcome!"))
enum Metrics {} //todo!()
enum Diagnostics {} // PaneBackdrop::new(
// self_handle.id(),
PaneBackdrop::new( // Flex::column()
self_handle.id(), // .with_child(
Flex::column() // Flex::column()
.with_child( // .with_child(
Flex::column() // theme::ui::svg(&theme.welcome.logo)
.with_child( // .aligned()
theme::ui::svg(&theme.welcome.logo) // .contained()
.aligned() // .aligned(),
.contained() // )
.aligned(), // .with_child(
) // Label::new(
.with_child( // "Code at the speed of thought",
Label::new( // theme.welcome.logo_subheading.text.clone(),
"Code at the speed of thought", // )
theme.welcome.logo_subheading.text.clone(), // .aligned()
) // .contained()
.aligned() // .with_style(theme.welcome.logo_subheading.container),
.contained() // )
.with_style(theme.welcome.logo_subheading.container), // .contained()
) // .with_style(theme.welcome.heading_group)
.contained() // .constrained()
.with_style(theme.welcome.heading_group) // .with_width(width),
.constrained() // )
.with_width(width), // .with_child(
) // Flex::column()
.with_child( // .with_child(theme::ui::cta_button::<theme_selector::Toggle, _, _, _>(
Flex::column() // "Choose a theme",
.with_child(theme::ui::cta_button::<theme_selector::Toggle, _, _, _>( // width,
"Choose a theme", // &theme.welcome.button,
width, // cx,
&theme.welcome.button, // |_, this, cx| {
cx, // if let Some(workspace) = this.workspace.upgrade(cx) {
|_, this, cx| { // workspace.update(cx, |workspace, cx| {
if let Some(workspace) = this.workspace.upgrade(cx) { // theme_selector::toggle(workspace, &Default::default(), cx)
workspace.update(cx, |workspace, cx| { // })
theme_selector::toggle(workspace, &Default::default(), cx) // }
}) // },
} // ))
}, // .with_child(theme::ui::cta_button::<ToggleBaseKeymapSelector, _, _, _>(
)) // "Choose a keymap",
.with_child(theme::ui::cta_button::<ToggleBaseKeymapSelector, _, _, _>( // width,
"Choose a keymap", // &theme.welcome.button,
width, // cx,
&theme.welcome.button, // |_, this, cx| {
cx, // if let Some(workspace) = this.workspace.upgrade(cx) {
|_, this, cx| { // workspace.update(cx, |workspace, cx| {
if let Some(workspace) = this.workspace.upgrade(cx) { // base_keymap_picker::toggle(
workspace.update(cx, |workspace, cx| { // workspace,
base_keymap_picker::toggle( // &Default::default(),
workspace, // cx,
&Default::default(), // )
cx, // })
) // }
}) // },
} // ))
}, // .with_child(theme::ui::cta_button::<install_cli::Install, _, _, _>(
)) // "Install the CLI",
.with_child(theme::ui::cta_button::<install_cli::Install, _, _, _>( // width,
"Install the CLI", // &theme.welcome.button,
width, // cx,
&theme.welcome.button, // |_, _, cx| {
cx, // cx.app_context()
|_, _, cx| { // .spawn(|cx| async move { install_cli::install_cli(&cx).await })
cx.app_context() // .detach_and_log_err(cx);
.spawn(|cx| async move { install_cli::install_cli(&cx).await }) // },
.detach_and_log_err(cx); // ))
}, // .contained()
)) // .with_style(theme.welcome.button_group)
.contained() // .constrained()
.with_style(theme.welcome.button_group) // .with_width(width),
.constrained() // )
.with_width(width), // .with_child(
) // Flex::column()
.with_child( // .with_child(
Flex::column() // theme::ui::checkbox::<Diagnostics, Self, _>(
.with_child( // "Enable vim mode",
theme::ui::checkbox::<Diagnostics, Self, _>( // &theme.welcome.checkbox,
"Enable vim mode", // vim_mode_setting,
&theme.welcome.checkbox, // 0,
vim_mode_setting, // cx,
0, // |this, checked, cx| {
cx, // if let Some(workspace) = this.workspace.upgrade(cx) {
|this, checked, cx| { // let fs = workspace.read(cx).app_state().fs.clone();
if let Some(workspace) = this.workspace.upgrade(cx) { // update_settings_file::<VimModeSetting>(
let fs = workspace.read(cx).app_state().fs.clone(); // fs,
update_settings_file::<VimModeSetting>( // cx,
fs, // move |setting| *setting = Some(checked),
cx, // )
move |setting| *setting = Some(checked), // }
) // },
} // )
}, // .contained()
) // .with_style(theme.welcome.checkbox_container),
.contained() // )
.with_style(theme.welcome.checkbox_container), // .with_child(
) // theme::ui::checkbox_with_label::<Metrics, _, Self, _>(
.with_child( // Flex::column()
theme::ui::checkbox_with_label::<Metrics, _, Self, _>( // .with_child(
Flex::column() // Label::new(
.with_child( // "Send anonymous usage data",
Label::new( // theme.welcome.checkbox.label.text.clone(),
"Send anonymous usage data", // )
theme.welcome.checkbox.label.text.clone(), // .contained()
) // .with_style(theme.welcome.checkbox.label.container),
.contained() // )
.with_style(theme.welcome.checkbox.label.container), // .with_child(
) // Label::new(
.with_child( // "Help > View Telemetry",
Label::new( // theme.welcome.usage_note.text.clone(),
"Help > View Telemetry", // )
theme.welcome.usage_note.text.clone(), // .contained()
) // .with_style(theme.welcome.usage_note.container),
.contained() // ),
.with_style(theme.welcome.usage_note.container), // &theme.welcome.checkbox,
), // telemetry_settings.metrics,
&theme.welcome.checkbox, // 0,
telemetry_settings.metrics, // cx,
0, // |this, checked, cx| {
cx, // if let Some(workspace) = this.workspace.upgrade(cx) {
|this, checked, cx| { // let fs = workspace.read(cx).app_state().fs.clone();
if let Some(workspace) = this.workspace.upgrade(cx) { // update_settings_file::<TelemetrySettings>(
let fs = workspace.read(cx).app_state().fs.clone(); // fs,
update_settings_file::<TelemetrySettings>( // cx,
fs, // move |setting| setting.metrics = Some(checked),
cx, // )
move |setting| setting.metrics = Some(checked), // }
) // },
} // )
}, // .contained()
) // .with_style(theme.welcome.checkbox_container),
.contained() // )
.with_style(theme.welcome.checkbox_container), // .with_child(
) // theme::ui::checkbox::<Diagnostics, Self, _>(
.with_child( // "Send crash reports",
theme::ui::checkbox::<Diagnostics, Self, _>( // &theme.welcome.checkbox,
"Send crash reports", // telemetry_settings.diagnostics,
&theme.welcome.checkbox, // 1,
telemetry_settings.diagnostics, // cx,
1, // |this, checked, cx| {
cx, // if let Some(workspace) = this.workspace.upgrade(cx) {
|this, checked, cx| { // let fs = workspace.read(cx).app_state().fs.clone();
if let Some(workspace) = this.workspace.upgrade(cx) { // update_settings_file::<TelemetrySettings>(
let fs = workspace.read(cx).app_state().fs.clone(); // fs,
update_settings_file::<TelemetrySettings>( // cx,
fs, // move |setting| setting.diagnostics = Some(checked),
cx, // )
move |setting| setting.diagnostics = Some(checked), // }
) // },
} // )
}, // .contained()
) // .with_style(theme.welcome.checkbox_container),
.contained() // )
.with_style(theme.welcome.checkbox_container), // .contained()
) // .with_style(theme.welcome.checkbox_group)
.contained() // .constrained()
.with_style(theme.welcome.checkbox_group) // .with_width(width),
.constrained() // )
.with_width(width), // .constrained()
) // .with_max_width(width)
.constrained() // .contained()
.with_max_width(width) // .with_uniform_padding(10.)
.contained() // .aligned()
.with_uniform_padding(10.) // .into_any(),
.aligned() // )
.into_any(), // .into_any_named("welcome page")
)
.into_any_named("welcome page")
} }
} }
impl WelcomePage { impl WelcomePage {
pub fn new(workspace: &Workspace, cx: &mut ViewContext<Self>) -> Self { pub fn new(workspace: &Workspace, cx: &mut ViewContext<Self>) -> Self {
WelcomePage { WelcomePage {
focus_handle: cx.focus_handle(),
workspace: workspace.weak_handle(), workspace: workspace.weak_handle(),
_settings_subscription: cx.observe_global::<SettingsStore, _>(move |_, cx| cx.notify()), _settings_subscription: cx.observe_global::<SettingsStore>(move |_, cx| cx.notify()),
} }
} }
} }
impl Item for WelcomePage { impl EventEmitter<ItemEvent> for WelcomePage {}
fn tab_tooltip_text(&self, _: &AppContext) -> Option<Cow<str>> {
Some("Welcome to Zed!".into())
}
fn tab_content<T: 'static>( impl FocusableView for WelcomePage {
&self, fn focus_handle(&self, _: &AppContext) -> gpui::FocusHandle {
_detail: Option<usize>, self.focus_handle.clone()
style: &theme::Tab, }
_cx: &gpui::AppContext, }
) -> AnyElement<T> {
Flex::row() impl Item for WelcomePage {
.with_child( fn tab_content(&self, _: Option<usize>, _: &WindowContext) -> AnyElement {
Label::new("Welcome to Zed!", style.label.clone()) "Welcome to Zed!".into_any()
.aligned()
.contained(),
)
.into_any()
} }
fn show_toolbar(&self) -> bool { fn show_toolbar(&self) -> bool {
@ -278,10 +270,11 @@ impl Item for WelcomePage {
&self, &self,
_workspace_id: WorkspaceId, _workspace_id: WorkspaceId,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> Option<Self> { ) -> Option<View<Self>> {
Some(WelcomePage { Some(cx.build_view(|cx| WelcomePage {
focus_handle: cx.focus_handle(),
workspace: self.workspace.clone(), workspace: self.workspace.clone(),
_settings_subscription: cx.observe_global::<SettingsStore, _>(move |_, cx| cx.notify()), _settings_subscription: cx.observe_global::<SettingsStore>(move |_, cx| cx.notify()),
}) }))
} }
} }

View file

@ -46,7 +46,6 @@ impl ModalLayer {
previous_focus_handle: cx.focused(), previous_focus_handle: cx.focused(),
focus_handle: cx.focus_handle(), focus_handle: cx.focus_handle(),
}); });
dbg!("focusing");
cx.focus_view(&new_modal); cx.focus_view(&new_modal);
cx.notify(); cx.notify();
} }

View file

@ -1808,22 +1808,22 @@ impl Workspace {
pane pane
} }
// pub fn add_item_to_center( pub fn add_item_to_center(
// &mut self, &mut self,
// item: Box<dyn ItemHandle>, item: Box<dyn ItemHandle>,
// cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
// ) -> bool { ) -> bool {
// if let Some(center_pane) = self.last_active_center_pane.clone() { if let Some(center_pane) = self.last_active_center_pane.clone() {
// if let Some(center_pane) = center_pane.upgrade(cx) { if let Some(center_pane) = center_pane.upgrade() {
// center_pane.update(cx, |pane, cx| pane.add_item(item, true, true, None, cx)); center_pane.update(cx, |pane, cx| pane.add_item(item, true, true, None, cx));
// true true
// } else { } else {
// false false
// } }
// } else { } else {
// false false
// } }
// } }
pub fn add_item(&mut self, item: Box<dyn ItemHandle>, cx: &mut ViewContext<Self>) { pub fn add_item(&mut self, item: Box<dyn ItemHandle>, cx: &mut ViewContext<Self>) {
self.active_pane self.active_pane

View file

@ -13,7 +13,7 @@ use db::kvp::KEY_VALUE_STORE;
use editor::Editor; use editor::Editor;
use fs::RealFs; use fs::RealFs;
use futures::StreamExt; use futures::StreamExt;
use gpui::{Action, App, AppContext, AsyncAppContext, Context, SemanticVersion, Task}; use gpui::{App, AppContext, AsyncAppContext, Context, SemanticVersion, Task};
use isahc::{prelude::Configurable, Request}; use isahc::{prelude::Configurable, Request};
use language::LanguageRegistry; use language::LanguageRegistry;
use log::LevelFilter; use log::LevelFilter;
@ -48,6 +48,7 @@ use util::{
paths, ResultExt, paths, ResultExt,
}; };
use uuid::Uuid; use uuid::Uuid;
use welcome::{show_welcome_experience, FIRST_OPEN};
use workspace::{AppState, WorkspaceStore}; use workspace::{AppState, WorkspaceStore};
use zed2::{ use zed2::{
build_window_options, ensure_only_instance, handle_cli_connection, initialize_workspace, build_window_options, ensure_only_instance, handle_cli_connection, initialize_workspace,
@ -163,17 +164,16 @@ fn main() {
// assistant::init(cx); // assistant::init(cx);
// component_test::init(cx); // component_test::init(cx);
// cx.spawn(|cx| watch_themes(fs.clone(), cx)).detach();
// cx.spawn(|_| watch_languages(fs.clone(), languages.clone())) // cx.spawn(|_| watch_languages(fs.clone(), languages.clone()))
// .detach(); // .detach();
// watch_file_types(fs.clone(), cx); // watch_file_types(fs.clone(), cx);
languages.set_theme(cx.theme().clone()); languages.set_theme(cx.theme().clone());
// cx.observe_global::<SettingsStore, _>({ cx.observe_global::<SettingsStore>({
// let languages = languages.clone(); let languages = languages.clone();
// move |cx| languages.set_theme(theme::current(cx).clone()) move |cx| languages.set_theme(cx.theme().clone())
// }) })
// .detach(); .detach();
client.telemetry().start(installation_id, session_id, cx); client.telemetry().start(installation_id, session_id, cx);
let telemetry_settings = *client::TelemetrySettings::get_global(cx); let telemetry_settings = *client::TelemetrySettings::get_global(cx);
@ -217,14 +217,13 @@ fn main() {
// journal2::init(app_state.clone(), cx); // journal2::init(app_state.clone(), cx);
// language_selector::init(cx); // language_selector::init(cx);
// theme_selector::init(cx); theme_selector::init(cx);
// activity_indicator::init(cx); // activity_indicator::init(cx);
// language_tools::init(cx); // language_tools::init(cx);
call::init(app_state.client.clone(), app_state.user_store.clone(), cx); call::init(app_state.client.clone(), app_state.user_store.clone(), cx);
collab_ui::init(&app_state, cx); collab_ui::init(&app_state, cx);
// feedback::init(cx); // feedback::init(cx);
// welcome::init(cx); welcome::init(cx);
// zed::init(&app_state, cx);
// cx.set_menus(menus::menus()); // cx.set_menus(menus::menus());
initialize_workspace(app_state.clone(), cx); initialize_workspace(app_state.clone(), cx);
@ -283,6 +282,7 @@ fn main() {
cx.spawn(|mut cx| async move { cx.spawn(|mut cx| async move {
// ignore errors here, we'll show a generic "not signed in" // ignore errors here, we'll show a generic "not signed in"
let _ = authenticate(client, &cx).await; let _ = authenticate(client, &cx).await;
//todo!()
// cx.update(|cx| workspace::join_channel(channel_id, app_state, None, cx)) // cx.update(|cx| workspace::join_channel(channel_id, app_state, None, cx))
// .await // .await
anyhow::Ok(()) anyhow::Ok(())
@ -367,7 +367,8 @@ 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_experience(app_state, cx))
.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| {
@ -705,44 +706,23 @@ fn load_embedded_fonts(cx: &AppContext) {
.unwrap(); .unwrap();
} }
// #[cfg(debug_assertions)] #[cfg(debug_assertions)]
// async fn watch_themes(fs: Arc<dyn Fs>, mut cx: AsyncAppContext) -> Option<()> { async fn watch_languages(fs: Arc<dyn fs::Fs>, languages: Arc<LanguageRegistry>) -> Option<()> {
// let mut events = fs use std::time::Duration;
// .watch("styles/src".as_ref(), Duration::from_millis(100))
// .await;
// while (events.next().await).is_some() {
// let output = Command::new("npm")
// .current_dir("styles")
// .args(["run", "build"])
// .output()
// .await
// .log_err()?;
// if output.status.success() {
// cx.update(|cx| theme_selector::reload(cx))
// } else {
// eprintln!(
// "build script failed {}",
// String::from_utf8_lossy(&output.stderr)
// );
// }
// }
// Some(())
// }
// #[cfg(debug_assertions)] let mut events = fs
// async fn watch_languages(fs: Arc<dyn Fs>, languages: Arc<LanguageRegistry>) -> Option<()> { .watch(
// let mut events = fs "crates/zed2/src/languages".as_ref(),
// .watch( Duration::from_millis(100),
// "crates/zed/src/languages".as_ref(), )
// Duration::from_millis(100), .await;
// ) while (events.next().await).is_some() {
// .await; languages.reload();
// while (events.next().await).is_some() { }
// languages.reload(); Some(())
// } }
// Some(())
// }
//todo!()
// #[cfg(debug_assertions)] // #[cfg(debug_assertions)]
// fn watch_file_types(fs: Arc<dyn Fs>, cx: &mut AppContext) { // fn watch_file_types(fs: Arc<dyn Fs>, cx: &mut AppContext) {
// cx.spawn(|mut cx| async move { // cx.spawn(|mut cx| async move {
@ -763,26 +743,10 @@ fn load_embedded_fonts(cx: &AppContext) {
// .detach() // .detach()
// } // }
// #[cfg(not(debug_assertions))] #[cfg(not(debug_assertions))]
// async fn watch_themes(_fs: Arc<dyn Fs>, _cx: AsyncAppContext) -> Option<()> { async fn watch_languages(_: Arc<dyn Fs>, _: Arc<LanguageRegistry>) -> Option<()> {
// None None
// } }
// #[cfg(not(debug_assertions))]
// async fn watch_languages(_: Arc<dyn Fs>, _: Arc<LanguageRegistry>) -> Option<()> {
// None
//
// #[cfg(not(debug_assertions))] // #[cfg(not(debug_assertions))]
// fn watch_file_types(_fs: Arc<dyn Fs>, _cx: &mut AppContext) {} // fn watch_file_types(_fs: Arc<dyn Fs>, _cx: &mut AppContext) {}
pub fn background_actions() -> &'static [(&'static str, &'static dyn Action)] {
// &[
// ("Go to file", &file_finder::Toggle),
// ("Open command palette", &command_palette::Toggle),
// ("Open recent projects", &recent_projects::OpenRecent),
// ("Change your settings", &zed_actions::OpenSettings),
// ]
// todo!()
&[]
}