forked from Wobbl/Bread_Editor
Implemented reopening of multiple files.
This commit is contained in:
parent
27e26903fb
commit
bce4cff103
3 changed files with 22 additions and 17 deletions
2
file.py
2
file.py
|
@ -98,8 +98,6 @@ class File:
|
||||||
|
|
||||||
self.bit_editor = BitEditor(self.app, self)
|
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)
|
self.app.gui.main_window.openFileTabs.setCurrentIndex(self.app.gui.main_window.openFileTabs.count() - 1)
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import os
|
from dataclasses import dataclass, field
|
||||||
from dataclasses import dataclass
|
from typing import List
|
||||||
|
from utils import Utils
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Settings:
|
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
|
highlight_ones: bool=False
|
||||||
square_bits: bool=False
|
square_bits: bool=False
|
||||||
|
|
30
utils.py
30
utils.py
|
@ -8,11 +8,12 @@ from file import File
|
||||||
|
|
||||||
|
|
||||||
class Utils:
|
class Utils:
|
||||||
|
home_path = str(Path.home())
|
||||||
|
editor_path = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
def __init__(self, app):
|
def __init__(self, app):
|
||||||
self.app = app
|
self.app = app
|
||||||
|
|
||||||
self.home_path = str(Path.home())
|
|
||||||
|
|
||||||
def popup_init(self):
|
def popup_init(self):
|
||||||
self.usc_popup = QMessageBox() # create a popup window that notifies the user that we have unsaved changes
|
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
|
self.usc_popup.setWindowTitle("Unsaved Changes!") # usc means unsaved changes
|
||||||
|
@ -95,6 +96,14 @@ class Utils:
|
||||||
def close(self):
|
def close(self):
|
||||||
print("Bye!")
|
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")
|
self.app.settings.save("settings.json")
|
||||||
|
|
||||||
def update_style_in_all_bit_editors(self):
|
def update_style_in_all_bit_editors(self):
|
||||||
|
@ -108,16 +117,7 @@ class Utils:
|
||||||
|
|
||||||
def on_start(self):
|
def on_start(self):
|
||||||
if len(sys.argv) == 1: # if no parameters were passed to the editor
|
if len(sys.argv) == 1: # if no parameters were passed to the editor
|
||||||
file_path = self.app.settings.last_opened_file
|
self.load_files(self.app.settings.last_opened_files)
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
file_path = sys.argv[1]
|
file_path = sys.argv[1]
|
||||||
|
@ -125,3 +125,9 @@ class Utils:
|
||||||
if os.path.isfile(file_path):
|
if os.path.isfile(file_path):
|
||||||
file = File(self.app, file_path, file_path.split("/")[-1])
|
file = File(self.app, file_path, file_path.split("/")[-1])
|
||||||
self.app.open_files[file_path] = file
|
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
|
||||||
|
|
Loading…
Reference in a new issue