@@ -226,10 +226,10 @@ def reload_from_disk(self):
226226 return
227227 disk_pixbuf = GdkPixbuf .Pixbuf .new_from_file (self .get_file_path ())
228228 self ._load_pixbuf_common (disk_pixbuf )
229- self .window .update_picture_title ()
230229 self .use_stable_pixbuf ()
231230 self .update ()
232231 self .remember_current_state ()
232+ self .window .update_picture_title ()
233233
234234 def try_load_file (self , gfile ):
235235 try :
@@ -250,6 +250,12 @@ def try_load_file(self, gfile):
250250 self ._update_can_reload_action ()
251251
252252 def _connect_gfile_monitoring (self ):
253+ if self ._gfile_monitor :
254+ # Probably no need to reconnect it again.
255+ # XXX est-il vraiment bon ? on devrait le déconnecter, le refaire ?
256+ # Tout cela n'est pas débuggable parce que le fichier que je traque
257+ # est le proxy de la sandbox (/run/user/1000/...)
258+ self ._gfile_monitor = None
253259 flags = Gio .FileMonitorFlags .WATCH_MOUNTS
254260 self ._gfile_monitor = self .gfile .monitor (flags )
255261 self ._gfile_monitor .connect ('changed' , self .reveal_reload_message )
@@ -258,13 +264,29 @@ def disable_monitoring(self):
258264 self ._monitoring_disabled = True
259265
260266 def enable_monitoring (self ):
267+ """This should only be called initially, or asynchronously, or in case
268+ of an exception"""
261269 self ._monitoring_disabled = False
262270
263271 def reveal_reload_message (self , * args ):
272+ """This method is called when the file changed, which is async: we can't
273+ enable or disable the monitoring in the DrSavingManager's method because
274+ saving the pixbuf takes longer to trigger the 'changed' signal on the
275+ monitor than it takes to run the end of the saving process."""
276+ # I'm not sure this lock is 100% correct because i'm monitoring the
277+ # portal proxy file when testing with flatpak.
264278 if self ._monitoring_disabled :
265- # I'm not sure this lock is 100% correct because i'm monitoring the
266- # portal proxy file when testing with flatpak. Better than nothing.
279+ # The idea is that the message banner is temporarily disabled until
280+ # the monitor sends its next "changed" event, which we expect (it's
281+ # the one from our own saving process).
267282 if args [3 ] != Gio .FileMonitorEvent .CHANGED :
283+ try :
284+ self .reload_from_disk ()
285+ except Exception as ex :
286+ print (e )
287+ # Context: an error message
288+ self ._window .reveal_message (_ ("Failed to reload %s" ) % \
289+ self .gfile .get_path ())
268290 self .enable_monitoring ()
269291 return
270292 self ._update_can_reload_action ()
@@ -556,12 +578,11 @@ def on_enter_image(self, *args):
556578 def on_leave_image (self , * args ):
557579 self .window .set_cursor (False )
558580
559- def post_save (self , gfile ):
581+ def pre_save (self , gfile ):
582+ """The gfile is set before saving, because reveal_reload_message expects
583+ self.gfile to be correct."""
560584 self .gfile = gfile
561585 self ._connect_gfile_monitoring ()
562- self .use_stable_pixbuf ()
563- self .update ()
564- self .reload_from_disk ()
565586
566587 def set_surface_as_stable_pixbuf (self ):
567588 w = self .surface .get_width ()
0 commit comments