mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-24 02:46:43 +00:00
Merge pull request #1959 from zed-industries/serializing-bug-fixes
Add check for if the user wants a blanks workspace when deserializing
This commit is contained in:
parent
4b612882a3
commit
b13a60735b
4 changed files with 52 additions and 22 deletions
|
@ -139,9 +139,7 @@ impl<V: View> DragAndDrop<V> {
|
|||
region_offset,
|
||||
region,
|
||||
}) => {
|
||||
if (dbg!(event.position) - (dbg!(region.origin() + region_offset))).length()
|
||||
> DEAD_ZONE
|
||||
{
|
||||
if (event.position - (region.origin() + region_offset)).length() > DEAD_ZONE {
|
||||
this.currently_dragged = Some(State::Dragging {
|
||||
window_id,
|
||||
region_offset,
|
||||
|
|
|
@ -8,7 +8,7 @@ use anyhow::{anyhow, bail, Context, Result};
|
|||
use db::{define_connection, query, sqlez::connection::Connection, sqlez_macros::sql};
|
||||
use gpui::Axis;
|
||||
|
||||
use util::{iife, unzip_option, ResultExt};
|
||||
use util::{ unzip_option, ResultExt};
|
||||
|
||||
use crate::dock::DockPosition;
|
||||
use crate::WorkspaceId;
|
||||
|
@ -96,20 +96,14 @@ impl WorkspaceDb {
|
|||
WorkspaceLocation,
|
||||
bool,
|
||||
DockPosition,
|
||||
) = iife!({
|
||||
if worktree_roots.len() == 0 {
|
||||
self.select_row(sql!(
|
||||
) =
|
||||
self.select_row_bound(sql!{
|
||||
SELECT workspace_id, workspace_location, left_sidebar_open, dock_visible, dock_anchor
|
||||
FROM workspaces
|
||||
ORDER BY timestamp DESC LIMIT 1))?()?
|
||||
} else {
|
||||
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")
|
||||
WHERE workspace_location = ?
|
||||
})
|
||||
.and_then(|mut prepared_statement| (prepared_statement)(&workspace_location))
|
||||
.context("No workspaces found")
|
||||
.warn_on_err()
|
||||
.flatten()?;
|
||||
|
||||
|
@ -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> {
|
||||
self.get_pane_group(workspace_id, None)?
|
||||
.into_iter()
|
||||
|
@ -371,6 +375,15 @@ impl WorkspaceDb {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
query!{
|
||||
pub async fn update_timestamp(workspace_id: WorkspaceId) -> Result<()> {
|
||||
UPDATE workspaces
|
||||
SET timestamp = CURRENT_TIMESTAMP
|
||||
WHERE workspace_id = ?
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -176,6 +176,7 @@ pub fn init(app_state: Arc<AppState>, cx: &mut MutableAppContext) {
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
cx.add_global_action({
|
||||
let app_state = Arc::downgrade(&app_state);
|
||||
move |_: &NewWindow, cx: &mut MutableAppContext| {
|
||||
|
@ -2181,7 +2182,11 @@ impl Workspace {
|
|||
}
|
||||
|
||||
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 {
|
||||
pane.update(cx, |pane, cx| {
|
||||
if let Some(item) = pane.active_item() {
|
||||
|
@ -2618,6 +2623,10 @@ pub fn activate_workspace_for_project(
|
|||
None
|
||||
}
|
||||
|
||||
pub fn last_opened_workspace_paths() -> Option<WorkspaceLocation> {
|
||||
DB.last_workspace().log_err().flatten()
|
||||
}
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub fn open_paths(
|
||||
abs_paths: &[PathBuf],
|
||||
|
|
|
@ -167,7 +167,7 @@ fn main() {
|
|||
cx.platform().activate(true);
|
||||
let paths = collect_path_args();
|
||||
if paths.is_empty() {
|
||||
cx.dispatch_global_action(NewFile);
|
||||
restore_or_create_workspace(cx);
|
||||
} else {
|
||||
cx.dispatch_global_action(OpenPaths { paths });
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ fn main() {
|
|||
cx.spawn(|cx| handle_cli_connection(connection, app_state.clone(), cx))
|
||||
.detach();
|
||||
} else {
|
||||
cx.dispatch_global_action(NewFile);
|
||||
restore_or_create_workspace(cx);
|
||||
}
|
||||
cx.spawn(|cx| async move {
|
||||
while let Some(connection) = cli_connections_rx.next().await {
|
||||
|
@ -200,6 +200,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() {
|
||||
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");
|
||||
|
|
Loading…
Reference in a new issue