Skip to content

Commit

Permalink
also put opened SBML files on the recently used list
Browse files Browse the repository at this point in the history
  • Loading branch information
axelvonkamp committed May 10, 2024
1 parent 34745a7 commit c9b36ab
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions cnapy/gui_elements/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __init__(self, appdata: AppData):
self.file_menu.addAction(open_project_action)
open_project_action.triggered.connect(self.open_project_dialog)

self.recent_cna_menu = self.file_menu.addMenu("Open recent project")
self.recent_cna_menu = self.file_menu.addMenu("Open recent")
self.recent_cna_actions: Dict[str, QAction] = {}

self.save_project_action = QAction("&Save project", self)
Expand Down Expand Up @@ -709,8 +709,21 @@ def open_selected_recent_project(self):
"The selected recently opened .cna file could not be found. Possible reasons: The file was deleted, moved or renamed."
)
return
if self.checked_unsaved():
self.open_project(filename=selected_last_project)
if selected_last_project.endswith(".cna"):
if self.checked_unsaved():
self.open_project(filename=selected_last_project)
else:
self.new_project_from_sbml(filename=selected_last_project) # calls self.checked_unsaved()

def update_recently_used_models(self, filename: str):
if filename in self.appdata.recent_cna_files:
filename_index = self.appdata.recent_cna_files.index(filename)
del(self.appdata.recent_cna_files[filename_index])
if len(self.appdata.recent_cna_files) > 19: # Actually allows 20 shown recent .cna files
del(self.appdata.recent_cna_files[-1])
self.appdata.recent_cna_files.insert(0, filename)
self.appdata.save_cnapy_config()
self.build_recent_cna_menu()

def build_recent_cna_menu(self):
recent_cnas = list(self.recent_cna_actions.keys())
Expand Down Expand Up @@ -1221,11 +1234,12 @@ def new_project_unchecked(self):
self.nounsaved_changes()

@Slot()
def new_project_from_sbml(self):
def new_project_from_sbml(self, filename=''):
if self.checked_unsaved():
dialog = QFileDialog(self)
filename: str = dialog.getOpenFileName(
directory=self.appdata.work_directory, filter=SBML_suffixes)[0]
if len(filename) == 0:
dialog = QFileDialog(self)
filename: str = dialog.getOpenFileName(
directory=self.appdata.work_directory, filter=SBML_suffixes)[0]
if not filename or len(filename) == 0 or not os.path.exists(filename):
return

Expand All @@ -1243,6 +1257,7 @@ def new_project_from_sbml(self):
self.recreate_maps()
self.centralWidget().update(rebuild_all_tabs=True)
self.update_scenario_file_name()
self.update_recently_used_models(filename)

self.setCursor(Qt.ArrowCursor)

Expand Down Expand Up @@ -1316,15 +1331,9 @@ def open_project(self, filename):
self.centralWidget().fit_mapview()

self.centralWidget().update(rebuild_all_tabs=True)
self.update_scenario_file_name()
self.update_recently_used_models(filename)

if filename in self.appdata.recent_cna_files:
filename_index = self.appdata.recent_cna_files.index(filename)
del(self.appdata.recent_cna_files[filename_index])
if len(self.appdata.recent_cna_files) > 19: # Actually allows 20 shown recent .cna files
del(self.appdata.recent_cna_files[-1])
self.appdata.recent_cna_files.insert(0, filename)
self.appdata.save_cnapy_config()
self.build_recent_cna_menu()
except FileNotFoundError:
exstr = get_last_exception_string()
QMessageBox.warning(self, 'Could not open project.', exstr)
Expand Down

0 comments on commit c9b36ab

Please sign in to comment.