481 if result is not None: |
481 if result is not None: |
482 first_line, first_column, last_line, last_column, error = result.groups() |
482 first_line, first_column, last_line, last_column, error = result.groups() |
483 infos = self.PluginRoot.ShowError(self.Log, |
483 infos = self.PluginRoot.ShowError(self.Log, |
484 (int(first_line), int(first_column)), |
484 (int(first_line), int(first_column)), |
485 (int(last_line), int(last_column))) |
485 (int(last_line), int(last_column))) |
486 |
486 |
|
487 ## Function displaying an Error dialog in PLCOpenEditor. |
|
488 # @return False if closing cancelled. |
|
489 def CheckSaveBeforeClosing(self, title=_("Close Project")): |
|
490 if self.PluginRoot.ProjectTestModified(): |
|
491 dialog = wx.MessageDialog(self, |
|
492 _("There are changes, do you want to save?"), |
|
493 title, |
|
494 wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION) |
|
495 answer = dialog.ShowModal() |
|
496 dialog.Destroy() |
|
497 if answer == wx.ID_YES: |
|
498 self.PluginRoot.SaveProject() |
|
499 elif answer == wx.ID_CANCEL: |
|
500 return False |
|
501 return True |
|
502 |
487 def OnCloseFrame(self, event): |
503 def OnCloseFrame(self, event): |
488 if self.PluginRoot is not None: |
504 if self.PluginRoot is None or self.CheckSaveBeforeClosing(_("Close Application")): |
489 if self.PluginRoot.ProjectTestModified(): |
505 self.KillLocalRuntime() |
490 dialog = wx.MessageDialog(self, |
506 event.Skip() |
491 _("Save changes ?"), |
507 else: |
492 _("Close Application"), |
508 event.Veto() |
493 wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION) |
|
494 answer = dialog.ShowModal() |
|
495 dialog.Destroy() |
|
496 if answer == wx.ID_YES: |
|
497 self.PluginRoot.SaveProject() |
|
498 event.Skip() |
|
499 elif answer == wx.ID_NO: |
|
500 event.Skip() |
|
501 return |
|
502 else: |
|
503 event.Veto() |
|
504 return |
|
505 |
|
506 self.KillLocalRuntime() |
|
507 |
|
508 event.Skip() |
|
509 |
509 |
510 def OnMoveWindow(self, event): |
510 def OnMoveWindow(self, event): |
511 self.GetBestSize() |
511 self.GetBestSize() |
512 self.RefreshScrollBars() |
512 self.RefreshScrollBars() |
513 event.Skip() |
513 event.Skip() |
1298 self.PluginRoot = None |
1298 self.PluginRoot = None |
1299 self.Log.flush() |
1299 self.Log.flush() |
1300 self.DebugVariablePanel.SetDataProducer(None) |
1300 self.DebugVariablePanel.SetDataProducer(None) |
1301 |
1301 |
1302 def OnNewProjectMenu(self, event): |
1302 def OnNewProjectMenu(self, event): |
|
1303 if self.PluginRoot is not None and not self.CheckSaveBeforeClosing(): |
|
1304 return |
|
1305 |
1303 if not self.Config.HasEntry("lastopenedfolder"): |
1306 if not self.Config.HasEntry("lastopenedfolder"): |
1304 defaultpath = os.path.expanduser("~") |
1307 defaultpath = os.path.expanduser("~") |
1305 else: |
1308 else: |
1306 defaultpath = self.Config.Read("lastopenedfolder") |
1309 defaultpath = self.Config.Read("lastopenedfolder") |
1307 |
1310 |
1323 self.ResetView() |
1326 self.ResetView() |
1324 self.ShowErrorMessage(result) |
1327 self.ShowErrorMessage(result) |
1325 self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU) |
1328 self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU) |
1326 |
1329 |
1327 def OnOpenProjectMenu(self, event): |
1330 def OnOpenProjectMenu(self, event): |
|
1331 if self.PluginRoot is not None and not self.CheckSaveBeforeClosing(): |
|
1332 return |
|
1333 |
1328 if not self.Config.HasEntry("lastopenedfolder"): |
1334 if not self.Config.HasEntry("lastopenedfolder"): |
1329 defaultpath = os.path.expanduser("~") |
1335 defaultpath = os.path.expanduser("~") |
1330 else: |
1336 else: |
1331 defaultpath = self.Config.Read("lastopenedfolder") |
1337 defaultpath = self.Config.Read("lastopenedfolder") |
1332 |
1338 |
1351 self.ShowErrorMessage(_("\"%s\" folder is not a valid Beremiz project\n") % projectpath) |
1357 self.ShowErrorMessage(_("\"%s\" folder is not a valid Beremiz project\n") % projectpath) |
1352 self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU) |
1358 self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU) |
1353 dialog.Destroy() |
1359 dialog.Destroy() |
1354 |
1360 |
1355 def OnCloseProjectMenu(self, event): |
1361 def OnCloseProjectMenu(self, event): |
1356 if self.PluginRoot is not None: |
1362 if self.PluginRoot is not None and not self.CheckSaveBeforeClosing(): |
1357 if self.PluginRoot.ProjectTestModified(): |
1363 return |
1358 dialog = wx.MessageDialog(self, |
1364 |
1359 _("Save changes ?"), |
1365 self.ResetView() |
1360 _("Close Application"), |
1366 self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU) |
1361 wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION) |
1367 self.RefreshAll() |
1362 answer = dialog.ShowModal() |
|
1363 dialog.Destroy() |
|
1364 if answer == wx.ID_YES: |
|
1365 self.PluginRoot.SaveProject() |
|
1366 elif answer == wx.ID_CANCEL: |
|
1367 return |
|
1368 self.ResetView() |
|
1369 self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU) |
|
1370 self.RefreshAll() |
|
1371 |
1368 |
1372 def OnSaveProjectMenu(self, event): |
1369 def OnSaveProjectMenu(self, event): |
1373 if self.PluginRoot is not None: |
1370 if self.PluginRoot is not None: |
1374 self.PluginRoot.SaveProject() |
1371 self.PluginRoot.SaveProject() |
1375 self.RefreshAll() |
1372 self.RefreshAll() |