int TabWidget::addTab(const QString &label){ CodeEditor *e = new CodeEditor; connect(e,SIGNAL(textChanged()),this,SIGNAL(textChanged())); int index = QTabWidget::addTab(e,label); QStringList c; QString tip = Global::scriptFunctionsHelpText(&c); tip +="\nTag functions:"; tip += "\nvar tag = new Tag(const QString &fileName)";c<<"Tag"; tip += "bool tagOk() const;\n"; tip += "bool audioPropertiesOk() const;\n"; tip += "QString fileName() const;\n"; tip += "QString artist() const;\n"; tip += "QString title() const;\n"; tip += "QString album() const;\n"; tip += "QString comment() const;\n"; tip += "QString genre() const;\n"; tip += "uint year() const;\n"; tip += "uint track() const;\n"; tip += "uint length() const;\n"; tip += "uint bitRate() const;\n"; tip += "uint sampleRate() const;\n"; tip += "uint channels() const;\n"; tip += "QHash<QString,QStringList> xiphFrames() const;\n";c<<"xiphFrames"; tip += "QHash<QString,QStringList> ID3v2Frames() const;\n";c<<"ID3v2Frames"; tip += "QHash<QString,QStringList> APEItems() const;\n";c<<"APEItems"; tip += "QHash<QString,QStringList> MP4Items() const;\n";c<<"MP4Items"; tip += "QHash<QString,QStringList> ASFAttributes() const;";c<<"ASFAttributes"; e->setToolTip(tip); e->addCompletionWords(c); return index; }
void WorksheetQueryPane::executeAsScript() { if(!canExecute()){ return; } CodeEditor *editor = currentEditor()->editor(); QTextCursor cur; QString queryText = editor->getCurrentText(cur, true); sequentialRunnerStartPos = qMin(cur.position(), cur.anchor()); if(queryText.trimmed().isEmpty()){ emitMessage(tr("Query text cannot be empty")); return; } this->currentQueryCursor = cur; emit scriptModeStarted(); multiEditor->setReadOnly(true); setInProgress(true); sequentialRunner.execute(queryText, this); }
int main (int argc, char ** argv) { QApplication app(argc,argv);; QMainWindow *mainW = new QMainWindow; CodeEditor *plainTextEdit = new CodeEditor(mainW); mainW->setCentralWidget(plainTextEdit); QStatusBar *sbar = mainW->statusBar(); if(argc >1) { QFile file(argv[1]); plainTextEdit->setFile(&file); file.close(); } mainW->show(); // sbar->showMessage( "Ready"); return app.exec(); }
void TabWidget::setIsDeletable(int ind,bool isDeletable){ CodeEditor *e = this->codeEditor(ind); if(e==0){ return; } e->setUserData("isDeletable",isDeletable); }
int main(int argv, char **args) { QApplication app(argv, args); CodeEditor editor; editor.setWindowTitle(QObject::tr("Code Editor Example")); editor.show(); Window w; w.show(); Foo foo; foo.doFoo(); Blub b; b.blubber(); Bar bar; bar.doBar(); Abc abc; abc.doAbc(); Xyz xyz; xyz.doXyz(); Yaf yaf; yaf.doYaf(); LibC lc; lc.foo(); return app.exec(); }
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); }
void AppEditMenu::describeObject() { CodeEditor *editor = qobject_cast<CodeEditor*>(currentAppWidget); if(!editor){ return; } editor->describeObject(); }
void TabWidget::setText(const QString &text,int ind){ if(ind==-1){ ind=this->currentIndex(); } CodeEditor *e = codeEditor(ind); if(e){ e->setPlainText(text); } }
int main(int argv, char **args) { QApplication app(argv, args); CodeEditor editor; editor.setWindowTitle(QObject::tr("Code Editor Example")); editor.show(); return app.exec(); }
int main(int argc, char *argv[]) { QApplication a(argc, argv); // MainWindow w; // w.show(); CodeEditor w; w.show(); return a.exec(); }
QString TabWidget::text(int ind) const{ if(ind==-1){ ind=this->currentIndex(); } CodeEditor *e = codeEditor(ind); QString script; if(e!=0){ script = e->toPlainText(); } return script; }
void Demo::MainWindow::on_actionComplete_triggered() { if (!mProject) return; const QItemSelectionModel* s = mUI->projectItems->selectionModel(); if (s->hasSelection()) { QModelIndex index = s->selectedIndexes()[0]; if (index.parent() == mProject->itemParent(Project::ScriptItems)) { QWidget* widget = mProject->data(index, Project::EditorRole).value<QWidget*>(); CodeEditor* ed = qobject_cast<CodeEditor*>(widget); ed->complete(); } } }
bool TabWidget::isDeletable(int ind,bool default_) const{ CodeEditor *e = this->codeEditor(ind); if(e==0){ return default_; } QVariant v = e->userData().value("isDeletable"); if(v.canConvert(QVariant::Bool)){ return v.toBool(); }else{ return default_; } }
int main(int argv, char **args) { QApplication app(argv, args); CodeEditor editor; editor.setWindowTitle(QObject::tr("Code Editor Example")); #if defined(Q_OS_SYMBIAN) editor.showMaximized(); #else editor.show(); #endif return app.exec(); }
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; }
int PythonSyntax::CalculateSpaceIndetationSize(CodeEditor& editor) { int current = 0; for(int i = 0; i < editor.GetLineCount(); i++) { WString line = editor.GetWLine(i); for(int j = 0; j < line.GetLength(); j++) { if(line[j] == ' ') current++; else break; } if(current > 0) break; } // TODO: 4 is magic numer - try to find the way to get this number from ide constants return current > 0 ? current : 4; }
void AbstractMargin::setEditor( CodeEditor* editor ) { CodeEditor* oldEditor = this->editor(); if ( oldEditor ) { disconnect( oldEditor->textDocument()->layout(), SIGNAL( update( const QRectF& ) ), this, SLOT( update() ) ); disconnect( oldEditor, SIGNAL( cursorPositionChanged() ), this, SLOT( update() ) ); disconnect( oldEditor->verticalScrollBar(), SIGNAL( valueChanged( int ) ), this, SLOT( update() ) ); disconnect( oldEditor, SIGNAL( blockCountChanged( int ) ), this, SLOT( update() ) ); disconnect( oldEditor, SIGNAL( blockCountChanged( int ) ), this, SIGNAL( lineCountChanged( int ) ) ); } if ( editor ) { connect( editor->textDocument()->layout(), SIGNAL( update( const QRectF& ) ), this, SLOT( update() ) ); connect( editor, SIGNAL( cursorPositionChanged() ), this, SLOT( update() ) ); connect( editor->verticalScrollBar(), SIGNAL( valueChanged( int ) ), this, SLOT( update() ) ); connect( editor, SIGNAL( blockCountChanged( int ) ), this, SLOT( update() ) ); connect( editor, SIGNAL( blockCountChanged( int ) ), this, SIGNAL( lineCountChanged( int ) ) ); } updateWidthRequested(); }
PythonSyntax::Identation::Type PythonSyntax::FindIdentationType(CodeEditor& editor, const WString& line) { Identation::Type type = Identation::None; if(line.StartsWith("\t")) type = Identation::Tab; else if(line.StartsWith(" ")) type = Identation::Space; else { for(int i = 0; i < editor.GetLineCount(); i++) { WString cLine = editor.GetWLine(i); if(cLine.StartsWith("\t")) { type = Identation::Tab; break; } else if(cLine.StartsWith(" ")) { type = Identation::Space; break; } } } return type; }
void MainWindow::on_mainDirectoryTree_fileClicked(ProjectTreeItem *item) { for (int i = 0; i < ui->tabWidget->count(); i++) { CodeEditor *editor = static_cast<CodeEditor*>(ui->tabWidget->widget(i)); if (!editor->getFileInfo()->absoluteFilePath().compare(item->getFileInfo()->absoluteFilePath())) { int index = ui->tabWidget->indexOf(editor); ui->tabWidget->setCurrentIndex(index); return; } } QFile file(item->getFileInfo()->absoluteFilePath()); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) return; QFileInfo fileInfo(item->getFileInfo()->absoluteFilePath()); CodeEditor *codeEditor = new CodeEditor(ui->tabWidget, fileInfo); ClangHighlighter *highlighter = new ClangHighlighter(); codeEditor->setSyntaxHighlighter(highlighter); codeEditor->setPlainText(file.readAll()); file.close(); ui->tabWidget->setCurrentIndex(ui->tabWidget->insertTab(0, codeEditor, item->getFileInfo()->fileName())); }
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(); }
void PythonSyntax::IndentInsert(CodeEditor& editor, int chr, int count) { if(chr == '\n') { while(count--) { WString cursorLine = editor.GetWLine(editor.GetCursorLine()); editor.InsertChar('\n', 1); Identation::Type idType = FindIdentationType(editor, cursorLine); char idChar = GetIdentationByType(idType); int mult = 1; if(idType == Identation::Space) mult = CalculateSpaceIndetationSize(editor); if(LineHasColon(cursorLine)) editor.InsertChar(idChar, mult); editor.InsertChar(idChar, CalculateLineIndetations(cursorLine, idType)); } } if(count > 0) editor.InsertChar(chr, count); }
int LuaCodeEditor::getText(lua_State *L) { CodeEditor* obj = ObjectHelper<CodeEditor>::check( L, 1 ); lua_pushstring( L, obj->text().toLatin1() ); return 1; }
int LuaCodeEditor::setText(lua_State *L) { CodeEditor* obj = ObjectHelper<CodeEditor>::check( L, 1 ); obj->setText( luaL_checkstring( L, 2 ) ); return 0; }
void Ide::UpdateFormat(CodeEditor& editor) { if(!IsActiveFile() || ActiveFile().tabsize <= 0) editor.TabSize(editortabsize); editor.IndentSpaces(indent_spaces); editor.IndentAmount(indent_amount); editor.ShowTabs(show_tabs); editor.ShowLineEndings(show_tabs); editor.WarnWhiteSpace(warnwhitespace); editor.NoParenthesisIndent(no_parenthesis_indent); editor.HiliteScope(hilite_scope); editor.HiliteBracket(hilite_bracket); editor.HiliteIfDef(hilite_ifdef); editor.BarLine(barline); editor.HiliteIfEndif(hilite_if_endif); editor.ThousandsSeparator(thousands_separator); editor.ShowCurrentLine(hline ? HighlightSetup::GetHlStyle(HighlightSetup::SHOW_LINE).color : (Color)Null); editor.LineNumbers(line_numbers); editor.AutoEnclose(auto_enclose); editor.MarkLines(mark_lines); editor.BorderColumn(bordercolumn, bordercolor); editor.PersistentFindReplace(persistent_find_replace); editor.FindReplaceRestorePos(find_replace_restore_pos); editor.Refresh(); }
void EditorSyntax::IndentInsert(CodeEditor& editor, int chr, int count) { editor.InsertChar(chr, count); }