diff --git a/src/plugins/coreplugin/coreplugin.pro b/src/plugins/coreplugin/coreplugin.pro index a52122cf35d..aee407e7a05 100644 --- a/src/plugins/coreplugin/coreplugin.pro +++ b/src/plugins/coreplugin/coreplugin.pro @@ -90,7 +90,8 @@ SOURCES += mainwindow.cpp \ rssfetcher.cpp \ externaltool.cpp \ dialogs/externaltoolconfig.cpp \ - toolsettings.cpp + toolsettings.cpp \ + variablechooser.cpp HEADERS += mainwindow.h \ editmode.h \ @@ -178,7 +179,8 @@ HEADERS += mainwindow.h \ rssfetcher.h \ externaltool.h \ dialogs/externaltoolconfig.h \ - toolsettings.h + toolsettings.h \ + variablechooser.h FORMS += dialogs/newdialog.ui \ actionmanager/commandmappings.ui \ @@ -186,7 +188,8 @@ FORMS += dialogs/newdialog.ui \ dialogs/openwithdialog.ui \ editormanager/openeditorsview.ui \ generalsettings.ui \ - dialogs/externaltoolconfig.ui + dialogs/externaltoolconfig.ui \ + variablechooser.ui RESOURCES += core.qrc \ fancyactionbar.qrc diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index b9061bcd7e7..9428209a9aa 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -86,6 +86,11 @@ enum { debugEditorManager=0 }; +static const char * const kCurrentDocumentFilePath = "CurrentDocument:FilePath"; +static const char * const kCurrentDocumentPath = "CurrentDocument:Path"; +static const char * const kCurrentDocumentXPos = "CurrentDocument:XPos"; +static const char * const kCurrentDocumentYPos = "CurrentDocument:YPos"; + static inline ExtensionSystem::PluginManager *pluginManager() { return ExtensionSystem::PluginManager::instance(); @@ -470,7 +475,16 @@ void EditorManager::init() m_d->m_openEditorsFactory = new OpenEditorsViewFactory(); pluginManager()->addObject(m_d->m_openEditorsFactory); - connect(VariableManager::instance(), SIGNAL(variableUpdateRequested(QString)), + VariableManager *vm = VariableManager::instance(); + vm->registerVariable(QLatin1String(kCurrentDocumentFilePath), + tr("Full path of the current document including file name.")); + vm->registerVariable(QLatin1String(kCurrentDocumentPath), + tr("Full path of the current document excluding file name.")); + vm->registerVariable(QLatin1String(kCurrentDocumentXPos), + tr("X-coordinate of the current editor's upper left corner, relative to screen.")); + vm->registerVariable(QLatin1String(kCurrentDocumentYPos), + tr("Y-coordinate of the current editor's upper left corner, relative to screen.")); + connect(vm, SIGNAL(variableUpdateRequested(QString)), this, SLOT(updateVariable(QString))); } @@ -2008,10 +2022,6 @@ QString EditorManager::windowTitleAddition() const void EditorManager::updateVariable(const QString &variable) { - static const char * const kCurrentDocumentFilePath = "CurrentDocument:FilePath"; - static const char * const kCurrentDocumentPath = "CurrentDocument:Path"; - static const char * const kCurrentDocumentXPos = "CurrentDocument:XPos"; - static const char * const kCurrentDocumentYPos = "CurrentDocument:YPos"; if (variable == QLatin1String(kCurrentDocumentFilePath) || variable == QLatin1String(kCurrentDocumentPath)) { QString value; diff --git a/src/plugins/coreplugin/mainwindow.cpp b/src/plugins/coreplugin/mainwindow.cpp index e08b992a7b3..ad10e914982 100644 --- a/src/plugins/coreplugin/mainwindow.cpp +++ b/src/plugins/coreplugin/mainwindow.cpp @@ -57,6 +57,7 @@ #include "progressview.h" #include "shortcutsettings.h" #include "vcsmanager.h" +#include "variablechooser.h" #include "scriptmanager_p.h" #include "settingsdialog.h" diff --git a/src/plugins/coreplugin/variablechooser.cpp b/src/plugins/coreplugin/variablechooser.cpp new file mode 100644 index 00000000000..ea9def90efb --- /dev/null +++ b/src/plugins/coreplugin/variablechooser.cpp @@ -0,0 +1,116 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** No Commercial Usage +** +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#include "variablechooser.h" +#include "ui_variablechooser.h" +#include "variablemanager.h" + +using namespace Core; + +VariableChooser::VariableChooser(QWidget *parent) : + QWidget(parent), + ui(new Ui::VariableChooser), + m_lineEdit(0), + m_textEdit(0), + m_plainTextEdit(0) +{ + setAttribute(Qt::WA_DeleteOnClose); + ui->setupUi(this); + m_defaultDescription = ui->variableDescription->text(); + ui->variableList->setAttribute(Qt::WA_MacSmallSize); + ui->variableList->setAttribute(Qt::WA_MacShowFocusRect, false); + ui->variableDescription->setAttribute(Qt::WA_MacSmallSize); + setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint); + setFocusProxy(ui->variableList); + + VariableManager *vm = VariableManager::instance(); + foreach (const QString &variable, vm->variables()) { + ui->variableList->addItem(variable); + } + + connect(ui->variableList, SIGNAL(currentTextChanged(QString)), + this, SLOT(updateDescription(QString))); + connect(ui->variableList, SIGNAL(itemActivated(QListWidgetItem*)), + this, SLOT(handleItemActivated(QListWidgetItem*))); + connect(qApp, SIGNAL(focusChanged(QWidget*,QWidget*)), + this, SLOT(updateCurrentEditor(QWidget*))); + updateCurrentEditor(qApp->focusWidget()); +} + +VariableChooser::~VariableChooser() +{ + delete ui; +} + +void VariableChooser::updateDescription(const QString &variable) +{ + if (variable.isNull()) + ui->variableDescription->setText(m_defaultDescription); + else + ui->variableDescription->setText(VariableManager::instance()->variableDescription(variable)); +} + +void VariableChooser::updateCurrentEditor(QWidget *widget) +{ + if (QLineEdit *lineEdit = qobject_cast(widget)) { + m_lineEdit = lineEdit; + m_textEdit = 0; + m_plainTextEdit = 0; + } else if (QTextEdit *textEdit = qobject_cast(widget)) { + m_lineEdit = 0; + m_textEdit = textEdit; + m_plainTextEdit = 0; + } else if (QPlainTextEdit *plainTextEdit = qobject_cast(widget)) { + m_lineEdit = 0; + m_textEdit = 0; + m_plainTextEdit = plainTextEdit; + } +} + +void VariableChooser::handleItemActivated(QListWidgetItem *item) +{ + if (item) + insertVariable(item->text()); +} + +void VariableChooser::insertVariable(const QString &variable) +{ + const QString &text = QLatin1String("${") + variable + QLatin1String("}"); + if (m_lineEdit) { + m_lineEdit->insert(text); + } else if (m_textEdit) { + m_textEdit->insertPlainText(text); + } else if (m_plainTextEdit) { + m_plainTextEdit->insertPlainText(text); + } +} diff --git a/src/plugins/coreplugin/variablechooser.h b/src/plugins/coreplugin/variablechooser.h new file mode 100644 index 00000000000..71e2db56916 --- /dev/null +++ b/src/plugins/coreplugin/variablechooser.h @@ -0,0 +1,76 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** No Commercial Usage +** +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#ifndef VARIABLECHOOSER_H +#define VARIABLECHOOSER_H + +#include "core_global.h" + +#include +#include +#include +#include +#include +#include + +namespace Core { + +namespace Ui { + class VariableChooser; +} + +class CORE_EXPORT VariableChooser : public QWidget +{ + Q_OBJECT + +public: + explicit VariableChooser(QWidget *parent = 0); + ~VariableChooser(); + +private slots: + void updateDescription(const QString &variable); + void updateCurrentEditor(QWidget *widget); + void handleItemActivated(QListWidgetItem *item); + void insertVariable(const QString &variable); + +private: + Ui::VariableChooser *ui; + QString m_defaultDescription; + QPointer m_lineEdit; + QPointer m_textEdit; + QPointer m_plainTextEdit; +}; + + +} // namespace Core +#endif // VARIABLECHOOSER_H diff --git a/src/plugins/coreplugin/variablechooser.ui b/src/plugins/coreplugin/variablechooser.ui new file mode 100644 index 00000000000..7cb04a0ce92 --- /dev/null +++ b/src/plugins/coreplugin/variablechooser.ui @@ -0,0 +1,55 @@ + + + Core::VariableChooser + + + + 0 + 0 + 218 + 321 + + + + Variables + + + + 3 + + + 3 + + + 3 + + + 12 + + + + + + + + + 0 + 60 + + + + Select a variable to insert. + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + + + + + + diff --git a/src/plugins/coreplugin/variablemanager.cpp b/src/plugins/coreplugin/variablemanager.cpp index 460dacd8d84..8cafe1120e1 100644 --- a/src/plugins/coreplugin/variablemanager.cpp +++ b/src/plugins/coreplugin/variablemanager.cpp @@ -63,6 +63,7 @@ class VariableManagerPrivate : public QObject public: QHash m_map; VMMapExpander m_macroExpander; + QMap m_descriptions; static VariableManager *m_instance; }; @@ -113,6 +114,21 @@ VariableManager* VariableManager::instance() return VariableManagerPrivate::m_instance; } +void VariableManager::registerVariable(const QString &variable, const QString &description) +{ + d->m_descriptions.insert(variable, description); +} + +QList VariableManager::variables() const +{ + return d->m_descriptions.keys(); +} + +QString VariableManager::variableDescription(const QString &variable) const +{ + return d->m_descriptions.value(variable); +} + } // namespace Core #include "variablemanager.moc" diff --git a/src/plugins/coreplugin/variablemanager.h b/src/plugins/coreplugin/variablemanager.h index aca73c6ef45..bedefb7f0c7 100644 --- a/src/plugins/coreplugin/variablemanager.h +++ b/src/plugins/coreplugin/variablemanager.h @@ -67,6 +67,11 @@ public: QString value(const QString &variable, const QString &defaultValue); Utils::AbstractMacroExpander *macroExpander(); + void registerVariable(const QString &variable, + const QString &description); + QList variables() const; + QString variableDescription(const QString &variable) const; + signals: void variableUpdateRequested(const QString &variable); diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index cda7db40d8c..8cbd0004b9b 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -129,6 +129,9 @@ namespace { bool debug = false; } +static const char * const kCurrentProjectPath = "CurrentProject:Path"; +static const char * const kCurrentProjectFilePath = "CurrentProject:FilePath"; + namespace ProjectExplorer { struct ProjectExplorerPluginPrivate { @@ -899,7 +902,12 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er updateWelcomePage(); - connect(Core::VariableManager::instance(), SIGNAL(variableUpdateRequested(QString)), + Core::VariableManager *vm = Core::VariableManager::instance(); + vm->registerVariable(QLatin1String(kCurrentProjectFilePath), + tr("Full path of the current project's main file, including file name.")); + vm->registerVariable(QLatin1String(kCurrentProjectPath), + tr("Full path of the current project's main file, excluding file name.")); + connect(vm, SIGNAL(variableUpdateRequested(QString)), this, SLOT(updateVariable(QString))); return true; @@ -1001,8 +1009,6 @@ void ProjectExplorerPlugin::loadCustomWizards() void ProjectExplorerPlugin::updateVariable(const QString &variable) { - static const char * const kCurrentProjectPath= "CurrentProject:Path"; - static const char * const kCurrentProjectFilePath= "CurrentProject:FilePath"; if (variable == QLatin1String(kCurrentProjectFilePath)) { if (currentProject() && currentProject()->file()) { Core::VariableManager::instance()->insert(variable, diff --git a/src/plugins/qt4projectmanager/qt4projectmanager.cpp b/src/plugins/qt4projectmanager/qt4projectmanager.cpp index 0ba8a73ff61..d6ca081d4b7 100644 --- a/src/plugins/qt4projectmanager/qt4projectmanager.cpp +++ b/src/plugins/qt4projectmanager/qt4projectmanager.cpp @@ -76,6 +76,8 @@ using ProjectExplorer::FormType; using ProjectExplorer::ResourceType; using ProjectExplorer::UnknownFileType; +static const char * const kInstallBins = "CurrentProject:QT_INSTALL_BINS"; + // Known file types of a Qt 4 project static const char* qt4FileTypes[] = { "CppHeaderFiles", @@ -134,7 +136,10 @@ void Qt4Manager::init() connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)), this, SLOT(editorChanged(Core::IEditor*))); - connect(Core::VariableManager::instance(), SIGNAL(variableUpdateRequested(QString)), + Core::VariableManager *vm = Core::VariableManager::instance(); + vm->registerVariable(QLatin1String(kInstallBins), + tr("Full path to the bin/ install directory of the current project's Qt version.")); + connect(vm, SIGNAL(variableUpdateRequested(QString)), this, SLOT(updateVariable(QString))); } @@ -179,7 +184,6 @@ void Qt4Manager::editorAboutToClose(Core::IEditor *editor) void Qt4Manager::updateVariable(const QString &variable) { - static const char * const kInstallBins = "QT_INSTALL_BINS"; if (variable == QLatin1String(kInstallBins)) { Qt4Project *qt4pro = qobject_cast(projectExplorer()->currentProject()); if (!qt4pro) { diff --git a/src/plugins/texteditor/texteditorplugin.cpp b/src/plugins/texteditor/texteditorplugin.cpp index 0e9defdc02c..513caa37eaa 100644 --- a/src/plugins/texteditor/texteditorplugin.cpp +++ b/src/plugins/texteditor/texteditorplugin.cpp @@ -68,6 +68,13 @@ using namespace TextEditor; using namespace TextEditor::Internal; +static const char * const kCurrentDocumentSelection = "CurrentDocument:Selection"; +static const char * const kCurrentDocumentRow = "CurrentDocument:Row"; +static const char * const kCurrentDocumentColumn = "CurrentDocument:Column"; +static const char * const kCurrentDocumentRowCount = "CurrentDocument:RowCount"; +static const char * const kCurrentDocumentColumnCount = "CurrentDocument:ColumnCount"; +static const char * const kCurrentDocumentFontSize = "CurrentDocument:FontSize"; + TextEditorPlugin *TextEditorPlugin::m_instance = 0; TextEditorPlugin::TextEditorPlugin() @@ -177,7 +184,21 @@ void TextEditorPlugin::extensionsInitialized() addAutoReleasedObject(new FindInFiles(Find::SearchResultWindow::instance())); addAutoReleasedObject(new FindInCurrentFile(Find::SearchResultWindow::instance())); - connect(Core::VariableManager::instance(), SIGNAL(variableUpdateRequested(QString)), + + Core::VariableManager *vm = Core::VariableManager::instance(); + vm->registerVariable(QLatin1String(kCurrentDocumentSelection), + tr("Selected text within the current document.")); + vm->registerVariable(QLatin1String(kCurrentDocumentRow), + tr("Line number of the text cursor position in current document (starts with 1).")); + vm->registerVariable(QLatin1String(kCurrentDocumentColumn), + tr("Column number of the text cursor position in current document (starts with 0).")); + vm->registerVariable(QLatin1String(kCurrentDocumentRowCount), + tr("Number of lines visible in current document.")); + vm->registerVariable(QLatin1String(kCurrentDocumentColumnCount), + tr("Number of columns visible in current document.")); + vm->registerVariable(QLatin1String(kCurrentDocumentFontSize), + tr("Current document's font size in points.")); + connect(vm, SIGNAL(variableUpdateRequested(QString)), this, SLOT(updateVariable(QString))); connect(Core::ExternalToolManager::instance(), SIGNAL(replaceSelectionRequested(QString)), this, SLOT(updateCurrentSelection(QString))); @@ -216,12 +237,6 @@ void TextEditorPlugin::updateSearchResultsFont(const FontSettings &settings) void TextEditorPlugin::updateVariable(const QString &variable) { - static const char * const kCurrentDocumentSelection = "CurrentDocument:Selection"; - static const char * const kCurrentDocumentRow = "CurrentDocument:Row"; - static const char * const kCurrentDocumentColumn = "CurrentDocument:Column"; - static const char * const kCurrentDocumentRowCount = "CurrentDocument:RowCount"; - static const char * const kCurrentDocumentColumnCount = "CurrentDocument:ColumnCount"; - static const char * const kCurrentDocumentFontSize = "CurrentDocument:FontSize"; static QSet variables = QSet() << QString::fromLatin1(kCurrentDocumentSelection) << QString::fromLatin1(kCurrentDocumentRow) diff --git a/src/share/qtcreator/externaltools/lrelease.xml b/src/share/qtcreator/externaltools/lrelease.xml index 70f69c12fd6..d42d15eacbd 100644 --- a/src/share/qtcreator/externaltools/lrelease.xml +++ b/src/share/qtcreator/externaltools/lrelease.xml @@ -38,7 +38,7 @@ Linguist 2 - %{QT_INSTALL_BINS}/lrelease + %{CurrentProject:QT_INSTALL_BINS}/lrelease lrelease %{CurrentProject:FilePath} %{CurrentProject:Path} diff --git a/src/share/qtcreator/externaltools/lupdate.xml b/src/share/qtcreator/externaltools/lupdate.xml index 65ce542efd4..b3ed21a4317 100644 --- a/src/share/qtcreator/externaltools/lupdate.xml +++ b/src/share/qtcreator/externaltools/lupdate.xml @@ -38,7 +38,7 @@ Linguist 1 - %{QT_INSTALL_BINS}/lupdate + %{CurrentProject:QT_INSTALL_BINS}/lupdate lupdate %{CurrentProject:FilePath} %{CurrentProject:Path}