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>
This commit is contained in:
Eike Ziller
2017-05-08 16:06:35 +02:00
parent 1f6764a54e
commit 2684254fad
7 changed files with 57 additions and 39 deletions

View File

@@ -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))
{
}