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;
|
||||
QAction *separator = new QAction(this);
|
||||
separator->setSeparator(true);
|
||||
Command *cmd = ActionManager::registerAction(separator, Id(QString::fromLatin1("%1.Separator.%2")
|
||||
.arg(id().toString()).arg(++separatorIdCount)),
|
||||
context);
|
||||
Id sepId = id().withSuffix(".Separator.").withSuffix(++separatorIdCount);
|
||||
Command *cmd = ActionManager::registerAction(separator, sepId, context);
|
||||
addAction(cmd, group);
|
||||
if (outSeparator)
|
||||
*outSeparator = separator;
|
||||
|
@@ -566,7 +566,7 @@ void ActionManagerPrivate::initialize()
|
||||
for (int i = 0; i < shortcuts; ++i) {
|
||||
settings->setArrayIndex(i);
|
||||
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);
|
||||
if (cmd)
|
||||
|
@@ -334,7 +334,7 @@ void SettingsDialog::showPage(Id categoryId, Id pageId)
|
||||
QString initialPage = pageId.toString();
|
||||
if (!initialCategory.isValid() && initialPage.isEmpty()) {
|
||||
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();
|
||||
}
|
||||
|
||||
|
@@ -1183,7 +1183,7 @@ void readSettings()
|
||||
editorId = ids.next();
|
||||
if (QFileInfo(fileName).isFile())
|
||||
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));
|
||||
|
@@ -1232,14 +1232,14 @@ Core::Id EditorManager::getOpenWithEditorId(const QString &fileName,
|
||||
//Unable to determine mime type of fileName. Falling back to text/plain",
|
||||
if (!mt)
|
||||
mt = ICore::mimeDatabase()->findByType(QLatin1String("text/plain"));
|
||||
QStringList allEditorIds;
|
||||
QList<Id> allEditorIds;
|
||||
QStringList allEditorDisplayNames;
|
||||
QList<Id> externalEditorIds;
|
||||
// Built-in
|
||||
const EditorFactoryList editors = editorFactories(mt, false);
|
||||
const int size = editors.size();
|
||||
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());
|
||||
}
|
||||
// External editors
|
||||
@@ -1247,7 +1247,7 @@ Core::Id EditorManager::getOpenWithEditorId(const QString &fileName,
|
||||
const int esize = exEditors.size();
|
||||
for (int i = 0; i < esize; i++) {
|
||||
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());
|
||||
}
|
||||
if (allEditorIds.empty())
|
||||
@@ -1259,7 +1259,7 @@ Core::Id EditorManager::getOpenWithEditorId(const QString &fileName,
|
||||
dialog.setCurrentEditor(0);
|
||||
if (dialog.exec() != QDialog::Accepted)
|
||||
return Id();
|
||||
const Id selectedId = Id(allEditorIds.at(dialog.editor()));
|
||||
const Id selectedId = allEditorIds.at(dialog.editor());
|
||||
if (isExternalEditor)
|
||||
*isExternalEditor = externalEditorIds.contains(selectedId);
|
||||
return selectedId;
|
||||
@@ -2019,9 +2019,9 @@ bool EditorManager::restoreState(const QByteArray &state)
|
||||
continue;
|
||||
QFileInfo rfi(autoSaveName(fileName));
|
||||
if (rfi.exists() && fi.lastModified() < rfi.lastModified())
|
||||
openEditor(fileName, Id(QString::fromUtf8(id)));
|
||||
openEditor(fileName, Id::fromName(id));
|
||||
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 <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); }
|
||||
Context(Id c1, Id c2) { add(c1); add(c2); }
|
||||
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); }
|
||||
int size() const { return d.size(); }
|
||||
bool isEmpty() const { return d.isEmpty(); }
|
||||
|
@@ -207,6 +207,8 @@ QString Id::toString() const
|
||||
This should not be used to handle a persistent version
|
||||
of the Id, use \c{fromSetting()} instead.
|
||||
|
||||
\deprecated
|
||||
|
||||
\sa toString(), fromSetting()
|
||||
*/
|
||||
|
||||
@@ -215,6 +217,22 @@ Id Id::fromString(const QString &name)
|
||||
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
|
||||
suitable to be stored in QSettings.
|
||||
@@ -239,15 +257,41 @@ Id Id::fromSetting(const QVariant &variant)
|
||||
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());
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
|
@@ -47,9 +47,13 @@ public:
|
||||
Id() : m_id(0) {}
|
||||
Id(int uid) : m_id(uid) {}
|
||||
Id(const char *name);
|
||||
explicit Id(const QByteArray &name);
|
||||
// FIXME: Remove
|
||||
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;
|
||||
QString toString() const; // Avoid.
|
||||
QVariant toSetting() const; // Good to use.
|
||||
@@ -63,9 +67,8 @@ public:
|
||||
int uniqueIdentifier() const { return m_id; }
|
||||
static Id fromUniqueIdentifier(int uid) { return Id(uid); }
|
||||
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 withSuffix(Id base, int suffix);
|
||||
static Id withSuffix(Id base, const char *name);
|
||||
static void registerId(int uid, const char *name);
|
||||
|
||||
private:
|
||||
|
@@ -143,7 +143,7 @@ void InfoBar::initializeGloballySuppressed()
|
||||
{
|
||||
QStringList list = ICore::settings()->value(QLatin1String(C_SUPPRESSED_WARNINGS)).toStringList();
|
||||
foreach (const QString &id, list)
|
||||
globallySuppressed.insert(Id(id.toLatin1()));
|
||||
globallySuppressed.insert(Id::fromString(id));
|
||||
}
|
||||
|
||||
void InfoBar::clearGloballySuppressed()
|
||||
|
@@ -198,7 +198,7 @@ void ModeManager::objectAdded(QObject *obj)
|
||||
d->m_modeStack->setTabEnabled(index, mode->isEnabled());
|
||||
|
||||
// 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);
|
||||
shortcut->setWhatsThis(tr("Switch to <b>%1</b> mode").arg(mode->displayName()));
|
||||
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);
|
||||
|
||||
Command *cmd = ActionManager::registerShortcut(shortcut,
|
||||
Id(QLatin1String("QtCreator.Sidebar.") + QLatin1String(id.name())), navicontext);
|
||||
id.withPrefix("QtCreator.Sidebar."), navicontext);
|
||||
cmd->setDefaultKeySequence(factory->activationSequence());
|
||||
d->m_commandMap.insert(id, cmd);
|
||||
|
||||
|
@@ -49,7 +49,7 @@ public:
|
||||
{ return m_name; }
|
||||
|
||||
virtual Core::Id id() const
|
||||
{ return Core::Id(m_name); }
|
||||
{ return Core::Id::fromString(m_name); }
|
||||
|
||||
virtual Core::IDocument *document() const
|
||||
{ return 0; }
|
||||
|
Reference in New Issue
Block a user