diff --git a/extension.json b/extension.json index e7d465e23c..14b0ae7556 100644 --- a/extension.json +++ b/extension.json @@ -1137,6 +1137,7 @@ "visualeditor-editingtabdialog-title", "visualeditor-mweditmode-tooltip", "visualeditor-mweditmodesource-tool", + "visualeditor-mweditmodesource-tool-current", "visualeditor-mweditmodesource-tool-unavailable", "visualeditor-mweditmodesource-warning-cancel", "visualeditor-mweditmodesource-warning-switch", @@ -1146,6 +1147,7 @@ "visualeditor-mweditmodeve-showagain", "visualeditor-mweditmodeve-title", "visualeditor-mweditmodeve-tool", + "visualeditor-mweditmodeve-tool-current", "visualeditor-mweditmodeve-tool-unavailable", "visualeditor-mweditmodeve-warning", "visualeditor-mweditmodewt-popup-body", diff --git a/modules/ve-mw/i18n/en.json b/modules/ve-mw/i18n/en.json index 6904ab89c3..2273dae55e 100644 --- a/modules/ve-mw/i18n/en.json +++ b/modules/ve-mw/i18n/en.json @@ -276,6 +276,7 @@ "visualeditor-mweditmodesource-progress": "Switching to source editing…", "visualeditor-mweditmodesource-title": "Switch to source editing?", "visualeditor-mweditmodesource-tool": "Switch to source editing", + "visualeditor-mweditmodesource-tool-current": "Source editing", "visualeditor-mweditmodesource-tool-unavailable": "Source editing is not available here", "visualeditor-mweditmodesource-warning": "You are switching to source editing.\nDo you want to continue?", "visualeditor-mweditmodesource-warning-cancel": "Cancel", @@ -287,6 +288,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-current": "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.", diff --git a/modules/ve-mw/i18n/qqq.json b/modules/ve-mw/i18n/qqq.json index 9a76fc9ed1..df3279174e 100644 --- a/modules/ve-mw/i18n/qqq.json +++ b/modules/ve-mw/i18n/qqq.json @@ -289,6 +289,7 @@ "visualeditor-mweditmodesource-progress": "Title of progress bar shown while switching to source mode.", "visualeditor-mweditmodesource-title": "Title of dialog to confirm switching to source mode.", "visualeditor-mweditmodesource-tool": "Label for tool that changes edit mode to source editing.", + "visualeditor-mweditmodesource-tool-current": "Label for tool that changes edit mode to source editing if the user is already in that mode.", "visualeditor-mweditmodesource-tool-unavailable": "'''Please translate \"Source\" as meaning \"Source codes\", not source of references.''' Label for tool that changes edit mode to source editing when it is not available.", "visualeditor-mweditmodesource-warning": "Warning message show before changing edit mode to source editing. It may allow the user to keep the changes using the message {{msg-mw|Visualeditor-mweditmodesource-warning-switch}} or cancel.", "visualeditor-mweditmodesource-warning-cancel": "Label for the button on the confirmation dialog for switching to source editing to cancel and return to editing.\n{{Identical|Cancel}}", @@ -300,6 +301,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-current": "Label for tool that changes edit mode to visual editing if the user is already in that mode.", "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", diff --git a/modules/ve-mw/init/ve.init.MWEditModeTool.js b/modules/ve-mw/init/ve.init.MWEditModeTool.js index f33f019b39..afde5fe766 100644 --- a/modules/ve-mw/init/ve.init.MWEditModeTool.js +++ b/modules/ve-mw/init/ve.init.MWEditModeTool.js @@ -38,6 +38,8 @@ mw.libs.ve.MWEditModeTool.static.autoAddToCatchall = false; mw.libs.ve.MWEditModeTool.static.autoAddToGroup = false; +mw.libs.ve.MWEditModeTool.static.currentTitle = null; + mw.libs.ve.MWEditModeTool.static.unavailableTooltip = null; /* Methods */ @@ -80,25 +82,32 @@ mw.libs.ve.MWEditModeTool.prototype.onSelect = function () { if ( this.getMode() !== this.constructor.static.editMode ) { this.switch(); } - this.setActive( this.getMode() === this.constructor.static.editMode ); }; /** * @inheritdoc */ mw.libs.ve.MWEditModeTool.prototype.onUpdateState = function () { - var modeAvailable = this.isModeAvailable( this.constructor.static.editMode ); + var titleKey, + modeAvailable = this.isModeAvailable( this.constructor.static.editMode ), + isCurrent = this.getMode() === this.constructor.static.editMode; // Change title if state has changed - if ( this.modeAvailable !== modeAvailable ) { - this.$link.attr( 'title', modeAvailable ? - OO.ui.resolveMsg( this.constructor.static.title ) : - OO.ui.resolveMsg( this.constructor.static.unavailableTooltip ) - ); - this.setDisabled( !modeAvailable ); + if ( this.isCurrent !== isCurrent || this.modeAvailable !== modeAvailable ) { + titleKey = isCurrent ? + this.constructor.static.currentTitle : + this.constructor.static.title; + this.setTitle( OO.ui.resolveMsg( titleKey ) ); + // Change tooltip if mode is unavailable + if ( !modeAvailable ) { + this.$link.attr( 'title', OO.ui.resolveMsg( this.constructor.static.unavailableTooltip ) ); + } this.modeAvailable = modeAvailable; + this.isCurrent = isCurrent; } - this.setActive( this.getMode() === this.constructor.static.editMode ); + // Update disabled and active state + this.setDisabled( !modeAvailable ); + this.setActive( isCurrent ); }; /** @@ -120,6 +129,8 @@ mw.libs.ve.MWEditModeSourceTool.static.name = 'editModeSource'; mw.libs.ve.MWEditModeSourceTool.static.icon = 'wikiText'; mw.libs.ve.MWEditModeSourceTool.static.title = OO.ui.deferMsg( 'visualeditor-mweditmodesource-tool' ); +mw.libs.ve.MWEditModeSourceTool.static.currentTitle = + OO.ui.deferMsg( 'visualeditor-mweditmodesource-tool-current' ); mw.libs.ve.MWEditModeSourceTool.static.unavailableTooltip = OO.ui.deferMsg( 'visualeditor-mweditmodesource-tool-unavailable' ); @@ -142,5 +153,7 @@ mw.libs.ve.MWEditModeVisualTool.static.name = 'editModeVisual'; mw.libs.ve.MWEditModeVisualTool.static.icon = 'eye'; mw.libs.ve.MWEditModeVisualTool.static.title = OO.ui.deferMsg( 'visualeditor-mweditmodeve-tool' ); +mw.libs.ve.MWEditModeVisualTool.static.currentTitle = + OO.ui.deferMsg( 'visualeditor-mweditmodeve-tool-current' ); mw.libs.ve.MWEditModeVisualTool.static.unavailableTooltip = OO.ui.deferMsg( 'visualeditor-mweditmodeve-tool-unavailable' );