diff --git a/src/plugins/coreplugin/coreplugin.pro b/src/plugins/coreplugin/coreplugin.pro index a52122cf35d373a08bc3225cedec604c4e085784..aee407e7a0514ba7091278d68f82ecf981144272 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 b9061bcd7e7715ba2a56170505e30b1f07069312..9428209a9aabda02c5c92f0af200169bb4587e12 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 e08b992a7b38f7d002aef7ece6a83630c1a747c1..ad10e914982b6972ada04b55ff5fbb703e0c2a91 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 0000000000000000000000000000000000000000..ea9def90efb7bd81cde9d295c32fcbcfa9499569 --- /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<QLineEdit *>(widget)) { + m_lineEdit = lineEdit; + m_textEdit = 0; + m_plainTextEdit = 0; + } else if (QTextEdit *textEdit = qobject_cast<QTextEdit *>(widget)) { + m_lineEdit = 0; + m_textEdit = textEdit; + m_plainTextEdit = 0; + } else if (QPlainTextEdit *plainTextEdit = qobject_cast<QPlainTextEdit *>(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 0000000000000000000000000000000000000000..71e2db569169f945dd6e8b1ece12033bd6c5b7a2 --- /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 <QtCore/QPointer> +#include <QtGui/QWidget> +#include <QtGui/QLineEdit> +#include <QtGui/QTextEdit> +#include <QtGui/QPlainTextEdit> +#include <QtGui/QListWidgetItem> + +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<QLineEdit> m_lineEdit; + QPointer<QTextEdit> m_textEdit; + QPointer<QPlainTextEdit> 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 0000000000000000000000000000000000000000..7cb04a0ce920f6962f441b29508f139d6039ae61 --- /dev/null +++ b/src/plugins/coreplugin/variablechooser.ui @@ -0,0 +1,55 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>Core::VariableChooser</class> + <widget class="QWidget" name="Core::VariableChooser"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>218</width> + <height>321</height> + </rect> + </property> + <property name="windowTitle"> + <string>Variables</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <property name="leftMargin"> + <number>3</number> + </property> + <property name="topMargin"> + <number>3</number> + </property> + <property name="rightMargin"> + <number>3</number> + </property> + <property name="bottomMargin"> + <number>12</number> + </property> + <item> + <widget class="QListWidget" name="variableList"/> + </item> + <item> + <widget class="QLabel" name="variableDescription"> + <property name="minimumSize"> + <size> + <width>0</width> + <height>60</height> + </size> + </property> + <property name="text"> + <string>Select a variable to insert.</string> + </property> + <property name="alignment"> + <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/src/plugins/coreplugin/variablemanager.cpp b/src/plugins/coreplugin/variablemanager.cpp index 460dacd8d84acb46d3a691035a3b80860a8f4035..8cafe1120e1891b521858a9a91201e977276687c 100644 --- a/src/plugins/coreplugin/variablemanager.cpp +++ b/src/plugins/coreplugin/variablemanager.cpp @@ -63,6 +63,7 @@ class VariableManagerPrivate : public QObject public: QHash<QString, QString> m_map; VMMapExpander m_macroExpander; + QMap<QString, QString> 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<QString> 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 aca73c6ef45b24f7ec2cc57a5a9a7d34a34bc9e4..bedefb7f0c72f207beb62e8c7a9347547aa0de03 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<QString> 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 cda7db40d8c4980951f8c7027b91785a6e0acfec..8cbd0004b9b22e2820a302b27b800a10a6c5cea8 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 0ba8a73ff6186d57d3bffbae4f97e4f9e2a5f69a..d6ca081d4b77c631a58c6e50bca3e8446fb2a34e 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<Qt4Project *>(projectExplorer()->currentProject()); if (!qt4pro) { diff --git a/src/plugins/texteditor/texteditorplugin.cpp b/src/plugins/texteditor/texteditorplugin.cpp index 0e9defdc02c57c74ebfbc9d754c4f00467179a1a..513caa37eaad5c9036f5a3831cc3142a6f32b8a0 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<QString> variables = QSet<QString>() << QString::fromLatin1(kCurrentDocumentSelection) << QString::fromLatin1(kCurrentDocumentRow) diff --git a/src/share/qtcreator/externaltools/lrelease.xml b/src/share/qtcreator/externaltools/lrelease.xml index 70f69c12fd6b127616424c27e02db3f3de55f3e6..d42d15eacbd5d8efc4c5f38b84966595c789ab48 100644 --- a/src/share/qtcreator/externaltools/lrelease.xml +++ b/src/share/qtcreator/externaltools/lrelease.xml @@ -38,7 +38,7 @@ <category xml:lang="de">Linguist</category> <order>2</order> <executable> - <path>%{QT_INSTALL_BINS}/lrelease</path> + <path>%{CurrentProject:QT_INSTALL_BINS}/lrelease</path> <path>lrelease</path> <arguments>%{CurrentProject:FilePath}</arguments> <workingdirectory>%{CurrentProject:Path}</workingdirectory> diff --git a/src/share/qtcreator/externaltools/lupdate.xml b/src/share/qtcreator/externaltools/lupdate.xml index 65ce542efd4e1f0822cfb8c7561dd06e0b8a3cc5..b3ed21a4317ab34053bd9035fef9571d67934348 100644 --- a/src/share/qtcreator/externaltools/lupdate.xml +++ b/src/share/qtcreator/externaltools/lupdate.xml @@ -38,7 +38,7 @@ <category xml:lang="de">Linguist</category> <order>1</order> <executable> - <path>%{QT_INSTALL_BINS}/lupdate</path> + <path>%{CurrentProject:QT_INSTALL_BINS}/lupdate</path> <path>lupdate</path> <arguments>%{CurrentProject:FilePath}</arguments> <workingdirectory>%{CurrentProject:Path}</workingdirectory>