Re-implement actions as derive macros instead of blanket impls

This commit is contained in:
Mikayla
2023-11-16 17:32:02 -08:00
parent a0e976599c
commit 4de2c0f7ef
22 changed files with 360 additions and 288 deletions
+4 -6
View File
@@ -7,7 +7,7 @@ use crate::{
use anyhow::Result;
use collections::{HashMap, HashSet, VecDeque};
use gpui::{
actions, prelude::*, register_action, AppContext, AsyncWindowContext, Component, Div, EntityId,
actions, prelude::*, Action, AppContext, AsyncWindowContext, Component, Div, EntityId,
EventEmitter, FocusHandle, Focusable, FocusableView, Model, PromptLevel, Render, Task, View,
ViewContext, VisualContext, WeakView, WindowContext,
};
@@ -70,15 +70,13 @@ pub struct ActivateItem(pub usize);
// pub pane: WeakView<Pane>,
// }
#[register_action]
#[derive(Clone, PartialEq, Debug, Deserialize, Default)]
#[derive(Clone, PartialEq, Debug, Deserialize, Default, Action)]
#[serde(rename_all = "camelCase")]
pub struct CloseActiveItem {
pub save_intent: Option<SaveIntent>,
}
#[register_action]
#[derive(Clone, PartialEq, Debug, Deserialize, Default)]
#[derive(Clone, PartialEq, Debug, Deserialize, Default, Action)]
#[serde(rename_all = "camelCase")]
pub struct CloseAllItems {
pub save_intent: Option<SaveIntent>,
@@ -1917,7 +1915,7 @@ impl Render for Pane {
.on_action(|pane: &mut Pane, _: &SplitRight, cx| pane.split(SplitDirection::Right, cx))
.on_action(|pane: &mut Pane, _: &SplitDown, cx| pane.split(SplitDirection::Down, cx))
.size_full()
.on_action(|pane: &mut Self, action, cx| {
.on_action(|pane: &mut Self, action: &CloseActiveItem, cx| {
pane.close_active_item(action, cx)
.map(|task| task.detach_and_log_err(cx));
})
+6 -7
View File
@@ -29,11 +29,11 @@ use futures::{
Future, FutureExt, StreamExt,
};
use gpui::{
actions, div, point, register_action, size, Action, AnyModel, AnyView, AnyWeakView, AppContext,
AsyncAppContext, AsyncWindowContext, Bounds, Context, Div, Entity, EntityId, EventEmitter,
FocusHandle, FocusableView, GlobalPixels, InteractiveComponent, KeyContext, Model,
ModelContext, ParentComponent, Point, Render, Size, Styled, Subscription, Task, View,
ViewContext, VisualContext, WeakView, WindowBounds, WindowContext, WindowHandle, WindowOptions,
actions, div, point, size, Action, AnyModel, AnyView, AnyWeakView, AppContext, AsyncAppContext,
AsyncWindowContext, Bounds, Context, Div, Entity, EntityId, EventEmitter, FocusHandle,
FocusableView, GlobalPixels, InteractiveComponent, KeyContext, Model, ModelContext,
ParentComponent, Point, Render, Size, Styled, Subscription, Task, View, ViewContext,
VisualContext, WeakView, WindowBounds, WindowContext, WindowHandle, WindowOptions,
};
use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ItemSettings, ProjectItem};
use itertools::Itertools;
@@ -194,8 +194,7 @@ impl Clone for Toast {
}
}
#[register_action]
#[derive(Debug, Default, Clone, Deserialize, PartialEq)]
#[derive(Debug, Default, Clone, Deserialize, PartialEq, Action)]
pub struct OpenTerminal {
pub working_directory: PathBuf,
}