Merge branch 'main' into feedback-2
This commit is contained in:
@@ -7,8 +7,8 @@ use gpui::{
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::Arc;
|
||||
use ui::prelude::*;
|
||||
use ui::{h_stack, menu_handle, ContextMenu, IconButton, Tooltip};
|
||||
use ui::{h_stack, ContextMenu, IconButton, Tooltip};
|
||||
use ui::{prelude::*, right_click_menu};
|
||||
|
||||
pub enum PanelEvent {
|
||||
ChangePosition,
|
||||
@@ -702,7 +702,7 @@ impl Render for PanelButtons {
|
||||
};
|
||||
|
||||
Some(
|
||||
menu_handle(name)
|
||||
right_click_menu(name)
|
||||
.menu(move |cx| {
|
||||
const POSITIONS: [DockPosition; 3] = [
|
||||
DockPosition::Left,
|
||||
@@ -726,14 +726,14 @@ impl Render for PanelButtons {
|
||||
})
|
||||
.anchor(menu_anchor)
|
||||
.attach(menu_attach)
|
||||
.child(move |_is_open| {
|
||||
.trigger(
|
||||
IconButton::new(name, icon)
|
||||
.selected(is_active_button)
|
||||
.action(action.boxed_clone())
|
||||
.tooltip(move |cx| {
|
||||
Tooltip::for_action(tooltip.clone(), &*action, cx)
|
||||
})
|
||||
}),
|
||||
}),
|
||||
),
|
||||
)
|
||||
});
|
||||
|
||||
|
||||
+300
-290
@@ -7,7 +7,7 @@ use crate::{
|
||||
ViewId, Workspace, WorkspaceId,
|
||||
};
|
||||
use anyhow::Result;
|
||||
use client2::{
|
||||
use client::{
|
||||
proto::{self, PeerId},
|
||||
Client,
|
||||
};
|
||||
@@ -16,10 +16,10 @@ use gpui::{
|
||||
HighlightStyle, Model, Pixels, Point, SharedString, Task, View, ViewContext, WeakView,
|
||||
WindowContext,
|
||||
};
|
||||
use project2::{Project, ProjectEntryId, ProjectPath};
|
||||
use project::{Project, ProjectEntryId, ProjectPath};
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use settings2::Settings;
|
||||
use settings::Settings;
|
||||
use smallvec::SmallVec;
|
||||
use std::{
|
||||
any::{Any, TypeId},
|
||||
@@ -33,7 +33,7 @@ use std::{
|
||||
},
|
||||
time::Duration,
|
||||
};
|
||||
use theme2::Theme;
|
||||
use theme::Theme;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct ItemSettings {
|
||||
@@ -110,7 +110,7 @@ pub trait Item: FocusableView + EventEmitter<ItemEvent> {
|
||||
fn for_each_project_item(
|
||||
&self,
|
||||
_: &AppContext,
|
||||
_: &mut dyn FnMut(EntityId, &dyn project2::Item),
|
||||
_: &mut dyn FnMut(EntityId, &dyn project::Item),
|
||||
) {
|
||||
}
|
||||
fn is_singleton(&self, _cx: &AppContext) -> bool {
|
||||
@@ -222,7 +222,7 @@ pub trait ItemHandle: 'static + Send {
|
||||
fn for_each_project_item(
|
||||
&self,
|
||||
_: &AppContext,
|
||||
_: &mut dyn FnMut(EntityId, &dyn project2::Item),
|
||||
_: &mut dyn FnMut(EntityId, &dyn project::Item),
|
||||
);
|
||||
fn is_singleton(&self, cx: &AppContext) -> bool;
|
||||
fn boxed_clone(&self) -> Box<dyn ItemHandle>;
|
||||
@@ -347,7 +347,7 @@ impl<T: Item> ItemHandle for View<T> {
|
||||
fn for_each_project_item(
|
||||
&self,
|
||||
cx: &AppContext,
|
||||
f: &mut dyn FnMut(EntityId, &dyn project2::Item),
|
||||
f: &mut dyn FnMut(EntityId, &dyn project::Item),
|
||||
) {
|
||||
self.read(cx).for_each_project_item(cx, f)
|
||||
}
|
||||
@@ -375,6 +375,7 @@ impl<T: Item> ItemHandle for View<T> {
|
||||
pane: View<Pane>,
|
||||
cx: &mut ViewContext<Workspace>,
|
||||
) {
|
||||
let weak_item = self.downgrade();
|
||||
let history = pane.read(cx).nav_history_for_item(self);
|
||||
self.update(cx, |this, cx| {
|
||||
this.set_nav_history(history, cx);
|
||||
@@ -491,16 +492,15 @@ impl<T: Item> ItemHandle for View<T> {
|
||||
}
|
||||
}));
|
||||
|
||||
// todo!()
|
||||
// cx.observe_focus(self, move |workspace, item, focused, cx| {
|
||||
// if !focused
|
||||
// && WorkspaceSettings::get_global(cx).autosave == AutosaveSetting::OnFocusChange
|
||||
// {
|
||||
// Pane::autosave_item(&item, workspace.project.clone(), cx)
|
||||
// .detach_and_log_err(cx);
|
||||
// }
|
||||
// })
|
||||
// .detach();
|
||||
cx.on_blur(&self.focus_handle(cx), move |workspace, cx| {
|
||||
if WorkspaceSettings::get_global(cx).autosave == AutosaveSetting::OnFocusChange {
|
||||
if let Some(item) = weak_item.upgrade() {
|
||||
Pane::autosave_item(&item, workspace.project.clone(), cx)
|
||||
.detach_and_log_err(cx);
|
||||
}
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
|
||||
let item_id = self.item_id();
|
||||
cx.observe_release(self, move |workspace, _, _| {
|
||||
@@ -640,7 +640,7 @@ impl<T: Item> WeakItemHandle for WeakView<T> {
|
||||
}
|
||||
|
||||
pub trait ProjectItem: Item {
|
||||
type Item: project2::Item;
|
||||
type Item: project::Item;
|
||||
|
||||
fn for_project_item(
|
||||
project: Model<Project>,
|
||||
@@ -662,19 +662,19 @@ pub trait FollowableEvents {
|
||||
pub trait FollowableItem: Item {
|
||||
type FollowableEvent: FollowableEvents;
|
||||
fn remote_id(&self) -> Option<ViewId>;
|
||||
fn to_state_proto(&self, cx: &AppContext) -> Option<proto::view::Variant>;
|
||||
fn to_state_proto(&self, cx: &WindowContext) -> Option<proto::view::Variant>;
|
||||
fn from_state_proto(
|
||||
pane: View<Pane>,
|
||||
project: View<Workspace>,
|
||||
id: ViewId,
|
||||
state: &mut Option<proto::view::Variant>,
|
||||
cx: &mut AppContext,
|
||||
cx: &mut WindowContext,
|
||||
) -> Option<Task<Result<View<Self>>>>;
|
||||
fn add_event_to_update_proto(
|
||||
&self,
|
||||
event: &Self::FollowableEvent,
|
||||
update: &mut Option<proto::update_view::Variant>,
|
||||
cx: &AppContext,
|
||||
cx: &WindowContext,
|
||||
) -> bool;
|
||||
fn apply_update_proto(
|
||||
&mut self,
|
||||
@@ -682,20 +682,20 @@ pub trait FollowableItem: Item {
|
||||
message: proto::update_view::Variant,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Task<Result<()>>;
|
||||
fn is_project_item(&self, cx: &AppContext) -> bool;
|
||||
fn is_project_item(&self, cx: &WindowContext) -> bool;
|
||||
|
||||
fn set_leader_peer_id(&mut self, leader_peer_id: Option<PeerId>, cx: &mut ViewContext<Self>);
|
||||
}
|
||||
|
||||
pub trait FollowableItemHandle: ItemHandle {
|
||||
fn remote_id(&self, client: &Arc<Client>, cx: &AppContext) -> Option<ViewId>;
|
||||
fn remote_id(&self, client: &Arc<Client>, cx: &WindowContext) -> Option<ViewId>;
|
||||
fn set_leader_peer_id(&self, leader_peer_id: Option<PeerId>, cx: &mut WindowContext);
|
||||
fn to_state_proto(&self, cx: &AppContext) -> Option<proto::view::Variant>;
|
||||
fn to_state_proto(&self, cx: &WindowContext) -> Option<proto::view::Variant>;
|
||||
fn add_event_to_update_proto(
|
||||
&self,
|
||||
event: &dyn Any,
|
||||
update: &mut Option<proto::update_view::Variant>,
|
||||
cx: &AppContext,
|
||||
cx: &WindowContext,
|
||||
) -> bool;
|
||||
fn to_follow_event(&self, event: &dyn Any) -> Option<FollowEvent>;
|
||||
fn apply_update_proto(
|
||||
@@ -704,11 +704,11 @@ pub trait FollowableItemHandle: ItemHandle {
|
||||
message: proto::update_view::Variant,
|
||||
cx: &mut WindowContext,
|
||||
) -> Task<Result<()>>;
|
||||
fn is_project_item(&self, cx: &AppContext) -> bool;
|
||||
fn is_project_item(&self, cx: &WindowContext) -> bool;
|
||||
}
|
||||
|
||||
impl<T: FollowableItem> FollowableItemHandle for View<T> {
|
||||
fn remote_id(&self, client: &Arc<Client>, cx: &AppContext) -> Option<ViewId> {
|
||||
fn remote_id(&self, client: &Arc<Client>, cx: &WindowContext) -> Option<ViewId> {
|
||||
self.read(cx).remote_id().or_else(|| {
|
||||
client.peer_id().map(|creator| ViewId {
|
||||
creator,
|
||||
@@ -721,7 +721,7 @@ impl<T: FollowableItem> FollowableItemHandle for View<T> {
|
||||
self.update(cx, |this, cx| this.set_leader_peer_id(leader_peer_id, cx))
|
||||
}
|
||||
|
||||
fn to_state_proto(&self, cx: &AppContext) -> Option<proto::view::Variant> {
|
||||
fn to_state_proto(&self, cx: &WindowContext) -> Option<proto::view::Variant> {
|
||||
self.read(cx).to_state_proto(cx)
|
||||
}
|
||||
|
||||
@@ -729,7 +729,7 @@ impl<T: FollowableItem> FollowableItemHandle for View<T> {
|
||||
&self,
|
||||
event: &dyn Any,
|
||||
update: &mut Option<proto::update_view::Variant>,
|
||||
cx: &AppContext,
|
||||
cx: &WindowContext,
|
||||
) -> bool {
|
||||
if let Some(event) = event.downcast_ref() {
|
||||
self.read(cx).add_event_to_update_proto(event, update, cx)
|
||||
@@ -754,305 +754,315 @@ impl<T: FollowableItem> FollowableItemHandle for View<T> {
|
||||
self.update(cx, |this, cx| this.apply_update_proto(project, message, cx))
|
||||
}
|
||||
|
||||
fn is_project_item(&self, cx: &AppContext) -> bool {
|
||||
fn is_project_item(&self, cx: &WindowContext) -> bool {
|
||||
self.read(cx).is_project_item(cx)
|
||||
}
|
||||
}
|
||||
|
||||
// #[cfg(any(test, feature = "test-support"))]
|
||||
// pub mod test {
|
||||
// use super::{Item, ItemEvent};
|
||||
// use crate::{ItemId, ItemNavHistory, Pane, Workspace, WorkspaceId};
|
||||
// use gpui::{
|
||||
// elements::Empty, AnyElement, AppContext, Element, Entity, Model, Task, View,
|
||||
// ViewContext, View, WeakViewHandle,
|
||||
// };
|
||||
// use project2::{Project, ProjectEntryId, ProjectPath, WorktreeId};
|
||||
// use smallvec::SmallVec;
|
||||
// use std::{any::Any, borrow::Cow, cell::Cell, path::Path};
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
pub mod test {
|
||||
use super::{Item, ItemEvent};
|
||||
use crate::{ItemId, ItemNavHistory, Pane, Workspace, WorkspaceId};
|
||||
use gpui::{
|
||||
AnyElement, AppContext, Context as _, Div, EntityId, EventEmitter, FocusableView,
|
||||
IntoElement, Model, Render, SharedString, Task, View, ViewContext, VisualContext, WeakView,
|
||||
};
|
||||
use project::{Project, ProjectEntryId, ProjectPath, WorktreeId};
|
||||
use std::{any::Any, cell::Cell, path::Path};
|
||||
|
||||
// pub struct TestProjectItem {
|
||||
// pub entry_id: Option<ProjectEntryId>,
|
||||
// pub project_path: Option<ProjectPath>,
|
||||
// }
|
||||
pub struct TestProjectItem {
|
||||
pub entry_id: Option<ProjectEntryId>,
|
||||
pub project_path: Option<ProjectPath>,
|
||||
}
|
||||
|
||||
// pub struct TestItem {
|
||||
// pub workspace_id: WorkspaceId,
|
||||
// pub state: String,
|
||||
// pub label: String,
|
||||
// pub save_count: usize,
|
||||
// pub save_as_count: usize,
|
||||
// pub reload_count: usize,
|
||||
// pub is_dirty: bool,
|
||||
// pub is_singleton: bool,
|
||||
// pub has_conflict: bool,
|
||||
// pub project_items: Vec<Model<TestProjectItem>>,
|
||||
// pub nav_history: Option<ItemNavHistory>,
|
||||
// pub tab_descriptions: Option<Vec<&'static str>>,
|
||||
// pub tab_detail: Cell<Option<usize>>,
|
||||
// }
|
||||
pub struct TestItem {
|
||||
pub workspace_id: WorkspaceId,
|
||||
pub state: String,
|
||||
pub label: String,
|
||||
pub save_count: usize,
|
||||
pub save_as_count: usize,
|
||||
pub reload_count: usize,
|
||||
pub is_dirty: bool,
|
||||
pub is_singleton: bool,
|
||||
pub has_conflict: bool,
|
||||
pub project_items: Vec<Model<TestProjectItem>>,
|
||||
pub nav_history: Option<ItemNavHistory>,
|
||||
pub tab_descriptions: Option<Vec<&'static str>>,
|
||||
pub tab_detail: Cell<Option<usize>>,
|
||||
focus_handle: gpui::FocusHandle,
|
||||
}
|
||||
|
||||
// impl Entity for TestProjectItem {
|
||||
// type Event = ();
|
||||
// }
|
||||
impl project::Item for TestProjectItem {
|
||||
fn entry_id(&self, _: &AppContext) -> Option<ProjectEntryId> {
|
||||
self.entry_id
|
||||
}
|
||||
|
||||
// impl project2::Item for TestProjectItem {
|
||||
// fn entry_id(&self, _: &AppContext) -> Option<ProjectEntryId> {
|
||||
// self.entry_id
|
||||
// }
|
||||
fn project_path(&self, _: &AppContext) -> Option<ProjectPath> {
|
||||
self.project_path.clone()
|
||||
}
|
||||
}
|
||||
|
||||
// fn project_path(&self, _: &AppContext) -> Option<ProjectPath> {
|
||||
// self.project_path.clone()
|
||||
// }
|
||||
// }
|
||||
pub enum TestItemEvent {
|
||||
Edit,
|
||||
}
|
||||
|
||||
// pub enum TestItemEvent {
|
||||
// Edit,
|
||||
// }
|
||||
// impl Clone for TestItem {
|
||||
// fn clone(&self) -> Self {
|
||||
// Self {
|
||||
// state: self.state.clone(),
|
||||
// label: self.label.clone(),
|
||||
// save_count: self.save_count,
|
||||
// save_as_count: self.save_as_count,
|
||||
// reload_count: self.reload_count,
|
||||
// is_dirty: self.is_dirty,
|
||||
// is_singleton: self.is_singleton,
|
||||
// has_conflict: self.has_conflict,
|
||||
// project_items: self.project_items.clone(),
|
||||
// nav_history: None,
|
||||
// tab_descriptions: None,
|
||||
// tab_detail: Default::default(),
|
||||
// workspace_id: self.workspace_id,
|
||||
// focus_handle: self.focus_handle.clone(),
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// impl Clone for TestItem {
|
||||
// fn clone(&self) -> Self {
|
||||
// Self {
|
||||
// state: self.state.clone(),
|
||||
// label: self.label.clone(),
|
||||
// save_count: self.save_count,
|
||||
// save_as_count: self.save_as_count,
|
||||
// reload_count: self.reload_count,
|
||||
// is_dirty: self.is_dirty,
|
||||
// is_singleton: self.is_singleton,
|
||||
// has_conflict: self.has_conflict,
|
||||
// project_items: self.project_items.clone(),
|
||||
// nav_history: None,
|
||||
// tab_descriptions: None,
|
||||
// tab_detail: Default::default(),
|
||||
// workspace_id: self.workspace_id,
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
impl TestProjectItem {
|
||||
pub fn new(id: u64, path: &str, cx: &mut AppContext) -> Model<Self> {
|
||||
let entry_id = Some(ProjectEntryId::from_proto(id));
|
||||
let project_path = Some(ProjectPath {
|
||||
worktree_id: WorktreeId::from_usize(0),
|
||||
path: Path::new(path).into(),
|
||||
});
|
||||
cx.build_model(|_| Self {
|
||||
entry_id,
|
||||
project_path,
|
||||
})
|
||||
}
|
||||
|
||||
// impl TestProjectItem {
|
||||
// pub fn new(id: u64, path: &str, cx: &mut AppContext) -> Model<Self> {
|
||||
// let entry_id = Some(ProjectEntryId::from_proto(id));
|
||||
// let project_path = Some(ProjectPath {
|
||||
// worktree_id: WorktreeId::from_usize(0),
|
||||
// path: Path::new(path).into(),
|
||||
// });
|
||||
// cx.add_model(|_| Self {
|
||||
// entry_id,
|
||||
// project_path,
|
||||
// })
|
||||
// }
|
||||
pub fn new_untitled(cx: &mut AppContext) -> Model<Self> {
|
||||
cx.build_model(|_| Self {
|
||||
project_path: None,
|
||||
entry_id: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// pub fn new_untitled(cx: &mut AppContext) -> Model<Self> {
|
||||
// cx.add_model(|_| Self {
|
||||
// project_path: None,
|
||||
// entry_id: None,
|
||||
// })
|
||||
// }
|
||||
// }
|
||||
impl TestItem {
|
||||
pub fn new(cx: &mut ViewContext<Self>) -> Self {
|
||||
Self {
|
||||
state: String::new(),
|
||||
label: String::new(),
|
||||
save_count: 0,
|
||||
save_as_count: 0,
|
||||
reload_count: 0,
|
||||
is_dirty: false,
|
||||
has_conflict: false,
|
||||
project_items: Vec::new(),
|
||||
is_singleton: true,
|
||||
nav_history: None,
|
||||
tab_descriptions: None,
|
||||
tab_detail: Default::default(),
|
||||
workspace_id: 0,
|
||||
focus_handle: cx.focus_handle(),
|
||||
}
|
||||
}
|
||||
|
||||
// impl TestItem {
|
||||
// pub fn new() -> Self {
|
||||
// Self {
|
||||
// state: String::new(),
|
||||
// label: String::new(),
|
||||
// save_count: 0,
|
||||
// save_as_count: 0,
|
||||
// reload_count: 0,
|
||||
// is_dirty: false,
|
||||
// has_conflict: false,
|
||||
// project_items: Vec::new(),
|
||||
// is_singleton: true,
|
||||
// nav_history: None,
|
||||
// tab_descriptions: None,
|
||||
// tab_detail: Default::default(),
|
||||
// workspace_id: 0,
|
||||
// }
|
||||
// }
|
||||
pub fn new_deserialized(id: WorkspaceId, cx: &mut ViewContext<Self>) -> Self {
|
||||
let mut this = Self::new(cx);
|
||||
this.workspace_id = id;
|
||||
this
|
||||
}
|
||||
|
||||
// pub fn new_deserialized(id: WorkspaceId) -> Self {
|
||||
// let mut this = Self::new();
|
||||
// this.workspace_id = id;
|
||||
// this
|
||||
// }
|
||||
pub fn with_label(mut self, state: &str) -> Self {
|
||||
self.label = state.to_string();
|
||||
self
|
||||
}
|
||||
|
||||
// pub fn with_label(mut self, state: &str) -> Self {
|
||||
// self.label = state.to_string();
|
||||
// self
|
||||
// }
|
||||
pub fn with_singleton(mut self, singleton: bool) -> Self {
|
||||
self.is_singleton = singleton;
|
||||
self
|
||||
}
|
||||
|
||||
// pub fn with_singleton(mut self, singleton: bool) -> Self {
|
||||
// self.is_singleton = singleton;
|
||||
// self
|
||||
// }
|
||||
pub fn with_dirty(mut self, dirty: bool) -> Self {
|
||||
self.is_dirty = dirty;
|
||||
self
|
||||
}
|
||||
|
||||
// pub fn with_dirty(mut self, dirty: bool) -> Self {
|
||||
// self.is_dirty = dirty;
|
||||
// self
|
||||
// }
|
||||
pub fn with_conflict(mut self, has_conflict: bool) -> Self {
|
||||
self.has_conflict = has_conflict;
|
||||
self
|
||||
}
|
||||
|
||||
// pub fn with_conflict(mut self, has_conflict: bool) -> Self {
|
||||
// self.has_conflict = has_conflict;
|
||||
// self
|
||||
// }
|
||||
pub fn with_project_items(mut self, items: &[Model<TestProjectItem>]) -> Self {
|
||||
self.project_items.clear();
|
||||
self.project_items.extend(items.iter().cloned());
|
||||
self
|
||||
}
|
||||
|
||||
// pub fn with_project_items(mut self, items: &[Model<TestProjectItem>]) -> Self {
|
||||
// self.project_items.clear();
|
||||
// self.project_items.extend(items.iter().cloned());
|
||||
// self
|
||||
// }
|
||||
pub fn set_state(&mut self, state: String, cx: &mut ViewContext<Self>) {
|
||||
self.push_to_nav_history(cx);
|
||||
self.state = state;
|
||||
}
|
||||
|
||||
// pub fn set_state(&mut self, state: String, cx: &mut ViewContext<Self>) {
|
||||
// self.push_to_nav_history(cx);
|
||||
// self.state = state;
|
||||
// }
|
||||
fn push_to_nav_history(&mut self, cx: &mut ViewContext<Self>) {
|
||||
if let Some(history) = &mut self.nav_history {
|
||||
history.push(Some(Box::new(self.state.clone())), cx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// fn push_to_nav_history(&mut self, cx: &mut ViewContext<Self>) {
|
||||
// if let Some(history) = &mut self.nav_history {
|
||||
// history.push(Some(Box::new(self.state.clone())), cx);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
impl Render for TestItem {
|
||||
type Element = Div;
|
||||
|
||||
// impl Entity for TestItem {
|
||||
// type Event = TestItemEvent;
|
||||
// }
|
||||
fn render(&mut self, _: &mut ViewContext<Self>) -> Self::Element {
|
||||
gpui::div()
|
||||
}
|
||||
}
|
||||
|
||||
// impl View for TestItem {
|
||||
// fn ui_name() -> &'static str {
|
||||
// "TestItem"
|
||||
// }
|
||||
impl EventEmitter<ItemEvent> for TestItem {}
|
||||
|
||||
// fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
|
||||
// Empty::new().into_any()
|
||||
// }
|
||||
// }
|
||||
impl FocusableView for TestItem {
|
||||
fn focus_handle(&self, cx: &AppContext) -> gpui::FocusHandle {
|
||||
self.focus_handle.clone()
|
||||
}
|
||||
}
|
||||
|
||||
// impl Item for TestItem {
|
||||
// fn tab_description(&self, detail: usize, _: &AppContext) -> Option<Cow<str>> {
|
||||
// self.tab_descriptions.as_ref().and_then(|descriptions| {
|
||||
// let description = *descriptions.get(detail).or_else(|| descriptions.last())?;
|
||||
// Some(description.into())
|
||||
// })
|
||||
// }
|
||||
impl Item for TestItem {
|
||||
fn tab_description(&self, detail: usize, _: &AppContext) -> Option<SharedString> {
|
||||
self.tab_descriptions.as_ref().and_then(|descriptions| {
|
||||
let description = *descriptions.get(detail).or_else(|| descriptions.last())?;
|
||||
Some(description.into())
|
||||
})
|
||||
}
|
||||
|
||||
// fn tab_content<V: 'static>(
|
||||
// &self,
|
||||
// detail: Option<usize>,
|
||||
// _: &theme2::Tab,
|
||||
// _: &AppContext,
|
||||
// ) -> AnyElement<V> {
|
||||
// self.tab_detail.set(detail);
|
||||
// Empty::new().into_any()
|
||||
// }
|
||||
fn tab_content(
|
||||
&self,
|
||||
detail: Option<usize>,
|
||||
cx: &ui::prelude::WindowContext,
|
||||
) -> AnyElement {
|
||||
self.tab_detail.set(detail);
|
||||
gpui::div().into_any_element()
|
||||
}
|
||||
|
||||
// fn for_each_project_item(
|
||||
// &self,
|
||||
// cx: &AppContext,
|
||||
// f: &mut dyn FnMut(usize, &dyn project2::Item),
|
||||
// ) {
|
||||
// self.project_items
|
||||
// .iter()
|
||||
// .for_each(|item| f(item.id(), item.read(cx)))
|
||||
// }
|
||||
fn for_each_project_item(
|
||||
&self,
|
||||
cx: &AppContext,
|
||||
f: &mut dyn FnMut(EntityId, &dyn project::Item),
|
||||
) {
|
||||
self.project_items
|
||||
.iter()
|
||||
.for_each(|item| f(item.entity_id(), item.read(cx)))
|
||||
}
|
||||
|
||||
// fn is_singleton(&self, _: &AppContext) -> bool {
|
||||
// self.is_singleton
|
||||
// }
|
||||
fn is_singleton(&self, _: &AppContext) -> bool {
|
||||
self.is_singleton
|
||||
}
|
||||
|
||||
// fn set_nav_history(&mut self, history: ItemNavHistory, _: &mut ViewContext<Self>) {
|
||||
// self.nav_history = Some(history);
|
||||
// }
|
||||
fn set_nav_history(&mut self, history: ItemNavHistory, _: &mut ViewContext<Self>) {
|
||||
self.nav_history = Some(history);
|
||||
}
|
||||
|
||||
// fn navigate(&mut self, state: Box<dyn Any>, _: &mut ViewContext<Self>) -> bool {
|
||||
// let state = *state.downcast::<String>().unwrap_or_default();
|
||||
// if state != self.state {
|
||||
// self.state = state;
|
||||
// true
|
||||
// } else {
|
||||
// false
|
||||
// }
|
||||
// }
|
||||
fn navigate(&mut self, state: Box<dyn Any>, _: &mut ViewContext<Self>) -> bool {
|
||||
let state = *state.downcast::<String>().unwrap_or_default();
|
||||
if state != self.state {
|
||||
self.state = state;
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
// fn deactivated(&mut self, cx: &mut ViewContext<Self>) {
|
||||
// self.push_to_nav_history(cx);
|
||||
// }
|
||||
fn deactivated(&mut self, cx: &mut ViewContext<Self>) {
|
||||
self.push_to_nav_history(cx);
|
||||
}
|
||||
|
||||
// fn clone_on_split(
|
||||
// &self,
|
||||
// _workspace_id: WorkspaceId,
|
||||
// _: &mut ViewContext<Self>,
|
||||
// ) -> Option<Self>
|
||||
// where
|
||||
// Self: Sized,
|
||||
// {
|
||||
// Some(self.clone())
|
||||
// }
|
||||
fn clone_on_split(
|
||||
&self,
|
||||
_workspace_id: WorkspaceId,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Option<View<Self>>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
Some(cx.build_view(|cx| Self {
|
||||
state: self.state.clone(),
|
||||
label: self.label.clone(),
|
||||
save_count: self.save_count,
|
||||
save_as_count: self.save_as_count,
|
||||
reload_count: self.reload_count,
|
||||
is_dirty: self.is_dirty,
|
||||
is_singleton: self.is_singleton,
|
||||
has_conflict: self.has_conflict,
|
||||
project_items: self.project_items.clone(),
|
||||
nav_history: None,
|
||||
tab_descriptions: None,
|
||||
tab_detail: Default::default(),
|
||||
workspace_id: self.workspace_id,
|
||||
focus_handle: cx.focus_handle(),
|
||||
}))
|
||||
}
|
||||
|
||||
// fn is_dirty(&self, _: &AppContext) -> bool {
|
||||
// self.is_dirty
|
||||
// }
|
||||
fn is_dirty(&self, _: &AppContext) -> bool {
|
||||
self.is_dirty
|
||||
}
|
||||
|
||||
// fn has_conflict(&self, _: &AppContext) -> bool {
|
||||
// self.has_conflict
|
||||
// }
|
||||
fn has_conflict(&self, _: &AppContext) -> bool {
|
||||
self.has_conflict
|
||||
}
|
||||
|
||||
// fn can_save(&self, cx: &AppContext) -> bool {
|
||||
// !self.project_items.is_empty()
|
||||
// && self
|
||||
// .project_items
|
||||
// .iter()
|
||||
// .all(|item| item.read(cx).entry_id.is_some())
|
||||
// }
|
||||
fn can_save(&self, cx: &AppContext) -> bool {
|
||||
!self.project_items.is_empty()
|
||||
&& self
|
||||
.project_items
|
||||
.iter()
|
||||
.all(|item| item.read(cx).entry_id.is_some())
|
||||
}
|
||||
|
||||
// fn save(
|
||||
// &mut self,
|
||||
// _: Model<Project>,
|
||||
// _: &mut ViewContext<Self>,
|
||||
// ) -> Task<anyhow::Result<()>> {
|
||||
// self.save_count += 1;
|
||||
// self.is_dirty = false;
|
||||
// Task::ready(Ok(()))
|
||||
// }
|
||||
fn save(
|
||||
&mut self,
|
||||
_: Model<Project>,
|
||||
_: &mut ViewContext<Self>,
|
||||
) -> Task<anyhow::Result<()>> {
|
||||
self.save_count += 1;
|
||||
self.is_dirty = false;
|
||||
Task::ready(Ok(()))
|
||||
}
|
||||
|
||||
// fn save_as(
|
||||
// &mut self,
|
||||
// _: Model<Project>,
|
||||
// _: std::path::PathBuf,
|
||||
// _: &mut ViewContext<Self>,
|
||||
// ) -> Task<anyhow::Result<()>> {
|
||||
// self.save_as_count += 1;
|
||||
// self.is_dirty = false;
|
||||
// Task::ready(Ok(()))
|
||||
// }
|
||||
fn save_as(
|
||||
&mut self,
|
||||
_: Model<Project>,
|
||||
_: std::path::PathBuf,
|
||||
_: &mut ViewContext<Self>,
|
||||
) -> Task<anyhow::Result<()>> {
|
||||
self.save_as_count += 1;
|
||||
self.is_dirty = false;
|
||||
Task::ready(Ok(()))
|
||||
}
|
||||
|
||||
// fn reload(
|
||||
// &mut self,
|
||||
// _: Model<Project>,
|
||||
// _: &mut ViewContext<Self>,
|
||||
// ) -> Task<anyhow::Result<()>> {
|
||||
// self.reload_count += 1;
|
||||
// self.is_dirty = false;
|
||||
// Task::ready(Ok(()))
|
||||
// }
|
||||
fn reload(
|
||||
&mut self,
|
||||
_: Model<Project>,
|
||||
_: &mut ViewContext<Self>,
|
||||
) -> Task<anyhow::Result<()>> {
|
||||
self.reload_count += 1;
|
||||
self.is_dirty = false;
|
||||
Task::ready(Ok(()))
|
||||
}
|
||||
|
||||
// fn to_item_events(_: &Self::Event) -> SmallVec<[ItemEvent; 2]> {
|
||||
// [ItemEvent::UpdateTab, ItemEvent::Edit].into()
|
||||
// }
|
||||
fn serialized_item_kind() -> Option<&'static str> {
|
||||
Some("TestItem")
|
||||
}
|
||||
|
||||
// fn serialized_item_kind() -> Option<&'static str> {
|
||||
// Some("TestItem")
|
||||
// }
|
||||
|
||||
// fn deserialize(
|
||||
// _project: Model<Project>,
|
||||
// _workspace: WeakViewHandle<Workspace>,
|
||||
// workspace_id: WorkspaceId,
|
||||
// _item_id: ItemId,
|
||||
// cx: &mut ViewContext<Pane>,
|
||||
// ) -> Task<anyhow::Result<View<Self>>> {
|
||||
// let view = cx.add_view(|_cx| Self::new_deserialized(workspace_id));
|
||||
// Task::Ready(Some(anyhow::Ok(view)))
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
fn deserialize(
|
||||
_project: Model<Project>,
|
||||
_workspace: WeakView<Workspace>,
|
||||
workspace_id: WorkspaceId,
|
||||
_item_id: ItemId,
|
||||
cx: &mut ViewContext<Pane>,
|
||||
) -> Task<anyhow::Result<View<Self>>> {
|
||||
let view = cx.build_view(|cx| Self::new_deserialized(workspace_id, cx));
|
||||
Task::Ready(Some(anyhow::Ok(view)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,24 +135,22 @@ impl Workspace {
|
||||
}
|
||||
|
||||
pub fn show_toast(&mut self, toast: Toast, cx: &mut ViewContext<Self>) {
|
||||
todo!()
|
||||
// self.dismiss_notification::<simple_message_notification::MessageNotification>(toast.id, cx);
|
||||
// self.show_notification(toast.id, cx, |cx| {
|
||||
// cx.add_view(|_cx| match toast.on_click.as_ref() {
|
||||
// Some((click_msg, on_click)) => {
|
||||
// let on_click = on_click.clone();
|
||||
// simple_message_notification::MessageNotification::new(toast.msg.clone())
|
||||
// .with_click_message(click_msg.clone())
|
||||
// .on_click(move |cx| on_click(cx))
|
||||
// }
|
||||
// None => simple_message_notification::MessageNotification::new(toast.msg.clone()),
|
||||
// })
|
||||
// })
|
||||
self.dismiss_notification::<simple_message_notification::MessageNotification>(toast.id, cx);
|
||||
self.show_notification(toast.id, cx, |cx| {
|
||||
cx.build_view(|_cx| match toast.on_click.as_ref() {
|
||||
Some((click_msg, on_click)) => {
|
||||
let on_click = on_click.clone();
|
||||
simple_message_notification::MessageNotification::new(toast.msg.clone())
|
||||
.with_click_message(click_msg.clone())
|
||||
.on_click(move |cx| on_click(cx))
|
||||
}
|
||||
None => simple_message_notification::MessageNotification::new(toast.msg.clone()),
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
pub fn dismiss_toast(&mut self, id: usize, cx: &mut ViewContext<Self>) {
|
||||
todo!()
|
||||
// self.dismiss_notification::<simple_message_notification::MessageNotification>(id, cx);
|
||||
self.dismiss_notification::<simple_message_notification::MessageNotification>(id, cx);
|
||||
}
|
||||
|
||||
fn dismiss_notification_internal(
|
||||
@@ -179,33 +177,10 @@ pub mod simple_message_notification {
|
||||
ParentElement, Render, SharedString, StatefulInteractiveElement, Styled, TextStyle,
|
||||
ViewContext,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use std::{borrow::Cow, sync::Arc};
|
||||
use std::sync::Arc;
|
||||
use ui::prelude::*;
|
||||
use ui::{h_stack, v_stack, Button, Icon, IconElement, Label, StyledExt};
|
||||
|
||||
#[derive(Clone, Default, Deserialize, PartialEq)]
|
||||
pub struct OsOpen(pub Cow<'static, str>);
|
||||
|
||||
impl OsOpen {
|
||||
pub fn new<I: Into<Cow<'static, str>>>(url: I) -> Self {
|
||||
OsOpen(url.into())
|
||||
}
|
||||
}
|
||||
|
||||
// todo!()
|
||||
// impl_actions!(message_notifications, [OsOpen]);
|
||||
//
|
||||
// todo!()
|
||||
// pub fn init(cx: &mut AppContext) {
|
||||
// cx.add_action(MessageNotification::dismiss);
|
||||
// cx.add_action(
|
||||
// |_workspace: &mut Workspace, open_action: &OsOpen, cx: &mut ViewContext<Workspace>| {
|
||||
// cx.platform().open_url(open_action.0.as_ref());
|
||||
// },
|
||||
// )
|
||||
// }
|
||||
|
||||
enum NotificationMessage {
|
||||
Text(SharedString),
|
||||
Element(fn(TextStyle, &AppContext) -> AnyElement),
|
||||
@@ -213,7 +188,7 @@ pub mod simple_message_notification {
|
||||
|
||||
pub struct MessageNotification {
|
||||
message: NotificationMessage,
|
||||
on_click: Option<Arc<dyn Fn(&mut ViewContext<Self>) + Send + Sync>>,
|
||||
on_click: Option<Arc<dyn Fn(&mut ViewContext<Self>)>>,
|
||||
click_message: Option<SharedString>,
|
||||
}
|
||||
|
||||
@@ -252,7 +227,7 @@ pub mod simple_message_notification {
|
||||
|
||||
pub fn on_click<F>(mut self, on_click: F) -> Self
|
||||
where
|
||||
F: 'static + Send + Sync + Fn(&mut ViewContext<Self>),
|
||||
F: 'static + Fn(&mut ViewContext<Self>),
|
||||
{
|
||||
self.on_click = Some(Arc::new(on_click));
|
||||
self
|
||||
|
||||
+285
-89
@@ -2,19 +2,20 @@ use crate::{
|
||||
item::{Item, ItemHandle, ItemSettings, WeakItemHandle},
|
||||
toolbar::Toolbar,
|
||||
workspace_settings::{AutosaveSetting, WorkspaceSettings},
|
||||
SplitDirection, Workspace,
|
||||
NewCenterTerminal, NewFile, NewSearch, SplitDirection, ToggleZoom, Workspace,
|
||||
};
|
||||
use anyhow::Result;
|
||||
use collections::{HashMap, HashSet, VecDeque};
|
||||
use gpui::{
|
||||
actions, prelude::*, Action, AppContext, AsyncWindowContext, Div, EntityId, EventEmitter,
|
||||
FocusHandle, Focusable, FocusableView, Model, Pixels, Point, PromptLevel, Render, Task, View,
|
||||
ViewContext, VisualContext, WeakView, WindowContext,
|
||||
actions, overlay, prelude::*, rems, Action, AnchorCorner, AnyWeakView, AppContext,
|
||||
AsyncWindowContext, DismissEvent, Div, EntityId, EventEmitter, FocusHandle, Focusable,
|
||||
FocusableView, Model, Pixels, Point, PromptLevel, Render, Task, View, ViewContext,
|
||||
VisualContext, WeakView, WindowContext,
|
||||
};
|
||||
use parking_lot::Mutex;
|
||||
use project2::{Project, ProjectEntryId, ProjectPath};
|
||||
use project::{Project, ProjectEntryId, ProjectPath};
|
||||
use serde::Deserialize;
|
||||
use settings2::Settings;
|
||||
use settings::Settings;
|
||||
use std::{
|
||||
any::Any,
|
||||
cmp, fmt, mem,
|
||||
@@ -25,8 +26,10 @@ use std::{
|
||||
},
|
||||
};
|
||||
|
||||
use ui::v_stack;
|
||||
use ui::{prelude::*, Color, Icon, IconButton, IconElement, Tooltip};
|
||||
use ui::{
|
||||
h_stack, prelude::*, right_click_menu, Color, Icon, IconButton, IconElement, Label, Tooltip,
|
||||
};
|
||||
use ui::{v_stack, ContextMenu};
|
||||
use util::truncate_and_remove_front;
|
||||
|
||||
#[derive(PartialEq, Clone, Copy, Deserialize, Debug)]
|
||||
@@ -50,7 +53,7 @@ pub enum SaveIntent {
|
||||
|
||||
//todo!("Do we need the default bound on actions? Decide soon")
|
||||
// #[register_action]
|
||||
#[derive(Clone, Deserialize, PartialEq, Debug)]
|
||||
#[derive(Action, Clone, Deserialize, PartialEq, Debug)]
|
||||
pub struct ActivateItem(pub usize);
|
||||
|
||||
// #[derive(Clone, PartialEq)]
|
||||
@@ -143,17 +146,24 @@ impl fmt::Debug for Event {
|
||||
}
|
||||
}
|
||||
|
||||
struct FocusedView {
|
||||
view: AnyWeakView,
|
||||
focus_handle: FocusHandle,
|
||||
}
|
||||
|
||||
pub struct Pane {
|
||||
focus_handle: FocusHandle,
|
||||
items: Vec<Box<dyn ItemHandle>>,
|
||||
activation_history: Vec<EntityId>,
|
||||
zoomed: bool,
|
||||
active_item_index: usize,
|
||||
// last_focused_view_by_item: HashMap<usize, AnyWeakViewHandle>,
|
||||
last_focused_view_by_item: HashMap<EntityId, FocusHandle>,
|
||||
autoscroll: bool,
|
||||
nav_history: NavHistory,
|
||||
toolbar: View<Toolbar>,
|
||||
// tab_bar_context_menu: TabBarContextMenu,
|
||||
tab_bar_focus_handle: FocusHandle,
|
||||
new_item_menu: Option<View<ContextMenu>>,
|
||||
split_item_menu: Option<View<ContextMenu>>,
|
||||
// tab_context_menu: ViewHandle<ContextMenu>,
|
||||
workspace: WeakView<Workspace>,
|
||||
project: Model<Project>,
|
||||
@@ -306,7 +316,7 @@ impl Pane {
|
||||
activation_history: Vec::new(),
|
||||
zoomed: false,
|
||||
active_item_index: 0,
|
||||
// last_focused_view_by_item: Default::default(),
|
||||
last_focused_view_by_item: Default::default(),
|
||||
autoscroll: false,
|
||||
nav_history: NavHistory(Arc::new(Mutex::new(NavHistoryState {
|
||||
mode: NavigationMode::Normal,
|
||||
@@ -318,6 +328,9 @@ impl Pane {
|
||||
next_timestamp,
|
||||
}))),
|
||||
toolbar: cx.build_view(|_| Toolbar::new()),
|
||||
tab_bar_focus_handle: cx.focus_handle(),
|
||||
new_item_menu: None,
|
||||
split_item_menu: None,
|
||||
// tab_bar_context_menu: TabBarContextMenu {
|
||||
// kind: TabBarContextMenuKind::New,
|
||||
// handle: context_menu,
|
||||
@@ -392,9 +405,48 @@ impl Pane {
|
||||
}
|
||||
|
||||
pub fn has_focus(&self, cx: &WindowContext) -> bool {
|
||||
// todo!(); // inline this manually
|
||||
self.focus_handle.contains_focused(cx)
|
||||
}
|
||||
|
||||
fn focus_in(&mut self, cx: &mut ViewContext<Self>) {
|
||||
if !self.has_focus(cx) {
|
||||
cx.emit(Event::Focus);
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
self.toolbar.update(cx, |toolbar, cx| {
|
||||
toolbar.focus_changed(true, cx);
|
||||
});
|
||||
|
||||
if let Some(active_item) = self.active_item() {
|
||||
if self.focus_handle.is_focused(cx) {
|
||||
// Pane was focused directly. We need to either focus a view inside the active item,
|
||||
// or focus the active item itself
|
||||
if let Some(weak_last_focused_view) =
|
||||
self.last_focused_view_by_item.get(&active_item.item_id())
|
||||
{
|
||||
weak_last_focused_view.focus(cx);
|
||||
return;
|
||||
}
|
||||
|
||||
active_item.focus_handle(cx).focus(cx);
|
||||
} else if !self.tab_bar_focus_handle.contains_focused(cx) {
|
||||
if let Some(focused) = cx.focused() {
|
||||
self.last_focused_view_by_item
|
||||
.insert(active_item.item_id(), focused);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn focus_out(&mut self, cx: &mut ViewContext<Self>) {
|
||||
self.toolbar.update(cx, |toolbar, cx| {
|
||||
toolbar.focus_changed(false, cx);
|
||||
});
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn active_item_index(&self) -> usize {
|
||||
self.active_item_index
|
||||
}
|
||||
@@ -457,24 +509,49 @@ impl Pane {
|
||||
!self.nav_history.0.lock().forward_stack.is_empty()
|
||||
}
|
||||
|
||||
fn navigate_backward(&mut self, cx: &mut ViewContext<Self>) {
|
||||
if let Some(workspace) = self.workspace.upgrade() {
|
||||
let pane = cx.view().downgrade();
|
||||
cx.window_context().defer(move |cx| {
|
||||
workspace.update(cx, |workspace, cx| {
|
||||
workspace.go_back(pane, cx).detach_and_log_err(cx)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn navigate_forward(&mut self, cx: &mut ViewContext<Self>) {
|
||||
if let Some(workspace) = self.workspace.upgrade() {
|
||||
let pane = cx.view().downgrade();
|
||||
cx.window_context().defer(move |cx| {
|
||||
workspace.update(cx, |workspace, cx| {
|
||||
workspace.go_forward(pane, cx).detach_and_log_err(cx)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn history_updated(&mut self, cx: &mut ViewContext<Self>) {
|
||||
self.toolbar.update(cx, |_, cx| cx.notify());
|
||||
}
|
||||
|
||||
pub(crate) fn open_item(
|
||||
&mut self,
|
||||
project_entry_id: ProjectEntryId,
|
||||
project_entry_id: Option<ProjectEntryId>,
|
||||
focus_item: bool,
|
||||
cx: &mut ViewContext<Self>,
|
||||
build_item: impl FnOnce(&mut ViewContext<Pane>) -> Box<dyn ItemHandle>,
|
||||
) -> Box<dyn ItemHandle> {
|
||||
let mut existing_item = None;
|
||||
for (index, item) in self.items.iter().enumerate() {
|
||||
if item.is_singleton(cx) && item.project_entry_ids(cx).as_slice() == [project_entry_id]
|
||||
{
|
||||
let item = item.boxed_clone();
|
||||
existing_item = Some((index, item));
|
||||
break;
|
||||
if let Some(project_entry_id) = project_entry_id {
|
||||
for (index, item) in self.items.iter().enumerate() {
|
||||
if item.is_singleton(cx)
|
||||
&& item.project_entry_ids(cx).as_slice() == [project_entry_id]
|
||||
{
|
||||
let item = item.boxed_clone();
|
||||
existing_item = Some((index, item));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -630,21 +707,16 @@ impl Pane {
|
||||
.position(|i| i.item_id() == item.item_id())
|
||||
}
|
||||
|
||||
// pub fn toggle_zoom(&mut self, _: &ToggleZoom, cx: &mut ViewContext<Self>) {
|
||||
// // Potentially warn the user of the new keybinding
|
||||
// let workspace_handle = self.workspace().clone();
|
||||
// cx.spawn(|_, mut cx| async move { notify_of_new_dock(&workspace_handle, &mut cx) })
|
||||
// .detach();
|
||||
|
||||
// if self.zoomed {
|
||||
// cx.emit(Event::ZoomOut);
|
||||
// } else if !self.items.is_empty() {
|
||||
// if !self.has_focus {
|
||||
// cx.focus_self();
|
||||
// }
|
||||
// cx.emit(Event::ZoomIn);
|
||||
// }
|
||||
// }
|
||||
pub fn toggle_zoom(&mut self, _: &ToggleZoom, cx: &mut ViewContext<Self>) {
|
||||
if self.zoomed {
|
||||
cx.emit(Event::ZoomOut);
|
||||
} else if !self.items.is_empty() {
|
||||
if !self.focus_handle.contains_focused(cx) {
|
||||
cx.focus_self();
|
||||
}
|
||||
cx.emit(Event::ZoomIn);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn activate_item(
|
||||
&mut self,
|
||||
@@ -1381,7 +1453,7 @@ impl Pane {
|
||||
let close_right = ItemSettings::get_global(cx).close_position.right();
|
||||
let is_active = ix == self.active_item_index;
|
||||
|
||||
div()
|
||||
let tab = div()
|
||||
.group("")
|
||||
.id(ix)
|
||||
.cursor_pointer()
|
||||
@@ -1455,43 +1527,68 @@ impl Pane {
|
||||
.children((!close_right).then(|| close_icon()))
|
||||
.child(label)
|
||||
.children(close_right.then(|| close_icon())),
|
||||
)
|
||||
);
|
||||
|
||||
right_click_menu(ix).trigger(tab).menu(|cx| {
|
||||
ContextMenu::build(cx, |menu, cx| {
|
||||
menu.action(
|
||||
"Close Active Item",
|
||||
CloseActiveItem { save_intent: None }.boxed_clone(),
|
||||
)
|
||||
.action("Close Inactive Items", CloseInactiveItems.boxed_clone())
|
||||
.action("Close Clean Items", CloseCleanItems.boxed_clone())
|
||||
.action("Close Items To The Left", CloseItemsToTheLeft.boxed_clone())
|
||||
.action(
|
||||
"Close Items To The Right",
|
||||
CloseItemsToTheRight.boxed_clone(),
|
||||
)
|
||||
.action(
|
||||
"Close All Items",
|
||||
CloseAllItems { save_intent: None }.boxed_clone(),
|
||||
)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn render_tab_bar(&mut self, cx: &mut ViewContext<'_, Pane>) -> impl IntoElement {
|
||||
div()
|
||||
.group("tab_bar")
|
||||
.id("tab_bar")
|
||||
.group("tab_bar")
|
||||
.track_focus(&self.tab_bar_focus_handle)
|
||||
.w_full()
|
||||
// 30px @ 16px/rem
|
||||
.h(rems(1.875))
|
||||
.overflow_hidden()
|
||||
.flex()
|
||||
.flex_none()
|
||||
.bg(cx.theme().colors().tab_bar_background)
|
||||
// Left Side
|
||||
.child(
|
||||
div()
|
||||
.relative()
|
||||
.px_1()
|
||||
h_stack()
|
||||
.px_2()
|
||||
.flex()
|
||||
.flex_none()
|
||||
.gap_2()
|
||||
.gap_1()
|
||||
// Nav Buttons
|
||||
.child(
|
||||
div()
|
||||
.right_0()
|
||||
.flex()
|
||||
.items_center()
|
||||
.gap_px()
|
||||
.child(
|
||||
div().border().border_color(gpui::red()).child(
|
||||
IconButton::new("navigate_backward", Icon::ArrowLeft)
|
||||
.disabled(!self.can_navigate_backward()),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
div().border().border_color(gpui::red()).child(
|
||||
IconButton::new("navigate_forward", Icon::ArrowRight)
|
||||
.disabled(!self.can_navigate_forward()),
|
||||
),
|
||||
),
|
||||
div().border().border_color(gpui::red()).child(
|
||||
IconButton::new("navigate_backward", Icon::ArrowLeft)
|
||||
.on_click({
|
||||
let view = cx.view().clone();
|
||||
move |_, cx| view.update(cx, Self::navigate_backward)
|
||||
})
|
||||
.disabled(!self.can_navigate_backward()),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
div().border().border_color(gpui::red()).child(
|
||||
IconButton::new("navigate_forward", Icon::ArrowRight)
|
||||
.on_click({
|
||||
let view = cx.view().clone();
|
||||
move |_, cx| view.update(cx, Self::navigate_backward)
|
||||
})
|
||||
.disabled(!self.can_navigate_forward()),
|
||||
),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
@@ -1520,20 +1617,78 @@ impl Pane {
|
||||
.gap_px()
|
||||
.child(
|
||||
div()
|
||||
.bg(gpui::blue())
|
||||
.border()
|
||||
.border_color(gpui::red())
|
||||
.child(IconButton::new("plus", Icon::Plus)),
|
||||
.child(IconButton::new("plus", Icon::Plus).on_click(
|
||||
cx.listener(|this, _, cx| {
|
||||
let menu = ContextMenu::build(cx, |menu, cx| {
|
||||
menu.action("New File", NewFile.boxed_clone())
|
||||
.action(
|
||||
"New Terminal",
|
||||
NewCenterTerminal.boxed_clone(),
|
||||
)
|
||||
.action("New Search", NewSearch.boxed_clone())
|
||||
});
|
||||
cx.subscribe(
|
||||
&menu,
|
||||
|this, _, event: &DismissEvent, cx| {
|
||||
this.focus(cx);
|
||||
this.new_item_menu = None;
|
||||
},
|
||||
)
|
||||
.detach();
|
||||
this.new_item_menu = Some(menu);
|
||||
}),
|
||||
))
|
||||
.when_some(self.new_item_menu.as_ref(), |el, new_item_menu| {
|
||||
el.child(Self::render_menu_overlay(new_item_menu))
|
||||
}),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.border()
|
||||
.border_color(gpui::red())
|
||||
.child(IconButton::new("split", Icon::Split)),
|
||||
.child(IconButton::new("split", Icon::Split).on_click(
|
||||
cx.listener(|this, _, cx| {
|
||||
let menu = ContextMenu::build(cx, |menu, cx| {
|
||||
menu.action("Split Right", SplitRight.boxed_clone())
|
||||
.action("Split Left", SplitLeft.boxed_clone())
|
||||
.action("Split Up", SplitUp.boxed_clone())
|
||||
.action("Split Down", SplitDown.boxed_clone())
|
||||
});
|
||||
cx.subscribe(
|
||||
&menu,
|
||||
|this, _, event: &DismissEvent, cx| {
|
||||
this.focus(cx);
|
||||
this.split_item_menu = None;
|
||||
},
|
||||
)
|
||||
.detach();
|
||||
this.split_item_menu = Some(menu);
|
||||
}),
|
||||
))
|
||||
.when_some(
|
||||
self.split_item_menu.as_ref(),
|
||||
|el, split_item_menu| {
|
||||
el.child(Self::render_menu_overlay(split_item_menu))
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
fn render_menu_overlay(menu: &View<ContextMenu>) -> Div {
|
||||
div()
|
||||
.absolute()
|
||||
.z_index(1)
|
||||
.bottom_0()
|
||||
.right_0()
|
||||
.size_0()
|
||||
.child(overlay().anchor(AnchorCorner::TopRight).child(menu.clone()))
|
||||
}
|
||||
|
||||
// fn render_tabs(&mut self, cx: &mut ViewContext<Self>) -> impl Element<Self> {
|
||||
// let theme = theme::current(cx).clone();
|
||||
|
||||
@@ -1932,40 +2087,78 @@ impl Render for Pane {
|
||||
type Element = Focusable<Div>;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
let this = cx.view().downgrade();
|
||||
|
||||
v_stack()
|
||||
.key_context("Pane")
|
||||
.track_focus(&self.focus_handle)
|
||||
.on_action(cx.listener(|pane: &mut Pane, _: &SplitLeft, cx| {
|
||||
pane.split(SplitDirection::Left, cx)
|
||||
.on_focus_in({
|
||||
let this = this.clone();
|
||||
move |event, cx| {
|
||||
this.update(cx, |this, cx| this.focus_in(cx)).ok();
|
||||
}
|
||||
})
|
||||
.on_focus_out({
|
||||
let this = this.clone();
|
||||
move |event, cx| {
|
||||
this.update(cx, |this, cx| this.focus_out(cx)).ok();
|
||||
}
|
||||
})
|
||||
.on_action(cx.listener(|pane, _: &SplitLeft, cx| pane.split(SplitDirection::Left, cx)))
|
||||
.on_action(cx.listener(|pane, _: &SplitUp, cx| pane.split(SplitDirection::Up, cx)))
|
||||
.on_action(
|
||||
cx.listener(|pane, _: &SplitRight, cx| pane.split(SplitDirection::Right, cx)),
|
||||
)
|
||||
.on_action(cx.listener(|pane, _: &SplitDown, cx| pane.split(SplitDirection::Down, cx)))
|
||||
.on_action(cx.listener(|pane, _: &GoBack, cx| pane.navigate_backward(cx)))
|
||||
.on_action(cx.listener(|pane, _: &GoForward, cx| pane.navigate_forward(cx)))
|
||||
.on_action(cx.listener(Pane::toggle_zoom))
|
||||
.on_action(cx.listener(|pane: &mut Pane, action: &ActivateItem, cx| {
|
||||
pane.activate_item(action.0, true, true, cx);
|
||||
}))
|
||||
.on_action(cx.listener(|pane: &mut Pane, _: &ActivateLastItem, cx| {
|
||||
pane.activate_item(pane.items.len() - 1, true, true, cx);
|
||||
}))
|
||||
.on_action(cx.listener(|pane: &mut Pane, _: &ActivatePrevItem, cx| {
|
||||
pane.activate_prev_item(true, cx);
|
||||
}))
|
||||
.on_action(cx.listener(|pane: &mut Pane, _: &ActivateNextItem, cx| {
|
||||
pane.activate_next_item(true, cx);
|
||||
}))
|
||||
.on_action(
|
||||
cx.listener(|pane: &mut Pane, _: &SplitUp, cx| pane.split(SplitDirection::Up, cx)),
|
||||
cx.listener(|pane: &mut Self, action: &CloseActiveItem, cx| {
|
||||
pane.close_active_item(action, cx)
|
||||
.map(|task| task.detach_and_log_err(cx));
|
||||
}),
|
||||
)
|
||||
.on_action(cx.listener(|pane: &mut Pane, _: &SplitRight, cx| {
|
||||
pane.split(SplitDirection::Right, cx)
|
||||
.on_action(
|
||||
cx.listener(|pane: &mut Self, action: &CloseInactiveItems, cx| {
|
||||
pane.close_inactive_items(action, cx)
|
||||
.map(|task| task.detach_and_log_err(cx));
|
||||
}),
|
||||
)
|
||||
.on_action(
|
||||
cx.listener(|pane: &mut Self, action: &CloseCleanItems, cx| {
|
||||
pane.close_clean_items(action, cx)
|
||||
.map(|task| task.detach_and_log_err(cx));
|
||||
}),
|
||||
)
|
||||
.on_action(
|
||||
cx.listener(|pane: &mut Self, action: &CloseItemsToTheLeft, cx| {
|
||||
pane.close_items_to_the_left(action, cx)
|
||||
.map(|task| task.detach_and_log_err(cx));
|
||||
}),
|
||||
)
|
||||
.on_action(
|
||||
cx.listener(|pane: &mut Self, action: &CloseItemsToTheRight, cx| {
|
||||
pane.close_items_to_the_right(action, cx)
|
||||
.map(|task| task.detach_and_log_err(cx));
|
||||
}),
|
||||
)
|
||||
.on_action(cx.listener(|pane: &mut Self, action: &CloseAllItems, cx| {
|
||||
pane.close_all_items(action, cx)
|
||||
.map(|task| task.detach_and_log_err(cx));
|
||||
}))
|
||||
.on_action(cx.listener(|pane: &mut Pane, _: &SplitDown, cx| {
|
||||
pane.split(SplitDirection::Down, cx)
|
||||
}))
|
||||
// cx.add_action(Pane::toggle_zoom);
|
||||
// cx.add_action(|pane: &mut Pane, action: &ActivateItem, cx| {
|
||||
// pane.activate_item(action.0, true, true, cx);
|
||||
// });
|
||||
// cx.add_action(|pane: &mut Pane, _: &ActivateLastItem, cx| {
|
||||
// pane.activate_item(pane.items.len() - 1, true, true, cx);
|
||||
// });
|
||||
// cx.add_action(|pane: &mut Pane, _: &ActivatePrevItem, cx| {
|
||||
// pane.activate_prev_item(true, cx);
|
||||
// });
|
||||
// cx.add_action(|pane: &mut Pane, _: &ActivateNextItem, cx| {
|
||||
// pane.activate_next_item(true, cx);
|
||||
// });
|
||||
// cx.add_async_action(Pane::close_active_item);
|
||||
// cx.add_async_action(Pane::close_inactive_items);
|
||||
// cx.add_async_action(Pane::close_clean_items);
|
||||
// cx.add_async_action(Pane::close_items_to_the_left);
|
||||
// cx.add_async_action(Pane::close_items_to_the_right);
|
||||
// cx.add_async_action(Pane::close_all_items);
|
||||
.size_full()
|
||||
.on_action(
|
||||
cx.listener(|pane: &mut Self, action: &CloseActiveItem, cx| {
|
||||
@@ -1978,8 +2171,11 @@ impl Render for Pane {
|
||||
.child(if let Some(item) = self.active_item() {
|
||||
div().flex().flex_1().child(item.to_any())
|
||||
} else {
|
||||
// todo!()
|
||||
div().child("Empty Pane")
|
||||
h_stack()
|
||||
.items_center()
|
||||
.size_full()
|
||||
.justify_center()
|
||||
.child(Label::new("Open a file or project to get started.").color(Color::Muted))
|
||||
})
|
||||
|
||||
// enum MouseNavigationHandler {}
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
use crate::{AppState, FollowerState, Pane, Workspace};
|
||||
use anyhow::{anyhow, bail, Result};
|
||||
use call::{ActiveCall, ParticipantLocation};
|
||||
use collections::HashMap;
|
||||
use db2::sqlez::{
|
||||
use db::sqlez::{
|
||||
bindable::{Bind, Column, StaticColumnCount},
|
||||
statement::Statement,
|
||||
};
|
||||
use gpui::{
|
||||
point, size, AnyWeakView, Bounds, Div, IntoElement, Model, Pixels, Point, View, ViewContext,
|
||||
point, size, AnyWeakView, Bounds, Div, Entity as _, IntoElement, Model, Pixels, Point, View,
|
||||
ViewContext,
|
||||
};
|
||||
use parking_lot::Mutex;
|
||||
use project2::Project;
|
||||
use project::Project;
|
||||
use serde::Deserialize;
|
||||
use std::sync::Arc;
|
||||
use ui::prelude::*;
|
||||
use ui::{prelude::*, Button};
|
||||
|
||||
const HANDLE_HITBOX_SIZE: f32 = 4.0;
|
||||
const HORIZONTAL_MIN_SIZE: f32 = 80.;
|
||||
@@ -126,6 +128,7 @@ impl PaneGroup {
|
||||
&self,
|
||||
project: &Model<Project>,
|
||||
follower_states: &HashMap<View<Pane>, FollowerState>,
|
||||
active_call: Option<&Model<ActiveCall>>,
|
||||
active_pane: &View<Pane>,
|
||||
zoomed: Option<&AnyWeakView>,
|
||||
app_state: &Arc<AppState>,
|
||||
@@ -135,6 +138,7 @@ impl PaneGroup {
|
||||
project,
|
||||
0,
|
||||
follower_states,
|
||||
active_call,
|
||||
active_pane,
|
||||
zoomed,
|
||||
app_state,
|
||||
@@ -196,6 +200,7 @@ impl Member {
|
||||
project: &Model<Project>,
|
||||
basis: usize,
|
||||
follower_states: &HashMap<View<Pane>, FollowerState>,
|
||||
active_call: Option<&Model<ActiveCall>>,
|
||||
active_pane: &View<Pane>,
|
||||
zoomed: Option<&AnyWeakView>,
|
||||
app_state: &Arc<AppState>,
|
||||
@@ -203,19 +208,89 @@ impl Member {
|
||||
) -> impl IntoElement {
|
||||
match self {
|
||||
Member::Pane(pane) => {
|
||||
// todo!()
|
||||
// let pane_element = if Some(pane.into()) == zoomed {
|
||||
// None
|
||||
// } else {
|
||||
// Some(pane)
|
||||
// };
|
||||
let leader = follower_states.get(pane).and_then(|state| {
|
||||
let room = active_call?.read(cx).room()?.read(cx);
|
||||
room.remote_participant_for_peer_id(state.leader_id)
|
||||
});
|
||||
|
||||
div().size_full().child(pane.clone()).into_any()
|
||||
let mut leader_border = None;
|
||||
let mut leader_status_box = None;
|
||||
if let Some(leader) = &leader {
|
||||
let mut leader_color = cx
|
||||
.theme()
|
||||
.players()
|
||||
.color_for_participant(leader.participant_index.0)
|
||||
.cursor;
|
||||
leader_color.fade_out(0.3);
|
||||
leader_border = Some(leader_color);
|
||||
|
||||
// Stack::new()
|
||||
// .with_child(pane_element.contained().with_border(leader_border))
|
||||
// .with_children(leader_status_box)
|
||||
// .into_any()
|
||||
leader_status_box = match leader.location {
|
||||
ParticipantLocation::SharedProject {
|
||||
project_id: leader_project_id,
|
||||
} => {
|
||||
if Some(leader_project_id) == project.read(cx).remote_id() {
|
||||
None
|
||||
} else {
|
||||
let leader_user = leader.user.clone();
|
||||
let leader_user_id = leader.user.id;
|
||||
Some(
|
||||
Button::new(
|
||||
("leader-status", pane.entity_id()),
|
||||
format!(
|
||||
"Follow {} to their active project",
|
||||
leader_user.github_login,
|
||||
),
|
||||
)
|
||||
.on_click(cx.listener(
|
||||
move |this, _, cx| {
|
||||
crate::join_remote_project(
|
||||
leader_project_id,
|
||||
leader_user_id,
|
||||
this.app_state().clone(),
|
||||
cx,
|
||||
)
|
||||
.detach_and_log_err(cx);
|
||||
},
|
||||
)),
|
||||
)
|
||||
}
|
||||
}
|
||||
ParticipantLocation::UnsharedProject => Some(Button::new(
|
||||
("leader-status", pane.entity_id()),
|
||||
format!(
|
||||
"{} is viewing an unshared Zed project",
|
||||
leader.user.github_login
|
||||
),
|
||||
)),
|
||||
ParticipantLocation::External => Some(Button::new(
|
||||
("leader-status", pane.entity_id()),
|
||||
format!(
|
||||
"{} is viewing a window outside of Zed",
|
||||
leader.user.github_login
|
||||
),
|
||||
)),
|
||||
};
|
||||
}
|
||||
|
||||
div()
|
||||
.relative()
|
||||
.size_full()
|
||||
.child(pane.clone())
|
||||
.when_some(leader_border, |this, color| {
|
||||
this.border_2().border_color(color)
|
||||
})
|
||||
.when_some(leader_status_box, |this, status_box| {
|
||||
this.child(
|
||||
div()
|
||||
.absolute()
|
||||
.w_96()
|
||||
.bottom_3()
|
||||
.right_3()
|
||||
.z_index(1)
|
||||
.child(status_box),
|
||||
)
|
||||
})
|
||||
.into_any()
|
||||
|
||||
// let el = div()
|
||||
// .flex()
|
||||
|
||||
@@ -5,7 +5,7 @@ pub mod model;
|
||||
use std::path::Path;
|
||||
|
||||
use anyhow::{anyhow, bail, Context, Result};
|
||||
use db2::{define_connection, query, sqlez::connection::Connection, sqlez_macros::sql};
|
||||
use db::{define_connection, query, sqlez::connection::Connection, sqlez_macros::sql};
|
||||
use gpui::WindowBounds;
|
||||
|
||||
use util::{unzip_option, ResultExt};
|
||||
@@ -552,7 +552,7 @@ impl WorkspaceDb {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use db2::open_test_db;
|
||||
use db::open_test_db;
|
||||
use gpui;
|
||||
|
||||
#[gpui::test]
|
||||
|
||||
@@ -3,12 +3,12 @@ use crate::{
|
||||
};
|
||||
use anyhow::{Context, Result};
|
||||
use async_recursion::async_recursion;
|
||||
use db2::sqlez::{
|
||||
use db::sqlez::{
|
||||
bindable::{Bind, Column, StaticColumnCount},
|
||||
statement::Statement,
|
||||
};
|
||||
use gpui::{AsyncWindowContext, Model, Task, View, WeakView, WindowBounds};
|
||||
use project2::Project;
|
||||
use project::Project;
|
||||
use std::{
|
||||
path::{Path, PathBuf},
|
||||
sync::Arc,
|
||||
|
||||
@@ -4,7 +4,7 @@ use gpui::{
|
||||
AnyView, AppContext, EventEmitter, Subscription, Task, View, ViewContext, WeakView,
|
||||
WindowContext,
|
||||
};
|
||||
use project2::search::SearchQuery;
|
||||
use project::search::SearchQuery;
|
||||
|
||||
use crate::{
|
||||
item::{Item, WeakItemHandle},
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
use crate::{
|
||||
item::{Item, ItemEvent},
|
||||
ItemNavHistory, WorkspaceId,
|
||||
};
|
||||
use anyhow::Result;
|
||||
use call::participant::{Frame, RemoteVideoTrack};
|
||||
use client::{proto::PeerId, User};
|
||||
use futures::StreamExt;
|
||||
use gpui::{
|
||||
div, img, AppContext, Div, Element, EventEmitter, FocusHandle, Focusable, FocusableView,
|
||||
InteractiveElement, ParentElement, Render, SharedString, Styled, Task, View, ViewContext,
|
||||
VisualContext, WindowContext,
|
||||
};
|
||||
use std::sync::{Arc, Weak};
|
||||
use ui::{h_stack, Icon, IconElement};
|
||||
|
||||
pub enum Event {
|
||||
Close,
|
||||
}
|
||||
|
||||
pub struct SharedScreen {
|
||||
track: Weak<RemoteVideoTrack>,
|
||||
frame: Option<Frame>,
|
||||
pub peer_id: PeerId,
|
||||
user: Arc<User>,
|
||||
nav_history: Option<ItemNavHistory>,
|
||||
_maintain_frame: Task<Result<()>>,
|
||||
focus: FocusHandle,
|
||||
}
|
||||
|
||||
impl SharedScreen {
|
||||
pub fn new(
|
||||
track: &Arc<RemoteVideoTrack>,
|
||||
peer_id: PeerId,
|
||||
user: Arc<User>,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Self {
|
||||
cx.focus_handle();
|
||||
let mut frames = track.frames();
|
||||
Self {
|
||||
track: Arc::downgrade(track),
|
||||
frame: None,
|
||||
peer_id,
|
||||
user,
|
||||
nav_history: Default::default(),
|
||||
_maintain_frame: cx.spawn(|this, mut cx| async move {
|
||||
while let Some(frame) = frames.next().await {
|
||||
this.update(&mut cx, |this, cx| {
|
||||
this.frame = Some(frame);
|
||||
cx.notify();
|
||||
})?;
|
||||
}
|
||||
this.update(&mut cx, |_, cx| cx.emit(Event::Close))?;
|
||||
Ok(())
|
||||
}),
|
||||
focus: cx.focus_handle(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl EventEmitter<Event> for SharedScreen {}
|
||||
impl EventEmitter<ItemEvent> for SharedScreen {}
|
||||
|
||||
impl FocusableView for SharedScreen {
|
||||
fn focus_handle(&self, _: &AppContext) -> FocusHandle {
|
||||
self.focus.clone()
|
||||
}
|
||||
}
|
||||
impl Render for SharedScreen {
|
||||
type Element = Focusable<Div>;
|
||||
|
||||
fn render(&mut self, _: &mut ViewContext<Self>) -> Self::Element {
|
||||
div().track_focus(&self.focus).size_full().children(
|
||||
self.frame
|
||||
.as_ref()
|
||||
.map(|frame| img(frame.image()).size_full()),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl Item for SharedScreen {
|
||||
fn tab_tooltip_text(&self, _: &AppContext) -> Option<SharedString> {
|
||||
Some(format!("{}'s screen", self.user.github_login).into())
|
||||
}
|
||||
fn deactivated(&mut self, cx: &mut ViewContext<Self>) {
|
||||
if let Some(nav_history) = self.nav_history.as_mut() {
|
||||
nav_history.push::<()>(None, cx);
|
||||
}
|
||||
}
|
||||
|
||||
fn tab_content(&self, _: Option<usize>, _: &WindowContext<'_>) -> gpui::AnyElement {
|
||||
h_stack()
|
||||
.gap_1()
|
||||
.child(IconElement::new(Icon::Screen))
|
||||
.child(SharedString::from(format!(
|
||||
"{}'s screen",
|
||||
self.user.github_login
|
||||
)))
|
||||
.into_any()
|
||||
}
|
||||
|
||||
fn set_nav_history(&mut self, history: ItemNavHistory, _: &mut ViewContext<Self>) {
|
||||
self.nav_history = Some(history);
|
||||
}
|
||||
|
||||
fn clone_on_split(
|
||||
&self,
|
||||
_workspace_id: WorkspaceId,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Option<View<Self>> {
|
||||
let track = self.track.upgrade()?;
|
||||
Some(cx.build_view(|cx| Self::new(&track, self.peer_id, self.user.clone(), cx)))
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ use gpui::{
|
||||
WindowContext,
|
||||
};
|
||||
use ui::prelude::*;
|
||||
use ui::{h_stack, Button, Icon, IconButton};
|
||||
use ui::{h_stack, Icon, IconButton};
|
||||
use util::ResultExt;
|
||||
|
||||
pub trait StatusItemView: Render {
|
||||
@@ -52,49 +52,12 @@ impl Render for StatusBar {
|
||||
h_stack()
|
||||
.gap_4()
|
||||
.child(
|
||||
h_stack()
|
||||
.gap_1()
|
||||
.child(
|
||||
// TODO: Line / column numbers
|
||||
div()
|
||||
.border()
|
||||
.border_color(gpui::red())
|
||||
.child(Button::new("status_line_column_numbers", "15:22")),
|
||||
)
|
||||
.child(
|
||||
// TODO: Language picker
|
||||
div()
|
||||
.border()
|
||||
.border_color(gpui::red())
|
||||
.child(Button::new("status_buffer_language", "Rust")),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
h_stack()
|
||||
.gap_1()
|
||||
.child(
|
||||
// Github tool
|
||||
div()
|
||||
.border()
|
||||
.border_color(gpui::red())
|
||||
.child(IconButton::new("status-copilot", Icon::Copilot)),
|
||||
)
|
||||
.child(
|
||||
// Feedback Tool
|
||||
div()
|
||||
.border()
|
||||
.border_color(gpui::red())
|
||||
.child(IconButton::new("status-feedback", Icon::Envelope)),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
// Bottom Dock
|
||||
h_stack().gap_1().child(
|
||||
// Terminal
|
||||
// Feedback Tool
|
||||
div()
|
||||
.border()
|
||||
.border_color(gpui::red())
|
||||
.child(IconButton::new("status-terminal", Icon::Terminal)),
|
||||
.child(IconButton::new("status-feedback", Icon::Envelope)),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
@@ -133,7 +96,7 @@ impl StatusBar {
|
||||
h_stack()
|
||||
.items_center()
|
||||
.gap_2()
|
||||
.children(self.right_items.iter().map(|item| item.to_any()))
|
||||
.children(self.right_items.iter().rev().map(|item| item.to_any()))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ use gpui::{
|
||||
ViewContext, WindowContext,
|
||||
};
|
||||
use ui::prelude::*;
|
||||
use ui::{h_stack, v_stack, ButtonLike, Color, Icon, IconButton, Label};
|
||||
use ui::{h_stack, v_stack, Icon, IconButton};
|
||||
|
||||
pub enum ToolbarItemEvent {
|
||||
ChangeLocation(ToolbarItemLocation),
|
||||
@@ -80,7 +80,6 @@ impl Render for Toolbar {
|
||||
type Element = Div;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
//dbg!(&self.items.len());
|
||||
v_stack()
|
||||
.border_b()
|
||||
.border_color(cx.theme().colors().border_variant)
|
||||
@@ -88,17 +87,8 @@ impl Render for Toolbar {
|
||||
.child(
|
||||
h_stack()
|
||||
.justify_between()
|
||||
.child(
|
||||
// Toolbar left side
|
||||
h_stack().border().border_color(gpui::red()).p_1().child(
|
||||
ButtonLike::new("breadcrumb")
|
||||
.child(Label::new("crates/workspace2/src/toolbar.rs"))
|
||||
.child(Label::new("›").color(Color::Muted))
|
||||
.child(Label::new("impl Render for Toolbar"))
|
||||
.child(Label::new("›").color(Color::Muted))
|
||||
.child(Label::new("fn render")),
|
||||
),
|
||||
)
|
||||
// Toolbar left side
|
||||
.children(self.items.iter().map(|(child, _)| child.to_any()))
|
||||
// Toolbar right side
|
||||
.child(
|
||||
h_stack()
|
||||
@@ -117,7 +107,6 @@ impl Render for Toolbar {
|
||||
),
|
||||
),
|
||||
)
|
||||
.children(self.items.iter().map(|(child, _)| child.to_any()))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1466
-1645
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use settings2::Settings;
|
||||
use settings::Settings;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct WorkspaceSettings {
|
||||
|
||||
Reference in New Issue
Block a user