diff options
author | Leandro Melo <leandro.melo@nokia.com> | 2011-04-06 11:47:48 +0200 |
---|---|---|
committer | Leandro Melo <leandro.melo@nokia.com> | 2011-04-06 16:00:35 +0200 |
commit | dc25adbe67383c0d0f23bfcc9b0320440658349b (patch) | |
tree | 20df3d04e72dcea8cce02cc86ca746eb50855a30 /src/plugins/coreplugin/mimetypesettings.cpp | |
parent | cad1c094f59b55780cd92e6f0d9867edaf1117f1 (diff) | |
download | qt-creator-dc25adbe67383c0d0f23bfcc9b0320440658349b.tar.gz |
Fix duplicate mime types in the user file
Also avoid writing the file on every apply and do it
only when the dialog is finished.
Reset can still be improved to take effect immediately.
Reviewed-by: con
Diffstat (limited to 'src/plugins/coreplugin/mimetypesettings.cpp')
-rw-r--r-- | src/plugins/coreplugin/mimetypesettings.cpp | 54 |
1 files changed, 38 insertions, 16 deletions
diff --git a/src/plugins/coreplugin/mimetypesettings.cpp b/src/plugins/coreplugin/mimetypesettings.cpp index ebede48aa1..45bb4da6b0 100644 --- a/src/plugins/coreplugin/mimetypesettings.cpp +++ b/src/plugins/coreplugin/mimetypesettings.cpp @@ -204,7 +204,7 @@ void MimeTypeSettingsModel::updateKnownPatterns(const QStringList &oldPatterns, } } -// MimeTypeSettingsPagePrivate +// MimeTypeSettingsPrivate class MimeTypeSettingsPrivate : public QObject { Q_OBJECT @@ -231,6 +231,7 @@ public: void editMagicHeaderRowData(const int row, const MagicData &data); void updateMimeDatabase(); + void resetState(); public slots: void syncData(const QModelIndex ¤t, const QModelIndex &previous); @@ -249,6 +250,7 @@ public: int m_mimeForPatternSync; int m_mimeForMagicSync; bool m_reset; + bool m_persist; QList<int> m_modifiedMimeTypes; Ui::MimeTypeSettingsPage m_ui; }; @@ -261,6 +263,7 @@ MimeTypeSettingsPrivate::MimeTypeSettingsPrivate() , m_mimeForPatternSync(-1) , m_mimeForMagicSync(-1) , m_reset(false) + , m_persist(false) {} MimeTypeSettingsPrivate::~MimeTypeSettingsPrivate() @@ -507,22 +510,32 @@ void MimeTypeSettingsPrivate::editMagicHeader() void MimeTypeSettingsPrivate::updateMimeDatabase() { - MimeDatabase *db = ICore::instance()->mimeDatabase(); + if (m_modifiedMimeTypes.isEmpty()) + return; + // For this case it is a better approach to simply use a list and to remove duplicates // afterwards than to keep a more complex data structure like a hash table. qSort(m_modifiedMimeTypes.begin(), m_modifiedMimeTypes.end()); m_modifiedMimeTypes.erase(std::unique(m_modifiedMimeTypes.begin(), m_modifiedMimeTypes.end()), m_modifiedMimeTypes.end()); - if (!m_modifiedMimeTypes.isEmpty()) { - QList<MimeType> allModified; - foreach (int index, m_modifiedMimeTypes) { - const MimeType &mimeType = m_model->m_mimeTypes.at(index); - db->setGlobPatterns(mimeType.type(), mimeType.globPatterns()); - db->setMagicMatchers(mimeType.type(), mimeType.magicMatchers()); - allModified.append(mimeType); - } - db->writeUserModifiedMimeTypes(allModified); + + MimeDatabase *db = ICore::instance()->mimeDatabase(); + QList<MimeType> allModified; + foreach (int index, m_modifiedMimeTypes) { + const MimeType &mimeType = m_model->m_mimeTypes.at(index); + db->setGlobPatterns(mimeType.type(), mimeType.globPatterns()); + db->setMagicMatchers(mimeType.type(), mimeType.magicMatchers()); + allModified.append(mimeType); } + db->writeUserModifiedMimeTypes(allModified); +} + +void MimeTypeSettingsPrivate::resetState() +{ + clearSyncData(); + m_modifiedMimeTypes.clear(); + m_reset = false; + m_persist = false; } void MimeTypeSettingsPrivate::resetMimeTypes() @@ -581,9 +594,7 @@ QWidget *MimeTypeSettings::createPage(QWidget *parent) void MimeTypeSettings::apply() { - if (m_d->m_reset) { - ICore::instance()->mimeDatabase()->clearUserModifiedMimeTypes(); - } else if (!m_d->m_modifiedMimeTypes.isEmpty()) { + if (!m_d->m_modifiedMimeTypes.isEmpty()) { const QModelIndex &modelIndex = m_d->m_ui.mimeTypesTableView->selectionModel()->currentIndex(); if (modelIndex.isValid()) { @@ -592,12 +603,23 @@ void MimeTypeSettings::apply() if (m_d->m_mimeForMagicSync == modelIndex.row()) m_d->syncMimeMagic(); } - m_d->updateMimeDatabase(); + m_d->clearSyncData(); } + + if (!m_d->m_persist) + m_d->m_persist = true; } void MimeTypeSettings::finish() -{} +{ + if (m_d->m_persist) { + if (m_d->m_reset) + ICore::instance()->mimeDatabase()->clearUserModifiedMimeTypes(); + else + m_d->updateMimeDatabase(); + } + m_d->resetState(); +} } // Internal } // Core |