forked from qt-creator/qt-creator
The macros plugin use a directory in userResourcePath.
It is not possible to manage different directory for the macro plugin, it uses the user resource path per default. This change cleans a lot of code, specially we don't need any specific settings for the macro plugin, and the option page is more simple. Merge-request: 240 Reviewed-by: con <qtc-committer@nokia.com>
This commit is contained in:
committed by
con
parent
23e024de64
commit
acf607f009
@@ -36,7 +36,6 @@
|
|||||||
#include "macrosconstants.h"
|
#include "macrosconstants.h"
|
||||||
#include "macroevent.h"
|
#include "macroevent.h"
|
||||||
#include "macro.h"
|
#include "macro.h"
|
||||||
#include "macrosettings.h"
|
|
||||||
#include "imacrohandler.h"
|
#include "imacrohandler.h"
|
||||||
#include "savedialog.h"
|
#include "savedialog.h"
|
||||||
#include "actionmacrohandler.h"
|
#include "actionmacrohandler.h"
|
||||||
@@ -63,7 +62,6 @@
|
|||||||
#include <QtCore/QList>
|
#include <QtCore/QList>
|
||||||
|
|
||||||
#include <QtGui/QShortcut>
|
#include <QtGui/QShortcut>
|
||||||
#include <QtGui/QKeySequence>
|
|
||||||
#include <QtGui/QMainWindow>
|
#include <QtGui/QMainWindow>
|
||||||
#include <QtGui/QAction>
|
#include <QtGui/QAction>
|
||||||
#include <QtGui/QFileDialog>
|
#include <QtGui/QFileDialog>
|
||||||
@@ -107,7 +105,6 @@ public:
|
|||||||
MacroManagerPrivate(MacroManager *qq);
|
MacroManagerPrivate(MacroManager *qq);
|
||||||
|
|
||||||
MacroManager *q;
|
MacroManager *q;
|
||||||
MacroSettings settings;
|
|
||||||
QMap<QString, Macro *> macros;
|
QMap<QString, Macro *> macros;
|
||||||
Macro *currentMacro;
|
Macro *currentMacro;
|
||||||
bool isRecording;
|
bool isRecording;
|
||||||
@@ -120,10 +117,8 @@ public:
|
|||||||
TextEditorMacroHandler *textEditorHandler;
|
TextEditorMacroHandler *textEditorHandler;
|
||||||
FindMacroHandler *findHandler;
|
FindMacroHandler *findHandler;
|
||||||
|
|
||||||
void init();
|
void initialize();
|
||||||
void appendDirectory(const QString &directory);
|
void addMacro(Macro *macro);
|
||||||
void removeDirectory(const QString &directory);
|
|
||||||
void addMacro(Macro *macro, QKeySequence ks=QKeySequence());
|
|
||||||
void removeMacro(const QString &name);
|
void removeMacro(const QString &name);
|
||||||
void changeMacroDescription(Macro *macro, const QString &description);
|
void changeMacroDescription(Macro *macro, const QString &description);
|
||||||
|
|
||||||
@@ -137,23 +132,20 @@ MacroManager::MacroManagerPrivate::MacroManagerPrivate(MacroManager *qq):
|
|||||||
isRecording(false),
|
isRecording(false),
|
||||||
mapper(new QSignalMapper(qq))
|
mapper(new QSignalMapper(qq))
|
||||||
{
|
{
|
||||||
settings.fromSettings(Core::ICore::instance()->settings());
|
|
||||||
|
|
||||||
connect(mapper, SIGNAL(mapped(QString)), q, SLOT(executeMacro(QString)));
|
connect(mapper, SIGNAL(mapped(QString)), q, SLOT(executeMacro(QString)));
|
||||||
|
|
||||||
// Load/unload macros
|
// Load existing macros
|
||||||
foreach (const QString &dir, settings.directories)
|
initialize();
|
||||||
appendDirectory(dir);
|
|
||||||
|
|
||||||
actionHandler = new ActionMacroHandler;
|
actionHandler = new ActionMacroHandler;
|
||||||
textEditorHandler = new TextEditorMacroHandler;
|
textEditorHandler = new TextEditorMacroHandler;
|
||||||
findHandler = new FindMacroHandler;
|
findHandler = new FindMacroHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacroManager::MacroManagerPrivate::appendDirectory(const QString &directory)
|
void MacroManager::MacroManagerPrivate::initialize()
|
||||||
{
|
{
|
||||||
macros.clear();
|
macros.clear();
|
||||||
QDir dir(directory);
|
QDir dir(q->macrosDirectory());
|
||||||
QStringList filter;
|
QStringList filter;
|
||||||
filter << QString("*.")+Constants::M_EXTENSION;
|
filter << QString("*.")+Constants::M_EXTENSION;
|
||||||
QStringList files = dir.entryList(filter, QDir::Files);
|
QStringList files = dir.entryList(filter, QDir::Files);
|
||||||
@@ -162,32 +154,11 @@ void MacroManager::MacroManagerPrivate::appendDirectory(const QString &directory
|
|||||||
QString fileName = dir.absolutePath()+"/"+name;
|
QString fileName = dir.absolutePath()+"/"+name;
|
||||||
Macro *macro = new Macro;
|
Macro *macro = new Macro;
|
||||||
macro->loadHeader(fileName);
|
macro->loadHeader(fileName);
|
||||||
|
addMacro(macro);
|
||||||
// Create shortcut
|
|
||||||
QKeySequence ks;
|
|
||||||
if (settings.shortcuts.contains(macro->displayName()))
|
|
||||||
ks.fromString(settings.shortcuts.value(macro->displayName()).toString());
|
|
||||||
|
|
||||||
addMacro(macro, ks);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacroManager::MacroManagerPrivate::removeDirectory(const QString &directory)
|
void MacroManager::MacroManagerPrivate::addMacro(Macro *macro)
|
||||||
{
|
|
||||||
QMapIterator<QString, Macro *> it(macros);
|
|
||||||
QDir dir(directory);
|
|
||||||
QStringList removeList;
|
|
||||||
while (it.hasNext()) {
|
|
||||||
it.next();
|
|
||||||
QFileInfo fileInfo(it.value()->fileName());
|
|
||||||
if (fileInfo.absoluteDir() == dir.absolutePath())
|
|
||||||
removeList.append(it.key());
|
|
||||||
}
|
|
||||||
foreach (const QString &name, removeList)
|
|
||||||
removeMacro(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MacroManager::MacroManagerPrivate::addMacro(Macro *macro, QKeySequence ks)
|
|
||||||
{
|
{
|
||||||
// Add sortcut
|
// Add sortcut
|
||||||
Core::Context context(TextEditor::Constants::C_TEXTEDITOR);
|
Core::Context context(TextEditor::Constants::C_TEXTEDITOR);
|
||||||
@@ -196,9 +167,7 @@ void MacroManager::MacroManagerPrivate::addMacro(Macro *macro, QKeySequence ks)
|
|||||||
QShortcut *shortcut = new QShortcut(core->mainWindow());
|
QShortcut *shortcut = new QShortcut(core->mainWindow());
|
||||||
shortcut->setWhatsThis(macro->description());
|
shortcut->setWhatsThis(macro->description());
|
||||||
const QString macroId = QLatin1String(Constants::PREFIX_MACRO) + macro->displayName();
|
const QString macroId = QLatin1String(Constants::PREFIX_MACRO) + macro->displayName();
|
||||||
Core::Command *command = am->registerShortcut(shortcut, macroId, context);
|
am->registerShortcut(shortcut, macroId, context);
|
||||||
if (!ks.isEmpty())
|
|
||||||
command->setDefaultKeySequence(ks);
|
|
||||||
connect(shortcut, SIGNAL(activated()), mapper, SLOT(map()));
|
connect(shortcut, SIGNAL(activated()), mapper, SLOT(map()));
|
||||||
mapper->setMapping(shortcut, macro->displayName());
|
mapper->setMapping(shortcut, macro->displayName());
|
||||||
|
|
||||||
@@ -274,22 +243,8 @@ void MacroManager::MacroManagerPrivate::showSaveDialog()
|
|||||||
if (dialog.name().isEmpty())
|
if (dialog.name().isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Check if there's a default directory
|
// Save in the resource path
|
||||||
// If not, ask a directory to the user
|
QString fileName = q->macrosDirectory() + '/' + dialog.name()
|
||||||
QString directory = settings.defaultDirectory;
|
|
||||||
QDir dir(directory);
|
|
||||||
if (directory.isEmpty() || !dir.exists()) {
|
|
||||||
directory = QFileDialog::getExistingDirectory(
|
|
||||||
mainWindow,
|
|
||||||
tr("Choose a default macro directory"),
|
|
||||||
QDir::homePath());
|
|
||||||
if (directory.isNull())
|
|
||||||
return;
|
|
||||||
settings.directories.append(directory);
|
|
||||||
settings.defaultDirectory= directory;
|
|
||||||
q->saveSettings();
|
|
||||||
}
|
|
||||||
QString fileName = directory + '/' + dialog.name()
|
|
||||||
+ '.' + Constants::M_EXTENSION;
|
+ '.' + Constants::M_EXTENSION;
|
||||||
currentMacro->setDescription(dialog.description());
|
currentMacro->setDescription(dialog.description());
|
||||||
currentMacro->save(fileName);
|
currentMacro->save(fileName);
|
||||||
@@ -324,11 +279,6 @@ MacroManager::~MacroManager()
|
|||||||
delete d;
|
delete d;
|
||||||
}
|
}
|
||||||
|
|
||||||
const MacroSettings &MacroManager::settings() const
|
|
||||||
{
|
|
||||||
return d->settings;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MacroManager::startMacro()
|
void MacroManager::startMacro()
|
||||||
{
|
{
|
||||||
d->isRecording = true;
|
d->isRecording = true;
|
||||||
@@ -397,30 +347,12 @@ bool MacroManager::executeMacro(const QString &name)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacroManager::appendDirectory(const QString &directory)
|
|
||||||
{
|
|
||||||
d->appendDirectory(directory);
|
|
||||||
d->settings.directories.append(directory);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MacroManager::removeDirectory(const QString &directory)
|
|
||||||
{
|
|
||||||
d->removeDirectory(directory);
|
|
||||||
d->settings.directories.removeAll(directory);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MacroManager::setDefaultDirectory(const QString &directory)
|
|
||||||
{
|
|
||||||
d->settings.defaultDirectory = directory;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MacroManager::deleteMacro(const QString &name)
|
void MacroManager::deleteMacro(const QString &name)
|
||||||
{
|
{
|
||||||
Macro *macro = d->macros.value(name);
|
Macro *macro = d->macros.value(name);
|
||||||
if (macro) {
|
if (macro) {
|
||||||
QString fileName = macro->fileName();
|
QString fileName = macro->fileName();
|
||||||
d->removeMacro(name);
|
d->removeMacro(name);
|
||||||
d->settings.shortcuts.remove(name);
|
|
||||||
QFile::remove(fileName);
|
QFile::remove(fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -430,11 +362,6 @@ const QMap<QString,Macro*> &MacroManager::macros() const
|
|||||||
return d->macros;
|
return d->macros;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacroManager::saveSettings()
|
|
||||||
{
|
|
||||||
d->settings.toSettings(Core::ICore::instance()->settings());
|
|
||||||
}
|
|
||||||
|
|
||||||
void MacroManager::registerMacroHandler(IMacroHandler *handler)
|
void MacroManager::registerMacroHandler(IMacroHandler *handler)
|
||||||
{
|
{
|
||||||
d->handlers.prepend(handler);
|
d->handlers.prepend(handler);
|
||||||
@@ -461,3 +388,12 @@ void Macros::MacroManager::saveLastMacro()
|
|||||||
if (d->currentMacro->events().count())
|
if (d->currentMacro->events().count())
|
||||||
d->showSaveDialog();
|
d->showSaveDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Macros::MacroManager::macrosDirectory() const
|
||||||
|
{
|
||||||
|
const QString &path =
|
||||||
|
Core::ICore::instance()->userResourcePath() + QLatin1String("/macros");
|
||||||
|
if (QFile::exists(path) || QDir().mkpath(path))
|
||||||
|
return path;
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ class Macro;
|
|||||||
class IMacroHandler;
|
class IMacroHandler;
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
class MacroSettings;
|
|
||||||
class MacroOptionsWidget;
|
class MacroOptionsWidget;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,11 +61,12 @@ public:
|
|||||||
|
|
||||||
static MacroManager *instance();
|
static MacroManager *instance();
|
||||||
|
|
||||||
const Internal::MacroSettings &settings() const;
|
|
||||||
const QMap<QString, Macro *> ¯os() const;
|
const QMap<QString, Macro *> ¯os() const;
|
||||||
|
|
||||||
void registerMacroHandler(IMacroHandler *handler);
|
void registerMacroHandler(IMacroHandler *handler);
|
||||||
|
|
||||||
|
QString macrosDirectory() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void startMacro();
|
void startMacro();
|
||||||
void endMacro();
|
void endMacro();
|
||||||
@@ -79,10 +79,6 @@ protected:
|
|||||||
|
|
||||||
void deleteMacro(const QString &name);
|
void deleteMacro(const QString &name);
|
||||||
void changeMacro(const QString &name, const QString &description);
|
void changeMacro(const QString &name, const QString &description);
|
||||||
void appendDirectory(const QString &directory);
|
|
||||||
void removeDirectory(const QString &directory);
|
|
||||||
void setDefaultDirectory(const QString &directory);
|
|
||||||
void saveSettings();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static MacroManager *m_instance;
|
static MacroManager *m_instance;
|
||||||
|
|||||||
@@ -85,7 +85,6 @@ QIcon MacroOptionsPage::categoryIcon() const
|
|||||||
QWidget *MacroOptionsPage::createPage(QWidget *parent)
|
QWidget *MacroOptionsPage::createPage(QWidget *parent)
|
||||||
{
|
{
|
||||||
m_widget = new MacroOptionsWidget(parent);
|
m_widget = new MacroOptionsWidget(parent);
|
||||||
m_widget->setSettings(MacroManager::instance()->settings());
|
|
||||||
return m_widget;
|
return m_widget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,13 +33,13 @@
|
|||||||
|
|
||||||
#include "macrooptionswidget.h"
|
#include "macrooptionswidget.h"
|
||||||
#include "ui_macrooptionswidget.h"
|
#include "ui_macrooptionswidget.h"
|
||||||
#include "macrosettings.h"
|
|
||||||
#include "macrosconstants.h"
|
#include "macrosconstants.h"
|
||||||
#include "macromanager.h"
|
#include "macromanager.h"
|
||||||
#include "macro.h"
|
#include "macro.h"
|
||||||
#include "macrosconstants.h"
|
#include "macrosconstants.h"
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
#include <coreplugin/coreconstants.h>
|
||||||
#include <coreplugin/actionmanager/actionmanager.h>
|
#include <coreplugin/actionmanager/actionmanager.h>
|
||||||
#include <coreplugin/actionmanager/command.h>
|
#include <coreplugin/actionmanager/command.h>
|
||||||
#include <coreplugin/uniqueidmanager.h>
|
#include <coreplugin/uniqueidmanager.h>
|
||||||
@@ -58,13 +58,8 @@
|
|||||||
#include <QtGui/QLineEdit>
|
#include <QtGui/QLineEdit>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
int DIRECTORY = 1;
|
|
||||||
int MACRO = 2;
|
|
||||||
|
|
||||||
int DEFAULT_ROLE = Qt::UserRole;
|
|
||||||
int NAME_ROLE = Qt::UserRole;
|
int NAME_ROLE = Qt::UserRole;
|
||||||
int WRITE_ROLE = Qt::UserRole+1;
|
int WRITE_ROLE = Qt::UserRole+1;
|
||||||
int ID_ROLE = Qt::UserRole+2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
using namespace Macros;
|
using namespace Macros;
|
||||||
@@ -73,53 +68,42 @@ using namespace Macros::Internal;
|
|||||||
|
|
||||||
MacroOptionsWidget::MacroOptionsWidget(QWidget *parent) :
|
MacroOptionsWidget::MacroOptionsWidget(QWidget *parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
ui(new Ui::MacroOptionsWidget),
|
m_ui(new Ui::MacroOptionsWidget),
|
||||||
changingCurrent(false)
|
m_changingCurrent(false)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
m_ui->setupUi(this);
|
||||||
|
m_ui->removeButton->setIcon(QIcon(Core::Constants::ICON_MINUS));
|
||||||
|
|
||||||
connect(ui->treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
|
connect(m_ui->treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
|
||||||
this, SLOT(changeCurrentItem(QTreeWidgetItem*)));
|
this, SLOT(changeCurrentItem(QTreeWidgetItem*)));
|
||||||
connect(ui->removeButton, SIGNAL(clicked()),
|
connect(m_ui->removeButton, SIGNAL(clicked()),
|
||||||
this, SLOT(remove()));
|
this, SLOT(remove()));
|
||||||
connect(ui->defaultButton, SIGNAL(clicked()),
|
connect(m_ui->description, SIGNAL(textChanged(QString)),
|
||||||
this, SLOT(setDefault()));
|
|
||||||
connect(ui->addButton, SIGNAL(clicked()),
|
|
||||||
this, SLOT(addDirectoy()));
|
|
||||||
connect(ui->description, SIGNAL(textChanged(QString)),
|
|
||||||
this, SLOT(changeDescription(QString)));
|
this, SLOT(changeDescription(QString)));
|
||||||
|
|
||||||
ui->treeWidget->header()->setSortIndicator(0, Qt::AscendingOrder);
|
m_ui->treeWidget->header()->setSortIndicator(0, Qt::AscendingOrder);
|
||||||
|
|
||||||
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
MacroOptionsWidget::~MacroOptionsWidget()
|
MacroOptionsWidget::~MacroOptionsWidget()
|
||||||
{
|
{
|
||||||
delete ui;
|
delete m_ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacroOptionsWidget::setSettings(const MacroSettings &s)
|
void MacroOptionsWidget::initialize()
|
||||||
{
|
{
|
||||||
m_macroToRemove.clear();
|
m_macroToRemove.clear();
|
||||||
m_macroToChange.clear();
|
m_macroToChange.clear();
|
||||||
m_directories.clear();
|
m_ui->treeWidget->clear();
|
||||||
ui->treeWidget->clear();
|
|
||||||
|
|
||||||
// Create the treeview
|
// Create the treeview
|
||||||
foreach (const QString &dir, s.directories)
|
createTable();
|
||||||
appendDirectory(dir, s.defaultDirectory==dir);
|
|
||||||
m_directories = s.directories;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacroOptionsWidget::appendDirectory(const QString &directory, bool isDefault)
|
void MacroOptionsWidget::createTable()
|
||||||
{
|
{
|
||||||
QDir dir(directory);
|
QDir dir(MacroManager::instance()->macrosDirectory());
|
||||||
QTreeWidgetItem *dirItem = new QTreeWidgetItem(ui->treeWidget, DIRECTORY);
|
|
||||||
dirItem->setText(0, dir.absolutePath());
|
|
||||||
dirItem->setData(0, DEFAULT_ROLE, isDefault);
|
|
||||||
dirItem->setFirstColumnSpanned(true);
|
|
||||||
if (isDefault)
|
|
||||||
dirItem->setIcon(0, QPixmap(":/extensionsystem/images/ok.png"));
|
|
||||||
|
|
||||||
Core::ICore *core = Core::ICore::instance();
|
Core::ICore *core = Core::ICore::instance();
|
||||||
Core::ActionManager *am = core->actionManager();
|
Core::ActionManager *am = core->actionManager();
|
||||||
|
|
||||||
@@ -128,7 +112,7 @@ void MacroOptionsWidget::appendDirectory(const QString &directory, bool isDefaul
|
|||||||
it.next();
|
it.next();
|
||||||
QFileInfo fileInfo(it.value()->fileName());
|
QFileInfo fileInfo(it.value()->fileName());
|
||||||
if (fileInfo.absoluteDir() == dir.absolutePath()) {
|
if (fileInfo.absoluteDir() == dir.absolutePath()) {
|
||||||
QTreeWidgetItem *macroItem = new QTreeWidgetItem(dirItem, MACRO);
|
QTreeWidgetItem *macroItem = new QTreeWidgetItem(m_ui->treeWidget);
|
||||||
macroItem->setText(0, it.value()->displayName());
|
macroItem->setText(0, it.value()->displayName());
|
||||||
macroItem->setText(1, it.value()->description());
|
macroItem->setText(1, it.value()->description());
|
||||||
macroItem->setData(0, NAME_ROLE, it.value()->displayName());
|
macroItem->setData(0, NAME_ROLE, it.value()->displayName());
|
||||||
@@ -141,122 +125,58 @@ void MacroOptionsWidget::appendDirectory(const QString &directory, bool isDefaul
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacroOptionsWidget::addDirectoy()
|
|
||||||
{
|
|
||||||
QString directory = ui->directoryPathChooser->path();
|
|
||||||
appendDirectory(directory, ui->treeWidget->children().count()==0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MacroOptionsWidget::changeCurrentItem(QTreeWidgetItem *current)
|
void MacroOptionsWidget::changeCurrentItem(QTreeWidgetItem *current)
|
||||||
{
|
{
|
||||||
changingCurrent = true;
|
m_changingCurrent = true;
|
||||||
if (!current) {
|
if (!current) {
|
||||||
ui->removeButton->setEnabled(false);
|
m_ui->removeButton->setEnabled(false);
|
||||||
ui->defaultButton->setEnabled(false);
|
m_ui->description->clear();
|
||||||
ui->description->clear();
|
m_ui->macroGroup->setEnabled(false);
|
||||||
ui->macroGroup->setEnabled(false);
|
|
||||||
}
|
|
||||||
else if (current->type() == DIRECTORY) {
|
|
||||||
bool isDefault = current->data(0, DEFAULT_ROLE).toBool();
|
|
||||||
ui->removeButton->setEnabled(!isDefault);
|
|
||||||
ui->defaultButton->setEnabled(!isDefault);
|
|
||||||
ui->description->clear();
|
|
||||||
ui->macroGroup->setEnabled(false);
|
|
||||||
} else {
|
} else {
|
||||||
ui->removeButton->setEnabled(true);
|
m_ui->removeButton->setEnabled(true);
|
||||||
ui->defaultButton->setEnabled(false);
|
m_ui->description->setText(current->text(1));
|
||||||
ui->description->setText(current->text(1));
|
m_ui->description->setEnabled(current->data(0, WRITE_ROLE).toBool());
|
||||||
ui->description->setEnabled(current->data(0, WRITE_ROLE).toBool());
|
m_ui->macroGroup->setEnabled(true);
|
||||||
ui->macroGroup->setEnabled(true);
|
|
||||||
}
|
}
|
||||||
changingCurrent = false;
|
m_changingCurrent = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacroOptionsWidget::remove()
|
void MacroOptionsWidget::remove()
|
||||||
{
|
{
|
||||||
QTreeWidgetItem *current = ui->treeWidget->currentItem();
|
QTreeWidgetItem *current = m_ui->treeWidget->currentItem();
|
||||||
if (current->type() == MACRO)
|
m_macroToRemove.append(current->data(0, NAME_ROLE).toString());
|
||||||
m_macroToRemove.append(current->text(0));
|
|
||||||
delete current;
|
delete current;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacroOptionsWidget::setDefault()
|
|
||||||
{
|
|
||||||
QTreeWidgetItem *current = ui->treeWidget->currentItem();
|
|
||||||
if (!current || current->type() != DIRECTORY)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (int i = 0; i < ui->treeWidget->topLevelItemCount(); ++i) {
|
|
||||||
QTreeWidgetItem *item = ui->treeWidget->topLevelItem(i);
|
|
||||||
if (item->data(0, DEFAULT_ROLE).toBool()) {
|
|
||||||
item->setIcon(0, QPixmap());
|
|
||||||
item->setData(0, DEFAULT_ROLE, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
current->setData(0, DEFAULT_ROLE, true);
|
|
||||||
current->setIcon(0, QPixmap(":/extensionsystem/images/ok.png"));
|
|
||||||
}
|
|
||||||
|
|
||||||
void MacroOptionsWidget::apply()
|
void MacroOptionsWidget::apply()
|
||||||
{
|
{
|
||||||
// Remove macro
|
// Remove macro
|
||||||
foreach (const QString &name, m_macroToRemove)
|
foreach (const QString &name, m_macroToRemove) {
|
||||||
MacroManager::instance()->deleteMacro(name);
|
MacroManager::instance()->deleteMacro(name);
|
||||||
|
m_macroToChange.remove(name);
|
||||||
|
}
|
||||||
|
|
||||||
// Change macro
|
// Change macro
|
||||||
QMapIterator<QString, ChangeSet> it(m_macroToChange);
|
QMapIterator<QString, QString> it(m_macroToChange);
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
it.next();
|
it.next();
|
||||||
MacroManager::instance()->changeMacro(it.key(), it.value().description);
|
MacroManager::instance()->changeMacro(it.key(), it.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get list of dir to append or remove
|
|
||||||
QStringList dirToAppend;
|
|
||||||
QStringList dirToRemove = m_directories;
|
|
||||||
for (int i = 0; i < ui->treeWidget->topLevelItemCount(); ++i) {
|
|
||||||
QTreeWidgetItem *item = ui->treeWidget->topLevelItem(i);
|
|
||||||
if (!m_directories.contains(item->text(0)))
|
|
||||||
dirToAppend.append(item->text(0));
|
|
||||||
dirToRemove.removeAll(item->text(0));
|
|
||||||
if (item->data(0, DEFAULT_ROLE).toBool())
|
|
||||||
MacroManager::instance()->setDefaultDirectory(item->text(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Append/remove directory
|
|
||||||
foreach (const QString &dir, dirToAppend)
|
|
||||||
MacroManager::instance()->appendDirectory(dir);
|
|
||||||
foreach (const QString &dir, dirToRemove)
|
|
||||||
MacroManager::instance()->removeDirectory(dir);
|
|
||||||
|
|
||||||
MacroManager::instance()->saveSettings();
|
|
||||||
|
|
||||||
// Reinitialize the page
|
// Reinitialize the page
|
||||||
setSettings(MacroManager::instance()->settings());
|
initialize();
|
||||||
}
|
|
||||||
|
|
||||||
void MacroOptionsWidget::changeData(QTreeWidgetItem *current, int column, QVariant value)
|
|
||||||
{
|
|
||||||
QString macroName = current->data(0, NAME_ROLE).toString();
|
|
||||||
if (!m_macroToChange.contains(macroName)) {
|
|
||||||
m_macroToChange[macroName].description = current->text(1);
|
|
||||||
m_macroToChange[macroName].shortcut = (current->data(0, ID_ROLE).toInt() >= 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Change the description
|
|
||||||
if (column == 1) {
|
|
||||||
m_macroToChange[macroName].description = value.toString();
|
|
||||||
current->setText(1, value.toString());
|
|
||||||
QFont font = current->font(1);
|
|
||||||
font.setItalic(true);
|
|
||||||
current->setFont(1, font);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacroOptionsWidget::changeDescription(const QString &description)
|
void MacroOptionsWidget::changeDescription(const QString &description)
|
||||||
{
|
{
|
||||||
QTreeWidgetItem *current = ui->treeWidget->currentItem();
|
QTreeWidgetItem *current = m_ui->treeWidget->currentItem();
|
||||||
if (changingCurrent || !current || current->type() == DIRECTORY)
|
if (m_changingCurrent || !current)
|
||||||
return;
|
return;
|
||||||
changeData(current, 1, description);
|
|
||||||
|
QString macroName = current->data(0, NAME_ROLE).toString();
|
||||||
|
m_macroToChange[macroName] = description;
|
||||||
|
current->setText(1, description);
|
||||||
|
QFont font = current->font(1);
|
||||||
|
font.setItalic(true);
|
||||||
|
current->setFont(1, font);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,34 +59,26 @@ public:
|
|||||||
explicit MacroOptionsWidget(QWidget *parent = 0);
|
explicit MacroOptionsWidget(QWidget *parent = 0);
|
||||||
~MacroOptionsWidget();
|
~MacroOptionsWidget();
|
||||||
|
|
||||||
void setSettings(const MacroSettings &s);
|
void initialize();
|
||||||
|
|
||||||
void apply();
|
void apply();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void addDirectoy();
|
|
||||||
void remove();
|
void remove();
|
||||||
void setDefault();
|
|
||||||
void changeCurrentItem(QTreeWidgetItem *current);
|
void changeCurrentItem(QTreeWidgetItem *current);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void appendDirectory(const QString &directory, bool isDefault = false);
|
void createTable();
|
||||||
void changeData(QTreeWidgetItem *current, int column, QVariant value);
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void changeDescription(const QString &description);
|
void changeDescription(const QString &description);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MacroOptionsWidget *ui;
|
Ui::MacroOptionsWidget *m_ui;
|
||||||
QStringList m_macroToRemove;
|
QStringList m_macroToRemove;
|
||||||
QStringList m_directories;
|
bool m_changingCurrent;
|
||||||
bool changingCurrent;
|
|
||||||
|
|
||||||
struct ChangeSet {
|
QMap<QString, QString> m_macroToChange;
|
||||||
QString description;
|
|
||||||
bool shortcut;
|
|
||||||
};
|
|
||||||
QMap<QString, ChangeSet> m_macroToChange;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -20,37 +20,7 @@
|
|||||||
<string>Preferences</string>
|
<string>Preferences</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="0" column="0">
|
<item row="0" column="0" rowspan="2">
|
||||||
<widget class="QLabel" name="label_2">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Directory:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1">
|
|
||||||
<widget class="Utils::PathChooser" name="directoryPathChooser" native="true">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="2">
|
|
||||||
<widget class="QPushButton" name="addButton">
|
|
||||||
<property name="text">
|
|
||||||
<string>Add</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0" colspan="3">
|
|
||||||
<widget class="QTreeWidget" name="treeWidget">
|
<widget class="QTreeWidget" name="treeWidget">
|
||||||
<property name="textElideMode">
|
<property name="textElideMode">
|
||||||
<enum>Qt::ElideLeft</enum>
|
<enum>Qt::ElideLeft</enum>
|
||||||
@@ -87,33 +57,35 @@
|
|||||||
</column>
|
</column>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0">
|
<item row="0" column="1">
|
||||||
<widget class="QPushButton" name="defaultButton">
|
<widget class="QToolButton" name="removeButton">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>21</width>
|
||||||
|
<height>23</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Default Directory</string>
|
<string>-</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
<item row="1" column="1">
|
||||||
<spacer name="horizontalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" stdset="0">
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
<width>213</width>
|
<width>20</width>
|
||||||
<height>20</height>
|
<height>40</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="2">
|
|
||||||
<widget class="QPushButton" name="removeButton">
|
|
||||||
<property name="text">
|
|
||||||
<string>Remove</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@@ -141,14 +113,6 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
|
||||||
<customwidget>
|
|
||||||
<class>Utils::PathChooser</class>
|
|
||||||
<extends>QWidget</extends>
|
|
||||||
<header location="global">utils/pathchooser.h</header>
|
|
||||||
<container>1</container>
|
|
||||||
</customwidget>
|
|
||||||
</customwidgets>
|
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ include(macros_dependencies.pri)
|
|||||||
HEADERS += macrosplugin.h \
|
HEADERS += macrosplugin.h \
|
||||||
macros_global.h \
|
macros_global.h \
|
||||||
macrosconstants.h \
|
macrosconstants.h \
|
||||||
macrosettings.h \
|
|
||||||
macro.h \
|
macro.h \
|
||||||
macroevent.h \
|
macroevent.h \
|
||||||
macromanager.h \
|
macromanager.h \
|
||||||
@@ -24,7 +23,6 @@ HEADERS += macrosplugin.h \
|
|||||||
imacrohandler.h
|
imacrohandler.h
|
||||||
|
|
||||||
SOURCES += macrosplugin.cpp \
|
SOURCES += macrosplugin.cpp \
|
||||||
macrosettings.cpp \
|
|
||||||
macro.cpp \
|
macro.cpp \
|
||||||
macroevent.cpp \
|
macroevent.cpp \
|
||||||
macromanager.cpp \
|
macromanager.cpp \
|
||||||
|
|||||||
@@ -1,73 +0,0 @@
|
|||||||
/**************************************************************************
|
|
||||||
**
|
|
||||||
** This file is part of Qt Creator
|
|
||||||
**
|
|
||||||
** Copyright (c) 2010 Nicolas Arnaud-Cormos.
|
|
||||||
**
|
|
||||||
** 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 "macrosettings.h"
|
|
||||||
|
|
||||||
#include <QtCore/QSettings>
|
|
||||||
|
|
||||||
using namespace Macros::Internal;
|
|
||||||
|
|
||||||
static const char GROUP[] = "Macro";
|
|
||||||
static const char DEFAULT_DIRECTORY[] = "DefaultDirectory";
|
|
||||||
static const char DIRECTORIES[] = "Directories";
|
|
||||||
static const char SHORTCUTS[] = "Shortcuts";
|
|
||||||
|
|
||||||
|
|
||||||
MacroSettings::MacroSettings()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void MacroSettings::toSettings(QSettings *s) const
|
|
||||||
{
|
|
||||||
s->beginGroup(QLatin1String(GROUP));
|
|
||||||
s->setValue(QLatin1String(DEFAULT_DIRECTORY), defaultDirectory);
|
|
||||||
s->setValue(QLatin1String(DIRECTORIES), directories);
|
|
||||||
s->setValue(QLatin1String(SHORTCUTS), shortcuts);
|
|
||||||
s->endGroup();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MacroSettings::fromSettings(QSettings *s)
|
|
||||||
{
|
|
||||||
s->beginGroup(QLatin1String(GROUP));
|
|
||||||
defaultDirectory = s->value(QLatin1String(DEFAULT_DIRECTORY), QString("")).toString();
|
|
||||||
directories = s->value(QLatin1String(DIRECTORIES)).toStringList();
|
|
||||||
shortcuts = s->value(QLatin1String(SHORTCUTS)).toMap();
|
|
||||||
s->endGroup();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MacroSettings::equals(const MacroSettings &ms) const
|
|
||||||
{
|
|
||||||
return defaultDirectory == ms.defaultDirectory &&
|
|
||||||
shortcuts == ms.shortcuts &&
|
|
||||||
directories == ms.directories;
|
|
||||||
}
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
/**************************************************************************
|
|
||||||
**
|
|
||||||
** This file is part of Qt Creator
|
|
||||||
**
|
|
||||||
** Copyright (c) 2010 Nicolas Arnaud-Cormos.
|
|
||||||
**
|
|
||||||
** 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 MACROSPLUGIN_MACROSETTINGS_H
|
|
||||||
#define MACROSPLUGIN_MACROSETTINGS_H
|
|
||||||
|
|
||||||
#include <QtCore/QStringList>
|
|
||||||
#include <QtCore/QMap>
|
|
||||||
#include <QtCore/QVariant>
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
class QSettings;
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
namespace Macros {
|
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
class MacroSettings
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
MacroSettings();
|
|
||||||
|
|
||||||
void toSettings(QSettings *s) const;
|
|
||||||
void fromSettings(QSettings *s);
|
|
||||||
|
|
||||||
bool equals(const MacroSettings &ms) const;
|
|
||||||
|
|
||||||
QString defaultDirectory;
|
|
||||||
QStringList directories;
|
|
||||||
QMap<QString, QVariant> shortcuts;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline bool operator==(const MacroSettings &m1, const MacroSettings &m2) { return m1.equals(m2); }
|
|
||||||
inline bool operator!=(const MacroSettings &m1, const MacroSettings &m2) { return !m1.equals(m2); }
|
|
||||||
|
|
||||||
} // namespace Internal
|
|
||||||
} // namespace Macros
|
|
||||||
|
|
||||||
#endif // MACROSPLUGIN_MACROSETTINGS_H
|
|
||||||
Reference in New Issue
Block a user