Compare commits

...

8 Commits

Author SHA1 Message Date
Dongdong Zhou 4a0be8cf10 bump version
CI / Rust (stable) on macos-latest (push) Has been cancelled
CI / Rust (stable) on ubuntu-latest (push) Has been cancelled
CI / Rust (stable) on windows-latest (push) Has been cancelled
2022-03-24 17:40:20 +00:00
Dániel Buga c42265d5d3 Extract constant 2022-03-24 17:12:16 +00:00
Dániel Buga 3106edf3da Fix rebase mistake 2022-03-24 17:12:16 +00:00
Dániel Buga 293bd6d7b0 Don't save settings on each keypress 2022-03-24 17:12:16 +00:00
Dániel Buga 067c50ca52 Remove unnecessary clones from event handling 2022-03-24 17:12:16 +00:00
Dániel Buga 3f56695dea Assert that settings update was successful 2022-03-24 17:12:16 +00:00
Dániel Buga 4ab310674f Don't clone when deserializing settings value 2022-03-24 17:12:16 +00:00
Dániel Buga e39e9b0f8a Clean up update_file 2022-03-24 17:12:16 +00:00
10 changed files with 79 additions and 51 deletions
Generated
+5 -5
View File
@@ -1846,7 +1846,7 @@ dependencies = [
[[package]]
name = "lapce"
version = "0.0.10"
version = "0.0.12"
dependencies = [
"lapce-proxy",
"lapce-ui",
@@ -1854,7 +1854,7 @@ dependencies = [
[[package]]
name = "lapce-core"
version = "0.0.10"
version = "0.0.12"
dependencies = [
"itertools",
"serde 1.0.130",
@@ -1874,7 +1874,7 @@ dependencies = [
[[package]]
name = "lapce-data"
version = "0.0.10"
version = "0.0.12"
dependencies = [
"Inflector",
"alacritty_terminal",
@@ -1931,7 +1931,7 @@ dependencies = [
[[package]]
name = "lapce-proxy"
version = "0.0.10"
version = "0.0.12"
dependencies = [
"alacritty_terminal",
"anyhow",
@@ -1978,7 +1978,7 @@ dependencies = [
[[package]]
name = "lapce-ui"
version = "0.0.10"
version = "0.0.12"
dependencies = [
"Inflector",
"alacritty_terminal",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "lapce"
version = "0.0.10"
version = "0.0.12"
authors = ["Dongdong Zhou <dzhou121@gmail.com>"]
edition = "2021"
rust-version = "1.58"
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="windows-1252"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<Product Name="Lapce" Id="*" UpgradeCode="9c09a374-1135-4782-959f-2dec376a1dfa" Language="1033" Codepage="1252" Version="0.0.4" Manufacturer="Lapce">
<Product Name="Lapce" Id="*" UpgradeCode="9c09a374-1135-4782-959f-2dec376a1dfa" Language="1033" Codepage="1252" Version="0.0.12" Manufacturer="Lapce">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine"/>
<MajorUpgrade AllowSameVersionUpgrades="yes" DowngradeErrorMessage="A newer version of [ProductName] is already installed."/>
<Icon Id="lapce.exe" SourceFile=".\extra\windows\lapce.ico"/>
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "lapce-core"
version = "0.0.10"
version = "0.0.12"
authors = ["Dongdong Zhou <dzhou121@gmail.com>"]
edition = "2021"
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "lapce-data"
version = "0.0.10"
version = "0.0.12"
authors = ["Dongdong Zhou <dzhou121@gmail.com>"]
edition = "2021"
+17 -16
View File
@@ -361,28 +361,29 @@ impl Config {
}
pub fn update_file(key: &str, value: toml::Value) -> Option<()> {
let mut main_table =
Self::get_file_table().unwrap_or_else(toml::value::Table::new);
let mut main_table = Self::get_file_table().unwrap_or_default();
// Separate key from container path
let (path, key) = key.rsplit_once('.').unwrap_or(("", key));
// Find the container table
let mut table = &mut main_table;
let parts: Vec<&str> = key.split('.').collect();
let n = parts.len();
for (i, key) in parts.into_iter().enumerate() {
if i == n - 1 {
table.insert(key.to_string(), value.clone());
} else {
if !table.contains_key(key) {
table.insert(
key.to_string(),
toml::Value::Table(toml::value::Table::new()),
);
}
table = table.get_mut(key)?.as_table_mut()?;
for key in path.split('.') {
if !table.contains_key(key) {
table
.insert(key.to_string(), toml::Value::Table(Default::default()));
}
table = table.get_mut(key)?.as_table_mut()?;
}
// Update key
table.insert(key.to_string(), value);
// Store
let path = Self::settings_file()?;
std::fs::write(&path, toml::to_string(&main_table).ok()?.as_bytes()).ok()?;
None
Some(())
}
pub fn set_theme(&mut self, theme: &str, preview: bool) -> Option<()> {
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "lapce-proxy"
version = "0.0.10"
version = "0.0.12"
authors = ["Dongdong Zhou <dzhou121@gmail.com>"]
edition = "2021"
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "lapce-ui"
version = "0.0.10"
version = "0.0.12"
authors = ["Dongdong Zhou <dzhou121@gmail.com>"]
edition = "2021"
+47 -20
View File
@@ -1,4 +1,4 @@
use std::{collections::HashMap, sync::Arc};
use std::{collections::HashMap, sync::Arc, time::Duration};
use druid::{
kurbo::BezPath,
@@ -7,8 +7,8 @@ use druid::{
},
BoxConstraints, Command, Env, Event, EventCtx, ExtEventSink, FontFamily,
FontWeight, LayoutCtx, LifeCycle, LifeCycleCtx, Modifiers, MouseEvent, PaintCtx,
Point, Rect, RenderContext, Size, Target, UpdateCtx, Vec2, Widget, WidgetExt,
WidgetId, WidgetPod,
Point, Rect, RenderContext, Size, Target, TimerToken, UpdateCtx, Vec2, Widget,
WidgetExt, WidgetId, WidgetPod,
};
use inflector::Inflector;
use lapce_data::{
@@ -614,6 +614,8 @@ pub struct LapceSettingsItem {
width: f64,
cursor: usize,
input: String,
value_changed: bool,
last_idle_timer: TimerToken,
name_text: Option<PietTextLayout>,
desc_text: Option<PietTextLayout>,
@@ -624,6 +626,9 @@ pub struct LapceSettingsItem {
}
impl LapceSettingsItem {
/// The amount of time to wait for the next key press before storing settings.
const SAVE_DELAY: Duration = Duration::from_millis(300);
pub fn new(
data: &mut LapceTabData,
kind: String,
@@ -667,8 +672,11 @@ impl LapceSettingsItem {
width: 0.0,
checkbox_width: 20.0,
input_max_width: 500.0,
input: "".to_string(),
cursor: 0,
input: "".to_string(),
value_changed: false,
last_idle_timer: TimerToken::INVALID,
name_text: None,
desc_text: None,
value_text: None,
@@ -873,14 +881,8 @@ impl Widget<LapceTabData> for LapceSettingsItem {
));
if rect.contains(mouse_event.pos) {
self.value = serde_json::json!(!checked);
ctx.submit_command(Command::new(
LAPCE_UI_COMMAND,
LapceUICommand::UpdateSettingsFile(
self.get_key(),
serde_json::Value::Bool(!checked),
),
Target::Widget(data.id),
));
self.value_changed = true;
self.last_idle_timer = ctx.request_timer(Self::SAVE_DELAY);
}
}
}
@@ -894,6 +896,20 @@ impl Widget<LapceTabData> for LapceSettingsItem {
ctx.request_paint();
}
}
Event::Timer(token)
if self.value_changed && *token == self.last_idle_timer =>
{
self.value_changed = false;
ctx.submit_command(Command::new(
LAPCE_UI_COMMAND,
LapceUICommand::UpdateSettingsFile(
self.get_key(),
self.value.clone(),
),
Target::Widget(data.id),
));
}
_ => {}
}
}
@@ -905,6 +921,21 @@ impl Widget<LapceTabData> for LapceSettingsItem {
data: &LapceTabData,
env: &Env,
) {
match event {
LifeCycle::FocusChanged(false) if self.value_changed => {
self.value_changed = false;
ctx.submit_command(Command::new(
LAPCE_UI_COMMAND,
LapceUICommand::UpdateSettingsFile(
self.get_key(),
self.value.clone(),
),
Target::Widget(data.id),
));
}
_ => (),
};
if let Some(input) = self.input_widget.as_mut() {
input.lifecycle(ctx, event, data, env);
}
@@ -942,14 +973,10 @@ impl Widget<LapceTabData> for LapceSettingsItem {
}
_ => return,
};
ctx.submit_command(Command::new(
LAPCE_UI_COMMAND,
LapceUICommand::UpdateSettingsFile(
self.get_key(),
new_value,
),
Target::Widget(data.id),
));
self.value = new_value;
self.value_changed = true;
self.last_idle_timer = ctx.request_timer(Self::SAVE_DELAY);
}
}
}
+4 -4
View File
@@ -29,6 +29,7 @@ use lapce_data::{
state::LapceWorkspaceType,
};
use lsp_types::DiagnosticSeverity;
use serde::Deserialize;
use crate::{
activity::ActivityBar, code_action::CodeAction, completion::CompletionContainer,
@@ -596,10 +597,9 @@ impl Widget<LapceTabData> for LapceTabNew {
ctx.set_handled();
}
LapceUICommand::UpdateSettingsFile(key, value) => {
if let Ok(value) =
serde_json::from_value::<toml::Value>(value.clone())
{
Config::update_file(key, value);
if let Ok(value) = toml::Value::deserialize(value) {
let update_result = Config::update_file(key, value);
debug_assert!(update_result.is_some());
}
}
LapceUICommand::OpenFileDiff(path, history) => {