added opening files
This commit is contained in:
parent
358fd4c983
commit
787cf5cd34
|
@ -66,7 +66,7 @@ impl Calcifer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_app_state(app_state: core::AppState) -> Self {
|
pub fn from_app_state(app_state: core::AppState, file_to_open: Option<PathBuf>) -> Self {
|
||||||
let mut new = Self {
|
let mut new = Self {
|
||||||
theme: DEFAULT_THEMES[min(app_state.theme, DEFAULT_THEMES.len() - 1)],
|
theme: DEFAULT_THEMES[min(app_state.theme, DEFAULT_THEMES.len() - 1)],
|
||||||
tabs: Vec::new(),
|
tabs: Vec::new(),
|
||||||
|
@ -87,6 +87,10 @@ impl Calcifer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(path) = file_to_open {
|
||||||
|
new.open_file(Some(&path));
|
||||||
|
}
|
||||||
|
|
||||||
if new.tabs == vec![] {
|
if new.tabs == vec![] {
|
||||||
new.open_file(None);
|
new.open_file(None);
|
||||||
}
|
}
|
||||||
|
|
13
src/main.rs
13
src/main.rs
|
@ -5,6 +5,7 @@ use egui::{
|
||||||
};
|
};
|
||||||
use homedir::get_my_home;
|
use homedir::get_my_home;
|
||||||
use std::{ops::Range, path::PathBuf, sync::Arc, thread, time};
|
use std::{ops::Range, path::PathBuf, sync::Arc, thread, time};
|
||||||
|
use std::env;
|
||||||
|
|
||||||
mod core;
|
mod core;
|
||||||
mod editor;
|
mod editor;
|
||||||
|
@ -51,10 +52,20 @@ fn main() -> Result<(), eframe::Error> {
|
||||||
core::AppState::default()
|
core::AppState::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let args: Vec<String> = env::args().collect();
|
||||||
|
let file_to_open = if args.len() > 1 {
|
||||||
|
println!("Opening file: {}", args[1].clone());
|
||||||
|
let mut path = env::current_dir().unwrap_or_default();
|
||||||
|
path.push(args[1].clone());
|
||||||
|
Some(path)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
eframe::run_native(
|
eframe::run_native(
|
||||||
&format!("Calcifer{}", TITLE),
|
&format!("Calcifer{}", TITLE),
|
||||||
options,
|
options,
|
||||||
Box::new(move |_cc| Box::from(Calcifer::from_app_state(app_state))),
|
Box::new(move |_cc| Box::from(Calcifer::from_app_state(app_state, file_to_open))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue