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| { cx.spawn(|mut cx| {
async move { async move {
let (journal_dir, entry_path) = create_entry.await?; let (journal_dir, entry_path) = create_entry.await?;
let (workspace, _) = cx let (workspace, _, _) = cx
.update(|cx| workspace::open_paths(&[journal_dir], &app_state, cx)) .update(|cx| workspace::open_paths(&[journal_dir], &app_state, cx))
.await; .await;

View file

@ -2115,6 +2115,7 @@ pub fn open_paths(
) -> Task<( ) -> Task<(
ViewHandle<Workspace>, ViewHandle<Workspace>,
Vec<Option<Result<Box<dyn ItemHandle>, Arc<anyhow::Error>>>>, Vec<Option<Result<Box<dyn ItemHandle>, Arc<anyhow::Error>>>>,
bool,
)> { )> {
log::info!("open paths {:?}", abs_paths); 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(|| { let workspace = existing.unwrap_or_else(|| {
cx.add_window((app_state.build_window_options)(), |cx| { cx.add_window((app_state.build_window_options)(), |cx| {
let project = Project::local( 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)); let task = workspace.update(cx, |workspace, cx| workspace.open_paths(abs_paths, cx));
cx.spawn(|_| async move { cx.spawn(|_| async move {
let items = task.await; 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 std::{env, fs, path::PathBuf, sync::Arc, thread, time::Duration};
use theme::{ThemeRegistry, DEFAULT_THEME_NAME}; use theme::{ThemeRegistry, DEFAULT_THEME_NAME};
use util::ResultExt; use util::ResultExt;
use workspace::{self, AppState, OpenNew, OpenPaths}; use workspace::{
self,
sidebar::{Side, SidebarItemId, ToggleSidebarItem},
AppState, OpenNew, OpenPaths,
};
use zed::{ use zed::{
self, build_window_options, build_workspace, self, build_window_options, build_workspace,
fs::RealFs, fs::RealFs,
@ -362,12 +366,13 @@ async fn handle_cli_connection(
if let Some(request) = requests.next().await { if let Some(request) = requests.next().await {
match request { match request {
CliRequest::Open { paths, wait } => { CliRequest::Open { paths, wait } => {
let (workspace, items) = cx let (workspace, items, is_new_workspace) = cx
.update(|cx| workspace::open_paths(&paths, &app_state, cx)) .update(|cx| workspace::open_paths(&paths, &app_state, cx))
.await; .await;
let mut errored = false; let mut errored = false;
let mut futures = Vec::new(); let mut opened_directory = false;
let mut item_release_futures = Vec::new();
cx.update(|cx| { cx.update(|cx| {
for (item, path) in items.into_iter().zip(&paths) { for (item, path) in items.into_iter().zip(&paths) {
match item { match item {
@ -380,7 +385,7 @@ async fn handle_cli_connection(
}), }),
) )
.detach(); .detach();
futures.push(released.1); item_release_futures.push(released.1);
} }
Some(Err(err)) => { Some(Err(err)) => {
responses responses
@ -390,11 +395,23 @@ async fn handle_cli_connection(
.log_err(); .log_err();
errored = true; 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 { if wait {
let background = cx.background(); let background = cx.background();
let wait = async move { let wait = async move {
@ -408,7 +425,7 @@ async fn handle_cli_connection(
drop(workspace); drop(workspace);
let _ = done_rx.await; let _ = done_rx.await;
} else { } else {
let _ = futures::future::try_join_all(futures).await; let _ = futures::future::try_join_all(item_release_futures).await;
}; };
} }
.fuse(); .fuse();