Exemple #1
0
 void onReadyRead(void)
 {
     QByteArray out = QProcess::readAll();
     QString postString = QString::fromUtf8(out);
     if (postString.endsWith( '\n' ))
         postString.chop(1);
     emit scPost(postString);
 }
void ScProcess::postQuitNotification()
{
    QString message;
    switch (exitStatus()) {
    case QProcess::CrashExit:
        message = tr("Interpreter has crashed or stopped forcefully. [Exit code: %1]\n").arg(exitCode());
        break;
    default:
        message = tr("Interpreter has quit. [Exit code: %1]\n").arg(exitCode());
    }
    emit scPost(message);
}
void ScProcess::onReadyRead(void)
{
    if (mTerminationRequested) {
        // when stopping the language, we don't want to post for longer than 200 ms to prevent the UI to freeze
        if (QDateTime::currentDateTimeUtc().toMSecsSinceEpoch() - mTerminationRequestTime.toMSecsSinceEpoch() > 200)
            return;
    }

    QByteArray out = QProcess::readAll();
    QString postString = QString::fromUtf8(out);
    emit scPost(postString);
}
void ScProcess::updateSelectionMirrorForDocument ( Document * doc, int start, int range )
{
    QVariantList argList;
    
    argList.append(QVariant(doc->id()));
    argList.append(QVariant(start));
    argList.append(QVariant(range));
    
    try {
        QDataStream stream(mIpcSocket);
        stream.setVersion(QDataStream::Qt_4_6);
        stream << QString("updateDocSelection");
        stream << argList;
    } catch (std::exception const & e) {
        scPost(QString("Exception during ScIDE_Send: %1\n").arg(e.what()));
    }
}
void ScProcess::updateTextMirrorForDocument ( Document * doc, int position, int charsRemoved, int charsAdded )
{
    QVariantList argList;
    
    argList.append(QVariant(doc->id()));
    argList.append(QVariant(position));
    argList.append(QVariant(charsRemoved));
    
    QTextCursor cursor = QTextCursor(doc->textDocument());
    cursor.setPosition(position, QTextCursor::MoveAnchor);
    cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, charsAdded);
    
    argList.append(QVariant(cursor.selection().toPlainText()));
    
    try {
        QDataStream stream(mIpcSocket);
        stream.setVersion(QDataStream::Qt_4_6);
        stream << QString("updateDocText");
        stream << argList;
    } catch (std::exception const & e) {
        scPost(QString("Exception during ScIDE_Send: %1\n").arg(e.what()));
    }
}
Exemple #6
0
MainWindow::MainWindow(Main * main) :
    mMain(main)
{
    setCorner( Qt::BottomLeftCorner, Qt::LeftDockWidgetArea );

    // Construct status bar:

    mLangStatus = new StatusLabel();
    mLangStatus->setText("Inactive");
    mSynthStatus = new StatusLabel();
    mSynthStatus->setText("Inactive");

    QStatusBar *status = statusBar();
    status->addPermanentWidget( new QLabel("Interpreter:") );
    status->addPermanentWidget( mLangStatus );
    status->addPermanentWidget( new QLabel("Synth:") );
    status->addPermanentWidget( mSynthStatus );

    // Code editor
    mEditors = new MultiEditor(main);

    // Docks
    mDocListDock = new DocumentsDock(main->documentManager(), this);
    mPostDock = new PostDock(this);

    // Layout

    // use a layout for tool widgets, to provide for separate margin control
    QVBoxLayout *tool_box = new QVBoxLayout;
    tool_box->addWidget(cmdLine());
    tool_box->setContentsMargins(5,2,5,2);

    QVBoxLayout *center_box = new QVBoxLayout;
    center_box->setContentsMargins(0,0,0,0);
    center_box->setSpacing(0);
    center_box->addWidget(mEditors);
    center_box->addLayout(tool_box);
    QWidget *central = new QWidget;
    central->setLayout(center_box);
    setCentralWidget(central);

    addDockWidget(Qt::LeftDockWidgetArea, mDocListDock);
    addDockWidget(Qt::BottomDockWidgetArea, mPostDock);

    // A system for easy evaluation of pre-defined code:
    connect(&mCodeEvalMapper, SIGNAL(mapped(QString)),
            this, SIGNAL(evaluateCode(QString)));
    connect(this, SIGNAL(evaluateCode(QString,bool)),
            main->scProcess(), SLOT(evaluateCode(QString,bool)));
    // Interpreter: post output
    connect(main->scProcess(), SIGNAL( scPost(QString) ),
            mPostDock->mPostWindow, SLOT( post(QString) ) );
    // Interpreter: monitor running state
    connect(main->scProcess(), SIGNAL( stateChanged(QProcess::ProcessState) ),
            this, SLOT( onInterpreterStateChanged(QProcess::ProcessState) ) );
    // Interpreter: forward status messages
    connect(main->scProcess(), SIGNAL(statusMessage(const QString&)),
            status, SLOT(showMessage(const QString&)));
    // Document list interaction
    connect(mDocListDock->list(), SIGNAL(clicked(Document*)),
            mEditors, SLOT(setCurrent(Document*)));
    connect(mEditors, SIGNAL(currentChanged(Document*)),
            mDocListDock->list(), SLOT(setCurrent(Document*)),
            Qt::QueuedConnection);

    createMenus();

    QIcon icon;
    icon.addFile(":/icons/sc-cube-128");
    icon.addFile(":/icons/sc-cube-48");
    icon.addFile(":/icons/sc-cube-32");
    icon.addFile(":/icons/sc-cube-16");
    QApplication::setWindowIcon(icon);
}