forked from qt-creator/qt-creator
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:
@@ -57,7 +57,6 @@ AndroidManifestEditor::AndroidManifestEditor(AndroidManifestEditorWidget *editor
|
|||||||
|
|
||||||
generalAction->setChecked(true);
|
generalAction->setChecked(true);
|
||||||
|
|
||||||
setContext(Core::Context(Constants::ANDROID_MANIFEST_EDITOR_CONTEXT));
|
|
||||||
setWidget(editorWidget);
|
setWidget(editorWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,9 @@ class AndroidTextEditorActionHandler : public TextEditor::TextEditorActionHandle
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit AndroidTextEditorActionHandler(QObject *parent)
|
explicit AndroidTextEditorActionHandler(QObject *parent)
|
||||||
: TextEditorActionHandler(parent, Constants::ANDROID_MANIFEST_EDITOR_CONTEXT)
|
: TextEditorActionHandler(parent,
|
||||||
|
Constants::ANDROID_MANIFEST_EDITOR_ID,
|
||||||
|
Constants::ANDROID_MANIFEST_EDITOR_CONTEXT)
|
||||||
{}
|
{}
|
||||||
private:
|
private:
|
||||||
TextEditor::TextEditorWidget *resolveTextEditorWidget(Core::IEditor *editor) const
|
TextEditor::TextEditorWidget *resolveTextEditorWidget(Core::IEditor *editor) const
|
||||||
|
|||||||
@@ -77,7 +77,6 @@ using namespace Android::Internal;
|
|||||||
namespace {
|
namespace {
|
||||||
const QLatin1String packageNameRegExp("^([a-z]{1}[a-z0-9_]+(\\.[a-zA-Z]{1}[a-zA-Z0-9_]*)*)$");
|
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 infoBarId[] = "Android.AndroidManifestEditor.InfoBar";
|
||||||
const char androidManifestEditorGeneralPaneContextId[] = "AndroidManifestEditorWidget.GeneralWidget";
|
|
||||||
|
|
||||||
bool checkPackageName(const QString &packageName)
|
bool checkPackageName(const QString &packageName)
|
||||||
{
|
{
|
||||||
@@ -126,11 +125,6 @@ AndroidManifestEditorWidget::AndroidManifestEditorWidget()
|
|||||||
|
|
||||||
void AndroidManifestEditorWidget::initializePage()
|
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
|
QWidget *mainWidget = new QWidget; // different name
|
||||||
|
|
||||||
QVBoxLayout *topLayout = new QVBoxLayout(mainWidget);
|
QVBoxLayout *topLayout = new QVBoxLayout(mainWidget);
|
||||||
@@ -1405,5 +1399,17 @@ AndroidManifestTextEditorWidget::AndroidManifestTextEditorWidget(AndroidManifest
|
|||||||
textDocument()->setMimeType(QLatin1String(Constants::ANDROID_MANIFEST_MIME_TYPE));
|
textDocument()->setMimeType(QLatin1String(Constants::ANDROID_MANIFEST_MIME_TYPE));
|
||||||
setupGenericHighlighter();
|
setupGenericHighlighter();
|
||||||
setMarksVisible(false);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,6 +77,10 @@ class AndroidManifestTextEditorWidget : public TextEditor::TextEditorWidget
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit AndroidManifestTextEditorWidget(AndroidManifestEditorWidget *parent);
|
explicit AndroidManifestTextEditorWidget(AndroidManifestEditorWidget *parent);
|
||||||
|
~AndroidManifestTextEditorWidget();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Core::IContext *m_context;
|
||||||
};
|
};
|
||||||
|
|
||||||
class AndroidManifestEditorWidget : public QStackedWidget
|
class AndroidManifestEditorWidget : public QStackedWidget
|
||||||
|
|||||||
@@ -7896,12 +7896,12 @@ void TextEditorFactory::setAutoCompleterCreator(const AutoCompleterCreator &crea
|
|||||||
|
|
||||||
void TextEditorFactory::setEditorActionHandlers(Id contextId, uint optionalActions)
|
void TextEditorFactory::setEditorActionHandlers(Id contextId, uint optionalActions)
|
||||||
{
|
{
|
||||||
new TextEditorActionHandler(this, contextId, optionalActions);
|
new TextEditorActionHandler(this, id(), contextId, optionalActions);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEditorFactory::setEditorActionHandlers(uint optionalActions)
|
void TextEditorFactory::setEditorActionHandlers(uint optionalActions)
|
||||||
{
|
{
|
||||||
new TextEditorActionHandler(this, id(), optionalActions);
|
new TextEditorActionHandler(this, id(), id(), optionalActions);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEditorFactory::addHoverHandler(BaseHoverHandler *handler)
|
void TextEditorFactory::addHoverHandler(BaseHoverHandler *handler)
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ class TextEditorActionHandlerPrivate : public QObject
|
|||||||
Q_DECLARE_TR_FUNCTIONS(TextEditor::Internal::TextEditorActionHandler)
|
Q_DECLARE_TR_FUNCTIONS(TextEditor::Internal::TextEditorActionHandler)
|
||||||
public:
|
public:
|
||||||
TextEditorActionHandlerPrivate(TextEditorActionHandler *parent,
|
TextEditorActionHandlerPrivate(TextEditorActionHandler *parent,
|
||||||
|
Core::Id editorId,
|
||||||
Core::Id contextId,
|
Core::Id contextId,
|
||||||
uint optionalActions);
|
uint optionalActions);
|
||||||
|
|
||||||
@@ -184,13 +185,15 @@ public:
|
|||||||
|
|
||||||
uint m_optionalActions = TextEditorActionHandler::None;
|
uint m_optionalActions = TextEditorActionHandler::None;
|
||||||
QPointer<TextEditorWidget> m_currentEditorWidget;
|
QPointer<TextEditorWidget> m_currentEditorWidget;
|
||||||
|
Core::Id m_editorId;
|
||||||
Core::Id m_contextId;
|
Core::Id m_contextId;
|
||||||
};
|
};
|
||||||
|
|
||||||
TextEditorActionHandlerPrivate::TextEditorActionHandlerPrivate
|
TextEditorActionHandlerPrivate::TextEditorActionHandlerPrivate
|
||||||
(TextEditorActionHandler *parent, Core::Id contextId, uint optionalActions)
|
(TextEditorActionHandler *parent, Core::Id editorId, Core::Id contextId, uint optionalActions)
|
||||||
: q(parent)
|
: q(parent)
|
||||||
, m_optionalActions(optionalActions)
|
, m_optionalActions(optionalActions)
|
||||||
|
, m_editorId(editorId)
|
||||||
, m_contextId(contextId)
|
, m_contextId(contextId)
|
||||||
{
|
{
|
||||||
createActions();
|
createActions();
|
||||||
@@ -501,18 +504,22 @@ void TextEditorActionHandlerPrivate::createActions()
|
|||||||
|
|
||||||
void TextEditorActionHandlerPrivate::updateActions()
|
void TextEditorActionHandlerPrivate::updateActions()
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_currentEditorWidget, return);
|
bool isWritable = m_currentEditorWidget && !m_currentEditorWidget->isReadOnly();
|
||||||
bool isWritable = !m_currentEditorWidget->isReadOnly();
|
|
||||||
foreach (QAction *a, m_modifyingActions)
|
foreach (QAction *a, m_modifyingActions)
|
||||||
a->setEnabled(isWritable);
|
a->setEnabled(isWritable);
|
||||||
m_formatAction->setEnabled((m_optionalActions & TextEditorActionHandler::Format) && isWritable);
|
m_formatAction->setEnabled((m_optionalActions & TextEditorActionHandler::Format) && isWritable);
|
||||||
m_unCommentSelectionAction->setEnabled((m_optionalActions & TextEditorActionHandler::UnCommentSelection) && isWritable);
|
m_unCommentSelectionAction->setEnabled((m_optionalActions & TextEditorActionHandler::UnCommentSelection) && isWritable);
|
||||||
m_visualizeWhitespaceAction->setChecked(m_currentEditorWidget->displaySettings().m_visualizeWhitespace);
|
m_visualizeWhitespaceAction->setEnabled(m_currentEditorWidget);
|
||||||
m_textWrappingAction->setChecked(m_currentEditorWidget->displaySettings().m_textWrapping);
|
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());
|
updateRedoAction(m_currentEditorWidget && m_currentEditorWidget->document()->isRedoAvailable());
|
||||||
updateUndoAction(m_currentEditorWidget->document()->isUndoAvailable());
|
updateUndoAction(m_currentEditorWidget && m_currentEditorWidget->document()->isUndoAvailable());
|
||||||
updateCopyAction(m_currentEditorWidget->textCursor().hasSelection());
|
updateCopyAction(m_currentEditorWidget && m_currentEditorWidget->textCursor().hasSelection());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEditorActionHandlerPrivate::updateRedoAction(bool on)
|
void TextEditorActionHandlerPrivate::updateRedoAction(bool on)
|
||||||
@@ -527,9 +534,9 @@ void TextEditorActionHandlerPrivate::updateUndoAction(bool on)
|
|||||||
|
|
||||||
void TextEditorActionHandlerPrivate::updateCopyAction(bool hasCopyableText)
|
void TextEditorActionHandlerPrivate::updateCopyAction(bool hasCopyableText)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_currentEditorWidget, return);
|
|
||||||
if (m_cutAction)
|
if (m_cutAction)
|
||||||
m_cutAction->setEnabled(hasCopyableText && !m_currentEditorWidget->isReadOnly());
|
m_cutAction->setEnabled(hasCopyableText && m_currentEditorWidget
|
||||||
|
&& !m_currentEditorWidget->isReadOnly());
|
||||||
if (m_copyAction)
|
if (m_copyAction)
|
||||||
m_copyAction->setEnabled(hasCopyableText);
|
m_copyAction->setEnabled(hasCopyableText);
|
||||||
}
|
}
|
||||||
@@ -540,29 +547,28 @@ void TextEditorActionHandlerPrivate::updateCurrentEditor(Core::IEditor *editor)
|
|||||||
m_currentEditorWidget->disconnect(this);
|
m_currentEditorWidget->disconnect(this);
|
||||||
m_currentEditorWidget = 0;
|
m_currentEditorWidget = 0;
|
||||||
|
|
||||||
// don't need to do anything if the editor's context doesn't match
|
if (editor && editor->document()->id() == m_editorId) {
|
||||||
// (our actions will be disabled because our context will not be active)
|
TextEditorWidget *editorWidget = q->resolveTextEditorWidget(editor);
|
||||||
if (!editor || !editor->context().contains(m_contextId))
|
QTC_ASSERT(editorWidget, return); // editor has our id, so shouldn't happen
|
||||||
return;
|
m_currentEditorWidget = editorWidget;
|
||||||
|
connect(editorWidget, &QPlainTextEdit::undoAvailable,
|
||||||
TextEditorWidget *editorWidget = q->resolveTextEditorWidget(editor);
|
this, &TextEditorActionHandlerPrivate::updateUndoAction);
|
||||||
QTC_ASSERT(editorWidget, return); // editor has our context id, so shouldn't happen
|
connect(editorWidget, &QPlainTextEdit::redoAvailable,
|
||||||
m_currentEditorWidget = editorWidget;
|
this, &TextEditorActionHandlerPrivate::updateRedoAction);
|
||||||
connect(editorWidget, &QPlainTextEdit::undoAvailable,
|
connect(editorWidget, &QPlainTextEdit::copyAvailable,
|
||||||
this, &TextEditorActionHandlerPrivate::updateUndoAction);
|
this, &TextEditorActionHandlerPrivate::updateCopyAction);
|
||||||
connect(editorWidget, &QPlainTextEdit::redoAvailable,
|
connect(editorWidget, &TextEditorWidget::readOnlyChanged,
|
||||||
this, &TextEditorActionHandlerPrivate::updateRedoAction);
|
this, &TextEditorActionHandlerPrivate::updateActions);
|
||||||
connect(editorWidget, &QPlainTextEdit::copyAvailable,
|
}
|
||||||
this, &TextEditorActionHandlerPrivate::updateCopyAction);
|
|
||||||
connect(editorWidget, &TextEditorWidget::readOnlyChanged,
|
|
||||||
this, &TextEditorActionHandlerPrivate::updateActions);
|
|
||||||
updateActions();
|
updateActions();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|
||||||
TextEditorActionHandler::TextEditorActionHandler(QObject *parent, Core::Id contextId, uint optionalActions)
|
TextEditorActionHandler::TextEditorActionHandler(QObject *parent, Core::Id editorId,
|
||||||
: QObject(parent), d(new Internal::TextEditorActionHandlerPrivate(this, contextId, optionalActions))
|
Core::Id contextId, uint optionalActions)
|
||||||
|
: QObject(parent), d(new Internal::TextEditorActionHandlerPrivate(this, editorId, contextId,
|
||||||
|
optionalActions))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,8 @@ public:
|
|||||||
JumpToFileUnderCursor = 16
|
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();
|
~TextEditorActionHandler();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
Reference in New Issue
Block a user