diff --git a/src/plugins/resourceeditor/resourceeditor.qrc b/src/plugins/resourceeditor/resourceeditor.qrc index 2265055f972..2a1816f1cba 100644 --- a/src/plugins/resourceeditor/resourceeditor.qrc +++ b/src/plugins/resourceeditor/resourceeditor.qrc @@ -1,5 +1,5 @@ - + images/qt_qrc.png ResourceEditor.mimetypes.xml diff --git a/src/plugins/resourceeditor/resourceeditorconstants.h b/src/plugins/resourceeditor/resourceeditorconstants.h index 005b35efee6..e6a159aa9aa 100644 --- a/src/plugins/resourceeditor/resourceeditorconstants.h +++ b/src/plugins/resourceeditor/resourceeditorconstants.h @@ -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 diff --git a/src/plugins/resourceeditor/resourceeditorplugin.cpp b/src/plugins/resourceeditor/resourceeditorplugin.cpp index 743824d92a4..371b3db8945 100644 --- a/src/plugins/resourceeditor/resourceeditorplugin.cpp +++ b/src/plugins/resourceeditor/resourceeditorplugin.cpp @@ -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) { diff --git a/src/plugins/resourceeditor/resourceeditorplugin.h b/src/plugins/resourceeditor/resourceeditorplugin.h index 8415d623aad..15de044a93b 100644 --- a/src/plugins/resourceeditor/resourceeditorplugin.h +++ b/src/plugins/resourceeditor/resourceeditorplugin.h @@ -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 diff --git a/src/plugins/resourceeditor/resourceeditorw.cpp b/src/plugins/resourceeditor/resourceeditorw.cpp index 1d17d42e31c..8796a2055fc 100644 --- a/src/plugins/resourceeditor/resourceeditorw.cpp +++ b/src/plugins/resourceeditor/resourceeditorw.cpp @@ -38,6 +38,8 @@ #include #include +#include +#include #include #include #include @@ -51,6 +53,7 @@ #include #include #include +#include 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()) diff --git a/src/plugins/resourceeditor/resourceeditorw.h b/src/plugins/resourceeditor/resourceeditorw.h index fc16ceb8116..d5a0e684f04 100644 --- a/src/plugins/resourceeditor/resourceeditorw.h +++ b/src/plugins/resourceeditor/resourceeditorw.h @@ -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(); diff --git a/src/shared/qrceditor/qrceditor.cpp b/src/shared/qrceditor/qrceditor.cpp index 8a60fae2851..1f2b7ea83f6 100644 --- a/src/shared/qrceditor/qrceditor.cpp +++ b/src/shared/qrceditor/qrceditor.cpp @@ -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(); diff --git a/src/shared/qrceditor/qrceditor.h b/src/shared/qrceditor/qrceditor.h index b026c12b950..56a70d1cdae 100644 --- a/src/shared/qrceditor/qrceditor.h +++ b/src/shared/qrceditor/qrceditor.h @@ -67,6 +67,8 @@ public: const QUndoStack *commandHistory() const { return &m_history; } + void refresh(); + signals: void dirtyChanged(bool dirty); void itemActivated(const QString &fileName); diff --git a/src/shared/qrceditor/resourcefile.cpp b/src/shared/qrceditor/resourcefile.cpp index 042c640701d..7878cd8a5d7 100644 --- a/src/shared/qrceditor/resourcefile.cpp +++ b/src/shared/qrceditor/resourcefile.cpp @@ -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; } diff --git a/src/shared/qrceditor/resourcefile_p.h b/src/shared/qrceditor/resourcefile_p.h index 97a6308f238..5164c26b375 100644 --- a/src/shared/qrceditor/resourcefile_p.h +++ b/src/shared/qrceditor/resourcefile_p.h @@ -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 @@ -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; diff --git a/src/shared/qrceditor/resourceview.cpp b/src/shared/qrceditor/resourceview.cpp index 19465ceba94..427e527cc08 100644 --- a/src/shared/qrceditor/resourceview.cpp +++ b/src/shared/qrceditor/resourceview.cpp @@ -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"), diff --git a/src/shared/qrceditor/resourceview.h b/src/shared/qrceditor/resourceview.h index 3ca9999d0e6..8314baedf06 100644 --- a/src/shared/qrceditor/resourceview.h +++ b/src/shared/qrceditor/resourceview.h @@ -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);