Fetch last workspace explicitly when starting Zed
co-authored-by: Max <max@zed.dev>
This commit is contained in:
parent
db3119b553
commit
5a29a74956
5 changed files with 53 additions and 35 deletions
|
@ -139,9 +139,7 @@ impl<V: View> DragAndDrop<V> {
|
||||||
region_offset,
|
region_offset,
|
||||||
region,
|
region,
|
||||||
}) => {
|
}) => {
|
||||||
if (dbg!(event.position) - (dbg!(region.origin() + region_offset))).length()
|
if (event.position - (region.origin() + region_offset)).length() > DEAD_ZONE {
|
||||||
> DEAD_ZONE
|
|
||||||
{
|
|
||||||
this.currently_dragged = Some(State::Dragging {
|
this.currently_dragged = Some(State::Dragging {
|
||||||
window_id,
|
window_id,
|
||||||
region_offset,
|
region_offset,
|
||||||
|
|
|
@ -8,7 +8,7 @@ use anyhow::{anyhow, bail, Context, Result};
|
||||||
use db::{define_connection, query, sqlez::connection::Connection, sqlez_macros::sql};
|
use db::{define_connection, query, sqlez::connection::Connection, sqlez_macros::sql};
|
||||||
use gpui::Axis;
|
use gpui::Axis;
|
||||||
|
|
||||||
use util::{iife, unzip_option, ResultExt};
|
use util::{ unzip_option, ResultExt};
|
||||||
|
|
||||||
use crate::dock::DockPosition;
|
use crate::dock::DockPosition;
|
||||||
use crate::WorkspaceId;
|
use crate::WorkspaceId;
|
||||||
|
@ -96,22 +96,16 @@ impl WorkspaceDb {
|
||||||
WorkspaceLocation,
|
WorkspaceLocation,
|
||||||
bool,
|
bool,
|
||||||
DockPosition,
|
DockPosition,
|
||||||
) = iife!({
|
) =
|
||||||
if worktree_roots.len() == 0 {
|
self.select_row_bound(sql!{
|
||||||
self.select_row(sql!(
|
SELECT workspace_id, workspace_location, left_sidebar_open, dock_visible, dock_anchor
|
||||||
SELECT workspace_id, workspace_location, left_sidebar_open, dock_visible, dock_anchor
|
FROM workspaces
|
||||||
FROM workspaces
|
WHERE workspace_location = ?
|
||||||
ORDER BY timestamp DESC LIMIT 1))?()?
|
})
|
||||||
} else {
|
.and_then(|mut prepared_statement| (prepared_statement)(&workspace_location))
|
||||||
self.select_row_bound(sql!(
|
|
||||||
SELECT workspace_id, workspace_location, left_sidebar_open, dock_visible, dock_anchor
|
|
||||||
FROM workspaces
|
|
||||||
WHERE workspace_location = ?))?(&workspace_location)?
|
|
||||||
}
|
|
||||||
.context("No workspaces found")
|
.context("No workspaces found")
|
||||||
})
|
.warn_on_err()
|
||||||
.warn_on_err()
|
.flatten()?;
|
||||||
.flatten()?;
|
|
||||||
|
|
||||||
Some(SerializedWorkspace {
|
Some(SerializedWorkspace {
|
||||||
id: workspace_id,
|
id: workspace_id,
|
||||||
|
@ -205,6 +199,16 @@ impl WorkspaceDb {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
query! {
|
||||||
|
pub fn last_workspace() -> Result<Option<WorkspaceLocation>> {
|
||||||
|
SELECT workspace_location
|
||||||
|
FROM workspaces
|
||||||
|
WHERE workspace_location IS NOT NULL
|
||||||
|
ORDER BY timestamp DESC
|
||||||
|
LIMIT 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn get_center_pane_group(&self, workspace_id: WorkspaceId) -> Result<SerializedPaneGroup> {
|
fn get_center_pane_group(&self, workspace_id: WorkspaceId) -> Result<SerializedPaneGroup> {
|
||||||
self.get_pane_group(workspace_id, None)?
|
self.get_pane_group(workspace_id, None)?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -371,9 +375,9 @@ impl WorkspaceDb {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
query!{
|
query!{
|
||||||
fn update_timestamp(workspace_id: WorkspaceId) -> Result<()> {
|
pub async fn update_timestamp(workspace_id: WorkspaceId) -> Result<()> {
|
||||||
UPDATE workspaces
|
UPDATE workspaces
|
||||||
SET timestamp = CURRENT_TIMESTAMP
|
SET timestamp = CURRENT_TIMESTAMP
|
||||||
WHERE workspace_id = ?
|
WHERE workspace_id = ?
|
||||||
|
|
|
@ -172,15 +172,16 @@ pub fn init(app_state: Arc<AppState>, cx: &mut MutableAppContext) {
|
||||||
let app_state = Arc::downgrade(&app_state);
|
let app_state = Arc::downgrade(&app_state);
|
||||||
move |_: &NewFile, cx: &mut MutableAppContext| {
|
move |_: &NewFile, cx: &mut MutableAppContext| {
|
||||||
if let Some(app_state) = app_state.upgrade() {
|
if let Some(app_state) = app_state.upgrade() {
|
||||||
open_new(&app_state, false, cx).detach();
|
open_new(&app_state, cx).detach();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
cx.add_global_action({
|
cx.add_global_action({
|
||||||
let app_state = Arc::downgrade(&app_state);
|
let app_state = Arc::downgrade(&app_state);
|
||||||
move |_: &NewWindow, cx: &mut MutableAppContext| {
|
move |_: &NewWindow, cx: &mut MutableAppContext| {
|
||||||
if let Some(app_state) = app_state.upgrade() {
|
if let Some(app_state) = app_state.upgrade() {
|
||||||
open_new(&app_state, true, cx).detach();
|
open_new(&app_state, cx).detach();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -652,7 +653,6 @@ impl Workspace {
|
||||||
fn new_local(
|
fn new_local(
|
||||||
abs_paths: Vec<PathBuf>,
|
abs_paths: Vec<PathBuf>,
|
||||||
app_state: Arc<AppState>,
|
app_state: Arc<AppState>,
|
||||||
blank: bool,
|
|
||||||
cx: &mut MutableAppContext,
|
cx: &mut MutableAppContext,
|
||||||
) -> Task<(
|
) -> Task<(
|
||||||
ViewHandle<Workspace>,
|
ViewHandle<Workspace>,
|
||||||
|
@ -667,9 +667,7 @@ impl Workspace {
|
||||||
);
|
);
|
||||||
|
|
||||||
cx.spawn(|mut cx| async move {
|
cx.spawn(|mut cx| async move {
|
||||||
let serialized_workspace = (!blank)
|
let serialized_workspace = persistence::DB.workspace_for_roots(&abs_paths.as_slice());
|
||||||
.then(|| persistence::DB.workspace_for_roots(&abs_paths.as_slice()))
|
|
||||||
.flatten();
|
|
||||||
|
|
||||||
let paths_to_open = serialized_workspace
|
let paths_to_open = serialized_workspace
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
@ -807,7 +805,7 @@ impl Workspace {
|
||||||
if self.project.read(cx).is_local() {
|
if self.project.read(cx).is_local() {
|
||||||
Task::Ready(Some(callback(self, cx)))
|
Task::Ready(Some(callback(self, cx)))
|
||||||
} else {
|
} else {
|
||||||
let task = Self::new_local(Vec::new(), app_state.clone(), true, cx);
|
let task = Self::new_local(Vec::new(), app_state.clone(), cx);
|
||||||
cx.spawn(|_vh, mut cx| async move {
|
cx.spawn(|_vh, mut cx| async move {
|
||||||
let (workspace, _) = task.await;
|
let (workspace, _) = task.await;
|
||||||
workspace.update(&mut cx, callback)
|
workspace.update(&mut cx, callback)
|
||||||
|
@ -2184,7 +2182,11 @@ impl Workspace {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_window_activation_changed(&mut self, active: bool, cx: &mut ViewContext<Self>) {
|
pub fn on_window_activation_changed(&mut self, active: bool, cx: &mut ViewContext<Self>) {
|
||||||
if !active {
|
if active {
|
||||||
|
cx.background()
|
||||||
|
.spawn(persistence::DB.update_timestamp(self.database_id()))
|
||||||
|
.detach();
|
||||||
|
} else {
|
||||||
for pane in &self.panes {
|
for pane in &self.panes {
|
||||||
pane.update(cx, |pane, cx| {
|
pane.update(cx, |pane, cx| {
|
||||||
if let Some(item) = pane.active_item() {
|
if let Some(item) = pane.active_item() {
|
||||||
|
@ -2621,6 +2623,10 @@ pub fn activate_workspace_for_project(
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn last_opened_workspace_paths() -> Option<WorkspaceLocation> {
|
||||||
|
DB.last_workspace().log_err().flatten()
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
pub fn open_paths(
|
pub fn open_paths(
|
||||||
abs_paths: &[PathBuf],
|
abs_paths: &[PathBuf],
|
||||||
|
@ -2655,7 +2661,7 @@ pub fn open_paths(
|
||||||
.contains(&false);
|
.contains(&false);
|
||||||
|
|
||||||
cx.update(|cx| {
|
cx.update(|cx| {
|
||||||
let task = Workspace::new_local(abs_paths, app_state.clone(), false, cx);
|
let task = Workspace::new_local(abs_paths, app_state.clone(), cx);
|
||||||
|
|
||||||
cx.spawn(|mut cx| async move {
|
cx.spawn(|mut cx| async move {
|
||||||
let (workspace, items) = task.await;
|
let (workspace, items) = task.await;
|
||||||
|
@ -2674,8 +2680,8 @@ pub fn open_paths(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn open_new(app_state: &Arc<AppState>, blank: bool, cx: &mut MutableAppContext) -> Task<()> {
|
pub fn open_new(app_state: &Arc<AppState>, cx: &mut MutableAppContext) -> Task<()> {
|
||||||
let task = Workspace::new_local(Vec::new(), app_state.clone(), blank, cx);
|
let task = Workspace::new_local(Vec::new(), app_state.clone(), cx);
|
||||||
cx.spawn(|mut cx| async move {
|
cx.spawn(|mut cx| async move {
|
||||||
let (workspace, opened_paths) = task.await;
|
let (workspace, opened_paths) = task.await;
|
||||||
|
|
||||||
|
|
|
@ -169,7 +169,7 @@ fn main() {
|
||||||
cx.platform().activate(true);
|
cx.platform().activate(true);
|
||||||
let paths = collect_path_args();
|
let paths = collect_path_args();
|
||||||
if paths.is_empty() {
|
if paths.is_empty() {
|
||||||
cx.dispatch_global_action(NewFile);
|
restore_or_create_workspace(cx);
|
||||||
} else {
|
} else {
|
||||||
cx.dispatch_global_action(OpenPaths { paths });
|
cx.dispatch_global_action(OpenPaths { paths });
|
||||||
}
|
}
|
||||||
|
@ -178,7 +178,7 @@ fn main() {
|
||||||
cx.spawn(|cx| handle_cli_connection(connection, app_state.clone(), cx))
|
cx.spawn(|cx| handle_cli_connection(connection, app_state.clone(), cx))
|
||||||
.detach();
|
.detach();
|
||||||
} else {
|
} else {
|
||||||
cx.dispatch_global_action(NewFile);
|
restore_or_create_workspace(cx);
|
||||||
}
|
}
|
||||||
cx.spawn(|cx| async move {
|
cx.spawn(|cx| async move {
|
||||||
while let Some(connection) = cli_connections_rx.next().await {
|
while let Some(connection) = cli_connections_rx.next().await {
|
||||||
|
@ -202,6 +202,16 @@ fn main() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn restore_or_create_workspace(cx: &mut gpui::MutableAppContext) {
|
||||||
|
if let Some(location) = workspace::last_opened_workspace_paths() {
|
||||||
|
cx.dispatch_global_action(OpenPaths {
|
||||||
|
paths: location.paths().as_ref().clone(),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
cx.dispatch_global_action(NewFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn init_paths() {
|
fn init_paths() {
|
||||||
std::fs::create_dir_all(&*util::paths::CONFIG_DIR).expect("could not create config path");
|
std::fs::create_dir_all(&*util::paths::CONFIG_DIR).expect("could not create config path");
|
||||||
std::fs::create_dir_all(&*util::paths::LANGUAGES_DIR).expect("could not create languages path");
|
std::fs::create_dir_all(&*util::paths::LANGUAGES_DIR).expect("could not create languages path");
|
||||||
|
|
|
@ -765,7 +765,7 @@ mod tests {
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_new_empty_workspace(cx: &mut TestAppContext) {
|
async fn test_new_empty_workspace(cx: &mut TestAppContext) {
|
||||||
let app_state = init(cx);
|
let app_state = init(cx);
|
||||||
cx.update(|cx| open_new(&app_state, true, cx)).await;
|
cx.update(|cx| open_new(&app_state, cx)).await;
|
||||||
|
|
||||||
let window_id = *cx.window_ids().first().unwrap();
|
let window_id = *cx.window_ids().first().unwrap();
|
||||||
let workspace = cx.root_view::<Workspace>(window_id).unwrap();
|
let workspace = cx.root_view::<Workspace>(window_id).unwrap();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue