WIP
This commit is contained in:
parent
e3465fbcf9
commit
fd61683c46
13 changed files with 1174 additions and 1186 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -11567,6 +11567,7 @@ dependencies = [
|
||||||
"smol",
|
"smol",
|
||||||
"sum_tree",
|
"sum_tree",
|
||||||
"tempdir",
|
"tempdir",
|
||||||
|
"terminal_view2",
|
||||||
"text2",
|
"text2",
|
||||||
"theme2",
|
"theme2",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
|
|
|
@ -426,7 +426,7 @@ impl Editor {
|
||||||
|
|
||||||
pub fn read_scroll_position_from_db(
|
pub fn read_scroll_position_from_db(
|
||||||
&mut self,
|
&mut self,
|
||||||
item_id: usize,
|
item_id: u64,
|
||||||
workspace_id: WorkspaceId,
|
workspace_id: WorkspaceId,
|
||||||
cx: &mut ViewContext<Editor>,
|
cx: &mut ViewContext<Editor>,
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -1830,8 +1830,8 @@ impl<'a, V: 'static> ViewContext<'a, V> {
|
||||||
self.view
|
self.view
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn model(&self) -> Model<V> {
|
pub fn model(&self) -> &Model<V> {
|
||||||
self.view.model.clone()
|
&self.view.model
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Access the underlying window context.
|
/// Access the underlying window context.
|
||||||
|
@ -2163,7 +2163,7 @@ impl<'a, V: 'static> ViewContext<'a, V> {
|
||||||
|
|
||||||
pub fn observe_global<G: 'static>(
|
pub fn observe_global<G: 'static>(
|
||||||
&mut self,
|
&mut self,
|
||||||
f: impl Fn(&mut V, &mut ViewContext<'_, V>) + 'static,
|
mut f: impl FnMut(&mut V, &mut ViewContext<'_, V>) + 'static,
|
||||||
) -> Subscription {
|
) -> Subscription {
|
||||||
let window_handle = self.window.handle;
|
let window_handle = self.window.handle;
|
||||||
let view = self.view().downgrade();
|
let view = self.view().downgrade();
|
||||||
|
|
|
@ -164,6 +164,23 @@ impl Column for i64 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl StaticColumnCount for u64 {}
|
||||||
|
impl Bind for u64 {
|
||||||
|
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
||||||
|
statement
|
||||||
|
.bind_int64(start_index, (*self) as i64)
|
||||||
|
.with_context(|| format!("Failed to bind i64 at index {start_index}"))?;
|
||||||
|
Ok(start_index + 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Column for u64 {
|
||||||
|
fn column(statement: &mut Statement, start_index: i32) -> Result<(Self, i32)> {
|
||||||
|
let result = statement.column_int64(start_index)? as u64;
|
||||||
|
Ok((result, start_index + 1))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl StaticColumnCount for u32 {}
|
impl StaticColumnCount for u32 {}
|
||||||
impl Bind for u32 {
|
impl Bind for u32 {
|
||||||
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use db::{define_connection, query, sqlez_macros::sql};
|
use db::{define_connection, query, sqlez_macros::sql};
|
||||||
use gpui::EntityId;
|
|
||||||
use workspace::{ItemId, WorkspaceDb, WorkspaceId};
|
use workspace::{ItemId, WorkspaceDb, WorkspaceId};
|
||||||
|
|
||||||
define_connection! {
|
define_connection! {
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -3,8 +3,9 @@ use std::{path::PathBuf, sync::Arc};
|
||||||
use crate::TerminalView;
|
use crate::TerminalView;
|
||||||
use db::kvp::KEY_VALUE_STORE;
|
use db::kvp::KEY_VALUE_STORE;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, serde_json, Action, AppContext, AsyncAppContext, Entity, EventEmitter, Render,
|
actions, div, serde_json, AppContext, AsyncWindowContext, Div, Entity, EventEmitter,
|
||||||
Subscription, Task, View, ViewContext, VisualContext, WeakView, WindowContext,
|
FocusHandle, FocusableView, ParentComponent, Render, Subscription, Task, View, ViewContext,
|
||||||
|
VisualContext, WeakView, WindowContext,
|
||||||
};
|
};
|
||||||
use project::Fs;
|
use project::Fs;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -14,7 +15,9 @@ use util::{ResultExt, TryFutureExt};
|
||||||
use workspace::{
|
use workspace::{
|
||||||
dock::{DockPosition, Panel, PanelEvent},
|
dock::{DockPosition, Panel, PanelEvent},
|
||||||
item::Item,
|
item::Item,
|
||||||
pane, Pane, Workspace,
|
pane,
|
||||||
|
ui::Icon,
|
||||||
|
Pane, Workspace,
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
@ -28,20 +31,14 @@ pub fn init(cx: &mut AppContext) {
|
||||||
|workspace: &mut Workspace, _: &mut ViewContext<Workspace>| {
|
|workspace: &mut Workspace, _: &mut ViewContext<Workspace>| {
|
||||||
workspace.register_action(TerminalPanel::new_terminal);
|
workspace.register_action(TerminalPanel::new_terminal);
|
||||||
workspace.register_action(TerminalPanel::open_terminal);
|
workspace.register_action(TerminalPanel::open_terminal);
|
||||||
|
workspace.register_action(|workspace, _: &ToggleFocus, cx| {
|
||||||
|
workspace.toggle_panel_focus::<TerminalPanel>(cx);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.detach();
|
.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum Event {
|
|
||||||
Close,
|
|
||||||
DockPositionChanged,
|
|
||||||
ZoomIn,
|
|
||||||
ZoomOut,
|
|
||||||
Focus,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct TerminalPanel {
|
pub struct TerminalPanel {
|
||||||
pane: View<Pane>,
|
pane: View<Pane>,
|
||||||
fs: Arc<dyn Fs>,
|
fs: Arc<dyn Fs>,
|
||||||
|
@ -54,9 +51,9 @@ pub struct TerminalPanel {
|
||||||
|
|
||||||
impl TerminalPanel {
|
impl TerminalPanel {
|
||||||
fn new(workspace: &Workspace, cx: &mut ViewContext<Self>) -> Self {
|
fn new(workspace: &Workspace, cx: &mut ViewContext<Self>) -> Self {
|
||||||
let weak_self = cx.weak_handle();
|
let _weak_self = cx.view().downgrade();
|
||||||
let pane = cx.build_view(|cx| {
|
let pane = cx.build_view(|cx| {
|
||||||
let window = cx.window_handle();
|
let _window = cx.window_handle();
|
||||||
let mut pane = Pane::new(
|
let mut pane = Pane::new(
|
||||||
workspace.weak_handle(),
|
workspace.weak_handle(),
|
||||||
workspace.project().clone(),
|
workspace.project().clone(),
|
||||||
|
@ -65,54 +62,55 @@ impl TerminalPanel {
|
||||||
);
|
);
|
||||||
pane.set_can_split(false, cx);
|
pane.set_can_split(false, cx);
|
||||||
pane.set_can_navigate(false, cx);
|
pane.set_can_navigate(false, cx);
|
||||||
pane.on_can_drop(move |drag_and_drop, cx| {
|
// todo!()
|
||||||
drag_and_drop
|
// pane.on_can_drop(move |drag_and_drop, cx| {
|
||||||
.currently_dragged::<DraggedItem>(window)
|
// drag_and_drop
|
||||||
.map_or(false, |(_, item)| {
|
// .currently_dragged::<DraggedItem>(window)
|
||||||
item.handle.act_as::<TerminalView>(cx).is_some()
|
// .map_or(false, |(_, item)| {
|
||||||
})
|
// item.handle.act_as::<TerminalView>(cx).is_some()
|
||||||
});
|
// })
|
||||||
pane.set_render_tab_bar_buttons(cx, move |pane, cx| {
|
// });
|
||||||
let this = weak_self.clone();
|
// pane.set_render_tab_bar_buttons(cx, move |pane, cx| {
|
||||||
Flex::row()
|
// let this = weak_self.clone();
|
||||||
.with_child(Pane::render_tab_bar_button(
|
// Flex::row()
|
||||||
0,
|
// .with_child(Pane::render_tab_bar_button(
|
||||||
"icons/plus.svg",
|
// 0,
|
||||||
false,
|
// "icons/plus.svg",
|
||||||
Some(("New Terminal", Some(Box::new(workspace::NewTerminal)))),
|
// false,
|
||||||
cx,
|
// Some(("New Terminal", Some(Box::new(workspace::NewTerminal)))),
|
||||||
move |_, cx| {
|
// cx,
|
||||||
let this = this.clone();
|
// move |_, cx| {
|
||||||
cx.window_context().defer(move |cx| {
|
// let this = this.clone();
|
||||||
if let Some(this) = this.upgrade() {
|
// cx.window_context().defer(move |cx| {
|
||||||
this.update(cx, |this, cx| {
|
// if let Some(this) = this.upgrade() {
|
||||||
this.add_terminal(None, cx);
|
// this.update(cx, |this, cx| {
|
||||||
});
|
// this.add_terminal(None, cx);
|
||||||
}
|
// });
|
||||||
})
|
// }
|
||||||
},
|
// })
|
||||||
|_, _| {},
|
// },
|
||||||
None,
|
// |_, _| {},
|
||||||
))
|
// None,
|
||||||
.with_child(Pane::render_tab_bar_button(
|
// ))
|
||||||
1,
|
// .with_child(Pane::render_tab_bar_button(
|
||||||
if pane.is_zoomed() {
|
// 1,
|
||||||
"icons/minimize.svg"
|
// if pane.is_zoomed() {
|
||||||
} else {
|
// "icons/minimize.svg"
|
||||||
"icons/maximize.svg"
|
// } else {
|
||||||
},
|
// "icons/maximize.svg"
|
||||||
pane.is_zoomed(),
|
// },
|
||||||
Some(("Toggle Zoom".into(), Some(Box::new(workspace::ToggleZoom)))),
|
// pane.is_zoomed(),
|
||||||
cx,
|
// Some(("Toggle Zoom".into(), Some(Box::new(workspace::ToggleZoom)))),
|
||||||
move |pane, cx| pane.toggle_zoom(&Default::default(), cx),
|
// cx,
|
||||||
|_, _| {},
|
// move |pane, cx| pane.toggle_zoom(&Default::default(), cx),
|
||||||
None,
|
// |_, _| {},
|
||||||
))
|
// None,
|
||||||
.into_any()
|
// ))
|
||||||
});
|
// .into_any()
|
||||||
let buffer_search_bar = cx.build_view(search::BufferSearchBar::new);
|
// });
|
||||||
pane.toolbar()
|
// let buffer_search_bar = cx.build_view(search::BufferSearchBar::new);
|
||||||
.update(cx, |toolbar, cx| toolbar.add_item(buffer_search_bar, cx));
|
// pane.toolbar()
|
||||||
|
// .update(cx, |toolbar, cx| toolbar.add_item(buffer_search_bar, cx));
|
||||||
pane
|
pane
|
||||||
});
|
});
|
||||||
let subscriptions = vec![
|
let subscriptions = vec![
|
||||||
|
@ -133,80 +131,81 @@ impl TerminalPanel {
|
||||||
let new_dock_position = this.position(cx);
|
let new_dock_position = this.position(cx);
|
||||||
if new_dock_position != old_dock_position {
|
if new_dock_position != old_dock_position {
|
||||||
old_dock_position = new_dock_position;
|
old_dock_position = new_dock_position;
|
||||||
cx.emit(Event::DockPositionChanged);
|
cx.emit(PanelEvent::ChangePosition);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
this
|
this
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load(workspace: WeakView<Workspace>, cx: AsyncAppContext) -> Task<Result<View<Self>>> {
|
pub async fn load(
|
||||||
cx.spawn(|mut cx| async move {
|
workspace: WeakView<Workspace>,
|
||||||
let serialized_panel = if let Some(panel) = cx
|
mut cx: AsyncWindowContext,
|
||||||
.background_executor()
|
) -> Result<View<Self>> {
|
||||||
.spawn(async move { KEY_VALUE_STORE.read_kvp(TERMINAL_PANEL_KEY) })
|
let serialized_panel = cx
|
||||||
.await
|
.background_executor()
|
||||||
.log_err()
|
.spawn(async move { KEY_VALUE_STORE.read_kvp(TERMINAL_PANEL_KEY) })
|
||||||
.flatten()
|
.await
|
||||||
{
|
.log_err()
|
||||||
Some(serde_json::from_str::<SerializedTerminalPanel>(&panel)?)
|
.flatten()
|
||||||
} else {
|
.map(|panel| serde_json::from_str::<SerializedTerminalPanel>(&panel))
|
||||||
None
|
.transpose()
|
||||||
};
|
.log_err()
|
||||||
let (panel, pane, items) = workspace.update(&mut cx, |workspace, cx| {
|
.flatten();
|
||||||
let panel = cx.build_view(|cx| TerminalPanel::new(workspace, cx));
|
|
||||||
let items = if let Some(serialized_panel) = serialized_panel.as_ref() {
|
|
||||||
panel.update(cx, |panel, cx| {
|
|
||||||
cx.notify();
|
|
||||||
panel.height = serialized_panel.height;
|
|
||||||
panel.width = serialized_panel.width;
|
|
||||||
panel.pane.update(cx, |_, cx| {
|
|
||||||
serialized_panel
|
|
||||||
.items
|
|
||||||
.iter()
|
|
||||||
.map(|item_id| {
|
|
||||||
TerminalView::deserialize(
|
|
||||||
workspace.project().clone(),
|
|
||||||
workspace.weak_handle(),
|
|
||||||
workspace.database_id(),
|
|
||||||
*item_id,
|
|
||||||
cx,
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
Default::default()
|
|
||||||
};
|
|
||||||
let pane = panel.read(cx).pane.clone();
|
|
||||||
(panel, pane, items)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let pane = pane.downgrade();
|
let (panel, pane, items) = workspace.update(&mut cx, |workspace, cx| {
|
||||||
let items = futures::future::join_all(items).await;
|
let panel = cx.build_view(|cx| TerminalPanel::new(workspace, cx));
|
||||||
pane.update(&mut cx, |pane, cx| {
|
let items = if let Some(serialized_panel) = serialized_panel.as_ref() {
|
||||||
let active_item_id = serialized_panel
|
panel.update(cx, |panel, cx| {
|
||||||
.as_ref()
|
cx.notify();
|
||||||
.and_then(|panel| panel.active_item_id);
|
panel.height = serialized_panel.height;
|
||||||
let mut active_ix = None;
|
panel.width = serialized_panel.width;
|
||||||
for item in items {
|
panel.pane.update(cx, |_, cx| {
|
||||||
if let Some(item) = item.log_err() {
|
serialized_panel
|
||||||
let item_id = item.entity_id().as_u64();
|
.items
|
||||||
pane.add_item(Box::new(item), false, false, None, cx);
|
.iter()
|
||||||
if Some(item_id) == active_item_id {
|
.map(|item_id| {
|
||||||
active_ix = Some(pane.items_len() - 1);
|
TerminalView::deserialize(
|
||||||
}
|
workspace.project().clone(),
|
||||||
|
workspace.weak_handle(),
|
||||||
|
workspace.database_id(),
|
||||||
|
*item_id,
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
Default::default()
|
||||||
|
};
|
||||||
|
let pane = panel.read(cx).pane.clone();
|
||||||
|
(panel, pane, items)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let pane = pane.downgrade();
|
||||||
|
let items = futures::future::join_all(items).await;
|
||||||
|
pane.update(&mut cx, |pane, cx| {
|
||||||
|
let active_item_id = serialized_panel
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|panel| panel.active_item_id);
|
||||||
|
let mut active_ix = None;
|
||||||
|
for item in items {
|
||||||
|
if let Some(item) = item.log_err() {
|
||||||
|
let item_id = item.entity_id().as_u64();
|
||||||
|
pane.add_item(Box::new(item), false, false, None, cx);
|
||||||
|
if Some(item_id) == active_item_id {
|
||||||
|
active_ix = Some(pane.items_len() - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(active_ix) = active_ix {
|
if let Some(active_ix) = active_ix {
|
||||||
pane.activate_item(active_ix, false, false, cx)
|
pane.activate_item(active_ix, false, false, cx)
|
||||||
}
|
}
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
Ok(panel)
|
Ok(panel)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_pane_event(
|
fn handle_pane_event(
|
||||||
|
@ -218,10 +217,10 @@ impl TerminalPanel {
|
||||||
match event {
|
match event {
|
||||||
pane::Event::ActivateItem { .. } => self.serialize(cx),
|
pane::Event::ActivateItem { .. } => self.serialize(cx),
|
||||||
pane::Event::RemoveItem { .. } => self.serialize(cx),
|
pane::Event::RemoveItem { .. } => self.serialize(cx),
|
||||||
pane::Event::Remove => cx.emit(Event::Close),
|
pane::Event::Remove => cx.emit(PanelEvent::Close),
|
||||||
pane::Event::ZoomIn => cx.emit(Event::ZoomIn),
|
pane::Event::ZoomIn => cx.emit(PanelEvent::ZoomIn),
|
||||||
pane::Event::ZoomOut => cx.emit(Event::ZoomOut),
|
pane::Event::ZoomOut => cx.emit(PanelEvent::ZoomOut),
|
||||||
pane::Event::Focus => cx.emit(Event::Focus),
|
pane::Event::Focus => cx.emit(PanelEvent::Focus),
|
||||||
|
|
||||||
pane::Event::AddItem { item } => {
|
pane::Event::AddItem { item } => {
|
||||||
if let Some(workspace) = self.workspace.upgrade() {
|
if let Some(workspace) = self.workspace.upgrade() {
|
||||||
|
@ -334,20 +333,20 @@ impl TerminalPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventEmitter<Event> for TerminalPanel {}
|
|
||||||
impl EventEmitter<PanelEvent> for TerminalPanel {}
|
impl EventEmitter<PanelEvent> for TerminalPanel {}
|
||||||
|
|
||||||
impl Render for TerminalPanel {
|
impl Render for TerminalPanel {
|
||||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> gpui::AnyElement<Self> {
|
type Element = Div<Self>;
|
||||||
ChildView::new(&self.pane, cx).into_any()
|
|
||||||
}
|
|
||||||
|
|
||||||
// todo!()
|
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element {
|
||||||
// fn focus_in(&mut self, _: gpui::AnyView, cx: &mut ViewContext<Self>) {
|
div().child(self.pane.clone())
|
||||||
// if cx.is_self_focused() {
|
}
|
||||||
// cx.focus(&self.pane);
|
}
|
||||||
// }
|
|
||||||
// }
|
impl FocusableView for TerminalPanel {
|
||||||
|
fn focus_handle(&self, cx: &AppContext) -> FocusHandle {
|
||||||
|
self.pane.focus_handle(cx)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Panel for TerminalPanel {
|
impl Panel for TerminalPanel {
|
||||||
|
@ -407,14 +406,6 @@ impl Panel for TerminalPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn icon_path(&self, _: &WindowContext) -> Option<&'static str> {
|
|
||||||
Some("icons/terminal.svg")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn icon_tooltip(&self) -> (String, Option<Box<dyn Action>>) {
|
|
||||||
("Terminal Panel".into(), Some(Box::new(ToggleFocus)))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn icon_label(&self, cx: &WindowContext) -> Option<String> {
|
fn icon_label(&self, cx: &WindowContext) -> Option<String> {
|
||||||
let count = self.pane.read(cx).items_len();
|
let count = self.pane.read(cx).items_len();
|
||||||
if count == 0 {
|
if count == 0 {
|
||||||
|
@ -428,34 +419,22 @@ impl Panel for TerminalPanel {
|
||||||
self.pane.read(cx).has_focus(cx)
|
self.pane.read(cx).has_focus(cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn persistent_name(&self) -> &'static str {
|
fn persistent_name() -> &'static str {
|
||||||
todo!()
|
"TerminalPanel"
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo!() is it needed?
|
// todo!()
|
||||||
// fn should_change_position_on_event(event: &Self::Event) -> bool {
|
// fn icon_tooltip(&self) -> (String, Option<Box<dyn Action>>) {
|
||||||
// matches!(event, Event::DockPositionChanged)
|
// ("Terminal Panel".into(), Some(Box::new(ToggleFocus)))
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// fn should_activate_on_event(_: &Self::Event) -> bool {
|
fn icon(&self, _cx: &WindowContext) -> Option<Icon> {
|
||||||
// false
|
Some(Icon::Terminal)
|
||||||
// }
|
}
|
||||||
|
|
||||||
// fn should_close_on_event(event: &Event) -> bool {
|
fn toggle_action(&self) -> Box<dyn gpui::Action> {
|
||||||
// matches!(event, Event::Close)
|
Box::new(ToggleFocus)
|
||||||
// }
|
}
|
||||||
|
|
||||||
// fn is_focus_event(event: &Self::Event) -> bool {
|
|
||||||
// matches!(event, Event::Focus)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn should_zoom_in_on_event(event: &Event) -> bool {
|
|
||||||
// matches!(event, Event::ZoomIn)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn should_zoom_out_on_event(event: &Event) -> bool {
|
|
||||||
// matches!(event, Event::ZoomOut)
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
|
|
|
@ -1,22 +1,23 @@
|
||||||
#![allow(unused_variables)]
|
#![allow(unused_variables)]
|
||||||
//todo!(remove)
|
//todo!(remove)
|
||||||
|
|
||||||
// mod persistence;
|
mod persistence;
|
||||||
pub mod terminal_element;
|
pub mod terminal_element;
|
||||||
pub mod terminal_panel;
|
pub mod terminal_panel;
|
||||||
|
|
||||||
use crate::terminal_element::TerminalElement;
|
// todo!()
|
||||||
|
// use crate::terminal_element::TerminalElement;
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use dirs::home_dir;
|
use dirs::home_dir;
|
||||||
use editor::{scroll::autoscroll::Autoscroll, Editor};
|
use editor::{scroll::autoscroll::Autoscroll, Editor};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, div, img, red, register_action, AnyElement, AppContext, Component, DispatchPhase, Div,
|
actions, div, img, red, register_action, AnyElement, AppContext, Component, DispatchPhase, Div,
|
||||||
EventEmitter, FocusEvent, FocusHandle, Focusable, FocusableKeyDispatch, InputHandler,
|
EventEmitter, FocusEvent, FocusHandle, Focusable, FocusableComponent, FocusableView,
|
||||||
KeyDownEvent, Keystroke, Model, ParentElement, Pixels, Render, SharedString,
|
InputHandler, InteractiveComponent, KeyDownEvent, Keystroke, Model, ParentComponent, Pixels,
|
||||||
StatefulInteractivity, StatelessInteractive, Styled, Task, View, ViewContext, VisualContext,
|
Render, SharedString, Styled, Task, View, ViewContext, VisualContext, WeakView,
|
||||||
WeakView,
|
|
||||||
};
|
};
|
||||||
use language::Bias;
|
use language::Bias;
|
||||||
|
use persistence::TERMINAL_DB;
|
||||||
use project::{search::SearchQuery, LocalWorktree, Project};
|
use project::{search::SearchQuery, LocalWorktree, Project};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use settings::Settings;
|
use settings::Settings;
|
||||||
|
@ -68,7 +69,7 @@ pub fn init(cx: &mut AppContext) {
|
||||||
|
|
||||||
cx.observe_new_views(
|
cx.observe_new_views(
|
||||||
|workspace: &mut Workspace, cx: &mut ViewContext<Workspace>| {
|
|workspace: &mut Workspace, cx: &mut ViewContext<Workspace>| {
|
||||||
workspace.register_action(TerminalView::deploy)
|
workspace.register_action(TerminalView::deploy);
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.detach();
|
.detach();
|
||||||
|
@ -94,6 +95,12 @@ impl EventEmitter<Event> for TerminalView {}
|
||||||
impl EventEmitter<ItemEvent> for TerminalView {}
|
impl EventEmitter<ItemEvent> for TerminalView {}
|
||||||
impl EventEmitter<SearchEvent> for TerminalView {}
|
impl EventEmitter<SearchEvent> for TerminalView {}
|
||||||
|
|
||||||
|
impl FocusableView for TerminalView {
|
||||||
|
fn focus_handle(&self, _cx: &AppContext) -> FocusHandle {
|
||||||
|
self.focus_handle.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl TerminalView {
|
impl TerminalView {
|
||||||
///Create a new Terminal in the current working directory or the user's home directory
|
///Create a new Terminal in the current working directory or the user's home directory
|
||||||
pub fn deploy(
|
pub fn deploy(
|
||||||
|
@ -159,15 +166,14 @@ impl TerminalView {
|
||||||
|
|
||||||
let item_id = cx.entity_id();
|
let item_id = cx.entity_id();
|
||||||
let workspace_id = this.workspace_id;
|
let workspace_id = this.workspace_id;
|
||||||
// todo!(persistence)
|
cx.background_executor()
|
||||||
// cx.background_executor()
|
.spawn(async move {
|
||||||
// .spawn(async move {
|
TERMINAL_DB
|
||||||
// TERMINAL_DB
|
.save_working_directory(item_id.as_u64(), workspace_id, cwd)
|
||||||
// .save_working_directory(item_id, workspace_id, cwd)
|
.await
|
||||||
// .await
|
.log_err();
|
||||||
// .log_err();
|
})
|
||||||
// })
|
.detach();
|
||||||
// .detach();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -526,7 +532,7 @@ impl TerminalView {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Render for TerminalView {
|
impl Render for TerminalView {
|
||||||
type Element = Div<Self, StatefulInteractivity<Self>, FocusableKeyDispatch<Self>>;
|
type Element = Focusable<Self, Div<Self>>;
|
||||||
|
|
||||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||||
let terminal_handle = self.terminal.clone().downgrade();
|
let terminal_handle = self.terminal.clone().downgrade();
|
||||||
|
@ -536,7 +542,7 @@ impl Render for TerminalView {
|
||||||
|
|
||||||
div()
|
div()
|
||||||
.track_focus(&self.focus_handle)
|
.track_focus(&self.focus_handle)
|
||||||
.on_focus_in(Self::focus_out)
|
.on_focus_in(Self::focus_in)
|
||||||
.on_focus_out(Self::focus_out)
|
.on_focus_out(Self::focus_out)
|
||||||
.on_key_down(Self::key_down)
|
.on_key_down(Self::key_down)
|
||||||
.on_action(TerminalView::send_text)
|
.on_action(TerminalView::send_text)
|
||||||
|
@ -828,10 +834,6 @@ impl Item for TerminalView {
|
||||||
// .detach();
|
// .detach();
|
||||||
self.workspace_id = workspace.database_id();
|
self.workspace_id = workspace.database_id();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn focus_handle(&self) -> FocusHandle {
|
|
||||||
self.focus_handle.clone()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SearchableItem for TerminalView {
|
impl SearchableItem for TerminalView {
|
||||||
|
|
|
@ -277,7 +277,7 @@ impl SerializedPane {
|
||||||
|
|
||||||
pub type GroupId = i64;
|
pub type GroupId = i64;
|
||||||
pub type PaneId = i64;
|
pub type PaneId = i64;
|
||||||
pub type ItemId = usize;
|
pub type ItemId = u64;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||||
pub struct SerializedItem {
|
pub struct SerializedItem {
|
||||||
|
|
|
@ -15,13 +15,6 @@ mod status_bar;
|
||||||
mod toolbar;
|
mod toolbar;
|
||||||
mod workspace_settings;
|
mod workspace_settings;
|
||||||
|
|
||||||
pub use crate::persistence::{
|
|
||||||
model::{
|
|
||||||
DockData, DockStructure, ItemId, SerializedItem, SerializedPane, SerializedPaneGroup,
|
|
||||||
SerializedWorkspace,
|
|
||||||
},
|
|
||||||
WorkspaceDb,
|
|
||||||
};
|
|
||||||
use anyhow::{anyhow, Context as _, Result};
|
use anyhow::{anyhow, Context as _, Result};
|
||||||
use call2::ActiveCall;
|
use call2::ActiveCall;
|
||||||
use client2::{
|
use client2::{
|
||||||
|
@ -37,11 +30,10 @@ use futures::{
|
||||||
};
|
};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, div, point, register_action, size, Action, AnyModel, AnyView, AnyWeakView, AppContext,
|
actions, div, point, register_action, size, Action, AnyModel, AnyView, AnyWeakView, AppContext,
|
||||||
AsyncAppContext, AsyncWindowContext, Bounds, Div, Entity, EntityId, EventEmitter, FocusHandle,
|
AsyncAppContext, AsyncWindowContext, Bounds, Context, Div, Entity, EntityId, EventEmitter,
|
||||||
FocusableView, GlobalPixels, KeyContext, Model, ModelContext, ParentElement, Point, Render,
|
FocusHandle, FocusableView, GlobalPixels, InteractiveComponent, KeyContext, Model,
|
||||||
Size, StatefulInteractive, StatelessInteractive, StatelessInteractivity, Styled, Subscription,
|
ModelContext, ParentComponent, Point, Render, Size, Styled, Subscription, Task, View,
|
||||||
Task, View, ViewContext, VisualContext, WeakView, WindowBounds, WindowContext, WindowHandle,
|
ViewContext, VisualContext, WeakView, WindowBounds, WindowContext, WindowHandle, WindowOptions,
|
||||||
WindowOptions,
|
|
||||||
};
|
};
|
||||||
use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ItemSettings, ProjectItem};
|
use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ItemSettings, ProjectItem};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
@ -52,7 +44,10 @@ use node_runtime::NodeRuntime;
|
||||||
use notifications::{simple_message_notification::MessageNotification, NotificationHandle};
|
use notifications::{simple_message_notification::MessageNotification, NotificationHandle};
|
||||||
pub use pane::*;
|
pub use pane::*;
|
||||||
pub use pane_group::*;
|
pub use pane_group::*;
|
||||||
use persistence::{model::WorkspaceLocation, DB};
|
pub use persistence::{
|
||||||
|
model::{ItemId, SerializedWorkspace, WorkspaceLocation},
|
||||||
|
WorkspaceDb, DB,
|
||||||
|
};
|
||||||
use postage::stream::Stream;
|
use postage::stream::Stream;
|
||||||
use project2::{Project, ProjectEntryId, ProjectPath, Worktree};
|
use project2::{Project, ProjectEntryId, ProjectPath, Worktree};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
@ -69,10 +64,15 @@ use std::{
|
||||||
};
|
};
|
||||||
use theme2::{ActiveTheme, ThemeSettings};
|
use theme2::{ActiveTheme, ThemeSettings};
|
||||||
pub use toolbar::{ToolbarItemLocation, ToolbarItemView};
|
pub use toolbar::{ToolbarItemLocation, ToolbarItemView};
|
||||||
|
pub use ui;
|
||||||
use util::ResultExt;
|
use util::ResultExt;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
pub use workspace_settings::{AutosaveSetting, WorkspaceSettings};
|
pub use workspace_settings::{AutosaveSetting, WorkspaceSettings};
|
||||||
|
|
||||||
|
use crate::persistence::model::{
|
||||||
|
DockData, DockStructure, SerializedItem, SerializedPane, SerializedPaneGroup,
|
||||||
|
};
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref ZED_WINDOW_SIZE: Option<Size<GlobalPixels>> = env::var("ZED_WINDOW_SIZE")
|
static ref ZED_WINDOW_SIZE: Option<Size<GlobalPixels>> = env::var("ZED_WINDOW_SIZE")
|
||||||
.ok()
|
.ok()
|
||||||
|
@ -1582,13 +1582,11 @@ impl Workspace {
|
||||||
self.serialize_workspace(cx);
|
self.serialize_workspace(cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
// /// Transfer focus to the panel of the given type.
|
/// Transfer focus to the panel of the given type.
|
||||||
// pub fn focus_panel<T: Panel>(&mut self, cx: &mut ViewContext<Self>) -> Option<View<T>> {
|
pub fn focus_panel<T: Panel>(&mut self, cx: &mut ViewContext<Self>) -> Option<View<T>> {
|
||||||
// self.focus_or_unfocus_panel::<T>(cx, |_, _| true)?
|
let panel = self.focus_or_unfocus_panel::<T>(cx, |_, _| true)?;
|
||||||
// .as_any()
|
panel.to_any().downcast().ok()
|
||||||
// .clone()
|
}
|
||||||
// .downcast()
|
|
||||||
// }
|
|
||||||
|
|
||||||
/// Focus the panel of the given type if it isn't already focused. If it is
|
/// Focus the panel of the given type if it isn't already focused. If it is
|
||||||
/// already focused, then transfer focus back to the workspace center.
|
/// already focused, then transfer focus back to the workspace center.
|
||||||
|
@ -2981,7 +2979,7 @@ impl Workspace {
|
||||||
.filter_map(|item_handle| {
|
.filter_map(|item_handle| {
|
||||||
Some(SerializedItem {
|
Some(SerializedItem {
|
||||||
kind: Arc::from(item_handle.serialized_item_kind()?),
|
kind: Arc::from(item_handle.serialized_item_kind()?),
|
||||||
item_id: item_handle.id().as_u64() as usize,
|
item_id: item_handle.id().as_u64(),
|
||||||
active: Some(item_handle.id()) == active_item_id,
|
active: Some(item_handle.id()) == active_item_id,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -66,7 +66,7 @@ feature_flags = { package = "feature_flags2", path = "../feature_flags2" }
|
||||||
sum_tree = { path = "../sum_tree" }
|
sum_tree = { path = "../sum_tree" }
|
||||||
shellexpand = "2.1.0"
|
shellexpand = "2.1.0"
|
||||||
text = { package = "text2", path = "../text2" }
|
text = { package = "text2", path = "../text2" }
|
||||||
# terminal_view = { path = "../terminal_view" }
|
terminal_view = { package = "terminal_view2", path = "../terminal_view2" }
|
||||||
theme = { package = "theme2", path = "../theme2" }
|
theme = { package = "theme2", path = "../theme2" }
|
||||||
# theme_selector = { path = "../theme_selector" }
|
# theme_selector = { path = "../theme_selector" }
|
||||||
util = { path = "../util" }
|
util = { path = "../util" }
|
||||||
|
|
|
@ -198,7 +198,7 @@ fn main() {
|
||||||
// search::init(cx);
|
// search::init(cx);
|
||||||
// semantic_index::init(fs.clone(), http.clone(), languages.clone(), cx);
|
// semantic_index::init(fs.clone(), http.clone(), languages.clone(), cx);
|
||||||
// vim::init(cx);
|
// vim::init(cx);
|
||||||
// terminal_view::init(cx);
|
terminal_view::init(cx);
|
||||||
|
|
||||||
// journal2::init(app_state.clone(), cx);
|
// journal2::init(app_state.clone(), cx);
|
||||||
// language_selector::init(cx);
|
// language_selector::init(cx);
|
||||||
|
|
|
@ -20,6 +20,7 @@ use anyhow::{anyhow, Context as _};
|
||||||
use project_panel::ProjectPanel;
|
use project_panel::ProjectPanel;
|
||||||
use settings::{initial_local_settings_content, Settings};
|
use settings::{initial_local_settings_content, Settings};
|
||||||
use std::{borrow::Cow, ops::Deref, sync::Arc};
|
use std::{borrow::Cow, ops::Deref, sync::Arc};
|
||||||
|
use terminal_view::terminal_panel::TerminalPanel;
|
||||||
use util::{
|
use util::{
|
||||||
asset_str,
|
asset_str,
|
||||||
channel::ReleaseChannel,
|
channel::ReleaseChannel,
|
||||||
|
@ -174,7 +175,7 @@ pub fn initialize_workspace(app_state: Arc<AppState>, cx: &mut AppContext) {
|
||||||
|
|
||||||
cx.spawn(|workspace_handle, mut cx| async move {
|
cx.spawn(|workspace_handle, mut cx| async move {
|
||||||
let project_panel = ProjectPanel::load(workspace_handle.clone(), cx.clone());
|
let project_panel = ProjectPanel::load(workspace_handle.clone(), cx.clone());
|
||||||
// let terminal_panel = TerminalPanel::load(workspace_handle.clone(), cx.clone());
|
let terminal_panel = TerminalPanel::load(workspace_handle.clone(), cx.clone());
|
||||||
// let assistant_panel = AssistantPanel::load(workspace_handle.clone(), cx.clone());
|
// let assistant_panel = AssistantPanel::load(workspace_handle.clone(), cx.clone());
|
||||||
let channels_panel =
|
let channels_panel =
|
||||||
collab_ui::collab_panel::CollabPanel::load(workspace_handle.clone(), cx.clone());
|
collab_ui::collab_panel::CollabPanel::load(workspace_handle.clone(), cx.clone());
|
||||||
|
@ -186,14 +187,14 @@ pub fn initialize_workspace(app_state: Arc<AppState>, cx: &mut AppContext) {
|
||||||
// );
|
// );
|
||||||
let (
|
let (
|
||||||
project_panel,
|
project_panel,
|
||||||
// terminal_panel,
|
terminal_panel,
|
||||||
// assistant_panel,
|
// assistant_panel,
|
||||||
channels_panel,
|
channels_panel,
|
||||||
// chat_panel,
|
// chat_panel,
|
||||||
// notification_panel,
|
// notification_panel,
|
||||||
) = futures::try_join!(
|
) = futures::try_join!(
|
||||||
project_panel,
|
project_panel,
|
||||||
// terminal_panel,
|
terminal_panel,
|
||||||
// assistant_panel,
|
// assistant_panel,
|
||||||
channels_panel,
|
channels_panel,
|
||||||
// chat_panel,
|
// chat_panel,
|
||||||
|
@ -203,7 +204,7 @@ pub fn initialize_workspace(app_state: Arc<AppState>, cx: &mut AppContext) {
|
||||||
workspace_handle.update(&mut cx, |workspace, cx| {
|
workspace_handle.update(&mut cx, |workspace, cx| {
|
||||||
let project_panel_position = project_panel.position(cx);
|
let project_panel_position = project_panel.position(cx);
|
||||||
workspace.add_panel(project_panel, cx);
|
workspace.add_panel(project_panel, cx);
|
||||||
// workspace.add_panel(terminal_panel, cx);
|
workspace.add_panel(terminal_panel, cx);
|
||||||
// workspace.add_panel(assistant_panel, cx);
|
// workspace.add_panel(assistant_panel, cx);
|
||||||
workspace.add_panel(channels_panel, cx);
|
workspace.add_panel(channels_panel, cx);
|
||||||
// workspace.add_panel(chat_panel, cx);
|
// workspace.add_panel(chat_panel, cx);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue