Show project panel when opening a folder via the CLI

This commit is contained in:
Antonio Scandurra 2022-04-22 10:45:46 +02:00
parent 67c55255fa
commit 9d8e3f51c8
3 changed files with 27 additions and 8 deletions

View File

@ -43,7 +43,7 @@ pub fn new_journal_entry(app_state: Arc<AppState>, cx: &mut MutableAppContext) {
cx.spawn(|mut cx| {
async move {
let (journal_dir, entry_path) = create_entry.await?;
let (workspace, _) = cx
let (workspace, _, _) = cx
.update(|cx| workspace::open_paths(&[journal_dir], &app_state, cx))
.await;

View File

@ -2115,6 +2115,7 @@ pub fn open_paths(
) -> Task<(
ViewHandle<Workspace>,
Vec<Option<Result<Box<dyn ItemHandle>, Arc<anyhow::Error>>>>,
bool,
)> {
log::info!("open paths {:?}", abs_paths);
@ -2136,6 +2137,7 @@ pub fn open_paths(
}
}
let is_new_workspace = existing.is_none();
let workspace = existing.unwrap_or_else(|| {
cx.add_window((app_state.build_window_options)(), |cx| {
let project = Project::local(
@ -2153,7 +2155,7 @@ pub fn open_paths(
let task = workspace.update(cx, |workspace, cx| workspace.open_paths(abs_paths, cx));
cx.spawn(|_| async move {
let items = task.await;
(workspace, items)
(workspace, items, is_new_workspace)
})
}

View File

@ -22,7 +22,11 @@ use smol::process::Command;
use std::{env, fs, path::PathBuf, sync::Arc, thread, time::Duration};
use theme::{ThemeRegistry, DEFAULT_THEME_NAME};
use util::ResultExt;
use workspace::{self, AppState, OpenNew, OpenPaths};
use workspace::{
self,
sidebar::{Side, SidebarItemId, ToggleSidebarItem},
AppState, OpenNew, OpenPaths,
};
use zed::{
self, build_window_options, build_workspace,
fs::RealFs,
@ -362,12 +366,13 @@ async fn handle_cli_connection(
if let Some(request) = requests.next().await {
match request {
CliRequest::Open { paths, wait } => {
let (workspace, items) = cx
let (workspace, items, is_new_workspace) = cx
.update(|cx| workspace::open_paths(&paths, &app_state, cx))
.await;
let mut errored = false;
let mut futures = Vec::new();
let mut opened_directory = false;
let mut item_release_futures = Vec::new();
cx.update(|cx| {
for (item, path) in items.into_iter().zip(&paths) {
match item {
@ -380,7 +385,7 @@ async fn handle_cli_connection(
}),
)
.detach();
futures.push(released.1);
item_release_futures.push(released.1);
}
Some(Err(err)) => {
responses
@ -390,11 +395,23 @@ async fn handle_cli_connection(
.log_err();
errored = true;
}
None => {}
None => opened_directory = true,
}
}
});
if opened_directory && is_new_workspace {
workspace.update(&mut cx, |workspace, cx| {
workspace.toggle_sidebar_item(
&ToggleSidebarItem(SidebarItemId {
side: Side::Left,
item_index: 0,
}),
cx,
);
});
}
if wait {
let background = cx.background();
let wait = async move {
@ -408,7 +425,7 @@ async fn handle_cli_connection(
drop(workspace);
let _ = done_rx.await;
} else {
let _ = futures::future::try_join_all(futures).await;
let _ = futures::future::try_join_all(item_release_futures).await;
};
}
.fuse();