diff --git a/src/ukatali/mainwindow.py b/src/ukatali/mainwindow.py index 22e0c05..02e5fa6 100644 --- a/src/ukatali/mainwindow.py +++ b/src/ukatali/mainwindow.py @@ -176,6 +176,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) @@ -187,7 +188,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')) @@ -235,6 +236,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'): @@ -252,6 +266,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""" @@ -260,6 +276,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""" @@ -313,6 +331,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)