| 3411 | |
| 3412 | |
| 3413 | void CsvApplication::editSingleCell() { |
| 3414 | int winWidth = 600; |
| 3415 | int winHeight = 450; |
| 3416 | int buttonHeight = 24; |
| 3417 | int margin = 20; |
| 3418 | int winIndex = getTopWindow(); |
| 3419 | std::vector<int> selected = windows[winIndex].grid->getSelection(); |
| 3420 | if( selected[0] < 0 || selected[0] >= windows[winIndex].table->getNumberRows() || selected[1] < 0 || selected[1] >= windows[winIndex].table->getNumberCols() ) { |
| 3421 | return; |
| 3422 | } |
| 3423 | bool changeContent = false; |
| 3424 | |
| 3425 | if( lastSingleEditWinWidth > 0 && lastSingleEditWinHeight > 0 ) { |
| 3426 | winWidth = lastSingleEditWinWidth; |
| 3427 | winHeight = lastSingleEditWinHeight; |
| 3428 | } |
| 3429 | |
| 3430 | My_Fl_Small_Window *singleCellEditWin = new My_Fl_Small_Window(winWidth,winHeight); |
| 3431 | singleCellEditWin->set_modal(); |
| 3432 | singleCellEditWin->color(ColorThemes::getColor(app.getTheme(), "win_bg")); |
| 3433 | singleCellEditWin->labelcolor(ColorThemes::getColor(app.getTheme(), "win_text")); |
| 3434 | singleCellEditWin->label("Edit cell"); |
| 3435 | |
| 3436 | Fl_Text_Buffer *cellBuffer = new Fl_Text_Buffer(); |
| 3437 | Fl_Text_Editor *cellEditor = new Fl_Text_Editor(margin, margin, winWidth - 2*margin, winHeight - 3 * margin - buttonHeight); |
| 3438 | |
| 3439 | cellBuffer->text( windows[winIndex].table->getCell(selected[0], selected[1]).c_str() ); |
| 3440 | cellBuffer->tab_distance(getEditorTabDistance()); |
| 3441 | cellEditor->buffer(cellBuffer); |
| 3442 | cellEditor->box(FL_FLAT_BOX); |
| 3443 | cellEditor->textsize(15); |
| 3444 | cellEditor->textfont(FL_COURIER); |
| 3445 | |
| 3446 | struct My_Fl_Button::buttonColorStruct colorsButton; |
| 3447 | colorsButton.background = ColorThemes::getColor(app.getTheme(), "button_bg"); |
| 3448 | colorsButton.label = ColorThemes::getColor(app.getTheme(), "button_text"); |
| 3449 | colorsButton.border = ColorThemes::getColor(app.getTheme(), "button_border"); |
| 3450 | colorsButton.windowBg = ColorThemes::getColor(app.getTheme(), "win_bg"); |
| 3451 | colorsButton.borderWidth = ColorThemes::getColor(app.getTheme(), "button_border_width"); |
| 3452 | |
| 3453 | singleCellEditWin->begin(); |
| 3454 | My_Fl_Button *saveButton = new My_Fl_Button(winWidth - margin - 100, winHeight - margin - buttonHeight, 100, buttonHeight, "Save"); |
| 3455 | saveButton->colors = colorsButton; |
| 3456 | saveButton->shortcut(FL_Enter); |
| 3457 | saveButton->callback(editSingleCellSaveCB, &changeContent); |
| 3458 | singleCellEditWin->end(); |
| 3459 | |
| 3460 | singleCellEditWin->resizable(cellEditor); |
| 3461 | |
| 3462 | singleCellEditWin->show(); |
| 3463 | while( singleCellEditWin->shown() ) { |
| 3464 | Fl::wait(); |
| 3465 | } |
| 3466 | |
| 3467 | if( changeContent ) { |
| 3468 | windows[winIndex].addUndoStateCell(windows[winIndex].table->getCell(selected[0], selected[1]), selected[0], selected[1], "Cell edited"); |
| 3469 | windows[winIndex].setChanged(true); |
| 3470 | windows[winIndex].setUsed(true); |
no test coverage detected