MCPcopy Create free account
hub / github.com/Tablecruncher/tablecruncher / paste

Method paste

src/csvapplication.cpp:1483–1590  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1481
1482
1483void CsvApplication::paste(bool askUser, bool fillSelection) {
1484 std::vector<std::vector<std::string>> block;
1485 CsvDataStorage localStorage;
1486 int block_rows, block_cols;
1487 int row_top, row_bottom, col_top, col_bottom;
1488
1489 windows[topWindow].grid->get_selection(row_top, col_top, row_bottom, col_bottom);
1490 CsvDefinition activeDefinition = windows[topWindow].table->getDefinition(); // the definition of the table in the active window
1491
1492 std::pair<CsvDefinition, float> guessedDefinition;
1493 CsvDefinition definition;
1494 CsvParser parser;
1495
1496 Fl::paste(*windows[topWindow].win, 1, Fl::clipboard_plain_text);
1497 std::string pasted(Fl::event_text(), Fl::event_length());
1498
1499 //
1500 // "Paste into Selection": Pastes content into all selected cells and returns
1501 if( fillSelection ) {
1502 windows[topWindow].addUndoStateTable("Fill");
1503 showImWorkingWindow("Pasting data ...");
1504 for( int r = row_top; r <= row_bottom; ++r ) {
1505 for( int c = col_top; c <= col_bottom; ++c ) {
1506 windows[topWindow].table->setCell(pasted, r,c);
1507 }
1508 }
1509 hideImWorkingWindow();
1510 windows[topWindow].updateTable();
1511 windows[topWindow].setChanged(true);
1512 windows[topWindow].setUsed(true);
1513 return;
1514 }
1515
1516 std::istringstream input(pasted);
1517 std::cout << std::endl;
1518
1519
1520 //
1521 // if pasted string doesn't contain active delimiter and
1522 // askUser is not set
1523 if( !askUser && pasted.find(activeDefinition.delimiter) == std::string::npos ) {
1524 windows[topWindow].addUndoStateCell(windows[topWindow].table->getCell(row_top,col_top), row_top, col_top, "Paste cell");
1525 windows[topWindow].table->setCell(pasted,row_top,col_top);
1526 windows[topWindow].setChanged(true);
1527 windows[topWindow].setUsed(true);
1528 windows[topWindow].grid->redraw();
1529 Fl::check();
1530 return;
1531 }
1532
1533 // guess properties
1534 guessedDefinition = app.guessDefinition(&input);
1535 definition = guessedDefinition.first;
1536 definition.encoding = CsvDefinition::ENC_UTF8;
1537
1538
1539 // ask user if confidence is lower than 1.0, if the user should be asked or if the guessed delimiter is none of the top 3 delimiters and not the one used in the underlying table
1540 #ifdef DEBUG

Callers 1

MyMenuCallbackMethod · 0.80

Calls 15

checkFunction · 0.85
getDefinitionMethod · 0.80
addUndoStateTableMethod · 0.80
setCellMethod · 0.80
updateTableMethod · 0.80
setChangedMethod · 0.80
setUsedMethod · 0.80
findMethod · 0.80
addUndoStateCellMethod · 0.80
getCellMethod · 0.80
guessDefinitionMethod · 0.80
parseCsvStreamMethod · 0.80

Tested by

no test coverage detected