Wire up GoToLine modal

This commit is contained in:
Conrad Irwin 2023-11-07 12:07:04 -07:00
parent 0233864e92
commit 1e6a0f1c7b
3 changed files with 9 additions and 19 deletions

View file

@ -1,12 +1,10 @@
use gpui::{div, px, red, AppContext, Div, Render, Styled, ViewContext, VisualContext}; use gpui::{actions, div, px, red, AppContext, Div, Render, Styled, ViewContext, VisualContext};
use serde::Deserialize;
use workspace::ModalRegistry; use workspace::ModalRegistry;
// actions!(go_to_line, [Toggle]); actions!(Toggle);
#[derive(Clone, Default, PartialEq, Deserialize)]
struct Toggle;
pub fn init(cx: &mut AppContext) { pub fn init(cx: &mut AppContext) {
cx.register_action_type::<Toggle>();
cx.global_mut::<ModalRegistry>() cx.global_mut::<ModalRegistry>()
.register_modal(Toggle, |_, cx| { .register_modal(Toggle, |_, cx| {
// if let Some(editor) = workspace // if let Some(editor) = workspace

View file

@ -1,8 +1,8 @@
use std::{any::TypeId, sync::Arc}; use std::{any::TypeId, sync::Arc};
use gpui::{ use gpui::{
div, AnyView, AppContext, Component, DispatchPhase, Div, ParentElement, Render, div, AnyView, AppContext, DispatchPhase, Div, ParentElement, Render, StatelessInteractive,
StatelessInteractive, View, ViewContext, View, ViewContext,
}; };
use crate::Workspace; use crate::Workspace;
@ -28,10 +28,6 @@ struct ToggleModal {
name: String, name: String,
} }
// complete change of plan?
// on_action(ToggleModal{ name})
// register_modal(name, |workspace, cx| { ... })
impl ModalRegistry { impl ModalRegistry {
pub fn register_modal<A: 'static, V, B>(&mut self, action: A, build_view: B) pub fn register_modal<A: 'static, V, B>(&mut self, action: A, build_view: B)
where where
@ -40,12 +36,10 @@ impl ModalRegistry {
{ {
let build_view = Arc::new(build_view); let build_view = Arc::new(build_view);
dbg!("yonder");
self.registered_modals.push(( self.registered_modals.push((
TypeId::of::<A>(), TypeId::of::<A>(),
Box::new(move |mut div| { Box::new(move |mut div| {
let build_view = build_view.clone(); let build_view = build_view.clone();
dbg!("this point");
div.on_action( div.on_action(
move |workspace: &mut Workspace, move |workspace: &mut Workspace,
@ -75,9 +69,7 @@ impl ModalLayer {
Self { open_modal: None } Self { open_modal: None }
} }
pub fn render(&self, cx: &ViewContext<Workspace>) -> impl Component<Workspace> { pub fn render(&self, workspace: &Workspace, cx: &ViewContext<Workspace>) -> Div<Workspace> {
dbg!("rendering ModalLayer");
let mut div = div(); let mut div = div();
// div, c workspace.toggle_modal()div.on_action()) { // div, c workspace.toggle_modal()div.on_action()) {

View file

@ -3707,7 +3707,9 @@ impl Render for Workspace {
.bg(cx.theme().colors().background) .bg(cx.theme().colors().background)
.child(self.render_titlebar(cx)) .child(self.render_titlebar(cx))
.child( .child(
div() self.modal_layer
.read(cx)
.render(self, cx)
.flex_1() .flex_1()
.w_full() .w_full()
.flex() .flex()
@ -3840,8 +3842,6 @@ impl Render for Workspace {
// .on_click(Arc::new(|workspace, cx| workspace.toggle_debug(cx))), // .on_click(Arc::new(|workspace, cx| workspace.toggle_debug(cx))),
// ), // ),
) )
// .child(self.modal_layer.clone())
.child(self.modal_layer.read(cx).render(cx))
} }
} }