void KateProject::slotModifiedChanged(KTextEditor::Document* document) { KateProjectItem *item = itemForFile (m_documents.value (document)); if (!item) return; item->slotModifiedChanged(document); }
void KateProject::slotModifiedOnDisk (KTextEditor::Document *document, bool isModified, KTextEditor::ModificationInterface::ModifiedOnDiskReason reason) { KateProjectItem *item = itemForFile (m_documents.value (document)); if (!item) return; item->slotModifiedOnDisk(document,isModified, reason); }
void KateProject::registerDocument (KTextEditor::Document *document) { // remember the document, if not already there if (!m_documents.contains(document)) m_documents[document] = document->url().toLocalFile (); // try to get item for the document KateProjectItem *item = itemForFile (document->url().toLocalFile ()); // if we got one, we are done, else create a dummy! if (item) { disconnect(document,SIGNAL(modifiedChanged(KTextEditor::Document *)),this,SLOT(slotModifiedChanged(KTextEditor::Document *))); disconnect(document,SIGNAL(modifiedOnDisk(KTextEditor::Document*,bool,KTextEditor::ModificationInterface::ModifiedOnDiskReason)),this,SLOT(slotModifiedOnDisk(KTextEditor::Document*,bool,KTextEditor::ModificationInterface::ModifiedOnDiskReason))); item->slotModifiedChanged(document); /*FIXME item->slotModifiedOnDisk(document,document->isModified(),qobject_cast<KTextEditor::ModificationInterface*>(document)->modifiedOnDisk()); FIXME*/ connect(document,SIGNAL(modifiedChanged(KTextEditor::Document *)),this,SLOT(slotModifiedChanged(KTextEditor::Document *))); connect(document,SIGNAL(modifiedOnDisk(KTextEditor::Document*,bool,KTextEditor::ModificationInterface::ModifiedOnDiskReason)),this,SLOT(slotModifiedOnDisk(KTextEditor::Document*,bool,KTextEditor::ModificationInterface::ModifiedOnDiskReason))); return; } // perhaps create the parent item if (!m_documentsParent) { m_documentsParent = new KateProjectItem (KateProjectItem::Directory, i18n ("<untracked>")); m_model.insertRow (0, m_documentsParent); } // create document item QFileInfo fileInfo (document->url().toLocalFile ()); KateProjectItem *fileItem = new KateProjectItem (KateProjectItem::File, fileInfo.fileName()); fileItem->setData(document->url().toLocalFile (), Qt::ToolTipRole); fileItem->slotModifiedChanged(document); connect(document,SIGNAL(modifiedChanged(KTextEditor::Document *)),this,SLOT(slotModifiedChanged(KTextEditor::Document *))); connect(document,SIGNAL(modifiedOnDisk(KTextEditor::Document*,bool,KTextEditor::ModificationInterface::ModifiedOnDiskReason)),this,SLOT(slotModifiedOnDisk(KTextEditor::Document*,bool,KTextEditor::ModificationInterface::ModifiedOnDiskReason))); bool inserted = false; for (int i = 0; i < m_documentsParent->rowCount(); ++i) { if (m_documentsParent->child (i)->data(Qt::UserRole).toString() > document->url().toLocalFile ()) { m_documentsParent->insertRow (i, fileItem); inserted = true; break; } } if (!inserted) m_documentsParent->appendRow (fileItem); fileItem->setData (document->url().toLocalFile (), Qt::UserRole); fileItem->setData (QVariant (true), Qt::UserRole + 3); if (!m_file2Item) m_file2Item = KateProjectSharedQMapStringItem (new QMap<QString, KateProjectItem *> ()); (*m_file2Item)[document->url().toLocalFile ()] = fileItem; }
void KateProjectWorker::loadFilesEntry(QStandardItem *parent, const QVariantMap &filesEntry, QMap<QString, KateProjectItem *> *file2Item) { QDir dir(m_baseDir); if (!dir.cd(filesEntry[QStringLiteral("directory")].toString())) { return; } QStringList files = findFiles(dir, filesEntry); if (files.isEmpty()) { return; } files.sort(); /** * construct paths first in tree and items in a map */ QMap<QString, QStandardItem *> dir2Item; dir2Item[QString()] = parent; QList<QPair<QStandardItem *, QStandardItem *> > item2ParentPath; for (const QString &filePath : files) { /** * skip dupes */ if (file2Item->contains(filePath)) { continue; } /** * get file info and skip NON-files */ QFileInfo fileInfo(filePath); if (!fileInfo.isFile()) { continue; } /** * construct the item with right directory prefix * already hang in directories in tree */ KateProjectItem *fileItem = new KateProjectItem(KateProjectItem::File, fileInfo.fileName()); fileItem->setData(filePath, Qt::ToolTipRole); // get the directory's relative path to the base directory QString dirRelPath = dir.relativeFilePath(fileInfo.absolutePath()); // if the relative path is ".", clean it up if (dirRelPath == QStringLiteral(".")) { dirRelPath = QString(); } item2ParentPath.append(QPair<QStandardItem *, QStandardItem *>(fileItem, directoryParent(dir2Item, dirRelPath))); fileItem->setData(filePath, Qt::UserRole); (*file2Item)[filePath] = fileItem; } /** * plug in the file items to the tree */ auto i = item2ParentPath.constBegin(); while (i != item2ParentPath.constEnd()) { i->second->appendRow(i->first); ++i; } }