Implemented copying files.
This commit is contained in:
parent
b829164f0d
commit
ae049233c5
3 changed files with 26 additions and 5 deletions
|
@ -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
|
||||
|
|
14
file.py
14
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()
|
||||
|
||||
|
|
|
@ -57,7 +57,9 @@
|
|||
</property>
|
||||
<addaction name="newFile"/>
|
||||
<addaction name="openFile"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="saveFile"/>
|
||||
<addaction name="saveFileAs"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuEdit">
|
||||
<property name="locale">
|
||||
|
@ -221,6 +223,11 @@
|
|||
<string>Ctrl+N</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="saveFileAs">
|
||||
<property name="text">
|
||||
<string>Save As</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
|
Loading…
Add table
Reference in a new issue