void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev) { QMenu menu; // Open current item const QModelIndex current = currentItem(); const bool hasCurrentItem = current.isValid(); QAction *actionOpen = menu.addAction(actionOpenText(m_fileSystemModel, current)); actionOpen->setEnabled(hasCurrentItem); // Explorer & teminal QAction *actionExplorer = menu.addAction(Core::FileUtils::msgGraphicalShellAction()); actionExplorer->setEnabled(hasCurrentItem); QAction *actionTerminal = menu.addAction(Core::FileUtils::msgTerminalAction()); actionTerminal->setEnabled(hasCurrentItem); QAction *actionFind = menu.addAction(msgFindOnFileSystem()); actionFind->setEnabled(hasCurrentItem); // open with... if (!m_fileSystemModel->isDir(current)) { QMenu *openWith = menu.addMenu(tr("Open with")); Core::DocumentManager::populateOpenWithMenu(openWith, m_fileSystemModel->filePath(current)); } // Open file dialog to choose a path starting from current QAction *actionChooseFolder = menu.addAction(tr("Choose Folder...")); QAction *action = menu.exec(ev->globalPos()); if (!action) return; ev->accept(); if (action == actionOpen) { // Handle open file. openItem(current); return; } if (action == actionChooseFolder) { // Open file dialog const QString newPath = QFileDialog::getExistingDirectory(this, tr("Choose Folder"), currentDirectory()); if (!newPath.isEmpty()) setCurrentDirectory(newPath); return; } if (action == actionTerminal) { Core::FileUtils::openTerminal(m_fileSystemModel->filePath(current)); return; } if (action == actionExplorer) { Core::FileUtils::showInGraphicalShell(this, m_fileSystemModel->filePath(current)); return; } if (action == actionFind) { QFileInfo info = m_fileSystemModel->fileInfo(current); if (m_fileSystemModel->isDir(current)) findOnFileSystem(info.absoluteFilePath()); else findOnFileSystem(info.absolutePath()); return; } Core::DocumentManager::executeOpenWithMenuAction(action); }
void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev) { QMenu menu; // Open current item const QModelIndex current = currentItem(); const bool hasCurrentItem = current.isValid(); QAction *actionOpen = menu.addAction(actionOpenText(m_fileSystemModel, current)); actionOpen->setEnabled(hasCurrentItem); // Explorer & teminal QAction *actionExplorer = menu.addAction(msgGraphicalShellAction()); actionExplorer->setEnabled(hasCurrentItem); QAction *actionTerminal = menu.addAction(msgTerminalAction()); actionTerminal->setEnabled(hasCurrentItem); // open with... if (!m_fileSystemModel->isDir(current)) { QMenu *openWith = menu.addMenu(tr("Open with")); ProjectExplorerPlugin::populateOpenWithMenu(openWith, m_fileSystemModel->filePath(current)); } // Open file dialog to choose a path starting from current QAction *actionChooseFolder = menu.addAction(tr("Choose folder...")); QAction *action = menu.exec(ev->globalPos()); if (!action) return; ev->accept(); if (action == actionOpen) { // Handle open file. openItem(current); return; } if (action == actionChooseFolder) { // Open file dialog const QString newPath = QFileDialog::getExistingDirectory(this, tr("Choose folder"), currentDirectory()); if (!newPath.isEmpty()) setCurrentDirectory(newPath); return; } if (action == actionTerminal) { openTerminal(m_fileSystemModel->filePath(current)); return; } if (action == actionExplorer) { showInGraphicalShell(this, m_fileSystemModel->filePath(current)); return; } ProjectExplorerPlugin::openEditorFromAction(action, m_fileSystemModel->filePath(current)); }
void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev) { QMenu menu; // Open current item const QModelIndex current = currentItem(); const bool hasCurrentItem = current.isValid(); QAction *actionOpen = menu.addAction(actionOpenText(m_fileSystemModel, current)); actionOpen->setEnabled(hasCurrentItem); // we need dummy DocumentModel::Entry with absolute file path in it // to get EditorManager::addNativeDirAndOpenWithActions() working Core::DocumentModel::Entry fakeEntry; Core::IDocument document; document.setFilePath(Utils::FileName::fromString(m_fileSystemModel->filePath(current))); fakeEntry.document = &document; Core::EditorManager::addNativeDirAndOpenWithActions(&menu, &fakeEntry); const bool isDirectory = hasCurrentItem && m_fileSystemModel->isDir(current); QAction *actionOpenDirectoryAsProject = 0; if (isDirectory && m_fileSystemModel->fileName(current) != QLatin1String("..")) { actionOpenDirectoryAsProject = menu.addAction(tr("Open Project in \"%1\"") .arg(m_fileSystemModel->fileName(current))); } // Open file dialog to choose a path starting from current QAction *actionChooseFolder = menu.addAction(tr("Choose Folder...")); QAction *action = menu.exec(ev->globalPos()); if (!action) return; ev->accept(); if (action == actionOpen) { // Handle open file. openItem(current); } else if (action == actionOpenDirectoryAsProject) { openItem(current, true); } else if (action == actionChooseFolder) { // Open file dialog const QString newPath = QFileDialog::getExistingDirectory(this, tr("Choose Folder"), currentDirectory()); if (!newPath.isEmpty()) setCurrentDirectory(newPath); } }
void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev) { QMenu menu; // Open current item const QModelIndex current = currentItem(); const bool hasCurrentItem = current.isValid(); QAction *actionOpen = menu.addAction(actionOpenText(m_fileSystemModel, current)); actionOpen->setEnabled(hasCurrentItem); const bool isDirectory = hasCurrentItem && m_fileSystemModel->isDir(current); QAction *actionOpenDirectoryAsProject = 0; if (isDirectory && m_fileSystemModel->fileName(current) != QLatin1String("..")) { actionOpenDirectoryAsProject = menu.addAction(tr("Open Project in \"%1\"") .arg(m_fileSystemModel->fileName(current))); } // Explorer & teminal QAction *actionExplorer = menu.addAction(Core::FileUtils::msgGraphicalShellAction()); actionExplorer->setEnabled(hasCurrentItem); QAction *actionTerminal = menu.addAction(Core::FileUtils::msgTerminalAction()); actionTerminal->setEnabled(hasCurrentItem); QAction *actionFind = menu.addAction(Core::FileUtils::msgFindInDirectory()); actionFind->setEnabled(hasCurrentItem); // open with... if (hasCurrentItem && !isDirectory) { QMenu *openWith = menu.addMenu(tr("Open With")); Core::EditorManager::populateOpenWithMenu(openWith, m_fileSystemModel->filePath(current)); } // Open file dialog to choose a path starting from current QAction *actionChooseFolder = menu.addAction(tr("Choose Folder...")); QAction *action = menu.exec(ev->globalPos()); if (!action) return; ev->accept(); if (action == actionOpen) { // Handle open file. openItem(current); return; } if (action == actionOpenDirectoryAsProject) { openItem(current, true); return; } if (action == actionChooseFolder) { // Open file dialog const QString newPath = QFileDialog::getExistingDirectory(this, tr("Choose Folder"), currentDirectory()); if (!newPath.isEmpty()) setCurrentDirectory(newPath); return; } if (action == actionTerminal) { Core::FileUtils::openTerminal(m_fileSystemModel->filePath(current)); return; } if (action == actionExplorer) { Core::FileUtils::showInGraphicalShell(this, m_fileSystemModel->filePath(current)); return; } if (action == actionFind) { TextEditor::FindInFiles::findOnFileSystem(m_fileSystemModel->filePath(current)); return; } }