settings_ui: Add placeholder view (#15019)
This PR adds a placeholder view for the settings UI. It does not contain any functionality, as of yet. This view is staff-shipped behind a feature flag. Release Notes: - N/A
This commit is contained in:
parent
bdf1d4edea
commit
7d0386eff9
7 changed files with 144 additions and 1 deletions
107
crates/settings_ui/src/settings_ui.rs
Normal file
107
crates/settings_ui/src/settings_ui.rs
Normal file
|
@ -0,0 +1,107 @@
|
|||
use std::any::TypeId;
|
||||
|
||||
use command_palette_hooks::CommandPaletteFilter;
|
||||
use feature_flags::{FeatureFlag, FeatureFlagViewExt};
|
||||
use gpui::{actions, AppContext, EventEmitter, FocusHandle, FocusableView, View};
|
||||
use ui::prelude::*;
|
||||
use workspace::item::{Item, ItemEvent};
|
||||
use workspace::Workspace;
|
||||
|
||||
pub struct SettingsUiFeatureFlag;
|
||||
|
||||
impl FeatureFlag for SettingsUiFeatureFlag {
|
||||
const NAME: &'static str = "settings-ui";
|
||||
}
|
||||
|
||||
actions!(zed, [OpenSettingsEditor]);
|
||||
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
cx.observe_new_views(|workspace: &mut Workspace, cx| {
|
||||
workspace.register_action(|workspace, _: &OpenSettingsEditor, cx| {
|
||||
let existing = workspace
|
||||
.active_pane()
|
||||
.read(cx)
|
||||
.items()
|
||||
.find_map(|item| item.downcast::<SettingsPage>());
|
||||
|
||||
if let Some(existing) = existing {
|
||||
workspace.activate_item(&existing, true, true, cx);
|
||||
} else {
|
||||
let settings_page = SettingsPage::new(workspace, cx);
|
||||
workspace.add_item_to_active_pane(Box::new(settings_page), None, true, cx)
|
||||
}
|
||||
});
|
||||
|
||||
let settings_ui_actions = [TypeId::of::<OpenSettingsEditor>()];
|
||||
|
||||
CommandPaletteFilter::update_global(cx, |filter, _cx| {
|
||||
filter.hide_action_types(&settings_ui_actions);
|
||||
});
|
||||
|
||||
cx.observe_flag::<SettingsUiFeatureFlag, _>(move |is_enabled, _view, cx| {
|
||||
if is_enabled {
|
||||
CommandPaletteFilter::update_global(cx, |filter, _cx| {
|
||||
filter.show_action_types(settings_ui_actions.iter());
|
||||
});
|
||||
} else {
|
||||
CommandPaletteFilter::update_global(cx, |filter, _cx| {
|
||||
filter.hide_action_types(&settings_ui_actions);
|
||||
});
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
|
||||
pub struct SettingsPage {
|
||||
focus_handle: FocusHandle,
|
||||
}
|
||||
|
||||
impl SettingsPage {
|
||||
pub fn new(_workspace: &Workspace, cx: &mut ViewContext<Workspace>) -> View<Self> {
|
||||
cx.new_view(|cx| Self {
|
||||
focus_handle: cx.focus_handle(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl EventEmitter<ItemEvent> for SettingsPage {}
|
||||
|
||||
impl FocusableView for SettingsPage {
|
||||
fn focus_handle(&self, _cx: &AppContext) -> FocusHandle {
|
||||
self.focus_handle.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl Item for SettingsPage {
|
||||
type Event = ItemEvent;
|
||||
|
||||
fn tab_icon(&self, _cx: &WindowContext) -> Option<Icon> {
|
||||
Some(Icon::new(IconName::Settings))
|
||||
}
|
||||
|
||||
fn tab_content_text(&self, _cx: &WindowContext) -> Option<SharedString> {
|
||||
Some("Settings".into())
|
||||
}
|
||||
|
||||
fn show_toolbar(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn to_item_events(event: &Self::Event, mut f: impl FnMut(ItemEvent)) {
|
||||
f(*event)
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for SettingsPage {
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
v_flex()
|
||||
.p_4()
|
||||
.size_full()
|
||||
.child(Label::new("Settings").size(LabelSize::Large))
|
||||
.child(Label::new(
|
||||
"Nothing to see here yet. Feature-flagged for staff.",
|
||||
))
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue