Implemented reopening of multiple files.

This commit is contained in:
The Wobbler 2024-12-07 21:39:07 +01:00
parent 27e26903fb
commit bce4cff103
3 changed files with 22 additions and 17 deletions

View file

@ -98,8 +98,6 @@ class File:
self.bit_editor = BitEditor(self.app, self)
self.app.settings.last_opened_file = self.path
self.app.gui.main_window.openFileTabs.setCurrentIndex(self.app.gui.main_window.openFileTabs.count() - 1)
def close(self):

View file

@ -1,11 +1,12 @@
#!/usr/bin/python3
import os
from dataclasses import dataclass
from dataclasses import dataclass, field
from typing import List
from utils import Utils
@dataclass
class Settings:
last_opened_file: str=f"{os.path.dirname(os.path.abspath(__file__))}/example.txt"
last_opened_files: List=field(default_factory=lambda: [f"{Utils.editor_path}/example.txt"])
highlight_ones: bool=False
square_bits: bool=False

View file

@ -8,11 +8,12 @@ from file import File
class Utils:
home_path = str(Path.home())
editor_path = os.path.dirname(os.path.abspath(__file__))
def __init__(self, app):
self.app = app
self.home_path = str(Path.home())
def popup_init(self):
self.usc_popup = QMessageBox() # create a popup window that notifies the user that we have unsaved changes
self.usc_popup.setWindowTitle("Unsaved Changes!") # usc means unsaved changes
@ -95,6 +96,14 @@ class Utils:
def close(self):
print("Bye!")
file_keys = self.app.open_files.keys()
open_files = []
for file_path in file_keys: # convert dict keys to strings
open_files.append(str(file_path))
self.app.settings.last_opened_files = open_files
self.app.settings.save("settings.json")
def update_style_in_all_bit_editors(self):
@ -108,16 +117,7 @@ class Utils:
def on_start(self):
if len(sys.argv) == 1: # if no parameters were passed to the editor
file_path = self.app.settings.last_opened_file
if os.path.isfile(file_path): # open last opened file if it still exists else open the example file
file = File(self.app, file_path, file_path.split("/")[-1])
self.app.open_files[file_path] = file
else:
file_path = f"{os.path.dirname(os.path.abspath(__file__))}/example.txt"
file = File(self.app, file_path, file_path.split("/")[-1])
self.app.open_files[file_path] = file
self.load_files(self.app.settings.last_opened_files)
else:
file_path = sys.argv[1]
@ -125,3 +125,9 @@ class Utils:
if os.path.isfile(file_path):
file = File(self.app, file_path, file_path.split("/")[-1])
self.app.open_files[file_path] = file
def load_files(self, file_paths):
for file_path in file_paths:
if os.path.isfile(file_path):
file = File(self.app, file_path, file_path.split("/")[-1])
self.app.open_files[file_path] = file