mirror of
https://github.com/zed-industries/zed.git
synced 2024-09-20 19:08:00 +03:00
WIP
This commit is contained in:
parent
d47ef6470b
commit
4d320f065e
@ -833,6 +833,10 @@ where
|
||||
self.platform().path_for_auxiliary_executable(name)
|
||||
}
|
||||
|
||||
pub fn displays(&self) -> Vec<Rc<dyn PlatformDisplay>> {
|
||||
self.platform().displays()
|
||||
}
|
||||
|
||||
pub fn display_for_uuid(&self, uuid: Uuid) -> Option<Rc<dyn PlatformDisplay>> {
|
||||
self.platform()
|
||||
.displays()
|
||||
@ -889,13 +893,14 @@ impl MainThread<AppContext> {
|
||||
pub fn open_window<V: Render>(
|
||||
&mut self,
|
||||
options: crate::WindowOptions,
|
||||
build_root_view: impl FnOnce(&mut WindowContext) -> View<V> + Send + 'static,
|
||||
build_root_view: impl FnOnce(&mut MainThread<WindowContext>) -> View<V> + Send + 'static,
|
||||
) -> WindowHandle<V> {
|
||||
self.update(|cx| {
|
||||
let id = cx.windows.insert(None);
|
||||
let handle = WindowHandle::new(id);
|
||||
let mut window = Window::new(handle.into(), options, cx);
|
||||
let root_view = build_root_view(&mut WindowContext::new(cx, &mut window));
|
||||
let mut window_context = MainThread(WindowContext::new(cx, &mut window));
|
||||
let root_view = build_root_view(&mut window_context);
|
||||
window.root_view.replace(root_view.into());
|
||||
cx.windows.get_mut(id).unwrap().replace(window);
|
||||
handle
|
||||
|
@ -5,7 +5,7 @@ use crate::{
|
||||
use anyhow::Context as _;
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use parking_lot::Mutex;
|
||||
use std::{future::Future, sync::Weak};
|
||||
use std::{future::Future, mem, sync::Weak};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct AsyncAppContext {
|
||||
@ -44,7 +44,9 @@ impl Context for AsyncAppContext {
|
||||
where
|
||||
F: FnOnce(&mut Self::WindowContext<'_>) -> T,
|
||||
{
|
||||
todo!()
|
||||
let app = self.app.upgrade().context("app was released")?;
|
||||
let mut lock = app.lock(); // Need this to compile
|
||||
lock.update_window(window, f)
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,14 +102,14 @@ impl AsyncAppContext {
|
||||
|
||||
pub fn spawn_on_main<Fut, R>(
|
||||
&self,
|
||||
f: impl FnOnce(AsyncAppContext) -> Fut + Send + 'static,
|
||||
f: impl FnOnce(MainThread<AsyncAppContext>) -> Fut + Send + 'static,
|
||||
) -> Task<R>
|
||||
where
|
||||
Fut: Future<Output = R> + 'static,
|
||||
R: Send + 'static,
|
||||
{
|
||||
let this = self.clone();
|
||||
self.executor.spawn_on_main(|| f(this))
|
||||
self.executor.spawn_on_main(|| f(MainThread(this)))
|
||||
}
|
||||
|
||||
pub fn run_on_main<R>(
|
||||
@ -153,6 +155,29 @@ impl AsyncAppContext {
|
||||
}
|
||||
}
|
||||
|
||||
impl MainThread<AsyncAppContext> {
|
||||
pub fn update<R>(&self, f: impl FnOnce(&mut MainThread<AppContext>) -> R) -> Result<R> {
|
||||
let app = self.app.upgrade().context("app was released")?;
|
||||
let cx = &mut *app.lock();
|
||||
let cx = unsafe { mem::transmute::<&mut AppContext, &mut MainThread<AppContext>>(cx) };
|
||||
Ok(f(cx))
|
||||
}
|
||||
|
||||
/// Opens a new window with the given option and the root view returned by the given function.
|
||||
/// The function is invoked with a `WindowContext`, which can be used to interact with window-specific
|
||||
/// functionality.
|
||||
pub fn open_window<V: Render>(
|
||||
&mut self,
|
||||
options: crate::WindowOptions,
|
||||
build_root_view: impl FnOnce(&mut MainThread<WindowContext>) -> View<V> + Send + 'static,
|
||||
) -> Result<WindowHandle<V>> {
|
||||
let app = self.app.upgrade().context("app was released")?;
|
||||
let cx = &mut *app.lock();
|
||||
let cx = unsafe { mem::transmute::<&mut AppContext, &mut MainThread<AppContext>>(cx) };
|
||||
Ok(cx.open_window(options, build_root_view))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Deref, DerefMut)]
|
||||
pub struct AsyncWindowContext {
|
||||
#[deref]
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::{private::Sealed, AnyBox, AppContext, AsyncAppContext, Context, Entity, ModelContext};
|
||||
use crate::{private::Sealed, AnyBox, AppContext, Context, Entity};
|
||||
use anyhow::{anyhow, Result};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use parking_lot::{RwLock, RwLockUpgradableReadGuard};
|
||||
|
@ -931,6 +931,18 @@ impl From<f64> for GlobalPixels {
|
||||
}
|
||||
}
|
||||
|
||||
impl sqlez::bindable::StaticColumnCount for GlobalPixels {}
|
||||
|
||||
impl sqlez::bindable::Bind for GlobalPixels {
|
||||
fn bind(
|
||||
&self,
|
||||
statement: &sqlez::statement::Statement,
|
||||
start_index: i32,
|
||||
) -> anyhow::Result<i32> {
|
||||
self.0.bind(statement, start_index)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Default, Add, Sub, Mul, Div, Neg)]
|
||||
pub struct Rems(f32);
|
||||
|
||||
|
@ -397,18 +397,17 @@ impl Bind for WindowBounds {
|
||||
}
|
||||
};
|
||||
|
||||
// statement.bind(
|
||||
// ®ion.map(|region| {
|
||||
// (
|
||||
// region.origin.x,
|
||||
// region.origin.y,
|
||||
// region.size.width,
|
||||
// region.size.height,
|
||||
// )
|
||||
// }),
|
||||
// next_index,
|
||||
// )
|
||||
todo!()
|
||||
statement.bind(
|
||||
®ion.map(|region| {
|
||||
(
|
||||
region.origin.x,
|
||||
region.origin.y,
|
||||
region.size.width,
|
||||
region.size.height,
|
||||
)
|
||||
}),
|
||||
next_index,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ use std::{
|
||||
borrow::{Borrow, BorrowMut, Cow},
|
||||
fmt::Debug,
|
||||
future::Future,
|
||||
hash::{Hash, Hasher},
|
||||
marker::PhantomData,
|
||||
mem,
|
||||
sync::{
|
||||
@ -2014,7 +2015,7 @@ impl WindowId {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Deref, DerefMut)]
|
||||
#[derive(Deref, DerefMut)]
|
||||
pub struct WindowHandle<V> {
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
@ -2062,13 +2063,27 @@ impl<V> Clone for WindowHandle<V> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<V> PartialEq for WindowHandle<V> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.any_handle == other.any_handle
|
||||
}
|
||||
}
|
||||
|
||||
impl<V> Eq for WindowHandle<V> {}
|
||||
|
||||
impl<V> Hash for WindowHandle<V> {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.any_handle.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: 'static> Into<AnyWindowHandle> for WindowHandle<V> {
|
||||
fn into(self) -> AnyWindowHandle {
|
||||
self.any_handle
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct AnyWindowHandle {
|
||||
pub(crate) id: WindowId,
|
||||
state_type: TypeId,
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::{status_bar::StatusItemView, Axis, Workspace};
|
||||
use gpui2::{
|
||||
Action, AnyView, Div, EventEmitter, Render, Subscription, View, ViewContext, WeakView,
|
||||
WindowContext,
|
||||
Action, AnyView, Div, Entity, EntityId, EventEmitter, Render, Subscription, View, ViewContext,
|
||||
WeakView, WindowContext,
|
||||
};
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -40,8 +40,8 @@ pub trait Panel: Render + EventEmitter {
|
||||
fn is_focus_event(_: &Self::Event) -> bool;
|
||||
}
|
||||
|
||||
pub trait PanelHandle {
|
||||
fn id(&self) -> usize;
|
||||
pub trait PanelHandle: Send + Sync {
|
||||
fn id(&self) -> EntityId;
|
||||
fn position(&self, cx: &WindowContext) -> DockPosition;
|
||||
fn position_is_valid(&self, position: DockPosition, cx: &WindowContext) -> bool;
|
||||
fn set_position(&self, position: DockPosition, cx: &mut WindowContext);
|
||||
@ -61,8 +61,8 @@ impl<T> PanelHandle for View<T>
|
||||
where
|
||||
T: Panel,
|
||||
{
|
||||
fn id(&self) -> usize {
|
||||
self.id()
|
||||
fn id(&self) -> EntityId {
|
||||
self.entity_id()
|
||||
}
|
||||
|
||||
fn position(&self, cx: &WindowContext) -> DockPosition {
|
||||
@ -178,18 +178,18 @@ pub struct PanelButtons {
|
||||
}
|
||||
|
||||
impl Dock {
|
||||
// pub fn new(position: DockPosition) -> Self {
|
||||
// Self {
|
||||
// position,
|
||||
// panel_entries: Default::default(),
|
||||
// active_panel_index: 0,
|
||||
// is_open: false,
|
||||
// }
|
||||
// }
|
||||
pub fn new(position: DockPosition) -> Self {
|
||||
Self {
|
||||
position,
|
||||
panel_entries: Default::default(),
|
||||
active_panel_index: 0,
|
||||
is_open: false,
|
||||
}
|
||||
}
|
||||
|
||||
// pub fn position(&self) -> DockPosition {
|
||||
// self.position
|
||||
// }
|
||||
pub fn position(&self) -> DockPosition {
|
||||
self.position
|
||||
}
|
||||
|
||||
pub fn is_open(&self) -> bool {
|
||||
self.is_open
|
||||
@ -432,17 +432,16 @@ impl Dock {
|
||||
// }
|
||||
// }
|
||||
|
||||
// todo!()
|
||||
// impl PanelButtons {
|
||||
// pub fn new(
|
||||
// dock: View<Dock>,
|
||||
// workspace: WeakViewHandle<Workspace>,
|
||||
// cx: &mut ViewContext<Self>,
|
||||
// ) -> Self {
|
||||
// cx.observe(&dock, |_, _, cx| cx.notify()).detach();
|
||||
// Self { dock, workspace }
|
||||
// }
|
||||
// }
|
||||
impl PanelButtons {
|
||||
pub fn new(
|
||||
dock: View<Dock>,
|
||||
workspace: WeakView<Workspace>,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Self {
|
||||
cx.observe(&dock, |_, _, cx| cx.notify()).detach();
|
||||
Self { dock, workspace }
|
||||
}
|
||||
}
|
||||
|
||||
impl EventEmitter for PanelButtons {
|
||||
type Event = ();
|
||||
|
@ -1,35 +1,36 @@
|
||||
use crate::{Toast, Workspace};
|
||||
use collections::HashMap;
|
||||
use gpui2::{AnyViewHandle, AppContext, Entity, View, ViewContext, ViewHandle};
|
||||
use gpui2::{AnyView, AppContext, Entity, EntityId, EventEmitter, Render, View, ViewContext};
|
||||
use std::{any::TypeId, ops::DerefMut};
|
||||
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
cx.set_global(NotificationTracker::new());
|
||||
simple_message_notification::init(cx);
|
||||
// todo!()
|
||||
// simple_message_notification::init(cx);
|
||||
}
|
||||
|
||||
pub trait Notification: View {
|
||||
fn should_dismiss_notification_on_event(&self, event: &<Self as Entity>::Event) -> bool;
|
||||
pub trait Notification: EventEmitter + Render {
|
||||
fn should_dismiss_notification_on_event(&self, event: &Self::Event) -> bool;
|
||||
}
|
||||
|
||||
pub trait NotificationHandle {
|
||||
fn id(&self) -> usize;
|
||||
fn as_any(&self) -> &AnyViewHandle;
|
||||
pub trait NotificationHandle: Send {
|
||||
fn id(&self) -> EntityId;
|
||||
fn to_any(&self) -> AnyView;
|
||||
}
|
||||
|
||||
impl<T: Notification> NotificationHandle for ViewHandle<T> {
|
||||
fn id(&self) -> usize {
|
||||
self.id()
|
||||
impl<T: Notification> NotificationHandle for View<T> {
|
||||
fn id(&self) -> EntityId {
|
||||
self.entity_id()
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &AnyViewHandle {
|
||||
self
|
||||
fn to_any(&self) -> AnyView {
|
||||
self.clone().into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&dyn NotificationHandle> for AnyViewHandle {
|
||||
impl From<&dyn NotificationHandle> for AnyView {
|
||||
fn from(val: &dyn NotificationHandle) -> Self {
|
||||
val.as_any().clone()
|
||||
val.to_any()
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,14 +76,12 @@ impl Workspace {
|
||||
&mut self,
|
||||
id: usize,
|
||||
cx: &mut ViewContext<Self>,
|
||||
build_notification: impl FnOnce(&mut ViewContext<Self>) -> ViewHandle<V>,
|
||||
build_notification: impl FnOnce(&mut ViewContext<Self>) -> View<V>,
|
||||
) {
|
||||
if !self.has_shown_notification_once::<V>(id, cx) {
|
||||
cx.update_global::<NotificationTracker, _, _>(|tracker, _| {
|
||||
let entry = tracker.entry(TypeId::of::<V>()).or_default();
|
||||
entry.push(id);
|
||||
});
|
||||
|
||||
let tracker = cx.global_mut::<NotificationTracker>();
|
||||
let entry = tracker.entry(TypeId::of::<V>()).or_default();
|
||||
entry.push(id);
|
||||
self.show_notification::<V>(id, cx, build_notification)
|
||||
}
|
||||
}
|
||||
@ -91,7 +90,7 @@ impl Workspace {
|
||||
&mut self,
|
||||
id: usize,
|
||||
cx: &mut ViewContext<Self>,
|
||||
build_notification: impl FnOnce(&mut ViewContext<Self>) -> ViewHandle<V>,
|
||||
build_notification: impl FnOnce(&mut ViewContext<Self>) -> View<V>,
|
||||
) {
|
||||
let type_id = TypeId::of::<V>();
|
||||
if self
|
||||
@ -121,22 +120,24 @@ impl Workspace {
|
||||
}
|
||||
|
||||
pub fn show_toast(&mut self, toast: Toast, cx: &mut ViewContext<Self>) {
|
||||
self.dismiss_notification::<simple_message_notification::MessageNotification>(toast.id, cx);
|
||||
self.show_notification(toast.id, cx, |cx| {
|
||||
cx.add_view(|_cx| match toast.on_click.as_ref() {
|
||||
Some((click_msg, on_click)) => {
|
||||
let on_click = on_click.clone();
|
||||
simple_message_notification::MessageNotification::new(toast.msg.clone())
|
||||
.with_click_message(click_msg.clone())
|
||||
.on_click(move |cx| on_click(cx))
|
||||
}
|
||||
None => simple_message_notification::MessageNotification::new(toast.msg.clone()),
|
||||
})
|
||||
})
|
||||
todo!()
|
||||
// self.dismiss_notification::<simple_message_notification::MessageNotification>(toast.id, cx);
|
||||
// self.show_notification(toast.id, cx, |cx| {
|
||||
// cx.add_view(|_cx| match toast.on_click.as_ref() {
|
||||
// Some((click_msg, on_click)) => {
|
||||
// let on_click = on_click.clone();
|
||||
// simple_message_notification::MessageNotification::new(toast.msg.clone())
|
||||
// .with_click_message(click_msg.clone())
|
||||
// .on_click(move |cx| on_click(cx))
|
||||
// }
|
||||
// None => simple_message_notification::MessageNotification::new(toast.msg.clone()),
|
||||
// })
|
||||
// })
|
||||
}
|
||||
|
||||
pub fn dismiss_toast(&mut self, id: usize, cx: &mut ViewContext<Self>) {
|
||||
self.dismiss_notification::<simple_message_notification::MessageNotification>(id, cx);
|
||||
todo!()
|
||||
// self.dismiss_notification::<simple_message_notification::MessageNotification>(id, cx);
|
||||
}
|
||||
|
||||
fn dismiss_notification_internal(
|
||||
@ -159,20 +160,12 @@ impl Workspace {
|
||||
|
||||
pub mod simple_message_notification {
|
||||
use super::Notification;
|
||||
use crate::Workspace;
|
||||
use gpui2::{
|
||||
actions,
|
||||
elements::{Flex, MouseEventHandler, Padding, ParentElement, Svg, Text},
|
||||
fonts::TextStyle,
|
||||
impl_actions,
|
||||
platform::{CursorStyle, MouseButton},
|
||||
AnyElement, AppContext, Element, Entity, View, ViewContext,
|
||||
};
|
||||
use menu::Cancel;
|
||||
use gpui2::{AnyElement, AppContext, Div, EventEmitter, Render, TextStyle, ViewContext};
|
||||
use serde::Deserialize;
|
||||
use std::{borrow::Cow, sync::Arc};
|
||||
|
||||
actions!(message_notifications, [CancelMessageNotification]);
|
||||
// todo!()
|
||||
// actions!(message_notifications, [CancelMessageNotification]);
|
||||
|
||||
#[derive(Clone, Default, Deserialize, PartialEq)]
|
||||
pub struct OsOpen(pub Cow<'static, str>);
|
||||
@ -183,16 +176,18 @@ pub mod simple_message_notification {
|
||||
}
|
||||
}
|
||||
|
||||
impl_actions!(message_notifications, [OsOpen]);
|
||||
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
cx.add_action(MessageNotification::dismiss);
|
||||
cx.add_action(
|
||||
|_workspace: &mut Workspace, open_action: &OsOpen, cx: &mut ViewContext<Workspace>| {
|
||||
cx.platform().open_url(open_action.0.as_ref());
|
||||
},
|
||||
)
|
||||
}
|
||||
// todo!()
|
||||
// impl_actions!(message_notifications, [OsOpen]);
|
||||
//
|
||||
// todo!()
|
||||
// pub fn init(cx: &mut AppContext) {
|
||||
// cx.add_action(MessageNotification::dismiss);
|
||||
// cx.add_action(
|
||||
// |_workspace: &mut Workspace, open_action: &OsOpen, cx: &mut ViewContext<Workspace>| {
|
||||
// cx.platform().open_url(open_action.0.as_ref());
|
||||
// },
|
||||
// )
|
||||
// }
|
||||
|
||||
enum NotificationMessage {
|
||||
Text(Cow<'static, str>),
|
||||
@ -201,7 +196,7 @@ pub mod simple_message_notification {
|
||||
|
||||
pub struct MessageNotification {
|
||||
message: NotificationMessage,
|
||||
on_click: Option<Arc<dyn Fn(&mut ViewContext<Self>)>>,
|
||||
on_click: Option<Arc<dyn Fn(&mut ViewContext<Self>) + Send + Sync>>,
|
||||
click_message: Option<Cow<'static, str>>,
|
||||
}
|
||||
|
||||
@ -209,7 +204,7 @@ pub mod simple_message_notification {
|
||||
Dismiss,
|
||||
}
|
||||
|
||||
impl Entity for MessageNotification {
|
||||
impl EventEmitter for MessageNotification {
|
||||
type Event = MessageNotificationEvent;
|
||||
}
|
||||
|
||||
@ -225,138 +220,147 @@ pub mod simple_message_notification {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_element(
|
||||
message: fn(TextStyle, &AppContext) -> AnyElement<MessageNotification>,
|
||||
) -> MessageNotification {
|
||||
Self {
|
||||
message: NotificationMessage::Element(message),
|
||||
on_click: None,
|
||||
click_message: None,
|
||||
}
|
||||
}
|
||||
// todo!()
|
||||
// pub fn new_element(
|
||||
// message: fn(TextStyle, &AppContext) -> AnyElement<MessageNotification>,
|
||||
// ) -> MessageNotification {
|
||||
// Self {
|
||||
// message: NotificationMessage::Element(message),
|
||||
// on_click: None,
|
||||
// click_message: None,
|
||||
// }
|
||||
// }
|
||||
|
||||
pub fn with_click_message<S>(mut self, message: S) -> Self
|
||||
where
|
||||
S: Into<Cow<'static, str>>,
|
||||
{
|
||||
self.click_message = Some(message.into());
|
||||
self
|
||||
}
|
||||
// pub fn with_click_message<S>(mut self, message: S) -> Self
|
||||
// where
|
||||
// S: Into<Cow<'static, str>>,
|
||||
// {
|
||||
// self.click_message = Some(message.into());
|
||||
// self
|
||||
// }
|
||||
|
||||
pub fn on_click<F>(mut self, on_click: F) -> Self
|
||||
where
|
||||
F: 'static + Fn(&mut ViewContext<Self>),
|
||||
{
|
||||
self.on_click = Some(Arc::new(on_click));
|
||||
self
|
||||
}
|
||||
// pub fn on_click<F>(mut self, on_click: F) -> Self
|
||||
// where
|
||||
// F: 'static + Fn(&mut ViewContext<Self>),
|
||||
// {
|
||||
// self.on_click = Some(Arc::new(on_click));
|
||||
// self
|
||||
// }
|
||||
|
||||
pub fn dismiss(&mut self, _: &CancelMessageNotification, cx: &mut ViewContext<Self>) {
|
||||
cx.emit(MessageNotificationEvent::Dismiss);
|
||||
}
|
||||
// pub fn dismiss(&mut self, _: &CancelMessageNotification, cx: &mut ViewContext<Self>) {
|
||||
// cx.emit(MessageNotificationEvent::Dismiss);
|
||||
// }
|
||||
}
|
||||
|
||||
impl View for MessageNotification {
|
||||
fn ui_name() -> &'static str {
|
||||
"MessageNotification"
|
||||
}
|
||||
impl Render for MessageNotification {
|
||||
type Element = Div<Self>;
|
||||
|
||||
fn render(&mut self, cx: &mut gpui2::ViewContext<Self>) -> gpui::AnyElement<Self> {
|
||||
let theme = theme2::current(cx).clone();
|
||||
let theme = &theme.simple_message_notification;
|
||||
|
||||
enum MessageNotificationTag {}
|
||||
|
||||
let click_message = self.click_message.clone();
|
||||
let message = match &self.message {
|
||||
NotificationMessage::Text(text) => {
|
||||
Text::new(text.to_owned(), theme.message.text.clone()).into_any()
|
||||
}
|
||||
NotificationMessage::Element(e) => e(theme.message.text.clone(), cx),
|
||||
};
|
||||
let on_click = self.on_click.clone();
|
||||
let has_click_action = on_click.is_some();
|
||||
|
||||
Flex::column()
|
||||
.with_child(
|
||||
Flex::row()
|
||||
.with_child(
|
||||
message
|
||||
.contained()
|
||||
.with_style(theme.message.container)
|
||||
.aligned()
|
||||
.top()
|
||||
.left()
|
||||
.flex(1., true),
|
||||
)
|
||||
.with_child(
|
||||
MouseEventHandler::new::<Cancel, _>(0, cx, |state, _| {
|
||||
let style = theme.dismiss_button.style_for(state);
|
||||
Svg::new("icons/x.svg")
|
||||
.with_color(style.color)
|
||||
.constrained()
|
||||
.with_width(style.icon_width)
|
||||
.aligned()
|
||||
.contained()
|
||||
.with_style(style.container)
|
||||
.constrained()
|
||||
.with_width(style.button_width)
|
||||
.with_height(style.button_width)
|
||||
})
|
||||
.with_padding(Padding::uniform(5.))
|
||||
.on_click(MouseButton::Left, move |_, this, cx| {
|
||||
this.dismiss(&Default::default(), cx);
|
||||
})
|
||||
.with_cursor_style(CursorStyle::PointingHand)
|
||||
.aligned()
|
||||
.constrained()
|
||||
.with_height(cx.font_cache().line_height(theme.message.text.font_size))
|
||||
.aligned()
|
||||
.top()
|
||||
.flex_float(),
|
||||
),
|
||||
)
|
||||
.with_children({
|
||||
click_message
|
||||
.map(|click_message| {
|
||||
MouseEventHandler::new::<MessageNotificationTag, _>(
|
||||
0,
|
||||
cx,
|
||||
|state, _| {
|
||||
let style = theme.action_message.style_for(state);
|
||||
|
||||
Flex::row()
|
||||
.with_child(
|
||||
Text::new(click_message, style.text.clone())
|
||||
.contained()
|
||||
.with_style(style.container),
|
||||
)
|
||||
.contained()
|
||||
},
|
||||
)
|
||||
.on_click(MouseButton::Left, move |_, this, cx| {
|
||||
if let Some(on_click) = on_click.as_ref() {
|
||||
on_click(cx);
|
||||
this.dismiss(&Default::default(), cx);
|
||||
}
|
||||
})
|
||||
// Since we're not using a proper overlay, we have to capture these extra events
|
||||
.on_down(MouseButton::Left, |_, _, _| {})
|
||||
.on_up(MouseButton::Left, |_, _, _| {})
|
||||
.with_cursor_style(if has_click_action {
|
||||
CursorStyle::PointingHand
|
||||
} else {
|
||||
CursorStyle::Arrow
|
||||
})
|
||||
})
|
||||
.into_iter()
|
||||
})
|
||||
.into_any()
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
// todo!()
|
||||
// impl View for MessageNotification {
|
||||
// fn ui_name() -> &'static str {
|
||||
// "MessageNotification"
|
||||
// }
|
||||
|
||||
// fn render(&mut self, cx: &mut gpui2::ViewContext<Self>) -> gpui::AnyElement<Self> {
|
||||
// let theme = theme2::current(cx).clone();
|
||||
// let theme = &theme.simple_message_notification;
|
||||
|
||||
// enum MessageNotificationTag {}
|
||||
|
||||
// let click_message = self.click_message.clone();
|
||||
// let message = match &self.message {
|
||||
// NotificationMessage::Text(text) => {
|
||||
// Text::new(text.to_owned(), theme.message.text.clone()).into_any()
|
||||
// }
|
||||
// NotificationMessage::Element(e) => e(theme.message.text.clone(), cx),
|
||||
// };
|
||||
// let on_click = self.on_click.clone();
|
||||
// let has_click_action = on_click.is_some();
|
||||
|
||||
// Flex::column()
|
||||
// .with_child(
|
||||
// Flex::row()
|
||||
// .with_child(
|
||||
// message
|
||||
// .contained()
|
||||
// .with_style(theme.message.container)
|
||||
// .aligned()
|
||||
// .top()
|
||||
// .left()
|
||||
// .flex(1., true),
|
||||
// )
|
||||
// .with_child(
|
||||
// MouseEventHandler::new::<Cancel, _>(0, cx, |state, _| {
|
||||
// let style = theme.dismiss_button.style_for(state);
|
||||
// Svg::new("icons/x.svg")
|
||||
// .with_color(style.color)
|
||||
// .constrained()
|
||||
// .with_width(style.icon_width)
|
||||
// .aligned()
|
||||
// .contained()
|
||||
// .with_style(style.container)
|
||||
// .constrained()
|
||||
// .with_width(style.button_width)
|
||||
// .with_height(style.button_width)
|
||||
// })
|
||||
// .with_padding(Padding::uniform(5.))
|
||||
// .on_click(MouseButton::Left, move |_, this, cx| {
|
||||
// this.dismiss(&Default::default(), cx);
|
||||
// })
|
||||
// .with_cursor_style(CursorStyle::PointingHand)
|
||||
// .aligned()
|
||||
// .constrained()
|
||||
// .with_height(cx.font_cache().line_height(theme.message.text.font_size))
|
||||
// .aligned()
|
||||
// .top()
|
||||
// .flex_float(),
|
||||
// ),
|
||||
// )
|
||||
// .with_children({
|
||||
// click_message
|
||||
// .map(|click_message| {
|
||||
// MouseEventHandler::new::<MessageNotificationTag, _>(
|
||||
// 0,
|
||||
// cx,
|
||||
// |state, _| {
|
||||
// let style = theme.action_message.style_for(state);
|
||||
|
||||
// Flex::row()
|
||||
// .with_child(
|
||||
// Text::new(click_message, style.text.clone())
|
||||
// .contained()
|
||||
// .with_style(style.container),
|
||||
// )
|
||||
// .contained()
|
||||
// },
|
||||
// )
|
||||
// .on_click(MouseButton::Left, move |_, this, cx| {
|
||||
// if let Some(on_click) = on_click.as_ref() {
|
||||
// on_click(cx);
|
||||
// this.dismiss(&Default::default(), cx);
|
||||
// }
|
||||
// })
|
||||
// // Since we're not using a proper overlay, we have to capture these extra events
|
||||
// .on_down(MouseButton::Left, |_, _, _| {})
|
||||
// .on_up(MouseButton::Left, |_, _, _| {})
|
||||
// .with_cursor_style(if has_click_action {
|
||||
// CursorStyle::PointingHand
|
||||
// } else {
|
||||
// CursorStyle::Arrow
|
||||
// })
|
||||
// })
|
||||
// .into_iter()
|
||||
// })
|
||||
// .into_any()
|
||||
// }
|
||||
// }
|
||||
|
||||
impl Notification for MessageNotification {
|
||||
fn should_dismiss_notification_on_event(&self, event: &<Self as Entity>::Event) -> bool {
|
||||
fn should_dismiss_notification_on_event(&self, event: &Self::Event) -> bool {
|
||||
match event {
|
||||
MessageNotificationEvent::Dismiss => true,
|
||||
}
|
||||
@ -384,15 +388,15 @@ where
|
||||
match self {
|
||||
Ok(value) => Some(value),
|
||||
Err(err) => {
|
||||
workspace.show_notification(0, cx, |cx| {
|
||||
cx.add_view(|_cx| {
|
||||
simple_message_notification::MessageNotification::new(format!(
|
||||
"Error: {:?}",
|
||||
err,
|
||||
))
|
||||
})
|
||||
});
|
||||
|
||||
log::error!("TODO {err:?}");
|
||||
// todo!()
|
||||
// workspace.show_notification(0, cx, |cx| {
|
||||
// cx.add_view(|_cx| {
|
||||
// simple_message_notification::MessageNotification::new(format!(
|
||||
// "Error: {err:?}",
|
||||
// ))
|
||||
// })
|
||||
// });
|
||||
None
|
||||
}
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ impl fmt::Debug for Event {
|
||||
pub struct Pane {
|
||||
items: Vec<Box<dyn ItemHandle>>,
|
||||
activation_history: Vec<usize>,
|
||||
// zoomed: bool,
|
||||
zoomed: bool,
|
||||
active_item_index: usize,
|
||||
// last_focused_view_by_item: HashMap<usize, AnyWeakViewHandle>,
|
||||
autoscroll: bool,
|
||||
@ -220,7 +220,7 @@ impl Default for NavigationMode {
|
||||
|
||||
pub struct NavigationEntry {
|
||||
pub item: Arc<dyn WeakItemHandle>,
|
||||
pub data: Option<Box<dyn Any>>,
|
||||
pub data: Option<Box<dyn Any + Send>>,
|
||||
pub timestamp: usize,
|
||||
}
|
||||
|
||||
@ -327,7 +327,7 @@ impl Pane {
|
||||
Self {
|
||||
items: Vec::new(),
|
||||
activation_history: Vec::new(),
|
||||
// zoomed: false,
|
||||
zoomed: false,
|
||||
active_item_index: 0,
|
||||
// last_focused_view_by_item: Default::default(),
|
||||
autoscroll: false,
|
||||
@ -648,9 +648,9 @@ impl Pane {
|
||||
// })
|
||||
// }
|
||||
|
||||
// pub fn index_for_item(&self, item: &dyn ItemHandle) -> Option<usize> {
|
||||
// self.items.iter().position(|i| i.id() == item.id())
|
||||
// }
|
||||
pub fn index_for_item(&self, item: &dyn ItemHandle) -> Option<usize> {
|
||||
self.items.iter().position(|i| i.id() == item.id())
|
||||
}
|
||||
|
||||
// pub fn toggle_zoom(&mut self, _: &ToggleZoom, cx: &mut ViewContext<Self>) {
|
||||
// // Potentially warn the user of the new keybinding
|
||||
@ -994,77 +994,73 @@ impl Pane {
|
||||
// })
|
||||
// }
|
||||
|
||||
// pub fn remove_item(
|
||||
// &mut self,
|
||||
// item_index: usize,
|
||||
// activate_pane: bool,
|
||||
// cx: &mut ViewContext<Self>,
|
||||
// ) {
|
||||
// self.activation_history
|
||||
// .retain(|&history_entry| history_entry != self.items[item_index].id());
|
||||
pub fn remove_item(
|
||||
&mut self,
|
||||
item_index: usize,
|
||||
activate_pane: bool,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
self.activation_history
|
||||
.retain(|&history_entry| history_entry != self.items[item_index].id());
|
||||
|
||||
// if item_index == self.active_item_index {
|
||||
// let index_to_activate = self
|
||||
// .activation_history
|
||||
// .pop()
|
||||
// .and_then(|last_activated_item| {
|
||||
// self.items.iter().enumerate().find_map(|(index, item)| {
|
||||
// (item.id() == last_activated_item).then_some(index)
|
||||
// })
|
||||
// })
|
||||
// // We didn't have a valid activation history entry, so fallback
|
||||
// // to activating the item to the left
|
||||
// .unwrap_or_else(|| item_index.min(self.items.len()).saturating_sub(1));
|
||||
if item_index == self.active_item_index {
|
||||
let index_to_activate = self
|
||||
.activation_history
|
||||
.pop()
|
||||
.and_then(|last_activated_item| {
|
||||
self.items.iter().enumerate().find_map(|(index, item)| {
|
||||
(item.id() == last_activated_item).then_some(index)
|
||||
})
|
||||
})
|
||||
// We didn't have a valid activation history entry, so fallback
|
||||
// to activating the item to the left
|
||||
.unwrap_or_else(|| item_index.min(self.items.len()).saturating_sub(1));
|
||||
|
||||
// let should_activate = activate_pane || self.has_focus;
|
||||
// self.activate_item(index_to_activate, should_activate, should_activate, cx);
|
||||
// }
|
||||
let should_activate = activate_pane || self.has_focus;
|
||||
self.activate_item(index_to_activate, should_activate, should_activate, cx);
|
||||
}
|
||||
|
||||
// let item = self.items.remove(item_index);
|
||||
let item = self.items.remove(item_index);
|
||||
|
||||
// cx.emit(Event::RemoveItem { item_id: item.id() });
|
||||
// if self.items.is_empty() {
|
||||
// item.deactivated(cx);
|
||||
// self.update_toolbar(cx);
|
||||
// cx.emit(Event::Remove);
|
||||
// }
|
||||
cx.emit(Event::RemoveItem { item_id: item.id() });
|
||||
if self.items.is_empty() {
|
||||
item.deactivated(cx);
|
||||
self.update_toolbar(cx);
|
||||
cx.emit(Event::Remove);
|
||||
}
|
||||
|
||||
// if item_index < self.active_item_index {
|
||||
// self.active_item_index -= 1;
|
||||
// }
|
||||
if item_index < self.active_item_index {
|
||||
self.active_item_index -= 1;
|
||||
}
|
||||
|
||||
// self.nav_history.set_mode(NavigationMode::ClosingItem);
|
||||
// item.deactivated(cx);
|
||||
// self.nav_history.set_mode(NavigationMode::Normal);
|
||||
self.nav_history.set_mode(NavigationMode::ClosingItem);
|
||||
item.deactivated(cx);
|
||||
self.nav_history.set_mode(NavigationMode::Normal);
|
||||
|
||||
// if let Some(path) = item.project_path(cx) {
|
||||
// let abs_path = self
|
||||
// .nav_history
|
||||
// .0
|
||||
// .borrow()
|
||||
// .paths_by_item
|
||||
// .get(&item.id())
|
||||
// .and_then(|(_, abs_path)| abs_path.clone());
|
||||
if let Some(path) = item.project_path(cx) {
|
||||
let abs_path = self
|
||||
.nav_history
|
||||
.0
|
||||
.lock()
|
||||
.paths_by_item
|
||||
.get(&item.id())
|
||||
.and_then(|(_, abs_path)| abs_path.clone());
|
||||
|
||||
// self.nav_history
|
||||
// .0
|
||||
// .borrow_mut()
|
||||
// .paths_by_item
|
||||
// .insert(item.id(), (path, abs_path));
|
||||
// } else {
|
||||
// self.nav_history
|
||||
// .0
|
||||
// .borrow_mut()
|
||||
// .paths_by_item
|
||||
// .remove(&item.id());
|
||||
// }
|
||||
self.nav_history
|
||||
.0
|
||||
.lock()
|
||||
.paths_by_item
|
||||
.insert(item.id(), (path, abs_path));
|
||||
} else {
|
||||
self.nav_history.0.lock().paths_by_item.remove(&item.id());
|
||||
}
|
||||
|
||||
// if self.items.is_empty() && self.zoomed {
|
||||
// cx.emit(Event::ZoomOut);
|
||||
// }
|
||||
if self.items.is_empty() && self.zoomed {
|
||||
cx.emit(Event::ZoomOut);
|
||||
}
|
||||
|
||||
// cx.notify();
|
||||
// }
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
// pub async fn save_item(
|
||||
// project: Model<Project>,
|
||||
@ -1314,28 +1310,28 @@ impl Pane {
|
||||
// });
|
||||
// }
|
||||
|
||||
// pub fn toolbar(&self) -> &ViewHandle<Toolbar> {
|
||||
// &self.toolbar
|
||||
// }
|
||||
pub fn toolbar(&self) -> &View<Toolbar> {
|
||||
&self.toolbar
|
||||
}
|
||||
|
||||
// pub fn handle_deleted_project_item(
|
||||
// &mut self,
|
||||
// entry_id: ProjectEntryId,
|
||||
// cx: &mut ViewContext<Pane>,
|
||||
// ) -> Option<()> {
|
||||
// let (item_index_to_delete, item_id) = self.items().enumerate().find_map(|(i, item)| {
|
||||
// if item.is_singleton(cx) && item.project_entry_ids(cx).as_slice() == [entry_id] {
|
||||
// Some((i, item.id()))
|
||||
// } else {
|
||||
// None
|
||||
// }
|
||||
// })?;
|
||||
pub fn handle_deleted_project_item(
|
||||
&mut self,
|
||||
entry_id: ProjectEntryId,
|
||||
cx: &mut ViewContext<Pane>,
|
||||
) -> Option<()> {
|
||||
let (item_index_to_delete, item_id) = self.items().enumerate().find_map(|(i, item)| {
|
||||
if item.is_singleton(cx) && item.project_entry_ids(cx).as_slice() == [entry_id] {
|
||||
Some((i, item.id()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})?;
|
||||
|
||||
// self.remove_item(item_index_to_delete, false, cx);
|
||||
// self.nav_history.remove_item(item_id);
|
||||
self.remove_item(item_index_to_delete, false, cx);
|
||||
self.nav_history.remove_item(item_id);
|
||||
|
||||
// Some(())
|
||||
// }
|
||||
Some(())
|
||||
}
|
||||
|
||||
fn update_toolbar(&mut self, cx: &mut ViewContext<Self>) {
|
||||
let active_item = self
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user