Restructure action macro to assign a namespace to every action

Also, allow arbitrary types to be used as Actions via the impl_actions macro

Co-authored-by: Nathan Sobo <nathan@zed.dev>
Co-authored-by: Keith Simmons <keith@zed.dev>
This commit is contained in:
Max Brunsfeld
2022-04-07 16:20:49 -07:00
co-authored by Nathan Sobo Keith Simmons
parent 206b0f0f8c
commit 5242a3a6dc
33 changed files with 432 additions and 306 deletions
+4 -4
View File
@@ -1,9 +1,9 @@
use crate::{ItemHandle, StatusItemView};
use futures::StreamExt;
use gpui::AppContext;
use gpui::{actions, AppContext};
use gpui::{
action, elements::*, platform::CursorStyle, Entity, ModelHandle, MutableAppContext,
RenderContext, View, ViewContext,
elements::*, platform::CursorStyle, Entity, ModelHandle, MutableAppContext, RenderContext,
View, ViewContext,
};
use language::{LanguageRegistry, LanguageServerBinaryStatus};
use project::{LanguageServerProgress, Project};
@@ -13,7 +13,7 @@ use std::cmp::Reverse;
use std::fmt::Write;
use std::sync::Arc;
action!(DismissErrorMessage);
actions!(lsp_status, [DismissErrorMessage]);
pub struct LspStatus {
checking_for_update: Vec<String>,
+5 -6
View File
@@ -1,10 +1,9 @@
use gpui::{action, keymap::Binding, MutableAppContext};
use gpui::{actions, keymap::Binding, MutableAppContext};
action!(Confirm);
action!(SelectPrev);
action!(SelectNext);
action!(SelectFirst);
action!(SelectLast);
actions!(
menu,
[Confirm, SelectPrev, SelectNext, SelectFirst, SelectLast,]
);
pub fn init(cx: &mut MutableAppContext) {
cx.add_bindings([
+28 -10
View File
@@ -4,9 +4,10 @@ use anyhow::Result;
use collections::{HashMap, VecDeque};
use futures::StreamExt;
use gpui::{
action,
actions,
elements::*,
geometry::{rect::RectF, vector::vec2f},
impl_actions,
keymap::Binding,
platform::{CursorStyle, NavigationDirection},
AppContext, Entity, MutableAppContext, PromptLevel, Quad, RenderContext, Task, View,
@@ -17,15 +18,32 @@ use settings::Settings;
use std::{any::Any, cell::RefCell, cmp, mem, path::Path, rc::Rc};
use util::ResultExt;
action!(Split, SplitDirection);
action!(ActivateItem, usize);
action!(ActivatePrevItem);
action!(ActivateNextItem);
action!(CloseActiveItem);
action!(CloseInactiveItems);
action!(CloseItem, CloseItemParams);
action!(GoBack, Option<WeakViewHandle<Pane>>);
action!(GoForward, Option<WeakViewHandle<Pane>>);
actions!(
pane,
[
ActivatePrevItem,
ActivateNextItem,
CloseActiveItem,
CloseInactiveItems,
]
);
#[derive(Clone)]
pub struct Split(pub SplitDirection);
#[derive(Clone)]
pub struct CloseItem(pub CloseItemParams);
#[derive(Clone)]
pub struct ActivateItem(pub usize);
#[derive(Clone)]
pub struct GoBack(pub Option<WeakViewHandle<Pane>>);
#[derive(Clone)]
pub struct GoForward(pub Option<WeakViewHandle<Pane>>);
impl_actions!(pane, [Split, CloseItem, ActivateItem, GoBack, GoForward,]);
#[derive(Clone)]
pub struct CloseItemParams {
+8 -3
View File
@@ -1,5 +1,5 @@
use super::Workspace;
use gpui::{action, elements::*, platform::CursorStyle, AnyViewHandle, RenderContext};
use gpui::{elements::*, impl_actions, platform::CursorStyle, AnyViewHandle, RenderContext};
use std::{cell::RefCell, rc::Rc};
use theme::Theme;
@@ -21,8 +21,13 @@ struct Item {
view: AnyViewHandle,
}
action!(ToggleSidebarItem, SidebarItemId);
action!(ToggleSidebarItemFocus, SidebarItemId);
#[derive(Clone)]
pub struct ToggleSidebarItem(pub SidebarItemId);
#[derive(Clone)]
pub struct ToggleSidebarItemFocus(pub SidebarItemId);
impl_actions!(workspace, [ToggleSidebarItem, ToggleSidebarItemFocus]);
#[derive(Clone)]
pub struct SidebarItemId {
+34 -13
View File
@@ -13,10 +13,11 @@ use client::{
use clock::ReplicaId;
use collections::{hash_map, HashMap, HashSet};
use gpui::{
action,
actions,
color::Color,
elements::*,
geometry::{rect::RectF, vector::vec2f, PathBuilder},
impl_actions,
json::{self, to_string_pretty, ToJson},
keymap::Binding,
platform::{CursorStyle, WindowOptions},
@@ -69,18 +70,38 @@ type FollowableItemBuilders = HashMap<
),
>;
action!(Open, Arc<AppState>);
action!(OpenNew, Arc<AppState>);
action!(OpenPaths, OpenParams);
action!(ToggleShare);
action!(ToggleFollow, PeerId);
action!(FollowNextCollaborator);
action!(Unfollow);
action!(JoinProject, JoinProjectParams);
action!(Save);
action!(DebugElements);
action!(ActivatePreviousPane);
action!(ActivateNextPane);
actions!(
workspace,
[
ToggleShare,
Unfollow,
Save,
DebugElements,
ActivatePreviousPane,
ActivateNextPane,
FollowNextCollaborator,
]
);
#[derive(Clone)]
pub struct Open(pub Arc<AppState>);
#[derive(Clone)]
pub struct OpenNew(pub Arc<AppState>);
#[derive(Clone)]
pub struct OpenPaths(pub OpenParams);
#[derive(Clone)]
pub struct ToggleFollow(pub PeerId);
#[derive(Clone)]
pub struct JoinProject(pub JoinProjectParams);
impl_actions!(
workspace,
[Open, OpenNew, OpenPaths, ToggleFollow, JoinProject]
);
pub fn init(client: &Arc<Client>, cx: &mut MutableAppContext) {
pane::init(cx);