reopen the files that were open the last time

This commit is contained in:
2022-02-06 16:47:14 +01:00
parent 283bdae0fd
commit c470ca4ed1
6 changed files with 36 additions and 8 deletions

14
main.py
View File

@@ -57,12 +57,14 @@ if __name__ == "__main__":
window = PluginRegistry.execute_single("create_main_window") window = PluginRegistry.execute_single("create_main_window")
window.show() window.show()
PluginRegistry.execute("open_file", PluginRegistry.execute("after_start")
"/home/andi/ws/performanceDb/data/production/lt_axc_21.4_133.02_maxInstance/"
+ "lt_axc_21.4_133.02_maxInstance/app/axcng-service_i-0a69bd43d3624a5bc_172_28_" # PluginRegistry.execute("open_file",
+ "60_222_VADPERFO01AA001_2021-09-21_091717/service/service.log") # "/home/andi/ws/performanceDb/data/production/lt_axc_21.4_133.02_maxInstance/"
PluginRegistry.execute("open_file", # + "lt_axc_21.4_133.02_maxInstance/app/axcng-service_i-0a69bd43d3624a5bc_172_28_"
"testbed/example.log") # + "60_222_VADPERFO01AA001_2021-09-21_091717/service/service.log")
# PluginRegistry.execute("open_file",
# "testbed/example.log")
signal.signal(signal.SIGINT, stop_signal) signal.signal(signal.SIGINT, stop_signal)
signal.signal(signal.SIGTERM, stop_signal) signal.signal(signal.SIGTERM, stop_signal)

View File

@@ -144,6 +144,7 @@ class MainWindow(QMainWindow):
self.destruct() self.destruct()
def destruct(self): def destruct(self):
PluginRegistry.execute("before_shutdown")
self.tabs.destruct() self.tabs.destruct()
self.close() self.close()
SettingsStore.save(self.settings) SettingsStore.save(self.settings)

View File

@@ -82,3 +82,17 @@ class OpenFilePlugin(PluginBase):
def after_open_file(self, file: str): def after_open_file(self, file: str):
self._remember_recent_file(file) self._remember_recent_file(file)
def after_start(self):
open_files_as_string = self.settings.get_session('general', 'open_files', fallback='')
files = open_files_as_string.split(os.pathsep)
if "" in files:
files.remove("")
for file in files:
self.open_file(file)
def before_shutdown(self):
open_files = PluginRegistry.execute_single("get_open_files")
if open_files:
open_files_as_string = os.pathsep.join(open_files)
self.settings.set_session('general', 'open_files', open_files_as_string)

View File

@@ -5,6 +5,7 @@ from PySide6.QtCore import Qt
from PySide6.QtWidgets import QDockWidget, QMessageBox from PySide6.QtWidgets import QDockWidget, QMessageBox
import constants import constants
from raven.pluginregistry import PluginRegistry
from raven.plugins.ravenlog.aboutdialog import AboutDialog from raven.plugins.ravenlog.aboutdialog import AboutDialog
from raven.mainwindow import MainWindow from raven.mainwindow import MainWindow
from raven.pluginbase import PluginBase from raven.pluginbase import PluginBase
@@ -75,6 +76,9 @@ class RavenLogPlugin(PluginBase):
def current_file(self) -> Optional[str]: def current_file(self) -> Optional[str]:
return self.main_window.tabs.current_file() return self.main_window.tabs.current_file()
def get_open_files(self) -> [str]:
return self.main_window.tabs.open_files();
def update_window_title(self, title: str): def update_window_title(self, title: str):
if len(title) > 0: if len(title) > 0:
self.main_window.setWindowTitle(_("{0} - RavenLog").format(title)) self.main_window.setWindowTitle(_("{0} - RavenLog").format(title))

View File

@@ -9,8 +9,8 @@ class Settings():
def set_session(self, section: str, option: str, value: str): def set_session(self, section: str, option: str, value: str):
return self.session.set(section, option, value) return self.session.set(section, option, value)
def get_session(self, section: str, option: str) -> str: def get_session(self, section: str, option: str, fallback: str = object()) -> str:
return self.session.get(section, option) return self.session.get(section, option, fallback=fallback)
def getint_session(self, section: str, option: str) -> int: def getint_session(self, section: str, option: str) -> int:
return self.session.getint(section, option) return self.session.getint(section, option)

View File

@@ -62,3 +62,10 @@ class Tabs(QWidget):
tab: Tab = self.tabs.widget(self.tabs.currentIndex()) tab: Tab = self.tabs.widget(self.tabs.currentIndex())
return tab.get_file() return tab.get_file()
def open_files(self) -> [str]:
result = []
for i in range(self.tabs.count()):
tab: Tab = self.tabs.widget(i)
result.append(tab.get_file())
return result