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:
Konstantin Tokarev
2012-05-24 19:11:47 +04:00
committed by Eike Ziller
parent dab8d6d0e7
commit db6f01ba4a
12 changed files with 127 additions and 7 deletions

View File

@@ -1,5 +1,5 @@
<RCC>
<qresource prefix="/resourceeditor" >
<qresource prefix="/resourceeditor">
<file>images/qt_qrc.png</file>
<file>ResourceEditor.mimetypes.xml</file>
</qresource>

View File

@@ -40,6 +40,8 @@ const char C_RESOURCEEDITOR[] = "Qt4.ResourceEditor";
const char RESOURCEEDITOR_ID[] = "Qt4.ResourceEditor";
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";
} // namespace Constants

View File

@@ -92,10 +92,13 @@ bool ResourceEditorPlugin::initialize(const QStringList &arguments, QString *err
const Core::Context context(Constants::C_RESOURCEEDITOR);
m_undoAction = new QAction(tr("&Undo"), 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_redoAction, Core::Constants::REDO, context);
Core::ActionManager::registerAction(m_refreshAction, Constants::REFRESH, context);
connect(m_undoAction, SIGNAL(triggered()), this, SLOT(onUndo()));
connect(m_redoAction, SIGNAL(triggered()), this, SLOT(onRedo()));
connect(m_refreshAction, SIGNAL(triggered()), this, SLOT(onRefresh()));
return true;
}
@@ -114,6 +117,11 @@ void ResourceEditorPlugin::onRedo()
currentEditor()->onRedo();
}
void ResourceEditorPlugin::onRefresh()
{
currentEditor()->onRefresh();
}
void ResourceEditorPlugin::onUndoStackChanged(ResourceEditorW const *editor,
bool canUndo, bool canRedo)
{

View File

@@ -62,6 +62,7 @@ public:
private slots:
void onUndo();
void onRedo();
void onRefresh();
public:
void onUndoStackChanged(ResourceEditorW const *editor, bool canUndo, bool canRedo);
@@ -74,6 +75,7 @@ private:
ResourceEditorFactory *m_editor;
QAction *m_redoAction;
QAction *m_undoAction;
QAction *m_refreshAction;
};
} // namespace Internal

View File

