@@ -9,10 +9,12 @@ use gtk4::{
99} ;
1010use rnote_engine:: ext:: GdkRGBAExt ;
1111use 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
1515mod 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