Skip to content

Commit

Permalink
Fix file pickers in the configuration editor
Browse files Browse the repository at this point in the history
  • Loading branch information
kelpsyberry committed Jan 20, 2024
1 parent 2461ab9 commit b2e4446
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
22 changes: 13 additions & 9 deletions frontend/desktop/src/ui/config_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,11 @@ macro_rules! home_path {
}

macro_rules! opt_home_path {
(nonoverridable $id: ident) => {
(nonoverridable $id: ident, $is_folder: expr) => {
setting::OptHomePath::new(
|config| config!(config, &$id).as_ref(),
|config, value| set_config!(config, $id, value),
$is_folder,
)
};
}
Expand Down Expand Up @@ -403,7 +404,7 @@ macro_rules! overridable {
}

macro_rules! sys_path {
($label: literal, $field: ident) => {
($label: literal, $field: ident, $is_folder: expr) => {
setting::Overridable::new(
concat!($label, ": "),
(
Expand All @@ -416,6 +417,7 @@ macro_rules! sys_path {
})
});
},
$is_folder,
),
setting::OptHomePath::new(
|config| {
Expand All @@ -435,6 +437,7 @@ macro_rules! sys_path {
})
});
},
$is_folder,
),
),
|config| config.sys_paths.inner().game().$field.is_some(),
Expand Down Expand Up @@ -487,13 +490,14 @@ impl PathsSettings {
imgui_config_path: nonoverridable!(
"ImGui config path",
imgui_config_path,
opt_home_path
opt_home_path,
false
),
game_db_path: nonoverridable!("Game database path", game_db_path, opt_home_path),
sys_dir_path: sys_path!("System dir path", dir),
arm7_bios_path: sys_path!("ARM7 BIOS path", arm7_bios),
arm9_bios_path: sys_path!("ARM9 BIOS path", arm9_bios),
firmware_path: sys_path!("Firmware path", firmware),
game_db_path: nonoverridable!("Game database path", game_db_path, opt_home_path, false),
sys_dir_path: sys_path!("System dir path", dir, true),
arm7_bios_path: sys_path!("ARM7 BIOS path", arm7_bios, false),
arm9_bios_path: sys_path!("ARM9 BIOS path", arm9_bios, false),
firmware_path: sys_path!("Firmware path", firmware, false),
}
}
}
Expand Down Expand Up @@ -653,7 +657,7 @@ impl SavesSettings {
),
save_dir_path: nonoverridable!("Save directory path", save_dir_path, home_path),
savestate_dir_path: nonoverridable!(
"Saved state directory path",
"Savestate directory path",
savestate_dir_path,
home_path
),
Expand Down
23 changes: 20 additions & 3 deletions frontend/desktop/src/ui/config_editor/setting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,20 @@ pub struct OptHomePath {
pub get: fn(&Config) -> Option<&HomePathBuf>,
pub set: fn(&mut Config, Option<HomePathBuf>),
buffer: StdString,
is_folder: bool,
}

impl OptHomePath {
pub const fn new(
get: fn(&Config) -> Option<&HomePathBuf>,
set: fn(&mut Config, Option<HomePathBuf>),
is_folder: bool,
) -> Self {
OptHomePath {
get,
set,
buffer: StdString::new(),
is_folder,
}
}
}
Expand Down Expand Up @@ -179,17 +182,31 @@ impl RawSetting for OptHomePath {

ui.enabled(path.is_some(), || {
if ui.button("\u{f08e}") {
let _ = opener::open(&path.unwrap().0);
let path = &path.unwrap().0;
let _ = opener::open(if self.is_folder {
path
} else {
path.parent().unwrap_or(path)
});
}
if ui.is_item_hovered_with_flags(ItemHoveredFlags::ALLOW_WHEN_DISABLED) {
ui.tooltip_text("Open");
ui.tooltip_text(if self.is_folder {
"Open folder"
} else {
"Open containing folder"
});
}
});

ui.same_line();

if ui.button("\u{f07c}") {
if let Some(path) = FileDialog::new().pick_folder() {
let path = if self.is_folder {
FileDialog::new().pick_folder()
} else {
FileDialog::new().pick_file()
};
if let Some(path) = path {
new_value = Some(Some(HomePathBuf(path)));
}
}
Expand Down

0 comments on commit b2e4446

Please sign in to comment.