本文整理汇总了C++中ktexteditor::Document类的典型用法代码示例。如果您正苦于以下问题:C++ Document类的具体用法?C++ Document怎么用?C++ Document使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Document类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: closeCurrentDocument
void EditorTabWidget::closeCurrentDocument()
{
if(count() == 0) return;
m_closeGuard = true;
int index = currentPageIndex();
QValueList<Document_t>::iterator it = m_docList.at(index);
KTextEditor::Document* doc = (*it).view->document();
doc->closeURL();
KTextEditor::View* view = (*it).view;
delete view;
delete doc;
QWidget* w = page(index);
removePage(w);
m_docList.remove(it);
if(count() == 0) {
disableEditorActions();
}
m_closeGuard = false;
}
示例2: saveCurrentFile
bool EditorTabWidget::saveCurrentFile()
{
if(count() == 0) return false;
KTextEditor::Document *doc = (*(m_docList.at(currentPageIndex()))).view->document();
return doc->save();
}
示例3: testKateDocumentAndViewCreation
void TestShellDocumentOperation::testKateDocumentAndViewCreation()
{
//create one document
IDocumentController *documentController = Core::self()->documentController();
documentController->openDocumentFromText(QLatin1String(""));
QCOMPARE(documentController->openDocuments().count(), 1);
//assure we have only one kate view for the newly created document
KTextEditor::Document *doc = documentController->openDocuments().at(0)->textDocument();
QCOMPARE(doc->views().count(), 1);
QCOMPARE(dynamic_cast<KTextEditor::MovingInterface*>(doc)->revision(), qint64(0));
//also assure the view's xmlgui is plugged in
KParts::MainWindow *main = Core::self()->uiControllerInternal()->activeMainWindow();
QVERIFY(main);
QVERIFY(main->guiFactory()->clients().contains(doc->views().at(0)));
//KTextEditor::views is internally a QHash::keys() call: so the order of the views will vary
const auto originalView = doc->views().at(0);
//create the new view and activate it (using split action from mainwindow)
QAction *splitAction = main->actionCollection()->action(QStringLiteral("split_vertical"));
QVERIFY(splitAction);
splitAction->trigger();
const auto viewList = doc->views();
QCOMPARE(viewList.count(), 2);
const auto newlySplitView = originalView == viewList[0] ? viewList[1] : viewList[0];
//check that we did switch to the new xmlguiclient
QVERIFY(!main->guiFactory()->clients().contains(originalView));
QVERIFY(main->guiFactory()->clients().contains(newlySplitView));
documentController->openDocuments().at(0)->close(IDocument::Discard);
}
示例4: sync
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());
}
}
}
示例5: createView
KTextEditor::View* HtmlEditor::createView( QWidget* parent )
{
KTextEditor::Document *document = mEditor->createDocument( parent );
bool result = document->setHighlightingMode( "html" );
if ( result ) {
kDebug() << "Syntax highlighting enabled";
}
KTextEditor::View *view = document->createView( parent );
QMenu *menu = view->defaultContextMenu();
KTextEditor::ConfigInterface *interface = qobject_cast< KTextEditor::ConfigInterface* >( view );
if ( interface ) {
KAction *actWordWrap = new KAction( i18n( "Dynamic Word Wrap" ), view );
actWordWrap->setCheckable( true );
connect( actWordWrap, SIGNAL(triggered(bool)), this, SLOT(toggleWordWrap()) );
KAction *actLineNumber = new KAction( i18n("Show line numbers"), view );
actLineNumber->setCheckable( true );
connect( actLineNumber, SIGNAL(triggered(bool)), this, SLOT(toggleLineNumber()) );
QMenu *options = new QMenu( i18n( "Options" ), qobject_cast< QWidget* >( view ) );
options->addAction( actWordWrap );
options->addAction( actLineNumber );
menu->addSeparator();
menu->addMenu( options );
interface->setConfigValue( "dynamic-word-wrap", true );
actWordWrap->setChecked( true );
}
view->setContextMenu( menu );
return view;
}
示例6: slotFixOpenWithMenu
void KateFileTree::slotFixOpenWithMenu()
{
QMenu *menu = (QMenu*)sender();
menu->clear();
KTextEditor::Document *doc = model()->data(m_indexContextMenu, KateFileTreeModel::DocumentRole).value<KTextEditor::Document *>();
if (!doc) return;
// get a list of appropriate services.
KMimeType::Ptr mime = KMimeType::mimeType(doc->mimeType());
//kDebug(13001) << "mime type: " << mime->name();
QAction *a = 0;
KService::List offers = KMimeTypeTrader::self()->query(mime->name(), "Application");
// for each one, insert a menu item...
for(KService::List::Iterator it = offers.begin(); it != offers.end(); ++it)
{
KService::Ptr service = *it;
if (service->name() == "Kate") continue;
a = menu->addAction(KIcon(service->icon()), service->name());
a->setData(service->entryPath());
}
// append "Other..." to call the KDE "open with" dialog.
a = menu->addAction(i18n("&Other..."));
a->setData(QString());
}
示例7: slotOpenWithMenuAction
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"));
}
}
示例8: slotCopyFilename
void KateFileTree::slotCopyFilename()
{
KTextEditor::Document *doc = model()->data(m_indexContextMenu, KateFileTreeModel::DocumentRole).value<KTextEditor::Document *>();
if (doc) {
QApplication::clipboard()->setText(doc->url().url());
}
}
示例9: lock
void KDevelop::DocumentationController::doShowDocumentation()
{
IDocument* doc = ICore::self()->documentController()->activeDocument();
if(!doc)
return;
KTextEditor::Document* textDoc = doc->textDocument();
if(!textDoc)
return;
KTextEditor::View* view = textDoc->activeView();
if(!view)
return;
KDevelop::DUChainReadLocker lock( DUChain::lock() );
Declaration *dec = DUChainUtils::declarationForDefinition( DUChainUtils::itemUnderCursor( doc->url(), SimpleCursor(view->cursorPosition()) ) );
if(dec) {
KSharedPtr< IDocumentation > documentation = documentationForDeclaration(dec);
if(documentation) {
showDocumentation(documentation);
}
}
}
示例10: allMatches
// 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;
}
示例11: execute
void KeywordItem::execute(KTextEditor::View* view, const KTextEditor::Range& word)
{
KTextEditor::Document *document = view->document();
if ( !m_replacement.isEmpty() ) {
QString replacement = m_replacement;
replacement = replacement.replace('\n', '\n' + getIndendation(document->line(word.start().line())));
replacement = replacement.replace(QLatin1String("%INDENT%"), indentString(document));
int cursorPos = replacement.indexOf(QStringLiteral("%CURSOR%"));
int selectionEnd = -1;
if ( cursorPos != -1 ) {
replacement.remove(QStringLiteral("%CURSOR%"));
} else {
cursorPos = replacement.indexOf(QStringLiteral("%SELECT%"));
if ( cursorPos != -1 ) {
replacement.remove(QStringLiteral("%SELECT%"));
selectionEnd = replacement.indexOf(QStringLiteral("%ENDSELECT%"), cursorPos + 1);
if ( selectionEnd == -1 ) {
selectionEnd = replacement.length();
}
replacement.remove(QStringLiteral("%ENDSELECT%"));
}
}
document->replaceText(word, replacement);
if ( cursorPos != -1 ) {
if (view) {
replacement = replacement.left(cursorPos);
KTextEditor::Cursor newPos(
word.start().line() + replacement.count('\n'),
word.start().column() + replacement.length() - replacement.lastIndexOf('\n') - 1
);
view->setCursorPosition(newPos);
if ( selectionEnd != -1 ) {
///TODO: maybe we want to support multi-line selections in the future?
view->setSelection(
KTextEditor::Range(
newPos,
KTextEditor::Cursor(
newPos.line(),
newPos.column() + selectionEnd - cursorPos
)
)
);
}
}
}
} else {
document->replaceText(word, m_keyword + ' ');
}
}
示例12: activeView
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 ();
}
示例13: createTextPart
KTextEditor::Document* PartController::createTextPart(const QString &encoding)
{
KTextEditor::Document* doc = editorPart()->createDocument(this);
if ( !encoding.isNull() )
{
KParts::OpenUrlArguments args = doc->arguments();
args.setMimeType( QString::fromLatin1( "text/plain;" ) + encoding );
doc->setArguments( args );
}
doc->editor()->readConfig();
return doc;
}
示例14: openInput
bool KateApp::openInput (const QString &text)
{
activeMainWindow()->viewManager()->openUrl( KUrl(), "", true );
if (!activeMainWindow()->viewManager()->activeView ())
return false;
KTextEditor::Document *doc = activeMainWindow()->viewManager()->activeView ()->document();
if (!doc)
return false;
return doc->setText (text);
}
示例15: contents
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;
}