void RubyDebuggerPart::slotRunToCursor() { KParts::ReadWritePart *rwpart = dynamic_cast<KParts::ReadWritePart*>(partController()->activePart()); KTextEditor::ViewCursorInterface *cursorIface = dynamic_cast<KTextEditor::ViewCursorInterface*>(partController()->activeWidget()); if (!rwpart || !rwpart->url().isLocalFile() || !cursorIface) return; uint line, col; cursorIface->cursorPosition(&line, &col); controller->slotRunUntil(rwpart->url().path(), line); }
/** * Returns the current position of the cursor. * @param nLine Holds the line on which the cursor is currently located * @param nCol Holds the column on which the cursor is currently located * @return true if successful, false otherwise (cursor interface was not * obtained) */ bool EditorPage::getCursorPos(uint& nLine, uint& nCol) { KTextEditor::ViewCursorInterface* pCursorIf; // Acquire the view cursor pCursorIf = dynamic_cast<KTextEditor::ViewCursorInterface*>(m_pView); if (pCursorIf == NULL) return false; // Get the cursor position (adjusted to 1-based counting) pCursorIf->cursorPosition(&nLine, &nCol); nLine++; nCol++; return true; }
int EditorTabWidget::currentDocumentLine() { int index; uint line, col; KTextEditor::View* view; KTextEditor::ViewCursorInterface *vci; if((index = currentPageIndex()) == -1) return 0; Document_t d; d = *(m_docList.at(index)); view = d.view; vci = dynamic_cast<KTextEditor::ViewCursorInterface*>(view); vci->cursorPosition(&line, &col); return line+1; }
//--------------------------------------------------------------------------- bool ProjectSession::saveToFile( const QString & sessionFileName, const QValueList< KDevPlugin * > plugins ) { QString section, keyword; QDomElement session = domdoc.documentElement(); int nDocs = 0; QString docIdStr; //// // read the information about the mainframe widget //// QDomElement mainframeEl = session.namedItem("Mainframe").toElement(); //// if(mainframeEl.isNull()){ //// mainframeEl=domdoc.createElement("Mainframe"); //// session.appendChild( mainframeEl); //// } //// bool bMaxMode = ((QextMdiMainFrm*)m_pDocViewMan->parent())->isInMaximizedChildFrmMode(); //// mainframeEl.setAttribute("MaximizeMode", bMaxMode); // read the information about the documents QDomElement docsAndViewsEl = session.namedItem("DocsAndViews").toElement(); if (docsAndViewsEl.isNull()) { docsAndViewsEl = domdoc.createElement("DocsAndViews"); session.appendChild( docsAndViewsEl); } else { // we need to remove the old ones before memorizing the current ones (to avoid merging) QDomNode n = docsAndViewsEl.firstChild(); while ( !n.isNull() ) { QDomNode toBeRemoved = n; n = n.nextSibling(); docsAndViewsEl.removeChild(toBeRemoved); } } QPtrListIterator<KParts::Part> it( *PartController::getInstance()->parts() ); for ( ; it.current(); ++it ) { KParts::ReadOnlyPart* pReadOnlyPart = dynamic_cast<KParts::ReadOnlyPart*>(it.current()); if (!pReadOnlyPart) continue; QString url = pReadOnlyPart->url().url(); docIdStr.setNum(nDocs); QDomElement docEl = domdoc.createElement("Doc" + docIdStr); docEl.setAttribute( "URL", url); docsAndViewsEl.appendChild( docEl); nDocs++; docEl.setAttribute( "NumberOfViews", 1); QDomElement viewEl = domdoc.createElement( "View0"); docEl.appendChild( viewEl); if ( dynamic_cast<HTMLDocumentationPart*>(pReadOnlyPart) ) { viewEl.setAttribute("Type", "Documentation"); } else if ( pReadOnlyPart->inherits("KTextEditor::Document") ) { viewEl.setAttribute("Type", "Source"); KTextEditor::ViewCursorInterface *iface = dynamic_cast<KTextEditor::ViewCursorInterface*>(pReadOnlyPart->widget()); if (iface) { unsigned int line, col; iface->cursorPosition(&line, &col); viewEl.setAttribute( "line", line ); } if ( KTextEditor::EncodingInterface * ei = dynamic_cast<KTextEditor::EncodingInterface*>( pReadOnlyPart ) ) { QString encoding = ei->encoding(); if ( !encoding.isNull() ) { viewEl.setAttribute( "Encoding", encoding ); } } } else { viewEl.setAttribute("Type", "Other"); } } /* QPtrListIterator<KParts::Part> it( *PartController::getInstance()->parts() ); for ( ; it.current(); ++it ) { //// QString partName = it.current()->name(); //// QMessageBox::information(0L,"",partName); KParts::ReadOnlyPart* pReadOnlyPart = dynamic_cast<KParts::ReadOnlyPart*>(it.current()); if (!pReadOnlyPart) continue; // note: read-write parts are also a read-only part, they inherit from it HTMLDocumentationPart* pDocuPart = dynamic_cast<HTMLDocumentationPart*>(pReadOnlyPart); /// @todo Save relative path for project sharing? QString url = pReadOnlyPart->url().url(); docIdStr.setNum(nDocs); QDomElement docEl = domdoc.createElement("Doc" + docIdStr); docEl.setAttribute( "URL", url); docsAndViewsEl.appendChild( docEl); nDocs++; //// docEl.setAttribute( "Type", "???"); //// // get the view list //// QPtrList<KWpEditorPartriteView> viewList = pDoc->viewList(); //// // write the number of views //// docEl.setAttribute( "NumberOfViews", viewList.count()); docEl.setAttribute( "NumberOfViews", 1); // loop over all views of this document int nView = 0; //// KWriteView* pView = 0L; QString viewIdStr; //// for (viewList.first(), nView = 0; viewList.current() != 0; viewList.next(), nView++) { //// pView = viewList.current(); //// if (pView != 0L) { viewIdStr.setNum( nView); QDomElement viewEl = domdoc.createElement( "View"+viewIdStr); docEl.appendChild( viewEl); // focus? //// viewEl.setAttribute("Focus", (((CEditWidget*)pView->parentWidget()) == m_pDocViewMan->currentEditView())); viewEl.setAttribute("Type", "???"); QDomElement viewPropertiesEl = domdoc.createElement("AdditionalSettings"); viewEl.appendChild(viewPropertiesEl); emit sig_saveAdditionalViewProperties(url, &viewPropertiesEl); if (pReadOnlyPart->inherits("KTextEditor::Document")) { KTextEditor::ViewCursorInterface *iface = dynamic_cast<KTextEditor::ViewCursorInterface*>(pReadOnlyPart->widget()); if (iface) { unsigned int line, col; iface->cursorPosition(&line, &col); viewEl.setAttribute( "line", line ); } } if (pDocuPart) { docEl.setAttribute( "context", pDocuPart->context() ); } } */ docsAndViewsEl.setAttribute("NumberOfDocuments", nDocs); // now also let the project-related plugins save their session stuff // read the information about the documents QDomElement pluginListEl = session.namedItem("pluginList").toElement(); if (pluginListEl.isNull()) { pluginListEl = domdoc.createElement("pluginList"); session.appendChild( pluginListEl); } else { // we need to remove the old ones before memorizing the current ones (to avoid merging) QDomNode n = pluginListEl.firstChild(); while ( !n.isNull() ) { QDomNode toBeRemoved = n; n = n.nextSibling(); pluginListEl.removeChild(toBeRemoved); } } QValueList<KDevPlugin*>::ConstIterator itt = plugins.begin(); while( itt != plugins.end() ) { KDevPlugin* pPlugin = (*itt); QString pluginName = pPlugin->instance()->instanceName(); QDomElement pluginEl = domdoc.createElement(pluginName); // now plugin, save what you have! pPlugin->savePartialProjectSession(&pluginEl); // if the plugin wrote anything, accept itt for the session, otherwise forget itt if (pluginEl.hasChildNodes() || pluginEl.hasAttributes()) { pluginListEl.appendChild(pluginEl); } ++itt; } // Write it out to the session file on disc QFile f(sessionFileName); if ( f.open(IO_WriteOnly) ) { // file opened successfully QTextStream t( &f ); // use a text stream t << domdoc.toCString(); f.close(); } initXMLTree(); // clear and initialize the tree again return true; }