Merge branch 'main' into divs

This commit is contained in:
Nathan Sobo 2023-08-22 16:35:56 -06:00
commit d375f7992d
277 changed files with 19044 additions and 8896 deletions

View file

@ -1,4 +1,4 @@
use crate::{StatusItemView, Workspace};
use crate::{StatusItemView, Workspace, WorkspaceBounds};
use context_menu::{ContextMenu, ContextMenuItem};
use gpui::{
elements::*, platform::CursorStyle, platform::MouseButton, Action, AnyViewHandle, AppContext,
@ -13,20 +13,30 @@ pub trait Panel: View {
fn position_is_valid(&self, position: DockPosition) -> bool;
fn set_position(&mut self, position: DockPosition, cx: &mut ViewContext<Self>);
fn size(&self, cx: &WindowContext) -> f32;
fn set_size(&mut self, size: f32, cx: &mut ViewContext<Self>);
fn icon_path(&self) -> &'static str;
fn set_size(&mut self, size: Option<f32>, cx: &mut ViewContext<Self>);
fn icon_path(&self, cx: &WindowContext) -> Option<&'static str>;
fn icon_tooltip(&self) -> (String, Option<Box<dyn Action>>);
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;
fn should_zoom_out_on_event(_: &Self::Event) -> bool;
fn is_zoomed(&self, cx: &WindowContext) -> bool;
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;
fn should_close_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;
}
@ -40,8 +50,8 @@ pub trait PanelHandle {
fn set_zoomed(&self, zoomed: bool, cx: &mut WindowContext);
fn set_active(&self, active: bool, cx: &mut WindowContext);
fn size(&self, cx: &WindowContext) -> f32;
fn set_size(&self, size: f32, cx: &mut WindowContext);
fn icon_path(&self, cx: &WindowContext) -> &'static str;
fn set_size(&self, size: Option<f32>, cx: &mut WindowContext);
fn icon_path(&self, cx: &WindowContext) -> Option<&'static str>;
fn icon_tooltip(&self, cx: &WindowContext) -> (String, Option<Box<dyn Action>>);
fn icon_label(&self, cx: &WindowContext) -> Option<String>;
fn has_focus(&self, cx: &WindowContext) -> bool;
@ -72,7 +82,7 @@ where
self.read(cx).size(cx)
}
fn set_size(&self, size: f32, cx: &mut WindowContext) {
fn set_size(&self, size: Option<f32>, cx: &mut WindowContext) {
self.update(cx, |this, cx| this.set_size(size, cx))
}
@ -88,8 +98,8 @@ where
self.update(cx, |this, cx| this.set_active(active, cx))
}
fn icon_path(&self, cx: &WindowContext) -> &'static str {
self.read(cx).icon_path()
fn icon_path(&self, cx: &WindowContext) -> Option<&'static str> {
self.read(cx).icon_path(cx)
}
fn icon_tooltip(&self, cx: &WindowContext) -> (String, Option<Box<dyn Action>>) {
@ -363,7 +373,7 @@ impl Dock {
}
}
pub fn resize_active_panel(&mut self, size: f32, cx: &mut ViewContext<Self>) {
pub fn resize_active_panel(&mut self, size: Option<f32>, cx: &mut ViewContext<Self>) {
if let Some(entry) = self.panel_entries.get_mut(self.active_panel_index) {
entry.panel.set_size(size, cx);
cx.notify();
@ -376,7 +386,7 @@ impl Dock {
.into_any()
.contained()
.with_style(self.style(cx))
.resizable(
.resizable::<WorkspaceBounds>(
self.position.to_resize_handle_side(),
active_entry.panel.size(cx),
|_, _, _| {},
@ -413,7 +423,7 @@ impl View for Dock {
ChildView::new(active_entry.panel.as_any(), cx)
.contained()
.with_style(style)
.resizable(
.resizable::<WorkspaceBounds>(
self.position.to_resize_handle_side(),
active_entry.panel.size(cx),
|dock: &mut Self, size, cx| dock.resize_active_panel(size, cx),
@ -480,8 +490,9 @@ impl View for PanelButtons {
.map(|item| (item.panel.clone(), item.context_menu.clone()))
.collect::<Vec<_>>();
Flex::row()
.with_children(panels.into_iter().enumerate().map(
.with_children(panels.into_iter().enumerate().filter_map(
|(panel_ix, (view, context_menu))| {
let icon_path = view.icon_path(cx)?;
let is_active = is_open && panel_ix == active_ix;
let (tooltip, tooltip_action) = if is_active {
(
@ -495,93 +506,95 @@ impl View for PanelButtons {
} else {
view.icon_tooltip(cx)
};
Stack::new()
.with_child(
MouseEventHandler::<Self, _>::new(panel_ix, cx, |state, cx| {
let style = button_style.in_state(is_active);
Some(
Stack::new()
.with_child(
MouseEventHandler::new::<Self, _>(panel_ix, cx, |state, cx| {
let style = button_style.in_state(is_active);
let style = style.style_for(state);
Flex::row()
.with_child(
Svg::new(view.icon_path(cx))
.with_color(style.icon_color)
.constrained()
.with_width(style.icon_size)
.aligned(),
)
.with_children(if let Some(label) = view.icon_label(cx) {
Some(
Label::new(label, style.label.text.clone())
.contained()
.with_style(style.label.container)
let style = style.style_for(state);
Flex::row()
.with_child(
Svg::new(icon_path)
.with_color(style.icon_color)
.constrained()
.with_width(style.icon_size)
.aligned(),
)
} else {
None
})
.constrained()
.with_height(style.icon_size)
.contained()
.with_style(style.container)
})
.with_cursor_style(CursorStyle::PointingHand)
.on_click(MouseButton::Left, {
let tooltip_action =
tooltip_action.as_ref().map(|action| action.boxed_clone());
move |_, this, cx| {
if let Some(tooltip_action) = &tooltip_action {
let window = cx.window();
let view_id = this.workspace.id();
let tooltip_action = tooltip_action.boxed_clone();
cx.spawn(|_, mut cx| async move {
window.dispatch_action(
view_id,
&*tooltip_action,
&mut cx,
);
.with_children(if let Some(label) = view.icon_label(cx) {
Some(
Label::new(label, style.label.text.clone())
.contained()
.with_style(style.label.container)
.aligned(),
)
} else {
None
})
.detach();
.constrained()
.with_height(style.icon_size)
.contained()
.with_style(style.container)
})
.with_cursor_style(CursorStyle::PointingHand)
.on_click(MouseButton::Left, {
let tooltip_action =
tooltip_action.as_ref().map(|action| action.boxed_clone());
move |_, this, cx| {
if let Some(tooltip_action) = &tooltip_action {
let window = cx.window();
let view_id = this.workspace.id();
let tooltip_action = tooltip_action.boxed_clone();
cx.spawn(|_, mut cx| async move {
window.dispatch_action(
view_id,
&*tooltip_action,
&mut cx,
);
})
.detach();
}
}
}
})
.on_click(MouseButton::Right, {
let view = view.clone();
let menu = context_menu.clone();
move |_, _, cx| {
const POSITIONS: [DockPosition; 3] = [
DockPosition::Left,
DockPosition::Right,
DockPosition::Bottom,
];
})
.on_click(MouseButton::Right, {
let view = view.clone();
let menu = context_menu.clone();
move |_, _, cx| {
const POSITIONS: [DockPosition; 3] = [
DockPosition::Left,
DockPosition::Right,
DockPosition::Bottom,
];
menu.update(cx, |menu, cx| {
let items = POSITIONS
.into_iter()
.filter(|position| {
*position != dock_position
&& view.position_is_valid(*position, cx)
})
.map(|position| {
let view = view.clone();
ContextMenuItem::handler(
format!("Dock {}", position.to_label()),
move |cx| view.set_position(position, cx),
)
})
.collect();
menu.show(Default::default(), menu_corner, items, cx);
})
}
})
.with_tooltip::<Self>(
panel_ix,
tooltip,
tooltip_action,
tooltip_style.clone(),
cx,
),
)
.with_child(ChildView::new(&context_menu, cx))
menu.update(cx, |menu, cx| {
let items = POSITIONS
.into_iter()
.filter(|position| {
*position != dock_position
&& view.position_is_valid(*position, cx)
})
.map(|position| {
let view = view.clone();
ContextMenuItem::handler(
format!("Dock {}", position.to_label()),
move |cx| view.set_position(position, cx),
)
})
.collect();
menu.show(Default::default(), menu_corner, items, cx);
})
}
})
.with_tooltip::<Self>(
panel_ix,
tooltip,
tooltip_action,
tooltip_style.clone(),
cx,
),
)
.with_child(ChildView::new(&context_menu, cx)),
)
},
))
.contained()
@ -687,12 +700,12 @@ pub mod test {
self.size
}
fn set_size(&mut self, size: f32, _: &mut ViewContext<Self>) {
self.size = size;
fn set_size(&mut self, size: Option<f32>, _: &mut ViewContext<Self>) {
self.size = size.unwrap_or(300.);
}
fn icon_path(&self) -> &'static str {
"icons/test_panel.svg"
fn icon_path(&self, _: &WindowContext) -> Option<&'static str> {
Some("icons/test_panel.svg")
}
fn icon_tooltip(&self) -> (String, Option<Box<dyn Action>>) {

View file

@ -290,7 +290,7 @@ pub mod simple_message_notification {
.flex(1., true),
)
.with_child(
MouseEventHandler::<Cancel, _>::new(0, cx, |state, _| {
MouseEventHandler::new::<Cancel, _>(0, cx, |state, _| {
let style = theme.dismiss_button.style_for(state);
Svg::new("icons/x_mark_8.svg")
.with_color(style.color)
@ -319,7 +319,7 @@ pub mod simple_message_notification {
.with_children({
click_message
.map(|click_message| {
MouseEventHandler::<MessageNotificationTag, _>::new(
MouseEventHandler::new::<MessageNotificationTag, _>(
0,
cx,
|state, _| {

View file

@ -222,6 +222,56 @@ impl TabBarContextMenu {
}
}
#[allow(clippy::too_many_arguments)]
fn nav_button<A: Action, F: 'static + Fn(&mut Pane, &mut ViewContext<Pane>)>(
svg_path: &'static str,
style: theme::Interactive<theme::IconButton>,
nav_button_height: f32,
tooltip_style: TooltipStyle,
enabled: bool,
on_click: F,
tooltip_action: A,
action_name: &str,
cx: &mut ViewContext<Pane>,
) -> AnyElement<Pane> {
MouseEventHandler::new::<A, _>(0, cx, |state, _| {
let style = if enabled {
style.style_for(state)
} else {
style.disabled_style()
};
Svg::new(svg_path)
.with_color(style.color)
.constrained()
.with_width(style.icon_width)
.aligned()
.contained()
.with_style(style.container)
.constrained()
.with_width(style.button_width)
.with_height(nav_button_height)
.aligned()
.top()
})
.with_cursor_style(if enabled {
CursorStyle::PointingHand
} else {
CursorStyle::default()
})
.on_click(MouseButton::Left, move |_, toolbar, cx| {
on_click(toolbar, cx)
})
.with_tooltip::<A>(
0,
action_name.to_string(),
Some(Box::new(tooltip_action)),
tooltip_style,
cx,
)
.contained()
.into_any_named("nav button")
}
impl Pane {
pub fn new(
workspace: WeakViewHandle<Workspace>,
@ -253,7 +303,7 @@ impl Pane {
pane: handle.clone(),
next_timestamp,
}))),
toolbar: cx.add_view(|_| Toolbar::new(Some(handle))),
toolbar: cx.add_view(|_| Toolbar::new()),
tab_bar_context_menu: TabBarContextMenu {
kind: TabBarContextMenuKind::New,
handle: context_menu,
@ -265,7 +315,7 @@ impl Pane {
has_focus: false,
can_drop: Rc::new(|_, _| true),
can_split: true,
render_tab_bar_buttons: Rc::new(|pane, cx| {
render_tab_bar_buttons: Rc::new(move |pane, cx| {
Flex::row()
// New menu
.with_child(Self::render_tab_bar_button(
@ -1211,7 +1261,7 @@ impl Pane {
enum Tab {}
let mouse_event_handler =
MouseEventHandler::<Tab, Pane>::new(ix, cx, |_, cx| {
MouseEventHandler::new::<Tab, _>(ix, cx, |_, cx| {
Self::render_tab(
&item,
pane.clone(),
@ -1420,7 +1470,7 @@ impl Pane {
let item_id = item.id();
enum TabCloseButton {}
let icon = Svg::new("icons/x_mark_8.svg");
MouseEventHandler::<TabCloseButton, _>::new(item_id, cx, |mouse_state, _| {
MouseEventHandler::new::<TabCloseButton, _>(item_id, cx, |mouse_state, _| {
if mouse_state.hovered() {
icon.with_color(tab_style.icon_close_active)
} else {
@ -1485,7 +1535,7 @@ impl Pane {
) -> AnyElement<Pane> {
enum TabBarButton {}
let mut button = MouseEventHandler::<TabBarButton, _>::new(index, cx, |mouse_state, cx| {
let mut button = MouseEventHandler::new::<TabBarButton, _>(index, cx, |mouse_state, cx| {
let theme = &settings::get::<ThemeSettings>(cx).theme.workspace.tab_bar;
let style = theme.pane_button.in_state(is_active).style_for(mouse_state);
Svg::new(icon)
@ -1547,7 +1597,7 @@ impl View for Pane {
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
enum MouseNavigationHandler {}
MouseEventHandler::<MouseNavigationHandler, _>::new(0, cx, |_, cx| {
MouseEventHandler::new::<MouseNavigationHandler, _>(0, cx, |_, cx| {
let active_item_index = self.active_item_index;
if let Some(active_item) = self.active_item() {
@ -1559,7 +1609,7 @@ impl View for Pane {
enum TabBarEventHandler {}
stack.add_child(
MouseEventHandler::<TabBarEventHandler, _>::new(0, cx, |_, _| {
MouseEventHandler::new::<TabBarEventHandler, _>(0, cx, |_, _| {
Empty::new()
.contained()
.with_style(theme.workspace.tab_bar.container)
@ -1571,8 +1621,70 @@ impl View for Pane {
},
),
);
let tooltip_style = theme.tooltip.clone();
let tab_bar_theme = theme.workspace.tab_bar.clone();
let nav_button_height = tab_bar_theme.height;
let button_style = tab_bar_theme.nav_button;
let border_for_nav_buttons = tab_bar_theme
.tab_style(false, false)
.container
.border
.clone();
let mut tab_row = Flex::row()
.with_child(nav_button(
"icons/arrow_left_16.svg",
button_style.clone(),
nav_button_height,
tooltip_style.clone(),
self.can_navigate_backward(),
{
move |pane, cx| {
if let Some(workspace) = pane.workspace.upgrade(cx) {
let pane = cx.weak_handle();
cx.window_context().defer(move |cx| {
workspace.update(cx, |workspace, cx| {
workspace
.go_back(pane, cx)
.detach_and_log_err(cx)
})
})
}
}
},
super::GoBack,
"Go Back",
cx,
))
.with_child(
nav_button(
"icons/arrow_right_16.svg",
button_style.clone(),
nav_button_height,
tooltip_style,
self.can_navigate_forward(),
{
move |pane, cx| {
if let Some(workspace) = pane.workspace.upgrade(cx) {
let pane = cx.weak_handle();
cx.window_context().defer(move |cx| {
workspace.update(cx, |workspace, cx| {
workspace
.go_forward(pane, cx)
.detach_and_log_err(cx)
})
})
}
}
},
super::GoForward,
"Go Forward",
cx,
)
.contained()
.with_border(border_for_nav_buttons),
)
.with_child(self.render_tabs(cx).flex(1., true).into_any_named("tabs"));
if self.has_focus {

View file

@ -19,7 +19,7 @@ pub fn dragged_item_receiver<Tag, D, F>(
split_margin: Option<f32>,
cx: &mut ViewContext<Pane>,
render_child: F,
) -> MouseEventHandler<Tag, Pane>
) -> MouseEventHandler<Pane>
where
Tag: 'static,
D: Element<Pane>,
@ -39,7 +39,7 @@ where
None
};
let mut handler = MouseEventHandler::<Tag, _>::above(region_id, cx, |state, cx| {
let mut handler = MouseEventHandler::above::<Tag, _>(region_id, cx, |state, cx| {
// Observing hovered will cause a render when the mouse enters regardless
// of if mouse position was accessed before
let drag_position = if state.hovered() { drag_position } else { None };

View file

@ -212,7 +212,7 @@ impl Member {
let leader_user_id = leader.user.id;
let app_state = Arc::downgrade(app_state);
Some(
MouseEventHandler::<FollowIntoExternalProject, _>::new(
MouseEventHandler::new::<FollowIntoExternalProject, _>(
pane.id(),
cx,
|_, _| {

View file

@ -72,7 +72,7 @@ impl View for SharedScreen {
enum Focus {}
let frame = self.frame.clone();
MouseEventHandler::<Focus, _>::new(0, cx, |_, cx| {
MouseEventHandler::new::<Focus, _>(0, cx, |_, cx| {
Canvas::new(move |scene, bounds, _, _, _| {
if let Some(frame) = frame.clone() {
let size = constrain_size_preserving_aspect_ratio(

View file

@ -1,7 +1,7 @@
use crate::{ItemHandle, Pane};
use crate::ItemHandle;
use gpui::{
elements::*, platform::CursorStyle, platform::MouseButton, Action, AnyElement, AnyViewHandle,
AppContext, Entity, View, ViewContext, ViewHandle, WeakViewHandle, WindowContext,
elements::*, AnyElement, AnyViewHandle, AppContext, Entity, View, ViewContext, ViewHandle,
WindowContext,
};
pub trait ToolbarItemView: View {
@ -25,7 +25,7 @@ pub trait ToolbarItemView: View {
/// Number of times toolbar's height will be repeated to get the effective height.
/// Useful when multiple rows one under each other are needed.
/// The rows have the same width and act as a whole when reacting to resizes and similar events.
fn row_count(&self) -> usize {
fn row_count(&self, _cx: &ViewContext<Self>) -> usize {
1
}
}
@ -54,7 +54,6 @@ pub struct Toolbar {
active_item: Option<Box<dyn ItemHandle>>,
hidden: bool,
can_navigate: bool,
pane: Option<WeakViewHandle<Pane>>,
items: Vec<(Box<dyn ToolbarItemViewHandle>, ToolbarItemLocation)>,
}
@ -118,76 +117,10 @@ impl View for Toolbar {
}
}
let pane = self.pane.clone();
let mut enable_go_backward = false;
let mut enable_go_forward = false;
if let Some(pane) = pane.and_then(|pane| pane.upgrade(cx)) {
let pane = pane.read(cx);
enable_go_backward = pane.can_navigate_backward();
enable_go_forward = pane.can_navigate_forward();
}
let container_style = theme.container;
let height = theme.height * primary_items_row_count as f32;
let nav_button_height = theme.height;
let button_style = theme.nav_button;
let tooltip_style = theme::current(cx).tooltip.clone();
let mut primary_items = Flex::row();
if self.can_navigate {
primary_items.add_child(nav_button(
"icons/arrow_left_16.svg",
button_style,
nav_button_height,
tooltip_style.clone(),
enable_go_backward,
spacing,
{
move |toolbar, cx| {
if let Some(pane) = toolbar.pane.as_ref().and_then(|pane| pane.upgrade(cx))
{
if let Some(workspace) = pane.read(cx).workspace().upgrade(cx) {
let pane = pane.downgrade();
cx.window_context().defer(move |cx| {
workspace.update(cx, |workspace, cx| {
workspace.go_back(pane, cx).detach_and_log_err(cx);
});
})
}
}
}
},
super::GoBack,
"Go Back",
cx,
));
primary_items.add_child(nav_button(
"icons/arrow_right_16.svg",
button_style,
nav_button_height,
tooltip_style,
enable_go_forward,
spacing,
{
move |toolbar, cx| {
if let Some(pane) = toolbar.pane.as_ref().and_then(|pane| pane.upgrade(cx))
{
if let Some(workspace) = pane.read(cx).workspace().upgrade(cx) {
let pane = pane.downgrade();
cx.window_context().defer(move |cx| {
workspace.update(cx, |workspace, cx| {
workspace.go_forward(pane, cx).detach_and_log_err(cx);
});
})
}
}
}
},
super::GoForward,
"Go Forward",
cx,
));
}
primary_items.extend(primary_left_items);
primary_items.extend(primary_right_items);
@ -210,63 +143,65 @@ impl View for Toolbar {
}
}
#[allow(clippy::too_many_arguments)]
fn nav_button<A: Action, F: 'static + Fn(&mut Toolbar, &mut ViewContext<Toolbar>)>(
svg_path: &'static str,
style: theme::Interactive<theme::IconButton>,
nav_button_height: f32,
tooltip_style: TooltipStyle,
enabled: bool,
spacing: f32,
on_click: F,
tooltip_action: A,
action_name: &'static str,
cx: &mut ViewContext<Toolbar>,
) -> AnyElement<Toolbar> {
MouseEventHandler::<A, _>::new(0, cx, |state, _| {
let style = if enabled {
style.style_for(state)
} else {
style.disabled_style()
};
Svg::new(svg_path)
.with_color(style.color)
.constrained()
.with_width(style.icon_width)
.aligned()
.contained()
.with_style(style.container)
.constrained()
.with_width(style.button_width)
.with_height(nav_button_height)
.aligned()
.top()
})
.with_cursor_style(if enabled {
CursorStyle::PointingHand
} else {
CursorStyle::default()
})
.on_click(MouseButton::Left, move |_, toolbar, cx| {
on_click(toolbar, cx)
})
.with_tooltip::<A>(
0,
action_name,
Some(Box::new(tooltip_action)),
tooltip_style,
cx,
)
.contained()
.with_margin_right(spacing)
.into_any_named("nav button")
}
// <<<<<<< HEAD
// =======
// #[allow(clippy::too_many_arguments)]
// fn nav_button<A: Action, F: 'static + Fn(&mut Toolbar, &mut ViewContext<Toolbar>)>(
// svg_path: &'static str,
// style: theme::Interactive<theme::IconButton>,
// nav_button_height: f32,
// tooltip_style: TooltipStyle,
// enabled: bool,
// spacing: f32,
// on_click: F,
// tooltip_action: A,
// action_name: &'static str,
// cx: &mut ViewContext<Toolbar>,
// ) -> AnyElement<Toolbar> {
// MouseEventHandler::new::<A, _>(0, cx, |state, _| {
// let style = if enabled {
// style.style_for(state)
// } else {
// style.disabled_style()
// };
// Svg::new(svg_path)
// .with_color(style.color)
// .constrained()
// .with_width(style.icon_width)
// .aligned()
// .contained()
// .with_style(style.container)
// .constrained()
// .with_width(style.button_width)
// .with_height(nav_button_height)
// .aligned()
// .top()
// })
// .with_cursor_style(if enabled {
// CursorStyle::PointingHand
// } else {
// CursorStyle::default()
// })
// .on_click(MouseButton::Left, move |_, toolbar, cx| {
// on_click(toolbar, cx)
// })
// .with_tooltip::<A>(
// 0,
// action_name,
// Some(Box::new(tooltip_action)),
// tooltip_style,
// cx,
// )
// .contained()
// .with_margin_right(spacing)
// .into_any_named("nav button")
// }
// >>>>>>> 139cbbfd3aebd0863a7d51b0c12d748764cf0b2e
impl Toolbar {
pub fn new(pane: Option<WeakViewHandle<Pane>>) -> Self {
pub fn new() -> Self {
Self {
active_item: None,
pane,
items: Default::default(),
hidden: false,
can_navigate: true,
@ -362,7 +297,7 @@ impl<T: ToolbarItemView> ToolbarItemViewHandle for ViewHandle<T> {
}
fn row_count(&self, cx: &WindowContext) -> usize {
self.read(cx).row_count()
self.read_with(cx, |this, cx| this.row_count(cx))
}
}

View file

@ -14,7 +14,7 @@ use anyhow::{anyhow, Context, Result};
use call::ActiveCall;
use client::{
proto::{self, PeerId},
Client, TypedEnvelope, UserStore,
ChannelStore, Client, TypedEnvelope, UserStore,
};
use collections::{hash_map, HashMap, HashSet};
use drag_and_drop::DragAndDrop;
@ -400,8 +400,9 @@ pub fn register_deserializable_item<I: Item>(cx: &mut AppContext) {
pub struct AppState {
pub languages: Arc<LanguageRegistry>,
pub client: Arc<client::Client>,
pub user_store: ModelHandle<client::UserStore>,
pub client: Arc<Client>,
pub user_store: ModelHandle<UserStore>,
pub channel_store: ModelHandle<ChannelStore>,
pub fs: Arc<dyn fs::Fs>,
pub build_window_options:
fn(Option<WindowBounds>, Option<uuid::Uuid>, &dyn Platform) -> WindowOptions<'static>,
@ -424,6 +425,8 @@ impl AppState {
let http_client = util::http::FakeHttpClient::with_404_response();
let client = Client::new(http_client.clone(), cx);
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx));
let channel_store =
cx.add_model(|cx| ChannelStore::new(client.clone(), user_store.clone(), cx));
theme::init((), cx);
client::init(&client, cx);
@ -434,6 +437,7 @@ impl AppState {
fs,
languages,
user_store,
channel_store,
initialize_workspace: |_, _, _, _| Task::ready(Ok(())),
build_window_options: |_, _, _| Default::default(),
background_actions: || &[],
@ -549,6 +553,8 @@ struct FollowerState {
items_by_leader_view_id: HashMap<ViewId, Box<dyn FollowableItemHandle>>,
}
enum WorkspaceBounds {}
impl Workspace {
pub fn new(
workspace_id: WorkspaceId,
@ -2560,7 +2566,7 @@ impl Workspace {
};
enum TitleBar {}
MouseEventHandler::<TitleBar, _>::new(0, cx, |_, cx| {
MouseEventHandler::new::<TitleBar, _>(0, cx, |_, cx| {
Stack::new()
.with_children(
self.titlebar_item
@ -2649,7 +2655,7 @@ impl Workspace {
if self.project.read(cx).is_read_only() {
enum DisconnectedOverlay {}
Some(
MouseEventHandler::<DisconnectedOverlay, _>::new(0, cx, |_, cx| {
MouseEventHandler::new::<DisconnectedOverlay, _>(0, cx, |_, cx| {
let theme = &theme::current(cx);
Label::new(
"Your connection to the remote project has been lost.",
@ -3403,10 +3409,16 @@ impl Workspace {
#[cfg(any(test, feature = "test-support"))]
pub fn test_new(project: ModelHandle<Project>, cx: &mut ViewContext<Self>) -> Self {
let client = project.read(cx).client();
let user_store = project.read(cx).user_store();
let channel_store =
cx.add_model(|cx| ChannelStore::new(client.clone(), user_store.clone(), cx));
let app_state = Arc::new(AppState {
languages: project.read(cx).languages().clone(),
client: project.read(cx).client(),
user_store: project.read(cx).user_store(),
client,
user_store,
channel_store,
fs: project.read(cx).fs().clone(),
build_window_options: |_, _, _| Default::default(),
initialize_workspace: |_, _, _, _| Task::ready(Ok(())),
@ -3750,14 +3762,23 @@ impl View for Workspace {
)
}))
.with_children(self.modal.as_ref().map(|modal| {
ChildView::new(modal.view.as_any(), cx)
.contained()
.with_style(theme.workspace.modal)
.aligned()
.top()
// Prevent clicks within the modal from falling
// through to the rest of the workspace.
enum ModalBackground {}
MouseEventHandler::new::<ModalBackground, _>(
0,
cx,
|_, cx| ChildView::new(modal.view.as_any(), cx),
)
.on_click(MouseButton::Left, |_, _, _| {})
.contained()
.with_style(theme.workspace.modal)
.aligned()
.top()
}))
.with_children(self.render_notifications(&theme.workspace, cx)),
))
.provide_resize_bounds::<WorkspaceBounds>()
.flex(1.0, true),
)
.with_child(ChildView::new(&self.status_bar, cx))
@ -4841,7 +4862,9 @@ mod tests {
panel_1.size(cx)
);
left_dock.update(cx, |left_dock, cx| left_dock.resize_active_panel(1337., cx));
left_dock.update(cx, |left_dock, cx| {
left_dock.resize_active_panel(Some(1337.), cx)
});
assert_eq!(
workspace
.right_dock()