Commit f2a3876a authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Proper stack management

parent fd336359
......@@ -1364,6 +1364,9 @@ class SDL_View(QtGui.QGraphicsView, object):
top_scene = lambda self: (self.scene_stack[0][0] if self.scene_stack
else self.scene())
is_model_clean = lambda self: not any(not sc.undo_stack.isClean() for sc in
chain([self.top_scene()], self.top_scene().all_nested_scenes))
def set_toolbar(self):
''' Define the toolbar depending on the context '''
......@@ -1703,6 +1706,7 @@ class SDL_View(QtGui.QGraphicsView, object):
if not autosave:
for each in scene.all_nested_scenes:
print 'clean',
LOG.debug('Auto-saving backup file completed:' + filename)
......@@ -1781,14 +1785,6 @@ class SDL_View(QtGui.QGraphicsView, object):
def is_model_clean(self):
''' Check recursively if anything has changed in any scene '''
scene = self.top_scene()
for each in chain([scene], scene.all_nested_scenes):
if not each.undo_stack.isClean():
return False
return True
def propose_to_save(self):
''' Display a dialog to let the user save his diagram '''
msg_box = QtGui.QMessageBox(self)
......@@ -1809,9 +1805,7 @@ class SDL_View(QtGui.QGraphicsView, object):
def new_diagram(self):
''' If model state is clean, reset current diagram '''
if not self.is_model_clean():
# If changes occured since last save, pop up a window
if not self.propose_to_save():
if not self.is_model_clean() and not self.propose_to_save():
return False
self.scene_stack = []
......@@ -2179,16 +2173,14 @@ class OG_MainWindow(QtGui.QMainWindow, object):
# pylint: disable=C0103
def closeEvent(self, event):
''' Close main application '''
if not self.view.is_model_clean():
if not self.view.propose_to_save():
if not self.view.is_model_clean() and not self.view.propose_to_save():
# Clear the list of top-level symbols to avoid possible exit-crash
# due to pyside badly handling items that are not part of any scene
# Also clear undo stack that may keep reference to items
LOG.debug('Bye bye!')
super(OG_MainWindow, self).closeEvent(event)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment