Start moving terminal modal into dock UI
This commit is contained in:
parent
0fca4d02ec
commit
39d219c898
3 changed files with 12 additions and 14 deletions
|
@ -1,6 +1,6 @@
|
||||||
use gpui::{ModelHandle, ViewContext};
|
use gpui::{ModelHandle, ViewContext};
|
||||||
use settings::{Settings, WorkingDirectory};
|
use settings::{Settings, WorkingDirectory};
|
||||||
use workspace::{programs::ProgramManager, Workspace};
|
use workspace::{programs::Dock, Workspace};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
terminal_container_view::{
|
terminal_container_view::{
|
||||||
|
@ -13,7 +13,7 @@ pub fn deploy_modal(workspace: &mut Workspace, _: &DeployModal, cx: &mut ViewCon
|
||||||
let window = cx.window_id();
|
let window = cx.window_id();
|
||||||
|
|
||||||
// Pull the terminal connection out of the global if it has been stored
|
// Pull the terminal connection out of the global if it has been stored
|
||||||
let possible_terminal = ProgramManager::remove::<Terminal, _>(window, cx);
|
let possible_terminal = Dock::remove::<Terminal, _>(window, cx);
|
||||||
|
|
||||||
if let Some(terminal_handle) = possible_terminal {
|
if let Some(terminal_handle) = possible_terminal {
|
||||||
workspace.toggle_modal(cx, |_, cx| {
|
workspace.toggle_modal(cx, |_, cx| {
|
||||||
|
@ -22,7 +22,7 @@ pub fn deploy_modal(workspace: &mut Workspace, _: &DeployModal, cx: &mut ViewCon
|
||||||
});
|
});
|
||||||
// Toggle Modal will dismiss the terminal modal if it is currently shown, so we must
|
// Toggle Modal will dismiss the terminal modal if it is currently shown, so we must
|
||||||
// store the terminal back in the global
|
// store the terminal back in the global
|
||||||
ProgramManager::insert_or_replace::<Terminal, _>(window, terminal_handle, cx);
|
Dock::insert_or_replace::<Terminal, _>(window, terminal_handle, cx);
|
||||||
} else {
|
} else {
|
||||||
// No connection was stored, create a new terminal
|
// No connection was stored, create a new terminal
|
||||||
if let Some(closed_terminal_handle) = workspace.toggle_modal(cx, |workspace, cx| {
|
if let Some(closed_terminal_handle) = workspace.toggle_modal(cx, |workspace, cx| {
|
||||||
|
@ -43,7 +43,7 @@ pub fn deploy_modal(workspace: &mut Workspace, _: &DeployModal, cx: &mut ViewCon
|
||||||
cx.subscribe(&terminal_handle, on_event).detach();
|
cx.subscribe(&terminal_handle, on_event).detach();
|
||||||
// Set the global immediately if terminal construction was successful,
|
// Set the global immediately if terminal construction was successful,
|
||||||
// in case the user opens the command palette
|
// in case the user opens the command palette
|
||||||
ProgramManager::insert_or_replace::<Terminal, _>(window, terminal_handle, cx);
|
Dock::insert_or_replace::<Terminal, _>(window, terminal_handle, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
this
|
this
|
||||||
|
@ -55,7 +55,7 @@ pub fn deploy_modal(workspace: &mut Workspace, _: &DeployModal, cx: &mut ViewCon
|
||||||
let terminal_handle = connected.read(cx).handle();
|
let terminal_handle = connected.read(cx).handle();
|
||||||
// Set the global immediately if terminal construction was successful,
|
// Set the global immediately if terminal construction was successful,
|
||||||
// in case the user opens the command palette
|
// in case the user opens the command palette
|
||||||
ProgramManager::insert_or_replace::<Terminal, _>(window, terminal_handle, cx);
|
Dock::insert_or_replace::<Terminal, _>(window, terminal_handle, cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ pub fn on_event(
|
||||||
) {
|
) {
|
||||||
// Dismiss the modal if the terminal quit
|
// Dismiss the modal if the terminal quit
|
||||||
if let Event::CloseTerminal = event {
|
if let Event::CloseTerminal = event {
|
||||||
ProgramManager::remove::<Terminal, _>(cx.window_id(), cx);
|
Dock::remove::<Terminal, _>(cx.window_id(), cx);
|
||||||
|
|
||||||
if workspace.modal::<TerminalContainer>().is_some() {
|
if workspace.modal::<TerminalContainer>().is_some() {
|
||||||
workspace.dismiss_modal(cx)
|
workspace.dismiss_modal(cx)
|
||||||
|
|
|
@ -19,27 +19,25 @@ use gpui::{AnyModelHandle, Entity, ModelHandle, View, ViewContext};
|
||||||
/// This struct is going to be the starting point for the 'program manager' feature that will
|
/// This struct is going to be the starting point for the 'program manager' feature that will
|
||||||
/// eventually be implemented to provide a collaborative way of engaging with identity-having
|
/// eventually be implemented to provide a collaborative way of engaging with identity-having
|
||||||
/// features like the terminal.
|
/// features like the terminal.
|
||||||
pub struct ProgramManager {
|
pub struct Dock {
|
||||||
// TODO: Make this a hashset or something
|
// TODO: Make this a hashset or something
|
||||||
modals: HashMap<usize, AnyModelHandle>,
|
modals: HashMap<usize, AnyModelHandle>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProgramManager {
|
impl Dock {
|
||||||
pub fn insert_or_replace<T: Entity, V: View>(
|
pub fn insert_or_replace<T: Entity, V: View>(
|
||||||
window: usize,
|
window: usize,
|
||||||
program: ModelHandle<T>,
|
program: ModelHandle<T>,
|
||||||
cx: &mut ViewContext<V>,
|
cx: &mut ViewContext<V>,
|
||||||
) -> Option<AnyModelHandle> {
|
) -> Option<AnyModelHandle> {
|
||||||
cx.update_global::<ProgramManager, _, _>(|pm, _| {
|
cx.update_global::<Dock, _, _>(|pm, _| pm.insert_or_replace_internal::<T>(window, program))
|
||||||
pm.insert_or_replace_internal::<T>(window, program)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove<T: Entity, V: View>(
|
pub fn remove<T: Entity, V: View>(
|
||||||
window: usize,
|
window: usize,
|
||||||
cx: &mut ViewContext<V>,
|
cx: &mut ViewContext<V>,
|
||||||
) -> Option<ModelHandle<T>> {
|
) -> Option<ModelHandle<T>> {
|
||||||
cx.update_global::<ProgramManager, _, _>(|pm, _| pm.remove_internal::<T>(window))
|
cx.update_global::<Dock, _, _>(|pm, _| pm.remove_internal::<T>(window))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
|
|
|
@ -37,7 +37,7 @@ use log::error;
|
||||||
pub use pane::*;
|
pub use pane::*;
|
||||||
pub use pane_group::*;
|
pub use pane_group::*;
|
||||||
use postage::prelude::Stream;
|
use postage::prelude::Stream;
|
||||||
use programs::ProgramManager;
|
use programs::Dock;
|
||||||
use project::{fs, Fs, Project, ProjectEntryId, ProjectPath, ProjectStore, Worktree, WorktreeId};
|
use project::{fs, Fs, Project, ProjectEntryId, ProjectPath, ProjectStore, Worktree, WorktreeId};
|
||||||
use searchable::SearchableItemHandle;
|
use searchable::SearchableItemHandle;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
@ -147,7 +147,7 @@ impl_actions!(workspace, [ToggleProjectOnline, ActivatePane]);
|
||||||
|
|
||||||
pub fn init(app_state: Arc<AppState>, cx: &mut MutableAppContext) {
|
pub fn init(app_state: Arc<AppState>, cx: &mut MutableAppContext) {
|
||||||
// Initialize the program manager immediately
|
// Initialize the program manager immediately
|
||||||
cx.set_global(ProgramManager::new());
|
cx.set_global(Dock::new());
|
||||||
|
|
||||||
pane::init(cx);
|
pane::init(cx);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue