This commit is contained in:
Mikayla 2023-11-08 12:49:09 -08:00
parent 409e17ad30
commit 097efdebc5
No known key found for this signature in database
7 changed files with 79 additions and 52 deletions

1
Cargo.lock generated
View File

@ -11279,6 +11279,7 @@ dependencies = [
"libc",
"log",
"lsp2",
"menu2",
"node_runtime",
"num_cpus",
"parking_lot 0.11.2",

View File

@ -1,7 +1,7 @@
use editor::Editor;
use gpui::{
actions, div, AppContext, Div, EventEmitter, ParentElement, Render, SharedString, Styled, View,
ViewContext, VisualContext,
actions, div, AppContext, Div, EventEmitter, ParentElement, Render, SharedString,
StatelessInteractive, Styled, View, ViewContext, VisualContext,
};
use text::Point;
use theme::ActiveTheme;
@ -9,7 +9,7 @@ use ui::{h_stack, modal, v_stack, Label, LabelColor};
use util::paths::FILE_ROW_COLUMN_DELIMITER;
use workspace::ModalRegistry;
actions!(Toggle, Cancel, Confirm);
actions!(Toggle);
pub fn init(cx: &mut AppContext) {
cx.global_mut::<ModalRegistry>()
@ -20,10 +20,6 @@ pub fn init(cx: &mut AppContext) {
Some(cx.build_view(|cx| GoToLine::new(editor, cx)))
});
// cx.add_action(GoToLine::toggle);
// cx.add_action(GoToLine::confirm);
// cx.add_action(GoToLine::cancel);
}
pub struct GoToLine {
@ -37,7 +33,7 @@ pub enum Event {
}
impl EventEmitter for GoToLine {
type Event = Event;
type Event = ModalEvent;
}
impl GoToLine {
@ -45,6 +41,7 @@ impl GoToLine {
let line_editor = cx.build_view(|cx| {
let mut editor = Editor::single_line(cx);
editor.set_placeholder_text("Find something", cx);
editor.focus(cx);
editor
});
cx.subscribe(&line_editor, Self::on_line_editor_event)
@ -98,23 +95,24 @@ impl GoToLine {
))
}
// fn cancel(&mut self, _: &Cancel, cx: &mut ViewContext<Self>) {
// cx.emit(Event::Dismissed);
// }
fn cancel(&mut self, _: &menu::Cancel, cx: &mut ViewContext<Self>) {
println!("CANCLE");
cx.emit(Event::Dismissed);
}
// fn confirm(&mut self, _: &Confirm, cx: &mut ViewContext<Self>) {
// if let Some(point) = self.point_from_query(cx) {
// self.active_editor.update(cx, |active_editor, cx| {
// let snapshot = active_editor.snapshot(cx).display_snapshot;
// let point = snapshot.buffer_snapshot.clip_point(point, Bias::Left);
// active_editor.change_selections(Some(Autoscroll::center()), cx, |s| {
// s.select_ranges([point..point])
// });
// });
// }
fn confirm(&mut self, _: &menu::Confirm, cx: &mut ViewContext<Self>) {
// // if let Some(point) = self.point_from_query(cx) {
// // self.active_editor.update(cx, |active_editor, cx| {
// // let snapshot = active_editor.snapshot(cx).display_snapshot;
// // let point = snapshot.buffer_snapshot.clip_point(point, Bias::Left);
// // active_editor.change_selections(Some(Autoscroll::center()), cx, |s| {
// // s.select_ranges([point..point])
// // });
// // });
// // }
// cx.emit(Event::Dismissed);
// }
// cx.emit(Event::Dismissed);
}
fn status_text(&self) -> SharedString {
"Default text".into()
@ -125,31 +123,35 @@ impl Render for GoToLine {
type Element = Div<Self>;
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
modal(cx).w_96().child(
v_stack()
.px_1()
.pt_0p5()
.gap_px()
.child(
v_stack()
.py_0p5()
.px_1()
.child(div().px_1().py_0p5().child(self.line_editor.clone())),
)
.child(
div()
.h_px()
.w_full()
.bg(cx.theme().colors().element_background),
)
.child(
h_stack()
.justify_between()
.px_2()
.py_1()
.child(Label::new(self.status_text()).color(LabelColor::Muted)),
),
)
modal(cx)
.w_96()
.on_action(Self::cancel)
.on_action(Self::confirm)
.child(
v_stack()
.px_1()
.pt_0p5()
.gap_px()
.child(
v_stack()
.py_0p5()
.px_1()
.child(div().px_1().py_0p5().child(self.line_editor.clone())),
)
.child(
div()
.h_px()
.w_full()
.bg(cx.theme().colors().element_background),
)
.child(
h_stack()
.justify_between()
.px_2()
.py_1()
.child(Label::new(self.status_text()).color(LabelColor::Muted)),
),
)
}
}

View File

@ -123,6 +123,7 @@ pub fn register_action<A: Action>() {
/// Construct an action based on its name and optional JSON parameters sourced from the keymap.
pub fn build_action(name: &str, params: Option<serde_json::Value>) -> Result<Box<dyn Action>> {
let lock = ACTION_REGISTRY.read();
let build_action = lock
.builders_by_name
.get(name)

View File

@ -1,4 +1,9 @@
use gpui::actions;
use gpui::{actions, ctor};
// todo!(remove this)
// https://github.com/rust-lang/rust/issues/47384
// https://github.com/mmastrac/rust-ctor/issues/280
pub fn unused() {}
actions!(
Cancel,

View File

@ -1,7 +1,7 @@
use crate::Workspace;
use gpui::{
div, px, AnyView, AppContext, Component, Div, ParentElement, Render, StatelessInteractive,
Styled, View, ViewContext,
Styled, View, ViewContext, EventEmitter,
};
use std::{any::TypeId, sync::Arc};
use ui::v_stack;
@ -27,10 +27,18 @@ struct ToggleModal {
name: String,
}
pub enum ModalEvents {
Dismissed
}
trait Modal: EventEmitter + Render {
fn to_modal_events(&Self::Event) -> Option<ModalEvents>;
}
impl ModalRegistry {
pub fn register_modal<A: 'static, V, B>(&mut self, action: A, build_view: B)
where
V: Render,
V: Modal,
B: Fn(&Workspace, &mut ViewContext<Workspace>) -> Option<View<V>> + 'static,
{
let build_view = Arc::new(build_view);
@ -45,10 +53,15 @@ impl ModalRegistry {
let Some(new_modal) = (build_view)(workspace, cx) else {
return;
};
workspace.modal_layer.update(cx, |modal_layer, _| {
modal_layer.open_modal = Some(new_modal.into());
});
cx.subscribe(new_modal, |e, modal, cx| {
match modal.to_modal_events(e) {
Some(Dismissed) =>
dismissed -> whatever
}
})
cx.notify();
},

View File

@ -48,6 +48,7 @@ journal = { package = "journal2", path = "../journal2" }
language = { package = "language2", path = "../language2" }
# language_selector = { path = "../language_selector" }
lsp = { package = "lsp2", path = "../lsp2" }
menu = { package = "menu2", path = "../menu2" }
language_tools = { path = "../language_tools" }
node_runtime = { path = "../node_runtime" }
# assistant = { path = "../assistant" }

View File

@ -56,6 +56,10 @@ use zed2::{
mod open_listener;
fn main() {
//TODO!(figure out what the linker issues are here)
// https://github.com/rust-lang/rust/issues/47384
// https://github.com/mmastrac/rust-ctor/issues/280
menu::unused();
let http = http::client();
init_paths();
init_logger();