diff --git a/rnote-ui/src/app/mod.rs b/rnote-ui/src/app/mod.rs index 4f38f9a012..ef94d115be 100644 --- a/rnote-ui/src/app/mod.rs +++ b/rnote-ui/src/app/mod.rs @@ -72,9 +72,14 @@ mod imp { /// Initializes and shows a new app window fn new_appwindow_init_show(&self, input_file: Option) { let appwindow = RnoteAppWindow::new(self.instance().upcast_ref::()); - appwindow.init(input_file); + appwindow.init(); appwindow.show(); + + // Loading in input file in the first tab, if Some + if let Some(input_file) = input_file { + appwindow.open_file_w_dialogs(input_file, None, false); + } } fn setup_logging(&self) { diff --git a/rnote-ui/src/appwindow/appwindowactions.rs b/rnote-ui/src/appwindow/appwindowactions.rs index 50df010927..3e3d64d1bb 100644 --- a/rnote-ui/src/appwindow/appwindowactions.rs +++ b/rnote-ui/src/appwindow/appwindowactions.rs @@ -949,7 +949,7 @@ impl RnoteAppWindow { for file_path in file_paths { log::debug!("pasting from path: {:?}", file_path); - appwindow.open_file_w_dialogs(gio::File::for_path(&file_path), None); + appwindow.open_file_w_dialogs(gio::File::for_path(&file_path), None, true); } } Ok(None) => {} diff --git a/rnote-ui/src/appwindow/mod.rs b/rnote-ui/src/appwindow/mod.rs index 7628ee5ba2..74394e2b9d 100644 --- a/rnote-ui/src/appwindow/mod.rs +++ b/rnote-ui/src/appwindow/mod.rs @@ -757,7 +757,7 @@ impl RnoteAppWindow { } // Must be called after application is associated with it else it fails - pub(crate) fn init(&self, input_file: Option) { + pub(crate) fn init(&self) { let imp = self.imp(); imp.overlays.get().init(self); @@ -802,11 +802,6 @@ impl RnoteAppWindow { removed_id.remove(); } - // Loading in input file, if Some - if let Some(input_file) = input_file { - self.open_file_w_dialogs(input_file, None); - } - self.init_misc(); } @@ -1022,10 +1017,14 @@ impl RnoteAppWindow { self.mainheader().main_title().set_subtitle(&subtitle); } + /// Opens the file, with import dialogs when appropriate. + /// + /// When the file is a rnote save file, `rnote_file_new_tab` determines if a new tab is opened, or if it overwrites the current active one. pub(crate) fn open_file_w_dialogs( &self, input_file: gio::File, target_pos: Option>, + rnote_file_new_tab: bool, ) { match crate::utils::FileType::lookup_file_type(&input_file) { crate::utils::FileType::RnoteFile => { @@ -1038,13 +1037,17 @@ impl RnoteAppWindow { if let Some(page) = self.tabs_query_file_opened(input_file_path) { self.overlays().tabview().set_selected_page(&page); } else { - // open a new tab for rnote files - let new_tab = self.new_tab(); - let canvas = new_tab - .child() - .downcast::() - .unwrap() - .canvas(); + let canvas = if rnote_file_new_tab { + // open a new tab for rnote files + let new_tab = self.new_tab(); + new_tab + .child() + .downcast::() + .unwrap() + .canvas() + } else { + self.active_tab().canvas() + }; if let Err(e) = self.load_in_file(input_file, target_pos, &canvas) { log::error!( @@ -1094,7 +1097,7 @@ impl RnoteAppWindow { /// Loads in a file of any supported type into the engine of the given canvas. /// - /// ! if the file is a rnote save file, it will overwrite the current state so there should be a user prompt to confirm before this is called + /// ! if the file is a rnote save file, it will overwrite the state in the active tab so there should be a user prompt to confirm before this is called pub(crate) fn load_in_file( &self, file: gio::File, diff --git a/rnote-ui/src/canvas/mod.rs b/rnote-ui/src/canvas/mod.rs index 9d74652d6d..fef0382ddf 100644 --- a/rnote-ui/src/canvas/mod.rs +++ b/rnote-ui/src/canvas/mod.rs @@ -1163,7 +1163,7 @@ impl RnoteCanvas { na::point![x,y]).coords; if value.is::() { - appwindow.open_file_w_dialogs(value.get::().unwrap(), Some(pos)); + appwindow.open_file_w_dialogs(value.get::().unwrap(), Some(pos), true); return true; } else if value.is::() { diff --git a/rnote-ui/src/dialogs/import.rs b/rnote-ui/src/dialogs/import.rs index 4494610bb5..cb96bf7309 100644 --- a/rnote-ui/src/dialogs/import.rs +++ b/rnote-ui/src/dialogs/import.rs @@ -105,7 +105,7 @@ pub(crate) fn filechooser_open_doc(appwindow: &RnoteAppWindow) { match responsetype { ResponseType::Accept => { if let Some(input_file) = filechooser.file() { - appwindow.open_file_w_dialogs(input_file, None); + appwindow.open_file_w_dialogs(input_file, None, true); } }, _ => {} @@ -158,7 +158,7 @@ pub(crate) fn filechooser_import_file(appwindow: &RnoteAppWindow) { match responsetype { ResponseType::Accept => { if let Some(input_file) = filechooser.file() { - appwindow.open_file_w_dialogs(input_file, None); + appwindow.open_file_w_dialogs(input_file, None, true); } } _ => { diff --git a/rnote-ui/src/workspacebrowser/filerow/actions/open.rs b/rnote-ui/src/workspacebrowser/filerow/actions/open.rs index 398490fe5f..3c0d6417aa 100644 --- a/rnote-ui/src/workspacebrowser/filerow/actions/open.rs +++ b/rnote-ui/src/workspacebrowser/filerow/actions/open.rs @@ -9,7 +9,7 @@ pub(crate) fn open(filerow: &FileRow, appwindow: &RnoteAppWindow) -> gio::Simple action_open_file.connect_activate( clone!(@weak filerow as filerow, @weak appwindow => move |_action_open_file, _| { if let Some(current_file) = filerow.current_file() { - appwindow.open_file_w_dialogs(current_file, None); + appwindow.open_file_w_dialogs(current_file, None, true); } }), ); diff --git a/rnote-ui/src/workspacebrowser/mod.rs b/rnote-ui/src/workspacebrowser/mod.rs index 9f173e1a30..e1aa16aa8c 100644 --- a/rnote-ui/src/workspacebrowser/mod.rs +++ b/rnote-ui/src/workspacebrowser/mod.rs @@ -391,7 +391,7 @@ fn setup_file_rows(wb: &WorkspaceBrowser, appwindow: &RnoteAppWindow) { .downcast::().expect("selected item in primary_list is not of Type `gio::FileInfo`"); if let Some(input_file) = fileinfo.attribute_object("standard::file") { - appwindow.open_file_w_dialogs(input_file.downcast::().unwrap(), None); + appwindow.open_file_w_dialogs(input_file.downcast::().unwrap(), None, true); }; multisorter.changed(SorterChange::Different);