Added welcome experience sketch
Made toolbar hideable
This commit is contained in:
parent
7d7053b990
commit
5210be95fe
9 changed files with 103 additions and 51 deletions
|
@ -39,20 +39,24 @@ impl_internal_actions!(dock, [MoveDock, AddDefaultItemToDock]);
|
|||
pub fn init(cx: &mut MutableAppContext) {
|
||||
cx.add_action(Dock::focus_dock);
|
||||
cx.add_action(Dock::hide_dock);
|
||||
cx.add_action(Dock::move_dock);
|
||||
cx.add_action(
|
||||
|workspace: &mut Workspace, &MoveDock(dock_anchor), cx: &mut ViewContext<Workspace>| {
|
||||
Dock::move_dock(workspace, dock_anchor, true, cx);
|
||||
},
|
||||
);
|
||||
cx.add_action(
|
||||
|workspace: &mut Workspace, _: &AnchorDockRight, cx: &mut ViewContext<Workspace>| {
|
||||
Dock::move_dock(workspace, &MoveDock(DockAnchor::Right), cx)
|
||||
Dock::move_dock(workspace, DockAnchor::Right, true, cx);
|
||||
},
|
||||
);
|
||||
cx.add_action(
|
||||
|workspace: &mut Workspace, _: &AnchorDockBottom, cx: &mut ViewContext<Workspace>| {
|
||||
Dock::move_dock(workspace, &MoveDock(DockAnchor::Bottom), cx)
|
||||
Dock::move_dock(workspace, DockAnchor::Bottom, true, cx)
|
||||
},
|
||||
);
|
||||
cx.add_action(
|
||||
|workspace: &mut Workspace, _: &ExpandDock, cx: &mut ViewContext<Workspace>| {
|
||||
Dock::move_dock(workspace, &MoveDock(DockAnchor::Expanded), cx)
|
||||
Dock::move_dock(workspace, DockAnchor::Expanded, true, cx)
|
||||
},
|
||||
);
|
||||
cx.add_action(
|
||||
|
@ -215,6 +219,7 @@ impl Dock {
|
|||
pub(crate) fn set_dock_position(
|
||||
workspace: &mut Workspace,
|
||||
new_position: DockPosition,
|
||||
focus: bool,
|
||||
cx: &mut ViewContext<Workspace>,
|
||||
) {
|
||||
workspace.dock.position = new_position;
|
||||
|
@ -235,19 +240,23 @@ impl Dock {
|
|||
let pane = workspace.dock.pane.clone();
|
||||
if pane.read(cx).items().next().is_none() {
|
||||
if let Some(item_to_add) = (workspace.dock.default_item_factory)(workspace, cx) {
|
||||
Pane::add_item(workspace, &pane, item_to_add, true, true, None, cx);
|
||||
Pane::add_item(workspace, &pane, item_to_add, focus, focus, None, cx);
|
||||
} else {
|
||||
workspace.dock.position = workspace.dock.position.hide();
|
||||
}
|
||||
} else {
|
||||
cx.focus(pane);
|
||||
if focus {
|
||||
cx.focus(pane);
|
||||
}
|
||||
}
|
||||
} else if let Some(last_active_center_pane) = workspace
|
||||
.last_active_center_pane
|
||||
.as_ref()
|
||||
.and_then(|pane| pane.upgrade(cx))
|
||||
{
|
||||
cx.focus(last_active_center_pane);
|
||||
if focus {
|
||||
cx.focus(last_active_center_pane);
|
||||
}
|
||||
}
|
||||
cx.emit(crate::Event::DockAnchorChanged);
|
||||
workspace.serialize_workspace(cx);
|
||||
|
@ -255,11 +264,11 @@ impl Dock {
|
|||
}
|
||||
|
||||
pub fn hide(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
|
||||
Self::set_dock_position(workspace, workspace.dock.position.hide(), cx);
|
||||
Self::set_dock_position(workspace, workspace.dock.position.hide(), true, cx);
|
||||
}
|
||||
|
||||
pub fn show(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
|
||||
Self::set_dock_position(workspace, workspace.dock.position.show(), cx);
|
||||
pub fn show(workspace: &mut Workspace, focus: bool, cx: &mut ViewContext<Workspace>) {
|
||||
Self::set_dock_position(workspace, workspace.dock.position.show(), focus, cx);
|
||||
}
|
||||
|
||||
pub fn hide_on_sidebar_shown(
|
||||
|
@ -275,19 +284,20 @@ impl Dock {
|
|||
}
|
||||
|
||||
fn focus_dock(workspace: &mut Workspace, _: &FocusDock, cx: &mut ViewContext<Workspace>) {
|
||||
Self::set_dock_position(workspace, workspace.dock.position.show(), cx);
|
||||
Self::set_dock_position(workspace, workspace.dock.position.show(), true, cx);
|
||||
}
|
||||
|
||||
fn hide_dock(workspace: &mut Workspace, _: &HideDock, cx: &mut ViewContext<Workspace>) {
|
||||
Self::set_dock_position(workspace, workspace.dock.position.hide(), cx);
|
||||
Self::set_dock_position(workspace, workspace.dock.position.hide(), true, cx);
|
||||
}
|
||||
|
||||
fn move_dock(
|
||||
pub fn move_dock(
|
||||
workspace: &mut Workspace,
|
||||
&MoveDock(new_anchor): &MoveDock,
|
||||
new_anchor: DockAnchor,
|
||||
focus: bool,
|
||||
cx: &mut ViewContext<Workspace>,
|
||||
) {
|
||||
Self::set_dock_position(workspace, DockPosition::Shown(new_anchor), cx);
|
||||
Self::set_dock_position(workspace, DockPosition::Shown(new_anchor), focus, cx);
|
||||
}
|
||||
|
||||
pub fn render(
|
||||
|
|
|
@ -151,6 +151,9 @@ pub trait Item: View {
|
|||
"deserialize() must be implemented if serialized_item_kind() returns Some(_)"
|
||||
)
|
||||
}
|
||||
fn show_toolbar(&self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ItemHandle: 'static + fmt::Debug {
|
||||
|
@ -213,6 +216,7 @@ pub trait ItemHandle: 'static + fmt::Debug {
|
|||
fn breadcrumb_location(&self, cx: &AppContext) -> ToolbarItemLocation;
|
||||
fn breadcrumbs(&self, theme: &Theme, cx: &AppContext) -> Option<Vec<ElementBox>>;
|
||||
fn serialized_item_kind(&self) -> Option<&'static str>;
|
||||
fn show_toolbar(&self, cx: &AppContext) -> bool;
|
||||
}
|
||||
|
||||
pub trait WeakItemHandle {
|
||||
|
@ -591,6 +595,10 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
|
|||
fn serialized_item_kind(&self) -> Option<&'static str> {
|
||||
T::serialized_item_kind()
|
||||
}
|
||||
|
||||
fn show_toolbar(&self, cx: &AppContext) -> bool {
|
||||
self.read(cx).show_toolbar()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Box<dyn ItemHandle>> for AnyViewHandle {
|
||||
|
|
|
@ -1485,11 +1485,12 @@ impl View for Pane {
|
|||
cx,
|
||||
{
|
||||
let toolbar = self.toolbar.clone();
|
||||
let toolbar_hidden = toolbar.read(cx).hidden();
|
||||
move |_, cx| {
|
||||
Flex::column()
|
||||
.with_child(
|
||||
ChildView::new(&toolbar, cx).expanded().boxed(),
|
||||
)
|
||||
.with_children((!toolbar_hidden).then(|| {
|
||||
ChildView::new(&toolbar, cx).expanded().boxed()
|
||||
}))
|
||||
.with_child(
|
||||
ChildView::new(active_item, cx)
|
||||
.flex(1., true)
|
||||
|
|
|
@ -42,6 +42,7 @@ pub enum ToolbarItemLocation {
|
|||
|
||||
pub struct Toolbar {
|
||||
active_pane_item: Option<Box<dyn ItemHandle>>,
|
||||
hidden: bool,
|
||||
pane: WeakViewHandle<Pane>,
|
||||
items: Vec<(Box<dyn ToolbarItemViewHandle>, ToolbarItemLocation)>,
|
||||
}
|
||||
|
@ -211,6 +212,7 @@ impl Toolbar {
|
|||
active_pane_item: None,
|
||||
pane,
|
||||
items: Default::default(),
|
||||
hidden: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -243,6 +245,12 @@ impl Toolbar {
|
|||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
self.active_pane_item = pane_item.map(|item| item.boxed_clone());
|
||||
self.hidden = self
|
||||
.active_pane_item
|
||||
.as_ref()
|
||||
.map(|item| !item.show_toolbar(cx))
|
||||
.unwrap_or(false);
|
||||
|
||||
for (toolbar_item, current_location) in self.items.iter_mut() {
|
||||
let new_location = toolbar_item.set_active_pane_item(pane_item, cx);
|
||||
if new_location != *current_location {
|
||||
|
@ -257,6 +265,10 @@ impl Toolbar {
|
|||
.iter()
|
||||
.find_map(|(item, _)| item.to_any().downcast())
|
||||
}
|
||||
|
||||
pub fn hidden(&self) -> bool {
|
||||
self.hidden
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: ToolbarItemView> ToolbarItemViewHandle for ViewHandle<T> {
|
||||
|
|
|
@ -197,20 +197,12 @@ pub fn init(app_state: Arc<AppState>, cx: &mut MutableAppContext) {
|
|||
}
|
||||
}
|
||||
});
|
||||
cx.add_global_action({
|
||||
let app_state = Arc::downgrade(&app_state);
|
||||
move |_: &Welcome, cx: &mut MutableAppContext| {
|
||||
if let Some(app_state) = app_state.upgrade() {
|
||||
open_new(&app_state, cx).detach();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
cx.add_global_action({
|
||||
let app_state = Arc::downgrade(&app_state);
|
||||
move |_: &NewWindow, cx: &mut MutableAppContext| {
|
||||
if let Some(app_state) = app_state.upgrade() {
|
||||
open_new(&app_state, cx).detach();
|
||||
open_new(&app_state, cx, |_, cx| cx.dispatch_action(NewFile)).detach();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -1514,7 +1506,7 @@ impl Workspace {
|
|||
self.active_item_path_changed(cx);
|
||||
|
||||
if &pane == self.dock_pane() {
|
||||
Dock::show(self, cx);
|
||||
Dock::show(self, true, cx);
|
||||
} else {
|
||||
self.last_active_center_pane = Some(pane.downgrade());
|
||||
if self.dock.is_anchored_at(DockAnchor::Expanded) {
|
||||
|
@ -2527,7 +2519,12 @@ impl Workspace {
|
|||
// the focus the dock generates start generating alternating
|
||||
// focus due to the deferred execution each triggering each other
|
||||
cx.after_window_update(move |workspace, cx| {
|
||||
Dock::set_dock_position(workspace, serialized_workspace.dock_position, cx);
|
||||
Dock::set_dock_position(
|
||||
workspace,
|
||||
serialized_workspace.dock_position,
|
||||
true,
|
||||
cx,
|
||||
);
|
||||
});
|
||||
|
||||
cx.notify();
|
||||
|
@ -2859,14 +2856,18 @@ pub fn open_paths(
|
|||
})
|
||||
}
|
||||
|
||||
pub fn open_new(app_state: &Arc<AppState>, cx: &mut MutableAppContext) -> Task<()> {
|
||||
pub fn open_new(
|
||||
app_state: &Arc<AppState>,
|
||||
cx: &mut MutableAppContext,
|
||||
init: impl FnOnce(&mut Workspace, &mut ViewContext<Workspace>) + 'static,
|
||||
) -> Task<()> {
|
||||
let task = Workspace::new_local(Vec::new(), app_state.clone(), cx);
|
||||
cx.spawn(|mut cx| async move {
|
||||
let (workspace, opened_paths) = task.await;
|
||||
|
||||
workspace.update(&mut cx, |_, cx| {
|
||||
workspace.update(&mut cx, |workspace, cx| {
|
||||
if opened_paths.is_empty() {
|
||||
cx.dispatch_action(Welcome);
|
||||
init(workspace, cx)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue