Fix file modified, file name, etc #4

Merged
raoul merged 1 commits from new-file into master 2021-09-08 01:03:36 +00:00

View File

@ -183,6 +183,7 @@ class MainWindow(QtWidgets.QMainWindow):
self.cut_action.triggered.connect(self.file_editor.cut) self.cut_action.triggered.connect(self.file_editor.cut)
self.copy_action.triggered.connect(self.file_editor.copy) self.copy_action.triggered.connect(self.file_editor.copy)
self.paste_action.triggered.connect(self.file_editor.paste) 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.open_action.triggered.connect(self.on_open_clicked)
self.save_action.triggered.connect(self.on_save_clicked) self.save_action.triggered.connect(self.on_save_clicked)
self.save_as_action.triggered.connect(self.on_save_as_clicked) self.save_as_action.triggered.connect(self.on_save_as_clicked)
@ -195,7 +196,7 @@ class MainWindow(QtWidgets.QMainWindow):
def retranslate_ui(self): def retranslate_ui(self):
_translate = QtCore.QCoreApplication.translate _translate = QtCore.QCoreApplication.translate
self.setWindowTitle(_translate('MainWindow', 'Ukatali')) self.setWindowTitle(_translate('MainWindow', 'Untitled') + '[*] - Ukatali')
self.file_menu.setTitle(_translate('MainWindow', '&File')) self.file_menu.setTitle(_translate('MainWindow', '&File'))
self.edit_menu.setTitle(_translate('MainWindow', '&Edit')) self.edit_menu.setTitle(_translate('MainWindow', '&Edit'))
self.settings_menu.setTitle(_translate('MainWindow', '&Settings')) 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.setToolTip(_translate('MainWindow', 'Quit Ukatali'))
self.exit_action.setShortcut(_translate('MainWindow', 'Alt+F4')) 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): def on_open_clicked(self):
"""Open the file""" """Open the file"""
if self.settings.value('files/last-directory'): if self.settings.value('files/last-directory'):
@ -263,6 +277,8 @@ class MainWindow(QtWidgets.QMainWindow):
if file_path.exists(): if file_path.exists():
self.settings.setValue('files/last-directory', str(file_path.parent)) self.settings.setValue('files/last-directory', str(file_path.parent))
self.file_editor.setText(file_path.open().read()) self.file_editor.setText(file_path.open().read())
self.setWindowTitle('{}[*] - Ukatali'.format(file_path.name))
self.setWindowModified(False)
def on_save_clicked(self): def on_save_clicked(self):
"""Save the file""" """Save the file"""
@ -271,6 +287,8 @@ class MainWindow(QtWidgets.QMainWindow):
else: else:
with open(self.filename, 'w') as fd: with open(self.filename, 'w') as fd:
fd.write(self.file_editor.text()) fd.write(self.file_editor.text())
self.setWindowTitle('{}[*] - Ukatali'.format(Path(self.filename).name))
self.setWindowModified(False)
def on_save_as_clicked(self): def on_save_as_clicked(self):
"""Save the file""" """Save the file"""
@ -324,6 +342,7 @@ class MainWindow(QtWidgets.QMainWindow):
def on_text_changed(self): def on_text_changed(self):
"""Update the preview when the text changes""" """Update the preview when the text changes"""
# self.setWindowModified(True)
html = self._render_song() html = self._render_song()
self.preview_view.setHtml(html) self.preview_view.setHtml(html)