chore: clean up
This commit is contained in:
@@ -17,7 +17,7 @@ use gpui_native_core::context_menu::ContextMenu;
|
||||
use gpui_native_core::dialog::Dialog;
|
||||
use gpui_native_core::empty_state::EmptyState;
|
||||
use gpui_native_core::field::{Field, FieldVariant};
|
||||
use gpui_native_core::input::{Input, InputState, InputStateEvent};
|
||||
use gpui_native_core::input::{Input, InputState};
|
||||
use gpui_native_core::link::Link;
|
||||
use gpui_native_core::menu::{Menu, MenuItem};
|
||||
use gpui_native_core::popover::Popover;
|
||||
@@ -389,7 +389,9 @@ impl Gallery {
|
||||
cx,
|
||||
);
|
||||
dock.register_panel(
|
||||
PanelDescriptor::new("field", "Field", |_, cx| cx.new(FieldDemo::new).into()),
|
||||
PanelDescriptor::new("field", "Field", |window, cx| {
|
||||
cx.new(|cx| FieldDemo::new(window, cx)).into()
|
||||
}),
|
||||
cx,
|
||||
);
|
||||
dock.register_panel(
|
||||
@@ -822,6 +824,7 @@ struct InputDemo {
|
||||
text: Entity<InputState>,
|
||||
password: Entity<InputState>,
|
||||
notes: Entity<InputState>,
|
||||
_subscriptions: Vec<gpui::Subscription>,
|
||||
}
|
||||
|
||||
impl InputDemo {
|
||||
@@ -831,10 +834,18 @@ impl InputDemo {
|
||||
password.update(cx, |state, cx| state.set_password(true, cx));
|
||||
let notes = InputState::new(cx);
|
||||
notes.update(cx, |state, cx| state.set_multiline(true, cx));
|
||||
// The panel is a cached view in the dock: the value readouts re-render
|
||||
// only when the inputs it reads are notified.
|
||||
let subscriptions = vec![
|
||||
cx.observe(&text, |_, _, cx| cx.notify()),
|
||||
cx.observe(&password, |_, _, cx| cx.notify()),
|
||||
cx.observe(¬es, |_, _, cx| cx.notify()),
|
||||
];
|
||||
Self {
|
||||
text,
|
||||
password,
|
||||
notes,
|
||||
_subscriptions: subscriptions,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -871,24 +882,25 @@ struct FieldDemo {
|
||||
name: Entity<InputState>,
|
||||
notifications: bool,
|
||||
sync_on_open: bool,
|
||||
_subscription: gpui::Subscription,
|
||||
_subscriptions: (gpui::Subscription, gpui::Subscription),
|
||||
}
|
||||
|
||||
impl FieldDemo {
|
||||
fn new(cx: &mut Context<Self>) -> Self {
|
||||
fn new(_window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||
let url = InputState::new(cx);
|
||||
let name = InputState::new_with_text("reya", cx);
|
||||
let subscription = cx.subscribe(&url, |_, _, event, cx| {
|
||||
if matches!(event, InputStateEvent::TextChanged) {
|
||||
cx.notify();
|
||||
}
|
||||
});
|
||||
// The panel is a cached view in the dock: it re-renders only when the
|
||||
// entities it reads are notified. Both inputs are read at render time
|
||||
// (validation, error text), so every change must bust the cache.
|
||||
let url_observation = cx.observe(&url, |_, _, cx| cx.notify());
|
||||
let name_observation = cx.observe(&name, |_, _, cx| cx.notify());
|
||||
|
||||
Self {
|
||||
url,
|
||||
name,
|
||||
notifications: false,
|
||||
sync_on_open: true,
|
||||
_subscription: subscription,
|
||||
_subscriptions: (url_observation, name_observation),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1036,6 +1048,7 @@ struct ComboboxDemo {
|
||||
branch: Entity<ComboboxState<SharedString>>,
|
||||
label: Entity<ComboboxState<SharedString>>,
|
||||
label_created: Option<SharedString>,
|
||||
_subscriptions: Vec<gpui::Subscription>,
|
||||
}
|
||||
|
||||
impl ComboboxDemo {
|
||||
@@ -1087,10 +1100,17 @@ impl ComboboxDemo {
|
||||
});
|
||||
});
|
||||
let label = cx.new(|cx| ComboboxState::new(label_builder, window, cx));
|
||||
// The panel is a cached view in the dock: the value readouts re-render
|
||||
// only when the picker states it reads are notified.
|
||||
let subscriptions = vec![
|
||||
cx.observe(&branch, |_, _, cx| cx.notify()),
|
||||
cx.observe(&label, |_, _, cx| cx.notify()),
|
||||
];
|
||||
Self {
|
||||
branch,
|
||||
label,
|
||||
label_created: None,
|
||||
_subscriptions: subscriptions,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2835,7 +2855,15 @@ fn main() {
|
||||
gallery.downgrade(),
|
||||
cx,
|
||||
);
|
||||
dock.open_panel("welcome", window, cx);
|
||||
// TEMPORARY perf probe: open the field panel under the
|
||||
// autoplay env var so the probe types into a real window.
|
||||
let first = if std::env::var("GPUI_FIELD_AUTOPLAY").is_ok() {
|
||||
eprintln!("[field-probe] autoplay: opening field panel");
|
||||
"field"
|
||||
} else {
|
||||
"welcome"
|
||||
};
|
||||
dock.open_panel(first, window, cx);
|
||||
});
|
||||
gallery
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user