Skip to content

Commit

Permalink
Fixed bug with number of recent files
Browse files Browse the repository at this point in the history
The number of recent file actions in the menu is limited to
MAX_RECENT_FILES but on opening a new file which was not in the
list of recent files, it was added to the recent file list and
if there were more than MAX_RECENT_FILES in the list, an IndexError
was caused.

Added a few lines to mainwindow.open_file to ensure that the
list of recent files is never longer than MAX_RECENT_FILES.
Any new files are added to the start of the list and the end
of the list is clipped if necessary. This solved the above
problem.
  • Loading branch information
tgwoodcock committed Sep 30, 2022
1 parent ce78bc5 commit b435e7b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/hdf5view/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def main():
"""
parser = argparse.ArgumentParser()
parser.add_argument('--version', action='version',
version='%(prog)s {}'.format(__version__))
version=f'%(prog)s {__version__}')
parser.add_argument("-f", "--file", type=str, required=False)
args = parser.parse_args()

Expand Down
4 changes: 4 additions & 0 deletions src/hdf5view/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ def open_file(self, filename):
# Add filename to top of recent files list
self.recent_files.insert(0, filename)

# ensure not more than MAX_RECENT_FILES are kept:
if len(self.recent_files) > MAX_RECENT_FILES:
self.recent_files = self.recent_files[:MAX_RECENT_FILES]

# Create a new widget and tab for the file
# and select it.
hdf_widget = HDF5Widget(hdf)
Expand Down

0 comments on commit b435e7b

Please sign in to comment.