1 | define([ |
---|
2 | "dojo/_base/kernel", |
---|
3 | "dojo/_base/lang", |
---|
4 | "dojo/_base/array", |
---|
5 | "dojo/_base/declare", |
---|
6 | "dojo/_base/connect", |
---|
7 | "dijit/form/ToggleButton" |
---|
8 | ], function(dojo){ |
---|
9 | dojo.getObject("sketch", true, dojox); |
---|
10 | dojo.declare("dojox.sketch._Plugin", null, { |
---|
11 | // summary |
---|
12 | // This represents a "plugin" to the dojox.sketch.Figure, which is basically |
---|
13 | // a single button on the Toolbar and some associated code |
---|
14 | constructor: function(/*Object?*/args){ |
---|
15 | if(args){ |
---|
16 | dojo.mixin(this, args); |
---|
17 | } |
---|
18 | this._connects=[]; |
---|
19 | }, |
---|
20 | |
---|
21 | figure: null, |
---|
22 | iconClassPrefix: "dojoxSketchIcon", |
---|
23 | itemGroup: 'toolsGroup', |
---|
24 | button: null, |
---|
25 | queryCommand: null, |
---|
26 | shape: "", |
---|
27 | useDefaultCommand: true, |
---|
28 | buttonClass: dijit.form.ToggleButton, |
---|
29 | _initButton: function(){ |
---|
30 | if(this.shape.length){ |
---|
31 | //TODO: i18n |
---|
32 | // var label = dojox.sketch.shapes[this.shape]; |
---|
33 | var className = this.iconClassPrefix+" "+this.iconClassPrefix + this.shape.charAt(0).toUpperCase() + this.shape.substr(1); |
---|
34 | if(!this.button){ |
---|
35 | var props = { |
---|
36 | label: this.shape, //I18N |
---|
37 | showLabel: false, |
---|
38 | iconClass: className, |
---|
39 | dropDown: this.dropDown, |
---|
40 | tabIndex: "-1" |
---|
41 | }; |
---|
42 | this.button = new this.buttonClass(props); |
---|
43 | this.connect(this.button,'onClick','activate'); |
---|
44 | } |
---|
45 | } |
---|
46 | }, |
---|
47 | attr: function(name,/*?*/value){ |
---|
48 | return this.button.attr(name,value); |
---|
49 | }, |
---|
50 | onActivate: function(){}, |
---|
51 | activate: function(/*?*/e){ |
---|
52 | this.onActivate(); |
---|
53 | this.figure.setTool(this); |
---|
54 | this.attr('checked',true); |
---|
55 | }, |
---|
56 | onMouseDown: function(e){}, |
---|
57 | onMouseMove: function(e){}, |
---|
58 | onMouseUp: function(e){}, |
---|
59 | destroy: function(f){ |
---|
60 | dojo.forEach(this._connects,dojo.disconnect); |
---|
61 | }, |
---|
62 | connect: function(o,f,tf){ |
---|
63 | this._connects.push(dojo.connect(o,f,this,tf)); |
---|
64 | }, |
---|
65 | setFigure: function(/*dijit._Widget*/ figure){ |
---|
66 | // FIXME: detatch from previous figure!! |
---|
67 | this.figure = figure; |
---|
68 | }, |
---|
69 | setToolbar: function(/*dijit._Widget*/ toolbar){ |
---|
70 | // FIXME: prevent creating this if we don't need to (i.e., figure can't handle our command) |
---|
71 | this._initButton(); |
---|
72 | if(this.button){ |
---|
73 | toolbar.addChild(this.button); |
---|
74 | } |
---|
75 | if(this.itemGroup){ |
---|
76 | toolbar.addGroupItem(this,this.itemGroup); |
---|
77 | } |
---|
78 | } |
---|
79 | }); |
---|
80 | return dojox.sketch._Plugin; |
---|
81 | }); |
---|