Skip to content

Commit

Permalink
fix modal dialogs when importing files on window creation,
Browse files Browse the repository at this point in the history
load them in the first tab instead of creating a second
  • Loading branch information
flxzt committed Jan 16, 2023
1 parent 27c49a9 commit e22f15b
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 21 deletions.
7 changes: 6 additions & 1 deletion rnote-ui/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,14 @@ mod imp {
/// Initializes and shows a new app window
fn new_appwindow_init_show(&self, input_file: Option<gio::File>) {
let appwindow = RnoteAppWindow::new(self.instance().upcast_ref::<gtk4::Application>());
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) {
Expand Down
2 changes: 1 addition & 1 deletion rnote-ui/src/appwindow/appwindowactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {}
Expand Down
31 changes: 17 additions & 14 deletions rnote-ui/src/appwindow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<gio::File>) {
pub(crate) fn init(&self) {
let imp = self.imp();

imp.overlays.get().init(self);
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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<na::Vector2<f64>>,
rnote_file_new_tab: bool,
) {
match crate::utils::FileType::lookup_file_type(&input_file) {
crate::utils::FileType::RnoteFile => {
Expand All @@ -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::<RnoteCanvasWrapper>()
.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::<RnoteCanvasWrapper>()
.unwrap()
.canvas()
} else {
self.active_tab().canvas()
};

if let Err(e) = self.load_in_file(input_file, target_pos, &canvas) {
log::error!(
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion rnote-ui/src/canvas/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ impl RnoteCanvas {
na::point![x,y]).coords;

if value.is::<gio::File>() {
appwindow.open_file_w_dialogs(value.get::<gio::File>().unwrap(), Some(pos));
appwindow.open_file_w_dialogs(value.get::<gio::File>().unwrap(), Some(pos), true);

return true;
} else if value.is::<String>() {
Expand Down
4 changes: 2 additions & 2 deletions rnote-ui/src/dialogs/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
},
_ => {}
Expand Down Expand Up @@ -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);
}
}
_ => {
Expand Down
2 changes: 1 addition & 1 deletion rnote-ui/src/workspacebrowser/filerow/actions/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}),
);
Expand Down
2 changes: 1 addition & 1 deletion rnote-ui/src/workspacebrowser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ fn setup_file_rows(wb: &WorkspaceBrowser, appwindow: &RnoteAppWindow) {
.downcast::<gio::FileInfo>().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::<gio::File>().unwrap(), None);
appwindow.open_file_w_dialogs(input_file.downcast::<gio::File>().unwrap(), None, true);
};

multisorter.changed(SorterChange::Different);
Expand Down

0 comments on commit e22f15b

Please sign in to comment.