(function(){"use strict";var t=1e3;u8.Base.Widgets.ActionButton=function(t,e){this.Button(t,$.extend({},u8.Base.Widgets.ActionButton.defaults,e));this.$(this.element).attr("data-helpcontenttype","text/x-markdown")};u8.Base.Widgets.ActionButton.defaults={};u8.Base.Widgets.ActionButton.makeClass({name:"ActionButton",mixins:[u8.Base.ActionSource],deriveFrom:u8.Base.Widgets.Button,events:["QueryState","Dispose"]});$.extend(u8.Base.Widgets.ActionButton.prototype,{dispose:function(){if(this._isDisposed){return}this.raise("Dispose");this._disposeCommandStateBinding();this._disposeQueryStateAction();this._disposeHotKey();this.Button_dispose()},click:function(t,e){if(this.disabled){return}if(!this._isCreated){this.wait("Create",this.click.bind(this,t,e));return}var i={arguments:{},action:this.action,label:this.text};if(t){if(t.elEvent){i.arguments.elEvent=t.elEvent}if(t.arguments){$.extend(i.arguments,t.arguments)}}this.executeAction(i,e)},setVisible:function(t){t=t?true:false;if(this.visible==t){return}this.visible=t;this.$(this.element).toggle(t)},update:function(t){if(!t){return this.Button_update()}if(typeof t=="string"){var e=t;t={};t[e]=true}if(t.state){this._updateState()}},_createModel:function(t){if(this.designer){this.text=this.name,t();return}u8.services.actions.load(this.name,{},this._onActionLoad.bind(this).chain(t).ifAlive(this))},_onActionLoad:function(t,e){var i=e.action;this._disposeCommandStateBinding();this.action=i;this.text=e.label||"";this.image=e.image;this.helpText=e.helpText;this._createCommandStateBinding();this._createQueryStateAction(e.queryStateAction);this._createHotKey(e.hotKey);this._createTooltip()},_createCommandStateBinding:function(){var t=this.action;if(!t||t.templateName!="Command"){return}var e=t.getArgumentValue("Command");u8.services.commands.bindState(this,e,this._onUpdateCommandState.bind(this))},_disposeCommandStateBinding:function(){var t=this.action&&this.action.getArgumentValue("Command");if(t){u8.services.commands.unbindState(this,t)}},_createQueryStateAction:function(t){this._disposeQueryStateAction();if(!t){return}this.queryStateAction=new u8.Base.Action(t).getFunction();if(this.queryStateAction){this._startQueryStateTimer()}},_disposeQueryStateAction:function(){this._stopQueryStateTimer()},_createHotKey:function(t){this._disposeHotKey();if(!t){return}var e=this;this.hotKey=new u8.Base.HotKey(t);this.hotKey.bind("Hit",function(t,i){i.handled=true;e.click(i)});u8.services.hotKeys.register(this.id,this.hotKey)},_disposeHotKey:function(){if(!this.hotKey){return}u8.services.hotKeys.unregister(this.id);delete this.hotKey},_createTooltip:function(){var t=this.text||"";if(this.hotKey&&this.hotKey.isValid()){t+=(t?" ":"")+"("+this.hotKey.getDisplayString()+")"}if(this.helpText){t=t+"\n"+this.helpText}this.tooltip=t},_updateState:function(){var t={button:this,name:this.name,disabled:this.disabled,visible:this.visible};this.raise("QueryState",t);if(t.stopPropagation){delete t.stopPropagation}else{var e=null;if(this.action&&this.action.templateName=="Command"){e=this.action.getArgumentValue("Command")}if(!e){e="Action/"+t.name}u8.services.commands.queryState(this,e,t);if(this.queryStateAction){this._executeQueryStateAction(t)}}this.attr({visible:t.visible,disabled:t.disabled})},_stopQueryStateTimer:function(){if(this._queryStateTimer){clearInterval(this._queryStateTimer);delete this._queryStateTimer}},_startQueryStateTimer:function(){this._stopQueryStateTimer();this._queryStateTimer=setInterval(this._onQueryStateTimer.bind(this),t)},_executeQueryStateAction:function(t){if(typeof this.queryStateAction!="function"){t.disabled=true;return}var e=null;var i={name:this.name,source:this};if(typeof this.getCommandTarget=="function"){e=this.getCommandTarget(i)}if(!e){e=this.commandTarget}if(!e){e=this.parent}var s=this;var n=u8.debug.tryCatch(this.queryStateAction.bind(this,i,{target:e}),function(){s.queryStateAction=null;s._stopQueryStateTimer();return"QueryStateAction failed for button '"+s.name+"'. The QueryStateAction will now be disabled, the button will be active!"});if(typeof n==="object"){if("disabled"in n){t.disabled=!!n.disabled}if("visible"in n){t.visible=!!n.visible}if(n.done){s._stopQueryStateTimer()}}else{t.disabled=n}},_onQueryStateTimer:function(){var t={button:this,name:this.name,disabled:this.disabled,visible:this.visible};this._executeQueryStateAction(t);this.attr({visible:t.visible,disabled:t.disabled})},_onUpdateCommandState:function(t,e,i){if(typeof i.disabled!="undefined"){this.setDisabled(i.disabled)}if(typeof i.visible!="undefined"){this.setDisabled(i.visible)}}})})();