move restorable_workspace_locations to workspace
This commit is contained in:
parent
6cd3726a5a
commit
910469d4ff
3 changed files with 58 additions and 66 deletions
|
@ -8085,6 +8085,61 @@ pub fn with_active_or_new_workspace(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn restorable_workspace_locations(
|
||||||
|
cx: &mut AsyncApp,
|
||||||
|
app_state: &Arc<AppState>,
|
||||||
|
) -> Option<Vec<SerializedWorkspaceLocation>> {
|
||||||
|
let mut restore_behavior = cx
|
||||||
|
.update(|cx| WorkspaceSettings::get(None, cx).restore_on_startup)
|
||||||
|
.ok()?;
|
||||||
|
|
||||||
|
let session_handle = app_state.session.clone();
|
||||||
|
let (last_session_id, last_session_window_stack) = cx
|
||||||
|
.update(|cx| {
|
||||||
|
let session = session_handle.read(cx);
|
||||||
|
|
||||||
|
(
|
||||||
|
session.last_session_id().map(|id| id.to_string()),
|
||||||
|
session.last_session_window_stack(),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.ok()?;
|
||||||
|
|
||||||
|
if last_session_id.is_none()
|
||||||
|
&& matches!(restore_behavior, RestoreOnStartupBehavior::LastSession)
|
||||||
|
{
|
||||||
|
restore_behavior = RestoreOnStartupBehavior::LastWorkspace;
|
||||||
|
}
|
||||||
|
|
||||||
|
match restore_behavior {
|
||||||
|
RestoreOnStartupBehavior::LastWorkspace => last_opened_workspace_location()
|
||||||
|
.await
|
||||||
|
.map(|location| vec![location]),
|
||||||
|
RestoreOnStartupBehavior::LastSession => {
|
||||||
|
if let Some(last_session_id) = last_session_id {
|
||||||
|
let ordered = last_session_window_stack.is_some();
|
||||||
|
|
||||||
|
let mut locations =
|
||||||
|
last_session_workspace_locations(&last_session_id, last_session_window_stack)
|
||||||
|
.filter(|locations| !locations.is_empty());
|
||||||
|
|
||||||
|
// Since last_session_window_order returns the windows ordered front-to-back
|
||||||
|
// we need to open the window that was frontmost last.
|
||||||
|
if ordered {
|
||||||
|
if let Some(locations) = locations.as_mut() {
|
||||||
|
locations.reverse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
locations
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::{cell::RefCell, rc::Rc};
|
use std::{cell::RefCell, rc::Rc};
|
||||||
|
|
|
@ -46,7 +46,7 @@ use util::{ConnectionResult, ResultExt, TryFutureExt, maybe};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
use welcome::{FIRST_OPEN, show_welcome_view};
|
use welcome::{FIRST_OPEN, show_welcome_view};
|
||||||
use workspace::{
|
use workspace::{
|
||||||
AppState, SerializedWorkspaceLocation, Toast, Workspace, WorkspaceSettings, WorkspaceStore,
|
AppState, SerializedWorkspaceLocation, Toast, Workspace, WorkspaceStore,
|
||||||
notifications::NotificationId,
|
notifications::NotificationId,
|
||||||
};
|
};
|
||||||
use zed::{
|
use zed::{
|
||||||
|
@ -956,7 +956,7 @@ async fn installation_id() -> Result<IdType> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn restore_or_create_workspace(app_state: Arc<AppState>, cx: &mut AsyncApp) -> Result<()> {
|
async fn restore_or_create_workspace(app_state: Arc<AppState>, cx: &mut AsyncApp) -> Result<()> {
|
||||||
if let Some(locations) = restorable_workspace_locations(cx, &app_state).await {
|
if let Some(locations) = workspace::restorable_workspace_locations(cx, &app_state).await {
|
||||||
let mut tasks = Vec::new();
|
let mut tasks = Vec::new();
|
||||||
|
|
||||||
for location in locations {
|
for location in locations {
|
||||||
|
@ -1077,68 +1077,6 @@ async fn restore_or_create_workspace(app_state: Arc<AppState>, cx: &mut AsyncApp
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn restorable_workspace_locations(
|
|
||||||
cx: &mut AsyncApp,
|
|
||||||
app_state: &Arc<AppState>,
|
|
||||||
) -> Option<Vec<SerializedWorkspaceLocation>> {
|
|
||||||
let mut restore_behavior = cx
|
|
||||||
.update(|cx| WorkspaceSettings::get(None, cx).restore_on_startup)
|
|
||||||
.ok()?;
|
|
||||||
|
|
||||||
let session_handle = app_state.session.clone();
|
|
||||||
let (last_session_id, last_session_window_stack) = cx
|
|
||||||
.update(|cx| {
|
|
||||||
let session = session_handle.read(cx);
|
|
||||||
|
|
||||||
(
|
|
||||||
session.last_session_id().map(|id| id.to_string()),
|
|
||||||
session.last_session_window_stack(),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.ok()?;
|
|
||||||
|
|
||||||
if last_session_id.is_none()
|
|
||||||
&& matches!(
|
|
||||||
restore_behavior,
|
|
||||||
workspace::RestoreOnStartupBehavior::LastSession
|
|
||||||
)
|
|
||||||
{
|
|
||||||
restore_behavior = workspace::RestoreOnStartupBehavior::LastWorkspace;
|
|
||||||
}
|
|
||||||
|
|
||||||
match restore_behavior {
|
|
||||||
workspace::RestoreOnStartupBehavior::LastWorkspace => {
|
|
||||||
workspace::last_opened_workspace_location()
|
|
||||||
.await
|
|
||||||
.map(|location| vec![location])
|
|
||||||
}
|
|
||||||
workspace::RestoreOnStartupBehavior::LastSession => {
|
|
||||||
if let Some(last_session_id) = last_session_id {
|
|
||||||
let ordered = last_session_window_stack.is_some();
|
|
||||||
|
|
||||||
let mut locations = workspace::last_session_workspace_locations(
|
|
||||||
&last_session_id,
|
|
||||||
last_session_window_stack,
|
|
||||||
)
|
|
||||||
.filter(|locations| !locations.is_empty());
|
|
||||||
|
|
||||||
// Since last_session_window_order returns the windows ordered front-to-back
|
|
||||||
// we need to open the window that was frontmost last.
|
|
||||||
if ordered {
|
|
||||||
if let Some(locations) = locations.as_mut() {
|
|
||||||
locations.reverse();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
locations
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn init_paths() -> HashMap<io::ErrorKind, Vec<&'static Path>> {
|
fn init_paths() -> HashMap<io::ErrorKind, Vec<&'static Path>> {
|
||||||
[
|
[
|
||||||
paths::config_dir(),
|
paths::config_dir(),
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::handle_open_request;
|
use crate::handle_open_request;
|
||||||
use crate::restorable_workspace_locations;
|
|
||||||
use anyhow::{Context as _, Result, anyhow};
|
use anyhow::{Context as _, Result, anyhow};
|
||||||
use cli::{CliRequest, CliResponse, ipc::IpcSender};
|
use cli::{CliRequest, CliResponse, ipc::IpcSender};
|
||||||
use cli::{IpcHandshake, ipc};
|
use cli::{IpcHandshake, ipc};
|
||||||
|
@ -366,7 +365,7 @@ async fn open_workspaces(
|
||||||
if open_new_workspace == Some(true) {
|
if open_new_workspace == Some(true) {
|
||||||
Vec::new()
|
Vec::new()
|
||||||
} else {
|
} else {
|
||||||
let locations = restorable_workspace_locations(cx, &app_state).await;
|
let locations = workspace::restorable_workspace_locations(cx, &app_state).await;
|
||||||
locations.unwrap_or_default()
|
locations.unwrap_or_default()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue