bool subversionPart::urlFocusedDocument( KURL &url ) { KParts::ReadOnlyPart *part = dynamic_cast<KParts::ReadOnlyPart*>( partController()->activePart() ); if ( part ) { if (part->url().isLocalFile() ) { url = part->url(); return true; } } return false; }
void KShellCmdPlugin::slotExecuteShellCommand() { KParts::ReadOnlyPart *part = qobject_cast<KParts::ReadOnlyPart *>(parent()); if (!part) { KMessageBox::sorry(0L, i18n("KShellCmdPlugin::slotExecuteShellCommand: Program error, please report a bug.")); return; } KUrl url = KIO::NetAccess::mostLocalUrl(part->url(), NULL); if (!url.isLocalFile()) { KMessageBox::sorry(part->widget(), i18n("Executing shell commands works only on local directories.")); return; } QString path; KParts::FileInfoExtension *ext = KParts::FileInfoExtension::childObject(part); if (ext && ext->hasSelection() && (ext->supportedQueryModes() & KParts::FileInfoExtension::SelectedItems)) { KFileItemList list = ext->queryFor(KParts::FileInfoExtension::SelectedItems); QStringList fileNames; Q_FOREACH (const KFileItem &item, list) { fileNames << item.name(); } path = KShell::joinArgs(fileNames); }
void KShellCmdPlugin::slotExecuteShellCommand() { KParts::ReadOnlyPart * part = dynamic_cast<KParts::ReadOnlyPart *>(parent()); if ( !part ) { KMessageBox::sorry(0L, i18n("KShellCmdPlugin::slotExecuteShellCommand: Program error, please report a bug.")); return; } KUrl url = KIO::NetAccess::mostLocalUrl(part->url(),NULL); if ( !url.isLocalFile() ) { KMessageBox::sorry(part->widget(),i18n("Executing shell commands works only on local directories.")); return; } QString path; #if 0 // to be ported if still needed if ( part->currentItem() ) { // Putting the complete path to the selected file isn't really necessary, // since we'll cd to the directory first. But we do need to get the // complete relative path. path = KUrl::relativePath( url.path(), part->currentItem()->url().path() ); } else #endif { path = url.toLocalFile(); } bool ok; QString cmd = KInputDialog::getText( i18nc("@title:window", "Execute Shell Command"), i18n( "Execute shell command in current directory:" ), KShell::quoteArg( path ), &ok, part->widget() ); if ( ok ) { QString chDir; chDir="cd "; chDir+=KShell::quoteArg(part->url().path()); chDir+="; "; chDir+=cmd; KShellCommandDialog *shellCmdDialog=new KShellCommandDialog(i18n("Output from command: \"%1\"", cmd),chDir,part->widget(),true); shellCmdDialog->resize(500,300); shellCmdDialog->executeCommand(); delete shellCmdDialog; } }
QString PerforcePart::currentFile() { KParts::ReadOnlyPart *part = dynamic_cast<KParts::ReadOnlyPart*>( partController()->activePart() ); if ( part ) { KURL url = part->url(); if ( url.isLocalFile() ) return url.path(); } return QString::null; }
void RubySupportPart::slotSwitchToView() { KParts::Part *activePart = partController()->activePart(); if (!activePart) return; KParts::ReadOnlyPart *ropart = dynamic_cast<KParts::ReadOnlyPart*>(activePart); if (!ropart) return; QFileInfo file(ropart->url().path()); if (!file.exists()) return; QString ext = file.extension(); QString name = file.baseName(); QString switchTo = ""; if (ext == "rjs" || ext == "rxml" || ext == "rhtml" || ext == "js.rjs" || ext == "xml.builder" || ext == "html.erb") { //this is a view already, let's show the list of all views for this model switchTo = file.dir().dirName(); } else if (ext == "rb") switchTo = name.remove(QRegExp("_controller$")).remove(QRegExp("_controller_test$")).remove(QRegExp("_test$")); if (switchTo.isEmpty()) return; if (switchTo.endsWith("s")) switchTo = switchTo.mid(0, switchTo.length() - 1); KURL::List urls; QDir viewsDir; QDir viewsDirS = QDir(project()->projectDirectory() + "/app/views/" + switchTo); QDir viewsDirP = QDir(project()->projectDirectory() + "/app/views/" + switchTo + "s"); if (viewsDirS.exists()) viewsDir = viewsDirS; else if (viewsDirP.exists()) viewsDir = viewsDirP; else return; QStringList views = viewsDir.entryList(); for (QStringList::const_iterator it = views.begin(); it != views.end(); ++it) { QString viewName = *it; if ( !(viewName.endsWith("~") || viewName == "." || viewName == "..") ) urls << KURL::fromPathOrURL(viewsDir.absPath() + "/" + viewName); } KDevQuickOpen *qo = extension<KDevQuickOpen>("KDevelop/QuickOpen"); if (qo) qo->quickOpenFile(urls); }
void RubySupportPart::slotSwitchToTest() { KParts::Part *activePart = partController()->activePart(); if (!activePart) return; KParts::ReadOnlyPart *ropart = dynamic_cast<KParts::ReadOnlyPart*>(activePart); if (!ropart) return; QFileInfo file(ropart->url().path()); if (!file.exists()) return; QString ext = file.extension(); QString name = file.baseName(); QString switchTo = ""; if (ext == "rjs" || ext == "rxml" || ext == "rhtml" || ext == "js.rjs" || ext == "xml.builder" || ext == "html.erb") { //this is a view already, let's show the list of all views for this model switchTo = file.dir().dirName(); } else if (ext == "rb") switchTo = name.remove(QRegExp("_controller$")).remove(QRegExp("_controller_test$")).remove(QRegExp("_test$")); if (switchTo.isEmpty()) return; if (switchTo.endsWith("s")) switchTo = switchTo.mid(0, switchTo.length() - 1); KURL::List urls; QString testDir = project()->projectDirectory() + "/test/"; QString functionalTestS = testDir + "functional/" + switchTo + "_controller_test.rb"; QString functionalTestP = testDir + "functional/" + switchTo + "s_controller_test.rb"; QString integrationTestS = testDir + "integration/" + switchTo + "_test.rb"; QString integrationTestP = testDir + "integration/" + switchTo + "s_test.rb"; QString unitTestS = testDir + "unit/" + switchTo + "_test.rb"; QString unitTestP = testDir + "unit/" + switchTo + "s_test.rb"; if (QFile::exists(functionalTestP)) urls << KURL::fromPathOrURL(functionalTestP); if (QFile::exists(integrationTestP)) urls << KURL::fromPathOrURL(integrationTestP); if (QFile::exists(unitTestP)) urls << KURL::fromPathOrURL(unitTestP); if (QFile::exists(functionalTestS)) urls << KURL::fromPathOrURL(functionalTestS); if (QFile::exists(integrationTestS)) urls << KURL::fromPathOrURL(integrationTestS); if (QFile::exists(unitTestS)) urls << KURL::fromPathOrURL(unitTestS); KDevQuickOpen *qo = extension<KDevQuickOpen>("KDevelop/QuickOpen"); if (qo && !urls.isEmpty()) qo->quickOpenFile(urls); }
void AutoRefresh::slotRefresh() { KParts::ReadOnlyPart *part = qobject_cast< KParts::ReadOnlyPart * >( parent() ); if ( !part ) { QString title = i18nc( "@title:window", "Cannot Refresh Source" ); QString text = i18n( "<qt>This plugin cannot auto-refresh the current part.</qt>" ); KMessageBox::error( 0, text, title ); } else { // Get URL KUrl url = part->url(); part->openUrl( url ); } }
void AutoRefresh::slotRefresh() { if ( !parent()->inherits("KParts::ReadOnlyPart") ) { QString title = i18n( "Cannot Refresh Source" ); QString text = i18n( "<qt>This plugin cannot auto-refresh the current part.</qt>" ); QMessageBox::warning( 0, title, text ); } else { KParts::ReadOnlyPart *part = (KParts::ReadOnlyPart *) parent(); // Get URL KURL url = part->url(); part->openURL( url ); } }
void RubySupportPart::slotSwitchToController() { KParts::Part *activePart = partController()->activePart(); if (!activePart) return; KParts::ReadOnlyPart *ropart = dynamic_cast<KParts::ReadOnlyPart*>(activePart); if (!ropart) return; QFileInfo file(ropart->url().path()); if (!file.exists()) return; QString ext = file.extension(); QString name = file.baseName(); QString switchTo = ""; if ((ext == "rb") && !name.endsWith("_controller")) { if (name.endsWith("_test")) { switchTo = name.remove(QRegExp("_test$")); //the file is the test switchTo = name.remove(QRegExp("_controller$")); //remove functional test name parts } else switchTo = name; } else if (ext == "rjs" || ext == "rxml" || ext == "rhtml" || ext == "js.rjs" || ext == "xml.builder" || ext == "html.erb") { //this is a view, we need to find the directory of this view and try to find //the controller basing on the directory information switchTo = file.dir().dirName(); } QString controllersDir = project()->projectDirectory() + "/app/controllers/"; if (!switchTo.isEmpty()) { if (switchTo.endsWith("s")) switchTo = switchTo.mid(0, switchTo.length()-1); QString singular = controllersDir + switchTo + "_controller.rb"; QString plural = controllersDir + switchTo + "s_controller.rb"; KURL url = KURL::fromPathOrURL(QFile::exists(singular) ? singular : plural); partController()->editDocument(url); } }
void RubySupportPart::slotSwitchToModel() { KParts::Part *activePart = partController()->activePart(); if (!activePart) return; KParts::ReadOnlyPart *ropart = dynamic_cast<KParts::ReadOnlyPart*>(activePart); if (!ropart) return; QFileInfo file(ropart->url().path()); if (!file.exists()) return; QString ext = file.extension(); QString name = file.baseName(); QString switchTo = ""; if (ext == "rjs" || ext == "rxml" || ext == "rhtml" || ext == "js.rjs" || ext == "xml.builder" || ext == "html.erb") { //this is a view already, let's show the list of all views for this model switchTo = file.dir().dirName(); } else if (ext == "rb" && (name.endsWith("_controller") || name.endsWith("_test"))) { switchTo = name.remove(QRegExp("_controller$")).remove(QRegExp("_controller_test$")).remove(QRegExp("_test$")); } if (switchTo.isEmpty()) return; if (switchTo.endsWith("s")) switchTo = switchTo.mid(0, switchTo.length() - 1); QString modelsDir = project()->projectDirectory() + "/app/models/"; QString singular = modelsDir + switchTo + "_controller.rb"; QString plural = modelsDir + switchTo + "s_controller.rb"; KURL url = KURL::fromPathOrURL(QFile::exists(singular) ? singular : plural); partController()->editDocument(KURL::fromPathOrURL(modelsDir + switchTo + ".rb")); }
//--------------------------------------------------------------------------- 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; }
bool KJSDebugWin::sourceParsed(KJS::ExecState *exec, int sourceId, const KJS::UString &source, int errorLine) { // Work out which source file this fragment is in SourceFile *sourceFile = 0; if(!m_nextSourceUrl.isEmpty()) sourceFile = getSourceFile(exec->interpreter(), m_nextSourceUrl); int index; if(!sourceFile) { index = m_sourceSel->count(); if(!m_nextSourceUrl.isEmpty()) { QString code = source.qstring(); KParts::ReadOnlyPart *part = static_cast< ScriptInterpreter * >(exec->interpreter())->part(); if(m_nextSourceUrl == part->url().url()) { // Only store the code here if it's not from the part's html page... in that // case we can get it from KHTMLPageCache code = QString::null; } sourceFile = new SourceFile(m_nextSourceUrl, code, exec->interpreter()); setSourceFile(exec->interpreter(), m_nextSourceUrl, sourceFile); m_sourceSelFiles.append(sourceFile); m_sourceSel->insertItem(m_nextSourceUrl); } else { // Sourced passed from somewhere else (possibly an eval call)... we don't know the url, // but we still know the interpreter sourceFile = new SourceFile("(unknown)", source.qstring(), exec->interpreter()); m_sourceSelFiles.append(sourceFile); m_sourceSel->insertItem(QString::number(index) += "-???"); } } else { // Ensure that each source file to be displayed is associated with // an appropriate interpreter if(!sourceFile->interpreter) sourceFile->interpreter = exec->interpreter(); for(index = 0; index < m_sourceSel->count(); index++) { if(m_sourceSelFiles.at(index) == sourceFile) break; } assert(index < m_sourceSel->count()); } SourceFragment *sf = new SourceFragment(sourceId, m_nextSourceBaseLine, errorLine, sourceFile); m_sourceFragments[sourceId] = sf; if(m_sourceSel->currentItem() < 0) m_sourceSel->setCurrentItem(index); if(m_sourceSel->currentItem() == index) { displaySourceFile(sourceFile, true); } m_nextSourceBaseLine = 1; m_nextSourceUrl = ""; return (m_mode != Stop); }