Beispiel #1
0
    def prompt_user_to_save(self, index):
        """
        Ask the user if they wish to close a tab
        that has unsaved contents.
        """
        name = self.tabText(index)
        msg_box = QtWidgets.QMessageBox()
        msg_box.setWindowTitle('Save changes?')
        msg_box.setText('%s has not been saved to a file.' % name)
        msg_box.setInformativeText('Do you want to save your changes?')
        buttons = msg_box.Save | msg_box.Discard | msg_box.Cancel
        msg_box.setStandardButtons(buttons)
        msg_box.setDefaultButton(msg_box.Save)
        ret = msg_box.exec_()

        user_cancelled = (ret == msg_box.Cancel)

        if (ret == msg_box.Save):
            data = self.tabData(index)
            path = save.save(data['text'], data['path'])
            if path is None:
                user_cancelled = True

        if user_cancelled:
            return False

        return True
Beispiel #2
0
def save_action(tabs, editor):
    """
    """
    path = tabs.get('path')
    text = editor.toPlainText()
    path = save.save(text, path)
    if path is None:
        return
    tabs['path'] = path
    tabs['saved'] = True
    # notify the autosave to empty entry
    tabs.contents_saved_signal.emit(tabs['uuid'])