Qnx: Fixing Bar Descriptor XML file editor to provide editor actions

BarDescriptorEditorWidget is using TextEditorActionHandler class
to provide editor actions e.g. Undo, Redo, Cut, Copy, Paste accessible
from main menu and using shortcuts.

TextEditorActionHandler.resolveTextEditorWidget() virtual function is
added to all resolving TextEditorWidget for an Editor. This allows
to have IEditor->widget() to have non-BaseTextEditorWidget instances too.

Task-number: QTCREATORBUG-10040
Change-Id: I6f433fc307c13ef2b2a20c48e6473826f2619544
Reviewed-by: David Kaspar <dkaspar@blackberry.com>
Reviewed-by: David Schulz <david.schulz@digia.com>
Reviewed-by: Tobias Nätterlund <tobias.naetterlund@kdab.com>
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
Reviewed-by: Nicolas Arnaud-Cormos <nicolas@kdab.com>
This commit is contained in:
David Kaspar
2013-10-17 09:16:18 +02:00
parent ab4207acf2
commit 3d2ef178f6
8 changed files with 69 additions and 4 deletions

View File

@@ -39,6 +39,8 @@
#include <projectexplorer/task.h> #include <projectexplorer/task.h>
#include <projectexplorer/taskhub.h> #include <projectexplorer/taskhub.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <texteditor/texteditorconstants.h>
#include <texteditor/basetexteditor.h>
#include <QAction> #include <QAction>
#include <QToolBar> #include <QToolBar>
@@ -80,6 +82,9 @@ BarDescriptorEditor::BarDescriptorEditor(BarDescriptorEditorWidget *editorWidget
m_actionGroup->addAction(sourceAction); m_actionGroup->addAction(sourceAction);
generalAction->setChecked(true); generalAction->setChecked(true);
setContext(Core::Context(Constants::QNX_BAR_DESCRIPTOR_EDITOR_CONTEXT,
TextEditor::Constants::C_TEXTEDITOR));
} }
bool BarDescriptorEditor::open(QString *errorString, const QString &fileName, const QString &realFileName) bool BarDescriptorEditor::open(QString *errorString, const QString &fileName, const QString &realFileName)

View File

@@ -36,20 +36,42 @@
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h> #include <coreplugin/editormanager/ieditor.h>
#include <texteditor/texteditoractionhandler.h>
using namespace Qnx; using namespace Qnx;
using namespace Qnx::Internal; using namespace Qnx::Internal;
class BarDescriptorActionHandler : public TextEditor::TextEditorActionHandler
{
public:
BarDescriptorActionHandler()
: TextEditor::TextEditorActionHandler(Constants::QNX_BAR_DESCRIPTOR_EDITOR_CONTEXT)
{
}
protected:
TextEditor::BaseTextEditorWidget *resolveTextEditorWidget(Core::IEditor *editor) const
{
BarDescriptorEditorWidget *w = qobject_cast<BarDescriptorEditorWidget *>(editor->widget());
return w ? w->sourceWidget() : 0;
}
};
BarDescriptorEditorFactory::BarDescriptorEditorFactory(QObject *parent) BarDescriptorEditorFactory::BarDescriptorEditorFactory(QObject *parent)
: Core::IEditorFactory(parent) : Core::IEditorFactory(parent)
, m_actionHandler(new BarDescriptorActionHandler)
{ {
setId(Constants::QNX_BAR_DESCRIPTOR_EDITOR_ID); setId(Constants::QNX_BAR_DESCRIPTOR_EDITOR_ID);
setDisplayName(tr("Bar descriptor editor")); setDisplayName(tr("Bar descriptor editor"));
addMimeType(Constants::QNX_BAR_DESCRIPTOR_MIME_TYPE); addMimeType(Constants::QNX_BAR_DESCRIPTOR_MIME_TYPE);
} }
BarDescriptorEditorFactory::~BarDescriptorEditorFactory()
{
delete m_actionHandler;
}
Core::IEditor *BarDescriptorEditorFactory::createEditor(QWidget *parent) Core::IEditor *BarDescriptorEditorFactory::createEditor(QWidget *parent)
{ {
BarDescriptorEditorWidget *editorWidget = new BarDescriptorEditorWidget(parent); BarDescriptorEditorWidget *editorWidget = new BarDescriptorEditorWidget(parent, m_actionHandler);
return editorWidget->editor(); return editorWidget->editor();
} }

