Пример #1
0
void Demo::MainWindow::setupScriptActions(const QModelIndex& selection) {

    if (selection.parent() != mProject->itemParent(Project::ScriptItems)) return;

    auto scriptName = mProject->data(selection).toString();
    QStringList unmods;
    unmods << mProject->initScriptName() << mProject->drawScriptName();

    if (unmods.contains(scriptName)) {
        ADDACTION(Insert);
        ADDACTION(Open);
        ADDACTION(Save);
        ADDACTION(SaveAs);
        REMACTION(Rename);
        ADDACTION(Edit);
        ADDACTION(Compile);
        REMACTION(Delete);
        REMACTION(Reload);
        mUI->actionRename->setEnabled(false);
        mUI->actionDelete->setEnabled(false);
    } else {
        ADDACTION(Insert);
        ADDACTION(Open);
        ADDACTION(Save);
        ADDACTION(SaveAs);
        ADDACTION(Rename);
        ADDACTION(Edit);
        ADDACTION(Compile);
        ADDACTION(Delete);
        REMACTION(Reload);
        mUI->actionRename->setEnabled(true);
        mUI->actionDelete->setEnabled(true);
    }

    mUI->actionInsert->setEnabled(true);
    mUI->actionOpen->setEnabled(true);

    QWidget* widget = mProject->data(selection, Project::EditorRole).value<QWidget*>();
    if (mUI->editorsTabs->indexOf(widget) != -1) {
        mUI->editorsTabs->setCurrentWidget(widget);
    }
    CodeEditor* editor = qobject_cast<CodeEditor*>(widget);
    mUI->actionSave->setEnabled(editor->document()->isModified());

    QWidget* curr = mUI->editorsTabs->currentWidget();
    if (curr) {
        curr->setEnabled(curr == widget);
    }

    mUI->actionSaveAs->setEnabled(true);
    mUI->actionEdit->setEnabled(true);

    mUI->actionCompile->setDisabled(mUI->actionAutocompile->isChecked());

    mUI->actionReload->setEnabled(false);

    mUI->actionComplete->setEnabled(curr && curr == widget);

}
Пример #2
0
void ProjectReader::readScripts(QString &path, QString &name, bool open) {
    Q_ASSERT(xml.isStartElement() && xml.name() == QLatin1String("Script"));

    QString n;
    Highlighter *h;
    QCompleter *c;
    CodeEditor *editor = new CodeEditor(name, 0, h);
    
    if (open) {
        editor = 0;
        mMw->addCodeEditor(path + "/" + name);
    } else {
        
        editor->setUndoRedoEnabled(true);
        editor->setTabStopWidth(29);
#ifdef Q_WS_MAC
        int size = 12;
        QFont font("Monaco", size);
#endif
#ifdef Q_OS_WIN
        int size = 10;
        QFont font("Consolas", size);
#endif
#ifdef Q_OS_LINUX
        int size = 10;
        QFont font("Inconsolata-g", size);
#endif
        editor->setFont(font);
        h = new Highlighter(editor->document());
        c = new QCompleter();
        c->setModel(mDocumentManager->modelFromFile(":/wordlist.txt"));
        c->setModelSorting(QCompleter::CaseInsensitivelySortedModel);
        c->setCaseSensitivity(Qt::CaseInsensitive);
        c->setWrapAround(false);
        c->popup()->setStyleSheet("color: #848484; background-color: #2E2E2E; selection-background-color: #424242;");
        editor->setCompleter(c);
        
        n = path + "/" + name;
        //qDebug() << "look a script" << n;
        
        editor->openFile(path + "/" + name);
        
        mMw->addCodeEditor(editor, open);
    }

    xml.skipCurrentElement();
}
Пример #3
0
bool Demo::MainWindow::maybeSave(const QModelIndex& item) {
    if (item.parent() != mProject->itemParent(Project::ScriptItems)) return true;
    bool cancel = false;
    QWidget* widget = mProject->data(item, Project::EditorRole).value<QWidget*>();
    CodeEditor* editor = qobject_cast<CodeEditor*>(widget);
    if (editor->document()->isModified()) {
        QMessageBox msgBox;
        msgBox.setText("The script has been modified.");
        msgBox.setInformativeText("Do you want to save your changes?");
        msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
        msgBox.setDefaultButton(QMessageBox::Save);
        int ret = msgBox.exec();
        if (ret == QMessageBox::Save) on_actionSave_triggered();
        else if (ret == QMessageBox::Cancel) cancel = true;
    }
    return !cancel;
}