Implemented the creation of new files.

This commit is contained in:
The Wobbler 2024-11-30 21:58:02 +01:00
parent b4792df599
commit 047fcbe856
3 changed files with 31 additions and 0 deletions

View file

@ -8,3 +8,4 @@ def connect_gui(app):
app.gui.main_window.menuSettings.triggered.connect(app.gui.main_window.settingsDock.show)
app.gui.main_window.bitsAreSquaresSetting.stateChanged.connect(app.utils.update_style_in_all_bit_editors)
app.gui.main_window.highlightOnesSetting.stateChanged.connect(app.utils.update_style_in_all_bit_editors)
app.gui.main_window.newFile.triggered.connect(app.file_actions.create_file)

16
file.py
View file

@ -28,6 +28,22 @@ class FileActions:
self.app.open_files[file_path] = File(self.app, file_path, file_path.split("/")[-1])
def create_file(self):
file_path, extension = QFileDialog.getSaveFileName(
caption="New File",
directory=self.app.utils.home_path,
filter="Binary (*.bin);;Any (*)",
)
if "Binary" in extension:
file_path = file_path.split(".")[0] + ".bin" # make sure it has the right extension
file = open(file_path, "bw") # create new empty file
file.write(b"")
file.close()
self.app.open_files[file_path] = File(self.app, file_path, file_path.split("/")[-1]) # open file
def save_current_file(self):
current_tab = self.app.gui.main_window.openFileTabs.currentWidget()
current_file_path = current_tab.objectName()

View file

@ -55,6 +55,7 @@
<property name="title">
<string>File</string>
</property>
<addaction name="newFile"/>
<addaction name="openFile"/>
<addaction name="saveFile"/>
</widget>
@ -207,6 +208,19 @@
<string>New</string>
</property>
</action>
<action name="actionOpen">
<property name="text">
<string>Open</string>
</property>
</action>
<action name="newFile">
<property name="text">
<string>New</string>
</property>
<property name="shortcut">
<string>Ctrl+N</string>
</property>
</action>
</widget>
<resources/>
<connections/>