Register actions on the right div
This commit is contained in:
parent
c8fb8e2859
commit
44534b926d
2 changed files with 27 additions and 8 deletions
|
@ -1,8 +1,9 @@
|
||||||
use crate::SharedString;
|
use crate::SharedString;
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Eq, PartialEq, Hash)]
|
#[derive(Clone, Default, Eq, PartialEq, Hash)]
|
||||||
pub struct KeyContext(SmallVec<[ContextEntry; 8]>);
|
pub struct KeyContext(SmallVec<[ContextEntry; 8]>);
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
|
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
|
||||||
|
@ -99,6 +100,23 @@ impl KeyContext {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for KeyContext {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
let mut entries = self.0.iter().peekable();
|
||||||
|
while let Some(entry) = entries.next() {
|
||||||
|
if let Some(ref value) = entry.value {
|
||||||
|
write!(f, "{}={}", entry.key, value)?;
|
||||||
|
} else {
|
||||||
|
write!(f, "{}", entry.key)?;
|
||||||
|
}
|
||||||
|
if entries.peek().is_some() {
|
||||||
|
write!(f, " ")?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
|
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
|
||||||
pub enum KeyBindingContextPredicate {
|
pub enum KeyBindingContextPredicate {
|
||||||
Identifier(SharedString),
|
Identifier(SharedString),
|
||||||
|
|
|
@ -39,7 +39,7 @@ use gpui::{
|
||||||
actions, div, point, rems, size, Action, AnyModel, AnyView, AnyWeakView, AppContext,
|
actions, div, point, rems, size, Action, AnyModel, AnyView, AnyWeakView, AppContext,
|
||||||
AsyncAppContext, AsyncWindowContext, Bounds, Component, Div, Entity, EntityId, EventEmitter,
|
AsyncAppContext, AsyncWindowContext, Bounds, Component, Div, Entity, EntityId, EventEmitter,
|
||||||
FocusHandle, GlobalPixels, KeyContext, Model, ModelContext, ParentElement, Point, Render, Size,
|
FocusHandle, GlobalPixels, KeyContext, Model, ModelContext, ParentElement, Point, Render, Size,
|
||||||
StatefulInteractive, StatefulInteractivity, StatelessInteractive, Styled, Subscription, Task,
|
StatefulInteractive, StatelessInteractive, StatelessInteractivity, Styled, Subscription, Task,
|
||||||
View, ViewContext, VisualContext, WeakView, WindowBounds, WindowContext, WindowHandle,
|
View, ViewContext, VisualContext, WeakView, WindowBounds, WindowContext, WindowHandle,
|
||||||
WindowOptions,
|
WindowOptions,
|
||||||
};
|
};
|
||||||
|
@ -534,8 +534,8 @@ pub struct Workspace {
|
||||||
workspace_actions: Vec<
|
workspace_actions: Vec<
|
||||||
Box<
|
Box<
|
||||||
dyn Fn(
|
dyn Fn(
|
||||||
Div<Workspace, StatefulInteractivity<Workspace>>,
|
Div<Workspace, StatelessInteractivity<Workspace>>,
|
||||||
) -> Div<Workspace, StatefulInteractivity<Workspace>>,
|
) -> Div<Workspace, StatelessInteractivity<Workspace>>,
|
||||||
>,
|
>,
|
||||||
>,
|
>,
|
||||||
zoomed: Option<AnyWeakView>,
|
zoomed: Option<AnyWeakView>,
|
||||||
|
@ -3514,8 +3514,8 @@ impl Workspace {
|
||||||
|
|
||||||
fn add_workspace_actions_listeners(
|
fn add_workspace_actions_listeners(
|
||||||
&self,
|
&self,
|
||||||
mut div: Div<Workspace, StatefulInteractivity<Workspace>>,
|
mut div: Div<Workspace, StatelessInteractivity<Workspace>>,
|
||||||
) -> Div<Workspace, StatefulInteractivity<Workspace>> {
|
) -> Div<Workspace, StatelessInteractivity<Workspace>> {
|
||||||
for action in self.workspace_actions.iter() {
|
for action in self.workspace_actions.iter() {
|
||||||
div = (action)(div)
|
div = (action)(div)
|
||||||
}
|
}
|
||||||
|
@ -3746,7 +3746,7 @@ impl Render for Workspace {
|
||||||
let mut context = KeyContext::default();
|
let mut context = KeyContext::default();
|
||||||
context.add("Workspace");
|
context.add("Workspace");
|
||||||
|
|
||||||
div()
|
self.add_workspace_actions_listeners(div())
|
||||||
.context(context)
|
.context(context)
|
||||||
.relative()
|
.relative()
|
||||||
.size_full()
|
.size_full()
|
||||||
|
@ -3761,7 +3761,8 @@ impl Render for Workspace {
|
||||||
.child(self.render_titlebar(cx))
|
.child(self.render_titlebar(cx))
|
||||||
.child(
|
.child(
|
||||||
// todo! should this be a component a view?
|
// todo! should this be a component a view?
|
||||||
self.add_workspace_actions_listeners(div().id("workspace"))
|
div()
|
||||||
|
.id("workspace")
|
||||||
.relative()
|
.relative()
|
||||||
.flex_1()
|
.flex_1()
|
||||||
.w_full()
|
.w_full()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue