Close app if no config is selected
This commit is contained in:
parent
729c8082c2
commit
5e602d1540
|
|
@ -160,14 +160,18 @@ impl ConfigFile {
|
||||||
};
|
};
|
||||||
|
|
||||||
let default_config = (&*globals::CONFIG_NAME.read().unwrap()).to_string();
|
let default_config = (&*globals::CONFIG_NAME.read().unwrap()).to_string();
|
||||||
let config_name =
|
let config_name = if (map.len() > 1 || !map.contains_key(&default_config))
|
||||||
if (map.len() > 1 || !map.contains_key(&default_config)) && map.len() != 0 {
|
&& map.len() != 0
|
||||||
ConfigPicker::new(map.keys().map(|a| a.to_owned()).collect())
|
{
|
||||||
.selected()
|
let picked = ConfigPicker::new(map.keys().map(|a| a.to_owned()).collect()).selected;
|
||||||
.unwrap_or(default_config)
|
let picked = picked.borrow();
|
||||||
} else {
|
match &*picked {
|
||||||
default_config
|
Some(v) => v.to_owned(),
|
||||||
};
|
None => std::process::exit(0),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
default_config
|
||||||
|
};
|
||||||
|
|
||||||
if let Some(config) = map.get(&config_name) {
|
if let Some(config) = map.get(&config_name) {
|
||||||
*globals::CONFIG_NAME.write().unwrap() = config_name;
|
*globals::CONFIG_NAME.write().unwrap() = config_name;
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@
|
||||||
along with Post Maker. If not, see <https://www.gnu.org/licenses/>
|
along with Post Maker. If not, see <https://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use std::{cell::RefCell, rc::Rc};
|
||||||
|
|
||||||
use crate::globals;
|
use crate::globals;
|
||||||
use fltk::{
|
use fltk::{
|
||||||
app,
|
app,
|
||||||
|
|
@ -26,9 +28,9 @@ use fltk::{
|
||||||
|
|
||||||
pub(crate) struct ConfigPicker {
|
pub(crate) struct ConfigPicker {
|
||||||
pub(crate) win: Window,
|
pub(crate) win: Window,
|
||||||
|
pub(crate) selected: Rc<RefCell<Option<String>>>,
|
||||||
pub(crate) browse: Browser,
|
pub(crate) browse: Browser,
|
||||||
pub(crate) apply_btn: Button,
|
pub(crate) apply_btn: Button,
|
||||||
pub(crate) configs: Vec<String>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ConfigPicker {
|
impl ConfigPicker {
|
||||||
|
|
@ -72,9 +74,9 @@ impl ConfigPicker {
|
||||||
|
|
||||||
let mut config_picker = Self {
|
let mut config_picker = Self {
|
||||||
win,
|
win,
|
||||||
|
selected: Rc::new(RefCell::new(browse.selected_text())),
|
||||||
browse,
|
browse,
|
||||||
apply_btn,
|
apply_btn,
|
||||||
configs,
|
|
||||||
};
|
};
|
||||||
config_picker.event();
|
config_picker.event();
|
||||||
|
|
||||||
|
|
@ -90,14 +92,16 @@ impl ConfigPicker {
|
||||||
self.apply_btn.set_callback(move |_| {
|
self.apply_btn.set_callback(move |_| {
|
||||||
win.hide();
|
win.hide();
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn selected(&self) -> Option<String> {
|
let selected = Rc::clone(&self.selected);
|
||||||
let idx = self.browse.value();
|
self.browse.set_callback(move |f| {
|
||||||
if idx == 0 {
|
*selected.borrow_mut() = f.selected_text();
|
||||||
None
|
});
|
||||||
} else {
|
|
||||||
self.configs.get(idx as usize - 1).map(|a| a.to_owned())
|
let selected = Rc::clone(&self.selected);
|
||||||
}
|
self.win.set_callback(move |f| {
|
||||||
|
*selected.borrow_mut() = None;
|
||||||
|
f.hide();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue