示例#1
0
    def save_old_file(self):
        """
        If file not saved, display confirmation dialeg and if is needed, do it

        return: False if action have to be aborted
        """
        cfg.update_yaml_file(self.mainwindow.editor.text())
        if cfg.changed:
            msg_box = QMessageBox()
            msg_box.setWindowTitle("Confirmation")
            msg_box.setIcon(QMessageBox.Question)
            msg_box.setStandardButtons(QMessageBox.Yes | QMessageBox.No | QMessageBox.Abort)
            msg_box.setDefaultButton(QMessageBox.Abort)
            msg_box.setText("The document has unsaved changes, do you want to save it?")
            reply = msg_box.exec_()

            if reply == QtWidgets.QMessageBox.Abort:
                return False
            if reply == QtWidgets.QMessageBox.Yes:
                if cfg.curr_file is None:
                    return self.save_as()
                else:
                    self.save_file()
            if reply == QtWidgets.QMessageBox.No:
                self.autosave.delete_backup()
        return True
示例#2
0
 def transform(self, to_version):
     """Run transformation to version to_version."""
     cfg.update_yaml_file(self.mainwindow.editor.text())
     cfg.transform(to_version)
     # synchronize cfg document with editor text
     self.mainwindow.editor.setText(cfg.document, keep_history=True)
     self.mainwindow.reload()
示例#3
0
 def save_as(self):
     """save file menu action"""
     if cfg.confront_file_timestamp():
         return
     cfg.update_yaml_file(self.mainwindow.editor.text())
     if cfg.curr_file is None:
         if cfg.imported_file_name is not None:
             new_file = cfg.imported_file_name
         else:
             new_file = cfg.config.data_dir + os.path.sep + "NewFile.yaml"
     else:
         new_file = cfg.curr_file
     dialog = QtWidgets.QFileDialog(self.mainwindow, 'Save as YAML File', new_file,
                                    "YAML Files (*.yaml)")
     dialog.setDefaultSuffix('.yaml')
     dialog.setFileMode(QtWidgets.QFileDialog.AnyFile)
     dialog.setAcceptMode(QtWidgets.QFileDialog.AcceptSave)
     dialog.setOption(QtWidgets.QFileDialog.DontConfirmOverwrite, False)
     dialog.setViewMode(QtWidgets.QFileDialog.Detail)
     if dialog.exec_():
         self.autosave.delete_backup()
         file_name = dialog.selectedFiles()[0]
         cfg.save_as(file_name)
         self.mainwindow.update_recent_files()
         self._update_document_name()
         self.mainwindow.show_status_message("File is saved")
         return True
     return False
示例#4
0
 def save_file(self):
     """save file menu action"""
     if cfg.curr_file is None:
         return self.save_as()
     if cfg.confront_file_timestamp():
         return
     cfg.update_yaml_file(self.mainwindow.editor.text())
     cfg.save_file()
     self.mainwindow.show_status_message("File is saved")
     self.autosave.delete_backup()
示例#5
0
def test_meconfig_static(request):
    Config.SERIAL_FILE = "ModelEditorData_test"
    cfg.init(None)
    # cfg.config is assigned
    assert cfg.config.__class__ == Config

    def fin_test_config():
        import gm_base.config
        gm_base.config.delete_config_file("ModelEditorData_test")

    request.addfinalizer(fin_test_config)

    cfg.format_files = []
    cfg._read_format_files()

    # read format files
    assert '1.8.3' in cfg.format_files

    cfg.curr_format_file = None
    cfg.set_current_format_file('1.8.3')
    # good name
    assert cfg.curr_format_file == '1.8.3'
    cfg.set_current_format_file('bad_name')
    # bad name
    assert cfg.curr_format_file == '1.8.3'

    cfg.document = "#test"
    cfg.changed = True
    cfg.curr_file = "test"
    cfg.new_file()
    # new file test
    assert cfg.document == ""
    assert cfg.changed is False
    assert cfg.curr_file is None

    cfg.document = "#test"
    cfg.changed = True
    cfg.curr_file = "test.yaml"
    cfg.config.add_recent_file("test.yaml", "1.8.3")
    cfg.save_file()

    def fin_test_static():
        import os
        if os.path.isfile("test.yaml"):
            os.remove("test.yaml")
        if os.path.isfile("test2.yaml"):
            os.remove("test2.yaml")

    request.addfinalizer(fin_test_static)

    # save file test
    assert cfg.changed is False
    assert cfg.curr_file == "test.yaml"
    assert cfg.config.recent_files[0] == "test.yaml"
    assert cfg.config.format_files[0] == "1.8.3"

    cfg.document = "#test2"
    cfg.changed = True
    cfg.save_as("test2.yaml")

    # save us test
    assert cfg.changed is False
    assert cfg.curr_file == "test2.yaml"
    assert cfg.config.recent_files[0] == "test2.yaml"
    assert cfg.config.format_files[0] == "1.8.3"
    assert cfg.config.recent_files[1] == "test.yaml"
    assert cfg.config.format_files[1] == "1.8.3"

    cfg.document = "#test2"
    cfg.changed = True
    cfg.set_current_format_file('1.8.3')

    cfg.open_file("test.yaml")
    # open file test
    assert cfg.changed is False
    assert cfg.curr_file == "test.yaml"
    assert cfg.document == "#test"
    assert cfg.config.recent_files[1] == "test2.yaml"
    assert cfg.config.format_files[1] == "1.8.3"
    assert cfg.config.recent_files[0] == "test.yaml"
    assert cfg.config.format_files[0] == "1.8.3"
    assert cfg.curr_format_file == '1.8.3'

    cfg.document = ""
    cfg.changed = True
    cfg.set_current_format_file('1.8.3')

    cfg.open_recent_file("test2.yaml")
    # open recent file test
    assert cfg.changed is False
    assert cfg.curr_file == "test2.yaml"
    assert cfg.document == "#test2"
    assert cfg.config.recent_files[0] == "test2.yaml"
    assert cfg.config.format_files[0] == "1.8.3"
    assert cfg.config.recent_files[1] == "test.yaml"
    assert cfg.config.format_files[1] == "1.8.3"
    assert cfg.curr_format_file == '1.8.3'

    cfg.update_yaml_file("#new test")
    # test update_yaml_file 1
    assert cfg.changed == True
    assert cfg.document == "#new test"

    cfg.changed = False
    cfg.update_yaml_file("#new test")
    # test update_yaml_file 2
    assert cfg.changed is False
    assert cfg.document == "#new test"

    # test document parsing
    cfg.document = "n: 1"
    cfg.update()
    assert cfg.root.children[0].value == 1
示例#6
0
 def _structure_changed(self, line, column):
     """Editor structure change signal"""
     if cfg.update_yaml_file(self.editor.text()):
         self.reload()
     else:
         self._reload_node(line, column)