Fixed bug where selectedChanged and elementChanged were called too often

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1575 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Alexis Deveria 2010-05-24 19:46:32 +00:00
parent 2513923d61
commit 4c0148a684
2 changed files with 62 additions and 40 deletions

View File

@ -1070,10 +1070,13 @@
$('#stroke_style').val(selectedElement.getAttribute("stroke-dasharray")||"none"); $('#stroke_style').val(selectedElement.getAttribute("stroke-dasharray")||"none");
var attr = selectedElement.getAttribute("stroke-linejoin") || 'miter'; var attr = selectedElement.getAttribute("stroke-linejoin") || 'miter';
$('#linejoin_' + attr).mouseup();
var attr = selectedElement.getAttribute("stroke-linecap") || 'butt'; setStrokeOpt($('#linejoin_' + attr)[0]);
$('#linecap_' + attr).mouseup();
attr = selectedElement.getAttribute("stroke-linecap") || 'butt';
setStrokeOpt($('#linecap_' + attr)[0]);
} }
// All elements including image and group have opacity // All elements including image and group have opacity
@ -1382,11 +1385,6 @@
operaRepaint(); operaRepaint();
}); });
// $('#stroke_linecap').change(function(){
// svgCanvas.setStrokeAttr('stroke-linecap', $(this).val());
// operaRepaint();
// });
// Lose focus for select elements when changed (Allows keyboard shortcuts to work better) // Lose focus for select elements when changed (Allows keyboard shortcuts to work better)
$('select').change(function(){$(this).blur();}); $('select').change(function(){$(this).blur();});
@ -1561,6 +1559,20 @@
}()); }());
function setStrokeOpt(opt, changeElem) {
var id = opt.id;
var bits = id.split('_');
var pre = bits[0];
var val = bits[1];
if(changeElem) {
svgCanvas.setStrokeAttr('stroke-' + pre, val);
}
operaRepaint();
setIcon('#cur_' + pre , id, 20);
$(opt).addClass('current').siblings().removeClass('current');
}
(function() { (function() {
var button = $('#main_icon'); var button = $('#main_icon');
var overlay = $('#main_icon span'); var overlay = $('#main_icon span');
@ -1678,12 +1690,7 @@
if(dropUp) { if(dropUp) {
$(elem).addClass('dropup'); $(elem).addClass('dropup');
} }
list.find('li').bind('mouseup', function() { list.find('li').bind('mouseup', callback);
callback.apply(this, arguments);
if(!opts.multiclick) {
$(this).addClass('current').siblings().removeClass('current');
}
});
$(window).mouseup(function(evt) { $(window).mouseup(function(evt) {
if(!on_button) { if(!on_button) {
@ -1789,21 +1796,11 @@
}, true); }, true);
addAltDropDown('#stroke_linecap', '#linecap_opts', function() { addAltDropDown('#stroke_linecap', '#linecap_opts', function() {
var val = this.id.split('_')[1]; setStrokeOpt(this, true);
svgCanvas.setStrokeAttr('stroke-linecap', val);
operaRepaint();
var icon = $.getSvgIcon(this.id).clone();
$('#cur_linecap').empty().append(icon);
$.resizeSvgIcons({'#cur_linecap .svg_icon': 20});
}, {dropUp: true}); }, {dropUp: true});
addAltDropDown('#stroke_linejoin', '#linejoin_opts', function() { addAltDropDown('#stroke_linejoin', '#linejoin_opts', function() {
var val = this.id.split('_')[1]; setStrokeOpt(this, true);
svgCanvas.setStrokeAttr('stroke-linejoin', val);
operaRepaint();
var icon = $.getSvgIcon(this.id).clone();
$('#cur_linejoin').empty().append(icon);
$.resizeSvgIcons({'#cur_linejoin .svg_icon': 20});
}, {dropUp: true}); }, {dropUp: true});
addAltDropDown('#tool_position', '#position_opts', function() { addAltDropDown('#tool_position', '#position_opts', function() {
@ -2287,9 +2284,14 @@
svgCanvas.setBackground(color, url); svgCanvas.setBackground(color, url);
} }
var setIcon = function(elem, icon_id) { var setIcon = function(elem, icon_id, forcedSize) {
var icon = $.getSvgIcon(icon_id).clone(); var icon = $.getSvgIcon(icon_id).clone();
$(elem).empty().append(icon); $(elem).empty().append(icon);
if(forcedSize) {
var obj = {};
obj[elem + ' .svg_icon'] = forcedSize;
$.resizeSvgIcons(obj);
} else {
var size = curPrefs.iconsize; var size = curPrefs.iconsize;
if(size && size !== 'm') { if(size && size !== 'm') {
var icon_sizes = { s:16, m:24, l:32, xl:48}, obj = {}; var icon_sizes = { s:16, m:24, l:32, xl:48}, obj = {};
@ -2297,6 +2299,7 @@
$.resizeSvgIcons(obj); $.resizeSvgIcons(obj);
} }
} }
}
var setIconSize = Editor.setIconSize = function(size, force) { var setIconSize = Editor.setIconSize = function(size, force) {
if(size == curPrefs.size && !force) return; if(size == curPrefs.size && !force) return;
@ -2696,7 +2699,6 @@
shower.toggleClass('disabled', !has_enabled); shower.toggleClass('disabled', !has_enabled);
}); });
operaRepaint(); operaRepaint();
}; };

View File

@ -2609,7 +2609,7 @@ function BatchCommand(text) {
// Function: clearSelection // Function: clearSelection
// Clears the selection. The 'selected' handler is then called. // Clears the selection. The 'selected' handler is then called.
this.clearSelection = function() { this.clearSelection = function(noCall) {
if (selectedElements[0] != null) { if (selectedElements[0] != null) {
var len = selectedElements.length; var len = selectedElements.length;
for (var i = 0; i < len; ++i) { for (var i = 0; i < len; ++i) {
@ -2620,7 +2620,7 @@ function BatchCommand(text) {
} }
selectedBBoxes[0] = null; selectedBBoxes[0] = null;
} }
call("selected", selectedElements); if(!noCall) call("selected", selectedElements);
}; };
// TODO: do we need to worry about selectedBBoxes here? // TODO: do we need to worry about selectedBBoxes here?
@ -3012,7 +3012,8 @@ function BatchCommand(text) {
// only clear selection if shift is not pressed (otherwise, add // only clear selection if shift is not pressed (otherwise, add
// element to selection) // element to selection)
if (!evt.shiftKey) { if (!evt.shiftKey) {
canvas.clearSelection(); // No need to do the call here as it will be done on addToSelection
canvas.clearSelection(true);
} }
canvas.addToSelection([mouse_target]); canvas.addToSelection([mouse_target]);
justSelected = mouse_target; justSelected = mouse_target;
@ -3296,8 +3297,8 @@ function BatchCommand(text) {
if (selected == null) break; if (selected == null) break;
if (i==0) { if (i==0) {
var box = canvas.getBBox(selected); var box = canvas.getBBox(selected);
selectedBBoxes[i].x = box.x + dx; // selectedBBoxes[i].x = box.x + dx;
selectedBBoxes[i].y = box.y + dy; // selectedBBoxes[i].y = box.y + dy;
} }
// update the dummy transform in our transform list // update the dummy transform in our transform list
@ -3640,7 +3641,9 @@ function BatchCommand(text) {
cur_text.font_family = selected.getAttribute("font-family"); cur_text.font_family = selected.getAttribute("font-family");
} }
selectorManager.requestSelector(selected).showGrips(true); selectorManager.requestSelector(selected).showGrips(true);
call("selected", [selected]);
// This shouldn't be necessary as it was done on mouseDown...
// call("selected", [selected]);
} }
// always recalculate dimensions to strip off stray identity transforms // always recalculate dimensions to strip off stray identity transforms
recalculateAllSelectedDimensions(); recalculateAllSelectedDimensions();
@ -4191,6 +4194,11 @@ function BatchCommand(text) {
textActions.init(); textActions.init();
$(curtext).css('cursor', 'text'); $(curtext).css('cursor', 'text');
// if(support.editableText) {
// curtext.setAttribute('editable', 'simple');
// return;
// }
if(!arguments.length) { if(!arguments.length) {
setCursor(); setCursor();
} else { } else {
@ -4225,6 +4233,10 @@ function BatchCommand(text) {
$(textinput).blur(); $(textinput).blur();
curtext = false; curtext = false;
// if(support.editableText) {
// curtext.removeAttribute('editable');
// }
}, },
setInputElem: function(elem) { setInputElem: function(elem) {
textinput = elem; textinput = elem;
@ -4238,6 +4250,11 @@ function BatchCommand(text) {
init: function(inputElem) { init: function(inputElem) {
if(!curtext) return; if(!curtext) return;
// if(support.editableText) {
// curtext.select();
// return;
// }
if(!curtext.parentNode) { if(!curtext.parentNode) {
// Result of the ffClone, need to get correct element // Result of the ffClone, need to get correct element
curtext = selectedElements[0]; curtext = selectedElements[0];
@ -9170,6 +9187,9 @@ function BatchCommand(text) {
support.pathInsertItemBefore = false; support.pathInsertItemBefore = false;
} }
// TODO: Find better way to check support for this
support.editableText = isOpera;
// Correct decimals on clone attributes (Opera/win/non-en) // Correct decimals on clone attributes (Opera/win/non-en)
var rect = document.createElementNS(svgns,'rect'); var rect = document.createElementNS(svgns,'rect');
rect.setAttribute('x',.1); rect.setAttribute('x',.1);