Commit b40500a7 authored by con's avatar con

Add a generic variable chooser widget.

The chooser allows choosing variables from a list, and inserting them
into previously focused line edit, text edit, or plain text edit.
Variables are now registered with a description in the variable manager.
Also make the QT_INSTALL_BINS --> CurrentProject:QT_INSTALL_BINS for
consistency.
parent 738d1cce
...@@ -90,7 +90,8 @@ SOURCES += mainwindow.cpp \ ...@@ -90,7 +90,8 @@ SOURCES += mainwindow.cpp \
rssfetcher.cpp \ rssfetcher.cpp \
externaltool.cpp \ externaltool.cpp \
dialogs/externaltoolconfig.cpp \ dialogs/externaltoolconfig.cpp \
toolsettings.cpp toolsettings.cpp \
variablechooser.cpp
HEADERS += mainwindow.h \ HEADERS += mainwindow.h \
editmode.h \ editmode.h \
...@@ -178,7 +179,8 @@ HEADERS += mainwindow.h \ ...@@ -178,7 +179,8 @@ HEADERS += mainwindow.h \
rssfetcher.h \ rssfetcher.h \
externaltool.h \ externaltool.h \
dialogs/externaltoolconfig.h \ dialogs/externaltoolconfig.h \
toolsettings.h toolsettings.h \
variablechooser.h
FORMS += dialogs/newdialog.ui \ FORMS += dialogs/newdialog.ui \
actionmanager/commandmappings.ui \ actionmanager/commandmappings.ui \
...@@ -186,7 +188,8 @@ FORMS += dialogs/newdialog.ui \ ...@@ -186,7 +188,8 @@ FORMS += dialogs/newdialog.ui \
dialogs/openwithdialog.ui \ dialogs/openwithdialog.ui \
editormanager/openeditorsview.ui \ editormanager/openeditorsview.ui \
generalsettings.ui \ generalsettings.ui \
dialogs/externaltoolconfig.ui dialogs/externaltoolconfig.ui \
variablechooser.ui
RESOURCES += core.qrc \ RESOURCES += core.qrc \
fancyactionbar.qrc fancyactionbar.qrc
......
...@@ -86,6 +86,11 @@ ...@@ -86,6 +86,11 @@
enum { debugEditorManager=0 }; 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() static inline ExtensionSystem::PluginManager *pluginManager()
{ {
return ExtensionSystem::PluginManager::instance(); return ExtensionSystem::PluginManager::instance();
...@@ -470,7 +475,16 @@ void EditorManager::init() ...@@ -470,7 +475,16 @@ void EditorManager::init()
m_d->m_openEditorsFactory = new OpenEditorsViewFactory(); m_d->m_openEditorsFactory = new OpenEditorsViewFactory();
pluginManager()->addObject(m_d->m_openEditorsFactory); 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))); this, SLOT(updateVariable(QString)));
} }
...@@ -2008,10 +2022,6 @@ QString EditorManager::windowTitleAddition() const ...@@ -2008,10 +2022,6 @@ QString EditorManager::windowTitleAddition() const
void EditorManager::updateVariable(const QString &variable) 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) if (variable == QLatin1String(kCurrentDocumentFilePath)
|| variable == QLatin1String(kCurrentDocumentPath)) { || variable == QLatin1String(kCurrentDocumentPath)) {
QString value; QString value;
......
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
#include "progressview.h" #include "progressview.h"
#include "shortcutsettings.h" #include "shortcutsettings.h"
#include "vcsmanager.h" #include "vcsmanager.h"
#include "variablechooser.h"
#include "scriptmanager_p.h" #include "scriptmanager_p.h"
#include "settingsdialog.h" #include "settingsdialog.h"
......
/**************************************************************************
**
** 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);
}
}
/**************************************************************************
**
** 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
<?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>
...@@ -63,6 +63,7 @@ class VariableManagerPrivate : public QObject ...@@ -63,6 +63,7 @@ class VariableManagerPrivate : public QObject
public: public:
QHash<QString, QString> m_map; QHash<QString, QString> m_map;
VMMapExpander m_macroExpander; VMMapExpander m_macroExpander;
QMap<QString, QString> m_descriptions;
static VariableManager *m_instance; static VariableManager *m_instance;
}; };
...@@ -113,6 +114,21 @@ VariableManager* VariableManager::instance() ...@@ -113,6 +114,21 @@ VariableManager* VariableManager::instance()
return VariableManagerPrivate::m_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 } // namespace Core
#include "variablemanager.moc" #include "variablemanager.moc"
...@@ -67,6 +67,11 @@ public: ...@@ -67,6 +67,11 @@ public:
QString value(const QString &variable, const QString &defaultValue); QString value(const QString &variable, const QString &defaultValue);
Utils::AbstractMacroExpander *macroExpander(); Utils::AbstractMacroExpander *macroExpander();
void registerVariable(const QString &variable,
const QString &description);
QList<QString> variables() const;
QString variableDescription(const QString &variable) const;
signals: signals:
void variableUpdateRequested(const QString &variable); void variableUpdateRequested(const QString &variable);
......
...@@ -129,6 +129,9 @@ namespace { ...@@ -129,6 +129,9 @@ namespace {
bool debug = false; bool debug = false;
} }
static const char * const kCurrentProjectPath = "CurrentProject:Path";
static const char * const kCurrentProjectFilePath = "CurrentProject:FilePath";
namespace ProjectExplorer { namespace ProjectExplorer {
struct ProjectExplorerPluginPrivate { struct ProjectExplorerPluginPrivate {
...@@ -899,7 +902,12 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er ...@@ -899,7 +902,12 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
updateWelcomePage(); 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))); this, SLOT(updateVariable(QString)));
return true; return true;
...@@ -1001,8 +1009,6 @@ void ProjectExplorerPlugin::loadCustomWizards() ...@@ -1001,8 +1009,6 @@ void ProjectExplorerPlugin::loadCustomWizards()
void ProjectExplorerPlugin::updateVariable(const QString &variable) 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 (variable == QLatin1String(kCurrentProjectFilePath)) {
if (currentProject() && currentProject()->file()) { if (currentProject() && currentProject()->file()) {
Core::VariableManager::instance()->insert(variable, Core::VariableManager::instance()->insert(variable,
......
...@@ -76,6 +76,8 @@ using ProjectExplorer::FormType; ...@@ -76,6 +76,8 @@ using ProjectExplorer::FormType;
using ProjectExplorer::ResourceType; using ProjectExplorer::ResourceType;
using ProjectExplorer::UnknownFileType; using ProjectExplorer::UnknownFileType;
static const char * const kInstallBins = "CurrentProject:QT_INSTALL_BINS";
// Known file types of a Qt 4 project // Known file types of a Qt 4 project
static const char* qt4FileTypes[] = { static const char* qt4FileTypes[] = {
"CppHeaderFiles", "CppHeaderFiles",
...@@ -134,7 +136,10 @@ void Qt4Manager::init() ...@@ -134,7 +136,10 @@ void Qt4Manager::init()
connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)), connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
this, SLOT(editorChanged(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))); this, SLOT(updateVariable(QString)));
} }
...@@ -179,7 +184,6 @@ void Qt4Manager::editorAboutToClose(Core::IEditor *editor) ...@@ -179,7 +184,6 @@ void Qt4Manager::editorAboutToClose(Core::IEditor *editor)
void Qt4Manager::updateVariable(const QString &variable) void Qt4Manager::updateVariable(const QString &variable)
{ {
static const char * const kInstallBins = "QT_INSTALL_BINS";
if (variable == QLatin1String(kInstallBins)) { if (variable == QLatin1String(kInstallBins)) {
Qt4Project *qt4pro = qobject_cast<Qt4Project *>(projectExplorer()->currentProject()); Qt4Project *qt4pro = qobject_cast<Qt4Project *>(projectExplorer()->currentProject());
if (!qt4pro) { if (!qt4pro) {
......
...@@ -68,6 +68,13 @@ ...@@ -68,6 +68,13 @@
using namespace TextEditor; using namespace TextEditor;
using namespace TextEditor::Internal; 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::m_instance = 0;
TextEditorPlugin::TextEditorPlugin() TextEditorPlugin::TextEditorPlugin()
...@@ -177,7 +184,21 @@ void TextEditorPlugin::extensionsInitialized() ...@@ -177,7 +184,21 @@ void TextEditorPlugin::extensionsInitialized()
addAutoReleasedObject(new FindInFiles(Find::SearchResultWindow::instance())); addAutoReleasedObject(new FindInFiles(Find::SearchResultWindow::instance()));
addAutoReleasedObject(new FindInCurrentFile(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))); this, SLOT(updateVariable(QString)));
connect(Core::ExternalToolManager::instance(), SIGNAL(replaceSelectionRequested(QString)), connect(Core::ExternalToolManager::instance(), SIGNAL(replaceSelectionRequested(QString)),
this, SLOT(updateCurrentSelection(QString))); this, SLOT(updateCurrentSelection(QString)));
...@@ -216,12 +237,6 @@ void TextEditorPlugin::updateSearchResultsFont(const FontSettings &settings) ...@@ -216,12 +237,6 @@ void TextEditorPlugin::updateSearchResultsFont(const FontSettings &settings)
void TextEditorPlugin::updateVariable(const QString &variable) 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>() static QSet<QString> variables = QSet<QString>()
<< QString::fromLatin1(kCurrentDocumentSelection) << QString::fromLatin1(kCurrentDocumentSelection)
<< QString::fromLatin1(kCurrentDocumentRow) << QString::fromLatin1(kCurrentDocumentRow)
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
<category xml:lang="de">Linguist</category> <category xml:lang="de">Linguist</category>
<order>2</order> <order>2</order>
<executable> <executable>
<path>%{QT_INSTALL_BINS}/lrelease</path> <path>%{CurrentProject:QT_INSTALL_BINS}/lrelease</path>
<path>lrelease</path> <path>lrelease</path>
<arguments>%{CurrentProject:FilePath}</arguments> <arguments>%{CurrentProject:FilePath}</arguments>
<workingdirectory>%{CurrentProject:Path}</workingdirectory> <workingdirectory>%{CurrentProject:Path}</workingdirectory>
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
<category xml:lang="de">Linguist</category> <category xml:lang="de">Linguist</category>
<order>1</order> <order>1</order>
<executable> <executable>
<path>%{QT_INSTALL_BINS}/lupdate</path> <path>%{CurrentProject:QT_INSTALL_BINS}/lupdate</path>
<path>lupdate</path> <path>lupdate</path>
<arguments>%{CurrentProject:FilePath}</arguments>