Open file with default editor when it's activated in ResourceEditor.

This patch provides more convenient way to view/edit resource files than
"Open With" context menu.

Change-Id: I1c1fbfe48ed069d004f900e040b6517a4064b0f1
Reviewed-by: Eike Ziller <eike.ziller@nokia.com>
This commit is contained in:
Konstantin Tokarev
2012-05-16 13:38:31 +04:00
committed by Eike Ziller
parent 9b3e46b08f
commit dec03a0d6c
6 changed files with 34 additions and 1 deletions

View File

@@ -92,6 +92,7 @@ ResourceEditorW::ResourceEditorW(const Core::Context &context,
agg->add(new Find::TreeViewFind(m_resourceEditor->treeView())); agg->add(new Find::TreeViewFind(m_resourceEditor->treeView()));
m_resourceEditor->setResourceDragEnabled(true); m_resourceEditor->setResourceDragEnabled(true);
m_contextMenu->addAction(tr("Open File"), this, SLOT(openCurrentFile()));
m_openWithMenu = m_contextMenu->addMenu(tr("Open With")); m_openWithMenu = m_contextMenu->addMenu(tr("Open With"));
// Below we need QueuedConnection because otherwise, if this qrc file // Below we need QueuedConnection because otherwise, if this qrc file
// is inside of the qrc file, crashes happen when using "Open With" on it. // is inside of the qrc file, crashes happen when using "Open With" on it.
@@ -106,6 +107,8 @@ ResourceEditorW::ResourceEditorW(const Core::Context &context,
this, SLOT(onUndoStackChanged(bool,bool))); this, SLOT(onUndoStackChanged(bool,bool)));
connect(m_resourceEditor, SIGNAL(showContextMenu(QPoint,QString)), connect(m_resourceEditor, SIGNAL(showContextMenu(QPoint,QString)),
this, SLOT(showContextMenu(QPoint,QString))); this, SLOT(showContextMenu(QPoint,QString)));
connect(m_resourceEditor, SIGNAL(itemActivated(QString)),
this, SLOT(openFile(QString)));
connect(m_resourceEditor->commandHistory(), SIGNAL(indexChanged(int)), connect(m_resourceEditor->commandHistory(), SIGNAL(indexChanged(int)),
this, SLOT(setShouldAutoSave())); this, SLOT(setShouldAutoSave()));
connect(m_resourceDocument, SIGNAL(changed()), this, SIGNAL(changed())); connect(m_resourceDocument, SIGNAL(changed()), this, SIGNAL(changed()));
@@ -280,8 +283,20 @@ void ResourceEditorW::onUndoStackChanged(bool canUndo, bool canRedo)
void ResourceEditorW::showContextMenu(const QPoint &globalPoint, const QString &fileName) void ResourceEditorW::showContextMenu(const QPoint &globalPoint, const QString &fileName)
{ {
Core::DocumentManager::populateOpenWithMenu(m_openWithMenu, fileName); Core::DocumentManager::populateOpenWithMenu(m_openWithMenu, fileName);
if (!m_openWithMenu->actions().isEmpty()) if (!m_openWithMenu->actions().isEmpty()) {
m_currentFileName = fileName;
m_contextMenu->popup(globalPoint); m_contextMenu->popup(globalPoint);
}
}
void ResourceEditorW::openCurrentFile()
{
openFile(m_currentFileName);
}
void ResourceEditorW::openFile(const QString &fileName)
{
Core::EditorManager::openEditor(fileName);
} }
void ResourceEditorW::onUndo() void ResourceEditorW::onUndo()

View File

