From 281f1ab591a1321cfd700f5a8e54da3541498a52 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Thu, 20 Jun 2019 22:42:20 +0900 Subject: tdefilereplace: fixed up interaction between tdefilereplacepart and tdefilereplaceview, which was causing some odd issues with GUI updates at some times. Signed-off-by: Michele Calgaro --- tdefilereplace/tdefilereplaceview.cpp | 133 +++++++++++++++++++--------------- 1 file changed, 75 insertions(+), 58 deletions(-) (limited to 'tdefilereplace/tdefilereplaceview.cpp') diff --git a/tdefilereplace/tdefilereplaceview.cpp b/tdefilereplace/tdefilereplaceview.cpp index 2220c13..e7bfd87 100644 --- a/tdefilereplace/tdefilereplaceview.cpp +++ b/tdefilereplace/tdefilereplaceview.cpp @@ -133,38 +133,46 @@ void TDEFileReplaceView::displayScannedFiles(int foldersNumber, int filesNumber) void TDEFileReplaceView::stringsInvert(bool invertAll) { - TQListViewItem* lviCurItem, - * lviFirst; - TDEListView* sv = getStringsView(); + if (m_option->m_searchingOnlyMode) + { + return; + } - if(invertAll) - lviCurItem = lviFirst = sv->firstChild(); + TDEListView *sv = getStringsView(); + TQListViewItem *lviCurItem; + if (invertAll) + { + lviCurItem = sv->firstChild(); + } else - lviCurItem = lviFirst = sv->currentItem(); - - if(lviCurItem == 0) - return ; + { + lviCurItem = sv->currentItem(); + } + if (!lviCurItem) + { + return; + } do { - TQString searchText = lviCurItem->text(0), - replaceText = lviCurItem->text(1); + TQString searchText = lviCurItem->text(0), replaceText = lviCurItem->text(1); - // Cannot invert the string when search string is empty + // Cannot invert the string when search string is empty if (replaceText.isEmpty()) { - KMessageBox::error(0, i18n("Cannot invert string %1, because the search string would be empty.").arg(searchText)); - return; + KMessageBox::error(0, i18n("Cannot invert string %1, because the search string would be empty.") + .arg(searchText)); + } + else + { + lviCurItem->setText(0, replaceText); + lviCurItem->setText(1, searchText); } - - lviCurItem->setText(0, replaceText); - lviCurItem->setText(1, searchText); - lviCurItem = lviCurItem->nextSibling(); - if(!invertAll) - break; - } while(lviCurItem && lviCurItem != lviFirst); - setCurrentStringsViewMap(); + } while (invertAll && lviCurItem); + + updateStringMap(); + emit updateGUI(); } void TDEFileReplaceView::changeView(bool searchingOnlyMode) @@ -232,33 +240,33 @@ void TDEFileReplaceView::slotResultProperties() { TQString currItemPath = getItemPath(getCurrItemTopLevelParent()); if (!currItemPath.isEmpty()) - { - KURL url(currItemPath); - (void) new KPropertiesDialog(url); - m_lviCurrent = 0; - } + { + KURL url(currItemPath); + (void) new KPropertiesDialog(url); + m_lviCurrent = 0; + } } void TDEFileReplaceView::slotResultOpen() { TQString currItemPath = getItemPath(getCurrItemTopLevelParent()); if (!currItemPath.isEmpty()) - { - (void) new KRun(KURL(currItemPath), 0, true, true); - m_lviCurrent = 0; - } + { + (void) new KRun(KURL(currItemPath), 0, true, true); + m_lviCurrent = 0; + } } void TDEFileReplaceView::slotResultOpenWith() { TQString currItemPath = getItemPath(getCurrItemTopLevelParent()); if (!currItemPath.isEmpty()) - { - KURL::List kurls; - kurls.append(KURL(currItemPath)); - KRun::displayOpenWithDialog(kurls); - m_lviCurrent = 0; - } + { + KURL::List kurls; + kurls.append(KURL(currItemPath)); + KRun::displayOpenWithDialog(kurls); + m_lviCurrent = 0; + } } void TDEFileReplaceView::slotResultDirOpen() @@ -401,6 +409,7 @@ void TDEFileReplaceView::slotStringsAdd() raiseStringsView(); loadMapIntoView(addedStringsMap); + emit updateGUI(); } void TDEFileReplaceView::slotQuickStringsAdd(const TQString& quickSearch, const TQString& quickReplace) @@ -461,6 +470,7 @@ void TDEFileReplaceView::slotStringsEdit() raiseStringsView(); loadMapIntoView(newMap); + emit updateGUI(); } void TDEFileReplaceView::slotStringsSave() @@ -480,7 +490,6 @@ void TDEFileReplaceView::slotStringsSave() header += "\n\t"; TQListViewItem *lvi = sv->firstChild(); - while (lvi) { body += TQString("\n\t" @@ -510,29 +519,34 @@ void TDEFileReplaceView::slotStringsSave() file.close(); } +void TDEFileReplaceView::slotStringsInvertCur() +{ + stringsInvert(false); +} + +void TDEFileReplaceView::slotStringsInvertAll() +{ + stringsInvert(true); +} + void TDEFileReplaceView::slotStringsDeleteItem() { - TQListViewItem* item = m_sv->currentItem(); - if(item != 0) + TQListViewItem *item = m_sv->currentItem(); + if (item) { KeyValueMap m = m_option->m_mapStringsView; m.remove(item->text(0)); m_option->m_mapStringsView = m; delete item; + emit updateGUI(); } } void TDEFileReplaceView::slotStringsEmpty() { - TQListViewItem * myChild = m_sv->firstChild(); - while( myChild ) - { - TQListViewItem* item = myChild; - myChild = myChild->nextSibling(); - delete item; - } - KeyValueMap m; - m_option->m_mapStringsView = m; + m_sv->clear(); + m_option->m_mapStringsView.clear(); + emit updateGUI(); } //PRIVATE @@ -700,19 +714,22 @@ void TDEFileReplaceView::expand(TQListViewItem *lviCurrent, bool b) } } -void TDEFileReplaceView::setMap() +void TDEFileReplaceView::updateStringMap() { - KeyValueMap map; - TQListViewItem* i = m_sv->firstChild(); - while(i != 0) + m_option->m_mapStringsView.clear(); + TQListViewItem *item = m_sv->firstChild(); + while (item) { - if(m_option->m_searchingOnlyMode) - map[i->text(0)] = TQString(); + if (m_option->m_searchingOnlyMode) + { + m_option->m_mapStringsView[item->text(0)] = TQString(); + } else - map[i->text(0)] = i->text(1); - i = i->nextSibling(); + { + m_option->m_mapStringsView[item->text(0)] = item->text(1); + } + item = item->nextSibling(); } - m_option->m_mapStringsView = map; } void TDEFileReplaceView::loadMapIntoView(KeyValueMap map) -- cgit v1.2.1