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