forked from qt-creator/qt-creator
QrcEditor: Add action for ordering resource list
Change-Id: I8c2d53649af420b324d6a0f57b09d1cd4ccd5e25 Reviewed-by: hjk <hjk@qt.io> Reviewed-by: Andrea Ricchi <aricchi95@gmail.com>
This commit is contained in:
committed by
Federico Guerinoni
parent
818d79b655
commit
f6cfcc4411
@@ -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);
|
||||
|
@@ -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;
|
||||
|
||||
|
@@ -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();
|
||||
|
@@ -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();
|
||||
|
Reference in New Issue
Block a user