mirror of https://github.com/lapce/lapce.git
reset settings
This commit is contained in:
parent
3e5d897b36
commit
6bdd289f5a
|
@ -426,6 +426,7 @@ pub enum LapceUICommand {
|
|||
UpdatePaletteItems(String, Vec<NewPaletteItem>),
|
||||
FilterPaletteItems(String, String, Vec<NewPaletteItem>),
|
||||
UpdateKeymapsFilter(String),
|
||||
ResetSettingsFile(String, String),
|
||||
UpdateSettingsFile(String, String, serde_json::Value),
|
||||
UpdateSettingsFilter(String),
|
||||
FilterKeymaps(String, Arc<Vec<KeyMap>>, Arc<Vec<LapceCommand>>),
|
||||
|
|
|
@ -721,6 +721,28 @@ fn get_file_table() -> Option<toml::value::Table> {
|
|||
Some(table)
|
||||
}
|
||||
|
||||
pub fn reset_setting(parent: &str, key: &str) -> Option<()> {
|
||||
let mut main_table = Self::get_file_table().unwrap_or_default();
|
||||
|
||||
// Find the container table
|
||||
let mut table = &mut main_table;
|
||||
for key in parent.split('.') {
|
||||
if !table.contains_key(key) {
|
||||
table
|
||||
.insert(key.to_string(), toml::Value::Table(Default::default()));
|
||||
}
|
||||
table = table.get_mut(key)?.as_table_mut()?;
|
||||
}
|
||||
|
||||
table.remove(key);
|
||||
|
||||
// Store
|
||||
let path = Self::settings_file()?;
|
||||
std::fs::write(&path, toml::to_string(&main_table).ok()?.as_bytes()).ok()?;
|
||||
|
||||
Some(())
|
||||
}
|
||||
|
||||
pub fn update_file(parent: &str, key: &str, value: toml::Value) -> Option<()> {
|
||||
let mut main_table = Self::get_file_table().unwrap_or_default();
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::{collections::HashMap, sync::Arc, time::Duration};
|
||||
use std::{collections::HashMap, fmt::Display, sync::Arc, time::Duration};
|
||||
|
||||
use druid::{
|
||||
kurbo::{BezPath, Line},
|
||||
|
@ -983,12 +983,23 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceTabData, env: &Env) {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum ThemeKind {
|
||||
Base,
|
||||
UI,
|
||||
Syntax,
|
||||
}
|
||||
|
||||
impl Display for ThemeKind {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_str(match self {
|
||||
ThemeKind::Base => "theme.base",
|
||||
ThemeKind::UI => "theme.ui",
|
||||
ThemeKind::Syntax => "theme.syntax",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ThemeSettings {
|
||||
widget_id: WidgetId,
|
||||
kind: ThemeKind,
|
||||
|
@ -996,6 +1007,7 @@ pub struct ThemeSettings {
|
|||
keys: Vec<String>,
|
||||
text_layouts: Option<Vec<PietTextLayout>>,
|
||||
changed_rects: Vec<(String, Rect)>,
|
||||
mouse_down_rect: Option<(String, Rect)>,
|
||||
}
|
||||
|
||||
impl ThemeSettings {
|
||||
|
@ -1008,6 +1020,7 @@ fn new() -> LapceSplitNew {
|
|||
keys: Vec::new(),
|
||||
text_layouts: None,
|
||||
changed_rects: Vec::new(),
|
||||
mouse_down_rect: None,
|
||||
}
|
||||
.boxed(),
|
||||
);
|
||||
|
@ -1068,6 +1081,33 @@ fn event(
|
|||
data: &mut LapceTabData,
|
||||
env: &Env,
|
||||
) {
|
||||
match event {
|
||||
Event::MouseDown(mouse_event) => {
|
||||
self.mouse_down_rect = None;
|
||||
for (key, change) in self.changed_rects.iter() {
|
||||
if change.contains(mouse_event.pos) {
|
||||
self.mouse_down_rect =
|
||||
Some((key.to_string(), change.clone()));
|
||||
}
|
||||
}
|
||||
}
|
||||
Event::MouseUp(mouse_event) => {
|
||||
if let Some((key, rect)) = self.mouse_down_rect.as_ref() {
|
||||
if rect.contains(mouse_event.pos) {
|
||||
ctx.submit_command(Command::new(
|
||||
LAPCE_UI_COMMAND,
|
||||
LapceUICommand::ResetSettingsFile(
|
||||
self.kind.to_string(),
|
||||
key.clone(),
|
||||
),
|
||||
Target::Widget(data.id),
|
||||
));
|
||||
}
|
||||
}
|
||||
self.mouse_down_rect = None;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
for input in self.inputs.iter_mut() {
|
||||
match event {
|
||||
Event::Wheel(_) => {}
|
||||
|
|
|
@ -738,6 +738,9 @@ fn handle_event(
|
|||
debug_assert!(update_result.is_some());
|
||||
}
|
||||
}
|
||||
LapceUICommand::ResetSettingsFile(parent, key) => {
|
||||
Config::reset_setting(parent, key);
|
||||
}
|
||||
LapceUICommand::OpenFileDiff(path, history) => {
|
||||
let editor_view_id = data.main_split.active.clone();
|
||||
let editor_view_id = data.main_split.jump_to_location(
|
||||
|
|
Loading…
Reference in New Issue