mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-05 10:20:51 +00:00
Toggle project panel when opening new workspace in a dock-agnostic way
This commit is contained in:
parent
3d6b728364
commit
924ec961ff
3 changed files with 36 additions and 30 deletions
|
@ -194,7 +194,7 @@ impl TestServer {
|
||||||
themes: ThemeRegistry::new((), cx.font_cache()),
|
themes: ThemeRegistry::new((), cx.font_cache()),
|
||||||
fs: fs.clone(),
|
fs: fs.clone(),
|
||||||
build_window_options: |_, _, _| Default::default(),
|
build_window_options: |_, _, _| Default::default(),
|
||||||
initialize_workspace: |_, _, _| unimplemented!(),
|
initialize_workspace: |_, _, _, _| unimplemented!(),
|
||||||
background_actions: || &[],
|
background_actions: || &[],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -361,7 +361,7 @@ pub struct AppState {
|
||||||
pub fs: Arc<dyn fs::Fs>,
|
pub fs: Arc<dyn fs::Fs>,
|
||||||
pub build_window_options:
|
pub build_window_options:
|
||||||
fn(Option<WindowBounds>, Option<uuid::Uuid>, &dyn Platform) -> WindowOptions<'static>,
|
fn(Option<WindowBounds>, Option<uuid::Uuid>, &dyn Platform) -> WindowOptions<'static>,
|
||||||
pub initialize_workspace: fn(&mut Workspace, &Arc<AppState>, &mut ViewContext<Workspace>),
|
pub initialize_workspace: fn(&mut Workspace, bool, &Arc<AppState>, &mut ViewContext<Workspace>),
|
||||||
pub background_actions: BackgroundActions,
|
pub background_actions: BackgroundActions,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,7 +383,7 @@ impl AppState {
|
||||||
fs,
|
fs,
|
||||||
languages,
|
languages,
|
||||||
user_store,
|
user_store,
|
||||||
initialize_workspace: |_, _, _| {},
|
initialize_workspace: |_, _, _, _| {},
|
||||||
build_window_options: |_, _, _| Default::default(),
|
build_window_options: |_, _, _| Default::default(),
|
||||||
background_actions: || &[],
|
background_actions: || &[],
|
||||||
})
|
})
|
||||||
|
@ -733,6 +733,7 @@ impl Workspace {
|
||||||
let build_workspace =
|
let build_workspace =
|
||||||
|cx: &mut ViewContext<Workspace>,
|
|cx: &mut ViewContext<Workspace>,
|
||||||
serialized_workspace: Option<SerializedWorkspace>| {
|
serialized_workspace: Option<SerializedWorkspace>| {
|
||||||
|
let was_deserialized = serialized_workspace.is_some();
|
||||||
let mut workspace = Workspace::new(
|
let mut workspace = Workspace::new(
|
||||||
serialized_workspace,
|
serialized_workspace,
|
||||||
workspace_id,
|
workspace_id,
|
||||||
|
@ -740,7 +741,12 @@ impl Workspace {
|
||||||
app_state.clone(),
|
app_state.clone(),
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
(app_state.initialize_workspace)(&mut workspace, &app_state, cx);
|
(app_state.initialize_workspace)(
|
||||||
|
&mut workspace,
|
||||||
|
was_deserialized,
|
||||||
|
&app_state,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
workspace
|
workspace
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2734,7 +2740,7 @@ impl Workspace {
|
||||||
user_store: project.read(cx).user_store(),
|
user_store: project.read(cx).user_store(),
|
||||||
fs: project.read(cx).fs().clone(),
|
fs: project.read(cx).fs().clone(),
|
||||||
build_window_options: |_, _, _| Default::default(),
|
build_window_options: |_, _, _| Default::default(),
|
||||||
initialize_workspace: |_, _, _| {},
|
initialize_workspace: |_, _, _, _| {},
|
||||||
background_actions: || &[],
|
background_actions: || &[],
|
||||||
});
|
});
|
||||||
Self::new(None, 0, project, app_state, cx)
|
Self::new(None, 0, project, app_state, cx)
|
||||||
|
@ -2998,28 +3004,11 @@ pub fn open_paths(
|
||||||
.await,
|
.await,
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
let contains_directory =
|
Ok(cx
|
||||||
futures::future::join_all(abs_paths.iter().map(|path| app_state.fs.is_file(path)))
|
.update(|cx| {
|
||||||
.await
|
Workspace::new_local(abs_paths, app_state.clone(), requesting_window_id, cx)
|
||||||
.contains(&false);
|
|
||||||
|
|
||||||
cx.update(|cx| {
|
|
||||||
let task =
|
|
||||||
Workspace::new_local(abs_paths, app_state.clone(), requesting_window_id, cx);
|
|
||||||
|
|
||||||
cx.spawn(|mut cx| async move {
|
|
||||||
let (workspace, items) = task.await;
|
|
||||||
|
|
||||||
workspace.update(&mut cx, |workspace, cx| {
|
|
||||||
if contains_directory {
|
|
||||||
workspace.toggle_dock(DockPosition::Left, cx);
|
|
||||||
}
|
|
||||||
})?;
|
|
||||||
|
|
||||||
anyhow::Ok((workspace, items))
|
|
||||||
})
|
})
|
||||||
})
|
.await)
|
||||||
.await
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -3109,9 +3098,8 @@ pub fn join_remote_project(
|
||||||
let (_, workspace) = cx.add_window(
|
let (_, workspace) = cx.add_window(
|
||||||
(app_state.build_window_options)(None, None, cx.platform().as_ref()),
|
(app_state.build_window_options)(None, None, cx.platform().as_ref()),
|
||||||
|cx| {
|
|cx| {
|
||||||
let mut workspace =
|
let mut workspace = Workspace::new(None, 0, project, app_state.clone(), cx);
|
||||||
Workspace::new(Default::default(), 0, project, app_state.clone(), cx);
|
(app_state.initialize_workspace)(&mut workspace, false, &app_state, cx);
|
||||||
(app_state.initialize_workspace)(&mut workspace, &app_state, cx);
|
|
||||||
workspace
|
workspace
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -35,7 +35,10 @@ use terminal_view::terminal_panel::{self, TerminalPanel};
|
||||||
use util::{channel::ReleaseChannel, paths, ResultExt};
|
use util::{channel::ReleaseChannel, paths, ResultExt};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
pub use workspace;
|
pub use workspace;
|
||||||
use workspace::{create_and_open_local_file, open_new, AppState, NewFile, NewWindow, Workspace};
|
use workspace::{
|
||||||
|
create_and_open_local_file, dock::PanelHandle, open_new, AppState, NewFile, NewWindow,
|
||||||
|
Workspace,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Deserialize, Clone, PartialEq)]
|
#[derive(Deserialize, Clone, PartialEq)]
|
||||||
pub struct OpenBrowser {
|
pub struct OpenBrowser {
|
||||||
|
@ -279,6 +282,7 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut gpui::AppContext) {
|
||||||
|
|
||||||
pub fn initialize_workspace(
|
pub fn initialize_workspace(
|
||||||
workspace: &mut Workspace,
|
workspace: &mut Workspace,
|
||||||
|
was_deserialized: bool,
|
||||||
app_state: &Arc<AppState>,
|
app_state: &Arc<AppState>,
|
||||||
cx: &mut ViewContext<Workspace>,
|
cx: &mut ViewContext<Workspace>,
|
||||||
) {
|
) {
|
||||||
|
@ -316,7 +320,21 @@ pub fn initialize_workspace(
|
||||||
workspace.set_titlebar_item(collab_titlebar_item.into_any(), cx);
|
workspace.set_titlebar_item(collab_titlebar_item.into_any(), cx);
|
||||||
|
|
||||||
let project_panel = ProjectPanel::new(workspace, cx);
|
let project_panel = ProjectPanel::new(workspace, cx);
|
||||||
|
let project_panel_position = project_panel.position(cx);
|
||||||
workspace.add_panel(project_panel, cx);
|
workspace.add_panel(project_panel, cx);
|
||||||
|
if !was_deserialized
|
||||||
|
&& workspace
|
||||||
|
.project()
|
||||||
|
.read(cx)
|
||||||
|
.visible_worktrees(cx)
|
||||||
|
.any(|tree| {
|
||||||
|
tree.read(cx)
|
||||||
|
.root_entry()
|
||||||
|
.map_or(false, |entry| entry.is_dir())
|
||||||
|
})
|
||||||
|
{
|
||||||
|
workspace.toggle_dock(project_panel_position, cx);
|
||||||
|
}
|
||||||
|
|
||||||
let terminal_panel = cx.add_view(|cx| TerminalPanel::new(workspace, cx));
|
let terminal_panel = cx.add_view(|cx| TerminalPanel::new(workspace, cx));
|
||||||
workspace.add_panel(terminal_panel, cx);
|
workspace.add_panel(terminal_panel, cx);
|
||||||
|
|
Loading…
Reference in a new issue