* Replaces all occurences of "Find" with "Replace" if data == CsvApplication::ReplaceAllType::REPLACE * Flags all rows where "Find" is found if data == CsvApplication::ReplaceAllType::FLAG */
| 1750 | * Flags all rows where "Find" is found if data == CsvApplication::ReplaceAllType::FLAG |
| 1751 | */ |
| 1752 | void CsvApplication::find_replaceAll_CB(Fl_Widget *, long data) { |
| 1753 | int row_top, row_bottom, col_top, col_bottom; |
| 1754 | int numReplaces = 0; |
| 1755 | int allReplaces = 0; |
| 1756 | int allChangedCells = 0; |
| 1757 | int row, col; |
| 1758 | std::string msg; |
| 1759 | std::string query(app.searchInput->value()); |
| 1760 | std::string replace(app.replaceInput->value()); |
| 1761 | int winIndex = app.getTopWindow(); |
| 1762 | long long allCellCounter = 0, allCells = 0; |
| 1763 | bool caseSensitive = true; |
| 1764 | bool useRegex = false; |
| 1765 | if( app.ignoreCase->value() ) { |
| 1766 | caseSensitive = false; |
| 1767 | } |
| 1768 | if( app.useRegex->value() ) { |
| 1769 | useRegex = true; |
| 1770 | } |
| 1771 | |
| 1772 | if( data == CsvApplication::ReplaceAllType::REPLACE ) { |
| 1773 | app.showImWorkingWindow("Replacing ..."); |
| 1774 | app.searchWinLabel->copy_label("Start replacing ..."); |
| 1775 | windows[winIndex].addUndoStateTable("Replace All"); |
| 1776 | windows[winIndex].setChanged(true); |
| 1777 | } else if( data == CsvApplication::ReplaceAllType::FLAG ) { |
| 1778 | app.showImWorkingWindow("Flagging ..."); |
| 1779 | app.searchWinLabel->copy_label("Start flagging ..."); |
| 1780 | } else if( data == CsvApplication::ReplaceAllType::UNFLAG ) { |
| 1781 | app.showImWorkingWindow("Unflagging ..."); |
| 1782 | app.searchWinLabel->copy_label("Start unflagging ..."); |
| 1783 | } |
| 1784 | |
| 1785 | windows[winIndex].grid->get_selection(row_top, col_top, row_bottom, col_bottom); |
| 1786 | if( row_top == row_bottom && col_top == col_bottom ) { |
| 1787 | row_top = 0; |
| 1788 | col_top = 0; |
| 1789 | row_bottom = windows[winIndex].table->getNumberRows() - 1; |
| 1790 | col_bottom = windows[winIndex].table->getNumberCols() - 1; |
| 1791 | } |
| 1792 | |
| 1793 | allCellCounter = 0; |
| 1794 | allCells = (col_bottom - col_top + 1) * (row_bottom - row_top + 1); |
| 1795 | if( allCells > 0 ) { |
| 1796 | for( col = col_top; col <= col_bottom; ++col) { |
| 1797 | for( row = row_top; row <= row_bottom; ++row) { |
| 1798 | if( data == CsvApplication::ReplaceAllType::REPLACE ) { |
| 1799 | // REPLACE |
| 1800 | numReplaces = windows[winIndex].table->replaceInCurrentCell(row, col, query, replace, caseSensitive, useRegex); |
| 1801 | if( numReplaces > 0 ) { |
| 1802 | allReplaces += numReplaces; |
| 1803 | ++allChangedCells; |
| 1804 | } |
| 1805 | } else if( data == CsvApplication::ReplaceAllType::FLAG ) { |
| 1806 | // FLAG ROW |
| 1807 | if( windows[winIndex].table->findInCell(query, row, col, caseSensitive, useRegex) ) { |
| 1808 | if( !windows[winIndex].table->isFlagged(row) ) { |
| 1809 | windows[winIndex].table->flagRow(row, true); |
nothing calls this directly
no test coverage detected