diff options
author | Federico Guerinoni <guerinoni@micro-systems.it> | 2020-03-01 15:11:52 +0100 |
---|---|---|
committer | Federico Guerinoni <guerinoni.federico@gmail.com> | 2020-03-12 14:26:51 +0000 |
commit | f6cfcc4411f32dea9f4ed66cd2142152184a0aa1 (patch) | |
tree | 708871f45702629e04b10a0b38fff8e90a3eb48f /src/plugins/resourceeditor | |
parent | 818d79b65515dca657773be89e35cb10b289a14a (diff) | |
download | qt-creator-f6cfcc4411f32dea9f4ed66cd2142152184a0aa1.tar.gz |
QrcEditor: Add action for ordering resource list
Change-Id: I8c2d53649af420b324d6a0f57b09d1cd4ccd5e25
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Andrea Ricchi <aricchi95@gmail.com>
Diffstat (limited to 'src/plugins/resourceeditor')
4 files changed, 30 insertions, 1 deletions
diff --git a/src/plugins/resourceeditor/qrceditor/resourcefile.cpp b/src/plugins/resourceeditor/qrceditor/resourcefile.cpp index 81c211cb0a..71f5fb05c4 100644 --- a/src/plugins/resourceeditor/qrceditor/resourcefile.cpp +++ b/src/plugins/resourceeditor/qrceditor/resourcefile.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of Qt Creator. @@ -448,6 +448,18 @@ QString ResourceFile::absolutePath(const QString &rel_path) const return QDir::cleanPath(rc); } +void ResourceFile::orderList() +{ + for (Prefix *p : m_prefix_list) { + std::sort(p->file_list.begin(), p->file_list.end(), [&](File *f1, File *f2) { + return *f1 < *f2; + }); + } + + if (!save()) + m_error_message = tr("Cannot save file."); +} + bool ResourceFile::contains(const QString &prefix, const QString &lang, const QString &file) const { int pref_idx = indexOfPrefix(prefix, lang); @@ -688,6 +700,11 @@ QList<QModelIndex> ResourceModel::nonExistingFiles() const return files; } +void ResourceModel::orderList() +{ + m_resource_file.orderList(); +} + Qt::ItemFlags ResourceModel::flags(const QModelIndex &index) const { Qt::ItemFlags f = QAbstractItemModel::flags(index); diff --git a/src/plugins/resourceeditor/qrceditor/resourcefile_p.h b/src/plugins/resourceeditor/qrceditor/resourcefile_p.h index 8957a56f0e..0afb55290c 100644 --- a/src/plugins/resourceeditor/qrceditor/resourcefile_p.h +++ b/src/plugins/resourceeditor/qrceditor/resourcefile_p.h @@ -170,6 +170,8 @@ public: QString relativePath(const QString &abs_path) const; QString absolutePath(const QString &rel_path) const; + void orderList(); + static QString fixPrefix(const QString &prefix); private: @@ -260,6 +262,8 @@ public: bool dirty() const { return m_dirty; } void setDirty(bool b); + void orderList(); + private: QMimeData *mimeData (const QModelIndexList & indexes) const override; diff --git a/src/plugins/resourceeditor/resourceeditorw.cpp b/src/plugins/resourceeditor/resourceeditorw.cpp index 2255810bb9..8467b8bf13 100644 --- a/src/plugins/resourceeditor/resourceeditorw.cpp +++ b/src/plugins/resourceeditor/resourceeditorw.cpp @@ -95,6 +95,7 @@ ResourceEditorW::ResourceEditorW(const Core::Context &context, &ResourceEditorW::renameCurrentFile); m_copyFileNameAction = m_contextMenu->addAction(tr("Copy Resource Path to Clipboard"), this, &ResourceEditorW::copyCurrentResourcePath); + m_orderList = m_contextMenu->addAction(tr("Sort Alphabetically"), this, &ResourceEditorW::orderList); connect(m_resourceDocument, &ResourceEditorDocument::loaded, m_resourceEditor, &QrcEditor::loaded); @@ -331,6 +332,11 @@ void ResourceEditorW::copyCurrentResourcePath() QApplication::clipboard()->setText(m_resourceEditor->currentResourcePath()); } +void ResourceEditorW::orderList() +{ + m_resourceDocument->model()->orderList(); +} + void ResourceEditorW::onUndo() { m_resourceEditor->onUndo(); diff --git a/src/plugins/resourceeditor/resourceeditorw.h b/src/plugins/resourceeditor/resourceeditorw.h index 8ac4e8d9b2..90fbc93bb3 100644 --- a/src/plugins/resourceeditor/resourceeditorw.h +++ b/src/plugins/resourceeditor/resourceeditorw.h @@ -101,6 +101,7 @@ private: void openFile(const QString &fileName); void renameCurrentFile(); void copyCurrentResourcePath(); + void orderList(); const QString m_extension; const QString m_fileFilter; @@ -114,6 +115,7 @@ private: QToolBar *m_toolBar; QAction *m_renameAction; QAction *m_copyFileNameAction; + QAction *m_orderList; public: void onRefresh(); |