+ var depressBeforeEvent,\r
+ inReadOnly;\r
+ function stateFromNamedCommand( command, editor )\r
+ {\r
+ var retval;\r
+\r
+ if ( inReadOnly && command in { Paste : 1, Cut : 1 } )\r
+ return CKEDITOR.TRISTATE_DISABLED;\r
+\r
+ if ( command == 'Paste' )\r
+ {\r
+ // IE Bug: queryCommandEnabled('paste') fires also 'beforepaste(copy/cut)',\r
+ // guard to distinguish from the ordinary sources (either\r
+ // keyboard paste or execCommand) (#4874).\r
+ CKEDITOR.env.ie && ( depressBeforeEvent = 1 );\r
+ try\r
+ {\r
+ // Always return true for Webkit (which always returns false).\r
+ retval = editor.document.$.queryCommandEnabled( command ) || CKEDITOR.env.webkit;\r
+ }\r
+ catch( er ) {}\r
+ depressBeforeEvent = 0;\r
+ }\r
+ // Cut, Copy - check if the selection is not empty\r
+ else\r
+ {\r
+ var sel = editor.getSelection(),\r
+ ranges = sel && sel.getRanges();\r
+ retval = sel && !( ranges.length == 1 && ranges[ 0 ].collapsed );\r
+ }\r
+\r
+ return retval ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED;\r
+ }\r
+\r
+ function setToolbarStates()\r
+ {\r
+ if ( this.mode != 'wysiwyg' )\r
+ return;\r
+\r
+ var pasteState = stateFromNamedCommand( 'Paste', this );\r
+\r
+ this.getCommand( 'cut' ).setState( stateFromNamedCommand( 'Cut', this ) );\r
+ this.getCommand( 'copy' ).setState( stateFromNamedCommand( 'Copy', this ) );\r
+ this.getCommand( 'paste' ).setState( pasteState );\r
+ this.fire( 'pasteState', pasteState );\r
+ }\r
+\r