Merge branch 'main' into ime-support-2

This commit is contained in:
Antonio Scandurra 2022-07-22 16:03:38 +02:00
commit 7b009c8bbe
209 changed files with 1859 additions and 9740 deletions

View file

View file

@ -13,8 +13,9 @@ use gpui::{
},
impl_actions, impl_internal_actions,
platform::{CursorStyle, NavigationDirection},
AppContext, AsyncAppContext, Entity, ModelHandle, MutableAppContext, PromptLevel, Quad,
RenderContext, Task, View, ViewContext, ViewHandle, WeakViewHandle,
AppContext, AsyncAppContext, Entity, ModelHandle, MouseButton, MouseButtonEvent,
MutableAppContext, PromptLevel, Quad, RenderContext, Task, View, ViewContext, ViewHandle,
WeakViewHandle,
};
use project::{Project, ProjectEntryId, ProjectPath};
use serde::Deserialize;
@ -135,6 +136,7 @@ pub enum Event {
pub struct Pane {
items: Vec<Box<dyn ItemHandle>>,
is_active: bool,
active_item_index: usize,
autoscroll: bool,
nav_history: Rc<RefCell<NavHistory>>,
@ -183,6 +185,7 @@ impl Pane {
let split_menu = cx.add_view(|cx| ContextMenu::new(cx));
Self {
items: Vec::new(),
is_active: true,
active_item_index: 0,
autoscroll: false,
nav_history: Rc::new(RefCell::new(NavHistory {
@ -198,6 +201,11 @@ impl Pane {
}
}
pub fn set_active(&mut self, is_active: bool, cx: &mut ViewContext<Self>) {
self.is_active = is_active;
cx.notify();
}
pub fn nav_history_for_item<T: Item>(&self, item: &ViewHandle<T>) -> ItemNavHistory {
ItemNavHistory {
history: self.nav_history.clone(),
@ -864,26 +872,23 @@ impl Pane {
None
};
let is_pane_active = self.is_active;
let mut row = Flex::row().scrollable::<Tabs, _>(1, autoscroll, cx);
for (ix, (item, detail)) in self.items.iter().zip(self.tab_details(cx)).enumerate() {
let detail = if detail == 0 { None } else { Some(detail) };
let is_active = ix == self.active_item_index;
let is_tab_active = ix == self.active_item_index;
row.add_child({
let tab_style = if is_active {
theme.workspace.active_tab.clone()
} else {
theme.workspace.tab.clone()
let mut tab_style = match (is_pane_active, is_tab_active) {
(true, true) => theme.workspace.active_pane_active_tab.clone(),
(true, false) => theme.workspace.active_pane_inactive_tab.clone(),
(false, true) => theme.workspace.inactive_pane_active_tab.clone(),
(false, false) => theme.workspace.inactive_pane_inactive_tab.clone(),
};
let title = item.tab_content(detail, &tab_style, cx);
let mut style = if is_active {
theme.workspace.active_tab.clone()
} else {
theme.workspace.tab.clone()
};
if ix == 0 {
style.container.border.left = false;
tab_style.container.border.left = false;
}
MouseEventHandler::new::<Tab, _, _>(ix, cx, |_, cx| {
@ -893,9 +898,9 @@ impl Pane {
Align::new({
let diameter = 7.0;
let icon_color = if item.has_conflict(cx) {
Some(style.icon_conflict)
Some(tab_style.icon_conflict)
} else if item.is_dirty(cx) {
Some(style.icon_dirty)
Some(tab_style.icon_dirty)
} else {
None
};
@ -927,8 +932,8 @@ impl Pane {
Container::new(Align::new(title).boxed())
.with_style(ContainerStyle {
margin: Margin {
left: style.spacing,
right: style.spacing,
left: tab_style.spacing,
right: tab_style.spacing,
..Default::default()
},
..Default::default()
@ -940,24 +945,25 @@ impl Pane {
ConstrainedBox::new(if mouse_state.hovered {
let item_id = item.id();
enum TabCloseButton {}
let icon = Svg::new("icons/x.svg");
let icon = Svg::new("icons/x_mark_thin_8.svg");
MouseEventHandler::new::<TabCloseButton, _, _>(
item_id,
cx,
|mouse_state, _| {
if mouse_state.hovered {
icon.with_color(style.icon_close_active)
icon.with_color(tab_style.icon_close_active)
.boxed()
} else {
icon.with_color(style.icon_close).boxed()
icon.with_color(tab_style.icon_close)
.boxed()
}
},
)
.with_padding(Padding::uniform(4.))
.with_cursor_style(CursorStyle::PointingHand)
.on_click({
.on_click(MouseButton::Left, {
let pane = pane.clone();
move |_, _, cx| {
move |_, cx| {
cx.dispatch_action(CloseItem {
item_id,
pane: pane.clone(),
@ -968,27 +974,39 @@ impl Pane {
} else {
Empty::new().boxed()
})
.with_width(style.icon_width)
.with_width(tab_style.icon_width)
.boxed(),
)
.boxed(),
)
.boxed(),
)
.with_style(style.container)
.with_style(tab_style.container)
.boxed()
})
.on_mouse_down(move |_, cx| {
.with_cursor_style(if is_tab_active && is_pane_active {
CursorStyle::Arrow
} else {
CursorStyle::PointingHand
})
.on_down(MouseButton::Left, move |_, cx| {
cx.dispatch_action(ActivateItem(ix));
})
.boxed()
})
}
let filler_style = if is_pane_active {
&theme.workspace.active_pane_inactive_tab
} else {
&theme.workspace.inactive_pane_inactive_tab
};
row.add_child(
Empty::new()
.contained()
.with_border(theme.workspace.tab.container.border)
.with_style(filler_style.container)
.with_border(theme.workspace.active_pane_active_tab.container.border)
.flex(0., true)
.named("filler"),
);
@ -1053,10 +1071,12 @@ impl View for Pane {
.with_child(
EventHandler::new(if let Some(active_item) = self.active_item() {
Flex::column()
.with_child(
Flex::row()
.with_child(self.render_tabs(cx).flex(1., true).named("tabs"))
.with_child(
.with_child({
let mut tab_row = Flex::row()
.with_child(self.render_tabs(cx).flex(1., true).named("tabs"));
if self.is_active {
tab_row.add_child(
MouseEventHandler::new::<SplitIcon, _, _>(
0,
cx,
@ -1064,7 +1084,7 @@ impl View for Pane {
let theme = &cx.global::<Settings>().theme.workspace;
let style =
theme.pane_button.style_for(mouse_state, false);
Svg::new("icons/split.svg")
Svg::new("icons/split_12.svg")
.with_color(style.color)
.constrained()
.with_width(style.icon_width)
@ -1079,20 +1099,44 @@ impl View for Pane {
},
)
.with_cursor_style(CursorStyle::PointingHand)
.on_mouse_down(|position, cx| {
cx.dispatch_action(DeploySplitMenu { position });
})
.on_down(
MouseButton::Left,
|MouseButtonEvent { position, .. }, cx| {
cx.dispatch_action(DeploySplitMenu { position });
},
)
.boxed(),
)
}
tab_row
.constrained()
.with_height(cx.global::<Settings>().theme.workspace.tab.height)
.boxed(),
)
.with_height(
cx.global::<Settings>()
.theme
.workspace
.active_pane_active_tab
.height,
)
.boxed()
})
.with_child(ChildView::new(&self.toolbar).boxed())
.with_child(ChildView::new(active_item).flex(1., true).boxed())
.boxed()
} else {
Empty::new().boxed()
enum EmptyPane {}
let theme = cx.global::<Settings>().theme.clone();
MouseEventHandler::new::<EmptyPane, _, _>(0, cx, |_, _| {
Empty::new()
.contained()
.with_background_color(theme.workspace.background)
.boxed()
})
.on_down(MouseButton::Left, |_, cx| {
cx.focus_parent_view();
})
.boxed()
})
.on_navigate_mouse_down(move |direction, cx| {
let this = this.clone();

View file

@ -1,7 +1,7 @@
use crate::StatusItemView;
use gpui::{
elements::*, impl_actions, platform::CursorStyle, AnyViewHandle, AppContext, Entity,
RenderContext, Subscription, View, ViewContext, ViewHandle,
MouseButton, MouseMovedEvent, RenderContext, Subscription, View, ViewContext, ViewHandle,
};
use serde::Deserialize;
use settings::Settings;
@ -187,19 +187,27 @@ impl Sidebar {
..Default::default()
})
.with_cursor_style(CursorStyle::ResizeLeftRight)
.on_mouse_down(|_, _| {}) // This prevents the mouse down event from being propagated elsewhere
.on_drag(move |old_position, new_position, cx| {
let delta = new_position.x() - old_position.x();
let prev_width = *actual_width.borrow();
*custom_width.borrow_mut() = 0f32
.max(match side {
Side::Left => prev_width + delta,
Side::Right => prev_width - delta,
})
.round();
.on_down(MouseButton::Left, |_, _| {}) // This prevents the mouse down event from being propagated elsewhere
.on_drag(
MouseButton::Left,
move |old_position,
MouseMovedEvent {
position: new_position,
..
},
cx| {
let delta = new_position.x() - old_position.x();
let prev_width = *actual_width.borrow();
*custom_width.borrow_mut() = 0f32
.max(match side {
Side::Left => prev_width + delta,
Side::Right => prev_width - delta,
})
.round();
cx.notify();
})
cx.notify();
},
)
.boxed()
}
}
@ -314,9 +322,9 @@ impl View for SidebarButtons {
.boxed()
})
.with_cursor_style(CursorStyle::PointingHand)
.on_click({
.on_click(MouseButton::Left, {
let action = action.clone();
move |_, _, cx| cx.dispatch_action(action.clone())
move |_, cx| cx.dispatch_action(action.clone())
})
.with_tooltip::<Self, _>(
ix,

View file

@ -1,7 +1,7 @@
use crate::{ItemHandle, Pane};
use gpui::{
elements::*, platform::CursorStyle, Action, AnyViewHandle, AppContext, ElementBox, Entity,
MutableAppContext, RenderContext, View, ViewContext, ViewHandle, WeakViewHandle,
MouseButton, MutableAppContext, RenderContext, View, ViewContext, ViewHandle, WeakViewHandle,
};
use settings::Settings;
@ -118,7 +118,7 @@ impl View for Toolbar {
.with_child(
Flex::row()
.with_child(nav_button(
"icons/arrow-left.svg",
"icons/arrow_left_16.svg",
button_style,
tooltip_style.clone(),
enable_go_backward,
@ -131,7 +131,7 @@ impl View for Toolbar {
cx,
))
.with_child(nav_button(
"icons/arrow-right.svg",
"icons/arrow_right_16.svg",
button_style,
tooltip_style.clone(),
enable_go_forward,
@ -191,7 +191,9 @@ fn nav_button<A: Action + Clone>(
} else {
CursorStyle::default()
})
.on_click(move |_, _, cx| cx.dispatch_action(action.clone()))
.on_click(MouseButton::Left, move |_, cx| {
cx.dispatch_action(action.clone())
})
.with_tooltip::<A, _>(
0,
action_name.to_string(),

View file

@ -21,8 +21,8 @@ use gpui::{
json::{self, ToJson},
platform::{CursorStyle, WindowOptions},
AnyModelHandle, AnyViewHandle, AppContext, AsyncAppContext, Border, Entity, ImageData,
ModelContext, ModelHandle, MutableAppContext, PathPromptOptions, PromptLevel, RenderContext,
Task, View, ViewContext, ViewHandle, WeakViewHandle,
ModelContext, ModelHandle, MouseButton, MutableAppContext, PathPromptOptions, PromptLevel,
RenderContext, Task, View, ViewContext, ViewHandle, WeakViewHandle,
};
use language::LanguageRegistry;
use log::error;
@ -1567,7 +1567,11 @@ impl Workspace {
fn activate_pane(&mut self, pane: ViewHandle<Pane>, cx: &mut ViewContext<Self>) {
if self.active_pane != pane {
self.active_pane
.update(cx, |pane, cx| pane.set_active(false, cx));
self.active_pane = pane.clone();
self.active_pane
.update(cx, |pane, cx| pane.set_active(true, cx));
self.status_bar.update(cx, |status_bar, cx| {
status_bar.set_active_pane(&self.active_pane, cx);
});
@ -1630,17 +1634,17 @@ impl Workspace {
pane: ViewHandle<Pane>,
direction: SplitDirection,
cx: &mut ViewContext<Self>,
) -> ViewHandle<Pane> {
let new_pane = self.add_pane(cx);
self.activate_pane(new_pane.clone(), cx);
if let Some(item) = pane.read(cx).active_item() {
) -> Option<ViewHandle<Pane>> {
pane.read(cx).active_item().map(|item| {
let new_pane = self.add_pane(cx);
self.activate_pane(new_pane.clone(), cx);
if let Some(clone) = item.clone_on_split(cx.as_mut()) {
Pane::add_item(self, new_pane.clone(), clone, true, true, cx);
}
}
self.center.split(&pane, &new_pane, direction).unwrap();
cx.notify();
new_pane
self.center.split(&pane, &new_pane, direction).unwrap();
cx.notify();
new_pane
})
}
fn remove_pane(&mut self, pane: ViewHandle<Pane>, cx: &mut ViewContext<Self>) {
@ -1811,7 +1815,7 @@ impl Workspace {
Container::new(
Align::new(
ConstrainedBox::new(
Svg::new("icons/offline-14.svg")
Svg::new("icons/cloud_slash_12.svg")
.with_color(theme.workspace.titlebar.offline_icon.color)
.boxed(),
)
@ -1981,7 +1985,7 @@ impl Workspace {
.with_style(style.container)
.boxed()
})
.on_click(|_, _, cx| cx.dispatch_action(Authenticate))
.on_click(MouseButton::Left, |_, cx| cx.dispatch_action(Authenticate))
.with_cursor_style(CursorStyle::PointingHand)
.aligned()
.boxed(),
@ -2032,7 +2036,9 @@ impl Workspace {
if let Some((peer_id, peer_github_login)) = peer {
MouseEventHandler::new::<ToggleFollow, _, _>(replica_id.into(), cx, move |_, _| content)
.with_cursor_style(CursorStyle::PointingHand)
.on_click(move |_, _, cx| cx.dispatch_action(ToggleFollow(peer_id)))
.on_click(MouseButton::Left, move |_, cx| {
cx.dispatch_action(ToggleFollow(peer_id))
})
.with_tooltip::<ToggleFollow, _>(
peer_id.0 as usize,
if is_followed {
@ -3056,16 +3062,17 @@ mod tests {
// multi-entry items: (3, 4)
let left_pane = workspace.update(cx, |workspace, cx| {
let left_pane = workspace.active_pane().clone();
let right_pane = workspace.split_pane(left_pane.clone(), SplitDirection::Right, cx);
workspace.activate_pane(left_pane.clone(), cx);
workspace.add_item(Box::new(cx.add_view(|_| item_2_3.clone())), cx);
for item in &single_entry_items {
workspace.add_item(Box::new(cx.add_view(|_| item.clone())), cx);
}
left_pane.update(cx, |pane, cx| {
pane.activate_item(2, true, true, false, cx);
});
workspace.activate_pane(right_pane.clone(), cx);
workspace.add_item(Box::new(cx.add_view(|_| single_entry_items[1].clone())), cx);
workspace
.split_pane(left_pane.clone(), SplitDirection::Right, cx)
.unwrap();
workspace.add_item(Box::new(cx.add_view(|_| item_3_4.clone())), cx);
left_pane