| 2344 | |
| 2345 | |
| 2346 | void CsvApplication::executeMacroCB(Fl_Widget *, void *data) { |
| 2347 | int row_top, row_bottom, col_top, col_bottom; |
| 2348 | int winIndex = app.getTopWindow(); |
| 2349 | std::tuple<int, int, int, int> selection; |
| 2350 | std::tuple<int, std::string> executeReturn; |
| 2351 | std::tuple<Fl_Text_Buffer *, Fl_Text_Display *, Fl_Text_Display *> *widgets = (std::tuple<Fl_Text_Buffer *, Fl_Text_Display *, Fl_Text_Display *> *) data; |
| 2352 | std::string source = ((Fl_Text_Buffer *) std::get<0>(*widgets))->text(); |
| 2353 | void *logVoid = ((void *) std::get<1>(*widgets)); |
| 2354 | Fl_Text_Display *logDisplay = (Fl_Text_Display *) logVoid; |
| 2355 | |
| 2356 | #ifdef DEBUG |
| 2357 | printf("logDisplay: %p\n", (void *)logDisplay); |
| 2358 | #endif |
| 2359 | fflush(stdout); |
| 2360 | |
| 2361 | |
| 2362 | // TODO Check if macro source is shorter than TCRUNCHER_PREF_VALUE_MAX_LENGTH |
| 2363 | // TODO Save to `macros` before execution – seems already be done |
| 2364 | |
| 2365 | windows[winIndex].grid->get_selection(row_top, col_top, row_bottom, col_bottom); |
| 2366 | selection = std::make_tuple(row_top, col_top, row_bottom, col_bottom); |
| 2367 | |
| 2368 | app.showImWorkingWindow("Executing Macro ..."); |
| 2369 | windows[winIndex].addUndoStateTable("Execute Macro"); |
| 2370 | bool isChanged = windows[winIndex].isChanged(); |
| 2371 | windows[winIndex].setChanged(true); |
| 2372 | windows[winIndex].setUsed(true); |
| 2373 | |
| 2374 | logDisplay->buffer()->text( "Executing macro ...\n" ); |
| 2375 | Fl::check(); |
| 2376 | executeReturn = macro.execute( windows[winIndex].table, selection, source, logVoid ); |
| 2377 | app.hideImWorkingWindow(); |
| 2378 | if( std::get<0>(executeReturn) == -1 ) { |
| 2379 | // error |
| 2380 | logDisplay->buffer()->text( std::get<1>(executeReturn).c_str() ); |
| 2381 | } else if( std::get<0>(executeReturn) == 0 ) { |
| 2382 | // table data not modified: reset undo state |
| 2383 | windows[winIndex].removeLastUndoState(); |
| 2384 | windows[winIndex].setChanged(isChanged); |
| 2385 | } |
| 2386 | logDisplay->buffer()->append( "Done.\n" ); |
| 2387 | |
| 2388 | windows[winIndex].grid->redraw(); |
| 2389 | Fl::check(); |
| 2390 | } |
| 2391 | void CsvApplication::insertLoopButtonCB(Fl_Widget *, void *data) { |
| 2392 | std::tuple<Fl_Text_Buffer *, Fl_Text_Display *, Fl_Text_Editor *> *widgets = (std::tuple<Fl_Text_Buffer *, Fl_Text_Display *, Fl_Text_Editor *> *) data; |
| 2393 | int pos = (std::get<2>(*widgets))->insert_position(); |
nothing calls this directly
no test coverage detected