@@ -38,6 +38,8 @@
#include <aggregation/aggregate.h>
#include <coreplugin/icore.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/commandbutton.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/documentmanager.h>
#include <find/treeviewfind.h>
@@ -51,6 +53,7 @@
#include <QHBoxLayout>
#include <QMainWindow>
#include <QMenu>
#include <QToolBar>
namespace ResourceEditor {
namespace Internal {
@@ -82,11 +85,18 @@ ResourceEditorW::ResourceEditorW(const Core::Context &context,
m_plugin(plugin),
m_shouldAutoSave(false),
m_diskIo(false),
m_contextMenu(new QMenu)
m_contextMenu(new QMenu),
m_toolBar(new QToolBar)
{
setContext(context);
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;
agg->add(m_resourceEditor->treeView());
agg->add(new Find::TreeViewFind(m_resourceEditor->treeView()));
@@ -121,6 +131,7 @@ ResourceEditorW::~ResourceEditorW()
if (m_resourceEditor)
m_resourceEditor->deleteLater();
delete m_contextMenu;
delete m_toolBar;
}
bool ResourceEditorW::createNew(const QString &contents)
@@ -214,6 +225,11 @@ Core::Id ResourceEditorW::id() const
return Core::Id(ResourceEditor::Constants::RESOURCEEDITOR_ID);
}
QWidget *ResourceEditorW::toolBar()
{
return m_toolBar;
}
QString ResourceEditorDocument::fileName() const
{
return m_parent->m_resourceEditor->fileName();
@@ -299,6 +315,12 @@ void ResourceEditorW::openFile(const QString &fileName)
Core::EditorManager::openEditor(fileName);
}
void ResourceEditorW::onRefresh()
{
if (!m_resourceEditor.isNull())
m_resourceEditor.data()->refresh();
}
void ResourceEditorW::onUndo()
{
if (!m_resourceEditor.isNull())

View File

@@ -40,6 +40,7 @@
QT_BEGIN_NAMESPACE
class QMenu;
class QToolBar;
QT_END_NAMESPACE
namespace SharedTools {
@@ -96,7 +97,7 @@ public:
Core::Id id() const;
QString displayName() const { return m_displayName; }
void setDisplayName(const QString &title) { m_displayName = title; emit changed(); }
QWidget *toolBar() { return 0; }
QWidget *toolBar();
QByteArray saveState() const { return QByteArray(); }
bool restoreState(const QByteArray &/*state*/) { return true; }
@@ -124,6 +125,10 @@ private:
QMenu *m_contextMenu;
QMenu *m_openWithMenu;
QString m_currentFileName;
QToolBar *m_toolBar;
public slots:
void onRefresh();
public:
void onUndo();

View File

@@ -127,6 +127,11 @@ bool QrcEditor::load(const QString &fileName)
return success;
}
void QrcEditor::refresh()
{
m_treeview->refresh();
}
bool QrcEditor::save()
{
return m_treeview->save();

View File

@@ -67,6 +67,8 @@ public:
const QUndoStack *commandHistory() const { return &m_history; }
void refresh();
signals:
void dirtyChanged(bool dirty);
void itemActivated(const QString &fileName);

View File

@@ -61,6 +61,33 @@ static QString msgFileNameEmpty()
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
@@ -212,6 +239,15 @@ bool ResourceFile::save()
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
{
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());
FileList &fileList = m_prefix_list.at(prefix_idx)->file_list;
Q_ASSERT(file_idx >= 0 && file_idx < fileList.count());
fileList.at(file_idx)->checkExistence();
return fileList.at(file_idx)->name;
}
@@ -604,6 +641,11 @@ bool ResourceModel::hasChildren(const QModelIndex &parent) const
return rowCount(parent) != 0;
}
void ResourceModel::refresh()
{
m_resource_file.refresh();
}
bool ResourceModel::iconFileExtension(const QString &path)
{
static QStringList ext_list;
@@ -685,6 +727,14 @@ QVariant ResourceModel::data(const QModelIndex &index, int role) const
result = m_prefixIcon;
}
break;
case Qt::ForegroundRole:
if (isFileNode) {
// File node
Q_ASSERT(file);
if (!file->exists())
result = QBrush(QColor(Qt::red));
}
break;
default:
break;
}

View File

@@ -43,7 +43,7 @@ QT_BEGIN_NAMESPACE
namespace qdesigner_internal {
struct File;
class File;
struct Prefix;
/*!
@@ -71,15 +71,24 @@ private:
Represents a file node in a \l ResourceFile tree.
*/
struct File : public Node {
File(Prefix *prefix, const QString &_name = QString(), const QString &_alias = QString())
: Node(this, prefix), name(_name), alias(_alias) {}
class File : public Node
{
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; }
QString name;
QString alias;
QIcon icon;
private:
bool m_checked;
bool m_exists;
};
class FileList : public QList<File *>
@@ -125,6 +134,7 @@ public:
bool load();
bool save();
QString errorMessage() const { return m_error_message; }
void refresh();
private:
QString resolvePath(const QString &path) const;
@@ -202,6 +212,8 @@ public:
int columnCount(const QModelIndex &parent) const;
bool hasChildren(const QModelIndex &parent) const;
void refresh();
protected:
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;

View File

@@ -334,6 +334,16 @@ QModelIndex ResourceView::addPrefix()
return idx;
}
void ResourceView::refresh()
{
m_qrcModel->refresh();
QModelIndex idx = currentIndex();
setModel(0);
setModel(m_qrcModel);
setCurrentIndex(idx);
expandAll();
}
QStringList ResourceView::fileNamesToAdd()
{
return QFileDialog::getOpenFileNames(this, tr("Open File"),

View File

@@ -118,6 +118,8 @@ public:
QStringList fileNamesToAdd();
QModelIndex addPrefix();
void refresh();
public slots:
void setCurrentAlias(const QString &before, const QString &after);
void setCurrentPrefix(const QString &before, const QString &after);