Exemple #1
0
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;
}
Exemple #2
0
void KateProject::slotModifiedChanged(KTextEditor::Document* document) {
  KateProjectItem *item = itemForFile (m_documents.value (document));
  
  if (!item) return;
  
  item->slotModifiedChanged(document);
}