Skip to content

Commit

Permalink
Added open/save/save as
Browse files Browse the repository at this point in the history
  • Loading branch information
vaneri-9 committed Jul 25, 2023
1 parent 5a5a044 commit db61e9b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 0 additions & 2 deletions src/gui_egui/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ pub struct Gui {
pub simulator: Option<Simulator>,
pub path: PathBuf,
// History, acts like a stack
pub history: Vec<Vec<u32>>,
pub scale: f32,
// When the ui elements change size
pub ui_change: bool,
Expand All @@ -30,7 +29,6 @@ pub fn gui(cs: ComponentStore, path: &PathBuf) -> Result<(), eframe::Error> {
let gui = Gui {
path,
simulator: Some(simulator),
history: vec![],
scale: 1.0f32,
ui_change: true,
offset: egui::Vec2 { x: 0f32, y: 0f32 },
Expand Down
15 changes: 10 additions & 5 deletions src/gui_egui/keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,10 @@ impl Shortcuts {
pub fn file_new_fn(_gui: &mut Gui) {}
pub fn file_open_fn(gui: &mut Gui) {
let files = FileDialog::new().add_filter("json", &["json"]).pick_file();
let mut path = PathBuf::default();
if let Some(path_buf) = files {
path = path_buf;
gui.path = path_buf;
}
let cs = ComponentStore::load_file(&path);
let cs = ComponentStore::load_file(&gui.path);
match gui.editor_use {
true => {
if let Some(e) = gui.editor.as_mut() {
Expand All @@ -251,7 +250,7 @@ pub fn file_save_fn(gui: &mut Gui) {
ComponentStore {
store: e.components.clone(),
}
.save_file(&PathBuf::from("file.json"))
.save_file(&gui.path)
}
}
false => ComponentStore {
Expand All @@ -260,7 +259,13 @@ pub fn file_save_fn(gui: &mut Gui) {
.save_file(&PathBuf::from("file.json")),
}
}
pub fn file_save_as_fn(_gui: &mut Gui) {}
pub fn file_save_as_fn(gui: &mut Gui) {
let files = FileDialog::new().add_filter("json", &["json"]).save_file();
if let Some(path_buf) = files {
gui.path = path_buf;
file_save_fn(gui);
}
}
pub fn file_editor_toggle_fn(gui: &mut Gui) {
// Auto-save
file_save_fn(gui);
Expand Down

0 comments on commit db61e9b

Please sign in to comment.