forked from qt-creator/qt-creator
Highlight missing files in resource tree with red font.
Also added possibility to recheck file existance. Change-Id: I9f5e1d0499eb86238bb5c26420c48f322c87c65e Reviewed-by: Eike Ziller <eike.ziller@nokia.com>
This commit is contained in:
committed by
Eike Ziller
parent
dab8d6d0e7
commit
db6f01ba4a
@@ -1,5 +1,5 @@
|
|||||||
<RCC>
|
<RCC>
|
||||||
<qresource prefix="/resourceeditor" >
|
<qresource prefix="/resourceeditor">
|
||||||
<file>images/qt_qrc.png</file>
|
<file>images/qt_qrc.png</file>
|
||||||
<file>ResourceEditor.mimetypes.xml</file>
|
<file>ResourceEditor.mimetypes.xml</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ const char C_RESOURCEEDITOR[] = "Qt4.ResourceEditor";
|
|||||||
const char RESOURCEEDITOR_ID[] = "Qt4.ResourceEditor";
|
const char RESOURCEEDITOR_ID[] = "Qt4.ResourceEditor";
|
||||||
const char C_RESOURCEEDITOR_DISPLAY_NAME[] = QT_TRANSLATE_NOOP("OpenWith::Editors", "Resource Editor");
|
const char C_RESOURCEEDITOR_DISPLAY_NAME[] = QT_TRANSLATE_NOOP("OpenWith::Editors", "Resource Editor");
|
||||||
|
|
||||||
|
const char REFRESH[] = "ResourceEditor.Refresh";
|
||||||
|
|
||||||
const char C_RESOURCE_MIMETYPE[] = "application/vnd.nokia.xml.qt.resource";
|
const char C_RESOURCE_MIMETYPE[] = "application/vnd.nokia.xml.qt.resource";
|
||||||
|
|
||||||
} // namespace Constants
|
} // namespace Constants
|
||||||
|
|||||||
@@ -92,10 +92,13 @@ bool ResourceEditorPlugin::initialize(const QStringList &arguments, QString *err
|
|||||||
const Core::Context context(Constants::C_RESOURCEEDITOR);
|
const Core::Context context(Constants::C_RESOURCEEDITOR);
|
||||||
m_undoAction = new QAction(tr("&Undo"), this);
|
m_undoAction = new QAction(tr("&Undo"), this);
|
||||||
m_redoAction = new QAction(tr("&Redo"), this);
|
m_redoAction = new QAction(tr("&Redo"), this);
|
||||||
|
m_refreshAction = new QAction(tr("Recheck existence of referenced files"), this);
|
||||||
Core::ActionManager::registerAction(m_undoAction, Core::Constants::UNDO, context);
|
Core::ActionManager::registerAction(m_undoAction, Core::Constants::UNDO, context);
|
||||||
Core::ActionManager::registerAction(m_redoAction, Core::Constants::REDO, context);
|
Core::ActionManager::registerAction(m_redoAction, Core::Constants::REDO, context);
|
||||||
|
Core::ActionManager::registerAction(m_refreshAction, Constants::REFRESH, context);
|
||||||
connect(m_undoAction, SIGNAL(triggered()), this, SLOT(onUndo()));
|
connect(m_undoAction, SIGNAL(triggered()), this, SLOT(onUndo()));
|
||||||
connect(m_redoAction, SIGNAL(triggered()), this, SLOT(onRedo()));
|
connect(m_redoAction, SIGNAL(triggered()), this, SLOT(onRedo()));
|
||||||
|
connect(m_refreshAction, SIGNAL(triggered()), this, SLOT(onRefresh()));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -114,6 +117,11 @@ void ResourceEditorPlugin::onRedo()
|
|||||||
currentEditor()->onRedo();
|
currentEditor()->onRedo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ResourceEditorPlugin::onRefresh()
|
||||||
|
{
|
||||||
|
currentEditor()->onRefresh();
|
||||||
|
}
|
||||||
|
|
||||||
void ResourceEditorPlugin::onUndoStackChanged(ResourceEditorW const *editor,
|
void ResourceEditorPlugin::onUndoStackChanged(ResourceEditorW const *editor,
|
||||||
bool canUndo, bool canRedo)
|
bool canUndo, bool canRedo)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ public:
|
|||||||
private slots:
|
private slots:
|
||||||
void onUndo();
|
void onUndo();
|
||||||
void onRedo();
|
void onRedo();
|
||||||
|
void onRefresh();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void onUndoStackChanged(ResourceEditorW const *editor, bool canUndo, bool canRedo);
|
void onUndoStackChanged(ResourceEditorW const *editor, bool canUndo, bool canRedo);
|
||||||
@@ -74,6 +75,7 @@ private:
|
|||||||
ResourceEditorFactory *m_editor;
|
ResourceEditorFactory *m_editor;
|
||||||
QAction *m_redoAction;
|
QAction *m_redoAction;
|
||||||
QAction *m_undoAction;
|
QAction *m_undoAction;
|
||||||
|
QAction *m_refreshAction;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -38,6 +38,8 @@
|
|||||||
|
|
||||||
#include <aggregation/aggregate.h>
|
#include <aggregation/aggregate.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
#include <coreplugin/actionmanager/actionmanager.h>
|
||||||
|
#include <coreplugin/actionmanager/commandbutton.h>
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
#include <coreplugin/documentmanager.h>
|
#include <coreplugin/documentmanager.h>
|
||||||
#include <find/treeviewfind.h>
|
#include <find/treeviewfind.h>
|
||||||
@@ -51,6 +53,7 @@
|
|||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
#include <QToolBar>
|
||||||
|
|
||||||
namespace ResourceEditor {
|
namespace ResourceEditor {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -82,11 +85,18 @@ ResourceEditorW::ResourceEditorW(const Core::Context &context,
|
|||||||
m_plugin(plugin),
|
m_plugin(plugin),
|
||||||
m_shouldAutoSave(false),
|
m_shouldAutoSave(false),
|
||||||
m_diskIo(false),
|
m_diskIo(false),
|
||||||
m_contextMenu(new QMenu)
|
m_contextMenu(new QMenu),
|
||||||
|
m_toolBar(new QToolBar)
|
||||||
{
|
{
|
||||||
setContext(context);
|
setContext(context);
|
||||||
setWidget(m_resourceEditor);
|
setWidget(m_resourceEditor);
|
||||||
|
|
||||||
|
Core::ActionManager * const actionManager = Core::ICore::actionManager();
|
||||||
|
Core::CommandButton *refreshButton = new Core::CommandButton(Constants::REFRESH, m_toolBar);
|
||||||
|
refreshButton->setIcon(QIcon(QLatin1String(":/texteditor/images/finddocuments.png")));
|
||||||
|
connect(refreshButton, SIGNAL(clicked()), this, SLOT(onRefresh()));
|
||||||
|
m_toolBar->addWidget(refreshButton);
|
||||||
|
|
||||||
Aggregation::Aggregate * agg = new Aggregation::Aggregate;
|
Aggregation::Aggregate * agg = new Aggregation::Aggregate;
|
||||||
agg->add(m_resourceEditor->treeView());
|
agg->add(m_resourceEditor->treeView());
|
||||||
agg->add(new Find::TreeViewFind(m_resourceEditor->treeView()));
|
agg->add(new Find::TreeViewFind(m_resourceEditor->treeView()));
|
||||||
@@ -121,6 +131,7 @@ ResourceEditorW::~ResourceEditorW()
|
|||||||
if (m_resourceEditor)
|
if (m_resourceEditor)
|
||||||
m_resourceEditor->deleteLater();
|
m_resourceEditor->deleteLater();
|
||||||
delete m_contextMenu;
|
delete m_contextMenu;
|
||||||
|
delete m_toolBar;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ResourceEditorW::createNew(const QString &contents)
|
bool ResourceEditorW::createNew(const QString &contents)
|
||||||
@@ -214,6 +225,11 @@ Core::Id ResourceEditorW::id() const
|
|||||||
return Core::Id(ResourceEditor::Constants::RESOURCEEDITOR_ID);
|
return Core::Id(ResourceEditor::Constants::RESOURCEEDITOR_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QWidget *ResourceEditorW::toolBar()
|
||||||
|
{
|
||||||
|
return m_toolBar;
|
||||||
|
}
|
||||||
|
|
||||||
QString ResourceEditorDocument::fileName() const
|
QString ResourceEditorDocument::fileName() const
|
||||||
{
|
{
|
||||||
return m_parent->m_resourceEditor->fileName();
|
return m_parent->m_resourceEditor->fileName();
|
||||||
@@ -299,6 +315,12 @@ void ResourceEditorW::openFile(const QString &fileName)
|
|||||||
Core::EditorManager::openEditor(fileName);
|
Core::EditorManager::openEditor(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ResourceEditorW::onRefresh()
|
||||||
|
{
|
||||||
|
if (!m_resourceEditor.isNull())
|
||||||
|
m_resourceEditor.data()->refresh();
|
||||||
|
}
|
||||||
|
|
||||||
void ResourceEditorW::onUndo()
|
void ResourceEditorW::onUndo()
|
||||||
{
|
{
|
||||||
if (!m_resourceEditor.isNull())
|
if (!m_resourceEditor.isNull())
|
||||||
|
|||||||
@@ -40,6 +40,7 @@
|
|||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QMenu;
|
class QMenu;
|
||||||
|
class QToolBar;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace SharedTools {
|
namespace SharedTools {
|
||||||
@@ -96,7 +97,7 @@ public:
|
|||||||
Core::Id id() const;
|
Core::Id id() const;
|
||||||
QString displayName() const { return m_displayName; }
|
QString displayName() const { return m_displayName; }
|
||||||
void setDisplayName(const QString &title) { m_displayName = title; emit changed(); }
|
void setDisplayName(const QString &title) { m_displayName = title; emit changed(); }
|
||||||
QWidget *toolBar() { return 0; }
|
QWidget *toolBar();
|
||||||
QByteArray saveState() const { return QByteArray(); }
|
QByteArray saveState() const { return QByteArray(); }
|
||||||
bool restoreState(const QByteArray &/*state*/) { return true; }
|
bool restoreState(const QByteArray &/*state*/) { return true; }
|
||||||
|
|
||||||
@@ -124,6 +125,10 @@ private:
|
|||||||
QMenu *m_contextMenu;
|
QMenu *m_contextMenu;
|
||||||
QMenu *m_openWithMenu;
|
QMenu *m_openWithMenu;
|
||||||
QString m_currentFileName;
|
QString m_currentFileName;
|
||||||
|
QToolBar *m_toolBar;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void onRefresh();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void onUndo();
|
void onUndo();
|
||||||
|
|||||||
@@ -127,6 +127,11 @@ bool QrcEditor::load(const QString &fileName)
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QrcEditor::refresh()
|
||||||
|
{
|
||||||
|
m_treeview->refresh();
|
||||||
|
}
|
||||||
|
|
||||||
bool QrcEditor::save()
|
bool QrcEditor::save()
|
||||||
{
|
{
|
||||||
return m_treeview->save();
|
return m_treeview->save();
|
||||||
|
|||||||
@@ -67,6 +67,8 @@ public:
|
|||||||
|
|
||||||
const QUndoStack *commandHistory() const { return &m_history; }
|
const QUndoStack *commandHistory() const { return &m_history; }
|
||||||
|
|
||||||
|
void refresh();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void dirtyChanged(bool dirty);
|
void dirtyChanged(bool dirty);
|
||||||
void itemActivated(const QString &fileName);
|
void itemActivated(const QString &fileName);
|
||||||
|
|||||||
@@ -61,6 +61,33 @@ static QString msgFileNameEmpty()
|
|||||||
|
|
||||||
namespace qdesigner_internal {
|
namespace qdesigner_internal {
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
** File
|
||||||
|
*/
|
||||||
|
|
||||||
|
File::File(Prefix *prefix, const QString &_name, const QString &_alias)
|
||||||
|
: Node(this, prefix)
|
||||||
|
, name(_name)
|
||||||
|
, alias(_alias)
|
||||||
|
, m_checked(false)
|
||||||
|
, m_exists(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void File::checkExistence()
|
||||||
|
{
|
||||||
|
m_checked = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool File::exists()
|
||||||
|
{
|
||||||
|
if (!m_checked) {
|
||||||
|
m_exists = QFile::exists(name);
|
||||||
|
m_checked = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_exists;
|
||||||
|
}
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
** FileList
|
** FileList
|
||||||
@@ -212,6 +239,15 @@ bool ResourceFile::save()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ResourceFile::refresh()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < prefixCount(); ++i) {
|
||||||
|
const FileList &file_list = m_prefix_list.at(i)->file_list;
|
||||||
|
foreach (File *file, file_list)
|
||||||
|
file->checkExistence();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool ResourceFile::split(const QString &_path, QString *prefix, QString *file) const
|
bool ResourceFile::split(const QString &_path, QString *prefix, QString *file) const
|
||||||
{
|
{
|
||||||
prefix->clear();
|
prefix->clear();
|
||||||
@@ -457,6 +493,7 @@ QString ResourceFile::file(int prefix_idx, int file_idx) const
|
|||||||
Q_ASSERT(prefix_idx >= 0 && prefix_idx < m_prefix_list.count());
|
Q_ASSERT(prefix_idx >= 0 && prefix_idx < m_prefix_list.count());
|
||||||
FileList &fileList = m_prefix_list.at(prefix_idx)->file_list;
|
FileList &fileList = m_prefix_list.at(prefix_idx)->file_list;
|
||||||
Q_ASSERT(file_idx >= 0 && file_idx < fileList.count());
|
Q_ASSERT(file_idx >= 0 && file_idx < fileList.count());
|
||||||
|
fileList.at(file_idx)->checkExistence();
|
||||||
return fileList.at(file_idx)->name;
|
return fileList.at(file_idx)->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -604,6 +641,11 @@ bool ResourceModel::hasChildren(const QModelIndex &parent) const
|
|||||||
return rowCount(parent) != 0;
|
return rowCount(parent) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ResourceModel::refresh()
|
||||||
|
{
|
||||||
|
m_resource_file.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
bool ResourceModel::iconFileExtension(const QString &path)
|
bool ResourceModel::iconFileExtension(const QString &path)
|
||||||
{
|
{
|
||||||
static QStringList ext_list;
|
static QStringList ext_list;
|
||||||
@@ -685,6 +727,14 @@ QVariant ResourceModel::data(const QModelIndex &index, int role) const
|
|||||||
result = m_prefixIcon;
|
result = m_prefixIcon;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case Qt::ForegroundRole:
|
||||||
|
if (isFileNode) {
|
||||||
|
// File node
|
||||||
|
Q_ASSERT(file);
|
||||||
|
if (!file->exists())
|
||||||
|
result = QBrush(QColor(Qt::red));
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ QT_BEGIN_NAMESPACE
|
|||||||
|
|
||||||
namespace qdesigner_internal {
|
namespace qdesigner_internal {
|
||||||
|
|
||||||
struct File;
|
class File;
|
||||||
struct Prefix;
|
struct Prefix;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -71,15 +71,24 @@ private:
|
|||||||
|
|
||||||
Represents a file node in a \l ResourceFile tree.
|
Represents a file node in a \l ResourceFile tree.
|
||||||
*/
|
*/
|
||||||
struct File : public Node {
|
class File : public Node
|
||||||
File(Prefix *prefix, const QString &_name = QString(), const QString &_alias = QString())
|
{
|
||||||
: Node(this, prefix), name(_name), alias(_alias) {}
|
public:
|
||||||
|
File(Prefix *prefix, const QString &_name, const QString &_alias = QString());
|
||||||
|
void checkExistence();
|
||||||
|
bool exists();
|
||||||
|
|
||||||
bool operator < (const File &other) const { return name < other.name; }
|
bool operator < (const File &other) const { return name < other.name; }
|
||||||
bool operator == (const File &other) const { return name == other.name; }
|
bool operator == (const File &other) const { return name == other.name; }
|
||||||
bool operator != (const File &other) const { return name != other.name; }
|
bool operator != (const File &other) const { return name != other.name; }
|
||||||
|
|
||||||
QString name;
|
QString name;
|
||||||
QString alias;
|
QString alias;
|
||||||
QIcon icon;
|
QIcon icon;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_checked;
|
||||||
|
bool m_exists;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FileList : public QList<File *>
|
class FileList : public QList<File *>
|
||||||
@@ -125,6 +134,7 @@ public:
|
|||||||
bool load();
|
bool load();
|
||||||
bool save();
|
bool save();
|
||||||
QString errorMessage() const { return m_error_message; }
|
QString errorMessage() const { return m_error_message; }
|
||||||
|
void refresh();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString resolvePath(const QString &path) const;
|
QString resolvePath(const QString &path) const;
|
||||||
@@ -202,6 +212,8 @@ public:
|
|||||||
int columnCount(const QModelIndex &parent) const;
|
int columnCount(const QModelIndex &parent) const;
|
||||||
bool hasChildren(const QModelIndex &parent) const;
|
bool hasChildren(const QModelIndex &parent) const;
|
||||||
|
|
||||||
|
void refresh();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||||
|
|
||||||
|
|||||||
@@ -334,6 +334,16 @@ QModelIndex ResourceView::addPrefix()
|
|||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ResourceView::refresh()
|
||||||
|
{
|
||||||
|
m_qrcModel->refresh();
|
||||||
|
QModelIndex idx = currentIndex();
|
||||||
|
setModel(0);
|
||||||
|
setModel(m_qrcModel);
|
||||||
|
setCurrentIndex(idx);
|
||||||
|
expandAll();
|
||||||
|
}
|
||||||
|
|
||||||
QStringList ResourceView::fileNamesToAdd()
|
QStringList ResourceView::fileNamesToAdd()
|
||||||
{
|
{
|
||||||
return QFileDialog::getOpenFileNames(this, tr("Open File"),
|
return QFileDialog::getOpenFileNames(this, tr("Open File"),
|
||||||
|
|||||||
@@ -118,6 +118,8 @@ public:
|
|||||||
QStringList fileNamesToAdd();
|
QStringList fileNamesToAdd();
|
||||||
QModelIndex addPrefix();
|
QModelIndex addPrefix();
|
||||||
|
|
||||||
|
void refresh();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setCurrentAlias(const QString &before, const QString &after);
|
void setCurrentAlias(const QString &before, const QString &after);
|
||||||
void setCurrentPrefix(const QString &before, const QString &after);
|
void setCurrentPrefix(const QString &before, const QString &after);
|
||||||
|
|||||||
Reference in New Issue
Block a user