View File

@@ -34,6 +34,10 @@
#include <coreplugin/editormanager/ieditorfactory.h> #include <coreplugin/editormanager/ieditorfactory.h>
namespace TextEditor {
class TextEditorActionHandler;
}
namespace Qnx { namespace Qnx {
namespace Internal { namespace Internal {
@@ -43,8 +47,12 @@ class BarDescriptorEditorFactory : public Core::IEditorFactory
public: public:
explicit BarDescriptorEditorFactory(QObject *parent = 0); explicit BarDescriptorEditorFactory(QObject *parent = 0);
~BarDescriptorEditorFactory();
Core::IEditor *createEditor(QWidget *parent); Core::IEditor *createEditor(QWidget *parent);
private:
TextEditor::TextEditorActionHandler *m_actionHandler;
}; };
} // namespace Internal } // namespace Internal

View File

@@ -41,18 +41,29 @@
#include "bardescriptoreditorpackageinformationwidget.h" #include "bardescriptoreditorpackageinformationwidget.h"
#include "bardescriptoreditorpermissionswidget.h" #include "bardescriptoreditorpermissionswidget.h"
#include <coreplugin/icore.h>
#include <projectexplorer/iprojectproperties.h> #include <projectexplorer/iprojectproperties.h>
#include <projectexplorer/projectwindow.h> #include <projectexplorer/projectwindow.h>
#include <texteditor/plaintexteditor.h> #include <texteditor/plaintexteditor.h>
#include <texteditor/texteditoractionhandler.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/texteditorconstants.h>
using namespace Qnx; using namespace Qnx;
using namespace Qnx::Internal; using namespace Qnx::Internal;
BarDescriptorEditorWidget::BarDescriptorEditorWidget(QWidget *parent) BarDescriptorEditorWidget::BarDescriptorEditorWidget(
QWidget *parent, TextEditor::TextEditorActionHandler *handler)
: QStackedWidget(parent) : QStackedWidget(parent)
, m_editor(0) , m_editor(0)
, m_handler(handler)
, m_dirty(false) , m_dirty(false)
{ {
Core::IContext *myContext = new Core::IContext(this);
myContext->setWidget(this);
myContext->setContext(Core::Context(Constants::QNX_BAR_DESCRIPTOR_EDITOR_CONTEXT, TextEditor::Constants::C_TEXTEDITOR));
Core::ICore::addContextObject(myContext);
initGeneralPage(); initGeneralPage();
initApplicationPage(); initApplicationPage();
initAssetsPage(); initAssetsPage();
@@ -149,6 +160,8 @@ void BarDescriptorEditorWidget::initSourcePage()
m_xmlSourceWidget = new TextEditor::PlainTextEditorWidget(this); m_xmlSourceWidget = new TextEditor::PlainTextEditorWidget(this);
addWidget(m_xmlSourceWidget); addWidget(m_xmlSourceWidget);
TextEditor::TextEditorSettings::initializeEditor(m_xmlSourceWidget);
m_handler->setupActions(m_xmlSourceWidget);
m_xmlSourceWidget->configure(QLatin1String(Constants::QNX_BAR_DESCRIPTOR_MIME_TYPE)); m_xmlSourceWidget->configure(QLatin1String(Constants::QNX_BAR_DESCRIPTOR_MIME_TYPE));
connect(m_xmlSourceWidget, SIGNAL(textChanged()), this, SLOT(setDirty())); connect(m_xmlSourceWidget, SIGNAL(textChanged()), this, SLOT(setDirty()));
} }
@@ -204,6 +217,11 @@ BarDescriptorEditorAssetsWidget *BarDescriptorEditorWidget::assetsWidget() const
return m_assetsWidget; return m_assetsWidget;
} }
TextEditor::BaseTextEditorWidget *BarDescriptorEditorWidget::sourceWidget() const
{
return m_xmlSourceWidget;
}
void BarDescriptorEditorWidget::setFilePath(const QString &filePath) void BarDescriptorEditorWidget::setFilePath(const QString &filePath)
{ {
Core::IDocument *doc = m_xmlSourceWidget->editorDocument(); Core::IDocument *doc = m_xmlSourceWidget->editorDocument();

View File

@@ -46,6 +46,8 @@ class PanelsWidget;
namespace TextEditor { namespace TextEditor {
class PlainTextEditorWidget; class PlainTextEditorWidget;
class TextEditorActionHandler;
class BaseTextEditorWidget;
} }
namespace Qnx { namespace Qnx {
@@ -65,7 +67,7 @@ class BarDescriptorEditorWidget : public QStackedWidget
Q_OBJECT Q_OBJECT
public: public:
explicit BarDescriptorEditorWidget(QWidget *parent = 0); explicit BarDescriptorEditorWidget(QWidget *parent, TextEditor::TextEditorActionHandler *handler);
Core::IEditor *editor() const; Core::IEditor *editor() const;
@@ -79,6 +81,8 @@ public:
BarDescriptorEditorAssetsWidget *assetsWidget() const; BarDescriptorEditorAssetsWidget *assetsWidget() const;
TextEditor::BaseTextEditorWidget *sourceWidget() const;
void setFilePath(const QString &filePath); void setFilePath(const QString &filePath);
QString xmlSource() const; QString xmlSource() const;
void setXmlSource(const QString &xmlSource); void setXmlSource(const QString &xmlSource);
@@ -103,6 +107,7 @@ private:
mutable Core::IEditor *m_editor; mutable Core::IEditor *m_editor;
TextEditor::TextEditorActionHandler *m_handler;
bool m_dirty; bool m_dirty;
// New UI // New UI

View File

@@ -99,6 +99,7 @@ const char QNX_BB_SIGNING_ID[] = "ZZ.BlackBerry Signing Infrastructure Configura
const char QNX_BAR_DESCRIPTOR_MIME_TYPE[] = "application/vnd.rim.qnx.bar_descriptor"; const char QNX_BAR_DESCRIPTOR_MIME_TYPE[] = "application/vnd.rim.qnx.bar_descriptor";
const char QNX_BAR_DESCRIPTOR_EDITOR_ID[] = "Qnx.BarDescriptorEditor"; const char QNX_BAR_DESCRIPTOR_EDITOR_ID[] = "Qnx.BarDescriptorEditor";
const char QNX_BAR_DESCRIPTOR_EDITOR_CONTEXT[] = "Qnx.BarDescriptorEditor";
const char QNX_TASK_CATEGORY_BARDESCRIPTOR[] = "Task.Category.BarDescriptor"; const char QNX_TASK_CATEGORY_BARDESCRIPTOR[] = "Task.Category.BarDescriptor";

View File

@@ -560,6 +560,11 @@ FUNCTION(gotoNextWordCamelCase)
FUNCTION(gotoNextWordCamelCaseWithSelection) FUNCTION(gotoNextWordCamelCaseWithSelection)
BaseTextEditorWidget *TextEditorActionHandler::resolveTextEditorWidget(Core::IEditor *editor) const
{
return qobject_cast<BaseTextEditorWidget *>(editor->widget());
}
void TextEditorActionHandler::updateCurrentEditor(Core::IEditor *editor) void TextEditorActionHandler::updateCurrentEditor(Core::IEditor *editor)
{ {
m_currentEditor = 0; m_currentEditor = 0;
@@ -567,7 +572,7 @@ void TextEditorActionHandler::updateCurrentEditor(Core::IEditor *editor)
if (!editor) if (!editor)
return; return;
BaseTextEditorWidget *baseEditor = qobject_cast<BaseTextEditorWidget *>(editor->widget()); BaseTextEditorWidget *baseEditor = resolveTextEditorWidget(editor);
if (baseEditor && baseEditor->actionHack() == this) { if (baseEditor && baseEditor->actionHack() == this) {
m_currentEditor = baseEditor; m_currentEditor = baseEditor;

View File

@@ -79,6 +79,7 @@ public slots:
void updateCopyAction(); void updateCopyAction();
protected: protected:
virtual BaseTextEditorWidget *resolveTextEditorWidget(Core::IEditor *editor) const;
const QPointer<BaseTextEditorWidget> &currentEditor() const; const QPointer<BaseTextEditorWidget> &currentEditor() const;
QAction *registerAction(const Core::Id &id, QAction *registerAction(const Core::Id &id,