* Does Replacement, is called by callback functions below * Returns number of replacements */
| 1696 | * Returns number of replacements |
| 1697 | */ |
| 1698 | int CsvApplication::find_replace(bool callFindNext) { |
| 1699 | int row_top, row_bottom, col_top, col_bottom; |
| 1700 | int startFindRow, startFindCol; |
| 1701 | int numReplaces; |
| 1702 | std::string query(app.searchInput->value()); |
| 1703 | std::string replace(app.replaceInput->value()); |
| 1704 | int winIndex = app.getTopWindow(); |
| 1705 | bool caseSensitive = true; |
| 1706 | bool useRegex = false; |
| 1707 | if( app.ignoreCase->value() ) { |
| 1708 | caseSensitive = false; |
| 1709 | } |
| 1710 | if( app.useRegex->value() ) { |
| 1711 | useRegex = true; |
| 1712 | } |
| 1713 | windows[winIndex].grid->get_selection(row_top, col_top, row_bottom, col_bottom); |
| 1714 | if( std::get<0>(app.lastFound) >= 0 && std::get<1>(app.lastFound) >= 0 ) { |
| 1715 | startFindRow = std::get<0>(app.lastFound); |
| 1716 | startFindCol = std::get<1>(app.lastFound); |
| 1717 | } else { |
| 1718 | startFindRow = row_top; |
| 1719 | startFindCol = col_top; |
| 1720 | } |
| 1721 | app.showImWorkingWindow("Replacing ..."); |
| 1722 | windows[winIndex].addUndoStateTable("Replace"); |
| 1723 | windows[winIndex].setChanged(true); |
| 1724 | numReplaces = windows[winIndex].table->replaceInCurrentCell(startFindRow, startFindCol, query, replace, caseSensitive, useRegex); |
| 1725 | app.hideImWorkingWindow(); |
| 1726 | if( numReplaces ) { |
| 1727 | if( callFindNext ) { |
| 1728 | find_substring_CB(NULL, TCRUNCHER_MYFLCHOICE_MAGICAL); |
| 1729 | } |
| 1730 | app.searchWinLabel->copy_label("Replaced."); |
| 1731 | windows[winIndex].grid->redraw(); |
| 1732 | } else { |
| 1733 | app.searchWinLabel->copy_label("No match found."); |
| 1734 | } |
| 1735 | app.searchWinLabel->redraw(); |
| 1736 | Fl::check(); |
| 1737 | return numReplaces; |
| 1738 | } |
| 1739 | |
| 1740 | void CsvApplication::find_replace_CB(Fl_Widget *, void *) { |
| 1741 | find_replace(false); |
nothing calls this directly
no test coverage detected