Merge branch 'main' into event-emitter
This commit is contained in:
commit
2c67cc80ba
30 changed files with 756 additions and 511 deletions
|
@ -418,6 +418,14 @@ impl Dock {
|
|||
// }
|
||||
}
|
||||
|
||||
impl Render for Dock {
|
||||
type Element = Div<Self>;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
// todo!()
|
||||
// impl View for Dock {
|
||||
// fn ui_name() -> &'static str {
|
||||
|
|
|
@ -1,35 +1,34 @@
|
|||
use crate::Workspace;
|
||||
use gpui::{
|
||||
div, AnyView, AppContext, Div, ParentElement, Render, StatelessInteractive, View, ViewContext,
|
||||
div, px, AnyView, Component, Div, EventEmitter, ParentElement, Render, StatelessInteractive,
|
||||
Styled, Subscription, View, ViewContext,
|
||||
};
|
||||
use std::{any::TypeId, sync::Arc};
|
||||
use ui::v_stack;
|
||||
|
||||
pub struct ModalRegistry {
|
||||
pub struct ModalLayer {
|
||||
open_modal: Option<AnyView>,
|
||||
subscription: Option<Subscription>,
|
||||
registered_modals: Vec<(TypeId, Box<dyn Fn(Div<Workspace>) -> Div<Workspace>>)>,
|
||||
}
|
||||
|
||||
pub trait Modal {}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ModalLayer {
|
||||
open_modal: Option<AnyView>,
|
||||
pub enum ModalEvent {
|
||||
Dismissed,
|
||||
}
|
||||
|
||||
pub fn init_modal_registry(cx: &mut AppContext) {
|
||||
cx.set_global(ModalRegistry {
|
||||
registered_modals: Vec::new(),
|
||||
});
|
||||
}
|
||||
impl ModalLayer {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
open_modal: None,
|
||||
subscription: None,
|
||||
registered_modals: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
struct ToggleModal {
|
||||
name: String,
|
||||
}
|
||||
|
||||
impl ModalRegistry {
|
||||
pub fn register_modal<A: 'static, V, B>(&mut self, action: A, build_view: B)
|
||||
where
|
||||
V: Render,
|
||||
B: Fn(&Workspace, &mut ViewContext<Workspace>) -> View<V> + 'static,
|
||||
V: EventEmitter<ModalEvent> + Render,
|
||||
B: Fn(&mut Workspace, &mut ViewContext<Workspace>) -> Option<View<V>> + 'static,
|
||||
{
|
||||
let build_view = Arc::new(build_view);
|
||||
|
||||
|
@ -38,42 +37,56 @@ impl ModalRegistry {
|
|||
Box::new(move |mut div| {
|
||||
let build_view = build_view.clone();
|
||||
|
||||
div.on_action(
|
||||
move |workspace: &mut Workspace, event: &A, cx: &mut ViewContext<Workspace>| {
|
||||
let new_modal = (build_view)(workspace, cx);
|
||||
workspace.modal_layer.update(cx, |modal_layer, _| {
|
||||
modal_layer.open_modal = Some(new_modal.into());
|
||||
});
|
||||
|
||||
cx.notify();
|
||||
},
|
||||
)
|
||||
div.on_action(move |workspace, event: &A, cx| {
|
||||
let Some(new_modal) = (build_view)(workspace, cx) else {
|
||||
return;
|
||||
};
|
||||
workspace.modal_layer().show_modal(new_modal, cx);
|
||||
})
|
||||
}),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
impl ModalLayer {
|
||||
pub fn new() -> Self {
|
||||
Self { open_modal: None }
|
||||
pub fn show_modal<V>(&mut self, new_modal: View<V>, cx: &mut ViewContext<Workspace>)
|
||||
where
|
||||
V: EventEmitter<ModalEvent> + Render,
|
||||
{
|
||||
self.subscription = Some(cx.subscribe(&new_modal, |this, modal, e, cx| match e {
|
||||
ModalEvent::Dismissed => this.modal_layer().hide_modal(cx),
|
||||
}));
|
||||
self.open_modal = Some(new_modal.into());
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn render(&self, workspace: &Workspace, cx: &ViewContext<Workspace>) -> Div<Workspace> {
|
||||
let mut div = div();
|
||||
pub fn hide_modal(&mut self, cx: &mut ViewContext<Workspace>) {
|
||||
self.open_modal.take();
|
||||
self.subscription.take();
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
// div, c workspace.toggle_modal()div.on_action()) {
|
||||
//
|
||||
// }
|
||||
pub fn wrapper_element(&self, cx: &ViewContext<Workspace>) -> Div<Workspace> {
|
||||
let mut parent = div().relative().size_full();
|
||||
|
||||
// for (type_id, action) in cx.global::<ModalRegistry>().registered_modals.iter() {
|
||||
// div = div.useful_on_action(*type_id, action)
|
||||
// }
|
||||
|
||||
for (_, action) in cx.global::<ModalRegistry>().registered_modals.iter() {
|
||||
div = (action)(div);
|
||||
for (_, action) in self.registered_modals.iter() {
|
||||
parent = (action)(parent);
|
||||
}
|
||||
|
||||
div.children(self.open_modal.clone())
|
||||
parent.when_some(self.open_modal.as_ref(), |parent, open_modal| {
|
||||
let container1 = div()
|
||||
.absolute()
|
||||
.flex()
|
||||
.flex_col()
|
||||
.items_center()
|
||||
.size_full()
|
||||
.top_0()
|
||||
.left_0()
|
||||
.z_index(400);
|
||||
|
||||
// transparent layer
|
||||
let container2 = v_stack().h(px(0.0)).relative().top_20();
|
||||
|
||||
parent.child(container1.child(container2.child(open_modal.clone())))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use crate::ItemHandle;
|
||||
use gpui::{AnyView, Entity, EntityId, EventEmitter, Render, View, ViewContext, WindowContext};
|
||||
use gpui::{
|
||||
AnyView, Div, Entity, EntityId, EventEmitter, Render, View, ViewContext, WindowContext,
|
||||
};
|
||||
|
||||
pub enum ToolbarItemEvent {
|
||||
ChangeLocation(ToolbarItemLocation),
|
||||
|
@ -49,6 +51,14 @@ pub struct Toolbar {
|
|||
items: Vec<(Box<dyn ToolbarItemViewHandle>, ToolbarItemLocation)>,
|
||||
}
|
||||
|
||||
impl Render for Toolbar {
|
||||
type Element = Div<Self>;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
// todo!()
|
||||
// impl View for Toolbar {
|
||||
// fn ui_name() -> &'static str {
|
||||
|
@ -125,61 +135,6 @@ pub struct Toolbar {
|
|||
// }
|
||||
// }
|
||||
|
||||
// <<<<<<< HEAD
|
||||
// =======
|
||||
// #[allow(clippy::too_many_arguments)]
|
||||
// fn nav_button<A: Action, F: 'static + Fn(&mut Toolbar, &mut ViewContext<Toolbar>)>(
|
||||
// svg_path: &'static str,
|
||||
// style: theme::Interactive<theme::IconButton>,
|
||||
// nav_button_height: f32,
|
||||
// tooltip_style: TooltipStyle,
|
||||
// enabled: bool,
|
||||
// spacing: f32,
|
||||
// on_click: F,
|
||||
// tooltip_action: A,
|
||||
// action_name: &'static str,
|
||||
// cx: &mut ViewContext<Toolbar>,
|
||||
// ) -> AnyElement<Toolbar> {
|
||||
// MouseEventHandler::new::<A, _>(0, cx, |state, _| {
|
||||
// let style = if enabled {
|
||||
// style.style_for(state)
|
||||
// } else {
|
||||
// style.disabled_style()
|
||||
// };
|
||||
// Svg::new(svg_path)
|
||||
// .with_color(style.color)
|
||||
// .constrained()
|
||||
// .with_width(style.icon_width)
|
||||
// .aligned()
|
||||
// .contained()
|
||||
// .with_style(style.container)
|
||||
// .constrained()
|
||||
// .with_width(style.button_width)
|
||||
// .with_height(nav_button_height)
|
||||
// .aligned()
|
||||
// .top()
|
||||
// })
|
||||
// .with_cursor_style(if enabled {
|
||||
// CursorStyle::PointingHand
|
||||
// } else {
|
||||
// CursorStyle::default()
|
||||
// })
|
||||
// .on_click(MouseButton::Left, move |_, toolbar, cx| {
|
||||
// on_click(toolbar, cx)
|
||||
// })
|
||||
// .with_tooltip::<A>(
|
||||
// 0,
|
||||
// action_name,
|
||||
// Some(Box::new(tooltip_action)),
|
||||
// tooltip_style,
|
||||
// cx,
|
||||
// )
|
||||
// .contained()
|
||||
// .with_margin_right(spacing)
|
||||
// .into_any_named("nav button")
|
||||
// }
|
||||
|
||||
// >>>>>>> 139cbbfd3aebd0863a7d51b0c12d748764cf0b2e
|
||||
impl Toolbar {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
|
|
|
@ -46,8 +46,7 @@ use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ItemSettings,
|
|||
use itertools::Itertools;
|
||||
use language2::LanguageRegistry;
|
||||
use lazy_static::lazy_static;
|
||||
pub use modal_layer::ModalRegistry;
|
||||
use modal_layer::{init_modal_registry, ModalLayer};
|
||||
pub use modal_layer::*;
|
||||
use node_runtime::NodeRuntime;
|
||||
use notifications::{simple_message_notification::MessageNotification, NotificationHandle};
|
||||
pub use pane::*;
|
||||
|
@ -224,7 +223,6 @@ pub fn init_settings(cx: &mut AppContext) {
|
|||
|
||||
pub fn init(app_state: Arc<AppState>, cx: &mut AppContext) {
|
||||
init_settings(cx);
|
||||
init_modal_registry(cx);
|
||||
pane::init(cx);
|
||||
notifications::init(cx);
|
||||
|
||||
|
@ -544,7 +542,7 @@ pub struct Workspace {
|
|||
last_active_center_pane: Option<WeakView<Pane>>,
|
||||
last_active_view_id: Option<proto::ViewId>,
|
||||
status_bar: View<StatusBar>,
|
||||
modal_layer: View<ModalLayer>,
|
||||
modal_layer: ModalLayer,
|
||||
// titlebar_item: Option<AnyViewHandle>,
|
||||
notifications: Vec<(TypeId, usize, Box<dyn NotificationHandle>)>,
|
||||
project: Model<Project>,
|
||||
|
@ -695,7 +693,8 @@ impl Workspace {
|
|||
status_bar
|
||||
});
|
||||
|
||||
let modal_layer = cx.build_view(|cx| ModalLayer::new());
|
||||
let workspace_handle = cx.view().downgrade();
|
||||
let modal_layer = ModalLayer::new();
|
||||
|
||||
// todo!()
|
||||
// cx.update_default_global::<DragAndDrop<Workspace>, _, _>(|drag_and_drop, _| {
|
||||
|
@ -779,6 +778,10 @@ impl Workspace {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn modal_layer(&mut self) -> &mut ModalLayer {
|
||||
&mut self.modal_layer
|
||||
}
|
||||
|
||||
fn new_local(
|
||||
abs_paths: Vec<PathBuf>,
|
||||
app_state: Arc<AppState>,
|
||||
|
@ -3719,13 +3722,13 @@ impl Render for Workspace {
|
|||
.bg(cx.theme().colors().background)
|
||||
.child(self.render_titlebar(cx))
|
||||
.child(
|
||||
// todo! should this be a component a view?
|
||||
self.modal_layer
|
||||
.read(cx)
|
||||
.render(self, cx)
|
||||
.wrapper_element(cx)
|
||||
.relative()
|
||||
.flex_1()
|
||||
.w_full()
|
||||
.flex()
|
||||
.flex_row()
|
||||
.overflow_hidden()
|
||||
.border_t()
|
||||
.border_b()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue