|
17 | 17 | import wx |
18 | 18 | import wx.lib.agw.aui as aui |
19 | 19 | from wx import Icon |
20 | | -from robotide.lib.robot.utils.compat import with_metaclass |
21 | 20 | from robotide.action import ActionInfoCollection, ActionFactory, SeparatorInfo |
22 | 21 | from robotide.context import ABOUT_RIDE, SHORTCUT_KEYS |
23 | 22 | from robotide.controller.ctrlcommands import SaveFile, SaveAll |
24 | 23 | from robotide.publish import RideSaveAll, RideClosing, RideSaved, PUBLISHER,\ |
25 | 24 | RideInputValidationError, RideTreeSelection, RideModificationPrevented, RideBeforeSaving |
26 | 25 | from robotide.ui.tagdialogs import ViewAllTagsDialog |
27 | 26 | from robotide.ui.filedialogs import RobotFilePathDialog |
28 | | -from robotide.utils import RideEventHandler |
| 27 | +from robotide.utils import RideFSWatcherHandler |
29 | 28 | from robotide.widgets import Dialog, ImageProvider, HtmlWindow |
30 | 29 | from robotide.preferences import PreferenceEditor |
31 | 30 |
|
|
71 | 70 | ID_CustomizeToolbar = wx.ID_HIGHEST + 1 |
72 | 71 | ID_SampleItem = ID_CustomizeToolbar + 1 |
73 | 72 |
|
74 | | -# Metaclass fix from http://code.activestate.com/recipes/ |
75 | | -# 204197-solving-the-metaclass-conflict/ |
76 | | -from robotide.utils.noconflict import classmaker |
77 | 73 |
|
78 | 74 | ### DEBUG some testing |
79 | 75 | # -- SizeReportCtrl -- |
@@ -139,7 +135,7 @@ def OnSize(self, event): |
139 | 135 | self.Refresh() |
140 | 136 |
|
141 | 137 |
|
142 | | -class RideFrame(with_metaclass(classmaker(), wx.Frame, RideEventHandler)): |
| 138 | +class RideFrame(wx.Frame): |
143 | 139 |
|
144 | 140 | def __init__(self, application, controller): |
145 | 141 | size = application.settings.get('mainframe size', (1100, 700)) |
@@ -452,6 +448,9 @@ def check_unsaved_modifications(self): |
452 | 448 |
|
453 | 449 | def open_suite(self, path): |
454 | 450 | self._controller.update_default_dir(path) |
| 451 | + # self._controller.default_dir will only save dir path |
| 452 | + # need to save path to self._application.workspace_path too |
| 453 | + self._application.workspace_path = path |
455 | 454 | try: |
456 | 455 | err = self._controller.load_datafile(path, LoadProgressObserver(self)) |
457 | 456 | finally: |
@@ -593,6 +592,37 @@ def CreateSizeReportCtrl(self, width=80, height=80): |
593 | 592 | ctrl = SizeReportCtrl(self, -1, wx.DefaultPosition, wx.Size(width, height), self._mgr) |
594 | 593 | return ctrl |
595 | 594 |
|
| 595 | + def show_confirm_reload_dlg(self, event): |
| 596 | + msg = ['Workspace modifications detected on the file system.', |
| 597 | + 'Do you want to reload the workspace?', |
| 598 | + 'Answering <No> will overwrite the changes on disk.'] |
| 599 | + if self._controller.is_dirty(): |
| 600 | + msg.insert(2, 'Answering <Yes> will discard unsaved changes.') |
| 601 | + ret = wx.MessageBox('\n'.join(msg), 'Files Changed On Disk', |
| 602 | + style=wx.YES_NO | wx.ICON_WARNING) |
| 603 | + confirmed = ret == wx.YES |
| 604 | + if confirmed: |
| 605 | + # workspace_path should update after open directory/suite |
| 606 | + # There're two scenarios: |
| 607 | + # 1. path is a directory |
| 608 | + # 2. path is a suite file |
| 609 | + new_path = RideFSWatcherHandler.get_workspace_new_path() |
| 610 | + if new_path and os.path.exists(new_path): |
| 611 | + wx.CallAfter(self.open_suite, new_path) |
| 612 | + else: |
| 613 | + # in case workspace is totally removed |
| 614 | + # ask user to open new directory |
| 615 | + # TODO add some notification msg to users |
| 616 | + wx.CallAfter(self.OnOpenDirectory, event) |
| 617 | + else: |
| 618 | + for _ in self._controller.datafiles: |
| 619 | + if _.has_been_modified_on_disk() or _.has_been_removed_from_disk(): |
| 620 | + if not os.path.exists(_.directory): |
| 621 | + # sub folder is removed, create new one before saving |
| 622 | + os.makedirs(_.directory) |
| 623 | + _.mark_dirty() |
| 624 | + self.save_all() |
| 625 | + |
596 | 626 |
|
597 | 627 | # Code moved from actiontriggers |
598 | 628 | class ToolBar(aui.AuiToolBar): |
|
0 commit comments