Commit d34c81a2 authored by Jarek Kobus's avatar Jarek Kobus
Browse files

Add "Add Library" action to project explorer's context menu


Reviewed-by: default avatarTobias Hunger <tobias.hunger@nokia.com>
Task-number: QTCREATORBUG-4127
parent 52f52ffd
......@@ -37,7 +37,6 @@
#include "qt4projectmanager.h"
#include "qt4projectmanagerconstants.h"
#include "profileeditorfactory.h"
#include "addlibrarywizard.h"
#include <coreplugin/icore.h>
#include <coreplugin/actionmanager/actionmanager.h>
......@@ -244,26 +243,6 @@ void ProFileEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
highlighter->rehighlight();
}
void ProFileEditorWidget::addLibrary()
{
AddLibraryWizard wizard(file()->fileName(), this);
if (wizard.exec() != QDialog::Accepted)
return;
TextEditor::BaseTextEditor *editable = editor();
const int endOfDoc = editable->position(TextEditor::ITextEditor::EndOfDoc);
editable->setCursorPosition(endOfDoc);
QString snippet = wizard.snippet();
// add extra \n in case the last line is not empty
int line, column;
editable->convertPosition(endOfDoc, &line, &column);
if (!editable->textAt(endOfDoc - column, column).simplified().isEmpty())
snippet = QLatin1Char('\n') + snippet;
editable->insert(snippet);
}
void ProFileEditorWidget::jumpToFile()
{
openLink(findLinkAt(textCursor()));
......
......@@ -94,7 +94,6 @@ protected:
public slots:
virtual void setFontSettings(const TextEditor::FontSettings &);
void addLibrary();
void jumpToFile();
private:
......
......@@ -39,8 +39,10 @@
#include "qt4project.h"
#include "qt4target.h"
#include "profilereader.h"
#include "profileeditor.h"
#include "qmakestep.h"
#include "qt4buildconfiguration.h"
#include "addlibrarywizard.h"
#include "wizards/qtquickapp.h"
#include "wizards/html5app.h"
......@@ -285,6 +287,52 @@ ProjectExplorer::Project *Qt4Manager::contextProject() const
return m_contextProject;
}
void Qt4Manager::addLibrary()
{
Core::EditorManager *em = Core::EditorManager::instance();
ProFileEditorWidget *editor = qobject_cast<ProFileEditorWidget*>(em->currentEditor()->widget());
if (editor)
addLibrary(editor->file()->fileName(), editor);
}
void Qt4Manager::addLibraryContextMenu()
{
ProjectExplorer::Node *node = ProjectExplorer::ProjectExplorerPlugin::instance()->currentNode();
if (qobject_cast<Qt4ProFileNode *>(node))
addLibrary(node->path());
}
void Qt4Manager::addLibrary(const QString &fileName, ProFileEditorWidget *editor)
{
AddLibraryWizard wizard(fileName, Core::EditorManager::instance());
if (wizard.exec() != QDialog::Accepted)
return;
TextEditor::BaseTextEditor *editable = 0;
if (editor) {
editable = editor->editor();
} else {
Core::EditorManager *em = Core::EditorManager::instance();
editable = qobject_cast<TextEditor::BaseTextEditor *>
(em->openEditor(fileName, Qt4ProjectManager::Constants::PROFILE_EDITOR_ID));
}
if (!editable)
return;
const int endOfDoc = editable->position(TextEditor::ITextEditor::EndOfDoc);
editable->setCursorPosition(endOfDoc);
QString snippet = wizard.snippet();
// add extra \n in case the last line is not empty
int line, column;
editable->convertPosition(endOfDoc, &line, &column);
if (!editable->textAt(endOfDoc - column, column).simplified().isEmpty())
snippet = QLatin1Char('\n') + snippet;
editable->insert(snippet);
}
void Qt4Manager::runQMake()
{
runQMake(projectExplorer()->startupProject(), 0);
......
......@@ -93,6 +93,8 @@ public:
enum Action { BUILD, REBUILD, CLEAN };
public slots:
void addLibrary();
void addLibraryContextMenu();
void runQMake();
void runQMakeContextMenu();
void buildSubDirContextMenu();
......@@ -108,6 +110,7 @@ private slots:
private:
QList<Qt4Project *> m_projects;
void handleSubDirContexMenu(Action action);
void addLibrary(const QString &fileName, Internal::ProFileEditorWidget *editor = 0);
void runQMake(ProjectExplorer::Project *p, ProjectExplorer::Node *node);
Internal::Qt4ProjectManagerPlugin *m_plugin;
......
......@@ -109,6 +109,7 @@ bool Qt4ProjectManagerPlugin::initialize(const QStringList &arguments, QString *
{
Q_UNUSED(arguments)
const Core::Context projectContext(Qt4ProjectManager::Constants::PROJECT_ID);
Core::Context projecTreeContext(ProjectExplorer::Constants::C_PROJECT_TREE);
ProFileParser::initialize();
ProFileEvaluator::initialize();
......@@ -243,35 +244,43 @@ bool Qt4ProjectManagerPlugin::initialize(const QStringList &arguments, QString *
this, SLOT(buildStateChanged(ProjectExplorer::Project *)));
connect(m_projectExplorer, SIGNAL(currentProjectChanged(ProjectExplorer::Project *)),
this, SLOT(currentProjectChanged()));
connect(m_projectExplorer, SIGNAL(currentNodeChanged(ProjectExplorer::Node*,ProjectExplorer::Project*)),
this, SLOT(currentNodeChanged(ProjectExplorer::Node*)));
Core::ActionContainer *contextMenu = am->createMenu(Qt4ProjectManager::Constants::M_CONTEXT);
Core::Command *cmd;
Core::Context proFileEditorContext = Core::Context(Qt4ProjectManager::Constants::C_PROFILEEDITOR);
QAction *jumpToFile = new QAction(tr("Jump to File Under Cursor"), this);
cmd = am->registerAction(jumpToFile,
command = am->registerAction(jumpToFile,
Constants::JUMP_TO_FILE, proFileEditorContext);
cmd->setDefaultKeySequence(QKeySequence(Qt::Key_F2));
command->setDefaultKeySequence(QKeySequence(Qt::Key_F2));
connect(jumpToFile, SIGNAL(triggered()),
this, SLOT(jumpToFile()));
contextMenu->addAction(cmd);
contextMenu->addAction(command);
QAction *addLibrary = new QAction(tr("Add Library..."), this);
cmd = am->registerAction(addLibrary,
m_addLibraryAction = new QAction(tr("Add Library..."), this);
command = am->registerAction(m_addLibraryAction,
Constants::ADDLIBRARY, proFileEditorContext);
connect(addLibrary, SIGNAL(triggered()),
this, SLOT(addLibrary()));
contextMenu->addAction(cmd);
connect(m_addLibraryAction, SIGNAL(triggered()),
m_qt4ProjectManager, SLOT(addLibrary()));
contextMenu->addAction(command);
m_addLibraryActionContextMenu = new QAction(tr("Add Library..."), this);
command = am->registerAction(m_addLibraryActionContextMenu,
Constants::ADDLIBRARY, projecTreeContext);
connect(m_addLibraryActionContextMenu, SIGNAL(triggered()),
m_qt4ProjectManager, SLOT(addLibraryContextMenu()));
mproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_FILES);
msubproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_FILES);
QAction *separator = new QAction(this);
separator->setSeparator(true);
contextMenu->addAction(am->registerAction(separator,
Core::Id(Constants::SEPARATOR), proFileEditorContext));
cmd = am->command(TextEditor::Constants::UN_COMMENT_SELECTION);
contextMenu->addAction(cmd);
command = am->command(TextEditor::Constants::UN_COMMENT_SELECTION);
contextMenu->addAction(command);
return true;
}
......@@ -317,6 +326,11 @@ void Qt4ProjectManagerPlugin::currentProjectChanged()
m_runQMakeAction->setEnabled(!m_projectExplorer->buildManager()->isBuilding(m_projectExplorer->currentProject()));
}
void Qt4ProjectManagerPlugin::currentNodeChanged(ProjectExplorer::Node *node)
{
m_addLibraryActionContextMenu->setEnabled(qobject_cast<Qt4ProFileNode *>(node));
}
void Qt4ProjectManagerPlugin::buildStateChanged(ProjectExplorer::Project *pro)
{
ProjectExplorer::Project *currentProject = m_projectExplorer->currentProject();
......@@ -326,14 +340,6 @@ void Qt4ProjectManagerPlugin::buildStateChanged(ProjectExplorer::Project *pro)
m_runQMakeActionContextMenu->setEnabled(!m_projectExplorer->buildManager()->isBuilding(pro));
}
void Qt4ProjectManagerPlugin::addLibrary()
{
Core::EditorManager *em = Core::EditorManager::instance();
ProFileEditorWidget *editor = qobject_cast<ProFileEditorWidget*>(em->currentEditor()->widget());
if (editor)
editor->addLibrary();
}
void Qt4ProjectManagerPlugin::jumpToFile()
{
Core::EditorManager *em = Core::EditorManager::instance();
......
......@@ -69,8 +69,8 @@ private slots:
void updateContextMenu(ProjectExplorer::Project *project,
ProjectExplorer::Node *node);
void currentProjectChanged();
void currentNodeChanged(ProjectExplorer::Node *node);
void buildStateChanged(ProjectExplorer::Project *pro);
void addLibrary();
void jumpToFile();
#ifdef WITH_TESTS
......@@ -98,6 +98,8 @@ private:
QAction *m_buildSubProjectContextMenu;
QAction *m_rebuildSubProjectContextMenu;
QAction *m_cleanSubProjectContextMenu;
QAction *m_addLibraryAction;
QAction *m_addLibraryActionContextMenu;
GettingStartedWelcomePage *m_welcomePage;
Core::Context m_projectContext;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment