forked from qt-creator/qt-creator
Core: Use the new Id methods in a few places
There are a lot more left. Change-Id: I97d32629aa6deef0f4819f70cc0b8437f2814257 Reviewed-by: Christian Kandeler <christian.kandeler@digia.com>
This commit is contained in:
@@ -307,9 +307,8 @@ Command *ActionContainerPrivate::addSeparator(const Context &context, const Id &
|
|||||||
static int separatorIdCount = 0;
|
static int separatorIdCount = 0;
|
||||||
QAction *separator = new QAction(this);
|
QAction *separator = new QAction(this);
|
||||||
separator->setSeparator(true);
|
separator->setSeparator(true);
|
||||||
Command *cmd = ActionManager::registerAction(separator, Id(QString::fromLatin1("%1.Separator.%2")
|
Id sepId = id().withSuffix(".Separator.").withSuffix(++separatorIdCount);
|
||||||
.arg(id().toString()).arg(++separatorIdCount)),
|
Command *cmd = ActionManager::registerAction(separator, sepId, context);
|
||||||
context);
|
|
||||||
addAction(cmd, group);
|
addAction(cmd, group);
|
||||||
if (outSeparator)
|
if (outSeparator)
|
||||||
*outSeparator = separator;
|
*outSeparator = separator;
|
||||||
|
@@ -566,7 +566,7 @@ void ActionManagerPrivate::initialize()
|
|||||||
for (int i = 0; i < shortcuts; ++i) {
|
for (int i = 0; i < shortcuts; ++i) {
|
||||||
settings->setArrayIndex(i);
|
settings->setArrayIndex(i);
|
||||||
const QKeySequence key(settings->value(QLatin1String(sequenceKey)).toString());
|
const QKeySequence key(settings->value(QLatin1String(sequenceKey)).toString());
|
||||||
const Id id = Id(settings->value(QLatin1String(idKey)).toString());
|
const Id id = Id::fromSetting(settings->value(QLatin1String(idKey)));
|
||||||
|
|
||||||
Command *cmd = ActionManager::command(id);
|
Command *cmd = ActionManager::command(id);
|
||||||
if (cmd)
|
if (cmd)
|
||||||
|
@@ -334,7 +334,7 @@ void SettingsDialog::showPage(Id categoryId, Id pageId)
|
|||||||
QString initialPage = pageId.toString();
|
QString initialPage = pageId.toString();
|
||||||
if (!initialCategory.isValid() && initialPage.isEmpty()) {
|
if (!initialCategory.isValid() && initialPage.isEmpty()) {
|
||||||
QSettings *settings = ICore::settings();
|
QSettings *settings = ICore::settings();
|
||||||
initialCategory = Id(settings->value(QLatin1String(categoryKeyC), QVariant(QString())).toString());
|
initialCategory = Id::fromSetting(settings->value(QLatin1String(categoryKeyC)));
|
||||||
initialPage = settings->value(QLatin1String(pageKeyC), QVariant(QString())).toString();
|
initialPage = settings->value(QLatin1String(pageKeyC), QVariant(QString())).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1183,7 +1183,7 @@ void readSettings()
|
|||||||
editorId = ids.next();
|
editorId = ids.next();
|
||||||
if (QFileInfo(fileName).isFile())
|
if (QFileInfo(fileName).isFile())
|
||||||
d->m_recentFiles.append(DocumentManager::RecentFile(QDir::fromNativeSeparators(fileName), // from native to guard against old settings
|
d->m_recentFiles.append(DocumentManager::RecentFile(QDir::fromNativeSeparators(fileName), // from native to guard against old settings
|
||||||
Id(editorId)));
|
Id::fromString(editorId)));
|
||||||
}
|
}
|
||||||
|
|
||||||
s->beginGroup(QLatin1String(directoryGroupC));
|
s->beginGroup(QLatin1String(directoryGroupC));
|
||||||
|
@@ -1232,14 +1232,14 @@ Core::Id EditorManager::getOpenWithEditorId(const QString &fileName,
|
|||||||
//Unable to determine mime type of fileName. Falling back to text/plain",
|
//Unable to determine mime type of fileName. Falling back to text/plain",
|
||||||
if (!mt)
|
if (!mt)
|
||||||
mt = ICore::mimeDatabase()->findByType(QLatin1String("text/plain"));
|
mt = ICore::mimeDatabase()->findByType(QLatin1String("text/plain"));
|
||||||
QStringList allEditorIds;
|
QList<Id> allEditorIds;
|
||||||
QStringList allEditorDisplayNames;
|
QStringList allEditorDisplayNames;
|
||||||
QList<Id> externalEditorIds;
|
QList<Id> externalEditorIds;
|
||||||
// Built-in
|
// Built-in
|
||||||
const EditorFactoryList editors = editorFactories(mt, false);
|
const EditorFactoryList editors = editorFactories(mt, false);
|
||||||
const int size = editors.size();
|
const int size = editors.size();
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
allEditorIds.push_back(editors.at(i)->id().toString());
|
allEditorIds.push_back(editors.at(i)->id());
|
||||||
allEditorDisplayNames.push_back(editors.at(i)->displayName());
|
allEditorDisplayNames.push_back(editors.at(i)->displayName());
|
||||||
}
|
}
|
||||||
// External editors
|
// External editors
|
||||||
@@ -1247,7 +1247,7 @@ Core::Id EditorManager::getOpenWithEditorId(const QString &fileName,
|
|||||||
const int esize = exEditors.size();
|
const int esize = exEditors.size();
|
||||||
for (int i = 0; i < esize; i++) {
|
for (int i = 0; i < esize; i++) {
|
||||||
externalEditorIds.push_back(exEditors.at(i)->id());
|
externalEditorIds.push_back(exEditors.at(i)->id());
|
||||||
allEditorIds.push_back(exEditors.at(i)->id().toString());
|
allEditorIds.push_back(exEditors.at(i)->id());
|
||||||
allEditorDisplayNames.push_back(exEditors.at(i)->displayName());
|
allEditorDisplayNames.push_back(exEditors.at(i)->displayName());
|
||||||
}
|
}
|
||||||
if (allEditorIds.empty())
|
if (allEditorIds.empty())
|
||||||
@@ -1259,7 +1259,7 @@ Core::Id EditorManager::getOpenWithEditorId(const QString &fileName,
|
|||||||
dialog.setCurrentEditor(0);
|
dialog.setCurrentEditor(0);
|
||||||
if (dialog.exec() != QDialog::Accepted)
|
if (dialog.exec() != QDialog::Accepted)
|
||||||
return Id();
|
return Id();
|
||||||
const Id selectedId = Id(allEditorIds.at(dialog.editor()));
|
const Id selectedId = allEditorIds.at(dialog.editor());
|
||||||
if (isExternalEditor)
|
if (isExternalEditor)
|
||||||
*isExternalEditor = externalEditorIds.contains(selectedId);
|
*isExternalEditor = externalEditorIds.contains(selectedId);
|
||||||
return selectedId;
|
return selectedId;
|
||||||
@@ -2019,9 +2019,9 @@ bool EditorManager::restoreState(const QByteArray &state)
|
|||||||
continue;
|
continue;
|
||||||
QFileInfo rfi(autoSaveName(fileName));
|
QFileInfo rfi(autoSaveName(fileName));
|
||||||
if (rfi.exists() && fi.lastModified() < rfi.lastModified())
|
if (rfi.exists() && fi.lastModified() < rfi.lastModified())
|
||||||
openEditor(fileName, Id(QString::fromUtf8(id)));
|
openEditor(fileName, Id::fromName(id));
|
||||||
else
|
else
|
||||||
d->m_editorModel->addRestoredEditor(fileName, displayName, Id(QString::fromUtf8(id)));
|
d->m_editorModel->addRestoredEditor(fileName, displayName, Id::fromName(id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -28,14 +28,3 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "icontext.h"
|
#include "icontext.h"
|
||||||
|
|
||||||
#include <QString>
|
|
||||||
|
|
||||||
namespace Core {
|
|
||||||
|
|
||||||
Context::Context(const char *id, int offset)
|
|
||||||
{
|
|
||||||
d.append(Id(QLatin1String(id) + QString::number(offset)).uniqueIdentifier());
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Core
|
|
||||||
|
@@ -48,7 +48,6 @@ public:
|
|||||||
explicit Context(Id c1) { add(c1); }
|
explicit Context(Id c1) { add(c1); }
|
||||||
Context(Id c1, Id c2) { add(c1); add(c2); }
|
Context(Id c1, Id c2) { add(c1); add(c2); }
|
||||||
Context(Id c1, Id c2, Id c3) { add(c1); add(c2); add(c3); }
|
Context(Id c1, Id c2, Id c3) { add(c1); add(c2); add(c3); }
|
||||||
Context(const char *base, int offset);
|
|
||||||
bool contains(Id c) const { return d.contains(c); }
|
bool contains(Id c) const { return d.contains(c); }
|
||||||
int size() const { return d.size(); }
|
int size() const { return d.size(); }
|
||||||
bool isEmpty() const { return d.isEmpty(); }
|
bool isEmpty() const { return d.isEmpty(); }
|
||||||
|
@@ -207,6 +207,8 @@ QString Id::toString() const
|
|||||||
This should not be used to handle a persistent version
|
This should not be used to handle a persistent version
|
||||||
of the Id, use \c{fromSetting()} instead.
|
of the Id, use \c{fromSetting()} instead.
|
||||||
|
|
||||||
|
\deprecated
|
||||||
|
|
||||||
\sa toString(), fromSetting()
|
\sa toString(), fromSetting()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -215,6 +217,22 @@ Id Id::fromString(const QString &name)
|
|||||||
return Id(theId(name.toUtf8()));
|
return Id(theId(name.toUtf8()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Creates an id from a string representation.
|
||||||
|
|
||||||
|
This should not be used to handle a persistent version
|
||||||
|
of the Id, use \c{fromSetting()} instead.
|
||||||
|
|
||||||
|
\deprecated
|
||||||
|
|
||||||
|
\sa toString(), fromSetting()
|
||||||
|
*/
|
||||||
|
|
||||||
|
Id Id::fromName(const QByteArray &name)
|
||||||
|
{
|
||||||
|
return Id(theId(name));
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Returns a persistent value representing the id which is
|
Returns a persistent value representing the id which is
|
||||||
suitable to be stored in QSettings.
|
suitable to be stored in QSettings.
|
||||||
@@ -239,15 +257,41 @@ Id Id::fromSetting(const QVariant &variant)
|
|||||||
return Id(theId(ba));
|
return Id(theId(ba));
|
||||||
}
|
}
|
||||||
|
|
||||||
Id Id::withSuffix(Id id, int suffix)
|
/*!
|
||||||
|
Constructs a derived id.
|
||||||
|
|
||||||
|
This can be used to construct groups of ids logically
|
||||||
|
belonging together. The associated internal name
|
||||||
|
will be generated by appending \c{suffix}.
|
||||||
|
*/
|
||||||
|
|
||||||
|
Id Id::withSuffix(int suffix) const
|
||||||
{
|
{
|
||||||
const QByteArray ba = id.name() + QByteArray::number(suffix);
|
const QByteArray ba = name() + QByteArray::number(suffix);
|
||||||
return Id(ba.constData());
|
return Id(ba.constData());
|
||||||
}
|
}
|
||||||
|
|
||||||
Id Id::withSuffix(Id id, const char *suffix)
|
/*!
|
||||||
|
\overload
|
||||||
|
*/
|
||||||
|
|
||||||
|
Id Id::withSuffix(const char *suffix) const
|
||||||
{
|
{
|
||||||
const QByteArray ba = id.name() + suffix;
|
const QByteArray ba = name() + suffix;
|
||||||
|
return Id(ba.constData());
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Constructs a derived id.
|
||||||
|
|
||||||
|
This can be used to construct groups of ids logically
|
||||||
|
belonging together. The associated internal name
|
||||||
|
will be generated by prepending \c{prefix}.
|
||||||
|
*/
|
||||||
|
|
||||||
|
Id Id::withPrefix(const char *prefix) const
|
||||||
|
{
|
||||||
|
const QByteArray ba = prefix + name();
|
||||||
return Id(ba.constData());
|
return Id(ba.constData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -47,9 +47,13 @@ public:
|
|||||||
Id() : m_id(0) {}
|
Id() : m_id(0) {}
|
||||||
Id(int uid) : m_id(uid) {}
|
Id(int uid) : m_id(uid) {}
|
||||||
Id(const char *name);
|
Id(const char *name);
|
||||||
explicit Id(const QByteArray &name);
|
|
||||||
// FIXME: Remove
|
|
||||||
explicit Id(const QString &name);
|
explicit Id(const QString &name);
|
||||||
|
explicit Id(const QByteArray &name);
|
||||||
|
|
||||||
|
Id withSuffix(int suffix) const;
|
||||||
|
Id withSuffix(const char *name) const;
|
||||||
|
Id withPrefix(const char *name) const;
|
||||||
|
|
||||||
QByteArray name() const;
|
QByteArray name() const;
|
||||||
QString toString() const; // Avoid.
|
QString toString() const; // Avoid.
|
||||||
QVariant toSetting() const; // Good to use.
|
QVariant toSetting() const; // Good to use.
|
||||||
@@ -63,9 +67,8 @@ public:
|
|||||||
int uniqueIdentifier() const { return m_id; }
|
int uniqueIdentifier() const { return m_id; }
|
||||||
static Id fromUniqueIdentifier(int uid) { return Id(uid); }
|
static Id fromUniqueIdentifier(int uid) { return Id(uid); }
|
||||||
static Id fromString(const QString &str); // FIXME: avoid.
|
static Id fromString(const QString &str); // FIXME: avoid.
|
||||||
|
static Id fromName(const QByteArray &ba); // FIXME: avoid.
|
||||||
static Id fromSetting(const QVariant &variant); // Good to use.
|
static Id fromSetting(const QVariant &variant); // Good to use.
|
||||||
static Id withSuffix(Id base, int suffix);
|
|
||||||
static Id withSuffix(Id base, const char *name);
|
|
||||||
static void registerId(int uid, const char *name);
|
static void registerId(int uid, const char *name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@@ -143,7 +143,7 @@ void InfoBar::initializeGloballySuppressed()
|
|||||||
{
|
{
|
||||||
QStringList list = ICore::settings()->value(QLatin1String(C_SUPPRESSED_WARNINGS)).toStringList();
|
QStringList list = ICore::settings()->value(QLatin1String(C_SUPPRESSED_WARNINGS)).toStringList();
|
||||||
foreach (const QString &id, list)
|
foreach (const QString &id, list)
|
||||||
globallySuppressed.insert(Id(id.toLatin1()));
|
globallySuppressed.insert(Id::fromString(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
void InfoBar::clearGloballySuppressed()
|
void InfoBar::clearGloballySuppressed()
|
||||||
|
@@ -198,7 +198,7 @@ void ModeManager::objectAdded(QObject *obj)
|
|||||||
d->m_modeStack->setTabEnabled(index, mode->isEnabled());
|
d->m_modeStack->setTabEnabled(index, mode->isEnabled());
|
||||||
|
|
||||||
// Register mode shortcut
|
// Register mode shortcut
|
||||||
const Id shortcutId(QLatin1String("QtCreator.Mode.") + mode->id().toString());
|
const Id shortcutId = mode->id().withPrefix("QtCreator.Mode.");
|
||||||
QShortcut *shortcut = new QShortcut(d->m_mainWindow);
|
QShortcut *shortcut = new QShortcut(d->m_mainWindow);
|
||||||
shortcut->setWhatsThis(tr("Switch to <b>%1</b> mode").arg(mode->displayName()));
|
shortcut->setWhatsThis(tr("Switch to <b>%1</b> mode").arg(mode->displayName()));
|
||||||
Command *cmd = ActionManager::registerShortcut(shortcut, shortcutId, Context(Constants::C_GLOBAL));
|
Command *cmd = ActionManager::registerShortcut(shortcut, shortcutId, Context(Constants::C_GLOBAL));
|
||||||
|
@@ -195,7 +195,7 @@ void NavigationWidget::setFactories(const QList<INavigationWidgetFactory *> fact
|
|||||||
d->m_shortcutMap.insert(shortcut, id);
|
d->m_shortcutMap.insert(shortcut, id);
|
||||||
|
|
||||||
Command *cmd = ActionManager::registerShortcut(shortcut,
|
Command *cmd = ActionManager::registerShortcut(shortcut,
|
||||||
Id(QLatin1String("QtCreator.Sidebar.") + QLatin1String(id.name())), navicontext);
|
id.withPrefix("QtCreator.Sidebar."), navicontext);
|
||||||
cmd->setDefaultKeySequence(factory->activationSequence());
|
cmd->setDefaultKeySequence(factory->activationSequence());
|
||||||
d->m_commandMap.insert(id, cmd);
|
d->m_commandMap.insert(id, cmd);
|
||||||
|
|
||||||
|
@@ -49,7 +49,7 @@ public:
|
|||||||
{ return m_name; }
|
{ return m_name; }
|
||||||
|
|
||||||
virtual Core::Id id() const
|
virtual Core::Id id() const
|
||||||
{ return Core::Id(m_name); }
|
{ return Core::Id::fromString(m_name); }
|
||||||
|
|
||||||
virtual Core::IDocument *document() const
|
virtual Core::IDocument *document() const
|
||||||
{ return 0; }
|
{ return 0; }
|
||||||
|
Reference in New Issue
Block a user