Made selection of middle arrow for lines convert them to polylines, made extension tools more easy to add, fixed opacity selection on selected connector

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1347 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Alexis Deveria 2010-02-05 20:25:15 +00:00
parent 7054866293
commit 6980e8b0de
4 changed files with 107 additions and 21 deletions

View File

@ -382,12 +382,23 @@ function svg_edit_setup() {
}
var extAdded = function(window, ext) {
var cb_called = false;
var runCallback = function() {
if(ext.callback && !cb_called) {
cb_called = true;
ext.callback();
}
}
if(ext.buttons) {
var fallback_obj = {},
placement_obj = {},
svgicons = ext.svgicons;
var holders = {};
// Add buttons given by extension
$.each(ext.buttons, function(i, btn) {
@ -514,32 +525,70 @@ function svg_edit_setup() {
setIconSize('m');
setIconSize(old);
}
runCallback();
}
});
}
if(ext.context_panels) {
$.each(ext.context_panels, function(i, panel) {
// Add select panel
if(ext.context_tools) {
$.each(ext.context_tools, function(i, tool) {
// Add select tool
var cont_id = tool.container_id?(' id="' + tool.container_id + '"'):"";
// TODO: Allow support for other types, or adding to existing panel
if(panel.type == "select") {
var html = '<div id="' + panel.id + '"><label>'
+ '<select id="' + panel.list_id + '">';
$.each(panel.options, function(val, text) {
var sel = (val == panel.defopt) ? " selected":"";
html += '<option value="'+val+'"' + sel + '>' + text + '</option>';
});
html += "</select></label></div>";
// Creates the panel, hides & adds it, returns the select element
var sel = $(html).hide().appendTo("#tools_top").find("select");
$.each(panel.events, function(evt, func) {
$(sel).bind(evt, func);
});
var panel = $('#' + tool.panel);
if(!panel.length) {
panel = $('<div>', {id: tool.panel}).appendTo("#tools_top");
}
// TODO: Allow support for other types, or adding to existing tool
switch (tool.type) {
case 'select':
var html = '<label' + cont_id + '>'
+ '<select id="' + tool.id + '">';
$.each(tool.options, function(val, text) {
var sel = (val == tool.defval) ? " selected":"";
html += '<option value="'+val+'"' + sel + '>' + text + '</option>';
});
html += "</select></label>";
// Creates the tool, hides & adds it, returns the select element
var sel = $(html).appendTo(panel).find('select');
$.each(tool.events, function(evt, func) {
$(sel).bind(evt, func);
});
break;
case 'input':
var html = '<label' + cont_id + '">'
+ '<span id="' + tool.id + '_label">'
+ tool.label + ':</span>'
+ '<input id="' + tool.id + '" title="' + tool.title
+ '" size="' + (tool.size || "4") + '" value="' + (tool.defval || "") + '" type="text"/></label>'
// Creates the tool, hides & adds it, returns the select element
// Add to given tool.panel
var inp = $(html).appendTo(panel).find('input');
if(tool.spindata) {
inp.SpinButton(tool.spindata);
}
if(tool.events) {
$.each(tool.events, function(evt, func) {
$(sel).bind(evt, func);
});
}
break;
default:
break;
}
});
}
runCallback();
};
var getPaint = function(color, opac) {

View File

@ -6541,6 +6541,9 @@ function BatchCommand(text) {
// selector if the element is in that array
if ($.inArray(elem, selectedElements) != -1) {
setTimeout(function() {
// Due to element replacement, this element may no longer
// be part of the DOM
if(!elem.parentNode) return;
selectorManager.requestSelector(elem).resize();
},0);
}

View File

@ -135,10 +135,11 @@ $(function() {
return {
name: "Arrows",
context_panels: [{
context_tools: [{
type: "select",
id: "arrow_panel",
list_id: "arrow_list",
panel: "arrow_panel",
title: "Select arrow type",
id: "arrow_list",
options: {
none: "No arrow",
end: "----&gt;",
@ -147,11 +148,14 @@ $(function() {
mid: "--&gt;--",
mid_bk: "--&lt;--"
},
defopt: "none",
defval: "none",
events: {
change: setArrow
}
}],
callback: function() {
$('#arrow_panel').hide();
},
addLangData: function(lang) {
return {
data: lang_list[lang]

View File

@ -473,6 +473,7 @@ $(function() {
se_ns = svgCanvas.getEditorNS(true);
cur_line.setAttributeNS(se_ns, "se:connector", conn_str);
cur_line.setAttribute('class', conn_sel.substr(1));
cur_line.setAttribute('opacity', 1);
svgCanvas.addToSelection([cur_line]);
svgCanvas.moveToBottomSelectedElement();
selManager.requestSelector(cur_line).showGrips(false);
@ -522,11 +523,40 @@ $(function() {
elem.getAttribute("marker-end")
)) {
var start = elem.getAttribute("marker-start");
var mid = elem.getAttribute("marker-mid");
var end = elem.getAttribute("marker-end");
cur_line = elem;
$(elem)
.data("start_off", !!start)
.data("end_off", !!end);
if(elem.tagName == "line" && mid) {
// Convert to polyline to accept mid-arrow
var x1 = elem.getAttribute('x1')-0;
var x2 = elem.getAttribute('x2')-0;
var y1 = elem.getAttribute('y1')-0;
var y2 = elem.getAttribute('y2')-0;
var id = elem.id;
var mid_pt = (' '+((x1+x2)/2)+','+((y1+y2)/2) + ' ');
var pline = addElem({
"element": "polyline",
"attr": {
"points": (x1+','+y1+ mid_pt +x2+','+y2),
"stroke": elem.getAttribute('stroke'),
"stroke-width": elem.getAttribute('stroke-width'),
"marker-mid": mid,
"fill": "none",
"opacity": elem.getAttribute('opacity') || 1
}
});
$(elem).after(pline).remove();
svgCanvas.clearSelection();
pline.id = id;
svgCanvas.addToSelection([pline]);
}
}
updateConnectors();
},