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/
|
** Contact: https://www.qt.io/licensing/
|
||||||
**
|
**
|
||||||
** This file is part of Qt Creator.
|
** This file is part of Qt Creator.
|
||||||
@@ -448,6 +448,18 @@ QString ResourceFile::absolutePath(const QString &rel_path) const
|
|||||||
return QDir::cleanPath(rc);
|
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
|
bool ResourceFile::contains(const QString &prefix, const QString &lang, const QString &file) const
|
||||||
{
|
{
|
||||||
int pref_idx = indexOfPrefix(prefix, lang);
|
int pref_idx = indexOfPrefix(prefix, lang);
|
||||||
@@ -688,6 +700,11 @@ QList<QModelIndex> ResourceModel::nonExistingFiles() const
|
|||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ResourceModel::orderList()
|
||||||
|
{
|
||||||
|
m_resource_file.orderList();
|
||||||
|
}
|
||||||
|
|
||||||
Qt::ItemFlags ResourceModel::flags(const QModelIndex &index) const
|
Qt::ItemFlags ResourceModel::flags(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
Qt::ItemFlags f = QAbstractItemModel::flags(index);
|
Qt::ItemFlags f = QAbstractItemModel::flags(index);
|
||||||
|
@@ -170,6 +170,8 @@ public:
|
|||||||
QString relativePath(const QString &abs_path) const;
|
QString relativePath(const QString &abs_path) const;
|
||||||
QString absolutePath(const QString &rel_path) const;
|
QString absolutePath(const QString &rel_path) const;
|
||||||
|
|
||||||
|
void orderList();
|
||||||
|
|
||||||
static QString fixPrefix(const QString &prefix);
|
static QString fixPrefix(const QString &prefix);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -260,6 +262,8 @@ public:
|
|||||||
bool dirty() const { return m_dirty; }
|
bool dirty() const { return m_dirty; }
|
||||||
void setDirty(bool b);
|
void setDirty(bool b);
|
||||||
|
|
||||||
|
void orderList();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMimeData *mimeData (const QModelIndexList & indexes) const override;
|
QMimeData *mimeData (const QModelIndexList & indexes) const override;
|
||||||
|
|
||||||
|
@@ -95,6 +95,7 @@ ResourceEditorW::ResourceEditorW(const Core::Context &context,
|
|||||||
&ResourceEditorW::renameCurrentFile);
|
&ResourceEditorW::renameCurrentFile);
|
||||||
m_copyFileNameAction = m_contextMenu->addAction(tr("Copy Resource Path to Clipboard"),
|
m_copyFileNameAction = m_contextMenu->addAction(tr("Copy Resource Path to Clipboard"),
|
||||||
this, &ResourceEditorW::copyCurrentResourcePath);
|
this, &ResourceEditorW::copyCurrentResourcePath);
|
||||||
|
m_orderList = m_contextMenu->addAction(tr("Sort Alphabetically"), this, &ResourceEditorW::orderList);
|
||||||
|
|
||||||
connect(m_resourceDocument, &ResourceEditorDocument::loaded,
|
connect(m_resourceDocument, &ResourceEditorDocument::loaded,
|
||||||
m_resourceEditor, &QrcEditor::loaded);
|
m_resourceEditor, &QrcEditor::loaded);
|
||||||
@@ -331,6 +332,11 @@ void ResourceEditorW::copyCurrentResourcePath()
|
|||||||
QApplication::clipboard()->setText(m_resourceEditor->currentResourcePath());
|
QApplication::clipboard()->setText(m_resourceEditor->currentResourcePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ResourceEditorW::orderList()
|
||||||
|
{
|
||||||
|
m_resourceDocument->model()->orderList();
|
||||||
|
}
|
||||||
|
|
||||||
void ResourceEditorW::onUndo()
|
void ResourceEditorW::onUndo()
|
||||||
{
|
{
|
||||||
m_resourceEditor->onUndo();
|
m_resourceEditor->onUndo();
|
||||||
|
@@ -101,6 +101,7 @@ private:
|
|||||||
void openFile(const QString &fileName);
|
void openFile(const QString &fileName);
|
||||||
void renameCurrentFile();
|
void renameCurrentFile();
|
||||||
void copyCurrentResourcePath();
|
void copyCurrentResourcePath();
|
||||||
|
void orderList();
|
||||||
|
|
||||||
const QString m_extension;
|
const QString m_extension;
|
||||||
const QString m_fileFilter;
|
const QString m_fileFilter;
|
||||||
@@ -114,6 +115,7 @@ private:
|
|||||||
QToolBar *m_toolBar;
|
QToolBar *m_toolBar;
|
||||||
QAction *m_renameAction;
|
QAction *m_renameAction;
|
||||||
QAction *m_copyFileNameAction;
|
QAction *m_copyFileNameAction;
|
||||||
|
QAction *m_orderList;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void onRefresh();
|
void onRefresh();
|
||||||
|
Reference in New Issue
Block a user