The menu of bookmarks is kept sorted.
Showing the changes to interface/src/Menu.cpp (1 of 6 files). Show all
Unified · Split
| @@ -123,6 +123,10 @@ Menu::Menu() : · 122 unmodified lines | |||
| 123 | appInstance, SLOT(toggleRunningScriptsWidget())); | 123 | appInstance, SLOT(toggleRunningScriptsWidget())); |
| 124 | 124 | ||
| 125 | addDisabledActionAndSeparator(fileMenu, "Go"); | 125 | addDisabledActionAndSeparator(fileMenu, "Go"); |
| 126 | addActionToQMenuAndActionHash(fileMenu, MenuOption::BookmarkLocation, 0, | ||
| 127 | this, SLOT(bookmarkLocation())); | ||
| 128 | _bookmarksMenu = fileMenu->addMenu(MenuOption::Bookmarks); | ||
| 129 | _bookmarksMenu->setEnabled(false); | ||
| 126 | addActionToQMenuAndActionHash(fileMenu, | 130 | addActionToQMenuAndActionHash(fileMenu, |
| 127 | MenuOption::NameLocation, | 131 | MenuOption::NameLocation, |
| 128 | Qt::CTRL | Qt::Key_N, | 132 | Qt::CTRL | Qt::Key_N, |
| @@ -1010,6 +1014,53 @@ void Menu::changeVSync() { · 881 unmodified lines | |||
| 1010 | Application::getInstance()->setVSyncEnabled(isOptionChecked(MenuOption::RenderTargetFramerateVSyncOn)); | 1014 | Application::getInstance()->setVSyncEnabled(isOptionChecked(MenuOption::RenderTargetFramerateVSyncOn)); |
| 1011 | } | 1015 | } |
| 1012 | 1016 | ||
| 1017 | void Menu::bookmarkLocation() { | ||
| 1018 | |||
| 1019 | QInputDialog bookmarkLocationDialog(Application::getInstance()->getWindow()); | ||
| 1020 | bookmarkLocationDialog.setWindowTitle("Bookmark Location"); | ||
| 1021 | bookmarkLocationDialog.setLabelText("Name:"); | ||
| 1022 | bookmarkLocationDialog.setInputMode(QInputDialog::TextInput); | ||
| 1023 | bookmarkLocationDialog.resize(400, 200); | ||
| 1024 | |||
| 1025 | if (bookmarkLocationDialog.exec() == QDialog::Rejected) { | ||
| 1026 | return; | ||
| 1027 | } | ||
| 1028 | |||
| 1029 | QString bookmarkName = bookmarkLocationDialog.textValue().trimmed(); | ||
| 1030 | if (bookmarkName.length() == 0) { | ||
| 1031 | return; | ||
| 1032 | } | ||
| 1033 | |||
| 1034 | AddressManager::SharedPointer addressManager = DependencyManager::get<AddressManager>(); | ||
| 1035 | QString bookmarkAddress = addressManager->currentAddress().toString(); | ||
| 1036 | |||
| 1037 | Bookmarks* bookmarks = Application::getInstance()->getBookmarks(); | ||
| 1038 | if (bookmarks->contains(bookmarkName)) { | ||
| 1039 | QMessageBox duplicateBookmarkMessage; | ||
| 1040 | duplicateBookmarkMessage.setIcon(QMessageBox::Warning); | ||
| 1041 | duplicateBookmarkMessage.setText("The bookmark name you entered already exists in your list."); | ||
| 1042 | duplicateBookmarkMessage.setInformativeText("Would you like to overwrite it?"); | ||
| 1043 | duplicateBookmarkMessage.setStandardButtons(QMessageBox::Yes | QMessageBox::No); | ||
| 1044 | duplicateBookmarkMessage.setDefaultButton(QMessageBox::Yes); | ||
| 1045 | if (duplicateBookmarkMessage.exec() == QMessageBox::No) { | ||
| 1046 | return; | ||
| 1047 | } | ||
| 1048 | removeAction(_bookmarksMenu, bookmarkName); | ||
| 1049 | } | ||
| 1050 | |||
| 1051 | bookmarks->insert(bookmarkName, bookmarkAddress); | ||
| 1052 | |||
| 1053 | QList<QAction*> menuItems = _bookmarksMenu->actions(); | ||
| 1054 | int position = 0; | ||
| 1055 | while (position < menuItems.count() && bookmarkName > menuItems[position]->text()) { | ||
| 1056 | position += 1; | ||
| 1057 | } | ||
| 1058 | addActionToQMenuAndActionHash(_bookmarksMenu, bookmarkName, 0, | ||
| 1059 | this, NULL, QAction::NoRole, position); | ||
| 1060 | |||
| 1061 | _bookmarksMenu->setEnabled(true); | ||
| 1062 | } | ||
| 1063 | |||
| 1013 | void Menu::displayNameLocationResponse(const QString& errorString) { | 1064 | void Menu::displayNameLocationResponse(const QString& errorString) { |
| 1014 | 1065 | ||
| 1015 | if (!errorString.isEmpty()) { | 1066 | if (!errorString.isEmpty()) { |