Skip to content

Commit

Permalink
split setup tabview function
Browse files Browse the repository at this point in the history
  • Loading branch information
flxzt committed Jan 14, 2023
1 parent b9923bc commit c9c9f76
Showing 1 changed file with 50 additions and 51 deletions.
101 changes: 50 additions & 51 deletions rnote-ui/src/overlays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,59 +142,9 @@ impl RnoteOverlays {
}

pub(crate) fn init(&self, appwindow: &RnoteAppWindow) {
let imp = self.imp();

self.setup_pens_toggles(appwindow);
self.setup_colorpicker(appwindow);

imp.tabview
.connect_selected_page_notify(clone!(@weak appwindow => move |_tabview| {
let canvas = appwindow.active_tab().canvas();

appwindow.clear_rendering_inactive_tabs();
canvas.regenerate_background_pattern();
canvas.update_engine_rendering();
adw::prelude::ActionGroupExt::activate_action(&appwindow, "sync-state-active-tab", None);
}));

imp.tabview
.connect_page_attached(clone!(@weak appwindow => move |_tabview, page, _| {
let canvaswrapper = page.child().downcast::<RnoteCanvasWrapper>().unwrap();

canvaswrapper.init_reconnect(&appwindow);
canvaswrapper.connect_to_tab_page(page);
adw::prelude::ActionGroupExt::activate_action(&appwindow, "sync-state-active-tab", None);
}));

imp.tabview
.connect_page_detached(clone!(@weak appwindow => move |_tabview, page, _| {
let canvaswrapper = page.child().downcast::<RnoteCanvasWrapper>().unwrap();

canvaswrapper.disconnect_handlers(&appwindow);
}));

imp.tabview.connect_close_page(
clone!(@weak appwindow => @default-return true, move |tabview, page| {
if !page.is_pinned() {
if page
.child()
.downcast::<RnoteCanvasWrapper>()
.unwrap()
.canvas()
.unsaved_changes()
{
// We close after showing the dialog
dialogs::dialog_close_tab(&appwindow, page);
} else {
tabview.close_page_finish(page, true);
}
} else {
tabview.close_page_finish(page, false);
}

true
}),
);
self.setup_tabview(appwindow);
}

fn setup_pens_toggles(&self, appwindow: &RnoteAppWindow) {
Expand Down Expand Up @@ -297,6 +247,55 @@ impl RnoteOverlays {
);
}

fn setup_tabview(&self, appwindow: &RnoteAppWindow) {
let imp = self.imp();

imp.tabview
.connect_selected_page_notify(clone!(@weak appwindow => move |_tabview| {
let canvas = appwindow.active_tab().canvas();

appwindow.clear_rendering_inactive_tabs();
canvas.regenerate_background_pattern();
canvas.update_engine_rendering();
adw::prelude::ActionGroupExt::activate_action(&appwindow, "sync-state-active-tab", None);
}));

imp.tabview
.connect_page_attached(clone!(@weak appwindow => move |_tabview, page, _| {
let canvaswrapper = page.child().downcast::<RnoteCanvasWrapper>().unwrap();

canvaswrapper.init_reconnect(&appwindow);
canvaswrapper.connect_to_tab_page(page);
adw::prelude::ActionGroupExt::activate_action(&appwindow, "sync-state-active-tab", None);
}));

imp.tabview
.connect_page_detached(clone!(@weak appwindow => move |_tabview, page, _| {
let canvaswrapper = page.child().downcast::<RnoteCanvasWrapper>().unwrap();

canvaswrapper.disconnect_handlers(&appwindow);
}));

imp.tabview.connect_close_page(
clone!(@weak appwindow => @default-return true, move |tabview, page| {
if page
.child()
.downcast::<RnoteCanvasWrapper>()
.unwrap()
.canvas()
.unsaved_changes()
{
// close_tab_finish() is called in the dialog
dialogs::dialog_close_tab(&appwindow, page);
} else {
tabview.close_page_finish(page, true);
}

true
}),
);
}

pub(crate) fn start_pulsing_progressbar(&self) {
const PROGRESS_BAR_PULSE_INTERVAL: std::time::Duration =
std::time::Duration::from_millis(300);
Expand Down

0 comments on commit c9c9f76

Please sign in to comment.