Compare commits

..

No commits in common. "b3130823745bd093fde3f9c5dd41c90373eec886" and "3ee73c3d9b5de055d1e52bc13b5ba59f0ed61786" have entirely different histories.

8 changed files with 26 additions and 72 deletions

View File

@ -53,7 +53,6 @@ font_size = 16.0
| Option | Default | Description | | Option | Default | Description |
|--------|---------|-------------| |--------|---------|-------------|
| `auto_hide_toolbar` | `false` | If `true`, the menu bar at the top will be hidden. Move your mouse to the top of the window to reveal it. | | `auto_hide_toolbar` | `false` | If `true`, the menu bar at the top will be hidden. Move your mouse to the top of the window to reveal it. |
| `hide_tab_bar` | 'true' | If `false`, a separate tab bar will be drawn below the toolbar. |
| `show_line_numbers` | `false` | If `true`, line numbers will be displayed on the side specified by `line_side`. | | `show_line_numbers` | `false` | If `true`, line numbers will be displayed on the side specified by `line_side`. |
| `line_side` | `false` | If `false`, line numbers are on the left. If `true`, they are on the right. | | `line_side` | `false` | If `false`, line numbers are on the left. If `true`, they are on the right. |
| `word_wrap` | `false` | If `true`, lines will wrap when they reach the edge of the window. | | `word_wrap` | `false` | If `true`, lines will wrap when they reach the edge of the window. |

View File

