Debian Codegraph @

dojox/sketch/Toolbar.js

raw symbols SCIP
1 define([
2 "dojo/_base/kernel",
3 "dojo/_base/lang",
4 "dojo/_base/declare",
5 "./Annotation",
6 "dijit/Toolbar",
7 "dijit/form/Button"
8 ], function(dojo){
9 dojo.getObject("sketch", true, dojox);
10 dojo.declare("dojox.sketch.ButtonGroup", null, {
11 constructor: function(){
12 this._childMaps={};
13 this._children=[];
14 },
15 add: function(/*_Plugin*/ plugin){
16 this._childMaps[plugin]=plugin.connect(plugin,'onActivate',dojo.hitch(this,'_resetGroup',plugin));
17 this._children.push(plugin);
18 },
19 // remove: function(/*_Plugin*/ plugin){
20 // widget.disconnect(this._childMaps[widget.id]);
21 // delete this._childMaps[widget.id];
22 // this._children.splice(this._children.indexOf(widget.id),1);
23 // },
24 _resetGroup: function(p){
25 var cs=this._children;
26 dojo.forEach(cs,function(c){
27 if(p!=c && c['attr']){
28 c.attr('checked',false);
29 }
30 });
31 }
32 });
33
34 dojo.declare("dojox.sketch.Toolbar", dijit.Toolbar, {
35 figure: null,
36 plugins: null,
37 postCreate: function(){
38 this.inherited(arguments);
39 this.shapeGroup=new dojox.sketch.ButtonGroup;
40
41 if(!this.plugins){
42 this.plugins=['Lead','SingleArrow','DoubleArrow','Underline','Preexisting','Slider'];
43 }
44 this._plugins=[];
45
46 dojo.forEach(this.plugins,function(obj){
47 var name=dojo.isString(obj)?obj:obj.name;
48 var p=new dojox.sketch.tools[name](obj.args||{});
49 this._plugins.push(p);
50 p.setToolbar(this);
51 if(!this._defaultTool && p.button){
52 this._defaultTool=p;
53 }
54 },this);
55 },
56 setFigure: function(f){
57 this.figure = f;
58 this.connect(f,'onLoad','reset');
59 dojo.forEach(this._plugins, function(p){
60 p.setFigure(f);
61 });
62 },
63 destroy: function(){
64 dojo.forEach(this._plugins,function(p){
65 p.destroy();
66 });
67 this.inherited(arguments);
68 delete this._defaultTool;
69 delete this._plugins;
70 },
71 addGroupItem: function(/*_Plugin*/item,group){
72 if(group!='toolsGroup'){
73 console.error('not supported group '+group);
74 return;
75 }
76
77 this.shapeGroup.add(item);
78 },
79 reset: function(){
80 this._defaultTool.activate();
81 },
82 _setShape: function(s){
83 if(!this.figure.surface) return;
84 // now do the action.
85 if(this.figure.hasSelections()){
86 for(var i=0; i<this.figure.selected.length; i++){
87 var before=this.figure.selected[i].serialize();
88 this.figure.convert(this.figure.selected[i], s);
89 this.figure.history.add(dojox.sketch.CommandTypes.Convert, this.figure.selected[i], before);
90 }
91 }
92 }
93 });
94
95 dojox.sketch.makeToolbar=function(node,figure){
96 var toolbar=new dojox.sketch.Toolbar();
97 toolbar.setFigure(figure);
98 node.appendChild(toolbar.domNode);
99 return toolbar;
100 };
101
102 return dojox.sketch.Toolbar;
103 });