tdefilereplace: added save/load results functionality.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/11/head
Michele Calgaro 5 years ago
parent 10db438b9a
commit ae564d14ce
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -64,31 +64,6 @@ TQString TDEFileReplaceLib::formatFullPath(const TQString& basePath, const TQStr
return fullPath; return fullPath;
} }
/**
Add an extension to a filename, or a filepath
Parameters::.....* fileName: filename or filepath (it can have already the extension)
.................* extension: extension to add without "." (ex: "html", "kfr")
Return values:...* Filename / Filepath with the extension
*/
TQString TDEFileReplaceLib::addExtension(const TQString& fileName, const TQString& extension)
{
TQString fullExtension = ".";
TQString fname = fileName;
fullExtension.append(extension);
// filename cannot contain ".ext" ==> Add it
if(fname.length() <= fullExtension.length())
fname.append(fullExtension);
else // filename can contain ".ext"
{
if (fname.right(fullExtension.length()) != fullExtension)
fname.append(fullExtension);
}
return fname;
}
TQString TDEFileReplaceLib::formatFileSize(double size) TQString TDEFileReplaceLib::formatFileSize(double size)
{ {
TQString stringSize; TQString stringSize;

@ -40,14 +40,6 @@ class TDEFileReplaceLib
*/ */
static TQString formatFullPath(const TQString& basePath, const TQString& fileName); static TQString formatFullPath(const TQString& basePath, const TQString& fileName);
/**
Add an extension to a filename, or a filepath
Parameters::.....* filename: filename or filepath (it can have already the extension)
.................* extension: extension to add without "." (ex: "html", "kfr")
Return values:...* Filename / Filepath with the extension
*/
static TQString addExtension(const TQString& fileName, const TQString& extension);
static TQString formatFileSize(double size); static TQString formatFileSize(double size);
/** /**

@ -102,7 +102,7 @@ TDEFileReplacePart::~TDEFileReplacePart()
void TDEFileReplacePart::slotSetNewParameters() void TDEFileReplacePart::slotSetNewParameters()
{ {
launchNewProjectDialog(KURL()); launchNewProjectDialog(KURL());
m_view->changeView(m_option->m_searchingOnlyMode); m_view->changeViews(m_option->m_searchingOnlyMode);
emit setStatusBarText(i18n("Ready.")); emit setStatusBarText(i18n("Ready."));
} }
@ -388,28 +388,28 @@ void TDEFileReplacePart::reportBug()
void TDEFileReplacePart::updateGUI() void TDEFileReplacePart::updateGUI()
{ {
TDEListView* rv = m_view->getResultsView(), TDEListView *rv = m_view->getResultsView();
* sv = m_view->getStringsView(); TDEListView *sv = m_view->getStringsView();
bool hasItems = (sv->firstChild() != 0), bool hasResults = (rv->firstChild() != 0);
searchOnlyMode = m_option->m_searchingOnlyMode; bool hasStrings = (sv->firstChild() != 0);
bool searchOnlyMode = m_option->m_searchingOnlyMode;
// File // File
actionCollection()->action("new_project")->setEnabled(true); actionCollection()->action("new_project")->setEnabled(true);
actionCollection()->action("search")->setEnabled(hasItems && searchOnlyMode); actionCollection()->action("search")->setEnabled(hasStrings && searchOnlyMode);
actionCollection()->action("file_simulate")->setEnabled(hasItems && !searchOnlyMode); actionCollection()->action("file_simulate")->setEnabled(hasStrings && !searchOnlyMode);
actionCollection()->action("replace")->setEnabled(hasItems && !searchOnlyMode); actionCollection()->action("replace")->setEnabled(hasStrings && !searchOnlyMode);
actionCollection()->action("save_results")->setEnabled(hasItems);
actionCollection()->action("stop")->setEnabled(false); actionCollection()->action("stop")->setEnabled(false);
// Strings // Strings
actionCollection()->action("strings_add")->setEnabled(true); actionCollection()->action("strings_add")->setEnabled(true);
actionCollection()->action("strings_del")->setEnabled(hasItems); actionCollection()->action("strings_del")->setEnabled(hasStrings);
actionCollection()->action("strings_empty")->setEnabled(hasItems); actionCollection()->action("strings_empty")->setEnabled(hasStrings);
actionCollection()->action("strings_save")->setEnabled(hasItems); actionCollection()->action("strings_save")->setEnabled(hasStrings);
actionCollection()->action("strings_load")->setEnabled(true); actionCollection()->action("strings_load")->setEnabled(true);
actionCollection()->action("strings_invert")->setEnabled(hasItems && !searchOnlyMode); actionCollection()->action("strings_invert")->setEnabled(hasStrings && !searchOnlyMode);
actionCollection()->action("strings_invert_all")->setEnabled(hasItems && !searchOnlyMode); actionCollection()->action("strings_invert_all")->setEnabled(hasStrings && !searchOnlyMode);
// Options // Options
actionCollection()->action("options_recursive")->setEnabled(true); actionCollection()->action("options_recursive")->setEnabled(true);
@ -419,34 +419,35 @@ void TDEFileReplacePart::updateGUI()
actionCollection()->action("options_regularexpressions")->setEnabled(true); actionCollection()->action("options_regularexpressions")->setEnabled(true);
actionCollection()->action("configure_tdefilereplace")->setEnabled(true); actionCollection()->action("configure_tdefilereplace")->setEnabled(true);
hasItems = (rv->firstChild() != 0);
// Results // Results
actionCollection()->action("results_infos")->setEnabled(hasItems); actionCollection()->action("results_infos")->setEnabled(hasResults);
actionCollection()->action("results_openfile")->setEnabled(hasItems); actionCollection()->action("results_openfile")->setEnabled(hasResults);
actionCollection()->action("results_openfilewith")->setEnabled(hasItems); actionCollection()->action("results_openfilewith")->setEnabled(hasResults);
if (actionCollection()->action("results_editfile")) if (actionCollection()->action("results_editfile"))
{ {
actionCollection()->action("results_editfile")->setEnabled(hasItems); actionCollection()->action("results_editfile")->setEnabled(hasResults);
} }
actionCollection()->action("results_opendir")->setEnabled(hasItems); actionCollection()->action("results_opendir")->setEnabled(hasResults);
actionCollection()->action("results_removeentry")->setEnabled(hasItems); actionCollection()->action("results_removeentry")->setEnabled(hasResults);
actionCollection()->action("results_delete")->setEnabled(hasItems); actionCollection()->action("results_delete")->setEnabled(hasResults);
actionCollection()->action("results_treeexpand")->setEnabled(hasItems); actionCollection()->action("results_treeexpand")->setEnabled(hasResults);
actionCollection()->action("results_treereduce")->setEnabled(hasItems); actionCollection()->action("results_treereduce")->setEnabled(hasResults);
actionCollection()->action("results_create_report")->setEnabled(hasResults);
actionCollection()->action("results_save")->setEnabled(hasResults);
actionCollection()->action("results_load")->setEnabled(true);
// Updates menus and toolbar // Updates menus and toolbar
((TDEToggleAction* ) actionCollection()->action("options_recursive"))->setChecked(m_option->m_recursive); ((TDEToggleAction*) actionCollection()->action("options_recursive"))->setChecked(m_option->m_recursive);
((TDEToggleAction* ) actionCollection()->action("options_backup"))->setChecked(m_option->m_backup && !searchOnlyMode); ((TDEToggleAction*) actionCollection()->action("options_backup"))->setChecked(m_option->m_backup && !searchOnlyMode);
((TDEToggleAction* ) actionCollection()->action("options_case"))->setChecked(m_option->m_caseSensitive); ((TDEToggleAction*) actionCollection()->action("options_case"))->setChecked(m_option->m_caseSensitive);
((TDEToggleAction* ) actionCollection()->action("options_var"))->setChecked(m_option->m_variables && !searchOnlyMode); ((TDEToggleAction*) actionCollection()->action("options_var"))->setChecked(m_option->m_variables && !searchOnlyMode);
((TDEToggleAction* ) actionCollection()->action("options_regularexpressions"))->setChecked(m_option->m_regularExpressions); ((TDEToggleAction*) actionCollection()->action("options_regularexpressions"))->setChecked(m_option->m_regularExpressions);
} }
//PUBLIC METHODS //PUBLIC METHODS
TDEAboutData* TDEFileReplacePart::createAboutData() TDEAboutData* TDEFileReplacePart::createAboutData()
{ {
TDEAboutData * aboutData = new TDEAboutData("tdefilereplacepart", TDEAboutData *aboutData = new TDEAboutData("tdefilereplacepart",
I18N_NOOP("TDEFileReplacePart"), I18N_NOOP("TDEFileReplacePart"),
KFR_VERSION, KFR_VERSION,
I18N_NOOP( "Batch search and replace tool."), I18N_NOOP( "Batch search and replace tool."),
@ -513,7 +514,9 @@ void TDEFileReplacePart::initGUI()
(void)new TDEAction(i18n("S&imulate"), "filesimulate", 0, TQT_TQOBJECT(this), TQT_SLOT(slotSimulatingOperation()), actionCollection(), "file_simulate"); (void)new TDEAction(i18n("S&imulate"), "filesimulate", 0, TQT_TQOBJECT(this), TQT_SLOT(slotSimulatingOperation()), actionCollection(), "file_simulate");
(void)new TDEAction(i18n("&Replace"), "filereplace", 0, TQT_TQOBJECT(this), TQT_SLOT(slotReplacingOperation()), actionCollection(), "replace"); (void)new TDEAction(i18n("&Replace"), "filereplace", 0, TQT_TQOBJECT(this), TQT_SLOT(slotReplacingOperation()), actionCollection(), "replace");
(void)new TDEAction(i18n("Sto&p"), "process-stop", 0, TQT_TQOBJECT(this), TQT_SLOT(slotStop()), actionCollection(), "stop"); (void)new TDEAction(i18n("Sto&p"), "process-stop", 0, TQT_TQOBJECT(this), TQT_SLOT(slotStop()), actionCollection(), "stop");
(void)new TDEAction(i18n("Cre&ate Report File..."), "document-save-as", 0, TQT_TQOBJECT(this), TQT_SLOT(slotCreateReport()), actionCollection(), "save_results"); (void)new TDEAction(i18n("Cre&ate Report File..."), "document-save-as", 0, TQT_TQOBJECT(this), TQT_SLOT(slotCreateReport()), actionCollection(), "results_create_report");
(void)new TDEAction(i18n("&Save Results List to File..."), "document-save-as", 0, TQT_TQOBJECT(m_view), TQT_SLOT(slotResultSave()), actionCollection(), "results_save");
(void)new TDEAction(i18n("&Load Results List From File..."), "unsortedList", 0, TQT_TQOBJECT(m_view), TQT_SLOT(slotResultLoad()), actionCollection(), "results_load");
// Strings // Strings
(void)new TDEAction(i18n("&Add String..."), "editadd", 0, TQT_TQOBJECT(m_view), TQT_SLOT(slotStringsAdd()), actionCollection(), "strings_add"); (void)new TDEAction(i18n("&Add String..."), "editadd", 0, TQT_TQOBJECT(m_view), TQT_SLOT(slotStringsAdd()), actionCollection(), "strings_add");
@ -1392,7 +1395,7 @@ void TDEFileReplacePart::search(const TQString& currentDir, const TQString& file
else else
capturedText = line.mid(pos,strKey.length()); capturedText = line.mid(pos,strKey.length());
msg = i18n(" Line:%2, Col:%3 - \"%1\"").arg(capturedText).arg(TQString::number(lineNumber,10)).arg(TQString::number(columnNumber,10)); msg = i18n("Line:%2, Col:%3 - \"%1\"").arg(capturedText).arg(TQString::number(lineNumber,10)).arg(TQString::number(columnNumber,10));
tempItem->setMultiLinesEnabled(true); tempItem->setMultiLinesEnabled(true);
tempItem->setText(0,msg); tempItem->setText(0,msg);
occurrence = 1; occurrence = 1;
@ -1432,7 +1435,7 @@ void TDEFileReplacePart::search(const TQString& currentDir, const TQString& file
pos = line.find(strKey,pos+strKey.length()); pos = line.find(strKey,pos+strKey.length());
} }
msg = i18n(" Line:%2, Col:%3 - \"%1\"").arg(capturedText).arg(TQString::number(lineNumber,10)).arg(TQString::number(columnNumber,10)); msg = i18n("Line:%2, Col:%3 - \"%1\"").arg(capturedText).arg(TQString::number(lineNumber,10)).arg(TQString::number(columnNumber,10));
if(!item) if(!item)
item = new TDEListViewItem(rv); item = new TDEListViewItem(rv);

@ -1,5 +1,5 @@
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd"> <!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
<kpartgui name="tdefilereplace" version="7"> <kpartgui name="tdefilereplace" version="8">
<MenuBar> <MenuBar>
<Menu name="tdefilerepace"><text>Search/&amp;Replace</text> <Menu name="tdefilerepace"><text>Search/&amp;Replace</text>
<Action name="new_project"/> <Action name="new_project"/>
@ -28,7 +28,9 @@
<Action name="results_delete"/> <Action name="results_delete"/>
<Action name="results_infos"/> <Action name="results_infos"/>
<Separator/> <Separator/>
<Action name="save_results"/> <Action name="results_create_report"/>
<Action name="results_save"/>
<Action name="results_load"/>
<Separator/> <Separator/>
<Action name="results_treeexpand"/> <Action name="results_treeexpand"/>
<Action name="results_treereduce"/> <Action name="results_treereduce"/>

@ -168,27 +168,36 @@ void TDEFileReplaceView::stringsInvert(bool invertAll)
emit updateGUI(); emit updateGUI();
} }
void TDEFileReplaceView::changeView(bool searchingOnlyMode) void TDEFileReplaceView::changeViews()
{ {
if(searchingOnlyMode) changeViews(m_option->m_searchingOnlyMode);
{ }
m_stackResults->raiseWidget(m_lvResults_2);
m_stackStrings->raiseWidget(m_lvStrings_2); void TDEFileReplaceView::changeViews(bool searchingOnlyMode)
m_rv = m_lvResults_2; {
m_sv = m_lvStrings_2; if (searchingOnlyMode)
} {
m_stackResults->raiseWidget(m_lvResults_2);
m_stackStrings->raiseWidget(m_lvStrings_2);
m_rv = m_lvResults_2;
m_sv = m_lvStrings_2;
m_lvResults->clear();
m_lvStrings->clear();
}
else else
{ {
m_stackResults->raiseWidget(m_lvResults); m_stackResults->raiseWidget(m_lvResults);
m_stackStrings->raiseWidget(m_lvStrings); m_stackStrings->raiseWidget(m_lvStrings);
m_rv = m_lvResults; m_rv = m_lvResults;
m_sv = m_lvStrings; m_sv = m_lvStrings;
} m_lvResults_2->clear();
m_lvStrings_2->clear();
}
} }
TDEListView* TDEFileReplaceView::getResultsView() TDEListView* TDEFileReplaceView::getResultsView()
{ {
if(m_option->m_searchingOnlyMode) if (m_option->m_searchingOnlyMode)
m_rv = m_lvResults_2; m_rv = m_lvResults_2;
else else
m_rv = m_lvResults; m_rv = m_lvResults;
@ -198,7 +207,7 @@ TDEListView* TDEFileReplaceView::getResultsView()
TDEListView* TDEFileReplaceView::getStringsView() TDEListView* TDEFileReplaceView::getStringsView()
{ {
if(m_option->m_searchingOnlyMode) if (m_option->m_searchingOnlyMode)
m_sv = m_lvStrings_2; m_sv = m_lvStrings_2;
else else
m_sv = m_lvStrings; m_sv = m_lvStrings;
@ -315,9 +324,10 @@ void TDEFileReplaceView::slotResultRemoveEntry()
{ {
TQListViewItem *currItem = getCurrItemTopLevelParent(); TQListViewItem *currItem = getCurrItemTopLevelParent();
if (currItem) if (currItem)
{ {
delete currItem; delete currItem;
} }
emit updateGUI();
} }
void TDEFileReplaceView::slotResultDelete() void TDEFileReplaceView::slotResultDelete()
@ -337,6 +347,7 @@ void TDEFileReplaceView::slotResultDelete()
delete currItem; delete currItem;
} }
} }
emit updateGUI();
} }
void TDEFileReplaceView::slotResultTreeExpand() void TDEFileReplaceView::slotResultTreeExpand()
@ -355,6 +366,175 @@ void TDEFileReplaceView::slotResultTreeReduce()
expand(lviRoot, false); expand(lviRoot, false);
} }
void TDEFileReplaceView::slotResultLoad()
{
// Selects the file to load from
TQString menu = "*.tfr_results|" + i18n("TDEFileReplace Results") + " (*.tfr_results)\n*|" + i18n("All Files") + " (*)";
TQString fileName = KFileDialog::getOpenFileName(TQString(), menu, this, i18n("Load Results From File"));
if (fileName.isEmpty())
{
return;
}
// Creates a xml document and browses it
TQDomDocument doc("results");
TQFile file(fileName);
if (!file.open(IO_ReadOnly))
{
KMessageBox::error(this, i18n("<qt>Cannot open the file <b>%1</b> and load the results list.</qt>").arg(fileName));
return;
}
if (!doc.setContent(&file))
{
file.close();
KMessageBox::information(this, i18n("<qt>File <b>%1</b> seems not to be valid.</qt>").arg(fileName), i18n("Warning"));
return;
}
else
{
file.close();
}
TQDomElement docElem = doc.documentElement();
TQDomNode tln = docElem.firstChild(); // top level node
TQString searchAttribute = tln.toElement().attribute("search");
if (searchAttribute.isNull() || searchAttribute.isEmpty())
{
int answer = KMessageBox::warningYesNo(this, i18n("<qt>Missing search type. Is this a search-and-replace list of results?</qt>").arg(fileName),i18n("Warning"),i18n("Yes"),i18n("No"));
if (answer == KMessageBox::Yes)
{
m_option->m_searchingOnlyMode = false;
}
else
{
m_option->m_searchingOnlyMode = true;
}
}
else
{
m_option->m_searchingOnlyMode = (searchAttribute == "true");
}
changeViews();
// Clears view
TDEListView *rv = getResultsView();
rv->clear();
// Reads the result list
KeyValueMap docMap;
tln = tln.nextSibling();
if (!tln.isNull())
{
tln = tln.firstChild();
}
while (!tln.isNull())
{
TQDomElement fileEle = tln.toElement();
if (!fileEle.isNull())
{
TDEListViewItem *fileItem = new TDEListViewItem(rv);
fileItem->setText(0, fileEle.attribute("name", "!ERROR!"));
fileItem->setText(1, fileEle.attribute("folder"));
if (m_option->m_searchingOnlyMode)
{
fileItem->setText(2, fileEle.attribute("size"));
fileItem->setText(3, fileEle.attribute("matches"));
fileItem->setText(4, fileEle.attribute("user"));
fileItem->setText(5, fileEle.attribute("group"));
}
else
{
fileItem->setText(2, fileEle.attribute("old_size"));
fileItem->setText(3, fileEle.attribute("new_size"));
fileItem->setText(4, fileEle.attribute("matches"));
fileItem->setText(5, fileEle.attribute("user"));
fileItem->setText(6, fileEle.attribute("group"));
}
TQDomNode lineNode = fileEle.firstChild();
while (!lineNode.isNull())
{
TQDomElement lineEle = lineNode.toElement();
TDEListViewItem *lineItem = new TDEListViewItem(fileItem);
lineItem->setText(0, lineEle.text());
lineNode = lineNode.nextSibling();
}
}
tln = tln.nextSibling();
}
emit updateGUI();
}
void TDEFileReplaceView::slotResultSave()
{
// Check there are results in the list
TDEListView *rv = getResultsView();
if (!rv->firstChild())
{
KMessageBox::error(0, i18n("There are no results to save."));
return;
}
// Selects the file where results will be saved
TQString menu = "*.tfr_results|" + i18n("TDEFileReplace Results") + " (*.tfr_results)\n*|" + i18n("All Files") + " (*)";
TQString fileName = KFileDialog::getSaveFileName(TQString(), menu, this, i18n("Save Results to File"));
if (fileName.isEmpty())
{
return;
}
TQFile file(fileName);
if (!file.open(IO_WriteOnly))
{
KMessageBox::error(0, i18n("File %1 cannot be saved.").arg(fileName));
return;
}
TQTextStream filestream(&file);
filestream.setEncoding(TQTextStream::UnicodeUTF8);
filestream << "<?xml version=\"1.0\" ?>\n<kfr>\n";
if (m_option->m_searchingOnlyMode)
{
filestream << "\t<mode search=\"true\"/>\n";
}
else
{
filestream << "\t<mode search=\"false\"/>\n";
}
filestream << "\t<results>\n";
TQListViewItem *lvi = rv->firstChild();
while (lvi)
{
// File
filestream << TQString("\t\t<file name=\"%1\" folder=\"%2\" ").arg(lvi->text(0)).arg(lvi->text(1));
if (m_option->m_searchingOnlyMode)
{
filestream << TQString("size=\"%1\" matches=\"%2\" user=\"%3\" group=\"%4\">\n")
.arg(lvi->text(2)).arg(lvi->text(3)).arg(lvi->text(4)).arg(lvi->text(5));
}
else
{
filestream << TQString("old_size=\"%1\" new_size=\"%2\" matches=\"%3\" user=\"%4\" group=\"%5\">\n")
.arg(lvi->text(2)).arg(lvi->text(3)).arg(lvi->text(4)).arg(lvi->text(5)).arg(lvi->text(6));
}
// File entries
TQListViewItem *lvsubi = lvi->firstChild();
while (lvsubi)
{
filestream << TQString("\t\t\t<line>%1</line>\n").arg(lvsubi->text(0));
lvsubi = lvsubi->nextSibling();
}
filestream << "\t\t</file>\n";
lvi = lvi->nextSibling();
}
filestream << "\t</results>\n</kfr>\n";
file.close();
}
void TDEFileReplaceView::slotResultHeaderClicked(int sortCol) void TDEFileReplaceView::slotResultHeaderClicked(int sortCol)
{ {
TDEListView *lv = getResultsView(); TDEListView *lv = getResultsView();
@ -377,8 +557,7 @@ void TDEFileReplaceView::slotStringsAdd()
{ {
return; return;
} }
raiseResultsView(); changeViews();
raiseStringsView();
loadMapIntoView(m_option->m_mapStringsView); loadMapIntoView(m_option->m_mapStringsView);
emit updateGUI(); emit updateGUI();
} }
@ -401,9 +580,7 @@ void TDEFileReplaceView::slotQuickStringsAdd(const TQString& quickSearch, const
m_option->m_mapStringsView = map; m_option->m_mapStringsView = map;
raiseResultsView(); changeViews();
raiseStringsView();
loadMapIntoView(map); loadMapIntoView(map);
} }
} }
@ -418,17 +595,16 @@ void TDEFileReplaceView::slotStringsLoad()
return; return;
} }
// Loads a file with kfr extension, creates a xml document and browses it // Creates a xml document and browses it
TQDomDocument doc("mydocument"); TQDomDocument doc("strings");
TQFile file(fileName); TQFile file(fileName);
TDEListView *sv = getStringsView();
if (!file.open(IO_ReadOnly)) if (!file.open(IO_ReadOnly))
{ {
KMessageBox::error(this, i18n("<qt>Cannot open the file <b>%1</b> and load the string list.</qt>").arg(fileName)); KMessageBox::error(this, i18n("<qt>Cannot open the file <b>%1</b> and load the string list.</qt>").arg(fileName));
return; return;
} }
if(!doc.setContent(&file)) if (!doc.setContent(&file))
{ {
file.close(); file.close();
@ -440,12 +616,9 @@ void TDEFileReplaceView::slotStringsLoad()
file.close(); file.close();
} }
//clears view
sv->clear();
TQDomElement docElem = doc.documentElement(); TQDomElement docElem = doc.documentElement();
TQDomNode n = docElem.firstChild(); TQDomNode n = docElem.firstChild();
TQString searchAttribute = n.toElement().attribute("search").latin1(); TQString searchAttribute = n.toElement().attribute("search");
if (searchAttribute.isNull() || searchAttribute.isEmpty()) if (searchAttribute.isNull() || searchAttribute.isEmpty())
{ {
int answer = KMessageBox::warningYesNo(this, i18n("<qt>Missing search type. Is this a search-and-replace list of strings?</qt>").arg(fileName),i18n("Warning"),i18n("Yes"),i18n("No")); int answer = KMessageBox::warningYesNo(this, i18n("<qt>Missing search type. Is this a search-and-replace list of strings?</qt>").arg(fileName),i18n("Warning"),i18n("Yes"),i18n("No"));
@ -458,16 +631,22 @@ void TDEFileReplaceView::slotStringsLoad()
m_option->m_searchingOnlyMode = true; m_option->m_searchingOnlyMode = true;
} }
} }
else
{
m_option->m_searchingOnlyMode = (searchAttribute == "true");
}
changeViews();
// Refreshes the view appearances // Clears view
changeView(m_option->m_searchingOnlyMode); TDEListView *sv = getStringsView();
sv->clear();
// Reads the string list // Reads the string list
KeyValueMap docMap; KeyValueMap docMap;
n = n.nextSibling(); n = n.nextSibling();
while (!n.isNull()) while (!n.isNull())
{ {
TQDomElement e = n.toElement(); // tries to convert the node to an element. TQDomElement e = n.toElement();
if (!e.isNull()) if (!e.isNull())
{ {
TQString searchString = e.firstChild().toElement().text(); TQString searchString = e.firstChild().toElement().text();
@ -476,8 +655,6 @@ void TDEFileReplaceView::slotStringsLoad()
} }
n = n.nextSibling(); n = n.nextSibling();
} }
changeView(m_option->m_searchingOnlyMode);
loadMap(docMap); loadMap(docMap);
emit updateGUI(); emit updateGUI();
@ -493,6 +670,21 @@ void TDEFileReplaceView::slotStringsSave()
return; return;
} }
// Selects the file where strings will be saved
TQString menu = "*.kfr|" + i18n("TDEFileReplace Strings") + " (*.kfr)\n*|" + i18n("All Files") + " (*)";
TQString fileName = KFileDialog::getSaveFileName(TQString(), menu, this, i18n("Save Strings to File"));
if (fileName.isEmpty())
{
return;
}
TQFile file(fileName);
if (!file.open(IO_WriteOnly))
{
KMessageBox::error(0, i18n("File %1 cannot be saved.").arg(fileName));
return ;
}
TQString header("<?xml version=\"1.0\" ?>\n<kfr>"), footer("\n</kfr>"), body; TQString header("<?xml version=\"1.0\" ?>\n<kfr>"), footer("\n</kfr>"), body;
if(m_option->m_searchingOnlyMode) if(m_option->m_searchingOnlyMode)
header += "\n\t<mode search=\"true\"/>"; header += "\n\t<mode search=\"true\"/>";
@ -509,20 +701,6 @@ void TDEFileReplaceView::slotStringsSave()
lvi = lvi->nextSibling(); lvi = lvi->nextSibling();
} }
// Selects the file where strings will be saved
TQString menu = "*.kfr|" + i18n("TDEFileReplace Strings") + " (*.kfr)\n*|" + i18n("All Files") + " (*)";
TQString fileName = KFileDialog::getSaveFileName(TQString(), menu, this, i18n("Save Strings to File"));
if (fileName.isEmpty())
return;
// Forces the extension to be "kfr" == TDEFileReplace extension
fileName = TDEFileReplaceLib::addExtension(fileName, "kfr");
TQFile file(fileName);
if(!file.open(IO_WriteOnly))
{
KMessageBox::error(0, i18n("File %1 cannot be saved.").arg(fileName));
return ;
}
TQTextStream oTStream(&file); TQTextStream oTStream(&file);
oTStream.setEncoding(TQTextStream::UnicodeUTF8); oTStream.setEncoding(TQTextStream::UnicodeUTF8);
oTStream << header << body << footer; oTStream << header << body << footer;
@ -621,28 +799,7 @@ void TDEFileReplaceView::initGUI()
i18n("&Properties"), i18n("&Properties"),
this, this,
TQT_SLOT(slotResultProperties())); TQT_SLOT(slotResultProperties()));
raiseResultsView(); changeViews();
raiseStringsView();
}
void TDEFileReplaceView::raiseStringsView()
{
if(m_option->m_searchingOnlyMode)
m_sv = m_lvStrings_2;
else
m_sv = m_lvStrings;
m_stackStrings->raiseWidget(m_sv);
}
void TDEFileReplaceView::raiseResultsView()
{
if(m_option->m_searchingOnlyMode)
m_rv = m_lvResults_2;
else
m_rv = m_lvResults;
m_stackResults->raiseWidget(m_rv);
} }
coord TDEFileReplaceView::extractWordCoordinates(TQListViewItem* lvi) coord TDEFileReplaceView::extractWordCoordinates(TQListViewItem* lvi)

@ -67,7 +67,7 @@ class TDEFileReplaceView : public TDEFileReplaceViewWdg
void showSemaphore(TQString s); void showSemaphore(TQString s);
void displayScannedFiles(int foldersNumber, int filesNumber); void displayScannedFiles(int foldersNumber, int filesNumber);
void stringsInvert(bool invertAll); void stringsInvert(bool invertAll);
void changeView(bool searchingOnlyMode); void changeViews(bool searchingOnlyMode);
TDEListView* getResultsView(); TDEListView* getResultsView();
TDEListView* getStringsView(); TDEListView* getStringsView();
void updateOptions(RCOptions* info) { m_option = info; } void updateOptions(RCOptions* info) { m_option = info; }
@ -87,6 +87,8 @@ class TDEFileReplaceView : public TDEFileReplaceViewWdg
void slotResultDelete(); void slotResultDelete();
void slotResultTreeExpand(); void slotResultTreeExpand();
void slotResultTreeReduce(); void slotResultTreeReduce();
void slotResultLoad();
void slotResultSave();
void slotResultHeaderClicked(int sortCol); void slotResultHeaderClicked(int sortCol);
void slotStringsAdd(); void slotStringsAdd();
void slotQuickStringsAdd(const TQString& quickSearch, const TQString& quickReplace); void slotQuickStringsAdd(const TQString& quickSearch, const TQString& quickReplace);
@ -99,8 +101,7 @@ class TDEFileReplaceView : public TDEFileReplaceViewWdg
private: private:
void initGUI(); void initGUI();
void raiseStringsView(); void changeViews();
void raiseResultsView();
coord extractWordCoordinates(TQListViewItem* lvi); coord extractWordCoordinates(TQListViewItem* lvi);
void expand(TQListViewItem *lviCurrent, bool b); void expand(TQListViewItem *lviCurrent, bool b);
void updateStringMap(); void updateStringMap();

@ -99,7 +99,7 @@
</column> </column>
<column> <column>
<property name="text"> <property name="text">
<string>Replaced Strings</string> <string>Matches</string>
</property> </property>
<property name="clickable"> <property name="clickable">
<bool>true</bool> <bool>true</bool>
@ -211,7 +211,7 @@
</column> </column>
<column> <column>
<property name="text"> <property name="text">
<string>Found Strings</string> <string>Matches</string>
</property> </property>
<property name="clickable"> <property name="clickable">
<bool>true</bool> <bool>true</bool>

Loading…
Cancel
Save