| 680 | |
| 681 | |
| 682 | void NNotebookView::editComplete() { |
| 683 | editor->setVisible(false); |
| 684 | QString text = editor->text().trimmed(); |
| 685 | |
| 686 | // Check if this is a notebook or a stack |
| 687 | if (editor->lid > 0) { |
| 688 | qint32 lid = editor->lid; |
| 689 | NotebookTable table(global.db); |
| 690 | Notebook notebook; |
| 691 | table.get(notebook, lid); |
| 692 | QString oldName = ""; |
| 693 | if (notebook.name.isSet()) |
| 694 | oldName = notebook.name; |
| 695 | |
| 696 | // Check that this notebook doesn't already exist |
| 697 | // if it exists or the length == 0, we go back to the original name |
| 698 | qint32 check = 0; |
| 699 | if (text.toLower() == oldName.toLower() && text != oldName) |
| 700 | check = 0; |
| 701 | else |
| 702 | check = table.findByName(text); |
| 703 | if (check != 0 || text.trimmed() == "") { |
| 704 | NNotebookViewItem *item = dataStore[lid]; |
| 705 | item->setData(NAME_POSITION, Qt::DisplayRole, oldName); |
| 706 | } else { |
| 707 | notebook.name = text; |
| 708 | table.update(notebook, true); |
| 709 | emit notebookRenamed(lid, oldName, text); |
| 710 | } |
| 711 | |
| 712 | //delete editor; |
| 713 | this->sortItems(NAME_POSITION, Qt::AscendingOrder); |
| 714 | resetSize(); |
| 715 | this->sortByColumn(NAME_POSITION); |
| 716 | } else { |
| 717 | // This is if we are renaming a stack |
| 718 | QString oldName = editor->stackName; |
| 719 | NNotebookViewItem *item = stackStore[oldName]; |
| 720 | |
| 721 | // If this is null, then we are on our second time here. |
| 722 | if (item == NULL) |
| 723 | return; |
| 724 | |
| 725 | if (text.trimmed() == "" || stackStore[text.trimmed()] != NULL) { |
| 726 | item->setData(NAME_POSITION, Qt::DisplayRole, oldName); |
| 727 | return; |
| 728 | } |
| 729 | NotebookTable table(global.db); |
| 730 | table.renameStack(oldName, text); |
| 731 | |
| 732 | // Rename it in the stackStore |
| 733 | stackStore.remove(oldName); |
| 734 | stackStore.insert(text, item); |
| 735 | |
| 736 | // Remove the old menu item |
| 737 | for (int i=0; i<stackMenu->actions().size(); i++) { |
| 738 | if(stackMenu->actions().at(i)->text() == oldName) { |
| 739 | stackMenu->removeAction(stackMenu->actions().at(i)); |
nothing calls this directly
no test coverage detected