Merge branch 'main' into collab-titlebar-2
This commit is contained in:
commit
76366422a6
129 changed files with 5610 additions and 1796 deletions
|
@ -445,7 +445,7 @@ type WindowBoundsCallback = Box<dyn FnMut(WindowBounds, Uuid, &mut WindowContext
|
|||
type KeystrokeCallback =
|
||||
Box<dyn FnMut(&Keystroke, &MatchResult, Option<&Box<dyn Action>>, &mut WindowContext) -> bool>;
|
||||
type ActiveLabeledTasksCallback = Box<dyn FnMut(&mut AppContext) -> bool>;
|
||||
type DeserializeActionCallback = fn(json: &str) -> anyhow::Result<Box<dyn Action>>;
|
||||
type DeserializeActionCallback = fn(json: serde_json::Value) -> anyhow::Result<Box<dyn Action>>;
|
||||
type WindowShouldCloseSubscriptionCallback = Box<dyn FnMut(&mut AppContext) -> bool>;
|
||||
|
||||
pub struct AppContext {
|
||||
|
@ -624,14 +624,14 @@ impl AppContext {
|
|||
pub fn deserialize_action(
|
||||
&self,
|
||||
name: &str,
|
||||
argument: Option<&str>,
|
||||
argument: Option<serde_json::Value>,
|
||||
) -> Result<Box<dyn Action>> {
|
||||
let callback = self
|
||||
.action_deserializers
|
||||
.get(name)
|
||||
.ok_or_else(|| anyhow!("unknown action {}", name))?
|
||||
.1;
|
||||
callback(argument.unwrap_or("{}"))
|
||||
callback(argument.unwrap_or_else(|| serde_json::Value::Object(Default::default())))
|
||||
.with_context(|| format!("invalid data for action {}", name))
|
||||
}
|
||||
|
||||
|
@ -5573,7 +5573,7 @@ mod tests {
|
|||
let action1 = cx
|
||||
.deserialize_action(
|
||||
"test::something::ComplexAction",
|
||||
Some(r#"{"arg": "a", "count": 5}"#),
|
||||
Some(serde_json::from_str(r#"{"arg": "a", "count": 5}"#).unwrap()),
|
||||
)
|
||||
.unwrap();
|
||||
let action2 = cx
|
||||
|
|
|
@ -11,7 +11,7 @@ pub trait Action: 'static {
|
|||
fn qualified_name() -> &'static str
|
||||
where
|
||||
Self: Sized;
|
||||
fn from_json_str(json: &str) -> anyhow::Result<Box<dyn Action>>
|
||||
fn from_json_str(json: serde_json::Value) -> anyhow::Result<Box<dyn Action>>
|
||||
where
|
||||
Self: Sized;
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ macro_rules! actions {
|
|||
$crate::__impl_action! {
|
||||
$namespace,
|
||||
$name,
|
||||
fn from_json_str(_: &str) -> $crate::anyhow::Result<Box<dyn $crate::Action>> {
|
||||
fn from_json_str(_: $crate::serde_json::Value) -> $crate::anyhow::Result<Box<dyn $crate::Action>> {
|
||||
Ok(Box::new(Self))
|
||||
}
|
||||
}
|
||||
|
@ -58,8 +58,8 @@ macro_rules! impl_actions {
|
|||
$crate::__impl_action! {
|
||||
$namespace,
|
||||
$name,
|
||||
fn from_json_str(json: &str) -> $crate::anyhow::Result<Box<dyn $crate::Action>> {
|
||||
Ok(Box::new($crate::serde_json::from_str::<Self>(json)?))
|
||||
fn from_json_str(json: $crate::serde_json::Value) -> $crate::anyhow::Result<Box<dyn $crate::Action>> {
|
||||
Ok(Box::new($crate::serde_json::from_value::<Self>(json)?))
|
||||
}
|
||||
}
|
||||
)*
|
||||
|
|
|
@ -394,7 +394,7 @@ impl<'a> WindowContext<'a> {
|
|||
.iter()
|
||||
.filter_map(move |(name, (type_id, deserialize))| {
|
||||
if let Some(action_depth) = handler_depths_by_action_type.get(type_id).copied() {
|
||||
let action = deserialize("{}").ok()?;
|
||||
let action = deserialize(serde_json::Value::Object(Default::default())).ok()?;
|
||||
let bindings = self
|
||||
.keystroke_matcher
|
||||
.bindings_for_action_type(*type_id)
|
||||
|
|
|
@ -211,7 +211,7 @@ impl<V: View> Element<V> for List<V> {
|
|||
let mut cursor = old_items.cursor::<Count>();
|
||||
|
||||
if state.rendered_range.start < new_rendered_range.start {
|
||||
new_items.push_tree(
|
||||
new_items.append(
|
||||
cursor.slice(&Count(state.rendered_range.start), Bias::Right, &()),
|
||||
&(),
|
||||
);
|
||||
|
@ -221,7 +221,7 @@ impl<V: View> Element<V> for List<V> {
|
|||
cursor.next(&());
|
||||
}
|
||||
}
|
||||
new_items.push_tree(
|
||||
new_items.append(
|
||||
cursor.slice(&Count(new_rendered_range.start), Bias::Right, &()),
|
||||
&(),
|
||||
);
|
||||
|
@ -230,7 +230,7 @@ impl<V: View> Element<V> for List<V> {
|
|||
cursor.seek(&Count(new_rendered_range.end), Bias::Right, &());
|
||||
|
||||
if new_rendered_range.end < state.rendered_range.start {
|
||||
new_items.push_tree(
|
||||
new_items.append(
|
||||
cursor.slice(&Count(state.rendered_range.start), Bias::Right, &()),
|
||||
&(),
|
||||
);
|
||||
|
@ -240,7 +240,7 @@ impl<V: View> Element<V> for List<V> {
|
|||
cursor.next(&());
|
||||
}
|
||||
|
||||
new_items.push_tree(cursor.suffix(&()), &());
|
||||
new_items.append(cursor.suffix(&()), &());
|
||||
|
||||
state.items = new_items;
|
||||
state.rendered_range = new_rendered_range;
|
||||
|
@ -413,7 +413,7 @@ impl<V: View> ListState<V> {
|
|||
old_heights.seek_forward(&Count(old_range.end), Bias::Right, &());
|
||||
|
||||
new_heights.extend((0..count).map(|_| ListItem::Unrendered), &());
|
||||
new_heights.push_tree(old_heights.suffix(&()), &());
|
||||
new_heights.append(old_heights.suffix(&()), &());
|
||||
drop(old_heights);
|
||||
state.items = new_heights;
|
||||
}
|
||||
|
|
|
@ -786,7 +786,7 @@ impl platform::Platform for MacPlatform {
|
|||
|
||||
fn set_cursor_style(&self, style: CursorStyle) {
|
||||
unsafe {
|
||||
let cursor: id = match style {
|
||||
let new_cursor: id = match style {
|
||||
CursorStyle::Arrow => msg_send![class!(NSCursor), arrowCursor],
|
||||
CursorStyle::ResizeLeftRight => {
|
||||
msg_send![class!(NSCursor), resizeLeftRightCursor]
|
||||
|
@ -795,7 +795,11 @@ impl platform::Platform for MacPlatform {
|
|||
CursorStyle::PointingHand => msg_send![class!(NSCursor), pointingHandCursor],
|
||||
CursorStyle::IBeam => msg_send![class!(NSCursor), IBeamCursor],
|
||||
};
|
||||
let _: () = msg_send![cursor, set];
|
||||
|
||||
let old_cursor: id = msg_send![class!(NSCursor), currentCursor];
|
||||
if new_cursor != old_cursor {
|
||||
let _: () = msg_send![new_cursor, set];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue