This commit is contained in:
Kay Simmons 2023-01-22 20:33:21 -08:00
parent 15799f7af6
commit a581d0c5b8
8 changed files with 301 additions and 311 deletions

View file

@ -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(())
}); });
} }

View file

@ -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 {

View file

@ -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 {

View file

@ -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
} }
} }

View file

@ -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)
} }

View file

@ -143,13 +143,13 @@ impl WorkspaceDb {
// 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
@ -185,9 +185,9 @@ 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)
)) ))
}) })
} }
@ -481,7 +481,7 @@ impl WorkspaceDb {
} }
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,

View file

@ -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
} }
} }

View file

@ -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();