Ejemplo n.º 1
0
void toLexerOracleAPIs::updateAutoCompletionList(const QStringList &context, QStringList &list)
{
    list << "AAA" << "BBB";
    QsciScintilla* editor = lexer()->editor();
    if (editor == NULL)
        return;

    QmlJS::PersistentTrie::Trie trie;

    QString text = editor->text();
    int len = editor->length();
    char* bufferText = new char[len+1];
    editor->SendScintilla(QsciScintillaBase::SCI_GETTEXT, len, bufferText);
    bufferText[len] = '\0';
    std::auto_ptr <SQLLexer::Lexer> lexer = LexerFactTwoParmSing::Instance().create("OracleGuiLexer", "", "toCustomLexer");
    lexer->setStatement(bufferText, len);
    SQLLexer::Lexer::token_const_iterator it = lexer->begin();
    while (it != lexer->end())
    {
        SQLLexer::Token::TokenType t = it->getTokenType();
        if (it->getTokenType() == SQLLexer::Token::L_IDENTIFIER)
            trie.insert(it->getText());
        it++;
    }
    list << trie.complete(context.last());
}
Ejemplo n.º 2
0
void MainWindow::openFile()
{
    QString fileName = QFileDialog::getOpenFileName(this);
    if (!fileName.isEmpty())
    {
        QsciScintilla * editor = new QsciScintilla();
        editor->setPaper(QColor(1,81,107));
        editor->setMarginLineNumbers(1,true);
        editor->setAutoIndent(true);
        editor->setLexer(new QsciLexerPython());
        editor->setFolding(QsciScintilla::PlainFoldStyle);
        editor->setAutoCompletionThreshold(2);
        editor->setAutoCompletionSource(QsciScintilla::AcsAll);
        ui->tabWidget->addTab(editor, QIcon(), fileName);

        QFile file(fileName);
        if (!file.open(QFile::ReadOnly)) {
            QMessageBox::warning(this, tr("Application"),
                                tr("Cannot read file %1:\n%2.")
                                .arg(fileName)
                                .arg(file.errorString()));
            return;
        }

        QTextStream in(&file);
        QApplication::setOverrideCursor(Qt::WaitCursor);
        editor->setText(in.readAll());
        QApplication::restoreOverrideCursor();

        //setCurrentFile(fileName);
        //statusBar()->showMessage(tr("File loaded"), 2000);
    }
}
Ejemplo n.º 3
0
void ListBoxQt::GetValue(int n, char *value, int len)
{
    Q_ASSERT(slb);

    QString selection = slb->text(n);

    bool trim_selection = false;
    QObject *sci_obj = slb->parent();

    if (sci_obj->inherits("QsciScintilla"))
    {
        QsciScintilla *sci = static_cast<QsciScintilla *>(sci_obj);

        if (sci->isAutoCompletionList())
        {
            // Save the full selection and trim the value we return.
            sci->acSelection = selection;
            trim_selection = true;
        }
    }

    if (selection.isEmpty() || len <= 0)
        value[0] = '\0';
    else
    {
        const char *s;
        int slen;

        QByteArray bytes;

        if (utf8)
            bytes = selection.toUtf8();
        else
            bytes = selection.toLatin1();

        s = bytes.data();
        slen = bytes.length();

        while (slen-- && len--)
        {
            if (trim_selection && *s == ' ')
                break;

            *value++ = *s++;
        }

        *value = '\0';
    }
}
Ejemplo n.º 4
0
void MainWindow::runRun()
{
    QsciScintilla *active = dynamic_cast<QsciScintilla*>(ui->tabWidget->currentWidget());

    QString text = active->text();


    const char * script = text.toAscii().data();
    environment::world * w = new environment::world("Virtual world");
    w->start();
    w->run_script(script);
    //w->run_file("../../s.py");


}
Ejemplo n.º 5
0
void SciDoc::toggleMarker(int line) {
	LOGGER;

	QsciScintilla* edit = int_->curEdit_;
	if ( edit == NULL )
		return;

	qDebug() << edit->markersAtLine( line );

	if ( edit->markersAtLine(line) & 4 ) {
		edit->markerDelete(line, 1);
		edit->markerDelete(line, 2);
	}
	else {
		edit->markerAdd(line, 1);
		edit->markerAdd(line, 2);
	}
}
Ejemplo n.º 6
0
void MainWindow::newFile()
{
    QsciScintilla * editor = new QsciScintilla();
    editor->setPaper(QColor(1,81,107));
    editor->setMarginLineNumbers(1,true);
    editor->setAutoIndent(true);
    editor->setLexer(new QsciLexerPython());
    editor->setFolding(QsciScintilla::PlainFoldStyle);
    editor->setAutoCompletionThreshold(2);
    editor->setAutoCompletionSource(QsciScintilla::AcsAll);
    ui->tabWidget->addTab(editor, QIcon(), QString("New file"));

}
Ejemplo n.º 7
0
void MainWindow::runCode()
{

    if (running)
    {
        setRunning(false);
        updateSpeed();
        game->getCallbackState().stop();
    }
    else{
        QsciScintilla *ws = (QsciScintilla*)textWidget->currentWidget();

        int index = (textWidget->currentIndex())+ 1;

        std::string path = "python_embed/scripts/Script " + std::to_string(index) + ".py";

        //Save script as 'Script 1'/'Script 2' etc
        //Also save as 'Current Script.py' as temporary measure before new input manager
        //This python script is always run in bootstrapper.py (in start)
        ofstream fout(path.c_str(), ios::out|ios::trunc);
        ofstream foutcopy("python_embed/scripts/Current Script.py", ios::out|ios::trunc);

        if(!(fout.good() && foutcopy.good()))
        {
            LOG(INFO) << "Output file is bad" << endl;
            return;
        }

        fout << ws->text().toStdString();
        foutcopy << ws->text().toStdString();

        fout.close();
        foutcopy.close();

        setRunning(true);
        updateSpeed();
        game->getCallbackState().restart();
    }
    setGameFocus();
}
Ejemplo n.º 8
0
void SciDoc::applySettings() {
//	LOGGER;

	setShowLineNumbers(EditorSettings::get(EditorSettings::ShowLineNumbers));

	QFont font = EditorSettings::font();
	LexerStorage::instance()->updateLexers(font);
	QColor textColor = EditorSettings::get(EditorSettings::DefaultFontColor);
	QColor bgColor = EditorSettings::get(EditorSettings::DefaultBgColor);

	QsciScintilla* edits[] = { int_->edit1_, int_->edit2_, NULL };
	for (int i = 0; edits[i] != NULL; ++i ) {
		QsciScintilla* edit = edits[i];

		// indents
		//edit->setTabWidth(EditorSettings::get(EditorSettings::TabWidth));
		//edit->setIndentationsUseTabs(EditorSettings::get(EditorSettings::UseTabs));
		edit->setBackspaceUnindents(EditorSettings::get(EditorSettings::BackspaceUnindents));

		// colors
		edit->setIndentationGuides(QSciSettings::get(QSciSettings::ShowIndents));
		edit->setIndentationGuidesForegroundColor(QSciSettings::get(QSciSettings::IndentsColor));
		edit->setIndentationGuidesBackgroundColor(bgColor);

		QColor selBgColor = EditorSettings::get(EditorSettings::SelectionBgColor);
		edit->setSelectionBackgroundColor(selBgColor);
		if ( selBgColor.red() + selBgColor.green() + selBgColor.blue() < 3 * 255 / 2)
			edit->setSelectionForegroundColor(QColor(255, 255, 255));
		else
			edit->setSelectionForegroundColor(QColor(0, 0, 0));

		if ( QSciSettings::get(QSciSettings::HighlightMatchingBrace) ) {
			edit->setMatchedBraceBackgroundColor(QSciSettings::get(QSciSettings::MatchingBraceBgColor));
			edit->setMatchedBraceForegroundColor(QSciSettings::get(QSciSettings::MatchingBraceFgColor));
		}
		else {
			edit->setMatchedBraceBackgroundColor(bgColor);
			edit->setMatchedBraceForegroundColor(textColor);
		}

		edit->setCaretLineBackgroundColor(LexerStorage::instance()->curLineColor(syntax()));
		edit->setMarkerBackgroundColor(QSciSettings::get(QSciSettings::MarkersColor));
		edit->setCaretForegroundColor(textColor);

		QColor marginsBgColor = QSciSettings::get(QSciSettings::MarginsBgColor);
		edit->setMarginsBackgroundColor(marginsBgColor);
		edit->setMarginsForegroundColor(textColor);
		edit->setFoldMarginColors(marginsBgColor, bgColor);

		// markers
		edit->markerDefine(markerPixmap(QSciSettings::get(QSciSettings::MarkersColor), marginsBgColor), -1);
		edit->setCaretLineVisible(QSciSettings::get(QSciSettings::HighlightCurLine));


		// line length indicator
		int lInd = EditorSettings::get(EditorSettings::LineLengthIndicator);
		if ( lInd > 0 ) {
			edit->setEdgeMode(QsciScintilla::EdgeLine);
			edit->setEdgeColumn(lInd);
		}
		else {
			edit->setEdgeMode(QsciScintilla::EdgeNone);
		}

		edit->SendScintilla(QsciScintillaBase::SCI_SETWHITESPACEFORE, 1, QSciSettings::get(QSciSettings::WhiteSpaceColor));

		// selection
/*		QColor selBgColor = TextDocSettings::selectionBgColor();
		edit->setSelectionBackgroundColor(selBgColor);
		if ( selBgColor.red() + selBgColor.green() + selBgColor.blue() < 3 * 255 / 2)
			edit->setSelectionForegroundColor(QColor(255, 255, 255));
		else
			edit->setSelectionForegroundColor(QColor(0, 0, 0));
*/
		//	autocompletion
		edit->setAutoCompletionThreshold(AutocompleteSettings::get(AutocompleteSettings::Threshold));
		edit->setAutoCompletionReplaceWord(AutocompleteSettings::get(AutocompleteSettings::ReplaceWord));
//		edit->setAutoCompletionCaseSensitivity(AutocompleteSettings::get(AutocompleteSettings::CaseSensitive));
		if ( AutocompleteSettings::get(AutocompleteSettings::UseDocument) ) {
			if ( AutocompleteSettings::get(AutocompleteSettings::UseApis) )
				edit->setAutoCompletionSource(QsciScintilla::AcsAll);
			else
				edit->setAutoCompletionSource(QsciScintilla::AcsDocument);
		}
		else {
			if ( AutocompleteSettings::get(AutocompleteSettings::UseApis) )
				edit->setAutoCompletionSource(QsciScintilla::AcsAPIs);
			else
				edit->setAutoCompletionSource(QsciScintilla::AcsNone);
		}
		edit->setAutoCompletionCaseSensitivity(false);
	}
}