Skip to content

Commit 6de9682

Browse files
committed
fix: block signals modified the store upon startup
1 parent 76b3e2a commit 6de9682

File tree

3 files changed

+194
-93
lines changed

3 files changed

+194
-93
lines changed

crates/rnote-ui/src/appwindow/mod.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,11 @@ impl RnAppWindow {
237237
// An initial tab (canvas).
238238
self.add_initial_tab();
239239

240+
// NOW we can re enable the signal handler for the tab
241+
240242
// Anything that needs to be done right before showing the appwindow
241243

242-
self.refresh_ui();
244+
self.refresh_ui(true);
243245
}
244246

245247
fn setup_icon_theme(&self) {
@@ -285,7 +287,7 @@ impl RnAppWindow {
285287
canvas.queue_resize();
286288
}
287289
if widget_flags.refresh_ui {
288-
self.refresh_ui();
290+
self.refresh_ui(false);
289291
}
290292
if widget_flags.store_modified {
291293
canvas.set_unsaved_changes(true);
@@ -383,7 +385,9 @@ impl RnAppWindow {
383385
/// adds the initial tab to the tabview
384386
fn add_initial_tab(&self) -> adw::TabPage {
385387
let wrapper = self.new_canvas_wrapper();
386-
self.append_wrapper_new_tab(&wrapper)
388+
let out = self.append_wrapper_new_tab(&wrapper);
389+
self.overlays().set_tab_signal_state(true);
390+
out
387391
}
388392

389393
/// Creates a new canvas wrapper without attaching it as a tab.
@@ -697,7 +701,7 @@ impl RnAppWindow {
697701
}
698702

699703
/// Refresh the UI from the global state and from the current active tab page.
700-
pub(crate) fn refresh_ui(&self) {
704+
pub(crate) fn refresh_ui(&self, startup: bool) {
701705
let canvas = self.active_tab_canvas();
702706

703707
self.overlays().penssidebar().brush_page().refresh_ui(self);
@@ -712,7 +716,7 @@ impl RnAppWindow {
712716
.selector_page()
713717
.refresh_ui(self);
714718
self.overlays().penssidebar().tools_page().refresh_ui(self);
715-
self.sidebar().settings_panel().refresh_ui(self);
719+
self.sidebar().settings_panel().refresh_ui(self, startup);
716720

717721
if let Some(canvas) = canvas {
718722
self.refresh_titles(&canvas);

crates/rnote-ui/src/overlays.rs

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ use gtk4::{
99
};
1010
use rnote_engine::ext::GdkRGBAExt;
1111
use rnote_engine::pens::PenStyle;
12-
use std::cell::{Cell, RefCell};
13-
use tracing::error;
12+
use std::cell::{Cell, Ref, RefCell};
13+
use tracing::{debug, error};
1414

1515
mod imp {
16+
use adw::glib::SignalHandlerId;
17+
1618
use super::*;
1719

1820
#[derive(Default, Debug, CompositeTemplate)]
@@ -33,6 +35,7 @@ mod imp {
3335
pub(crate) colorpicker: TemplateChild<RnColorPicker>,
3436
#[template_child]
3537
pub(crate) tabview: TemplateChild<adw::TabView>,
38+
pub(crate) tabview_connect_selected: RefCell<Option<SignalHandlerId>>,
3639
#[template_child]
3740
pub(crate) sidebar_box: TemplateChild<gtk4::Box>,
3841
#[template_child]
@@ -230,23 +233,31 @@ impl RnOverlays {
230233
fn setup_tabview(&self, appwindow: &RnAppWindow) {
231234
let imp = self.imp();
232235

233-
imp.tabview.connect_selected_page_notify(clone!(
234-
#[weak]
235-
appwindow,
236-
move |_| {
237-
let Some(active_tab_page) = appwindow.active_tab_page() else {
238-
return;
239-
};
240-
let active_canvaswrapper = active_tab_page
241-
.child()
242-
.downcast::<RnCanvasWrapper>()
243-
.unwrap();
244-
appwindow.tabs_set_unselected_inactive();
245-
let widget_flags = active_canvaswrapper.canvas().engine_mut().set_active(true);
246-
appwindow.handle_widget_flags(widget_flags, &active_canvaswrapper.canvas());
247-
appwindow.refresh_ui();
248-
}
249-
));
236+
imp.tabview_connect_selected
237+
.replace(Some(imp.tabview.connect_selected_page_notify(clone!(
238+
#[weak]
239+
appwindow,
240+
move |_| {
241+
let Some(active_tab_page) = appwindow.active_tab_page() else {
242+
return;
243+
};
244+
let active_canvaswrapper = active_tab_page
245+
.child()
246+
.downcast::<RnCanvasWrapper>()
247+
.unwrap();
248+
appwindow.tabs_set_unselected_inactive();
249+
let widget_flags = active_canvaswrapper.canvas().engine_mut().set_active(true);
250+
appwindow.handle_widget_flags(widget_flags, &active_canvaswrapper.canvas());
251+
appwindow.refresh_ui(false);
252+
// this is an issue
253+
// check if we can disable this call for the first tab
254+
}
255+
))));
256+
257+
// TODO : retest that this is responsible for the unsaved indicator in some way
258+
// we set the connect select to false initially
259+
// as we don't want the first added tab to send anything
260+
self.set_tab_signal_state(false);
250261

251262
imp.tabview.connect_page_attached(clone!(
252263
#[weak]
@@ -331,6 +342,26 @@ impl RnOverlays {
331342
));
332343
}
333344

345+
pub(crate) fn set_tab_signal_state(&self, state: bool) {
346+
let imp = self.imp();
347+
debug!("setting the tab signal state to {:?}", state);
348+
349+
Ref::map(imp.tabview_connect_selected.borrow(), |x| {
350+
match x {
351+
Some(handler_id) => {
352+
debug!("handler id exists applying");
353+
if state {
354+
imp.tabview.unblock_signal(handler_id)
355+
} else {
356+
imp.tabview.block_signal(handler_id)
357+
}
358+
}
359+
None => (),
360+
}
361+
x
362+
});
363+
}
364+
334365
pub(crate) fn progressbar_start_pulsing(&self) {
335366
const PULSE_INTERVAL: std::time::Duration = std::time::Duration::from_millis(300);
336367

0 commit comments

Comments
 (0)