Change journal location setting name to "path" and default to ~
This commit is contained in:
parent
f8da5ab2e7
commit
3c62de34f7
5 changed files with 39 additions and 24 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -2765,6 +2765,7 @@ dependencies = [
|
||||||
"gpui",
|
"gpui",
|
||||||
"log",
|
"log",
|
||||||
"settings",
|
"settings",
|
||||||
|
"shellexpand",
|
||||||
"util",
|
"util",
|
||||||
"workspace",
|
"workspace",
|
||||||
]
|
]
|
||||||
|
|
|
@ -76,9 +76,9 @@
|
||||||
"tab_size": 4,
|
"tab_size": 4,
|
||||||
// Settings specific to journaling
|
// Settings specific to journaling
|
||||||
"journal": {
|
"journal": {
|
||||||
// The directory in which the journal entries are created
|
// The path of the directory where journal entries are stored
|
||||||
"journal_directory": "always_home",
|
"path": "~",
|
||||||
// What format to present the hours in
|
// What format to display the hours in
|
||||||
// May take 2 values:
|
// May take 2 values:
|
||||||
// 1. hour12
|
// 1. hour12
|
||||||
// 2. hour24
|
// 2. hour24
|
||||||
|
|
|
@ -16,3 +16,4 @@ chrono = "0.4"
|
||||||
dirs = "4.0"
|
dirs = "4.0"
|
||||||
log = { version = "0.4.16", features = ["kv_unstable_serde"] }
|
log = { version = "0.4.16", features = ["kv_unstable_serde"] }
|
||||||
settings = { path = "../settings" }
|
settings = { path = "../settings" }
|
||||||
|
shellexpand = "2.1.0"
|
|
@ -1,8 +1,12 @@
|
||||||
use chrono::{Datelike, Local, NaiveTime, Timelike};
|
use chrono::{Datelike, Local, NaiveTime, Timelike};
|
||||||
use editor::{Autoscroll, Editor};
|
use editor::{Autoscroll, Editor};
|
||||||
use gpui::{actions, MutableAppContext};
|
use gpui::{actions, MutableAppContext};
|
||||||
use settings::{HourFormat, JournalDirectory, Settings};
|
use settings::{HourFormat, Settings};
|
||||||
use std::{fs::OpenOptions, path::PathBuf, str::FromStr, sync::Arc};
|
use std::{
|
||||||
|
fs::OpenOptions,
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
sync::Arc,
|
||||||
|
};
|
||||||
use util::TryFutureExt as _;
|
use util::TryFutureExt as _;
|
||||||
use workspace::AppState;
|
use workspace::AppState;
|
||||||
|
|
||||||
|
@ -14,10 +18,10 @@ pub fn init(app_state: Arc<AppState>, cx: &mut MutableAppContext) {
|
||||||
|
|
||||||
pub fn new_journal_entry(app_state: Arc<AppState>, cx: &mut MutableAppContext) {
|
pub fn new_journal_entry(app_state: Arc<AppState>, cx: &mut MutableAppContext) {
|
||||||
let settings = cx.global::<Settings>();
|
let settings = cx.global::<Settings>();
|
||||||
let journal_dir = match journal_dir(&settings.journal_overrides.journal_directory) {
|
let journal_dir = match journal_dir(&settings) {
|
||||||
Some(journal_dir) => journal_dir,
|
Some(journal_dir) => journal_dir,
|
||||||
None => {
|
None => {
|
||||||
log::error!("can't determine home directory");
|
log::error!("Can't determine journal directory");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -76,17 +80,18 @@ pub fn new_journal_entry(app_state: Arc<AppState>, cx: &mut MutableAppContext) {
|
||||||
.detach();
|
.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn journal_dir(a: &Option<JournalDirectory>) -> Option<PathBuf> {
|
fn journal_dir(settings: &Settings) -> Option<PathBuf> {
|
||||||
let journal_default_dir = dirs::home_dir()?.join("journal");
|
let journal_dir = settings
|
||||||
|
.journal_overrides
|
||||||
|
.path
|
||||||
|
.as_ref()
|
||||||
|
.unwrap_or(settings.journal_defaults.path.as_ref()?);
|
||||||
|
|
||||||
let journal_dir = match a {
|
let expanded_journal_dir = shellexpand::full(&journal_dir) //TODO handle this better
|
||||||
Some(JournalDirectory::Always { directory }) => {
|
.ok()
|
||||||
PathBuf::from_str(&directory).unwrap_or(journal_default_dir)
|
.map(|dir| Path::new(&dir.to_string()).to_path_buf().join("journal"));
|
||||||
}
|
|
||||||
_ => journal_default_dir,
|
|
||||||
};
|
|
||||||
|
|
||||||
Some(journal_dir)
|
return expanded_journal_dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn heading_entry(now: NaiveTime, hour_format: &Option<HourFormat>) -> String {
|
fn heading_entry(now: NaiveTime, hour_format: &Option<HourFormat>) -> String {
|
||||||
|
|
|
@ -103,17 +103,19 @@ pub enum Autosave {
|
||||||
OnWindowChange,
|
OnWindowChange,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Deserialize, JsonSchema)]
|
#[derive(Clone, Debug, Deserialize, JsonSchema)]
|
||||||
pub struct JournalSettings {
|
pub struct JournalSettings {
|
||||||
pub journal_directory: Option<JournalDirectory>,
|
pub path: Option<String>,
|
||||||
pub hour_format: Option<HourFormat>,
|
pub hour_format: Option<HourFormat>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, JsonSchema)]
|
impl Default for JournalSettings {
|
||||||
#[serde(rename_all = "snake_case")]
|
fn default() -> Self {
|
||||||
pub enum JournalDirectory {
|
Self {
|
||||||
AlwaysHome,
|
path: Some("~".into()),
|
||||||
Always { directory: String },
|
hour_format: Some(Default::default()),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, JsonSchema)]
|
#[derive(Clone, Debug, Deserialize, JsonSchema)]
|
||||||
|
@ -123,6 +125,12 @@ pub enum HourFormat {
|
||||||
Hour24,
|
Hour24,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for HourFormat {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::Hour12
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Deserialize, JsonSchema)]
|
#[derive(Clone, Debug, Default, Deserialize, JsonSchema)]
|
||||||
pub struct TerminalSettings {
|
pub struct TerminalSettings {
|
||||||
pub shell: Option<Shell>,
|
pub shell: Option<Shell>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue