Debian Codegraph @

extensions/VisualEditor/modules/ve-mw/ui/actions/ve.ui.MWSaveDialogAction.js

raw symbols SCIP
1 /*!
2 * VisualEditor UserInterface MWSaveDialogAction class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 // TODO: Can perhaps extract a lot of the dialog lifecycle management code
8 // from ArticleTarget and put it here.
9
10 /**
11 * Save action.
12 *
13 * @class
14 * @extends ve.ui.Action
15 *
16 * @constructor
17 * @param {ve.ui.Surface} surface Surface to act on
18 */
19 ve.ui.MWSaveDialogAction = function VeUiMWSaveDialogAction() {
20 // Parent constructor
21 ve.ui.MWSaveDialogAction.super.apply( this, arguments );
22 };
23
24 /* Inheritance */
25
26 OO.inheritClass( ve.ui.MWSaveDialogAction, ve.ui.Action );
27
28 /* Static Properties */
29
30 ve.ui.MWSaveDialogAction.static.name = 'mwSaveDialog';
31
32 ve.ui.MWSaveDialogAction.static.methods = [ 'save', 'review', 'preview' ];
33
34 /* Methods */
35
36 /**
37 * Open the save dialog
38 *
39 * @param {string} checkbox Checkbox to toggle after opening
40 * @return {boolean} Action was executed
41 */
42 ve.ui.MWSaveDialogAction.prototype.save = function ( checkbox ) {
43 ve.init.target.showSaveDialog( null, checkbox );
44 return true;
45 };
46
47 /**
48 * Open the save dialog, and set it to the review panel
49 *
50 * @return {boolean} Action was executed
51 */
52 ve.ui.MWSaveDialogAction.prototype.review = function () {
53 ve.init.target.showSaveDialog( 'review' );
54 return true;
55 };
56
57 /**
58 * Open the save dialog, and set it to the preview panel
59 *
60 * @return {boolean} Action was executed
61 */
62 ve.ui.MWSaveDialogAction.prototype.preview = function () {
63 ve.init.target.showSaveDialog( 'preview' );
64 return true;
65 };
66
67 /* Registration */
68
69 ve.ui.actionFactory.register( ve.ui.MWSaveDialogAction );
70
71 /* Commands */
72
73 /**
74 * Command which can only execute when the document is saveable
75 *
76 * @class
77 * @extends ve.ui.Command
78 *
79 * @constructor
80 */
81 ve.ui.MWSaveCommand = function VeUiMwSaveCommand() {
82 // Parent constructor
83 ve.ui.MWSaveCommand.super.apply( this, arguments );
84 };
85
86 OO.inheritClass( ve.ui.MWSaveCommand, ve.ui.Command );
87
88 /**
89 * @inheritdoc ve.ui.Command
90 */
91 ve.ui.MWSaveCommand.prototype.isExecutable = function () {
92 // Parent method
93 return ve.ui.MWSaveCommand.super.prototype.isExecutable.apply( this, arguments ) &&
94 ve.init.target.isSaveable();
95 };
96
97 ve.ui.commandRegistry.register(
98 new ve.ui.MWSaveCommand(
99 'showSave', 'mwSaveDialog', 'save'
100 )
101 );
102 ve.ui.commandRegistry.register(
103 new ve.ui.MWSaveCommand(
104 'showChanges', 'mwSaveDialog', 'review'
105 )
106 );
107 if ( mw.libs.ve.isWikitextAvailable ) {
108 // Ensure wikitextCommandRegistry has finished loading
109 mw.loader.using( 'ext.visualEditor.mwwikitext' ).then( () => {
110 ve.ui.wikitextCommandRegistry.register(
111 new ve.ui.MWSaveCommand(
112 'showPreview', 'mwSaveDialog', 'preview'
113 )
114 );
115 } );
116 }
117 ve.ui.commandRegistry.register(
118 new ve.ui.MWSaveCommand(
119 'saveMinoredit', 'mwSaveDialog', 'save',
120 { args: [ 'wpMinoredit' ] }
121 )
122 );
123 ve.ui.commandRegistry.register(
124 new ve.ui.MWSaveCommand(
125 'saveWatchthis', 'mwSaveDialog', 'save',
126 { args: [ 'wpWatchthis' ] }
127 )
128 );
129
130 /* Triggers & command help */
131
132 ( function () {
133 const accessKeyPrefix = $.fn.updateTooltipAccessKeys.getAccessKeyPrefix().replace( /-/g, '+' ),
134 shortcuts = [
135 {
136 command: 'showSave',
137 accessKey: 'accesskey-save',
138 label: function () {
139 return ve.init.target.getSaveButtonLabel();
140 }
141 },
142 {
143 command: 'showChanges',
144 accessKey: 'accesskey-diff',
145 label: OO.ui.deferMsg( 'visualeditor-savedialog-label-review' )
146 },
147 {
148 command: 'showPreview',
149 accessKey: 'accesskey-preview',
150 label: OO.ui.deferMsg( 'showpreview' )
151 },
152 {
153 command: 'saveMinoredit',
154 accessKey: 'accesskey-minoredit',
155 label: OO.ui.deferMsg( 'tooltip-minoredit' )
156 },
157 {
158 command: 'saveWatchthis',
159 accessKey: 'accesskey-watch',
160 label: OO.ui.deferMsg( 'tooltip-watch' )
161 }
162 ];
163
164 shortcuts.forEach( ( shortcut ) => {
165 // The following messages can be used here:
166 // * accesskey-save
167 // * accesskey-diff
168 // * accesskey-preview
169 // * accesskey-minoredit
170 // * accesskey-watch
171 const accessKey = ve.msg( shortcut.accessKey );
172 if ( accessKey !== '-' && accessKey !== '' ) {
173 try {
174 ve.ui.triggerRegistry.register(
175 shortcut.command, new ve.ui.Trigger( accessKeyPrefix + accessKey )
176 );
177 } catch ( e ) {
178 mw.log.warn( 'Invalid accesskey data? Failed to register ' + accessKeyPrefix + accessKey );
179 return;
180 }
181 ve.ui.commandHelpRegistry.register( 'other', shortcut.command, {
182 trigger: shortcut.command,
183 label: shortcut.label
184 } );
185 ve.ui.MWCommandHelpDialog.static.commandGroups.other.demote = ve.ui.MWCommandHelpDialog.static.commandGroups.other.demote || [];
186 ve.ui.MWCommandHelpDialog.static.commandGroups.other.demote.push( shortcut.command );
187 }
188 } );
189 }() );