From 440a73206ddbd37fffc400920383cbc8450d8dab Mon Sep 17 00:00:00 2001 From: "James D. Forrester" Date: Tue, 21 Feb 2017 17:42:30 -0800 Subject: [PATCH] For the mode switch tool, show a different tooltip when disabled Bug: T158723 Change-Id: I8c397e9b10c51d78c0b0f18c494ca9f36400d23e --- extension.json | 4 +++- modules/ve-mw/i18n/en.json | 1 + modules/ve-mw/i18n/qqq.json | 1 + modules/ve-mw/ui/tools/ve.ui.MWEditModeTool.js | 14 +++++++++++++- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/extension.json b/extension.json index a5132f70c3..5a4a5eac36 100644 --- a/extension.json +++ b/extension.json @@ -319,7 +319,8 @@ "tooltip-ca-editsource", "tooltip-ca-ve-edit", "visualeditor-ca-editsource-section", - "visualeditor-mweditmodeve-tool" + "visualeditor-mweditmodeve-tool", + "visualeditor-mweditmodeve-tool-unavailable" ], "position": "top" }, @@ -1144,6 +1145,7 @@ "visualeditor-mweditmodeve-showagain", "visualeditor-mweditmodeve-title", "visualeditor-mweditmodeve-tool", + "visualeditor-mweditmodeve-tool-unavailable", "visualeditor-mweditmodeve-warning", "visualeditor-mweditmodewt-popup-body", "visualeditor-mweditmodewt-popup-title", diff --git a/modules/ve-mw/i18n/en.json b/modules/ve-mw/i18n/en.json index 5dfe4c6dcd..9814f50a00 100644 --- a/modules/ve-mw/i18n/en.json +++ b/modules/ve-mw/i18n/en.json @@ -285,6 +285,7 @@ "visualeditor-mweditmodeve-showagain": "Don't show this message again", "visualeditor-mweditmodeve-title": "Switch to visual editing?", "visualeditor-mweditmodeve-tool": "Switch to visual editing", + "visualeditor-mweditmodeve-tool-unavailable": "Visual editing is not available here", "visualeditor-mweditmodeve-warning": "You are switching to visual editing.\nDo you want to continue?", "visualeditor-mweditmodewt-popup-body": "You can switch back to source editing at any time by clicking on this icon.", "visualeditor-mweditmodewt-popup-title": "You have switched to visual editing", diff --git a/modules/ve-mw/i18n/qqq.json b/modules/ve-mw/i18n/qqq.json index 6a138e3599..8cb78fb9ef 100644 --- a/modules/ve-mw/i18n/qqq.json +++ b/modules/ve-mw/i18n/qqq.json @@ -298,6 +298,7 @@ "visualeditor-mweditmodeve-showagain": "Label for the checkboxes to not show one of the 'switched to visual mode' or 'switched to source mode' popups again", "visualeditor-mweditmodeve-title": "Title of dialog to confirm switching to visual mode.", "visualeditor-mweditmodeve-tool": "Label for tool that changes edit mode to visual editing.", + "visualeditor-mweditmodeve-tool-unavailable": "Label for tool that changes edit mode to visual editing when it is not available.", "visualeditor-mweditmodeve-warning": "Warning message show before changing edit mode to visual editing. It may allow the user to keep the changes using the message {{msg-mw|Visualeditor-mweditmodesource-warning-switch}}, or instaed that they'd need to start source editing from scratch using {{msg-mw|Visualeditor-mweditmodesource-warning-switch-discard}}.", "visualeditor-mweditmodewt-popup-body": "Body text of popup shown after switching to visual mode from source mode", "visualeditor-mweditmodewt-popup-title": "Title of popup shown after switching to visual mode from source mode", diff --git a/modules/ve-mw/ui/tools/ve.ui.MWEditModeTool.js b/modules/ve-mw/ui/tools/ve.ui.MWEditModeTool.js index 375c7acafa..3315472cf6 100644 --- a/modules/ve-mw/ui/tools/ve.ui.MWEditModeTool.js +++ b/modules/ve-mw/ui/tools/ve.ui.MWEditModeTool.js @@ -131,9 +131,21 @@ ve.ui.MWEditModeVisualTool.prototype.onSelect = function () { * @inheritdoc */ ve.ui.MWEditModeVisualTool.prototype.onUpdateState = function () { + var isVisualModeNowAvailable = ve.init.target.isModeAvailable( 'visual' ); + // Parent method ve.ui.MWEditModeVisualTool.super.prototype.onUpdateState.apply( this, arguments ); - this.setDisabled( !ve.init.target.isModeAvailable( 'visual' ) ); + // Cached for performance + if ( this.isVisualModeAvailable !== isVisualModeNowAvailable ) { + this.isVisualModeAvailable = isVisualModeNowAvailable; + + this.setDisabled( !isVisualModeNowAvailable ); + this.setTitle( OO.ui.msg( + isVisualModeNowAvailable ? + 'visualeditor-mweditmodeve-tool' : + 'visualeditor-mweditmodeve-tool-unavailable' + ) ); + } }; ve.ui.toolFactory.register( ve.ui.MWEditModeVisualTool );