@ -5,52 +5,22 @@ use super::theme::Theme;
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Config { pub struct Config {
#[serde(default = "default_auto_hide_toolbar")]
pub auto_hide_toolbar: bool, pub auto_hide_toolbar: bool,
#[serde(default = "default_hide_tab_bar")] pub auto_hide_tab_bar: bool,
pub hide_tab_bar: bool,
#[serde(default = "default_show_line_numbers")]
pub show_line_numbers: bool, pub show_line_numbers: bool,
#[serde(default = "default_word_wrap")]
pub word_wrap: bool, pub word_wrap: bool,
#[serde(default = "Theme::default")]
pub theme: Theme, pub theme: Theme,
#[serde(default = "default_line_side")]
pub line_side: bool, pub line_side: bool,
#[serde(default = "default_font_family")]
pub font_family: String, pub font_family: String,
#[serde(default = "default_font_size")]
pub font_size: f32, pub font_size: f32,
// pub vim_mode: bool, // pub vim_mode: bool,
} }
fn default_auto_hide_toolbar() -> bool {
false
}
fn default_hide_tab_bar() -> bool {
true
}
fn default_show_line_numbers() -> bool {
false
}
fn default_word_wrap() -> bool {
true
}
fn default_line_side() -> bool {
false
}
fn default_font_family() -> String {
"Proportional".to_string()
}
fn default_font_size() -> f32 {
14.0
}
impl Default for Config { impl Default for Config {
fn default() -> Self { fn default() -> Self {
Self { Self {
auto_hide_toolbar: false, auto_hide_toolbar: false,
hide_tab_bar: true, auto_hide_tab_bar: false,
show_line_numbers: false, show_line_numbers: false,
word_wrap: true, word_wrap: true,
theme: Theme::default(), theme: Theme::default(),
@ -65,11 +35,9 @@ impl Default for Config {
impl Config { impl Config {
pub fn config_path() -> Option<PathBuf> { pub fn config_path() -> Option<PathBuf> {
let config_dir = if let Some(config_dir) = dirs::config_dir() { let config_dir = if let Some(config_dir) = dirs::config_dir() {
config_dir.join(format!("{}", env!("CARGO_PKG_NAME"))) config_dir.join("ced")
} else if let Some(home_dir) = dirs::home_dir() { } else if let Some(home_dir) = dirs::home_dir() {
home_dir home_dir.join(".config").join("ced")
.join(".config")
.join(format!("{}", env!("CARGO_PKG_NAME")))
} else { } else {
return None; return None;
}; };
@ -92,8 +60,7 @@ impl Config {
} }
match std::fs::read_to_string(&config_path) { match std::fs::read_to_string(&config_path) {
Ok(content) => { Ok(content) => match toml::from_str::<Config>(&content) {
let mut config = match toml::from_str::<Config>(&content) {
Ok(config) => config, Ok(config) => config,
Err(e) => { Err(e) => {
eprintln!( eprintln!(
@ -101,14 +68,9 @@ impl Config {
config_path.display(), config_path.display(),
e e
); );
return Self::default(); Self::default()
}
};
let default_config = Self::default();
config.merge_with_default(default_config);
config
} }
},
Err(e) => { Err(e) => {
eprintln!( eprintln!(
"Failed to read config file {}: {}", "Failed to read config file {}: {}",
@ -120,16 +82,6 @@ impl Config {
} }
} }
fn merge_with_default(&mut self, default: Config) {
if self.font_family.is_empty() {
self.font_family = default.font_family;
}
if self.font_size <= 0.0 {
self.font_size = default.font_size;
}
}
pub fn save(&self) -> Result<(), Box<dyn std::error::Error>> { pub fn save(&self) -> Result<(), Box<dyn std::error::Error>> {
let config_path = Self::config_path().ok_or("Cannot determine config directory")?; let config_path = Self::config_path().ok_or("Cannot determine config directory")?;

View File

@ -24,7 +24,7 @@ impl eframe::App for TextEditor {
menu_bar(self, ctx); menu_bar(self, ctx);
if !self.hide_tab_bar { if !self.auto_hide_tab_bar {
tab_bar(self, ctx); tab_bar(self, ctx);
} }

View File

@ -19,7 +19,7 @@ impl TextEditor {
show_line_numbers: config.show_line_numbers, show_line_numbers: config.show_line_numbers,
word_wrap: config.word_wrap, word_wrap: config.word_wrap,
auto_hide_toolbar: config.auto_hide_toolbar, auto_hide_toolbar: config.auto_hide_toolbar,
hide_tab_bar: config.hide_tab_bar, auto_hide_tab_bar: config.auto_hide_tab_bar,
theme: config.theme, theme: config.theme,
line_side: config.line_side, line_side: config.line_side,
font_family: config.font_family, font_family: config.font_family,
@ -80,7 +80,7 @@ impl TextEditor {
Config { Config {
auto_hide_toolbar: self.auto_hide_toolbar, auto_hide_toolbar: self.auto_hide_toolbar,
show_line_numbers: self.show_line_numbers, show_line_numbers: self.show_line_numbers,
hide_tab_bar: self.hide_tab_bar, auto_hide_tab_bar: self.auto_hide_tab_bar,
word_wrap: self.word_wrap, word_wrap: self.word_wrap,
theme: self.theme, theme: self.theme,
line_side: self.line_side, line_side: self.line_side,

View File

@ -19,7 +19,7 @@ impl Default for TextEditor {
show_line_numbers: false, show_line_numbers: false,
word_wrap: true, word_wrap: true,
auto_hide_toolbar: false, auto_hide_toolbar: false,
hide_tab_bar: true, auto_hide_tab_bar: true,
theme: Theme::default(), theme: Theme::default(),
line_side: false, line_side: false,
font_family: "Proportional".to_string(), font_family: "Proportional".to_string(),

View File

@ -44,7 +44,7 @@ pub struct TextEditor {
pub(crate) show_line_numbers: bool, pub(crate) show_line_numbers: bool,
pub(crate) word_wrap: bool, pub(crate) word_wrap: bool,
pub(crate) auto_hide_toolbar: bool, pub(crate) auto_hide_toolbar: bool,
pub(crate) hide_tab_bar: bool, pub(crate) auto_hide_tab_bar: bool,
pub(crate) theme: Theme, pub(crate) theme: Theme,
pub(crate) line_side: bool, pub(crate) line_side: bool,
pub(crate) font_family: String, pub(crate) font_family: String,

View File

@ -125,7 +125,7 @@ impl TextEditor {
return self.calculate_editor_dimensions(ui).text_width; return self.calculate_editor_dimensions(ui).text_width;
} }
let longest_line_width = processing_result.longest_line_pixel_width + (self.font_size * 2.0); let longest_line_width = processing_result.longest_line_pixel_width + self.font_size;
let dimensions = self.calculate_editor_dimensions(ui); let dimensions = self.calculate_editor_dimensions(ui);
longest_line_width.max(dimensions.text_width) longest_line_width.max(dimensions.text_width)

View File

@ -182,7 +182,10 @@ pub(crate) fn menu_bar(app: &mut TextEditor, ctx: &egui::Context) {
app.save_config(); app.save_config();
ui.close_menu(); ui.close_menu();
} }
if ui.checkbox(&mut app.hide_tab_bar, "Hide Tab Bar").clicked() { if ui
.checkbox(&mut app.auto_hide_tab_bar, "Hide Tab Bar")
.clicked()
{
app.save_config(); app.save_config();
ui.close_menu(); ui.close_menu();
} }
@ -267,7 +270,7 @@ pub(crate) fn menu_bar(app: &mut TextEditor, ctx: &egui::Context) {
} }
}); });
if app.hide_tab_bar { if app.auto_hide_tab_bar {
let tab_title = if let Some(tab) = app.get_active_tab() { let tab_title = if let Some(tab) = app.get_active_tab() {
tab.title.clone() tab.title.clone()
} else { } else {