wip
This commit is contained in:
parent
15799f7af6
commit
a581d0c5b8
8 changed files with 301 additions and 311 deletions
|
@ -2377,11 +2377,20 @@ impl MutableAppContext {
|
||||||
let window = this.cx.windows.get_mut(&window_id)?;
|
let window = this.cx.windows.get_mut(&window_id)?;
|
||||||
window.is_fullscreen = is_fullscreen;
|
window.is_fullscreen = is_fullscreen;
|
||||||
|
|
||||||
let mut observations = this.window_fullscreen_observations.clone();
|
let mut fullscreen_observations = this.window_fullscreen_observations.clone();
|
||||||
observations.emit(window_id, this, |callback, this| {
|
fullscreen_observations.emit(window_id, this, |callback, this| {
|
||||||
callback(is_fullscreen, this)
|
callback(is_fullscreen, this)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let bounds = if this.window_is_fullscreen(window_id) {
|
||||||
|
WindowBounds::Fullscreen
|
||||||
|
} else {
|
||||||
|
WindowBounds::Fixed(this.window_bounds(window_id))
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut bounds_observations = this.window_bounds_observations.clone();
|
||||||
|
bounds_observations.emit(window_id, this, |callback, this| callback(bounds, this));
|
||||||
|
|
||||||
Some(())
|
Some(())
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ use pathfinder_geometry::vector::{vec2f, Vector2F};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use sqlez::{
|
use sqlez::{
|
||||||
bindable::{Bind, Column, StaticRowComponent},
|
bindable::{Bind, Column, StaticColumnCount},
|
||||||
statement::Statement,
|
statement::Statement,
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
|
@ -932,7 +932,7 @@ impl ToJson for Axis {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StaticRowComponent for Axis {}
|
impl StaticColumnCount for Axis {}
|
||||||
impl Bind for Axis {
|
impl Bind for Axis {
|
||||||
fn bind(&self, statement: &Statement, start_index: i32) -> anyhow::Result<i32> {
|
fn bind(&self, statement: &Statement, start_index: i32) -> anyhow::Result<i32> {
|
||||||
match self {
|
match self {
|
||||||
|
|
|
@ -15,7 +15,7 @@ use schemars::{
|
||||||
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use sqlez::{
|
use sqlez::{
|
||||||
bindable::{Bind, Column, StaticRowComponent},
|
bindable::{Bind, Column, StaticColumnCount},
|
||||||
statement::Statement,
|
statement::Statement,
|
||||||
};
|
};
|
||||||
use std::{collections::HashMap, fmt::Write as _, num::NonZeroU32, str, sync::Arc};
|
use std::{collections::HashMap, fmt::Write as _, num::NonZeroU32, str, sync::Arc};
|
||||||
|
@ -253,7 +253,7 @@ pub enum DockAnchor {
|
||||||
Expanded,
|
Expanded,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StaticRowComponent for DockAnchor {}
|
impl StaticColumnCount for DockAnchor {}
|
||||||
impl Bind for DockAnchor {
|
impl Bind for DockAnchor {
|
||||||
fn bind(&self, statement: &Statement, start_index: i32) -> anyhow::Result<i32> {
|
fn bind(&self, statement: &Statement, start_index: i32) -> anyhow::Result<i32> {
|
||||||
match self {
|
match self {
|
||||||
|
|
|
@ -9,37 +9,21 @@ use anyhow::{Context, Result};
|
||||||
|
|
||||||
use crate::statement::{SqlType, Statement};
|
use crate::statement::{SqlType, Statement};
|
||||||
|
|
||||||
pub trait StaticRowComponent {
|
pub trait StaticColumnCount {
|
||||||
fn static_column_count() -> usize {
|
fn column_count() -> usize {
|
||||||
1
|
1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait RowComponent {
|
pub trait Bind {
|
||||||
fn column_count(&self) -> usize;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: StaticRowComponent> RowComponent for T {
|
|
||||||
fn column_count(&self) -> usize {
|
|
||||||
T::static_column_count()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: StaticRowComponent> StaticRowComponent for &T {
|
|
||||||
fn static_column_count() -> usize {
|
|
||||||
T::static_column_count()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait Bind: RowComponent {
|
|
||||||
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32>;
|
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Column: Sized + RowComponent {
|
pub trait Column: Sized {
|
||||||
fn column(statement: &mut Statement, start_index: i32) -> Result<(Self, i32)>;
|
fn column(statement: &mut Statement, start_index: i32) -> Result<(Self, i32)>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StaticRowComponent for bool {}
|
impl StaticColumnCount for bool {}
|
||||||
impl Bind for bool {
|
impl Bind for bool {
|
||||||
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
||||||
statement
|
statement
|
||||||
|
@ -56,7 +40,7 @@ impl Column for bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StaticRowComponent for &[u8] {}
|
impl StaticColumnCount for &[u8] {}
|
||||||
impl Bind for &[u8] {
|
impl Bind for &[u8] {
|
||||||
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
||||||
statement
|
statement
|
||||||
|
@ -66,7 +50,7 @@ impl Bind for &[u8] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const C: usize> StaticRowComponent for &[u8; C] {}
|
impl<const C: usize> StaticColumnCount for &[u8; C] {}
|
||||||
impl<const C: usize> Bind for &[u8; C] {
|
impl<const C: usize> Bind for &[u8; C] {
|
||||||
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
||||||
statement
|
statement
|
||||||
|
@ -76,7 +60,7 @@ impl<const C: usize> Bind for &[u8; C] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StaticRowComponent for Vec<u8> {}
|
impl StaticColumnCount for Vec<u8> {}
|
||||||
impl Bind for Vec<u8> {
|
impl Bind for Vec<u8> {
|
||||||
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
||||||
statement
|
statement
|
||||||
|
@ -96,7 +80,7 @@ impl Column for Vec<u8> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StaticRowComponent for f64 {}
|
impl StaticColumnCount for f64 {}
|
||||||
impl Bind for f64 {
|
impl Bind for f64 {
|
||||||
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
||||||
statement
|
statement
|
||||||
|
@ -116,7 +100,7 @@ impl Column for f64 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StaticRowComponent for f32 {}
|
impl StaticColumnCount for f32 {}
|
||||||
impl Bind for f32 {
|
impl Bind for f32 {
|
||||||
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
||||||
statement
|
statement
|
||||||
|
@ -137,7 +121,7 @@ impl Column for f32 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StaticRowComponent for i32 {}
|
impl StaticColumnCount for i32 {}
|
||||||
impl Bind for i32 {
|
impl Bind for i32 {
|
||||||
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
||||||
statement
|
statement
|
||||||
|
@ -155,7 +139,7 @@ impl Column for i32 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StaticRowComponent for i64 {}
|
impl StaticColumnCount for i64 {}
|
||||||
impl Bind for i64 {
|
impl Bind for i64 {
|
||||||
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
||||||
statement
|
statement
|
||||||
|
@ -172,7 +156,7 @@ impl Column for i64 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StaticRowComponent for u32 {}
|
impl StaticColumnCount for u32 {}
|
||||||
impl Bind for u32 {
|
impl Bind for u32 {
|
||||||
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
||||||
(*self as i64)
|
(*self as i64)
|
||||||
|
@ -188,7 +172,7 @@ impl Column for u32 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StaticRowComponent for usize {}
|
impl StaticColumnCount for usize {}
|
||||||
impl Bind for usize {
|
impl Bind for usize {
|
||||||
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
||||||
(*self as i64)
|
(*self as i64)
|
||||||
|
@ -204,7 +188,7 @@ impl Column for usize {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StaticRowComponent for &str {}
|
impl StaticColumnCount for &str {}
|
||||||
impl Bind for &str {
|
impl Bind for &str {
|
||||||
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
||||||
statement.bind_text(start_index, self)?;
|
statement.bind_text(start_index, self)?;
|
||||||
|
@ -212,7 +196,7 @@ impl Bind for &str {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StaticRowComponent for Arc<str> {}
|
impl StaticColumnCount for Arc<str> {}
|
||||||
impl Bind for Arc<str> {
|
impl Bind for Arc<str> {
|
||||||
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
||||||
statement.bind_text(start_index, self.as_ref())?;
|
statement.bind_text(start_index, self.as_ref())?;
|
||||||
|
@ -220,7 +204,7 @@ impl Bind for Arc<str> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StaticRowComponent for String {}
|
impl StaticColumnCount for String {}
|
||||||
impl Bind for String {
|
impl Bind for String {
|
||||||
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
||||||
statement.bind_text(start_index, self)?;
|
statement.bind_text(start_index, self)?;
|
||||||
|
@ -242,17 +226,18 @@ impl Column for String {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: StaticRowComponent> StaticRowComponent for Option<T> {
|
impl<T: StaticColumnCount> StaticColumnCount for Option<T> {
|
||||||
fn static_column_count() -> usize {
|
fn column_count() -> usize {
|
||||||
T::static_column_count()
|
T::column_count()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<T: Bind + StaticRowComponent> Bind for Option<T> {
|
impl<T: Bind + StaticColumnCount> Bind for Option<T> {
|
||||||
fn bind(&self, statement: &Statement, mut start_index: i32) -> Result<i32> {
|
fn bind(&self, statement: &Statement, mut start_index: i32) -> Result<i32> {
|
||||||
if let Some(this) = self {
|
if let Some(this) = self {
|
||||||
this.bind(statement, start_index)
|
this.bind(statement, start_index)
|
||||||
} else {
|
} else {
|
||||||
for _ in 0..T::static_column_count() {
|
for i in 0..T::column_count() {
|
||||||
|
dbg!(i);
|
||||||
statement.bind_null(start_index)?;
|
statement.bind_null(start_index)?;
|
||||||
start_index += 1;
|
start_index += 1;
|
||||||
}
|
}
|
||||||
|
@ -261,22 +246,22 @@ impl<T: Bind + StaticRowComponent> Bind for Option<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Column + StaticRowComponent> Column for Option<T> {
|
impl<T: Column + StaticColumnCount> Column for Option<T> {
|
||||||
fn column(statement: &mut Statement, start_index: i32) -> Result<(Self, i32)> {
|
fn column(statement: &mut Statement, start_index: i32) -> Result<(Self, i32)> {
|
||||||
if let SqlType::Null = statement.column_type(start_index)? {
|
if let SqlType::Null = statement.column_type(start_index)? {
|
||||||
Ok((None, start_index + T::static_column_count() as i32))
|
Ok((None, start_index + T::column_count() as i32))
|
||||||
} else {
|
} else {
|
||||||
T::column(statement, start_index).map(|(result, next_index)| (Some(result), next_index))
|
T::column(statement, start_index).map(|(result, next_index)| (Some(result), next_index))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: StaticRowComponent, const COUNT: usize> StaticRowComponent for [T; COUNT] {
|
impl<T: StaticColumnCount, const COUNT: usize> StaticColumnCount for [T; COUNT] {
|
||||||
fn static_column_count() -> usize {
|
fn column_count() -> usize {
|
||||||
T::static_column_count() * COUNT
|
T::column_count() * COUNT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<T: Bind + StaticRowComponent, const COUNT: usize> Bind for [T; COUNT] {
|
impl<T: Bind, const COUNT: usize> Bind for [T; COUNT] {
|
||||||
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
||||||
let mut current_index = start_index;
|
let mut current_index = start_index;
|
||||||
for binding in self {
|
for binding in self {
|
||||||
|
@ -287,7 +272,7 @@ impl<T: Bind + StaticRowComponent, const COUNT: usize> Bind for [T; COUNT] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Column + StaticRowComponent + Default + Copy, const COUNT: usize> Column for [T; COUNT] {
|
impl<T: Column + Default + Copy, const COUNT: usize> Column for [T; COUNT] {
|
||||||
fn column(statement: &mut Statement, start_index: i32) -> Result<(Self, i32)> {
|
fn column(statement: &mut Statement, start_index: i32) -> Result<(Self, i32)> {
|
||||||
let mut array = [Default::default(); COUNT];
|
let mut array = [Default::default(); COUNT];
|
||||||
let mut current_index = start_index;
|
let mut current_index = start_index;
|
||||||
|
@ -298,21 +283,21 @@ impl<T: Column + StaticRowComponent + Default + Copy, const COUNT: usize> Column
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StaticRowComponent for &Path {}
|
impl StaticColumnCount for &Path {}
|
||||||
impl Bind for &Path {
|
impl Bind for &Path {
|
||||||
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
||||||
self.as_os_str().as_bytes().bind(statement, start_index)
|
self.as_os_str().as_bytes().bind(statement, start_index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StaticRowComponent for Arc<Path> {}
|
impl StaticColumnCount for Arc<Path> {}
|
||||||
impl Bind for Arc<Path> {
|
impl Bind for Arc<Path> {
|
||||||
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
||||||
self.as_ref().bind(statement, start_index)
|
self.as_ref().bind(statement, start_index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StaticRowComponent for PathBuf {}
|
impl StaticColumnCount for PathBuf {}
|
||||||
impl Bind for PathBuf {
|
impl Bind for PathBuf {
|
||||||
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
||||||
(self.as_ref() as &Path).bind(statement, start_index)
|
(self.as_ref() as &Path).bind(statement, start_index)
|
||||||
|
@ -330,8 +315,8 @@ impl Column for PathBuf {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StaticRowComponent for () {
|
impl StaticColumnCount for () {
|
||||||
fn static_column_count() -> usize {
|
fn column_count() -> usize {
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -350,11 +335,10 @@ impl Column for () {
|
||||||
|
|
||||||
macro_rules! impl_tuple_row_traits {
|
macro_rules! impl_tuple_row_traits {
|
||||||
( $($local:ident: $type:ident),+ ) => {
|
( $($local:ident: $type:ident),+ ) => {
|
||||||
impl<$($type: RowComponent),+> RowComponent for ($($type,)+) {
|
impl<$($type: StaticColumnCount),+> StaticColumnCount for ($($type,)+) {
|
||||||
fn column_count(&self) -> usize {
|
fn column_count() -> usize {
|
||||||
let ($($local,)+) = self;
|
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
$(count += $local.column_count();)+
|
$(count += $type::column_count();)+
|
||||||
count
|
count
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -238,15 +238,11 @@ impl<'a> Statement<'a> {
|
||||||
|
|
||||||
pub fn bind<T: Bind>(&self, value: T, index: i32) -> Result<i32> {
|
pub fn bind<T: Bind>(&self, value: T, index: i32) -> Result<i32> {
|
||||||
debug_assert!(index > 0);
|
debug_assert!(index > 0);
|
||||||
let after = value.bind(self, index)?;
|
Ok(value.bind(self, index)?)
|
||||||
debug_assert_eq!((after - index) as usize, value.column_count());
|
|
||||||
Ok(after)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn column<T: Column>(&mut self) -> Result<T> {
|
pub fn column<T: Column>(&mut self) -> Result<T> {
|
||||||
let (result, after) = T::column(self, 0)?;
|
Ok(T::column(self, 0)?.0)
|
||||||
debug_assert_eq!(T::column_count(&result), after as usize);
|
|
||||||
Ok(result)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn column_type(&mut self, index: i32) -> Result<SqlType> {
|
pub fn column_type(&mut self, index: i32) -> Result<SqlType> {
|
||||||
|
@ -263,9 +259,7 @@ impl<'a> Statement<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_bindings(&mut self, bindings: impl Bind) -> Result<&mut Self> {
|
pub fn with_bindings(&mut self, bindings: impl Bind) -> Result<&mut Self> {
|
||||||
let column_count = bindings.column_count();
|
self.bind(bindings, 1)?;
|
||||||
let after = self.bind(bindings, 1)?;
|
|
||||||
debug_assert_eq!((after - 1) as usize, column_count);
|
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,70 +65,70 @@ define_connection! {
|
||||||
// active: bool, // Indicates if this item is the active one in the pane
|
// active: bool, // Indicates if this item is the active one in the pane
|
||||||
// )
|
// )
|
||||||
pub static ref DB: WorkspaceDb<()> =
|
pub static ref DB: WorkspaceDb<()> =
|
||||||
&[sql!(
|
&[sql!(
|
||||||
CREATE TABLE workspaces(
|
CREATE TABLE workspaces(
|
||||||
workspace_id INTEGER PRIMARY KEY,
|
workspace_id INTEGER PRIMARY KEY,
|
||||||
workspace_location BLOB UNIQUE,
|
workspace_location BLOB UNIQUE,
|
||||||
dock_visible INTEGER, // Boolean
|
dock_visible INTEGER, // Boolean
|
||||||
dock_anchor TEXT, // Enum: 'Bottom' / 'Right' / 'Expanded'
|
dock_anchor TEXT, // Enum: 'Bottom' / 'Right' / 'Expanded'
|
||||||
dock_pane INTEGER, // NULL indicates that we don't have a dock pane yet
|
dock_pane INTEGER, // NULL indicates that we don't have a dock pane yet
|
||||||
left_sidebar_open INTEGER, //Boolean
|
left_sidebar_open INTEGER, //Boolean
|
||||||
timestamp TEXT DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
timestamp TEXT DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||||
FOREIGN KEY(dock_pane) REFERENCES panes(pane_id)
|
FOREIGN KEY(dock_pane) REFERENCES panes(pane_id)
|
||||||
) STRICT;
|
) STRICT;
|
||||||
|
|
||||||
CREATE TABLE pane_groups(
|
CREATE TABLE pane_groups(
|
||||||
group_id INTEGER PRIMARY KEY,
|
group_id INTEGER PRIMARY KEY,
|
||||||
workspace_id INTEGER NOT NULL,
|
workspace_id INTEGER NOT NULL,
|
||||||
parent_group_id INTEGER, // NULL indicates that this is a root node
|
parent_group_id INTEGER, // NULL indicates that this is a root node
|
||||||
position INTEGER, // NULL indicates that this is a root node
|
position INTEGER, // NULL indicates that this is a root node
|
||||||
axis TEXT NOT NULL, // Enum: 'Vertical' / 'Horizontal'
|
axis TEXT NOT NULL, // Enum: 'Vertical' / 'Horizontal'
|
||||||
FOREIGN KEY(workspace_id) REFERENCES workspaces(workspace_id)
|
FOREIGN KEY(workspace_id) REFERENCES workspaces(workspace_id)
|
||||||
ON DELETE CASCADE
|
ON DELETE CASCADE
|
||||||
ON UPDATE CASCADE,
|
ON UPDATE CASCADE,
|
||||||
FOREIGN KEY(parent_group_id) REFERENCES pane_groups(group_id) ON DELETE CASCADE
|
FOREIGN KEY(parent_group_id) REFERENCES pane_groups(group_id) ON DELETE CASCADE
|
||||||
) STRICT;
|
) STRICT;
|
||||||
|
|
||||||
CREATE TABLE panes(
|
CREATE TABLE panes(
|
||||||
pane_id INTEGER PRIMARY KEY,
|
pane_id INTEGER PRIMARY KEY,
|
||||||
workspace_id INTEGER NOT NULL,
|
workspace_id INTEGER NOT NULL,
|
||||||
active INTEGER NOT NULL, // Boolean
|
active INTEGER NOT NULL, // Boolean
|
||||||
FOREIGN KEY(workspace_id) REFERENCES workspaces(workspace_id)
|
FOREIGN KEY(workspace_id) REFERENCES workspaces(workspace_id)
|
||||||
ON DELETE CASCADE
|
ON DELETE CASCADE
|
||||||
ON UPDATE CASCADE
|
ON UPDATE CASCADE
|
||||||
) STRICT;
|
) STRICT;
|
||||||
|
|
||||||
CREATE TABLE center_panes(
|
CREATE TABLE center_panes(
|
||||||
pane_id INTEGER PRIMARY KEY,
|
pane_id INTEGER PRIMARY KEY,
|
||||||
parent_group_id INTEGER, // NULL means that this is a root pane
|
parent_group_id INTEGER, // NULL means that this is a root pane
|
||||||
position INTEGER, // NULL means that this is a root pane
|
position INTEGER, // NULL means that this is a root pane
|
||||||
FOREIGN KEY(pane_id) REFERENCES panes(pane_id)
|
FOREIGN KEY(pane_id) REFERENCES panes(pane_id)
|
||||||
ON DELETE CASCADE,
|
ON DELETE CASCADE,
|
||||||
FOREIGN KEY(parent_group_id) REFERENCES pane_groups(group_id) ON DELETE CASCADE
|
FOREIGN KEY(parent_group_id) REFERENCES pane_groups(group_id) ON DELETE CASCADE
|
||||||
) STRICT;
|
) STRICT;
|
||||||
|
|
||||||
CREATE TABLE items(
|
CREATE TABLE items(
|
||||||
item_id INTEGER NOT NULL, // This is the item's view id, so this is not unique
|
item_id INTEGER NOT NULL, // This is the item's view id, so this is not unique
|
||||||
workspace_id INTEGER NOT NULL,
|
workspace_id INTEGER NOT NULL,
|
||||||
pane_id INTEGER NOT NULL,
|
pane_id INTEGER NOT NULL,
|
||||||
kind TEXT NOT NULL,
|
kind TEXT NOT NULL,
|
||||||
position INTEGER NOT NULL,
|
position INTEGER NOT NULL,
|
||||||
active INTEGER NOT NULL,
|
active INTEGER NOT NULL,
|
||||||
FOREIGN KEY(workspace_id) REFERENCES workspaces(workspace_id)
|
FOREIGN KEY(workspace_id) REFERENCES workspaces(workspace_id)
|
||||||
ON DELETE CASCADE
|
ON DELETE CASCADE
|
||||||
ON UPDATE CASCADE,
|
ON UPDATE CASCADE,
|
||||||
FOREIGN KEY(pane_id) REFERENCES panes(pane_id)
|
FOREIGN KEY(pane_id) REFERENCES panes(pane_id)
|
||||||
ON DELETE CASCADE,
|
ON DELETE CASCADE,
|
||||||
PRIMARY KEY(item_id, workspace_id)
|
PRIMARY KEY(item_id, workspace_id)
|
||||||
) STRICT;
|
) STRICT;
|
||||||
),
|
),
|
||||||
sql!(
|
sql!(
|
||||||
ALTER TABLE workspaces ADD COLUMN fullscreen INTEGER; // Boolean
|
ALTER TABLE workspaces ADD COLUMN fullscreen INTEGER; // Boolean
|
||||||
ALTER TABLE workspaces ADD COLUMN window_x REAL; // Null means set to whatever
|
ALTER TABLE workspaces ADD COLUMN window_x REAL; // Null means set to whatever
|
||||||
ALTER TABLE workspaces ADD COLUMN window_y REAL; // Null means set to whatever
|
ALTER TABLE workspaces ADD COLUMN window_y REAL; // Null means set to whatever
|
||||||
ALTER TABLE workspaces ADD COLUMN window_width REAL; // Null means set to whatever
|
ALTER TABLE workspaces ADD COLUMN window_width REAL; // Null means set to whatever
|
||||||
ALTER TABLE workspaces ADD COLUMN window_height REAL; // Null means set to whatever
|
ALTER TABLE workspaces ADD COLUMN window_height REAL; // Null means set to whatever
|
||||||
)];
|
)];
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WorkspaceDb {
|
impl WorkspaceDb {
|
||||||
|
@ -140,16 +140,16 @@ impl WorkspaceDb {
|
||||||
worktree_roots: &[P],
|
worktree_roots: &[P],
|
||||||
) -> Option<SerializedWorkspace> {
|
) -> Option<SerializedWorkspace> {
|
||||||
let workspace_location: WorkspaceLocation = worktree_roots.into();
|
let workspace_location: WorkspaceLocation = worktree_roots.into();
|
||||||
|
|
||||||
// Note that we re-assign the workspace_id here in case it's empty
|
// Note that we re-assign the workspace_id here in case it's empty
|
||||||
// and we've grabbed the most recent workspace
|
// and we've grabbed the most recent workspace
|
||||||
let (workspace_id, workspace_location, left_sidebar_open, dock_position, fullscreen, window_x, window_y, window_width, window_height): (
|
let (workspace_id, workspace_location, left_sidebar_open, dock_position, fullscreen, window_region): (
|
||||||
WorkspaceId,
|
WorkspaceId,
|
||||||
WorkspaceLocation,
|
WorkspaceLocation,
|
||||||
bool,
|
bool,
|
||||||
DockPosition,
|
DockPosition,
|
||||||
bool,
|
bool,
|
||||||
f32, f32, f32, f32
|
Option<(f32, f32, f32, f32)>
|
||||||
) = self
|
) = self
|
||||||
.select_row_bound(sql! {
|
.select_row_bound(sql! {
|
||||||
SELECT
|
SELECT
|
||||||
|
@ -170,7 +170,7 @@ impl WorkspaceDb {
|
||||||
.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,
|
||||||
location: workspace_location.clone(),
|
location: workspace_location.clone(),
|
||||||
|
@ -185,13 +185,13 @@ impl WorkspaceDb {
|
||||||
dock_position,
|
dock_position,
|
||||||
left_sidebar_open,
|
left_sidebar_open,
|
||||||
fullscreen,
|
fullscreen,
|
||||||
bounds: Some(RectF::new(
|
bounds: dbg!(window_region).map(|(x, y, width, height)| RectF::new(
|
||||||
Vector2F::new(window_x, window_y),
|
Vector2F::new(x, y),
|
||||||
Vector2F::new(window_width, window_height)
|
Vector2F::new(width, height)
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Saves a workspace using the worktree roots. Will garbage collect any workspaces
|
/// Saves a workspace using the worktree roots. Will garbage collect any workspaces
|
||||||
/// that used this workspace previously
|
/// that used this workspace previously
|
||||||
pub async fn save_workspace(&self, workspace: SerializedWorkspace) {
|
pub async fn save_workspace(&self, workspace: SerializedWorkspace) {
|
||||||
|
@ -203,30 +203,30 @@ impl WorkspaceDb {
|
||||||
DELETE FROM pane_groups WHERE workspace_id = ?1;
|
DELETE FROM pane_groups WHERE workspace_id = ?1;
|
||||||
DELETE FROM panes WHERE workspace_id = ?1;))?(workspace.id)
|
DELETE FROM panes WHERE workspace_id = ?1;))?(workspace.id)
|
||||||
.expect("Clearing old panes");
|
.expect("Clearing old panes");
|
||||||
|
|
||||||
conn.exec_bound(sql!(
|
conn.exec_bound(sql!(
|
||||||
DELETE FROM workspaces WHERE workspace_location = ? AND workspace_id != ?
|
DELETE FROM workspaces WHERE workspace_location = ? AND workspace_id != ?
|
||||||
))?((&workspace.location, workspace.id.clone()))
|
))?((&workspace.location, workspace.id.clone()))
|
||||||
.context("clearing out old locations")?;
|
.context("clearing out old locations")?;
|
||||||
|
|
||||||
// Upsert
|
// Upsert
|
||||||
conn.exec_bound(sql!(
|
conn.exec_bound(sql!(
|
||||||
INSERT INTO workspaces(
|
INSERT INTO workspaces(
|
||||||
workspace_id,
|
workspace_id,
|
||||||
workspace_location,
|
workspace_location,
|
||||||
left_sidebar_open,
|
left_sidebar_open,
|
||||||
dock_visible,
|
dock_visible,
|
||||||
dock_anchor,
|
dock_anchor,
|
||||||
timestamp
|
timestamp
|
||||||
)
|
)
|
||||||
VALUES (?1, ?2, ?3, ?4, ?5, CURRENT_TIMESTAMP)
|
VALUES (?1, ?2, ?3, ?4, ?5, CURRENT_TIMESTAMP)
|
||||||
ON CONFLICT DO
|
ON CONFLICT DO
|
||||||
UPDATE SET
|
UPDATE SET
|
||||||
workspace_location = ?2,
|
workspace_location = ?2,
|
||||||
left_sidebar_open = ?3,
|
left_sidebar_open = ?3,
|
||||||
dock_visible = ?4,
|
dock_visible = ?4,
|
||||||
dock_anchor = ?5,
|
dock_anchor = ?5,
|
||||||
timestamp = CURRENT_TIMESTAMP
|
timestamp = CURRENT_TIMESTAMP
|
||||||
))?((
|
))?((
|
||||||
workspace.id,
|
workspace.id,
|
||||||
&workspace.location,
|
&workspace.location,
|
||||||
|
@ -234,35 +234,35 @@ impl WorkspaceDb {
|
||||||
workspace.dock_position,
|
workspace.dock_position,
|
||||||
))
|
))
|
||||||
.context("Updating workspace")?;
|
.context("Updating workspace")?;
|
||||||
|
|
||||||
// Save center pane group and dock pane
|
// Save center pane group and dock pane
|
||||||
Self::save_pane_group(conn, workspace.id, &workspace.center_group, None)
|
Self::save_pane_group(conn, workspace.id, &workspace.center_group, None)
|
||||||
.context("save pane group in save workspace")?;
|
.context("save pane group in save workspace")?;
|
||||||
|
|
||||||
let dock_id = Self::save_pane(conn, workspace.id, &workspace.dock_pane, None, true)
|
let dock_id = Self::save_pane(conn, workspace.id, &workspace.dock_pane, None, true)
|
||||||
.context("save pane in save workspace")?;
|
.context("save pane in save workspace")?;
|
||||||
|
|
||||||
// Complete workspace initialization
|
// Complete workspace initialization
|
||||||
conn.exec_bound(sql!(
|
conn.exec_bound(sql!(
|
||||||
UPDATE workspaces
|
UPDATE workspaces
|
||||||
SET dock_pane = ?
|
SET dock_pane = ?
|
||||||
WHERE workspace_id = ?
|
WHERE workspace_id = ?
|
||||||
))?((dock_id, workspace.id))
|
))?((dock_id, workspace.id))
|
||||||
.context("Finishing initialization with dock pane")?;
|
.context("Finishing initialization with dock pane")?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
.log_err();
|
.log_err();
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
query! {
|
query! {
|
||||||
pub async fn next_id() -> Result<WorkspaceId> {
|
pub async fn next_id() -> Result<WorkspaceId> {
|
||||||
INSERT INTO workspaces DEFAULT VALUES RETURNING workspace_id
|
INSERT INTO workspaces DEFAULT VALUES RETURNING workspace_id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
query! {
|
query! {
|
||||||
fn recent_workspaces() -> Result<Vec<(WorkspaceId, WorkspaceLocation)>> {
|
fn recent_workspaces() -> Result<Vec<(WorkspaceId, WorkspaceLocation)>> {
|
||||||
SELECT workspace_id, workspace_location
|
SELECT workspace_id, workspace_location
|
||||||
|
@ -271,14 +271,14 @@ impl WorkspaceDb {
|
||||||
ORDER BY timestamp DESC
|
ORDER BY timestamp DESC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
query! {
|
query! {
|
||||||
async fn delete_stale_workspace(id: WorkspaceId) -> Result<()> {
|
async fn delete_stale_workspace(id: WorkspaceId) -> Result<()> {
|
||||||
DELETE FROM workspaces
|
DELETE FROM workspaces
|
||||||
WHERE workspace_id IS ?
|
WHERE workspace_id IS ?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the recent locations which are still valid on disk and deletes ones which no longer
|
// Returns the recent locations which are still valid on disk and deletes ones which no longer
|
||||||
// exist.
|
// exist.
|
||||||
pub async fn recent_workspaces_on_disk(&self) -> Result<Vec<(WorkspaceId, WorkspaceLocation)>> {
|
pub async fn recent_workspaces_on_disk(&self) -> Result<Vec<(WorkspaceId, WorkspaceLocation)>> {
|
||||||
|
@ -286,18 +286,18 @@ impl WorkspaceDb {
|
||||||
let mut delete_tasks = Vec::new();
|
let mut delete_tasks = Vec::new();
|
||||||
for (id, location) in self.recent_workspaces()? {
|
for (id, location) in self.recent_workspaces()? {
|
||||||
if location.paths().iter().all(|path| path.exists())
|
if location.paths().iter().all(|path| path.exists())
|
||||||
&& location.paths().iter().any(|path| path.is_dir())
|
&& location.paths().iter().any(|path| path.is_dir())
|
||||||
{
|
{
|
||||||
result.push((id, location));
|
result.push((id, location));
|
||||||
} else {
|
} else {
|
||||||
delete_tasks.push(self.delete_stale_workspace(id));
|
delete_tasks.push(self.delete_stale_workspace(id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
futures::future::join_all(delete_tasks).await;
|
futures::future::join_all(delete_tasks).await;
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn last_workspace(&self) -> Result<Option<WorkspaceLocation>> {
|
pub async fn last_workspace(&self) -> Result<Option<WorkspaceLocation>> {
|
||||||
Ok(self
|
Ok(self
|
||||||
.recent_workspaces_on_disk()
|
.recent_workspaces_on_disk()
|
||||||
|
@ -306,7 +306,7 @@ impl WorkspaceDb {
|
||||||
.next()
|
.next()
|
||||||
.map(|(_, location)| location))
|
.map(|(_, location)| location))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_center_pane_group(&self, workspace_id: WorkspaceId) -> Result<SerializedPaneGroup> {
|
fn get_center_pane_group(&self, workspace_id: WorkspaceId) -> Result<SerializedPaneGroup> {
|
||||||
Ok(self
|
Ok(self
|
||||||
.get_pane_group(workspace_id, None)?
|
.get_pane_group(workspace_id, None)?
|
||||||
|
@ -319,7 +319,7 @@ impl WorkspaceDb {
|
||||||
})
|
})
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_pane_group(
|
fn get_pane_group(
|
||||||
&self,
|
&self,
|
||||||
workspace_id: WorkspaceId,
|
workspace_id: WorkspaceId,
|
||||||
|
@ -330,27 +330,27 @@ impl WorkspaceDb {
|
||||||
self.select_bound::<GroupKey, GroupOrPane>(sql!(
|
self.select_bound::<GroupKey, GroupOrPane>(sql!(
|
||||||
SELECT group_id, axis, pane_id, active
|
SELECT group_id, axis, pane_id, active
|
||||||
FROM (SELECT
|
FROM (SELECT
|
||||||
group_id,
|
group_id,
|
||||||
axis,
|
axis,
|
||||||
NULL as pane_id,
|
NULL as pane_id,
|
||||||
NULL as active,
|
NULL as active,
|
||||||
position,
|
position,
|
||||||
parent_group_id,
|
parent_group_id,
|
||||||
workspace_id
|
workspace_id
|
||||||
FROM pane_groups
|
FROM pane_groups
|
||||||
UNION
|
UNION
|
||||||
SELECT
|
SELECT
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
center_panes.pane_id,
|
center_panes.pane_id,
|
||||||
panes.active as active,
|
panes.active as active,
|
||||||
position,
|
position,
|
||||||
parent_group_id,
|
parent_group_id,
|
||||||
panes.workspace_id as workspace_id
|
panes.workspace_id as workspace_id
|
||||||
FROM center_panes
|
FROM center_panes
|
||||||
JOIN panes ON center_panes.pane_id = panes.pane_id)
|
JOIN panes ON center_panes.pane_id = panes.pane_id)
|
||||||
WHERE parent_group_id IS ? AND workspace_id = ?
|
WHERE parent_group_id IS ? AND workspace_id = ?
|
||||||
ORDER BY position
|
ORDER BY position
|
||||||
))?((group_id, workspace_id))?
|
))?((group_id, workspace_id))?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(group_id, axis, pane_id, active)| {
|
.map(|(group_id, axis, pane_id, active)| {
|
||||||
|
@ -376,7 +376,7 @@ impl WorkspaceDb {
|
||||||
})
|
})
|
||||||
.collect::<Result<_>>()
|
.collect::<Result<_>>()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save_pane_group(
|
fn save_pane_group(
|
||||||
conn: &Connection,
|
conn: &Connection,
|
||||||
workspace_id: WorkspaceId,
|
workspace_id: WorkspaceId,
|
||||||
|
@ -386,18 +386,18 @@ impl WorkspaceDb {
|
||||||
match pane_group {
|
match pane_group {
|
||||||
SerializedPaneGroup::Group { axis, children } => {
|
SerializedPaneGroup::Group { axis, children } => {
|
||||||
let (parent_id, position) = unzip_option(parent);
|
let (parent_id, position) = unzip_option(parent);
|
||||||
|
|
||||||
let group_id = conn.select_row_bound::<_, i64>(sql!(
|
let group_id = conn.select_row_bound::<_, i64>(sql!(
|
||||||
INSERT INTO pane_groups(workspace_id, parent_group_id, position, axis)
|
INSERT INTO pane_groups(workspace_id, parent_group_id, position, axis)
|
||||||
VALUES (?, ?, ?, ?)
|
VALUES (?, ?, ?, ?)
|
||||||
RETURNING group_id
|
RETURNING group_id
|
||||||
))?((workspace_id, parent_id, position, *axis))?
|
))?((workspace_id, parent_id, position, *axis))?
|
||||||
.ok_or_else(|| anyhow!("Couldn't retrieve group_id from inserted pane_group"))?;
|
.ok_or_else(|| anyhow!("Couldn't retrieve group_id from inserted pane_group"))?;
|
||||||
|
|
||||||
for (position, group) in children.iter().enumerate() {
|
for (position, group) in children.iter().enumerate() {
|
||||||
Self::save_pane_group(conn, workspace_id, group, Some((group_id, position)))?
|
Self::save_pane_group(conn, workspace_id, group, Some((group_id, position)))?
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
SerializedPaneGroup::Pane(pane) => {
|
SerializedPaneGroup::Pane(pane) => {
|
||||||
|
@ -406,7 +406,7 @@ impl WorkspaceDb {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_dock_pane(&self, workspace_id: WorkspaceId) -> Result<SerializedPane> {
|
fn get_dock_pane(&self, workspace_id: WorkspaceId) -> Result<SerializedPane> {
|
||||||
let (pane_id, active) = self.select_row_bound(sql!(
|
let (pane_id, active) = self.select_row_bound(sql!(
|
||||||
SELECT pane_id, active
|
SELECT pane_id, active
|
||||||
|
@ -414,13 +414,13 @@ impl WorkspaceDb {
|
||||||
WHERE pane_id = (SELECT dock_pane FROM workspaces WHERE workspace_id = ?)
|
WHERE pane_id = (SELECT dock_pane FROM workspaces WHERE workspace_id = ?)
|
||||||
))?(workspace_id)?
|
))?(workspace_id)?
|
||||||
.context("No dock pane for workspace")?;
|
.context("No dock pane for workspace")?;
|
||||||
|
|
||||||
Ok(SerializedPane::new(
|
Ok(SerializedPane::new(
|
||||||
self.get_items(pane_id).context("Reading items")?,
|
self.get_items(pane_id).context("Reading items")?,
|
||||||
active,
|
active,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save_pane(
|
fn save_pane(
|
||||||
conn: &Connection,
|
conn: &Connection,
|
||||||
workspace_id: WorkspaceId,
|
workspace_id: WorkspaceId,
|
||||||
|
@ -434,7 +434,7 @@ impl WorkspaceDb {
|
||||||
RETURNING pane_id
|
RETURNING pane_id
|
||||||
))?((workspace_id, pane.active))?
|
))?((workspace_id, pane.active))?
|
||||||
.ok_or_else(|| anyhow!("Could not retrieve inserted pane_id"))?;
|
.ok_or_else(|| anyhow!("Could not retrieve inserted pane_id"))?;
|
||||||
|
|
||||||
if !dock {
|
if !dock {
|
||||||
let (parent_id, order) = unzip_option(parent);
|
let (parent_id, order) = unzip_option(parent);
|
||||||
conn.exec_bound(sql!(
|
conn.exec_bound(sql!(
|
||||||
|
@ -442,20 +442,20 @@ impl WorkspaceDb {
|
||||||
VALUES (?, ?, ?)
|
VALUES (?, ?, ?)
|
||||||
))?((pane_id, parent_id, order))?;
|
))?((pane_id, parent_id, order))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Self::save_items(conn, workspace_id, pane_id, &pane.children).context("Saving items")?;
|
Self::save_items(conn, workspace_id, pane_id, &pane.children).context("Saving items")?;
|
||||||
|
|
||||||
Ok(pane_id)
|
Ok(pane_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_items(&self, pane_id: PaneId) -> Result<Vec<SerializedItem>> {
|
fn get_items(&self, pane_id: PaneId) -> Result<Vec<SerializedItem>> {
|
||||||
Ok(self.select_bound(sql!(
|
Ok(self.select_bound(sql!(
|
||||||
SELECT kind, item_id, active FROM items
|
SELECT kind, item_id, active FROM items
|
||||||
WHERE pane_id = ?
|
WHERE pane_id = ?
|
||||||
ORDER BY position
|
ORDER BY position
|
||||||
))?(pane_id)?)
|
))?(pane_id)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save_items(
|
fn save_items(
|
||||||
conn: &Connection,
|
conn: &Connection,
|
||||||
workspace_id: WorkspaceId,
|
workspace_id: WorkspaceId,
|
||||||
|
@ -468,10 +468,10 @@ impl WorkspaceDb {
|
||||||
for (position, item) in items.iter().enumerate() {
|
for (position, item) in items.iter().enumerate() {
|
||||||
insert((workspace_id, pane_id, position, item))?;
|
insert((workspace_id, pane_id, position, item))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
query! {
|
query! {
|
||||||
pub async fn update_timestamp(workspace_id: WorkspaceId) -> Result<()> {
|
pub async fn update_timestamp(workspace_id: WorkspaceId) -> Result<()> {
|
||||||
UPDATE workspaces
|
UPDATE workspaces
|
||||||
|
@ -479,9 +479,9 @@ impl WorkspaceDb {
|
||||||
WHERE workspace_id = ?
|
WHERE workspace_id = ?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
query! {
|
query! {
|
||||||
pub async fn set_bounds(workspace_id: WorkspaceId, fullscreen: bool, x: f32, y: f32, width: f32, height: f32) -> Result<()> {
|
pub async fn set_bounds(workspace_id: WorkspaceId, fullscreen: bool, bounds: Option<(f32, f32, f32, f32)>) -> Result<()> {
|
||||||
UPDATE workspaces
|
UPDATE workspaces
|
||||||
SET fullscreen = ?2,
|
SET fullscreen = ?2,
|
||||||
window_x = ?3,
|
window_x = ?3,
|
||||||
|
@ -495,20 +495,20 @@ impl WorkspaceDb {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use db::open_test_db;
|
use db::open_test_db;
|
||||||
use settings::DockAnchor;
|
use settings::DockAnchor;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_next_id_stability() {
|
async fn test_next_id_stability() {
|
||||||
env_logger::try_init().ok();
|
env_logger::try_init().ok();
|
||||||
|
|
||||||
let db = WorkspaceDb(open_test_db("test_next_id_stability").await);
|
let db = WorkspaceDb(open_test_db("test_next_id_stability").await);
|
||||||
|
|
||||||
db.write(|conn| {
|
db.write(|conn| {
|
||||||
conn.migrate(
|
conn.migrate(
|
||||||
"test_table",
|
"test_table",
|
||||||
|
@ -517,14 +517,14 @@ mod tests {
|
||||||
text TEXT,
|
text TEXT,
|
||||||
workspace_id INTEGER,
|
workspace_id INTEGER,
|
||||||
FOREIGN KEY(workspace_id) REFERENCES workspaces(workspace_id)
|
FOREIGN KEY(workspace_id) REFERENCES workspaces(workspace_id)
|
||||||
ON DELETE CASCADE
|
ON DELETE CASCADE
|
||||||
) STRICT;
|
) STRICT;
|
||||||
)],
|
)],
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let id = db.next_id().await.unwrap();
|
let id = db.next_id().await.unwrap();
|
||||||
// Assert the empty row got inserted
|
// Assert the empty row got inserted
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -535,28 +535,28 @@ mod tests {
|
||||||
.unwrap()(id)
|
.unwrap()(id)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
);
|
);
|
||||||
|
|
||||||
db.write(move |conn| {
|
db.write(move |conn| {
|
||||||
conn.exec_bound(sql!(INSERT INTO test_table(text, workspace_id) VALUES (?, ?)))
|
conn.exec_bound(sql!(INSERT INTO test_table(text, workspace_id) VALUES (?, ?)))
|
||||||
.unwrap()(("test-text-1", id))
|
.unwrap()(("test-text-1", id))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let test_text_1 = db
|
let test_text_1 = db
|
||||||
.select_row_bound::<_, String>(sql!(SELECT text FROM test_table WHERE workspace_id = ?))
|
.select_row_bound::<_, String>(sql!(SELECT text FROM test_table WHERE workspace_id = ?))
|
||||||
.unwrap()(1)
|
.unwrap()(1)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(test_text_1, "test-text-1");
|
assert_eq!(test_text_1, "test-text-1");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_workspace_id_stability() {
|
async fn test_workspace_id_stability() {
|
||||||
env_logger::try_init().ok();
|
env_logger::try_init().ok();
|
||||||
|
|
||||||
let db = WorkspaceDb(open_test_db("test_workspace_id_stability").await);
|
let db = WorkspaceDb(open_test_db("test_workspace_id_stability").await);
|
||||||
|
|
||||||
db.write(|conn| {
|
db.write(|conn| {
|
||||||
conn.migrate(
|
conn.migrate(
|
||||||
"test_table",
|
"test_table",
|
||||||
|
@ -566,13 +566,13 @@ mod tests {
|
||||||
workspace_id INTEGER,
|
workspace_id INTEGER,
|
||||||
FOREIGN KEY(workspace_id)
|
FOREIGN KEY(workspace_id)
|
||||||
REFERENCES workspaces(workspace_id)
|
REFERENCES workspaces(workspace_id)
|
||||||
ON DELETE CASCADE
|
ON DELETE CASCADE
|
||||||
) STRICT;)],
|
) STRICT;)],
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mut workspace_1 = SerializedWorkspace {
|
let mut workspace_1 = SerializedWorkspace {
|
||||||
id: 1,
|
id: 1,
|
||||||
location: (["/tmp", "/tmp2"]).into(),
|
location: (["/tmp", "/tmp2"]).into(),
|
||||||
|
@ -583,7 +583,7 @@ mod tests {
|
||||||
fullscreen: false,
|
fullscreen: false,
|
||||||
bounds: Default::default(),
|
bounds: Default::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut workspace_2 = SerializedWorkspace {
|
let mut workspace_2 = SerializedWorkspace {
|
||||||
id: 2,
|
id: 2,
|
||||||
location: (["/tmp"]).into(),
|
location: (["/tmp"]).into(),
|
||||||
|
@ -594,57 +594,57 @@ mod tests {
|
||||||
fullscreen: false,
|
fullscreen: false,
|
||||||
bounds: Default::default(),
|
bounds: Default::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
db.save_workspace(workspace_1.clone()).await;
|
db.save_workspace(workspace_1.clone()).await;
|
||||||
|
|
||||||
db.write(|conn| {
|
db.write(|conn| {
|
||||||
conn.exec_bound(sql!(INSERT INTO test_table(text, workspace_id) VALUES (?, ?)))
|
conn.exec_bound(sql!(INSERT INTO test_table(text, workspace_id) VALUES (?, ?)))
|
||||||
.unwrap()(("test-text-1", 1))
|
.unwrap()(("test-text-1", 1))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
db.save_workspace(workspace_2.clone()).await;
|
db.save_workspace(workspace_2.clone()).await;
|
||||||
|
|
||||||
db.write(|conn| {
|
db.write(|conn| {
|
||||||
conn.exec_bound(sql!(INSERT INTO test_table(text, workspace_id) VALUES (?, ?)))
|
conn.exec_bound(sql!(INSERT INTO test_table(text, workspace_id) VALUES (?, ?)))
|
||||||
.unwrap()(("test-text-2", 2))
|
.unwrap()(("test-text-2", 2))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
workspace_1.location = (["/tmp", "/tmp3"]).into();
|
workspace_1.location = (["/tmp", "/tmp3"]).into();
|
||||||
db.save_workspace(workspace_1.clone()).await;
|
db.save_workspace(workspace_1.clone()).await;
|
||||||
db.save_workspace(workspace_1).await;
|
db.save_workspace(workspace_1).await;
|
||||||
|
|
||||||
workspace_2.dock_pane.children.push(SerializedItem {
|
workspace_2.dock_pane.children.push(SerializedItem {
|
||||||
kind: Arc::from("Test"),
|
kind: Arc::from("Test"),
|
||||||
item_id: 10,
|
item_id: 10,
|
||||||
active: true,
|
active: true,
|
||||||
});
|
});
|
||||||
db.save_workspace(workspace_2).await;
|
db.save_workspace(workspace_2).await;
|
||||||
|
|
||||||
let test_text_2 = db
|
let test_text_2 = db
|
||||||
.select_row_bound::<_, String>(sql!(SELECT text FROM test_table WHERE workspace_id = ?))
|
.select_row_bound::<_, String>(sql!(SELECT text FROM test_table WHERE workspace_id = ?))
|
||||||
.unwrap()(2)
|
.unwrap()(2)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(test_text_2, "test-text-2");
|
assert_eq!(test_text_2, "test-text-2");
|
||||||
|
|
||||||
let test_text_1 = db
|
let test_text_1 = db
|
||||||
.select_row_bound::<_, String>(sql!(SELECT text FROM test_table WHERE workspace_id = ?))
|
.select_row_bound::<_, String>(sql!(SELECT text FROM test_table WHERE workspace_id = ?))
|
||||||
.unwrap()(1)
|
.unwrap()(1)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(test_text_1, "test-text-1");
|
assert_eq!(test_text_1, "test-text-1");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_full_workspace_serialization() {
|
async fn test_full_workspace_serialization() {
|
||||||
env_logger::try_init().ok();
|
env_logger::try_init().ok();
|
||||||
|
|
||||||
let db = WorkspaceDb(open_test_db("test_full_workspace_serialization").await);
|
let db = WorkspaceDb(open_test_db("test_full_workspace_serialization").await);
|
||||||
|
|
||||||
let dock_pane = crate::persistence::model::SerializedPane {
|
let dock_pane = crate::persistence::model::SerializedPane {
|
||||||
children: vec![
|
children: vec![
|
||||||
SerializedItem::new("Terminal", 1, false),
|
SerializedItem::new("Terminal", 1, false),
|
||||||
|
@ -654,7 +654,7 @@ mod tests {
|
||||||
],
|
],
|
||||||
active: false,
|
active: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
// -----------------
|
// -----------------
|
||||||
// | 1,2 | 5,6 |
|
// | 1,2 | 5,6 |
|
||||||
// | - - - | |
|
// | - - - | |
|
||||||
|
@ -691,7 +691,7 @@ mod tests {
|
||||||
)),
|
)),
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
let workspace = SerializedWorkspace {
|
let workspace = SerializedWorkspace {
|
||||||
id: 5,
|
id: 5,
|
||||||
location: (["/tmp", "/tmp2"]).into(),
|
location: (["/tmp", "/tmp2"]).into(),
|
||||||
|
@ -702,26 +702,26 @@ mod tests {
|
||||||
fullscreen: false,
|
fullscreen: false,
|
||||||
bounds: Default::default(),
|
bounds: Default::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
db.save_workspace(workspace.clone()).await;
|
db.save_workspace(workspace.clone()).await;
|
||||||
let round_trip_workspace = db.workspace_for_roots(&["/tmp2", "/tmp"]);
|
let round_trip_workspace = db.workspace_for_roots(&["/tmp2", "/tmp"]);
|
||||||
|
|
||||||
assert_eq!(workspace, round_trip_workspace.unwrap());
|
assert_eq!(workspace, round_trip_workspace.unwrap());
|
||||||
|
|
||||||
// Test guaranteed duplicate IDs
|
// Test guaranteed duplicate IDs
|
||||||
db.save_workspace(workspace.clone()).await;
|
db.save_workspace(workspace.clone()).await;
|
||||||
db.save_workspace(workspace.clone()).await;
|
db.save_workspace(workspace.clone()).await;
|
||||||
|
|
||||||
let round_trip_workspace = db.workspace_for_roots(&["/tmp", "/tmp2"]);
|
let round_trip_workspace = db.workspace_for_roots(&["/tmp", "/tmp2"]);
|
||||||
assert_eq!(workspace, round_trip_workspace.unwrap());
|
assert_eq!(workspace, round_trip_workspace.unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_workspace_assignment() {
|
async fn test_workspace_assignment() {
|
||||||
env_logger::try_init().ok();
|
env_logger::try_init().ok();
|
||||||
|
|
||||||
let db = WorkspaceDb(open_test_db("test_basic_functionality").await);
|
let db = WorkspaceDb(open_test_db("test_basic_functionality").await);
|
||||||
|
|
||||||
let workspace_1 = SerializedWorkspace {
|
let workspace_1 = SerializedWorkspace {
|
||||||
id: 1,
|
id: 1,
|
||||||
location: (["/tmp", "/tmp2"]).into(),
|
location: (["/tmp", "/tmp2"]).into(),
|
||||||
|
@ -732,7 +732,7 @@ mod tests {
|
||||||
fullscreen: false,
|
fullscreen: false,
|
||||||
bounds: Default::default(),
|
bounds: Default::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut workspace_2 = SerializedWorkspace {
|
let mut workspace_2 = SerializedWorkspace {
|
||||||
id: 2,
|
id: 2,
|
||||||
location: (["/tmp"]).into(),
|
location: (["/tmp"]).into(),
|
||||||
|
@ -743,10 +743,10 @@ mod tests {
|
||||||
fullscreen: false,
|
fullscreen: false,
|
||||||
bounds: Default::default(),
|
bounds: Default::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
db.save_workspace(workspace_1.clone()).await;
|
db.save_workspace(workspace_1.clone()).await;
|
||||||
db.save_workspace(workspace_2.clone()).await;
|
db.save_workspace(workspace_2.clone()).await;
|
||||||
|
|
||||||
// Test that paths are treated as a set
|
// Test that paths are treated as a set
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
db.workspace_for_roots(&["/tmp", "/tmp2"]).unwrap(),
|
db.workspace_for_roots(&["/tmp", "/tmp2"]).unwrap(),
|
||||||
|
@ -756,20 +756,20 @@ mod tests {
|
||||||
db.workspace_for_roots(&["/tmp2", "/tmp"]).unwrap(),
|
db.workspace_for_roots(&["/tmp2", "/tmp"]).unwrap(),
|
||||||
workspace_1
|
workspace_1
|
||||||
);
|
);
|
||||||
|
|
||||||
// Make sure that other keys work
|
// Make sure that other keys work
|
||||||
assert_eq!(db.workspace_for_roots(&["/tmp"]).unwrap(), workspace_2);
|
assert_eq!(db.workspace_for_roots(&["/tmp"]).unwrap(), workspace_2);
|
||||||
assert_eq!(db.workspace_for_roots(&["/tmp3", "/tmp2", "/tmp4"]), None);
|
assert_eq!(db.workspace_for_roots(&["/tmp3", "/tmp2", "/tmp4"]), None);
|
||||||
|
|
||||||
// Test 'mutate' case of updating a pre-existing id
|
// Test 'mutate' case of updating a pre-existing id
|
||||||
workspace_2.location = (["/tmp", "/tmp2"]).into();
|
workspace_2.location = (["/tmp", "/tmp2"]).into();
|
||||||
|
|
||||||
db.save_workspace(workspace_2.clone()).await;
|
db.save_workspace(workspace_2.clone()).await;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
db.workspace_for_roots(&["/tmp", "/tmp2"]).unwrap(),
|
db.workspace_for_roots(&["/tmp", "/tmp2"]).unwrap(),
|
||||||
workspace_2
|
workspace_2
|
||||||
);
|
);
|
||||||
|
|
||||||
// Test other mechanism for mutating
|
// Test other mechanism for mutating
|
||||||
let mut workspace_3 = SerializedWorkspace {
|
let mut workspace_3 = SerializedWorkspace {
|
||||||
id: 3,
|
id: 3,
|
||||||
|
@ -781,13 +781,13 @@ mod tests {
|
||||||
fullscreen: false,
|
fullscreen: false,
|
||||||
bounds: Default::default(),
|
bounds: Default::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
db.save_workspace(workspace_3.clone()).await;
|
db.save_workspace(workspace_3.clone()).await;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
db.workspace_for_roots(&["/tmp", "/tmp2"]).unwrap(),
|
db.workspace_for_roots(&["/tmp", "/tmp2"]).unwrap(),
|
||||||
workspace_3
|
workspace_3
|
||||||
);
|
);
|
||||||
|
|
||||||
// Make sure that updating paths differently also works
|
// Make sure that updating paths differently also works
|
||||||
workspace_3.location = (["/tmp3", "/tmp4", "/tmp2"]).into();
|
workspace_3.location = (["/tmp3", "/tmp4", "/tmp2"]).into();
|
||||||
db.save_workspace(workspace_3.clone()).await;
|
db.save_workspace(workspace_3.clone()).await;
|
||||||
|
@ -798,11 +798,11 @@ mod tests {
|
||||||
workspace_3
|
workspace_3
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
use crate::dock::DockPosition;
|
use crate::dock::DockPosition;
|
||||||
use crate::persistence::model::SerializedWorkspace;
|
use crate::persistence::model::SerializedWorkspace;
|
||||||
use crate::persistence::model::{SerializedItem, SerializedPane, SerializedPaneGroup};
|
use crate::persistence::model::{SerializedItem, SerializedPane, SerializedPaneGroup};
|
||||||
|
|
||||||
fn default_workspace<P: AsRef<Path>>(
|
fn default_workspace<P: AsRef<Path>>(
|
||||||
workspace_id: &[P],
|
workspace_id: &[P],
|
||||||
dock_pane: SerializedPane,
|
dock_pane: SerializedPane,
|
||||||
|
@ -819,13 +819,13 @@ mod tests {
|
||||||
bounds: Default::default(),
|
bounds: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_basic_dock_pane() {
|
async fn test_basic_dock_pane() {
|
||||||
env_logger::try_init().ok();
|
env_logger::try_init().ok();
|
||||||
|
|
||||||
let db = WorkspaceDb(open_test_db("basic_dock_pane").await);
|
let db = WorkspaceDb(open_test_db("basic_dock_pane").await);
|
||||||
|
|
||||||
let dock_pane = crate::persistence::model::SerializedPane::new(
|
let dock_pane = crate::persistence::model::SerializedPane::new(
|
||||||
vec![
|
vec![
|
||||||
SerializedItem::new("Terminal", 1, false),
|
SerializedItem::new("Terminal", 1, false),
|
||||||
|
@ -835,22 +835,22 @@ mod tests {
|
||||||
],
|
],
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
|
|
||||||
let workspace = default_workspace(&["/tmp"], dock_pane, &Default::default());
|
let workspace = default_workspace(&["/tmp"], dock_pane, &Default::default());
|
||||||
|
|
||||||
db.save_workspace(workspace.clone()).await;
|
db.save_workspace(workspace.clone()).await;
|
||||||
|
|
||||||
let new_workspace = db.workspace_for_roots(&["/tmp"]).unwrap();
|
let new_workspace = db.workspace_for_roots(&["/tmp"]).unwrap();
|
||||||
|
|
||||||
assert_eq!(workspace.dock_pane, new_workspace.dock_pane);
|
assert_eq!(workspace.dock_pane, new_workspace.dock_pane);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_simple_split() {
|
async fn test_simple_split() {
|
||||||
env_logger::try_init().ok();
|
env_logger::try_init().ok();
|
||||||
|
|
||||||
let db = WorkspaceDb(open_test_db("simple_split").await);
|
let db = WorkspaceDb(open_test_db("simple_split").await);
|
||||||
|
|
||||||
// -----------------
|
// -----------------
|
||||||
// | 1,2 | 5,6 |
|
// | 1,2 | 5,6 |
|
||||||
// | - - - | |
|
// | - - - | |
|
||||||
|
@ -887,22 +887,22 @@ mod tests {
|
||||||
)),
|
)),
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
let workspace = default_workspace(&["/tmp"], Default::default(), ¢er_pane);
|
let workspace = default_workspace(&["/tmp"], Default::default(), ¢er_pane);
|
||||||
|
|
||||||
db.save_workspace(workspace.clone()).await;
|
db.save_workspace(workspace.clone()).await;
|
||||||
|
|
||||||
let new_workspace = db.workspace_for_roots(&["/tmp"]).unwrap();
|
let new_workspace = db.workspace_for_roots(&["/tmp"]).unwrap();
|
||||||
|
|
||||||
assert_eq!(workspace.center_group, new_workspace.center_group);
|
assert_eq!(workspace.center_group, new_workspace.center_group);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_cleanup_panes() {
|
async fn test_cleanup_panes() {
|
||||||
env_logger::try_init().ok();
|
env_logger::try_init().ok();
|
||||||
|
|
||||||
let db = WorkspaceDb(open_test_db("test_cleanup_panes").await);
|
let db = WorkspaceDb(open_test_db("test_cleanup_panes").await);
|
||||||
|
|
||||||
let center_pane = SerializedPaneGroup::Group {
|
let center_pane = SerializedPaneGroup::Group {
|
||||||
axis: gpui::Axis::Horizontal,
|
axis: gpui::Axis::Horizontal,
|
||||||
children: vec![
|
children: vec![
|
||||||
|
@ -934,13 +934,13 @@ mod tests {
|
||||||
)),
|
)),
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
let id = &["/tmp"];
|
let id = &["/tmp"];
|
||||||
|
|
||||||
let mut workspace = default_workspace(id, Default::default(), ¢er_pane);
|
let mut workspace = default_workspace(id, Default::default(), ¢er_pane);
|
||||||
|
|
||||||
db.save_workspace(workspace.clone()).await;
|
db.save_workspace(workspace.clone()).await;
|
||||||
|
|
||||||
workspace.center_group = SerializedPaneGroup::Group {
|
workspace.center_group = SerializedPaneGroup::Group {
|
||||||
axis: gpui::Axis::Vertical,
|
axis: gpui::Axis::Vertical,
|
||||||
children: vec![
|
children: vec![
|
||||||
|
@ -960,11 +960,11 @@ mod tests {
|
||||||
)),
|
)),
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
db.save_workspace(workspace.clone()).await;
|
db.save_workspace(workspace.clone()).await;
|
||||||
|
|
||||||
let new_workspace = db.workspace_for_roots(id).unwrap();
|
let new_workspace = db.workspace_for_roots(id).unwrap();
|
||||||
|
|
||||||
assert_eq!(workspace.center_group, new_workspace.center_group);
|
assert_eq!(workspace.center_group, new_workspace.center_group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ use gpui::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use db::sqlez::{
|
use db::sqlez::{
|
||||||
bindable::{Bind, Column, StaticRowComponent},
|
bindable::{Bind, Column, StaticColumnCount},
|
||||||
statement::Statement,
|
statement::Statement,
|
||||||
};
|
};
|
||||||
use project::Project;
|
use project::Project;
|
||||||
|
@ -42,7 +42,7 @@ impl<P: AsRef<Path>, T: IntoIterator<Item = P>> From<T> for WorkspaceLocation {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StaticRowComponent for WorkspaceLocation {}
|
impl StaticColumnCount for WorkspaceLocation {}
|
||||||
impl Bind for &WorkspaceLocation {
|
impl Bind for &WorkspaceLocation {
|
||||||
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
||||||
bincode::serialize(&self.0)
|
bincode::serialize(&self.0)
|
||||||
|
@ -254,8 +254,8 @@ impl Default for SerializedItem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StaticRowComponent for SerializedItem {
|
impl StaticColumnCount for SerializedItem {
|
||||||
fn static_column_count() -> usize {
|
fn column_count() -> usize {
|
||||||
3
|
3
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -283,8 +283,8 @@ impl Column for SerializedItem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StaticRowComponent for DockPosition {
|
impl StaticColumnCount for DockPosition {
|
||||||
fn static_column_count() -> usize {
|
fn column_count() -> usize {
|
||||||
2
|
2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -683,9 +683,9 @@ impl Workspace {
|
||||||
|
|
||||||
// Use the serialized workspace to construct the new window
|
// Use the serialized workspace to construct the new window
|
||||||
let (_, workspace) = cx.add_window(
|
let (_, workspace) = cx.add_window(
|
||||||
(app_state.build_window_options)(
|
(app_state.build_window_options)(dbg!(serialized_workspace
|
||||||
serialized_workspace.as_ref().map(|sw| sw.bounds()),
|
.as_ref()
|
||||||
),
|
.map(|sw| sw.bounds()))),
|
||||||
|cx| {
|
|cx| {
|
||||||
let mut workspace = Workspace::new(
|
let mut workspace = Workspace::new(
|
||||||
serialized_workspace,
|
serialized_workspace,
|
||||||
|
@ -697,15 +697,18 @@ impl Workspace {
|
||||||
(app_state.initialize_workspace)(&mut workspace, &app_state, cx);
|
(app_state.initialize_workspace)(&mut workspace, &app_state, cx);
|
||||||
cx.observe_window_bounds(move |_, bounds, cx| {
|
cx.observe_window_bounds(move |_, bounds, cx| {
|
||||||
let fullscreen = cx.window_is_fullscreen(cx.window_id());
|
let fullscreen = cx.window_is_fullscreen(cx.window_id());
|
||||||
cx.background()
|
let bounds = if let WindowBounds::Fixed(region) = bounds {
|
||||||
.spawn(DB.set_bounds(
|
Some((
|
||||||
workspace_id,
|
region.min_x(),
|
||||||
fullscreen,
|
region.min_y(),
|
||||||
bounds.min_x(),
|
region.width(),
|
||||||
bounds.min_y(),
|
region.height(),
|
||||||
bounds.width(),
|
|
||||||
bounds.height(),
|
|
||||||
))
|
))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
cx.background()
|
||||||
|
.spawn(DB.set_bounds(workspace_id, fullscreen, bounds))
|
||||||
.detach_and_log_err(cx);
|
.detach_and_log_err(cx);
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue