WIP
This commit is contained in:
parent
409e17ad30
commit
097efdebc5
7 changed files with 79 additions and 52 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -11279,6 +11279,7 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"log",
|
"log",
|
||||||
"lsp2",
|
"lsp2",
|
||||||
|
"menu2",
|
||||||
"node_runtime",
|
"node_runtime",
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
"parking_lot 0.11.2",
|
"parking_lot 0.11.2",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use editor::Editor;
|
use editor::Editor;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, div, AppContext, Div, EventEmitter, ParentElement, Render, SharedString, Styled, View,
|
actions, div, AppContext, Div, EventEmitter, ParentElement, Render, SharedString,
|
||||||
ViewContext, VisualContext,
|
StatelessInteractive, Styled, View, ViewContext, VisualContext,
|
||||||
};
|
};
|
||||||
use text::Point;
|
use text::Point;
|
||||||
use theme::ActiveTheme;
|
use theme::ActiveTheme;
|
||||||
|
@ -9,7 +9,7 @@ use ui::{h_stack, modal, v_stack, Label, LabelColor};
|
||||||
use util::paths::FILE_ROW_COLUMN_DELIMITER;
|
use util::paths::FILE_ROW_COLUMN_DELIMITER;
|
||||||
use workspace::ModalRegistry;
|
use workspace::ModalRegistry;
|
||||||
|
|
||||||
actions!(Toggle, Cancel, Confirm);
|
actions!(Toggle);
|
||||||
|
|
||||||
pub fn init(cx: &mut AppContext) {
|
pub fn init(cx: &mut AppContext) {
|
||||||
cx.global_mut::<ModalRegistry>()
|
cx.global_mut::<ModalRegistry>()
|
||||||
|
@ -20,10 +20,6 @@ pub fn init(cx: &mut AppContext) {
|
||||||
|
|
||||||
Some(cx.build_view(|cx| GoToLine::new(editor, cx)))
|
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 {
|
pub struct GoToLine {
|
||||||
|
@ -37,7 +33,7 @@ pub enum Event {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventEmitter for GoToLine {
|
impl EventEmitter for GoToLine {
|
||||||
type Event = Event;
|
type Event = ModalEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GoToLine {
|
impl GoToLine {
|
||||||
|
@ -45,6 +41,7 @@ impl GoToLine {
|
||||||
let line_editor = cx.build_view(|cx| {
|
let line_editor = cx.build_view(|cx| {
|
||||||
let mut editor = Editor::single_line(cx);
|
let mut editor = Editor::single_line(cx);
|
||||||
editor.set_placeholder_text("Find something", cx);
|
editor.set_placeholder_text("Find something", cx);
|
||||||
|
editor.focus(cx);
|
||||||
editor
|
editor
|
||||||
});
|
});
|
||||||
cx.subscribe(&line_editor, Self::on_line_editor_event)
|
cx.subscribe(&line_editor, Self::on_line_editor_event)
|
||||||
|
@ -98,23 +95,24 @@ impl GoToLine {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn cancel(&mut self, _: &Cancel, cx: &mut ViewContext<Self>) {
|
fn cancel(&mut self, _: &menu::Cancel, cx: &mut ViewContext<Self>) {
|
||||||
// cx.emit(Event::Dismissed);
|
println!("CANCLE");
|
||||||
// }
|
cx.emit(Event::Dismissed);
|
||||||
|
}
|
||||||
|
|
||||||
// fn confirm(&mut self, _: &Confirm, cx: &mut ViewContext<Self>) {
|
fn confirm(&mut self, _: &menu::Confirm, cx: &mut ViewContext<Self>) {
|
||||||
// if let Some(point) = self.point_from_query(cx) {
|
// // if let Some(point) = self.point_from_query(cx) {
|
||||||
// self.active_editor.update(cx, |active_editor, cx| {
|
// // self.active_editor.update(cx, |active_editor, cx| {
|
||||||
// let snapshot = active_editor.snapshot(cx).display_snapshot;
|
// // let snapshot = active_editor.snapshot(cx).display_snapshot;
|
||||||
// let point = snapshot.buffer_snapshot.clip_point(point, Bias::Left);
|
// // let point = snapshot.buffer_snapshot.clip_point(point, Bias::Left);
|
||||||
// active_editor.change_selections(Some(Autoscroll::center()), cx, |s| {
|
// // active_editor.change_selections(Some(Autoscroll::center()), cx, |s| {
|
||||||
// s.select_ranges([point..point])
|
// // s.select_ranges([point..point])
|
||||||
// });
|
// // });
|
||||||
// });
|
// // });
|
||||||
// }
|
// // }
|
||||||
|
|
||||||
// cx.emit(Event::Dismissed);
|
// cx.emit(Event::Dismissed);
|
||||||
// }
|
}
|
||||||
|
|
||||||
fn status_text(&self) -> SharedString {
|
fn status_text(&self) -> SharedString {
|
||||||
"Default text".into()
|
"Default text".into()
|
||||||
|
@ -125,7 +123,11 @@ impl Render for GoToLine {
|
||||||
type Element = Div<Self>;
|
type Element = Div<Self>;
|
||||||
|
|
||||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||||
modal(cx).w_96().child(
|
modal(cx)
|
||||||
|
.w_96()
|
||||||
|
.on_action(Self::cancel)
|
||||||
|
.on_action(Self::confirm)
|
||||||
|
.child(
|
||||||
v_stack()
|
v_stack()
|
||||||
.px_1()
|
.px_1()
|
||||||
.pt_0p5()
|
.pt_0p5()
|
||||||
|
|
|
@ -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.
|
/// 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>> {
|
pub fn build_action(name: &str, params: Option<serde_json::Value>) -> Result<Box<dyn Action>> {
|
||||||
let lock = ACTION_REGISTRY.read();
|
let lock = ACTION_REGISTRY.read();
|
||||||
|
|
||||||
let build_action = lock
|
let build_action = lock
|
||||||
.builders_by_name
|
.builders_by_name
|
||||||
.get(name)
|
.get(name)
|
||||||
|
|
|
@ -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!(
|
actions!(
|
||||||
Cancel,
|
Cancel,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::Workspace;
|
use crate::Workspace;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, px, AnyView, AppContext, Component, Div, ParentElement, Render, StatelessInteractive,
|
div, px, AnyView, AppContext, Component, Div, ParentElement, Render, StatelessInteractive,
|
||||||
Styled, View, ViewContext,
|
Styled, View, ViewContext, EventEmitter,
|
||||||
};
|
};
|
||||||
use std::{any::TypeId, sync::Arc};
|
use std::{any::TypeId, sync::Arc};
|
||||||
use ui::v_stack;
|
use ui::v_stack;
|
||||||
|
@ -27,10 +27,18 @@ struct ToggleModal {
|
||||||
name: String,
|
name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub enum ModalEvents {
|
||||||
|
Dismissed
|
||||||
|
}
|
||||||
|
|
||||||
|
trait Modal: EventEmitter + Render {
|
||||||
|
fn to_modal_events(&Self::Event) -> Option<ModalEvents>;
|
||||||
|
}
|
||||||
|
|
||||||
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
|
||||||
V: Render,
|
V: Modal,
|
||||||
B: Fn(&Workspace, &mut ViewContext<Workspace>) -> Option<View<V>> + 'static,
|
B: Fn(&Workspace, &mut ViewContext<Workspace>) -> Option<View<V>> + 'static,
|
||||||
{
|
{
|
||||||
let build_view = Arc::new(build_view);
|
let build_view = Arc::new(build_view);
|
||||||
|
@ -45,10 +53,15 @@ impl ModalRegistry {
|
||||||
let Some(new_modal) = (build_view)(workspace, cx) else {
|
let Some(new_modal) = (build_view)(workspace, cx) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
workspace.modal_layer.update(cx, |modal_layer, _| {
|
workspace.modal_layer.update(cx, |modal_layer, _| {
|
||||||
modal_layer.open_modal = Some(new_modal.into());
|
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();
|
cx.notify();
|
||||||
},
|
},
|
||||||
|
|
|
@ -48,6 +48,7 @@ journal = { package = "journal2", path = "../journal2" }
|
||||||
language = { package = "language2", path = "../language2" }
|
language = { package = "language2", path = "../language2" }
|
||||||
# language_selector = { path = "../language_selector" }
|
# language_selector = { path = "../language_selector" }
|
||||||
lsp = { package = "lsp2", path = "../lsp2" }
|
lsp = { package = "lsp2", path = "../lsp2" }
|
||||||
|
menu = { package = "menu2", path = "../menu2" }
|
||||||
language_tools = { path = "../language_tools" }
|
language_tools = { path = "../language_tools" }
|
||||||
node_runtime = { path = "../node_runtime" }
|
node_runtime = { path = "../node_runtime" }
|
||||||
# assistant = { path = "../assistant" }
|
# assistant = { path = "../assistant" }
|
||||||
|
|
|
@ -56,6 +56,10 @@ use zed2::{
|
||||||
mod open_listener;
|
mod open_listener;
|
||||||
|
|
||||||
fn main() {
|
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();
|
let http = http::client();
|
||||||
init_paths();
|
init_paths();
|
||||||
init_logger();
|
init_logger();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue