+Panel.prototype.connectToolbar = function()
+{
+ var self = this;
+ self.hotkeys = [];
+
+ // check if there is a one
+ var toolbar = $("div.toolbar", this.contentDiv);
+ // $.log('Connecting toolbar', toolbar);
+ if(toolbar.length === 0) return;
+
+ // move the extra
+ var extra_buttons = $('span.panel-toolbar-extra', toolbar);
+ var placeholder = $('div.panel-toolbar span.panel-toolbar-extra', this.wrap);
+ placeholder.replaceWith(extra_buttons);
+ placeholder.hide();
+
+ var action_buttons = $('button', extra_buttons);
+
+ // connect group-switch buttons
+ var group_buttons = $('*.toolbar-tabs-container button', toolbar);
+
+ // $.log('Found groups:', group_buttons);
+
+ group_buttons.each(function() {
+ var group = $(this);
+ var group_name = group.attr('ui:group');
+ // $.log('Connecting group: ' + group_name);
+
+ group.click(function() {
+ // change the active group
+ var active = $("*.toolbar-tabs-container button.active", toolbar);
+ if (active != group) {
+ active.removeClass('active');
+ group.addClass('active');
+ $(".toolbar-button-groups-container p", toolbar).each(function() {
+ if ( $(this).attr('ui:group') != group_name) {
+ $(this).hide();
+ } else {
+ $(this).show();
+ }
+ });
+ self.callHook('toolbarResized');
+ }
+ });
+ });
+
+ // connect action buttons
+ var allbuttons = $.makeArray(action_buttons);
+ $.merge(allbuttons,
+ $.makeArray($('*.toolbar-button-groups-container button', toolbar)) );
+
+ $(allbuttons).each(function() {
+ var button = $(this);
+ var hk = button.attr('ui:hotkey');
+ if(hk) hk = new Hotkey( parseInt(hk) );
+
+ try {
+ var params = $.evalJSON(button.attr('ui:action-params'));
+ } catch(object) {
+ $.log('JSON exception in ', button, ': ', object);
+ button.attr('disabled', 'disabled');
+ return;
+ }
+
+ var callback = function() {
+ editor.callScriptlet(button.attr('ui:action'), self, params);
+ };
+
+ // connect button
+ button.click(callback);
+
+ // connect hotkey
+ if(hk) {
+ self.hotkeys[hk.code] = callback;
+ // $.log('hotkey', hk);
+ }
+
+ // tooltip
+ if (button.attr('ui:tooltip') )
+ {
+ var tooltip = button.attr('ui:tooltip');
+ if(hk) tooltip += ' ['+hk+']';
+
+ button.wTooltip({
+ delay: 1000,
+ style: {
+ border: "1px solid #7F7D67",
+ opacity: 0.9,
+ background: "#FBFBC6",
+ padding: "1px",
+ fontSize: "12px"
+ },
+ content: tooltip
+ });
+ }
+ });
+};