forked from qt-creator/qt-creator
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:
committed by
Eike Ziller
parent
9b3e46b08f
commit
dec03a0d6c
@@ -92,6 +92,7 @@ ResourceEditorW::ResourceEditorW(const Core::Context &context,
|
||||
agg->add(new Find::TreeViewFind(m_resourceEditor->treeView()));
|
||||
|
||||
m_resourceEditor->setResourceDragEnabled(true);
|
||||
m_contextMenu->addAction(tr("Open File"), this, SLOT(openCurrentFile()));
|
||||
m_openWithMenu = m_contextMenu->addMenu(tr("Open With"));
|
||||
// Below we need QueuedConnection because otherwise, if this qrc file
|
||||
// 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)));
|
||||
connect(m_resourceEditor, SIGNAL(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)),
|
||||
this, SLOT(setShouldAutoSave()));
|
||||
connect(m_resourceDocument, SIGNAL(changed()), this, SIGNAL(changed()));
|
||||
@@ -280,9 +283,21 @@ void ResourceEditorW::onUndoStackChanged(bool canUndo, bool canRedo)
|
||||
void ResourceEditorW::showContextMenu(const QPoint &globalPoint, const QString &fileName)
|
||||
{
|
||||
Core::DocumentManager::populateOpenWithMenu(m_openWithMenu, fileName);
|
||||
if (!m_openWithMenu->actions().isEmpty())
|
||||
if (!m_openWithMenu->actions().isEmpty()) {
|
||||
m_currentFileName = fileName;
|
||||
m_contextMenu->popup(globalPoint);
|
||||
}
|
||||
}
|
||||
|
||||
void ResourceEditorW::openCurrentFile()
|
||||
{
|
||||
openFile(m_currentFileName);
|
||||
}
|
||||
|
||||
void ResourceEditorW::openFile(const QString &fileName)
|
||||
{
|
||||
Core::EditorManager::openEditor(fileName);
|
||||
}
|
||||
|
||||
void ResourceEditorW::onUndo()
|
||||
{
|
||||
|
||||
@@ -108,6 +108,8 @@ private slots:
|
||||
void onUndoStackChanged(bool canUndo, bool canRedo);
|
||||
void setShouldAutoSave(bool sad = true) { m_shouldAutoSave = sad; }
|
||||
void showContextMenu(const QPoint &globalPoint, const QString &fileName);
|
||||
void openCurrentFile();
|
||||
void openFile(const QString &fileName);
|
||||
|
||||
private:
|
||||
const QString m_extension;
|
||||
@@ -121,6 +123,7 @@ private:
|
||||
bool m_diskIo;
|
||||
QMenu *m_contextMenu;
|
||||
QMenu *m_openWithMenu;
|
||||
QString m_currentFileName;
|
||||
|
||||
public:
|
||||
void onUndo();
|
||||
|
||||
@@ -66,6 +66,8 @@ QrcEditor::QrcEditor(QWidget *parent)
|
||||
connect(m_treeview->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
|
||||
this, SLOT(updateCurrent()));
|
||||
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)),
|
||||
this, SIGNAL(showContextMenu(QPoint,QString)));
|
||||
m_treeview->setFocus();
|
||||
|
||||
@@ -69,6 +69,7 @@ public:
|
||||
|
||||
signals:
|
||||
void dirtyChanged(bool dirty);
|
||||
void itemActivated(const QString &fileName);
|
||||
void showContextMenu(const QPoint &globalPos, const QString &fileName);
|
||||
|
||||
private slots:
|
||||
|
||||
@@ -190,6 +190,8 @@ ResourceView::ResourceView(QUndoStack *history, QWidget *parent) :
|
||||
this, SIGNAL(dirtyChanged(bool)));
|
||||
connect(this, SIGNAL(customContextMenuRequested(QPoint)),
|
||||
this, SLOT(showContextMenu(QPoint)));
|
||||
connect(this, SIGNAL(activated(QModelIndex)),
|
||||
this, SLOT(itemActivated(QModelIndex)));
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
const QModelIndex index = indexAt(pos);
|
||||
|
||||
@@ -130,6 +130,7 @@ protected:
|
||||
signals:
|
||||
void removeItem();
|
||||
void dirtyChanged(bool b);
|
||||
void itemActivated(const QString &fileName);
|
||||
void showContextMenu(const QPoint &globalPos, const QString &fileName);
|
||||
|
||||
public:
|
||||
@@ -137,6 +138,7 @@ public:
|
||||
void changeValue(const QModelIndex &nodeIndex, NodeProperty property, const QString &value);
|
||||
|
||||
private slots:
|
||||
void itemActivated(const QModelIndex &index);
|
||||
void showContextMenu(const QPoint &pos);
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user