summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2017-05-08 16:06:35 +0200
committerEike Ziller <eike.ziller@qt.io>2017-05-18 07:08:56 +0000
commit2684254fadad83dd25ae5e62141c8fc11a638543 (patch)
tree64ddd61c2ea520b574a3b96645c545e8aef76dd5
parent1f6764a54e4d508826f72a090bcb68fcd16a568d (diff)
downloadqt-creator-2684254fadad83dd25ae5e62141c8fc11a638543.tar.gz
Fix text based Android manifest editor actions
All text editor actions were disabled. We want the actions to be enabled when the focus is in the text editor widget in the Android manifest editor. For this the text editor action handler must differentiate between the _editor_ and the _context_ that it handles. The one for the text based manifest editor handles the manifest editor, but the context is specific to the text editor part. Change-Id: Ib91cc763cb27333a7d5b6e5b036dfead33961871 Reviewed-by: David Schulz <david.schulz@qt.io>
-rw-r--r--src/plugins/android/androidmanifesteditor.cpp1
-rw-r--r--src/plugins/android/androidmanifesteditorfactory.cpp4
-rw-r--r--src/plugins/android/androidmanifesteditorwidget.cpp18
-rw-r--r--src/plugins/android/androidmanifesteditorwidget.h4
-rw-r--r--src/plugins/texteditor/texteditor.cpp4
-rw-r--r--src/plugins/texteditor/texteditoractionhandler.cpp62
-rw-r--r--src/plugins/texteditor/texteditoractionhandler.h3
7 files changed, 57 insertions, 39 deletions
diff --git a/src/plugins/android/androidmanifesteditor.cpp b/src/plugins/android/androidmanifesteditor.cpp
index 559b5fb0dd..de0babde15 100644
--- a/src/plugins/android/androidmanifesteditor.cpp
+++ b/src/plugins/android/androidmanifesteditor.cpp
@@ -57,7 +57,6 @@ AndroidManifestEditor::AndroidManifestEditor(AndroidManifestEditorWidget *editor
generalAction->setChecked(true);
- setContext(Core::Context(Constants::ANDROID_MANIFEST_EDITOR_CONTEXT));
setWidget(editorWidget);
}
diff --git a/src/plugins/android/androidmanifesteditorfactory.cpp b/src/plugins/android/androidmanifesteditorfactory.cpp
index b120bee1a7..2dba95f0f5 100644
--- a/src/plugins/android/androidmanifesteditorfactory.cpp
+++ b/src/plugins/android/androidmanifesteditorfactory.cpp
@@ -39,7 +39,9 @@ class AndroidTextEditorActionHandler : public TextEditor::TextEditorActionHandle
{
public:
explicit AndroidTextEditorActionHandler(QObject *parent)
- : TextEditorActionHandler(parent, Constants::ANDROID_MANIFEST_EDITOR_CONTEXT)
+ : TextEditorActionHandler(parent,
+ Constants::ANDROID_MANIFEST_EDITOR_ID,
+ Constants::ANDROID_MANIFEST_EDITOR_CONTEXT)
{}
private:
TextEditor::TextEditorWidget *resolveTextEditorWidget(Core::IEditor *editor) const
diff --git a/src/plugins/android/androidmanifesteditorwidget.cpp b/src/plugins/android/androidmanifesteditorwidget.cpp
index 70d1ece18e..5bcd699816 100644
--- a/src/plugins/android/androidmanifesteditorwidget.cpp
+++ b/src/plugins/android/androidmanifesteditorwidget.cpp
@@ -77,7 +77,6 @@ using namespace Android::Internal;
namespace {
const QLatin1String packageNameRegExp("^([a-z]{1}[a-z0-9_]+(\\.[a-zA-Z]{1}[a-zA-Z0-9_]*)*)$");
const char infoBarId[] = "Android.AndroidManifestEditor.InfoBar";
-const char androidManifestEditorGeneralPaneContextId[] = "AndroidManifestEditorWidget.GeneralWidget";
bool checkPackageName(const QString &packageName)
{
@@ -126,11 +125,6 @@ AndroidManifestEditorWidget::AndroidManifestEditorWidget()
void AndroidManifestEditorWidget::initializePage()
{
- Core::IContext *myContext = new Core::IContext(this);
- myContext->setWidget(this);
- myContext->setContext(Core::Context(androidManifestEditorGeneralPaneContextId)); // where is the context used?
- Core::ICore::addContextObject(myContext);
-
QWidget *mainWidget = new QWidget; // different name
QVBoxLayout *topLayout = new QVBoxLayout(mainWidget);
@@ -1405,5 +1399,17 @@ AndroidManifestTextEditorWidget::AndroidManifestTextEditorWidget(AndroidManifest
textDocument()->setMimeType(QLatin1String(Constants::ANDROID_MANIFEST_MIME_TYPE));
setupGenericHighlighter();
setMarksVisible(false);
+
+ // this context is used by the TextEditorActionHandler registered for the text editor in
+ // the AndroidManifestEditorFactory
+ m_context = new Core::IContext(this);
+ m_context->setWidget(this);
+ m_context->setContext(Core::Context(Constants::ANDROID_MANIFEST_EDITOR_CONTEXT));
+ Core::ICore::addContextObject(m_context);
+}
+
+AndroidManifestTextEditorWidget::~AndroidManifestTextEditorWidget()
+{
+ Core::ICore::removeContextObject(m_context);
}
diff --git a/src/plugins/android/androidmanifesteditorwidget.h b/src/plugins/android/androidmanifesteditorwidget.h
index 9dab5e8d1a..39cb61ef64 100644
--- a/src/plugins/android/androidmanifesteditorwidget.h
+++ b/src/plugins/android/androidmanifesteditorwidget.h
@@ -77,6 +77,10 @@ class AndroidManifestTextEditorWidget : public TextEditor::TextEditorWidget
{
public:
explicit AndroidManifestTextEditorWidget(AndroidManifestEditorWidget *parent);
+ ~AndroidManifestTextEditorWidget();
+
+private:
+ Core::IContext *m_context;
};
class AndroidManifestEditorWidget : public QStackedWidget
diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp
index 99470287e6..4531d7979a 100644
--- a/src/plugins/texteditor/texteditor.cpp
+++ b/src/plugins/texteditor/texteditor.cpp
@@ -7896,12 +7896,12 @@ void TextEditorFactory::setAutoCompleterCreator(const AutoCompleterCreator &crea
void TextEditorFactory::setEditorActionHandlers(Id contextId, uint optionalActions)
{
- new TextEditorActionHandler(this, contextId, optionalActions);
+ new TextEditorActionHandler(this, id(), contextId, optionalActions);
}
void TextEditorFactory::setEditorActionHandlers(uint optionalActions)
{
- new TextEditorActionHandler(this, id(), optionalActions);
+ new TextEditorActionHandler(this, id(), id(), optionalActions);
}
void TextEditorFactory::addHoverHandler(BaseHoverHandler *handler)
diff --git a/src/plugins/texteditor/texteditoractionhandler.cpp b/src/plugins/texteditor/texteditoractionhandler.cpp
index fe550bc445..3c4eab5687 100644
--- a/src/plugins/texteditor/texteditoractionhandler.cpp
+++ b/src/plugins/texteditor/texteditoractionhandler.cpp
@@ -54,6 +54,7 @@ class TextEditorActionHandlerPrivate : public QObject
Q_DECLARE_TR_FUNCTIONS(TextEditor::Internal::TextEditorActionHandler)
public:
TextEditorActionHandlerPrivate(TextEditorActionHandler *parent,
+ Core::Id editorId,
Core::Id contextId,
uint optionalActions);
@@ -184,13 +185,15 @@ public:
uint m_optionalActions = TextEditorActionHandler::None;
QPointer<TextEditorWidget> m_currentEditorWidget;
+ Core::Id m_editorId;
Core::Id m_contextId;
};
TextEditorActionHandlerPrivate::TextEditorActionHandlerPrivate
- (TextEditorActionHandler *parent, Core::Id contextId, uint optionalActions)
+ (TextEditorActionHandler *parent, Core::Id editorId, Core::Id contextId, uint optionalActions)
: q(parent)
, m_optionalActions(optionalActions)
+ , m_editorId(editorId)
, m_contextId(contextId)
{
createActions();
@@ -501,18 +504,22 @@ void TextEditorActionHandlerPrivate::createActions()
void TextEditorActionHandlerPrivate::updateActions()
{
- QTC_ASSERT(m_currentEditorWidget, return);
- bool isWritable = !m_currentEditorWidget->isReadOnly();
+ bool isWritable = m_currentEditorWidget && !m_currentEditorWidget->isReadOnly();
foreach (QAction *a, m_modifyingActions)
a->setEnabled(isWritable);
m_formatAction->setEnabled((m_optionalActions & TextEditorActionHandler::Format) && isWritable);
m_unCommentSelectionAction->setEnabled((m_optionalActions & TextEditorActionHandler::UnCommentSelection) && isWritable);
- m_visualizeWhitespaceAction->setChecked(m_currentEditorWidget->displaySettings().m_visualizeWhitespace);
- m_textWrappingAction->setChecked(m_currentEditorWidget->displaySettings().m_textWrapping);
+ m_visualizeWhitespaceAction->setEnabled(m_currentEditorWidget);
+ m_textWrappingAction->setEnabled(m_currentEditorWidget);
+ if (m_currentEditorWidget) {
+ m_visualizeWhitespaceAction->setChecked(
+ m_currentEditorWidget->displaySettings().m_visualizeWhitespace);
+ m_textWrappingAction->setChecked(m_currentEditorWidget->displaySettings().m_textWrapping);
+ }
- updateRedoAction(m_currentEditorWidget->document()->isRedoAvailable());
- updateUndoAction(m_currentEditorWidget->document()->isUndoAvailable());
- updateCopyAction(m_currentEditorWidget->textCursor().hasSelection());
+ updateRedoAction(m_currentEditorWidget && m_currentEditorWidget->document()->isRedoAvailable());
+ updateUndoAction(m_currentEditorWidget && m_currentEditorWidget->document()->isUndoAvailable());
+ updateCopyAction(m_currentEditorWidget && m_currentEditorWidget->textCursor().hasSelection());
}
void TextEditorActionHandlerPrivate::updateRedoAction(bool on)
@@ -527,9 +534,9 @@ void TextEditorActionHandlerPrivate::updateUndoAction(bool on)
void TextEditorActionHandlerPrivate::updateCopyAction(bool hasCopyableText)
{
- QTC_ASSERT(m_currentEditorWidget, return);
if (m_cutAction)
- m_cutAction->setEnabled(hasCopyableText && !m_currentEditorWidget->isReadOnly());
+ m_cutAction->setEnabled(hasCopyableText && m_currentEditorWidget
+ && !m_currentEditorWidget->isReadOnly());
if (m_copyAction)
m_copyAction->setEnabled(hasCopyableText);
}
@@ -540,29 +547,28 @@ void TextEditorActionHandlerPrivate::updateCurrentEditor(Core::IEditor *editor)
m_currentEditorWidget->disconnect(this);
m_currentEditorWidget = 0;
- // don't need to do anything if the editor's context doesn't match
- // (our actions will be disabled because our context will not be active)
- if (!editor || !editor->context().contains(m_contextId))
- return;
-
- TextEditorWidget *editorWidget = q->resolveTextEditorWidget(editor);
- QTC_ASSERT(editorWidget, return); // editor has our context id, so shouldn't happen
- m_currentEditorWidget = editorWidget;
- connect(editorWidget, &QPlainTextEdit::undoAvailable,
- this, &TextEditorActionHandlerPrivate::updateUndoAction);
- connect(editorWidget, &QPlainTextEdit::redoAvailable,
- this, &TextEditorActionHandlerPrivate::updateRedoAction);
- connect(editorWidget, &QPlainTextEdit::copyAvailable,
- this, &TextEditorActionHandlerPrivate::updateCopyAction);
- connect(editorWidget, &TextEditorWidget::readOnlyChanged,
- this, &TextEditorActionHandlerPrivate::updateActions);
+ if (editor && editor->document()->id() == m_editorId) {
+ TextEditorWidget *editorWidget = q->resolveTextEditorWidget(editor);
+ QTC_ASSERT(editorWidget, return); // editor has our id, so shouldn't happen
+ m_currentEditorWidget = editorWidget;
+ connect(editorWidget, &QPlainTextEdit::undoAvailable,
+ this, &TextEditorActionHandlerPrivate::updateUndoAction);
+ connect(editorWidget, &QPlainTextEdit::redoAvailable,
+ this, &TextEditorActionHandlerPrivate::updateRedoAction);
+ connect(editorWidget, &QPlainTextEdit::copyAvailable,
+ this, &TextEditorActionHandlerPrivate::updateCopyAction);
+ connect(editorWidget, &TextEditorWidget::readOnlyChanged,
+ this, &TextEditorActionHandlerPrivate::updateActions);
+ }
updateActions();
}
} // namespace Internal
-TextEditorActionHandler::TextEditorActionHandler(QObject *parent, Core::Id contextId, uint optionalActions)
- : QObject(parent), d(new Internal::TextEditorActionHandlerPrivate(this, contextId, optionalActions))
+TextEditorActionHandler::TextEditorActionHandler(QObject *parent, Core::Id editorId,
+ Core::Id contextId, uint optionalActions)
+ : QObject(parent), d(new Internal::TextEditorActionHandlerPrivate(this, editorId, contextId,
+ optionalActions))
{
}
diff --git a/src/plugins/texteditor/texteditoractionhandler.h b/src/plugins/texteditor/texteditoractionhandler.h
index 02067ae12d..0b99c3b9b7 100644
--- a/src/plugins/texteditor/texteditoractionhandler.h
+++ b/src/plugins/texteditor/texteditoractionhandler.h
@@ -55,7 +55,8 @@ public:
JumpToFileUnderCursor = 16
};
- explicit TextEditorActionHandler(QObject *parent, Core::Id contextId, uint optionalActions = None);
+ explicit TextEditorActionHandler(QObject *parent, Core::Id editorId, Core::Id contextId,
+ uint optionalActions = None);
~TextEditorActionHandler();
protected: