QUrl KateBuildView::docUrl() { KTextEditor::View *kv = m_win->activeView(); if (!kv) { qDebug() << "no KTextEditor::View" << endl; return QUrl(); } if (kv->document()->isModified()) kv->document()->save(); return kv->document()->url(); }
void KatePluginSymbolViewerView::slotDocChanged() { slotRefreshSymbol(); KTextEditor::View *view = m_mainWindow->activeView(); //qDebug()<<"Document changed !!!!" << view; if (view) { connect(view, SIGNAL(cursorPositionChanged(KTextEditor::View*,KTextEditor::Cursor)), this, SLOT(cursorPositionChanged()), Qt::UniqueConnection); if (view->document()) { connect(view->document(), SIGNAL(textChanged(KTextEditor::Document*)), this, SLOT(slotDocEdited()), Qt::UniqueConnection); } }
void Konsole::sync() { if(!KileConfig::syncConsoleDirWithTabs()) { return; } KTextEditor::Document *doc = m_ki->activeTextDocument(); KTextEditor::View *view = Q_NULLPTR; if(doc) { view = doc->views().first(); } if(view) { QString finame; QUrl url = view->document()->url(); if(url.path().isEmpty()) { return; } QFileInfo fic(url.adjusted(QUrl::RemoveFilename|QUrl::StripTrailingSlash).path()); if(fic.isReadable()) { setDirectory(url.adjusted(QUrl::RemoveFilename|QUrl::StripTrailingSlash).path()); } } }
///The first definition that belongs to a context that surrounds the current cursor Declaration* cursorContextDeclaration() { KTextEditor::View* view = ICore::self()->documentController()->activeTextDocumentView(); if(!view) return nullptr; KDevelop::DUChainReadLocker lock( DUChain::lock() ); TopDUContext* ctx = DUChainUtils::standardContextForUrl(view->document()->url()); if(!ctx) return nullptr; KTextEditor::Cursor cursor(view->cursorPosition()); DUContext* subCtx = ctx->findContext(ctx->transformToLocalRevision(cursor)); while(subCtx && !subCtx->owner()) subCtx = subCtx->parentContext(); Declaration* definition = nullptr; if(!subCtx || !subCtx->owner()) definition = DUChainUtils::declarationInLine(cursor, ctx); else definition = subCtx->owner(); if(!definition) return nullptr; return definition; }
Declaration* cursorDeclaration() { KTextEditor::View* view = ICore::self()->documentController()->activeTextDocumentView(); if(!view) return nullptr; KDevelop::DUChainReadLocker lock( DUChain::lock() ); return DUChainUtils::declarationForDefinition( DUChainUtils::itemUnderCursor( view->document()->url(), KTextEditor::Cursor(view->cursorPosition()) ).declaration ); }
void View::run() { KTextEditor::View *view = mw->activeView(); if (!view) { return; } if (m_global.saveBeforeRun) { view->document()->save(); } KTextEditor::Document *doc = view->document(); QString filename = doc->url().path(); QString directory = doc->url().directory(); kDebug() << filename << "-" << directory; QString cmd = txtCommand->text(); cmd = cmd.replace("%filename", filename).replace("%directory", directory); execute(cmd); }
void KateBuildView::displayBuildResult(const QString &msg, KTextEditor::Message::MessageType level) { KTextEditor::View *kv = m_win->activeView(); if (!kv) return; delete m_infoMessage; m_infoMessage = new KTextEditor::Message(xi18nc("@info", "<title>Make Results:</title><nl/>%1", msg), level); m_infoMessage->setWordWrap(true); m_infoMessage->setPosition(KTextEditor::Message::BottomInView); m_infoMessage->setAutoHide(5000); m_infoMessage->setAutoHideMode(KTextEditor::Message::Immediate); m_infoMessage->setView(kv); kv->document()->postMessage(m_infoMessage); }
QString KateCTagsView::currentWord( ) { KTextEditor::View *kv = mainWindow()->activeView(); if (!kv) { kDebug() << "no KTextEditor::View" << endl; return QString(); } if (kv->selection()) { return kv->selectionText(); } if (!kv->cursorPosition().isValid()) { kDebug() << "cursor not valid!" << endl; return QString(); } int line = kv->cursorPosition().line(); int col = kv->cursorPosition().column(); bool includeColon = m_ctagsUi.cmdEdit->text().contains("--extra=+q"); QString linestr = kv->document()->line(line); int startPos = qMax(qMin(col, linestr.length()-1), 0); int endPos = startPos; while (startPos >= 0 && (linestr[startPos].isLetterOrNumber() || (linestr[startPos] == ':' && includeColon) || linestr[startPos] == '_' || linestr[startPos] == '~')) { startPos--; } while (endPos < (int)linestr.length() && (linestr[endPos].isLetterOrNumber() || (linestr[endPos] == ':' && includeColon) || linestr[endPos] == '_')) { endPos++; } if (startPos == endPos) { kDebug() << "no word found!" << endl; return QString(); } //kDebug() << linestr.mid(startPos+1, endPos-startPos-1); return linestr.mid(startPos+1, endPos-startPos-1); }
KTextEditor::View *KateViewSpace::createView(KTextEditor::Document *doc) { // should only be called if a view does not yet exist Q_ASSERT(! m_docToView.contains(doc)); /** * Create a fresh view */ KTextEditor::View *v = doc->createView(stack, m_viewManager->mainWindow()->wrapper()); // set status bar to right state v->setStatusBarEnabled(m_viewManager->mainWindow()->showStatusBar()); // restore the config of this view if possible if (!m_group.isEmpty()) { QString fn = v->document()->url().toString(); if (! fn.isEmpty()) { QString vgroup = QString::fromLatin1("%1 %2").arg(m_group).arg(fn); KateSession::Ptr as = KateApp::self()->sessionManager()->activeSession(); if (as->config() && as->config()->hasGroup(vgroup)) { KConfigGroup cg(as->config(), vgroup); v->readSessionConfig(cg); } } } // register document, it is shown below through showView() then if (! m_lruDocList.contains(doc)) { registerDocument(doc); Q_ASSERT(m_lruDocList.contains(doc)); } // insert View into stack stack->addWidget(v); m_docToView[doc] = v; showView(v); return v; }
void KateViewManager::slotDocumentOpen () { KTextEditor::View *cv = activeView(); if (cv) { KEncodingFileDialog::Result r = KEncodingFileDialog::getOpenUrlsAndEncoding( KateDocManager::self()->editor()->defaultEncoding(), cv->document()->url().url(), QString(), m_mainWindow, i18n("Open File")); KateDocumentInfo docInfo; docInfo.openedByUser = true; KTextEditor::Document *lastID = 0; for (KUrl::List::Iterator i = r.URLs.begin(); i != r.URLs.end(); ++i) lastID = openUrl( *i, r.encoding, false, false, docInfo); if (lastID) activateView (lastID); } }
void EditorTabWidget::createDocument(KURL url/*, const QString& text*/) { /* KTextEditor::PopupMenuInterface* popupIf = dynamic_cast<KTextEditor::PopupMenuInterface*>(w->view()); if (popupIf) popupIf->installPopup((QPopupMenu *)quantaApp->factory()->container("popup_editor", quantaApp)); */ KTextEditor::View *view; if((view = openKDocument(url)) == NULL) return; KTextEditor::MarkInterfaceExtension* imarkex = dynamic_cast<KTextEditor::MarkInterfaceExtension*>(view->document()); if(imarkex) { KIconLoader *loader = KGlobal::iconLoader(); #if (KDE_VERSION_MAJOR >= 3) && (KDE_VERSION_MINOR >= 3) imarkex->setPixmap(KTextEditor::MarkInterface::Execution, loader->loadIcon( "executionpoint", KIcon::Small)); #else imarkex->setPixmap(KTextEditor::MarkInterface::markType05, loader->loadIcon( "executionpoint", KIcon::Small)); #endif imarkex->setPixmap(KTextEditor::MarkInterface::markType08, loader->loadIcon( "preexecutionpoint", KIcon::Small)); #if (KDE_VERSION_MAJOR >= 3) && (KDE_VERSION_MINOR >= 3) imarkex->setPixmap(KTextEditor::MarkInterface::BreakpointActive, loader->loadIcon( "activebreakpoint",KIcon::Small)); #else imarkex->setPixmap(KTextEditor::MarkInterface::markType02, loader->loadIcon( "activebreakpoint", KIcon::Small)); #endif #if (KDE_VERSION_MAJOR >= 3) && (KDE_VERSION_MINOR >= 3) imarkex->setPixmap(KTextEditor::MarkInterface::BreakpointDisabled, loader->loadIcon( "disabledbreakpoint",KIcon::Small)); #else imarkex->setPixmap(KTextEditor::MarkInterface::markType04, loader->loadIcon( "disabledbreakpoint", KIcon::Small)); #endif #if (KDE_VERSION_MAJOR >= 3) && (KDE_VERSION_MINOR >= 3) imarkex->setDescription(KTextEditor::MarkInterface::BreakpointActive, "Breakpoint"); #else imarkex->setDescription(KTextEditor::MarkInterface::markType02, "Breakpoint"); #endif #if (KDE_VERSION_MAJOR >= 3) && (KDE_VERSION_MINOR >= 3) imarkex->setMarksUserChangable(KTextEditor::MarkInterface::Bookmark + KTextEditor::MarkInterface::BreakpointActive); #else imarkex->setMarksUserChangable(KTextEditor::MarkInterface::markType01 + KTextEditor::MarkInterface::markType02); #endif } connect(view->document(), SIGNAL(marksChanged()), this, SLOT(slotMarkChanged())); connect(view->document(), SIGNAL(undoChanged()), this, SLOT(slotUndoChanged())); Document_t d; d.path = url.path(); d.view = view; d.hasUndo = false; d.hasRedo = false; //d.marks = imark->marks(); m_docList.append(d); disableUndoAction(); disableRedoAction(); }
bool PluginKateXMLCheckView::slotValidate() { qDebug() << "slotValidate()"; m_mainWindow->showToolView (dock); m_validating = false; m_dtdname = ""; KTextEditor::View *kv = m_mainWindow->activeView(); if( ! kv ) return false; delete m_tmp_file; m_tmp_file = new QTemporaryFile(); if( !m_tmp_file->open() ) { qDebug() << "Error (slotValidate()): could not create '" << m_tmp_file->fileName() << "': " << m_tmp_file->errorString(); KMessageBox::error(0, i18n("<b>Error:</b> Could not create " "temporary file '%1'.", m_tmp_file->fileName())); delete m_tmp_file; m_tmp_file=0L; return false; } QTextStream s ( m_tmp_file ); s << kv->document()->text(); s.flush(); QString exe = QStandardPaths::findExecutable("xmllint"); if( exe.isEmpty() ) { exe = QStandardPaths::locate(QStandardPaths::ApplicationsLocation, "xmllint"); } //qDebug() << "exe=" <<exe; // // use catalogs for KDE docbook: // if( ! getenv("XML_CATALOG_FILES") ) { // KComponentData ins("katexmlcheckplugin"); // QString catalogs; // catalogs += ins.dirs()->findResource("data", "ksgmltools2/customization/catalog.xml"); // qDebug() << "catalogs: " << catalogs; // setenv("XML_CATALOG_FILES", QFile::encodeName( catalogs ).data(), 1); // } //qDebug() << "**catalogs: " << getenv("XML_CATALOG_FILES"); QStringList args; args << "--noout"; // tell xmllint the working path of the document's file, if possible. // otherweise it will not find relative DTDs // I should give path to location of file, but remove filename // I can make QUrl.adjusted(rm filename).path() // or QUrl.toString(rm filename|rm schema) // Result is the same. Which variant should I choose? //QString path = kv->document()->url().adjusted(QUrl::RemoveFilename).path(); // xmllint uses space- or colon-separated path option, so spaces should be encoded to %20. It is done with EncodeSpaces. // Now what about colons in file names or paths? // This way xmllint works normally: // xmllint --noout --path "/home/user/my/with:colon/" --valid "/home/user/my/with:colon/demo-1.xml" // but because this plugin makes temp file path to file is another and this way xmllint refuses to find dtd: // xmllint --noout --path "/home/user/my/with:colon/" --valid "/tmp/kate.X23725" // As workaround we can encode ':' with %3A QString path = kv->document()->url().toString(QUrl::RemoveFilename|QUrl::PreferLocalFile|QUrl::EncodeSpaces); path.replace(":","%3A"); // because of such inconvinience with xmllint and pathes, maybe switch to xmlstarlet? qDebug() << "path=" << path; if (!path.isEmpty()) { args << "--path" << path; } // heuristic: assume that the doctype is in the first 10,000 bytes: QString text_start = kv->document()->text().left(10000); // remove comments before looking for doctype (as a doctype might be commented out // and needs to be ignored then): QRegExp re("<!--.*-->"); re.setMinimal(true); text_start.remove(re); QRegExp re_doctype("<!DOCTYPE\\s+(.*)\\s+(?:PUBLIC\\s+[\"'].*[\"']\\s+[\"'](.*)[\"']|SYSTEM\\s+[\"'](.*)[\"'])", Qt::CaseInsensitive); re_doctype.setMinimal(true); if( re_doctype.indexIn(text_start) != -1 ) { QString dtdname; if( ! re_doctype.cap(2).isEmpty() ) { dtdname = re_doctype.cap(2); } else { dtdname = re_doctype.cap(3); } if( !dtdname.startsWith("http:") ) { // todo: u_dtd.isLocalFile() doesn't work :-( // a local DTD is used m_validating = true; args << "--valid"; } else { m_validating = true; args << "--valid"; } } else if( text_start.indexOf("<!DOCTYPE") != -1 ) { // DTD is inside the XML file m_validating = true; args << "--valid"; } args << m_tmp_file->fileName(); qDebug() << "m_tmp_file->fileName()=" << m_tmp_file->fileName(); m_proc.start(exe,args); qDebug() << "m_proc.program():" << m_proc.program(); // I want to see parmeters qDebug() << "args=" << args; qDebug() << "exit code:"<< m_proc.exitCode(); if( ! m_proc.waitForStarted(-1) ) { KMessageBox::error(0, i18n("<b>Error:</b> Failed to execute xmllint. Please make " "sure that xmllint is installed. It is part of libxml2.")); return false; } QApplication::setOverrideCursor(Qt::WaitCursor); return true; }
void KDataToolPluginView::aboutToShow() { kdDebug()<<"KTextEditor::KDataToolPluginView::aboutToShow"<<endl; QString word; m_singleWord = false; m_wordUnderCursor = QString::null; // unplug old actions, if any: KAction *ac; for ( ac = m_actionList.first(); ac; ac = m_actionList.next() ) { m_menu->remove(ac); } if (m_notAvailable) { m_menu->remove(m_notAvailable); delete m_notAvailable; m_notAvailable=0; } if ( selectionInterface(m_view->document())->hasSelection() ) { word = selectionInterface(m_view->document())->selection(); if ( word.find(' ') == -1 && word.find('\t') == -1 && word.find('\n') == -1 ) m_singleWord = true; else m_singleWord = false; } else { // No selection -> use word under cursor KTextEditor::EditInterface *ei; KTextEditor::ViewCursorInterface *ci; KTextEditor::View *v = (KTextEditor::View*)m_view; ei = KTextEditor::editInterface(v->document()); ci = KTextEditor::viewCursorInterface(v); uint line, col; ci->cursorPositionReal(&line, &col); QString tmp_line = ei->textLine(line); m_wordUnderCursor = ""; // find begin of word: m_singleWord_start = 0; for(int i = col; i >= 0; i--) { QChar ch = tmp_line.at(i); if( ! (ch.isLetter() || ch == '-' || ch == '\'') ) { m_singleWord_start = i+1; break; } m_wordUnderCursor = ch + m_wordUnderCursor; } // find end of word: m_singleWord_end = tmp_line.length(); for(uint i = col+1; i < tmp_line.length(); i++) { QChar ch = tmp_line.at(i); if( ! (ch.isLetter() || ch == '-' || ch == '\'') ) { m_singleWord_end = i; break; } m_wordUnderCursor += ch; } if( ! m_wordUnderCursor.isEmpty() ) { m_singleWord = true; m_singleWord_line = line; } else { m_notAvailable = new KAction(i18n("(not available)"), QString::null, 0, this, SLOT(slotNotAvailable()), actionCollection(),"dt_n_av"); m_menu->insert(m_notAvailable); return; } } KInstance *inst=instance(); QValueList<KDataToolInfo> tools; tools += KDataToolInfo::query( "QString", "text/plain", inst ); if( m_singleWord ) tools += KDataToolInfo::query( "QString", "application/x-singleword", inst ); m_actionList = KDataToolAction::dataToolActionList( tools, this, SLOT( slotToolActivated( const KDataToolInfo &, const QString & ) ) ); for ( ac = m_actionList.first(); ac; ac = m_actionList.next() ) { m_menu->insert(ac); } if( m_actionList.isEmpty() ) { m_notAvailable = new KAction(i18n("(not available)"), QString::null, 0, this, SLOT(slotNotAvailable()), actionCollection(),"dt_n_av"); m_menu->insert(m_notAvailable); } }