本文整理汇总了C++中IDocument类的典型用法代码示例。如果您正苦于以下问题:C++ IDocument类的具体用法?C++ IDocument怎么用?C++ IDocument使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
bool done = false;
string ext;
string docname;
while ( !done )
{
cout << endl << endl << "Enter the document name: ";
cin >> docname;
cout << "Enter the file extention: " << docname << ".";
cin >> ext;
string filename = docname + "." + ext;
IDocument* doc = NULL;
if ( ext == "txt" ) { doc = new TextDocument; }
else if ( ext == "csv" ) { doc = new CsvDocument; }
else if ( ext == "html" ) { doc = new WebDocument; }
else
{
cout << "Unknown file type" << endl;
continue;
}
doc->GetInput();
doc->Save( filename );
delete doc;
}
return 0;
}
示例2: cursorItemText
//Returns only the name, no template-parameters or scope
QString cursorItemText() {
KDevelop::DUChainReadLocker lock( DUChain::lock() );
Declaration* decl = cursorDeclaration();
if(!decl)
return QString();
IDocument* doc = ICore::self()->documentController()->activeDocument();
if(!doc)
return QString();
TopDUContext* context = DUChainUtils::standardContextForUrl( doc->url() );
if( !context ) {
qCDebug(PLUGIN_QUICKOPEN) << "Got no standard context";
return QString();
}
AbstractType::Ptr t = decl->abstractType();
IdentifiedType* idType = dynamic_cast<IdentifiedType*>(t.data());
if( idType && idType->declaration(context) )
decl = idType->declaration(context);
if(!decl->qualifiedIdentifier().isEmpty())
return decl->qualifiedIdentifier().last().identifier().str();
return QString();
}
示例3: IDocument
/*!
* \brief DocumentManager::createDocument
*/
void DocumentManager::createDocument()
{
IDocument *d = new IDocument();
d->setObjectName(QString("%1").arg(i++));
addDocument(d);
;
}
示例4: displayNameOfEditor
static inline QString displayNameOfEditor(const QString &fileName)
{
IDocument *document = DocumentModel::documentForFilePath(fileName);
if (document)
return document->displayName();
return QString();
}
示例5: 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);
}
}
}
示例6: updateEnabled
void QmlProjectRunConfiguration::updateEnabled()
{
bool qmlFileFound = false;
if (mainScriptSource() == FileInEditor) {
IDocument *document = EditorManager::currentDocument();
if (document) {
m_currentFileFilename = document->filePath();
if (MimeDatabase::findByFile(mainScript()).type() == QLatin1String("application/x-qml"))
qmlFileFound = true;
}
if (!document
|| MimeDatabase::findByFile(mainScript()).type() == QLatin1String("application/x-qmlproject")) {
// find a qml file with lowercase filename. This is slow, but only done
// in initialization/other border cases.
foreach (const QString &filename, target()->project()->files(ProjectExplorer::Project::AllFiles)) {
const QFileInfo fi(filename);
if (!filename.isEmpty() && fi.baseName()[0].isLower()
&& MimeDatabase::findByFile(fi).type() == QLatin1String("application/x-qml"))
{
m_currentFileFilename = filename;
qmlFileFound = true;
break;
}
}
}
示例7: itemFromIndex
void GrepOutputModel::activate( const QModelIndex &idx )
{
QStandardItem *stditem = itemFromIndex(idx);
GrepOutputItem *grepitem = dynamic_cast<GrepOutputItem*>(stditem);
if( !grepitem || !grepitem->isText() )
return;
QUrl url = QUrl::fromLocalFile(grepitem->filename());
int line = grepitem->lineNumber() - 1;
KTextEditor::Range range( line, 0, line+1, 0);
// Try to find the actual text range we found during the grep
IDocument* doc = ICore::self()->documentController()->documentForUrl( url );
if(!doc)
doc = ICore::self()->documentController()->openDocument( url, range );
if(!doc)
return;
if (KTextEditor::Document* tdoc = doc->textDocument()) {
KTextEditor::Range matchRange = grepitem->change()->m_range;
QString actualText = tdoc->text(matchRange);
QString expectedText = grepitem->change()->m_oldText;
if (actualText == expectedText) {
range = matchRange;
}
}
ICore::self()->documentController()->activateDocument( doc, range );
}
示例8: updateEnabled
void QmlProjectRunConfiguration::updateEnabled()
{
bool qmlFileFound = false;
if (mainScriptSource() == FileInEditor) {
Utils::MimeDatabase mimeDataBase;
IDocument *document = EditorManager::currentDocument();
Utils::MimeType mainScriptMimeType = mimeDataBase.mimeTypeForFile(mainScript());
if (document) {
m_currentFileFilename = document->filePath().toString();
if (mainScriptMimeType.matchesName(QLatin1String(ProjectExplorer::Constants::QML_MIMETYPE)))
qmlFileFound = true;
}
if (!document
|| mainScriptMimeType.matchesName(QLatin1String(QmlJSTools::Constants::QMLPROJECT_MIMETYPE))) {
// find a qml file with lowercase filename. This is slow, but only done
// in initialization/other border cases.
foreach (const QString &filename, target()->project()->files(Project::AllFiles)) {
const QFileInfo fi(filename);
if (!filename.isEmpty() && fi.baseName()[0].isLower()
&& mimeDataBase.mimeTypeForFile(fi).matchesName(QLatin1String(ProjectExplorer::Constants::QML_MIMETYPE)))
{
m_currentFileFilename = filename;
qmlFileFound = true;
break;
}
}
}
示例9: createCodeRepresentation
CodeRepresentation::Ptr createCodeRepresentation(const IndexedString& path) {
if(artificialCodeRepresentationExists(path))
return CodeRepresentation::Ptr(new StringCodeRepresentation(representationForPath(path)));
IDocument* document = ICore::self()->documentController()->documentForUrl(path.toUrl());
if(document && document->textDocument())
return CodeRepresentation::Ptr(new EditorCodeRepresentation(document->textDocument()));
else
return CodeRepresentation::Ptr(new FileCodeRepresentation(path));
}
示例10: QTC_ASSERT
bool BazaarPlugin::submitEditorAboutToClose()
{
CommitEditor *commitEditor = qobject_cast<CommitEditor *>(submitEditor());
QTC_ASSERT(commitEditor, return true);
IDocument *editorDocument = commitEditor->document();
QTC_ASSERT(editorDocument, return true);
bool dummyPrompt = false;
const VcsBaseSubmitEditor::PromptSubmitResult response =
commitEditor->promptSubmit(tr("Close Commit Editor"), tr("Do you want to commit the changes?"),
tr("Message check failed. Do you want to proceed?"),
&dummyPrompt, !m_submitActionTriggered);
m_submitActionTriggered = false;
switch (response) {
case VcsBaseSubmitEditor::SubmitCanceled:
return false;
case VcsBaseSubmitEditor::SubmitDiscarded:
return true;
default:
break;
}
QStringList files = commitEditor->checkedFiles();
if (!files.empty()) {
//save the commit message
if (!DocumentManager::saveDocument(editorDocument))
return false;
//rewrite entries of the form 'file => newfile' to 'newfile' because
//this would mess the commit command
for (QStringList::iterator iFile = files.begin(); iFile != files.end(); ++iFile) {
const QStringList parts = iFile->split(QLatin1String(" => "), QString::SkipEmptyParts);
if (!parts.isEmpty())
*iFile = parts.last();
}
BazaarCommitWidget *commitWidget = commitEditor->commitWidget();
QStringList extraOptions;
// Author
if (!commitWidget->committer().isEmpty())
extraOptions.append(QLatin1String("--author=") + commitWidget->committer());
// Fixed bugs
foreach (const QString &fix, commitWidget->fixedBugs()) {
if (!fix.isEmpty())
extraOptions << QLatin1String("--fixes") << fix;
}
// Whether local commit or not
if (commitWidget->isLocalOptionEnabled())
extraOptions += QLatin1String("--local");
m_client->commit(m_submitRepository, files, editorDocument->filePath(), extraOptions);
}
return true;
}
示例11: QTC_ASSERT
bool SubversionPlugin::submitEditorAboutToClose()
{
if (!isCommitEditorOpen())
return true;
SubversionSubmitEditor *editor = qobject_cast<SubversionSubmitEditor *>(submitEditor());
QTC_ASSERT(editor, return true);
IDocument *editorDocument = editor->document();
QTC_ASSERT(editorDocument, return true);
// Submit editor closing. Make it write out the commit message
// and retrieve files
const QFileInfo editorFile = editorDocument->filePath().toFileInfo();
const QFileInfo changeFile(m_commitMessageFileName);
if (editorFile.absoluteFilePath() != changeFile.absoluteFilePath())
return true; // Oops?!
// Prompt user. Force a prompt unless submit was actually invoked (that
// is, the editor was closed or shutdown).
SubversionSettings newSettings = m_settings;
const VcsBaseSubmitEditor::PromptSubmitResult answer =
editor->promptSubmit(tr("Closing Subversion Editor"),
tr("Do you want to commit the change?"),
tr("The commit message check failed. Do you want to commit the change?"),
newSettings.boolPointer(SubversionSettings::promptOnSubmitKey),
!m_submitActionTriggered);
m_submitActionTriggered = false;
switch (answer) {
case VcsBaseSubmitEditor::SubmitCanceled:
return false; // Keep editing and change file
case VcsBaseSubmitEditor::SubmitDiscarded:
cleanCommitMessageFile();
return true; // Cancel all
default:
break;
}
setSettings(newSettings); // in case someone turned prompting off
const QStringList fileList = editor->checkedFiles();
bool closeEditor = true;
if (!fileList.empty()) {
// get message & commit
closeEditor = DocumentManager::saveDocument(editorDocument);
if (closeEditor) {
VcsCommand *commitCmd = m_client->createCommitCmd(m_commitRepository,
fileList,
m_commitMessageFileName);
QObject::connect(commitCmd, &VcsCommand::finished,
this, [this]() { cleanCommitMessageFile(); });
commitCmd->execute();
}
}
return closeEditor;
}
示例12: applyAllChanges
bool ApplyChangesWidget::applyAllChanges()
{
/// @todo implement safeguard in case a file saving fails
bool ret = true;
for(int i = 0; i < d->m_files.size(); ++i )
if(d->m_editParts[i]->saveAs(d->m_files[i].toUrl())) {
IDocument* doc = ICore::self()->documentController()->documentForUrl(d->m_files[i].toUrl());
if(doc && doc->state()==IDocument::Dirty)
doc->reload();
} else
ret = false;
return ret;
}
示例13: fontMinimizeHeight_triggered
//-----------------------------------------------------------------------------
void ActionFontHandlers::fontMinimizeHeight_triggered()
{
if (this->editor() != NULL)
{
IDocument *doc = this->editor()->document();
int left = std::numeric_limits<int>::max();
int top = std::numeric_limits<int>::max();
int right = 0;
int bottom = 0;
int l, t, r, b;
// find limits
QStringList keys = doc->dataContainer()->keys();
QListIterator<QString> it(keys);
it.toFront();
while (it.hasNext())
{
QString key = it.next();
const QImage *original = doc->dataContainer()->image(key);
BitmapHelper::findEmptyArea(original, &l, &t, &r, &b);
left = qMin(left, l);
top = qMin(top, t);
right = qMin(right, r);
bottom = qMin(bottom, b);
}
DialogCanvasResize dialog(doc->dataContainer(), this->mMainWindow->parentWidget());
dialog.selectKeys(keys);
dialog.setResizeInfo(-left, -top, -right, -bottom);
if (dialog.exec() == QDialog::Accepted)
{
dialog.resizeInfo(&left, &top, &right, &bottom);
if (left != 0 || top != 0 || right != 0 || bottom != 0)
{
doc->beginChanges();
QStringListIterator iterator(keys);
while (iterator.hasNext())
{
QString key = iterator.next();
const QImage *original = doc->dataContainer()->image(key);
QImage result = BitmapHelper::crop(original, left, top, right, bottom, BitmapEditorOptions::color2());
doc->dataContainer()->setImage(key, &result);
}
doc->endChanges();
}
}
}
}
示例14: TF_ASSERT
void BaseEditor::actionOpen()
{
auto uiFramework = pImpl_->get<IUIFramework>();
TF_ASSERT(uiFramework != nullptr);
if (!uiFramework)
{
return;
}
IDocument* doc = nullptr;
auto path = uiFramework->showOpenFileDialog("Open", lastSaveFolder(), fileOpenFilter(), IUIFramework::None);
if (!path.empty())
{
auto editor = pImpl_->get<IEditor>();
TF_ASSERT(editor != nullptr);
if (editor)
{
doc = editor->open(path.front().c_str());
if (doc == nullptr)
{
return;
}
bindDocument(doc);
if (path.front() == doc->getFilePath())
{
clearCheckoutState();
}
}
onOpen(path.front().c_str(), doc);
auto editorCommon = pImpl_->get<IEditorCommon>();
TF_ASSERT(editorCommon != nullptr);
if (editorCommon)
{
editorCommon->addToRecentFiles(path.front().c_str());
}
}
}
示例15: renameUrl
bool KDevelop::renameUrl(const KDevelop::IProject* project, const KUrl& oldname, const KUrl& newname)
{
bool wasVcsMoved = false;
IPlugin* vcsplugin = project->versionControlPlugin();
if (vcsplugin) {
IBasicVersionControl* vcs = vcsplugin->extension<IBasicVersionControl>();
// We have a vcs and the file/folder is controller, need to make the rename through vcs
if (vcs->isVersionControlled(oldname)) {
VcsJob* job = vcs->move(oldname, newname);
if (job && !job->exec()) {
return false;
}
wasVcsMoved = true;
}
}
// Fallback for the case of no vcs, or not-vcs-managed file/folder
// try to save-as the text document, so users can directly continue to work
// on the renamed url as well as keeping the undo-stack intact
IDocument* document = ICore::self()->documentController()->documentForUrl(oldname);
if (document && document->textDocument()) {
if (!document->textDocument()->saveAs(newname)) {
return false;
}
if (!wasVcsMoved) {
// unlink the old file
removeUrl(project, oldname, false);
}
return true;
} else if (!wasVcsMoved) {
// fallback for non-textdocuments (also folders e.g.)
KIO::CopyJob* job = KIO::move(oldname, newname);
return KIO::NetAccess::synchronousRun(job, 0);
} else {
return true;
}
}