Files
JiboSDK/lib/behavior-editor/modals/choose-rule-modal.js
2026-03-22 03:21:45 +02:00

1 line
3.3 KiB
JavaScript

"use strict";var e=function(e){return e&&e.__esModule?e["default"]:e},t=e(require("react")),s=require("atom").CompositeDisposable,n=e(require("../../common/directory-tree-view")),a=e(require("path")),i=e(require("normalize-path")),o=e(require("../../common/get-asset-packs"));module.exports=t.createClass({displayName:"choose-rule-modal",onChoose:function(){var e=this.state.currentAssetPack,t=a.join(e.root,"rules"),s=a.relative(t,this.state.currentRule);s=i(s),"project"!==this.state.currentAssetPack.id&&(s=e.id+"://"+s),this.props.onChoose(s),this.props.onClose()},onCancel:function(){this.props.onClose()},getLength:function(){return Object.keys(this.behaviorToIndexMap).length},getInitialState:function(){return{currentAssetPack:{id:"project"},currentRule:"",filter:""}},onAssetPackSelected:function(e){this.setState({currentAssetPack:e})},onSelected:function(e){this.setState({currentRule:e})},getPanelHeading:function(e){return t.createElement("div",{className:"panel-heading",style:{padding:"0px",width:"100%",height:30}},t.createElement("p",{style:{textAlign:"center",marginTop:"4px",marginBottom:"4px"}},e))},render:function(){for(var e=this,s=o(this.props.root),i=void 0,r=[],c=0;c<s.length;c++){var l=s[c],m="list-item";this.state.currentAssetPack.id===l.id&&(this.state.currentAssetPack=l,i=l,m+=" selected"),r.push(t.createElement("li",{className:m,onClick:this.onAssetPackSelected.bind(this,l)},t.createElement("span",null,l.name)))}return t.createElement("div",{className:"asset-selector-modal",ref:"modal"},t.createElement("div",{className:"panel-heading",style:{padding:"0px"}},t.createElement("h2",{style:{textAlign:"center",marginTop:"6px",marginBottom:"6px"}},"Choose an Animation")),t.createElement("label",{style:{marginLeft:10}},"Search"),t.createElement("atom-text-editor",{ref:"editor",style:{marginLeft:10,marginRight:10,marginBottom:10},mini:!0}),t.createElement("div",{className:"contents"},t.createElement("div",{className:"list-contents"},this.getPanelHeading("Asset Pack"),t.createElement("div",{className:"list-group asset-pack",ref:"assetPackList"},r)),t.createElement("div",{className:"list-contents"},this.getPanelHeading("Rule"),t.createElement("div",{className:"asset-list"},t.createElement(n,{uri:a.resolve(i.root,"rules"),onChosen:function(t){e.onSelected(t),e.onChoose()},onSelected:this.onSelected,extension:[".grm",".rule",".nli"],filter:this.state.filter}))),t.createElement("div",{className:"preview-contents"},this.getPanelHeading("Preview"),t.createElement("div",{className:"asset-preview"},"Look for your grammar preview here!"))),t.createElement("div",{className:"btn-group"},t.createElement("button",{className:"btn",onClick:this.onChoose},"Choose"),t.createElement("button",{className:"btn",onClick:this.onCancel},"Cancel")))},onLeft:function(){var e=t.findDOMNode(this.refs.assetPackList);e.focus()},onRight:function(){var e=t.findDOMNode(this.refs.schemaList);e.focus()},componentDidMount:function(){var e=this,n=t.findDOMNode(this.refs.editor);setTimeout(function(){n.focus(),e.disposable=new s,e.disposable.add(atom.commands.add(e.getDOMNode(),{"jibo-sdk:escape":e.onCancel})),e.disposable=atom.commands.add(n,"jibo-sdk:confirm",function(){e.onChoose()})},100);var a=n.getModel();a.onDidChange(function(){e.setState({filter:a.getText()})})},componentWillUnmount:function(){this.disposable.dispose()}});