Fix file modified, file name, etc

This commit is contained in:
Raoul Snyman 2021-09-07 18:01:53 -07:00
parent d6b77e13b6
commit 79fa8777e9
Signed by: raoul
GPG Key ID: F55BCED79626AE9C

View File

@ -183,6 +183,7 @@ class MainWindow(QtWidgets.QMainWindow):
self.cut_action.triggered.connect(self.file_editor.cut)
self.copy_action.triggered.connect(self.file_editor.copy)
self.paste_action.triggered.connect(self.file_editor.paste)
self.new_action.triggered.connect(self.on_new_clicked)
self.open_action.triggered.connect(self.on_open_clicked)
self.save_action.triggered.connect(self.on_save_clicked)
self.save_as_action.triggered.connect(self.on_save_as_clicked)
@ -195,7 +196,7 @@ class MainWindow(QtWidgets.QMainWindow):
def retranslate_ui(self):
_translate = QtCore.QCoreApplication.translate
self.setWindowTitle(_translate('MainWindow', 'Ukatali'))
self.setWindowTitle(_translate('MainWindow', 'Untitled') + '[*] - Ukatali')
self.file_menu.setTitle(_translate('MainWindow', '&File'))
self.edit_menu.setTitle(_translate('MainWindow', '&Edit'))
self.settings_menu.setTitle(_translate('MainWindow', '&Settings'))
@ -246,6 +247,19 @@ class MainWindow(QtWidgets.QMainWindow):
self.exit_action.setToolTip(_translate('MainWindow', 'Quit Ukatali'))
self.exit_action.setShortcut(_translate('MainWindow', 'Alt+F4'))
def on_new_clicked(self):
"""Start a new file"""
if self.file_editor.isModified() and QtWidgets.QMessageBox.question(self, 'Save file?',
'The current file is not saved, do you '
'want to save it now?') \
== QtWidgets.QMessageBox.Yes:
self.on_save_clicked()
self.file_editor.setText('')
self.file_editor.setModified(False)
self.filename = ''
self.setWindowTitle('Untitled[*] - Ukatali')
self.setWindowModified(False)
def on_open_clicked(self):
"""Open the file"""
if self.settings.value('files/last-directory'):
@ -263,6 +277,8 @@ class MainWindow(QtWidgets.QMainWindow):
if file_path.exists():
self.settings.setValue('files/last-directory', str(file_path.parent))
self.file_editor.setText(file_path.open().read())
self.setWindowTitle('{}[*] - Ukatali'.format(file_path.name))
self.setWindowModified(False)
def on_save_clicked(self):
"""Save the file"""
@ -271,6 +287,8 @@ class MainWindow(QtWidgets.QMainWindow):
else:
with open(self.filename, 'w') as fd:
fd.write(self.file_editor.text())
self.setWindowTitle('{}[*] - Ukatali'.format(Path(self.filename).name))
self.setWindowModified(False)
def on_save_as_clicked(self):
"""Save the file"""
@ -324,6 +342,7 @@ class MainWindow(QtWidgets.QMainWindow):
def on_text_changed(self):
"""Update the preview when the text changes"""
# self.setWindowModified(True)
html = self._render_song()
self.preview_view.setHtml(html)