void KateFileTree::switchDocument( const QString &doc ) { if (doc.isEmpty()) { // no argument: switch to the previous document slotDocumentPrev(); } else if (doc.toInt() > 0 && doc.toInt() <= model()->rowCount( model()->parent(currentIndex()) )) { // numerical argument: switch to the nth document int i = doc.toInt() - 1; KTextEditor::Document *doc = model()->data(model()->index(i - 1, 0), KateFileTreeModel::DocumentRole).value<KTextEditor::Document *>(); if (doc) { emit activateDocument(doc); } } else { // string argument: switch to the given file QModelIndexList matches = model()->match(model()->index(0, 0), Qt::DisplayRole, QVariant(doc), 1, Qt::MatchContains); if (!matches.isEmpty()) { KTextEditor::Document *doc = model()->data(matches.takeFirst(), KateFileTreeModel::DocumentRole).value<KTextEditor::Document *>(); if (doc) { emit activateDocument(doc); } } } }
void KateFileTree::slotDocumentFirst() { KTextEditor::Document *doc = model()->data(model()->index(0, 0), KateFileTreeModel::DocumentRole).value<KTextEditor::Document *>(); if (doc) { emit activateDocument(doc); } }
void KateFileTree::slotDocumentLast() { int count = model()->rowCount( model()->parent(currentIndex()) ); KTextEditor::Document *doc = model()->data(model()->index(count - 1, 0), KateFileTreeModel::DocumentRole).value<KTextEditor::Document *>(); if (doc) { emit activateDocument(doc); } }
void KateFileTree::mouseClicked ( const QModelIndex &index ) { kDebug(debugArea()) << "got index" << index; KTextEditor::Document *doc = model()->data(index, KateFileTreeModel::DocumentRole).value<KTextEditor::Document *>(); if(doc) { kDebug(debugArea()) << "got doc" << index << "setting prev:" << QModelIndex(); emit activateDocument(doc); //m_previouslySelected = QModelIndex(); } else { kDebug(debugArea()) << "selecting previous item" << m_previouslySelected; selectionModel()->setCurrentIndex(m_previouslySelected,QItemSelectionModel::ClearAndSelect); } }
void KateFileTree::slotDocumentNext() { kDebug(debugArea()) << "BEGIN"; KateFileTreeProxyModel *ftpm = static_cast<KateFileTreeProxyModel*>(model()); QModelIndex current_index = currentIndex(); int parent_row_count = ftpm->rowCount( ftpm->parent(current_index) ); QModelIndex next; // scan down the tree skipping any dir nodes while(current_index.isValid()) { if(current_index.row() < parent_row_count-1) { current_index = ftpm->sibling(current_index.row()+1, current_index.column(), current_index); if(!current_index.isValid()) { break; } if(ftpm->isDir(current_index)) { // we have a dir node while(ftpm->isDir(current_index)) { current_index = ftpm->index(0, 0, current_index); } parent_row_count = ftpm->rowCount( ftpm->parent(current_index) ); if(!ftpm->isDir(current_index)) { next = current_index; break; } } else { // found document item next = current_index; break; } } else { // select the parent's next sibling QModelIndex parent_index = ftpm->parent(current_index); int grandparent_row_count = ftpm->rowCount( ftpm->parent(parent_index) ); current_index = parent_index; parent_row_count = grandparent_row_count; // at least if we're not past the last node if(!current_index.isValid()) { // paste the root node here, try and wrap around QModelIndex last_index = ftpm->index(0, 0, QModelIndex()); if(!last_index.isValid()) { break; } if(ftpm->isDir(last_index)) { // last node is a dir, select first child row while(ftpm->isDir(last_index)) { if(ftpm->rowCount(last_index)) { // has children, select first last_index = ftpm->index(0, 0, last_index); } } next = last_index; break; } else { // got first file node next = last_index; break; } } } } if(next.isValid()) { //kDebug(debugArea()) << "got next node:" << next; //kDebug(debugArea()) << "doc:" << ftpm->data(next, Qt::DisplayRole).value<QString>(); KTextEditor::Document *doc = model()->data(next, KateFileTreeModel::DocumentRole).value<KTextEditor::Document *>(); emit activateDocument(doc); } else { kDebug(debugArea()) << "didn't get next node :("; } kDebug(debugArea()) << "END"; }
void KateFileTree::slotDocumentPrev() { kDebug(debugArea()) << "BEGIN"; KateFileTreeProxyModel *ftpm = static_cast<KateFileTreeProxyModel*>(model()); QModelIndex current_index = currentIndex(); QModelIndex prev; // scan up the tree skipping any dir nodes //kDebug(debugArea()) << "cur" << ftpm->data(current_index, Qt::DisplayRole); while(current_index.isValid()) { if(current_index.row() > 0) { current_index = ftpm->sibling(current_index.row()-1, current_index.column(), current_index); //kDebug(debugArea()) << "get prev" << ftpm->data(current_index, Qt::DisplayRole); if(!current_index.isValid()) { //kDebug(debugArea()) << "somehow getting prev index from sibling didn't work :("; break; } if(ftpm->isDir(current_index)) { // try and select the last child in this parent //kDebug(debugArea()) << "is a dir"; int children = ftpm->rowCount(current_index); current_index = ftpm->index(children-1, 0, current_index); //kDebug(debugArea()) << "child" << ftpm->data(current_index, Qt::DisplayRole); if(ftpm->isDir(current_index)) { // since we're a dir, keep going //kDebug(debugArea()) << "child is a dir"; while(ftpm->isDir(current_index)) { children = ftpm->rowCount(current_index); current_index = ftpm->index(children-1, 0, current_index); } if(!ftpm->isDir(current_index)) { prev = current_index; break; } continue; } else { // we're the previous file, set prev //kDebug(debugArea()) << "got doc 1"; prev = current_index; break; } } else { // found document item //kDebug(debugArea()) << "got doc 2"; prev = current_index; break; } } else { //kDebug(debugArea()) << "get parent"; // just select the parent, the logic above will handle the rest current_index = ftpm->parent(current_index); //kDebug(debugArea()) << "got parent" << ftpm->data(current_index, Qt::DisplayRole); if(!current_index.isValid()) { // paste the root node here, try and wrap around //kDebug(debugArea()) << "parent invalid"; int children = ftpm->rowCount(current_index); QModelIndex last_index = ftpm->index(children-1, 0, current_index); //kDebug(debugArea()) << "last" << ftpm->data(last_index, Qt::DisplayRole); if(!last_index.isValid()) break; if(ftpm->isDir(last_index)) { // last node is a dir, select last child row //kDebug(debugArea()) << "last root is a dir, select child"; int last_children = ftpm->rowCount(last_index); prev = ftpm->index(last_children-1, 0, last_index); //kDebug(debugArea()) << "last child" << ftpm->data(current_index, Qt::DisplayRole); // bug here? break; } else { // got last file node //kDebug(debugArea()) << "got doc"; prev = last_index; break; } } } } if(prev.isValid()) { //kDebug(debugArea()) << "got prev node:" << prev; //kDebug(debugArea()) << "doc:" << ftpm->data(prev, Qt::DisplayRole).value<QString>(); KTextEditor::Document *doc = model()->data(prev, KateFileTreeModel::DocumentRole).value<KTextEditor::Document *>(); emit activateDocument(doc); } else { kDebug(debugArea()) << "didn't get prev node :("; } kDebug(debugArea()) << "END"; }
/*! * Sets the active document path to path. * Emits activateDocument() with the workspace relative path. */ void LiveHubEngine::setActivePath(const QString &path) { m_activePath = path; emit activateDocument(m_watcher->relativeFilePath(path)); }