KTextEditor::View *KateViewManager::openUrlWithView (const KUrl &url, const QString& encoding) { KTextEditor::Document *doc = KateDocManager::self()->openUrl (url, encoding); if (!doc) return 0; if (!doc->url().isEmpty()) m_mainWindow->fileOpenRecent->addUrl( doc->url() ); activateView( doc ); return activeView (); }
void KateFileTree::slotCopyFilename() { KTextEditor::Document *doc = model()->data(m_indexContextMenu, KateFileTreeModel::DocumentRole).value<KTextEditor::Document *>(); if (doc) { QApplication::clipboard()->setText(doc->url().url()); } }
void KateFileTree::slotOpenWithMenuAction(QAction* a) { KUrl::List list; KTextEditor::Document *doc = model()->data(m_indexContextMenu, KateFileTreeModel::DocumentRole).value<KTextEditor::Document *>(); if (!doc) return; list.append( doc->url() ); const QString openWith = a->data().toString(); if (openWith.isEmpty()) { // display "open with" dialog KOpenWithDialog dlg(list); if (dlg.exec()) KRun::run(*dlg.service(), list, this); return; } KService::Ptr app = KService::serviceByDesktopPath(openWith); if (app) { KRun::run(*app, list, this); } else { KMessageBox::error(this, i18n("Application '%1' not found.", openWith), i18n("Application not found")); } }
KTextEditor::Document *KateViewManager::openUrl (const KUrl &url, const QString& encoding, bool activate, bool isTempFile, const KateDocumentInfo& docInfo) { KTextEditor::Document *doc = KateDocManager::self()->openUrl (url, encoding, isTempFile, docInfo); if (!doc->url().isEmpty()) m_mainWindow->fileOpenRecent->addUrl( doc->url() ); if (activate) activateView( doc ); return doc; }
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); }
// Scan throughout the entire document for possible completions, // ignoring any dublets const QStringList KateWordCompletionModel::allMatches( KTextEditor::View *view, const KTextEditor::Range &range ) const { KTextEditor::Document *doc = view->document(); QString match_str = doc->text(range); QString s, m; QSet<QString> seen; QStringList l; int i( 0 ); int pos( 0 ); QRegExp re( "\\b(" + match_str + "\\w{1,})" ); while( i < doc->lines() ) { s = doc->line( i ); pos = 0; while ( pos >= 0 ) { pos = re.indexIn( s, pos ); if ( pos >= 0 ) { // typing in the middle of a word if ( ! ( i == range.start().line() && pos == range.start().column() ) ) { m = re.cap( 1 ); if ( ! seen.contains( m ) ) { seen.insert( m ); l << m; } } pos += re.matchedLength(); } } i++; } // Global completion // int db_area = KDebug::registerArea("ktuan-debug"); QMap<QString, QStringList>::const_iterator ci = doc_word_list.constBegin(); while (ci != doc_word_list.constEnd()) { if (ci.key() != doc->url().prettyUrl()) { QStringList list = ci.value(); foreach (QString word, list) { // kDebug(db_area) << "complete word " << word; if (word.startsWith(match_str) && !seen.contains(word)) { // kDebug(db_area) << "Global completion"; seen.insert(word); l << word; } } } ++ci; }
virtual QString contents( const QString& fileName ) { QString contents = QString::null; if ( !m_readFromDisk ) { m_deadlock.unlock(); // GET LOCK kapp->lock (); //kdDebug(9007) << "-------> kapp locked" << endl; QPtrList<KParts::Part> parts( *m_cppSupport->partController() ->parts() ); QPtrListIterator<KParts::Part> it( parts ); while ( it.current() ) { KTextEditor::Document * doc = dynamic_cast<KTextEditor::Document*>( it.current() ); ++it; KTextEditor::EditInterface* editIface = dynamic_cast<KTextEditor::EditInterface*>( doc ); if ( !doc || !editIface || doc->url().path() != fileName ) continue; contents = QString( editIface->text().ascii() ); // deep copy //kdDebug(9007) << "-------> kapp unlocked" << endl; break; } // RELEASE LOCK kapp->unlock(); m_deadlock.lock(); //kdDebug(9007) << "-------> kapp unlocked" << endl; } if( m_readFromDisk || contents == QString::null ) { QFile f( fileName ); if ( f.open( IO_ReadOnly ) ) { QTextStream stream( &f ); contents = stream.read(); f.close(); } } return contents; }
virtual QString contents( const QString& fileName ) { if( !m_readFromDisk ){ //kdDebug(9013) << "-------> kapp is locked = " << kapp->locked() << endl; bool needToLock = kapp->locked() == false; if( needToLock ) kapp->lock(); //kdDebug(9013) << "-------> kapp locked" << endl; QPtrList<KParts::Part> parts( *m_javaSupport->partController()->parts() ); QPtrListIterator<KParts::Part> it( parts ); while( it.current() ){ KTextEditor::Document* doc = dynamic_cast<KTextEditor::Document*>( it.current() ); ++it; KTextEditor::EditInterface* editIface = dynamic_cast<KTextEditor::EditInterface*>( doc ); if( !doc || !editIface || doc->url().path() != fileName ) continue; QString contents = QString( editIface->text().ascii() ); // deep copy if( needToLock ) kapp->unlock(); //kdDebug(9013) << "-------> kapp unlocked" << endl; return contents; } if( needToLock ) kapp->unlock(); //kdDebug(9013) << "-------> kapp unlocked" << endl; } QFile f( fileName ); QTextStream stream( &f ); if( f.open(IO_ReadOnly) ){ QString contents = stream.read(); f.close(); return contents; } return QString::null; }
QStringList PHPFile::readFromEditor() { QStringList contents; kapp->lock(); QPtrList<KParts::Part> parts( *m_part->partController()->parts() ); QPtrListIterator<KParts::Part> it( parts ); while( it.current() ){ KTextEditor::Document* doc = dynamic_cast<KTextEditor::Document*>( it.current() ); ++it; KTextEditor::EditInterface* editIface = dynamic_cast<KTextEditor::EditInterface*>( doc ); if ( !doc || !editIface || doc->url().path() != fileName() ) continue; contents = QStringList::split("\n", editIface->text().ascii(), true); break; } kapp->unlock(); return contents; }
// ### the code below is slightly modified from kdelibs/kate/part/katedialogs, // class KateModOnHdPrompt. void KateMwModOnHdDialog::slotDiff() { if ( !btnDiff->isEnabled()) // diff button already pressed, proc not finished yet return; if ( ! twDocuments->currentItem() ) return; KTextEditor::Document *doc = ((KateDocItem*)twDocuments->currentItem())->document; // don't try to diff a deleted file if ( KateDocManager::self()->documentInfo( doc )->modifiedOnDiscReason == KTextEditor::ModificationInterface::OnDiskDeleted ) return; if (m_diffFile) return; m_diffFile = new KTemporaryFile(); m_diffFile->open(); // Start a KProcess that creates a diff m_proc = new KProcess( this ); m_proc->setOutputChannelMode( KProcess::MergedChannels ); *m_proc << "diff" << "-ub" << "-" << doc->url().toLocalFile(); connect( m_proc, SIGNAL(readyRead()), this, SLOT(slotDataAvailable()) ); connect( m_proc, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(slotPDone()) ); setCursor( Qt::WaitCursor ); btnDiff->setEnabled(false); m_proc->start(); QTextStream ts(m_proc); int lastln = doc->lines(); for ( int l = 0; l < lastln; ++l ) ts << doc->line( l ) << '\n'; ts.flush(); m_proc->closeWriteChannel(); }