/** \brief Process the result of the popup menu */ void popupAction() { if (popup_->result()) { /* * You could also bind extra data to an item using setData() and * check here for the action asked. For now, we just use the text. */ WString text = popup_->result()->text(); popup_->hide(); popupActionBox_ = new WMessageBox("Sorry.","Action '" + text + "' is not implemented.", NoIcon, Ok); popupActionBox_->buttonClicked() .connect(this, &TreeViewDragDrop::dialogDone); popupActionBox_->show(); } else { popup_->hide(); } }
/*! \brief Show a popup for a folder item. */ void showPopup(const WModelIndex& item, const WMouseEvent& event) { if (event.button() == WMouseEvent::RightButton) { // Select the item, it was not yet selected. if (!folderView_->isSelected(item)) folderView_->select(item); if (!popup_) { popup_ = new WPopupMenu(); popup_->addItem("icons/folder_new.gif", "Create a New Folder"); popup_->addItem("Rename this Folder")->setCheckable(true); popup_->addItem("Delete this Folder"); popup_->addSeparator(); popup_->addItem("Folder Details"); popup_->addSeparator(); popup_->addItem("Application Inventory"); popup_->addItem("Hardware Inventory"); popup_->addSeparator(); WPopupMenu *subMenu = new WPopupMenu(); subMenu->addItem("Sub Item 1"); subMenu->addItem("Sub Item 2"); popup_->addMenu("File Deployments", subMenu); /* * This is one method of executing a popup, which does not block a * thread for a reentrant event loop, and thus scales. * * Alternatively you could call WPopupMenu::exec(), which returns * the result, but while waiting for it, blocks the thread. */ popup_->aboutToHide().connect(this, &TreeViewDragDrop::popupAction); } if (popup_->isHidden()) popup_->popup(event); else popup_->hide(); } }