Cargo.lock 🔗
@@ -6109,7 +6109,6 @@ dependencies = [
"settings2",
"theme2",
"util",
- "workspace2",
]
[[package]]
Mikayla created
Cargo.lock | 1
crates/call2/src/call2.rs | 5
crates/call2/src/room.rs | 4
crates/channel2/src/channel_buffer.rs | 4
crates/channel2/src/channel_chat.rs | 4
crates/channel2/src/channel_store.rs | 4
crates/client2/src/user.rs | 4
crates/copilot2/src/copilot2.rs | 4
crates/editor2/src/editor.rs | 4
crates/gpui2/src/app.rs | 2
crates/gpui2/src/window.rs | 18 ---
crates/language2/src/buffer.rs | 4
crates/multi_buffer2/src/multi_buffer2.rs | 4
crates/picker2/Cargo.toml | 2
crates/project2/src/project2.rs | 4
crates/project2/src/worktree.rs | 4
crates/terminal2/src/terminal2.rs | 4
crates/workspace2/src/dock.rs | 113 +++++++++---------------
crates/workspace2/src/item.rs | 106 +++++++++++-----------
crates/workspace2/src/notifications.rs | 38 +++----
crates/workspace2/src/pane.rs | 76 ++++++++--------
crates/workspace2/src/searchable.rs | 23 +---
crates/workspace2/src/toolbar.rs | 32 ++----
crates/workspace2/src/workspace2.rs | 77 ++++++++--------
24 files changed, 223 insertions(+), 318 deletions(-)
@@ -6109,7 +6109,6 @@ dependencies = [
"settings2",
"theme2",
"util",
- "workspace2",
]
[[package]]
@@ -17,6 +17,7 @@ use gpui::{
};
use postage::watch;
use project::Project;
+use room::Event;
use settings::Settings;
use std::sync::Arc;
@@ -85,9 +86,7 @@ pub struct ActiveCall {
_subscriptions: Vec<client::Subscription>,
}
-impl EventEmitter for ActiveCall {
- type Event = room::Event;
-}
+impl EventEmitter<Event> for ActiveCall {}
impl ActiveCall {
fn new(client: Arc<Client>, user_store: Model<UserStore>, cx: &mut ModelContext<Self>) -> Self {
@@ -79,9 +79,7 @@ pub struct Room {
maintain_connection: Option<Task<Option<()>>>,
}
-impl EventEmitter for Room {
- type Event = Event;
-}
+impl EventEmitter<Event> for Room {}
impl Room {
pub fn channel_id(&self) -> Option<u64> {
@@ -38,9 +38,7 @@ pub enum ChannelBufferEvent {
ChannelChanged,
}
-impl EventEmitter for ChannelBuffer {
- type Event = ChannelBufferEvent;
-}
+impl EventEmitter<ChannelBufferEvent> for ChannelBuffer {}
impl ChannelBuffer {
pub(crate) async fn new(
@@ -76,9 +76,7 @@ pub enum ChannelChatEvent {
},
}
-impl EventEmitter for ChannelChat {
- type Event = ChannelChatEvent;
-}
+impl EventEmitter<ChannelChatEvent> for ChannelChat {}
pub fn init(client: &Arc<Client>) {
client.add_model_message_handler(ChannelChat::handle_message_sent);
client.add_model_message_handler(ChannelChat::handle_message_removed);
@@ -114,9 +114,7 @@ pub enum ChannelEvent {
ChannelRenamed(ChannelId),
}
-impl EventEmitter for ChannelStore {
- type Event = ChannelEvent;
-}
+impl EventEmitter<ChannelEvent> for ChannelStore {}
enum OpenedModelHandle<E> {
Open(WeakModel<E>),
@@ -103,9 +103,7 @@ pub enum ContactEventKind {
Cancelled,
}
-impl EventEmitter for UserStore {
- type Event = Event;
-}
+impl EventEmitter<Event> for UserStore {}
enum UpdateContacts {
Update(proto::UpdateContacts),
@@ -284,9 +284,7 @@ pub enum Event {
CopilotLanguageServerStarted,
}
-impl EventEmitter for Copilot {
- type Event = Event;
-}
+impl EventEmitter<Event> for Copilot {}
impl Copilot {
pub fn global(cx: &AppContext) -> Option<Model<Self>> {
@@ -9407,9 +9407,7 @@ pub struct EditorReleased(pub WeakView<Editor>);
// }
// }
//
-impl EventEmitter for Editor {
- type Event = Event;
-}
+impl EventEmitter<Event> for Editor {}
impl Render for Editor {
type Element = EditorElement;
@@ -201,7 +201,7 @@ pub struct AppContext {
pub(crate) pending_notifications: HashSet<EntityId>,
pub(crate) pending_global_notifications: HashSet<TypeId>,
pub(crate) observers: SubscriberSet<EntityId, Handler>,
- // (Entity, Event Type)
+ // TypeId is the type of the event that the listener callback expects
pub(crate) event_listeners: SubscriberSet<EntityId, (TypeId, Listener)>,
pub(crate) release_listeners: SubscriberSet<EntityId, ReleaseListener>,
pub(crate) global_observers: SubscriberSet<TypeId, Handler>,
@@ -1813,24 +1813,6 @@ impl<'a, V: 'static> ViewContext<'a, V> {
)
}
- // Options for simplifying this new event API:
- //
- // - Make a new stlye of API which does partial application of the arguments to capture
- // the types involved e.g.
- // `cx.for_entity(handle).subscribe::<ItemEvents>(..)`
- //
- // - Make it so there are less types:
- // - Bail on this idea all together, go back to associated types.
- // causes our event enums to be a blob of anything that could happen ever, and
- // makes applications have some translation boilerplate
- //
- // - Move some of the types into the method names,
- // `cx.subscribe_model::<_, ItemEvents>(handle)`
- //
- // - Do something drastic like removing views and models, or removing the multiple
- // kind of contexts. (Not going to happen, we already tried this before.)
- //
- // - Accept it, and use `cx.subscribe::<_, _, ItemEvents>(handle, ...)`
pub fn subscribe<V2, E, Evt>(
&mut self,
entity: &E,
@@ -1815,9 +1815,7 @@ impl Buffer {
}
}
-impl EventEmitter for Buffer {
- type Event = Event;
-}
+impl EventEmitter<Event> for Buffer {}
impl Deref for Buffer {
type Target = TextBuffer;
@@ -1872,9 +1872,7 @@ impl MultiBuffer {
}
}
-impl EventEmitter for MultiBuffer {
- type Event = Event;
-}
+impl EventEmitter<Event> for MultiBuffer {}
impl MultiBufferSnapshot {
pub fn text(&self) -> String {
@@ -15,7 +15,6 @@ menu = { package = "menu2", path = "../menu2" }
settings = { package = "settings2", path = "../settings2" }
util = { path = "../util" }
theme = { package = "theme2", path = "../theme2" }
-workspace = { package = "workspace2", path = "../workspace2" }
parking_lot.workspace = true
@@ -23,6 +22,5 @@ parking_lot.workspace = true
editor = { package = "editor2", path = "../editor2", features = ["test-support"] }
gpui = { package = "gpui2", path = "../gpui2", features = ["test-support"] }
serde_json.workspace = true
-workspace = { package = "workspace2", path = "../workspace2", features = ["test-support"] }
ctor.workspace = true
env_logger.workspace = true
@@ -9062,9 +9062,7 @@ impl<'a> Iterator for PathMatchCandidateSetIter<'a> {
}
}
-impl EventEmitter for Project {
- type Event = Event;
-}
+impl EventEmitter<Event> for Project {}
impl<P: AsRef<Path>> From<(WorktreeId, P)> for ProjectPath {
fn from((worktree_id, path): (WorktreeId, P)) -> Self {
@@ -281,9 +281,7 @@ pub enum Event {
UpdatedGitRepositories(UpdatedGitRepositoriesSet),
}
-impl EventEmitter for Worktree {
- type Event = Event;
-}
+impl EventEmitter<Event> for Worktree {}
impl Worktree {
pub async fn local(
@@ -1351,9 +1351,7 @@ impl Drop for Terminal {
}
}
-impl EventEmitter for Terminal {
- type Event = Event;
-}
+impl EventEmitter<Event> for Terminal {}
/// Based on alacritty/src/display/hint.rs > regex_match_at
/// Retrieve the match, if the specified point is inside the content matching the regex.
@@ -7,7 +7,16 @@ use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::sync::Arc;
-pub trait Panel: Render + EventEmitter {
+pub enum PanelEvent {
+ ChangePosition,
+ ZoomIn,
+ ZoomOut,
+ Activate,
+ Close,
+ Focus,
+}
+
+pub trait Panel: Render + EventEmitter<PanelEvent> {
fn persistent_name(&self) -> &'static str;
fn position(&self, cx: &WindowContext) -> DockPosition;
fn position_is_valid(&self, position: DockPosition) -> bool;
@@ -19,26 +28,12 @@ pub trait Panel: Render + EventEmitter {
fn icon_label(&self, _: &WindowContext) -> Option<String> {
None
}
- fn should_change_position_on_event(_: &Self::Event) -> bool;
- fn should_zoom_in_on_event(_: &Self::Event) -> bool {
- false
- }
- fn should_zoom_out_on_event(_: &Self::Event) -> bool {
- false
- }
fn is_zoomed(&self, _cx: &WindowContext) -> bool {
false
}
fn set_zoomed(&mut self, _zoomed: bool, _cx: &mut ViewContext<Self>) {}
fn set_active(&mut self, _active: bool, _cx: &mut ViewContext<Self>) {}
- fn should_activate_on_event(_: &Self::Event) -> bool {
- false
- }
- fn should_close_on_event(_: &Self::Event) -> bool {
- false
- }
fn has_focus(&self, cx: &WindowContext) -> bool;
- fn is_focus_event(_: &Self::Event) -> bool;
}
pub trait PanelHandle: Send + Sync {
@@ -268,21 +263,37 @@ impl Dock {
let subscriptions = [
cx.observe(&panel, |_, _, cx| cx.notify()),
cx.subscribe(&panel, |this, panel, event, cx| {
- if T::should_activate_on_event(event) {
- if let Some(ix) = this
- .panel_entries
- .iter()
- .position(|entry| entry.panel.id() == panel.id())
- {
- this.set_open(true, cx);
- this.activate_panel(ix, cx);
+ match event {
+ PanelEvent::ChangePosition => {
+ //todo!()
+ // see: Workspace::add_panel_with_extra_event_handler
+ }
+ PanelEvent::ZoomIn => {
+ //todo!()
+ // see: Workspace::add_panel_with_extra_event_handler
+ }
+ PanelEvent::ZoomOut => {
// todo!()
- // cx.focus(&panel);
+ // // see: Workspace::add_panel_with_extra_event_handler
}
- } else if T::should_close_on_event(event)
- && this.visible_panel().map_or(false, |p| p.id() == panel.id())
- {
- this.set_open(false, cx);
+ PanelEvent::Activate => {
+ if let Some(ix) = this
+ .panel_entries
+ .iter()
+ .position(|entry| entry.panel.id() == panel.id())
+ {
+ this.set_open(true, cx);
+ this.activate_panel(ix, cx);
+ //` todo!()
+ // cx.focus(&panel);
+ }
+ }
+ PanelEvent::Close => {
+ if this.visible_panel().map_or(false, |p| p.id() == panel.id()) {
+ this.set_open(false, cx);
+ }
+ }
+ PanelEvent::Focus => todo!(),
}
}),
];
@@ -452,10 +463,6 @@ impl PanelButtons {
}
}
-impl EventEmitter for PanelButtons {
- type Event = ();
-}
-
// impl Render for PanelButtons {
// type Element = ();
@@ -625,7 +632,7 @@ impl StatusItemView for PanelButtons {
_active_pane_item: Option<&dyn crate::ItemHandle>,
_cx: &mut ViewContext<Self>,
) {
- // todo!(This is empty in the old `workspace::dock`)
+ // Nothing to do, panel buttons don't depend on the active center item
}
}
@@ -634,16 +641,6 @@ pub mod test {
use super::*;
use gpui::{div, Div, ViewContext, WindowContext};
- #[derive(Debug)]
- pub enum TestPanelEvent {
- PositionChanged,
- Activated,
- Closed,
- ZoomIn,
- ZoomOut,
- Focus,
- }
-
pub struct TestPanel {
pub position: DockPosition,
pub zoomed: bool,
@@ -652,9 +649,7 @@ pub mod test {
pub size: f32,
}
- impl EventEmitter for TestPanel {
- type Event = TestPanelEvent;
- }
+ impl EventEmitter<PanelEvent> for TestPanel {}
impl TestPanel {
pub fn new(position: DockPosition) -> Self {
@@ -691,7 +686,7 @@ pub mod test {
fn set_position(&mut self, position: DockPosition, cx: &mut ViewContext<Self>) {
self.position = position;
- cx.emit(TestPanelEvent::PositionChanged);
+ cx.emit(PanelEvent::ChangePosition);
}
fn size(&self, _: &WindowContext) -> f32 {
@@ -710,18 +705,6 @@ pub mod test {
("Test Panel".into(), None)
}
- fn should_change_position_on_event(event: &Self::Event) -> bool {
- matches!(event, TestPanelEvent::PositionChanged)
- }
-
- fn should_zoom_in_on_event(event: &Self::Event) -> bool {
- matches!(event, TestPanelEvent::ZoomIn)
- }
-
- fn should_zoom_out_on_event(event: &Self::Event) -> bool {
- matches!(event, TestPanelEvent::ZoomOut)
- }
-
fn is_zoomed(&self, _: &WindowContext) -> bool {
self.zoomed
}
@@ -734,20 +717,8 @@ pub mod test {
self.active = active;
}
- fn should_activate_on_event(event: &Self::Event) -> bool {
- matches!(event, TestPanelEvent::Activated)
- }
-
- fn should_close_on_event(event: &Self::Event) -> bool {
- matches!(event, TestPanelEvent::Closed)
- }
-
fn has_focus(&self, _cx: &WindowContext) -> bool {
self.has_focus
}
-
- fn is_focus_event(event: &Self::Event) -> bool {
- matches!(event, TestPanelEvent::Focus)
- }
}
}
@@ -91,7 +91,7 @@ pub struct BreadcrumbText {
pub highlights: Option<Vec<(Range<usize>, HighlightStyle)>>,
}
-pub trait Item: Render + EventEmitter {
+pub trait Item: Render + EventEmitter<ItemEvent> {
fn focus_handle(&self) -> FocusHandle;
fn deactivated(&mut self, _: &mut ViewContext<Self>) {}
fn workspace_deactivated(&mut self, _: &mut ViewContext<Self>) {}
@@ -106,12 +106,13 @@ pub trait Item: Render + EventEmitter {
}
fn tab_content<V: 'static>(&self, detail: Option<usize>, cx: &AppContext) -> AnyElement<V>;
+ /// (model id, Item)
fn for_each_project_item(
&self,
_: &AppContext,
_: &mut dyn FnMut(EntityId, &dyn project2::Item),
) {
- } // (model id, Item)
+ }
fn is_singleton(&self, _cx: &AppContext) -> bool {
false
}
@@ -153,15 +154,6 @@ pub trait Item: Render + EventEmitter {
) -> Task<Result<()>> {
unimplemented!("reload() must be implemented if can_save() returns true")
}
- fn to_item_events(_event: &Self::Event) -> SmallVec<[ItemEvent; 2]> {
- SmallVec::new()
- }
- fn should_close_item_on_event(_: &Self::Event) -> bool {
- false
- }
- fn should_update_tab_on_event(_: &Self::Event) -> bool {
- false
- }
fn act_as_type<'a>(
&'a self,
@@ -218,7 +210,7 @@ pub trait ItemHandle: 'static + Send {
fn subscribe_to_item_events(
&self,
cx: &mut WindowContext,
- handler: Box<dyn Fn(ItemEvent, &mut WindowContext) + Send>,
+ handler: Box<dyn Fn(&ItemEvent, &mut WindowContext) + Send>,
) -> gpui::Subscription;
fn tab_tooltip_text(&self, cx: &AppContext) -> Option<SharedString>;
fn tab_description(&self, detail: usize, cx: &AppContext) -> Option<SharedString>;
@@ -300,12 +292,10 @@ impl<T: Item> ItemHandle for View<T> {
fn subscribe_to_item_events(
&self,
cx: &mut WindowContext,
- handler: Box<dyn Fn(ItemEvent, &mut WindowContext) + Send>,
+ handler: Box<dyn Fn(&ItemEvent, &mut WindowContext) + Send>,
) -> gpui::Subscription {
cx.subscribe(self, move |_, event, cx| {
- for item_event in T::to_item_events(event) {
- handler(item_event, cx)
- }
+ handler(event, cx);
})
}
@@ -433,7 +423,10 @@ impl<T: Item> ItemHandle for View<T> {
let is_project_item = item.is_project_item(cx);
let leader_id = workspace.leader_for_pane(&pane);
- if leader_id.is_some() && item.should_unfollow_on_event(event, cx) {
+ let follow_event = item.to_follow_event(event);
+ if leader_id.is_some()
+ && matches!(follow_event, Some(FollowEvent::Unfollow))
+ {
workspace.unfollow(&pane, cx);
}
@@ -467,36 +460,34 @@ impl<T: Item> ItemHandle for View<T> {
}
}
- for item_event in T::to_item_events(event).into_iter() {
- match item_event {
- ItemEvent::CloseItem => {
- pane.update(cx, |pane, cx| {
- pane.close_item_by_id(item.id(), crate::SaveIntent::Close, cx)
- })
- .detach_and_log_err(cx);
- return;
- }
+ match event {
+ ItemEvent::CloseItem => {
+ pane.update(cx, |pane, cx| {
+ pane.close_item_by_id(item.id(), crate::SaveIntent::Close, cx)
+ })
+ .detach_and_log_err(cx);
+ return;
+ }
- ItemEvent::UpdateTab => {
- pane.update(cx, |_, cx| {
- cx.emit(pane::Event::ChangeItemTitle);
- cx.notify();
- });
- }
+ ItemEvent::UpdateTab => {
+ pane.update(cx, |_, cx| {
+ cx.emit(pane::Event::ChangeItemTitle);
+ cx.notify();
+ });
+ }
- ItemEvent::Edit => {
- let autosave = WorkspaceSettings::get_global(cx).autosave;
- if let AutosaveSetting::AfterDelay { milliseconds } = autosave {
- let delay = Duration::from_millis(milliseconds);
- let item = item.clone();
- pending_autosave.fire_new(delay, cx, move |workspace, cx| {
- Pane::autosave_item(&item, workspace.project().clone(), cx)
- });
- }
+ ItemEvent::Edit => {
+ let autosave = WorkspaceSettings::get_global(cx).autosave;
+ if let AutosaveSetting::AfterDelay { milliseconds } = autosave {
+ let delay = Duration::from_millis(milliseconds);
+ let item = item.clone();
+ pending_autosave.fire_new(delay, cx, move |workspace, cx| {
+ Pane::autosave_item(&item, workspace.project().clone(), cx)
+ });
}
-
- _ => {}
}
+
+ _ => {}
}
}));
@@ -660,7 +651,16 @@ pub trait ProjectItem: Item {
Self: Sized;
}
+pub enum FollowEvent {
+ Unfollow,
+}
+
+pub trait FollowableEvents {
+ fn to_follow_event(&self) -> Option<FollowEvent>;
+}
+
pub trait FollowableItem: Item {
+ type FollowableEvent: FollowableEvents;
fn remote_id(&self) -> Option<ViewId>;
fn to_state_proto(&self, cx: &AppContext) -> Option<proto::view::Variant>;
fn from_state_proto(
@@ -672,7 +672,7 @@ pub trait FollowableItem: Item {
) -> Option<Task<Result<View<Self>>>>;
fn add_event_to_update_proto(
&self,
- event: &Self::Event,
+ event: &Self::FollowableEvent,
update: &mut Option<proto::update_view::Variant>,
cx: &AppContext,
) -> bool;
@@ -685,7 +685,6 @@ pub trait FollowableItem: Item {
fn is_project_item(&self, cx: &AppContext) -> bool;
fn set_leader_peer_id(&mut self, leader_peer_id: Option<PeerId>, cx: &mut ViewContext<Self>);
- fn should_unfollow_on_event(event: &Self::Event, cx: &AppContext) -> bool;
}
pub trait FollowableItemHandle: ItemHandle {
@@ -698,13 +697,13 @@ pub trait FollowableItemHandle: ItemHandle {
update: &mut Option<proto::update_view::Variant>,
cx: &AppContext,
) -> bool;
+ fn to_follow_event(&self, event: &dyn Any) -> Option<FollowEvent>;
fn apply_update_proto(
&self,
project: &Model<Project>,
message: proto::update_view::Variant,
cx: &mut WindowContext,
) -> Task<Result<()>>;
- fn should_unfollow_on_event(&self, event: &dyn Any, cx: &AppContext) -> bool;
fn is_project_item(&self, cx: &AppContext) -> bool;
}
@@ -739,6 +738,13 @@ impl<T: FollowableItem> FollowableItemHandle for View<T> {
}
}
+ fn to_follow_event(&self, event: &dyn Any) -> Option<FollowEvent> {
+ event
+ .downcast_ref()
+ .map(T::FollowableEvent::to_follow_event)
+ .flatten()
+ }
+
fn apply_update_proto(
&self,
project: &Model<Project>,
@@ -748,14 +754,6 @@ impl<T: FollowableItem> FollowableItemHandle for View<T> {
self.update(cx, |this, cx| this.apply_update_proto(project, message, cx))
}
- fn should_unfollow_on_event(&self, event: &dyn Any, cx: &AppContext) -> bool {
- if let Some(event) = event.downcast_ref() {
- T::should_unfollow_on_event(event, cx)
- } else {
- false
- }
- }
-
fn is_project_item(&self, cx: &AppContext) -> bool {
self.read(cx).is_project_item(cx)
}
@@ -9,10 +9,12 @@ pub fn init(cx: &mut AppContext) {
// simple_message_notification::init(cx);
}
-pub trait Notification: EventEmitter + Render {
- fn should_dismiss_notification_on_event(&self, event: &Self::Event) -> bool;
+pub enum NotificationEvent {
+ Dismiss,
}
+pub trait Notification: EventEmitter<NotificationEvent> + Render {}
+
pub trait NotificationHandle: Send {
fn id(&self) -> EntityId;
fn to_any(&self) -> AnyView;
@@ -101,11 +103,14 @@ impl Workspace {
})
{
let notification = build_notification(cx);
- cx.subscribe(¬ification, move |this, handle, event, cx| {
- if handle.read(cx).should_dismiss_notification_on_event(event) {
- this.dismiss_notification_internal(type_id, id, cx);
- }
- })
+ cx.subscribe(
+ ¬ification,
+ move |this, handle, event: &NotificationEvent, cx| match event {
+ NotificationEvent::Dismiss => {
+ this.dismiss_notification_internal(type_id, id, cx);
+ }
+ },
+ )
.detach();
self.notifications
.push((type_id, id, Box::new(notification)));
@@ -159,7 +164,7 @@ impl Workspace {
}
pub mod simple_message_notification {
- use super::Notification;
+ use super::{Notification, NotificationEvent};
use gpui::{AnyElement, AppContext, Div, EventEmitter, Render, TextStyle, ViewContext};
use serde::Deserialize;
use std::{borrow::Cow, sync::Arc};
@@ -200,13 +205,7 @@ pub mod simple_message_notification {
click_message: Option<Cow<'static, str>>,
}
- pub enum MessageNotificationEvent {
- Dismiss,
- }
-
- impl EventEmitter for MessageNotification {
- type Event = MessageNotificationEvent;
- }
+ impl EventEmitter<NotificationMessage> for MessageNotification {}
impl MessageNotification {
pub fn new<S>(message: S) -> MessageNotification
@@ -359,13 +358,8 @@ pub mod simple_message_notification {
// }
// }
- impl Notification for MessageNotification {
- fn should_dismiss_notification_on_event(&self, event: &Self::Event) -> bool {
- match event {
- MessageNotificationEvent::Dismiss => true,
- }
- }
- }
+ impl EventEmitter<NotificationEvent> for MessageNotification {}
+ impl Notification for MessageNotification {}
}
pub trait NotifyResultExt {
@@ -9,8 +9,9 @@ use crate::{
use anyhow::Result;
use collections::{HashMap, HashSet, VecDeque};
use gpui::{
- AppContext, AsyncWindowContext, Component, Div, EntityId, EventEmitter, FocusHandle, Model,
- PromptLevel, Render, Task, View, ViewContext, VisualContext, WeakView, WindowContext,
+ actions, register_action, AppContext, AsyncWindowContext, Component, Div, EntityId,
+ EventEmitter, FocusHandle, Model, PromptLevel, Render, Task, View, ViewContext, VisualContext,
+ WeakView, WindowContext,
};
use parking_lot::Mutex;
use project2::{Project, ProjectEntryId, ProjectPath};
@@ -48,8 +49,10 @@ pub enum SaveIntent {
Skip,
}
-// #[derive(Clone, Deserialize, PartialEq)]
-// pub struct ActivateItem(pub usize);
+//todo!("Do we need the default bound on actions? Decide soon")
+// #[register_action]
+#[derive(Clone, Deserialize, PartialEq, Debug)]
+pub struct ActivateItem(pub usize);
// #[derive(Clone, PartialEq)]
// pub struct CloseItemById {
@@ -69,40 +72,37 @@ pub enum SaveIntent {
// pub pane: WeakView<Pane>,
// }
-// #[derive(Clone, PartialEq, Debug, Deserialize, Default)]
-// #[serde(rename_all = "camelCase")]
-// pub struct CloseActiveItem {
-// pub save_intent: Option<SaveIntent>,
-// }
+#[register_action]
+#[derive(Clone, PartialEq, Debug, Deserialize, Default)]
+#[serde(rename_all = "camelCase")]
+pub struct CloseActiveItem {
+ pub save_intent: Option<SaveIntent>,
+}
-// #[derive(Clone, PartialEq, Debug, Deserialize)]
-// #[serde(rename_all = "camelCase")]
-// pub struct CloseAllItems {
-// pub save_intent: Option<SaveIntent>,
-// }
+#[register_action]
+#[derive(Clone, PartialEq, Debug, Deserialize, Default)]
+#[serde(rename_all = "camelCase")]
+pub struct CloseAllItems {
+ pub save_intent: Option<SaveIntent>,
+}
-// todo!()
-// actions!(
-// pane,
-// [
-// ActivatePrevItem,
-// ActivateNextItem,
-// ActivateLastItem,
-// CloseInactiveItems,
-// CloseCleanItems,
-// CloseItemsToTheLeft,
-// CloseItemsToTheRight,
-// GoBack,
-// GoForward,
-// ReopenClosedItem,
-// SplitLeft,
-// SplitUp,
-// SplitRight,
-// SplitDown,
-// ]
-// );
-
-// impl_actions!(pane, [ActivateItem, CloseActiveItem, CloseAllItems]);
+// todo!(These used to be under pane::{Action}. Are they now workspace::pane::{Action}?)
+actions!(
+ ActivatePrevItem,
+ ActivateNextItem,
+ ActivateLastItem,
+ CloseInactiveItems,
+ CloseCleanItems,
+ CloseItemsToTheLeft,
+ CloseItemsToTheRight,
+ GoBack,
+ GoForward,
+ ReopenClosedItem,
+ SplitLeft,
+ SplitUp,
+ SplitRight,
+ SplitDown,
+);
const MAX_NAVIGATION_HISTORY_LEN: usize = 1024;
@@ -310,9 +310,7 @@ pub struct NavigationEntry {
// .into_any_named("nav button")
// }
-impl EventEmitter for Pane {
- type Event = Event;
-}
+impl EventEmitter<Event> for Pane {}
impl Pane {
pub fn new(
@@ -1,6 +1,8 @@
use std::{any::Any, sync::Arc};
-use gpui::{AnyView, AppContext, Subscription, Task, View, ViewContext, WindowContext};
+use gpui::{
+ AnyView, AppContext, EventEmitter, Subscription, Task, View, ViewContext, WindowContext,
+};
use project2::search::SearchQuery;
use crate::{
@@ -29,7 +31,7 @@ pub struct SearchOptions {
pub replacement: bool,
}
-pub trait SearchableItem: Item {
+pub trait SearchableItem: Item + EventEmitter<SearchEvent> {
type Match: Any + Sync + Send + Clone;
fn supported_options() -> SearchOptions {
@@ -40,11 +42,7 @@ pub trait SearchableItem: Item {
replacement: true,
}
}
- fn to_search_event(
- &mut self,
- event: &Self::Event,
- cx: &mut ViewContext<Self>,
- ) -> Option<SearchEvent>;
+
fn clear_matches(&mut self, cx: &mut ViewContext<Self>);
fn update_matches(&mut self, matches: Vec<Self::Match>, cx: &mut ViewContext<Self>);
fn query_suggestion(&mut self, cx: &mut ViewContext<Self>) -> String;
@@ -95,7 +93,7 @@ pub trait SearchableItemHandle: ItemHandle {
fn subscribe_to_search_events(
&self,
cx: &mut WindowContext,
- handler: Box<dyn Fn(SearchEvent, &mut WindowContext) + Send>,
+ handler: Box<dyn Fn(&SearchEvent, &mut WindowContext) + Send>,
) -> Subscription;
fn clear_matches(&self, cx: &mut WindowContext);
fn update_matches(&self, matches: &Vec<Box<dyn Any + Send>>, cx: &mut WindowContext);
@@ -146,14 +144,9 @@ impl<T: SearchableItem> SearchableItemHandle for View<T> {
fn subscribe_to_search_events(
&self,
cx: &mut WindowContext,
- handler: Box<dyn Fn(SearchEvent, &mut WindowContext) + Send>,
+ handler: Box<dyn Fn(&SearchEvent, &mut WindowContext) + Send>,
) -> Subscription {
- cx.subscribe(self, move |handle, event, cx| {
- let search_event = handle.update(cx, |handle, cx| handle.to_search_event(event, cx));
- if let Some(search_event) = search_event {
- handler(search_event, cx)
- }
- })
+ cx.subscribe(self, move |_, event: &SearchEvent, cx| handler(event, cx))
}
fn clear_matches(&self, cx: &mut WindowContext) {
@@ -1,24 +1,17 @@
use crate::ItemHandle;
-use gpui::{
- AnyView, AppContext, Entity, EntityId, EventEmitter, Render, View, ViewContext, WindowContext,
-};
+use gpui::{AnyView, Entity, EntityId, EventEmitter, Render, View, ViewContext, WindowContext};
-pub trait ToolbarItemView: Render + EventEmitter {
+pub enum ToolbarItemEvent {
+ ChangeLocation(ToolbarItemLocation),
+}
+
+pub trait ToolbarItemView: Render + EventEmitter<ToolbarItemEvent> {
fn set_active_pane_item(
&mut self,
active_pane_item: Option<&dyn crate::ItemHandle>,
cx: &mut ViewContext<Self>,
) -> ToolbarItemLocation;
- fn location_for_event(
- &self,
- _event: &Self::Event,
- current_location: ToolbarItemLocation,
- _cx: &AppContext,
- ) -> ToolbarItemLocation {
- current_location
- }
-
fn pane_focus_update(&mut self, _pane_focused: bool, _cx: &mut ViewContext<Self>) {}
/// Number of times toolbar's height will be repeated to get the effective height.
@@ -211,12 +204,13 @@ impl Toolbar {
if let Some((_, current_location)) =
this.items.iter_mut().find(|(i, _)| i.id() == item.id())
{
- let new_location = item
- .read(cx)
- .location_for_event(event, *current_location, cx);
- if new_location != *current_location {
- *current_location = new_location;
- cx.notify();
+ match event {
+ ToolbarItemEvent::ChangeLocation(new_location) => {
+ if new_location != current_location {
+ *current_location = *new_location;
+ cx.notify();
+ }
+ }
}
}
})
@@ -36,7 +36,7 @@ use futures::{
Future, FutureExt, StreamExt,
};
use gpui::{
- div, point, rems, size, AnyModel, AnyView, AnyWeakView, AppContext, AsyncAppContext,
+ actions, div, point, rems, size, AnyModel, AnyView, AnyWeakView, AppContext, AsyncAppContext,
AsyncWindowContext, Bounds, Component, Div, Entity, EntityId, EventEmitter, FocusHandle,
GlobalPixels, Model, ModelContext, ParentElement, Point, Render, Size, StatefulInteractive,
Styled, Subscription, Task, View, ViewContext, VisualContext, WeakView, WindowBounds,
@@ -88,35 +88,32 @@ lazy_static! {
// #[derive(Clone, PartialEq)]
// pub struct RemoveWorktreeFromProject(pub WorktreeId);
-// actions!(
-// workspace,
-// [
-// Open,
-// NewFile,
-// NewWindow,
-// CloseWindow,
-// CloseInactiveTabsAndPanes,
-// AddFolderToProject,
-// Unfollow,
-// SaveAs,
-// ReloadActiveItem,
-// ActivatePreviousPane,
-// ActivateNextPane,
-// FollowNextCollaborator,
-// NewTerminal,
-// NewCenterTerminal,
-// ToggleTerminalFocus,
-// NewSearch,
-// Feedback,
-// Restart,
-// Welcome,
-// ToggleZoom,
-// ToggleLeftDock,
-// ToggleRightDock,
-// ToggleBottomDock,
-// CloseAllDocks,
-// ]
-// );
+actions!(
+ Open,
+ NewFile,
+ NewWindow,
+ CloseWindow,
+ CloseInactiveTabsAndPanes,
+ AddFolderToProject,
+ Unfollow,
+ SaveAs,
+ ReloadActiveItem,
+ ActivatePreviousPane,
+ ActivateNextPane,
+ FollowNextCollaborator,
+ NewTerminal,
+ NewCenterTerminal,
+ ToggleTerminalFocus,
+ NewSearch,
+ Feedback,
+ Restart,
+ Welcome,
+ ToggleZoom,
+ ToggleLeftDock,
+ ToggleRightDock,
+ ToggleBottomDock,
+ CloseAllDocks,
+);
// #[derive(Clone, PartialEq)]
// pub struct OpenPaths {
@@ -964,6 +961,9 @@ impl Workspace {
// let mut prev_position = panel.position(cx);
// move |this, panel, event, cx| {
// if T::should_change_position_on_event(event) {
+ // THIS HAS BEEN MOVED TO NORMAL EVENT EMISSION
+ // See: Dock::add_panel
+ //
// let new_position = panel.read(cx).position(cx);
// let mut was_visible = false;
// dock.update(cx, |dock, cx| {
@@ -994,6 +994,9 @@ impl Workspace {
// }
// });
// } else if T::should_zoom_in_on_event(event) {
+ // THIS HAS BEEN MOVED TO NORMAL EVENT EMISSION
+ // See: Dock::add_panel
+ //
// dock.update(cx, |dock, cx| dock.set_panel_zoomed(&panel, true, cx));
// if !panel.has_focus(cx) {
// cx.focus(&panel);
@@ -1001,6 +1004,9 @@ impl Workspace {
// this.zoomed = Some(panel.downgrade().into_any());
// this.zoomed_position = Some(panel.read(cx).position(cx));
// } else if T::should_zoom_out_on_event(event) {
+ // THIS HAS BEEN MOVED TO NORMAL EVENT EMISSION
+ // See: Dock::add_panel
+ //
// dock.update(cx, |dock, cx| dock.set_panel_zoomed(&panel, false, cx));
// if this.zoomed_position == Some(prev_position) {
// this.zoomed = None;
@@ -1008,6 +1014,9 @@ impl Workspace {
// }
// cx.notify();
// } else if T::is_focus_event(event) {
+ // THIS HAS BEEN MOVED TO NORMAL EVENT EMISSION
+ // See: Dock::add_panel
+ //
// let position = panel.read(cx).position(cx);
// this.dismiss_zoomed_items_to_reveal(Some(position), cx);
// if panel.is_zoomed(cx) {
@@ -3691,9 +3700,7 @@ fn notify_if_database_failed(workspace: WindowHandle<Workspace>, cx: &mut AsyncA
.log_err();
}
-impl EventEmitter for Workspace {
- type Event = Event;
-}
+impl EventEmitter<Event> for Workspace {}
impl Render for Workspace {
type Element = Div<Self>;
@@ -4135,10 +4142,6 @@ impl WorkspaceStore {
}
}
-impl EventEmitter for WorkspaceStore {
- type Event = ();
-}
-
impl ViewId {
pub(crate) fn from_proto(message: proto::ViewId) -> Result<Self> {
Ok(Self {