Commit e73991a3 authored by Bilal Elmoussaoui's avatar Bilal Elmoussaoui

Don't drop open project, fixes #65

parent 5a21f22d
Pipeline #201376 passed with stage
in 10 minutes and 59 seconds
......@@ -7,8 +7,8 @@ pub fn format_name(name: &str) -> String {
let name = name.trim_end_matches(".svg").trim_end_matches(".Source").split('.').last().unwrap();
let mut formatted_chars = vec![];
let mut chars = name.chars().into_iter();
name.chars().into_iter().for_each(|c| {
let mut chars = name.chars();
name.chars().for_each(|c| {
if c.is_uppercase() && !chars.next().unwrap_or(' ').is_uppercase() {
formatted_chars.push(' ');
}
......
......@@ -148,7 +148,7 @@ impl Project {
pub fn get_nightly(&self) -> anyhow::Result<gio::File> {
let dest_path = common::create_tmp(&format!("#nightly-{}-{}", 128.0, self.name()))?;
let dest = gio::File::new_for_path(&dest_path.clone());
let dest = gio::File::new_for_path(&dest_path);
let (_, hicolor) = self.get_hicolor(Some(dest_path))?;
......
......@@ -21,7 +21,7 @@ pub struct Window {
builder: gtk::Builder,
sender: glib::Sender<Action>,
previewer: ProjectPreviewer,
open_project: RefCell<Option<Rc<Project>>>,
open_project: Rc<RefCell<Option<Rc<Project>>>>,
exporter: ExportPopover,
monitor: RefCell<Option<gio::FileMonitor>>,
}
......@@ -38,7 +38,7 @@ impl Window {
sender,
previewer,
exporter: ExportPopover::new(),
open_project: RefCell::new(None),
open_project: Rc::new(RefCell::new(None)),
monitor: RefCell::new(None),
});
......@@ -61,15 +61,16 @@ impl Window {
let monitor = project.file.monitor_file(gio::FileMonitorFlags::all(), gio::NONE_CANCELLABLE).unwrap();
self.monitor.borrow_mut().replace(monitor);
self.open_project.borrow_mut().replace(project.clone());
self.open_project.borrow_mut().replace(project);
self.monitor
.borrow()
.as_ref()
.unwrap()
.connect_changed(clone!(@strong self.sender as sender => move |monitor, _, _, event| {
.connect_changed(clone!(@strong self.sender as sender, @strong self.open_project as project => move |monitor, _, _, event| {
if event == gio::FileMonitorEvent::Changed {
match Project::parse(project.file.clone()) {
let file = project.borrow().as_ref().unwrap().file.clone();
match Project::parse(file) {
Ok(project) => {
monitor.cancel();
send!(sender, Action::OpenProject(project));
......@@ -140,13 +141,13 @@ impl Window {
self.widget,
"export-save",
Some(&glib::VariantTy::new("s").unwrap()),
clone!(@strong self.open_project as project, @weak self.widget as parent => move |_, target| {
if let Some(ref project) = * project.borrow() {
clone!(@weak self.open_project as project, @weak self.widget as parent => move |_, target| {
if let Some(project) = project.borrow().as_ref() {
let project_type = target.unwrap().get_str().unwrap();
if project.export(project_type, &parent.upcast::<gtk::Window>()).is_err() {
warn!("Failed to export the project");
}
}
};
})
);
......@@ -165,13 +166,17 @@ impl Window {
action!(
self.widget,
"refresh",
clone!(@strong self.sender as sender, @strong self.open_project as project => move |_, _| {
if let Some(ref project) = * project.borrow() {
clone!(@strong self.sender as sender, @weak self.open_project as project,
@strong self.exporter as exporter, @strong self.previewer as previewer => move |_, _| {
if let Some(project) = project.borrow().as_ref() {
match Project::parse(project.file.clone()) {
Ok(project) => send!(sender, Action::OpenProject(project)),
Ok(project) => {
previewer.preview(&project);
exporter.set_project(&project);
},
Err(err) => warn!("Failed to parse the project {}", err),
}
}
};
})
);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment