diff --git a/connect_gui.py b/connect_gui.py index df6ce0a..086f55d 100644 --- a/connect_gui.py +++ b/connect_gui.py @@ -2,10 +2,14 @@ def connect_gui(app): app.gui.main_window.openFile.triggered.connect(app.file_actions.open_files) + app.gui.main_window.newFile.triggered.connect(app.file_actions.create_file) app.gui.main_window.saveFile.triggered.connect(app.file_actions.save_current_file) - app.gui.main_window.openFileTabs.tabCloseRequested.connect(app.file_actions.close_current_file) - app.gui.QTMainWindow.closeEvent = app.utils.on_close + app.gui.main_window.saveFileAs.triggered.connect(app.file_actions.save_current_file_as) + 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) + + app.gui.main_window.openFileTabs.tabCloseRequested.connect(app.file_actions.close_current_file) + app.gui.QTMainWindow.closeEvent = app.utils.on_close diff --git a/file.py b/file.py index 3debb90..75ad6cf 100644 --- a/file.py +++ b/file.py @@ -28,7 +28,7 @@ class FileActions: self.app.open_files[file_path] = File(self.app, file_path, file_path.split("/")[-1]) - def create_file(self): + def create_file(self, content: str=""): file_path, extension = QFileDialog.getSaveFileName( caption="New File", directory=self.app.utils.home_path, @@ -39,7 +39,7 @@ class FileActions: 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.write(content) file.close() self.app.open_files[file_path] = File(self.app, file_path, file_path.split("/")[-1]) # open file @@ -50,6 +50,16 @@ class FileActions: self.app.open_files[current_file_path].save() + def save_current_file_as(self): + current_tab = self.app.gui.main_window.openFileTabs.currentWidget() # get currently open file + current_file_path = current_tab.objectName() + file = self.app.open_files[current_file_path] + + oz_content = file.bit_editor.input.toPlainText() # convert user input to binary data + file_content = self.app.utils.oz_string_to_bstring(oz_content) + + self.create_file(file_content) + def close_current_file(self): current_file_path = self.app.gui.main_window.openFileTabs.currentWidget().objectName() diff --git a/gui/raw_ui/main_window.ui b/gui/raw_ui/main_window.ui index 2c45102..70e596d 100644 --- a/gui/raw_ui/main_window.ui +++ b/gui/raw_ui/main_window.ui @@ -57,7 +57,9 @@ + + @@ -221,6 +223,11 @@ Ctrl+N + + + Save As + +