@@ -108,6 +108,8 @@ private slots:
void onUndoStackChanged(bool canUndo, bool canRedo); void onUndoStackChanged(bool canUndo, bool canRedo);
void setShouldAutoSave(bool sad = true) { m_shouldAutoSave = sad; } void setShouldAutoSave(bool sad = true) { m_shouldAutoSave = sad; }
void showContextMenu(const QPoint &globalPoint, const QString &fileName); void showContextMenu(const QPoint &globalPoint, const QString &fileName);
void openCurrentFile();
void openFile(const QString &fileName);
private: private:
const QString m_extension; const QString m_extension;
@@ -121,6 +123,7 @@ private:
bool m_diskIo; bool m_diskIo;
QMenu *m_contextMenu; QMenu *m_contextMenu;
QMenu *m_openWithMenu; QMenu *m_openWithMenu;
QString m_currentFileName;
public: public:
void onUndo(); void onUndo();

View File

@@ -66,6 +66,8 @@ QrcEditor::QrcEditor(QWidget *parent)
connect(m_treeview->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), connect(m_treeview->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
this, SLOT(updateCurrent())); this, SLOT(updateCurrent()));
connect(m_treeview, SIGNAL(dirtyChanged(bool)), this, SIGNAL(dirtyChanged(bool))); connect(m_treeview, SIGNAL(dirtyChanged(bool)), this, SIGNAL(dirtyChanged(bool)));
connect(m_treeview, SIGNAL(itemActivated(QString)),
this, SIGNAL(itemActivated(QString)));
connect(m_treeview, SIGNAL(showContextMenu(QPoint,QString)), connect(m_treeview, SIGNAL(showContextMenu(QPoint,QString)),
this, SIGNAL(showContextMenu(QPoint,QString))); this, SIGNAL(showContextMenu(QPoint,QString)));
m_treeview->setFocus(); m_treeview->setFocus();

View File

@@ -69,6 +69,7 @@ public:
signals: signals:
void dirtyChanged(bool dirty); void dirtyChanged(bool dirty);
void itemActivated(const QString &fileName);
void showContextMenu(const QPoint &globalPos, const QString &fileName); void showContextMenu(const QPoint &globalPos, const QString &fileName);
private slots: private slots:

View File

@@ -190,6 +190,8 @@ ResourceView::ResourceView(QUndoStack *history, QWidget *parent) :
this, SIGNAL(dirtyChanged(bool))); this, SIGNAL(dirtyChanged(bool)));
connect(this, SIGNAL(customContextMenuRequested(QPoint)), connect(this, SIGNAL(customContextMenuRequested(QPoint)),
this, SLOT(showContextMenu(QPoint))); this, SLOT(showContextMenu(QPoint)));
connect(this, SIGNAL(activated(QModelIndex)),
this, SLOT(itemActivated(QModelIndex)));
} }
ResourceView::~ResourceView() ResourceView::~ResourceView()
@@ -432,6 +434,14 @@ void ResourceView::changeValue(const QModelIndex &nodeIndex, NodeProperty proper
} }
} }
void ResourceView::itemActivated(const QModelIndex &index)
{
const QString fileName = m_qrcModel->file(index);
if (fileName.isEmpty())
return;
emit itemActivated(fileName);
}
void ResourceView::showContextMenu(const QPoint &pos) void ResourceView::showContextMenu(const QPoint &pos)
{ {
const QModelIndex index = indexAt(pos); const QModelIndex index = indexAt(pos);

View File

@@ -130,6 +130,7 @@ protected:
signals: signals:
void removeItem(); void removeItem();
void dirtyChanged(bool b); void dirtyChanged(bool b);
void itemActivated(const QString &fileName);
void showContextMenu(const QPoint &globalPos, const QString &fileName); void showContextMenu(const QPoint &globalPos, const QString &fileName);
public: public:
@@ -137,6 +138,7 @@ public:
void changeValue(const QModelIndex &nodeIndex, NodeProperty property, const QString &value); void changeValue(const QModelIndex &nodeIndex, NodeProperty property, const QString &value);
private slots: private slots:
void itemActivated(const QModelIndex &index);
void showContextMenu(const QPoint &pos); void showContextMenu(const QPoint &pos);
private: private: