src/eric7/WebBrowser/Session/SessionManager.py

branch
eric7
changeset 10679
4d3e0ce54322
parent 10439
21c28b0f9e41
child 10926
9ef616cd220d
equal deleted inserted replaced
10678:665f1084ebf9 10679:4d3e0ce54322
18 18
19 from PyQt6.QtCore import ( 19 from PyQt6.QtCore import (
20 QByteArray, 20 QByteArray,
21 QDateTime, 21 QDateTime,
22 QDir, 22 QDir,
23 QFileSystemWatcher,
24 QObject, 23 QObject,
25 Qt, 24 Qt,
26 QTimer, 25 QTimer,
27 pyqtSignal, 26 pyqtSignal,
28 pyqtSlot, 27 pyqtSlot,
38 QLineEdit, 37 QLineEdit,
39 QVBoxLayout, 38 QVBoxLayout,
40 ) 39 )
41 40
42 from eric7 import Globals, Preferences 41 from eric7 import Globals, Preferences
42 from eric7.EricCore import EricFileSystemWatcher
43 from eric7.EricGui.EricOverrideCursor import EricOverrideCursor 43 from eric7.EricGui.EricOverrideCursor import EricOverrideCursor
44 from eric7.EricWidgets import EricMessageBox 44 from eric7.EricWidgets import EricMessageBox
45 from eric7.WebBrowser.WebBrowserWindow import WebBrowserWindow 45 from eric7.WebBrowser.WebBrowserWindow import WebBrowserWindow
46 46
47 47
96 96
97 self.__lastActiveSession = Preferences.getWebBrowser("SessionLastActivePath") 97 self.__lastActiveSession = Preferences.getWebBrowser("SessionLastActivePath")
98 if not os.path.exists(self.__lastActiveSession): 98 if not os.path.exists(self.__lastActiveSession):
99 self.__lastActiveSession = self.__sessionDefault 99 self.__lastActiveSession = self.__sessionDefault
100 100
101 self.__sessionsDirectoryWatcher = QFileSystemWatcher( 101 watcher = EricFileSystemWatcher.instance()
102 [self.getSessionsDirectory()], self 102 watcher.directoryChanged.connect(self.__sessionDirectoryChanged)
103 ) 103 watcher.addPath(self.getSessionsDirectory())
104 self.__sessionsDirectoryWatcher.directoryChanged.connect(
105 self.__sessionDirectoryChanged
106 )
107 104
108 self.__backupSavedSession() 105 self.__backupSavedSession()
109 106
110 self.__autoSaveTimer = None 107 self.__autoSaveTimer = None
111 self.__shutdown = False 108 self.__shutdown = False
158 Public method to perform any shutdown actions. 155 Public method to perform any shutdown actions.
159 """ 156 """
160 self.__autoSaveTimer.stop() 157 self.__autoSaveTimer.stop()
161 if not self.__shutdown: 158 if not self.__shutdown:
162 self.__autoSaveSession(startTimer=False) 159 self.__autoSaveSession(startTimer=False)
160 watcher = EricFileSystemWatcher.instance()
161 watcher.removePath(self.getSessionsDirectory())
163 self.__shutdown = True 162 self.__shutdown = True
164 163
165 def autoSaveSession(self): 164 def autoSaveSession(self):
166 """ 165 """
167 Public method to save the current session state. 166 Public method to save the current session state.
356 @return flag indicating the active file 355 @return flag indicating the active file
357 @rtype bool 356 @rtype bool
358 """ 357 """
359 return pathlib.Path(filePath) == pathlib.Path(self.__lastActiveSession) 358 return pathlib.Path(filePath) == pathlib.Path(self.__lastActiveSession)
360 359
361 @pyqtSlot() 360 @pyqtSlot(str)
362 def __sessionDirectoryChanged(self): 361 def __sessionDirectoryChanged(self, path):
363 """ 362 """
364 Private slot handling changes of the sessions directory. 363 Private slot handling changes of the sessions directory.
365 """ 364
366 self.__sessionMetaData = [] 365 @param path name of the changed directory
367 366 @type str
368 self.sessionsMetaDataChanged.emit() 367 """
368 if path == self.getSessionsDirectory():
369 self.__sessionMetaData = []
370
371 self.sessionsMetaDataChanged.emit()
369 372
370 @pyqtSlot() 373 @pyqtSlot()
371 def aboutToShowSessionsMenu(self, menu): 374 def aboutToShowSessionsMenu(self, menu):
372 """ 375 """
373 Public slot to populate the sessions selection menu. 376 Public slot to populate the sessions selection menu.

eric ide

mercurial