-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added open recent functionality #551
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
from trnsysGUI.MassFlowVisualizer import MassFlowVisualizer | ||
from trnsysGUI.ProcessMain import ProcessMain | ||
from trnsysGUI.RunMain import RunMain | ||
from trnsysGUI.userSettings import UserSettings | ||
from trnsysGUI.common import cancelled as _ccl | ||
from trnsysGUI.diagram import Editor as _de | ||
from trnsysGUI.storageTank.widget import StorageTank | ||
|
@@ -130,6 +131,10 @@ def __init__(self, logger, project: _prj.Project, parent=None): | |
fileMenuOpenAction.setShortcut("Ctrl+o") | ||
self.fileMenu.addAction(fileMenuOpenAction) | ||
|
||
fileMenuOpenRecentAction = _qtw.QAction("Open Recent", self) | ||
fileMenuOpenRecentAction.triggered.connect(self.openRecentFile) | ||
self.fileMenu.addAction(fileMenuOpenRecentAction) | ||
|
||
fileMenuSaveAction = _qtw.QAction("Save", self) | ||
fileMenuSaveAction.triggered.connect(self.saveDia) | ||
fileMenuSaveAction.setShortcut("Ctrl+s") | ||
|
@@ -256,6 +261,7 @@ def newDia(self): | |
createProjectMaybeCancelled = _prj.getCreateProject(startingDirectoryPath) | ||
if _ccl.isCancelled(createProjectMaybeCancelled): | ||
return | ||
UserSettings.setRecentProjectJsonPath(self.editor.diagramPath) | ||
createProject = _ccl.value(createProjectMaybeCancelled) | ||
|
||
self._resetEditor(createProject) | ||
|
@@ -466,13 +472,30 @@ def openFile(self): | |
maybeCancelled = _prj.getLoadOrMigrateProject() | ||
if _ccl.isCancelled(maybeCancelled): | ||
return | ||
UserSettings.setRecentProjectJsonPath(self.editor.diagramPath) | ||
project = _ccl.value(maybeCancelled) | ||
|
||
self._resetEditor(project) | ||
|
||
if isinstance(project, _prj.MigrateProject): | ||
self.editor.save() | ||
|
||
def openRecentFile(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like duplication of the usual functionality when opening another project. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not exactly, we can defintely extract message box |
||
qmb = _qtw.QMessageBox() | ||
qmb.setText("Are you sure you want to open another project? Unsaved progress on the current one will be lost.") | ||
qmb.setStandardButtons(_qtw.QMessageBox.Yes | _qtw.QMessageBox.Cancel) | ||
qmb.setDefaultButton(_qtw.QMessageBox.Cancel) | ||
ret = qmb.exec() | ||
|
||
if ret == _qtw.QMessageBox.Cancel: | ||
return | ||
maybeCancelled = _prj.loadRecentProject() | ||
if _ccl.isCancelled(maybeCancelled): | ||
return | ||
UserSettings.setRecentProjectJsonPath(self.editor.diagramPath) | ||
project = _ccl.value(maybeCancelled) | ||
self._resetEditor(project) | ||
|
||
def _resetEditor(self, project): | ||
wasRunning = self.editor and self.editor.isRunning() | ||
|
||
|
@@ -577,11 +600,14 @@ def closeEvent(self, e): | |
if ret == _qtw.QMessageBox.Cancel: | ||
e.ignore() | ||
elif ret == _qtw.QMessageBox.Close: | ||
UserSettings.setRecentProjectJsonPath(self.editor.diagramPath) | ||
e.accept() | ||
elif ret == _qtw.QMessageBox.Save: | ||
self.editor.save() | ||
UserSettings.setRecentProjectJsonPath(self.editor.diagramPath) | ||
e.accept() | ||
else: | ||
sebastian-swob marked this conversation as resolved.
Show resolved
Hide resolved
|
||
UserSettings.setRecentProjectJsonPath(self.editor.diagramPath) | ||
e.accept() | ||
|
||
def ensureSettingsExist(self): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import pathlib as _pl | ||
from PyQt5.QtCore import QSettings # pylint: disable=invalid-name | ||
|
||
|
||
class UserSettings: | ||
|
||
_SETTINGS = QSettings("SPF", "pytrnsys") | ||
sebastian-swob marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@staticmethod | ||
def setRecentProjectJsonPath(jsonFilePath: _pl.Path) -> None: | ||
jsonFilePath = _pl.Path(jsonFilePath) | ||
if jsonFilePath.exists(): | ||
UserSettings._SETTINGS.setValue("recentProject", jsonFilePath) | ||
|
||
@staticmethod | ||
def getRecentProjectJsonPath() -> _pl.Path: | ||
return UserSettings._SETTINGS.value("recentProject") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's discuss this refactoring choice, as it may lead to incremental improvements.