Commit 01a8422d authored by Kåre Särs's avatar Kåre Särs

S&R: Re-add the collapse/expand checkbox to the header item.

parent 2c5e75ff
......@@ -686,7 +686,9 @@ void KatePluginSearchView::folderFileListChanged()
void KatePluginSearchView::addHeaderItem(const QString& text)
{
QTreeWidgetItem *item = new QTreeWidgetItem(m_curResults->tree, QStringList(text));
item->setFlags(Qt::NoItemFlags);
item->setCheckState(0, Qt::Checked);
item->setFlags(item->flags() | Qt::ItemIsTristate);
m_curResults->tree->expandItem(item);
}
......@@ -701,22 +703,27 @@ QTreeWidgetItem * KatePluginSearchView::rootFileItem(const QString &url)
path.replace(m_resultBaseDir, "");
QString name = kurl.fileName();
for (int i=0; i<m_curResults->tree->topLevelItemCount(); i++) {
if (m_curResults->tree->topLevelItem(i)->data(0, Qt::UserRole).toString() == url) {
int matches = m_curResults->tree->topLevelItem(i)->data(1, Qt::UserRole).toInt() + 1;
if (m_curResults->tree->topLevelItemCount() == 0) {
addHeaderItem(i18n("<b><i>Results</i></b>"));
}
QTreeWidgetItem *root = m_curResults->tree->topLevelItem(0);
for (int i=0; i<root->childCount(); i++) {
if (root->child(i)->data(0, Qt::UserRole).toString() == url) {
int matches = root->child(i)->data(1, Qt::UserRole).toInt() + 1;
QString tmpUrl = QString("%1<b>%2</b>: <b>%3</b>").arg(path).arg(name).arg(matches);
m_curResults->tree->topLevelItem(i)->setData(0, Qt::DisplayRole, tmpUrl);
m_curResults->tree->topLevelItem(i)->setData(1, Qt::UserRole, matches);
return m_curResults->tree->topLevelItem(i);
root->child(i)->setData(0, Qt::DisplayRole, tmpUrl);
root->child(i)->setData(1, Qt::UserRole, matches);
return root->child(i);
}
}
// file item not found create a new one
QString tmpUrl = QString("%1<b>%2</b>: <b>%3</b>").arg(path).arg(name).arg(1);
TreeWidgetItem *item = new TreeWidgetItem(m_curResults->tree, QStringList(tmpUrl));
TreeWidgetItem *item = new TreeWidgetItem(root, QStringList(tmpUrl));
item->setData(0, Qt::UserRole, url);
item->setData(1, Qt::UserRole, 1);
item->setCheckState (0, Qt::Checked);
item->setCheckState(0, Qt::Checked);
item->setFlags(item->flags() | Qt::ItemIsTristate);
return item;
}
......@@ -971,20 +978,23 @@ void KatePluginSearchView::searchDone()
m_curResults->tree->sortItems(0, Qt::AscendingOrder);
if (m_curResults->tree->topLevelItemCount() > 1) {
m_curResults->tree->setCurrentItem(m_curResults->tree->topLevelItem(1));
m_curResults->tree->setFocus(Qt::OtherFocusReason);
}
m_curResults->tree->expandAll();
m_curResults->tree->resizeColumnToContents(0);
if (m_curResults->tree->columnWidth(0) < m_curResults->tree->width()-30) {
m_curResults->tree->setColumnWidth(0, m_curResults->tree->width()-30);
}
if (!m_ui.expandResults->isChecked()) {
m_curResults->tree->collapseAll();
QTreeWidgetItem *root = m_curResults->tree->topLevelItem(0);
m_curResults->tree->expandItem(root);
if ((root->childCount() > 1) && (!m_ui.expandResults->isChecked())) {
for (int i=0; i<root->childCount(); i++) {
m_curResults->tree->collapseItem(root->child(i));
}
}
m_curResults->tree->setCurrentItem(root);
m_curResults->tree->setFocus(Qt::OtherFocusReason);
indicateMatch(m_curResults->tree->topLevelItemCount() > 0);
indicateMatch(m_curResults->matches > 0);
m_curResults = 0;
m_toolView->unsetCursor();
m_searchJustOpened = false;
......@@ -1035,15 +1045,56 @@ void KatePluginSearchView::indicateMatch(bool hasMatch) {
lineEdit->setPalette(background);
}
void KatePluginSearchView::docViewChanged()
{
Results *res = qobject_cast<Results *>(m_ui.resultTabWidget->currentWidget());
if (!res) {
return;
}
m_curResults = res;
if (!mainWindow()->activeView()) {
return;
}
// add the marks if it is not already open
KTextEditor::Document *doc = mainWindow()->activeView()->document();
if (doc) {
QTreeWidgetItem *rootItem = 0;
for (int i=0; i<res->tree->topLevelItemCount(); i++) {
if (res->tree->topLevelItem(i)->data(0, Qt::UserRole).toString() == doc->url().pathOrUrl()) {
rootItem = res->tree->topLevelItem(i);
break;
}
}
if (rootItem) {
int line;
int column;
int len;
QTreeWidgetItem *item;
for (int i=0; i<rootItem->childCount(); i++) {
item = rootItem->child(i);
line = item->data(1, Qt::UserRole).toInt();
column = item->data(2, Qt::UserRole).toInt();
len = item->data(3, Qt::UserRole).toInt();
addMatchMark(doc, line, column, len);
}
}
}
}
void KatePluginSearchView::itemSelected(QTreeWidgetItem *item)
{
if (!item) return;
if ((item->parent()==0) && (item->child(0))) {
while (item->data(2, Qt::UserRole).toString().isEmpty()) {
item->treeWidget()->expandItem(item);
item = item->child(0);
item->treeWidget()->setCurrentItem(item);
if (!item) return;
}
item->treeWidget()->setCurrentItem(item);
// get stuff
const QString url = item->data(0, Qt::UserRole).toString();
......@@ -1082,48 +1133,6 @@ void KatePluginSearchView::itemSelected(QTreeWidgetItem *item)
mainWindow()->activeView()->setFocus();
}
void KatePluginSearchView::docViewChanged()
{
Results *res = qobject_cast<Results *>(m_ui.resultTabWidget->currentWidget());
if (!res) {
return;
}
m_curResults = res;
if (!mainWindow()->activeView()) {
return;
}
// add the marks if it is not already open
KTextEditor::Document *doc = mainWindow()->activeView()->document();
if (doc) {
QTreeWidgetItem *rootItem = 0;
for (int i=0; i<res->tree->topLevelItemCount(); i++) {
if (res->tree->topLevelItem(i)->data(0, Qt::UserRole).toString() == doc->url().pathOrUrl()) {
rootItem = res->tree->topLevelItem(i);
break;
}
}
if (rootItem) {
int line;
int column;
int len;
QTreeWidgetItem *item;
for (int i=0; i<rootItem->childCount(); i++) {
item = rootItem->child(i);
line = item->data(1, Qt::UserRole).toInt();
column = item->data(2, Qt::UserRole).toInt();
len = item->data(3, Qt::UserRole).toInt();
addMatchMark(doc, line, column, len);
}
}
}
}
void KatePluginSearchView::goToNextMatch()
{
Results *res = qobject_cast<Results *>(m_ui.resultTabWidget->currentWidget());
......@@ -1136,20 +1145,13 @@ void KatePluginSearchView::goToNextMatch()
}
if (!curr) return;
if (curr->parent() == 0) {
res->tree->expandItem(curr);
}
curr = res->tree->itemBelow(curr);
if (!curr) {
curr = res->tree->topLevelItem(0);
}
if (curr->parent() == 0) {
res->tree->expandItem(curr);
if (!curr->data(2, Qt::UserRole).toString().isEmpty()) {
curr = res->tree->itemBelow(curr);
if (!curr) {
curr = res->tree->topLevelItem(0);
}
}
if (!curr) return;
res->tree->setCurrentItem(curr);
itemSelected(curr);
}
......@@ -1163,41 +1165,28 @@ void KatePluginSearchView::goToPreviousMatch()
return;
}
QTreeWidgetItem *curr = res->tree->currentItem();
if (!curr) {
// select the last child of the last top-level item
curr = res->tree->topLevelItem(res->tree->topLevelItemCount()-1);
curr = curr->child(curr->childCount()-1);
if (!curr) return;
res->tree->setCurrentItem(curr);
itemSelected(curr);
return;
}
// go to the item above. (curr == null is not a problem)
curr = res->tree->itemAbove(curr);
if (!curr) {
// current was the first top-level item
res->tree->setCurrentItem(curr);
goToPreviousMatch();
return;
}
if (curr->parent() == 0) {
// this is a top-level item -> go to the item above
// skip file name items and the root item
while (curr && curr->data(2, Qt::UserRole).toString().isEmpty()) {
curr = res->tree->itemAbove(curr);
if (!curr) {
res->tree->setCurrentItem(curr);
goToPreviousMatch();
return;
}
}
if (curr->parent() == 0) {
// still a top-level item -> expand and take the last
res->tree->expandItem(curr);
curr = curr->child(curr->childCount()-1);
if (!curr) return;
if (!curr) {
// select the last child of the last next-to-top-level item
QTreeWidgetItem *root = res->tree->topLevelItem(0);
// select the last "root item"
if (!root || (root->childCount() < 1)) return;
root = root->child(root->childCount()-1);
// select the last match of the "root item"
if (!root || (root->childCount() < 1)) return;
curr = root->child(root->childCount()-1);
}
res->tree->setCurrentItem(curr);
itemSelected(curr);
}
......@@ -1281,6 +1270,8 @@ void KatePluginSearchView::addTab()
Results *res = new Results();
res->tree->setRootIsDecorated(false);
connect(res->tree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),
this, SLOT (itemSelected(QTreeWidgetItem*)), Qt::QueuedConnection);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment