Made connectors be removed upon connected-element deletion. Made easier method for adding context panel options

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1345 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Alexis Deveria 2010-02-05 16:11:19 +00:00
parent 7e8f5a312b
commit a4f835a044
4 changed files with 135 additions and 47 deletions

View File

@ -382,7 +382,7 @@ function svg_edit_setup() {
} }
var extAdded = function(window, ext) { var extAdded = function(window, ext) {
if("buttons" in ext) { if(ext.buttons) {
var fallback_obj = {}, var fallback_obj = {},
placement_obj = {}, placement_obj = {},
svgicons = ext.svgicons; svgicons = ext.svgicons;
@ -518,6 +518,28 @@ function svg_edit_setup() {
}); });
} }
if(ext.context_panels) {
$.each(ext.context_panels, function(i, panel) {
// Add select panel
// 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 getPaint = function(color, opac) { var getPaint = function(color, opac) {
@ -1864,7 +1886,7 @@ function svg_edit_setup() {
var bNoFill = (svgCanvas.getFillColor() == 'none'); var bNoFill = (svgCanvas.getFillColor() == 'none');
var bNoStroke = (svgCanvas.getStrokeColor() == 'none'); var bNoStroke = (svgCanvas.getStrokeColor() == 'none');
var buttonsNeedingStroke = [ '#tool_fhpath', '#tool_line' ]; var buttonsNeedingStroke = [ '#tool_fhpath', '#tool_line' ];
var buttonsNeedingFillAndStroke = [ '#tools_rect .tool_button', '#tools_ellipse .tool_button', '#tool_text' ]; var buttonsNeedingFillAndStroke = [ '#tools_rect .tool_button', '#tools_ellipse .tool_button', '#tool_text', '#tool_path'];
if (bNoStroke) { if (bNoStroke) {
for (index in buttonsNeedingStroke) { for (index in buttonsNeedingStroke) {
var button = buttonsNeedingStroke[index]; var button = buttonsNeedingStroke[index];

View File

@ -984,27 +984,6 @@ function BatchCommand(text) {
return result; return result;
} }
this.addExtension = function(name, ext_func) {
if(!(name in extensions)) {
// Provide constants here (or should these be accessed through getSomething()?
var ext = ext_func({
content: svgcontent,
root: svgroot,
call: call,
getNextId: getNextId,
getElem: getElem,
addSvgElementFromJson: addSvgElementFromJson,
selectorManager: selectorManager,
findDefs: findDefs,
recalculateDimensions: recalculateDimensions
});
extensions[name] = ext;
call("extension_added", ext);
} else {
console.log('Cannot add extension "' + name + '", an extension by that name already exists"');
}
};
// This method rounds the incoming value to the nearest value based on the current_zoom // This method rounds the incoming value to the nearest value based on the current_zoom
var round = function(val){ var round = function(val){
return parseInt(val*current_zoom)/current_zoom; return parseInt(val*current_zoom)/current_zoom;
@ -7439,6 +7418,78 @@ function BatchCommand(text) {
// return svgdoc.getElementById(id); // return svgdoc.getElementById(id);
} }
// Being able to access private methods publicly seems wrong somehow,
// but currently appears to be the best way to allow testing and provide
// access to them to plugins.
this.getPrivateMethods = function() {
return {
addCommandToHistory: addCommandToHistory,
addGradient: addGradient,
addSvgElementFromJson: addSvgElementFromJson,
assignAttributes: assignAttributes,
BatchCommand: BatchCommand,
call: call,
ChangeElementCommand: ChangeElementCommand,
cleanupElement: cleanupElement,
copyElem: copyElem,
ffClone: ffClone,
findDefs: findDefs,
findDuplicateGradient: findDuplicateGradient,
fromXml: fromXml,
getElem: getElem,
getId: getId,
getIntersectionList: getIntersectionList,
getNextId: getNextId,
getPathBBox: getPathBBox,
getUrlFromAttr: getUrlFromAttr,
hasMatrixTransform: hasMatrixTransform,
identifyLayers: identifyLayers,
InsertElementCommand: InsertElementCommand,
isIdentity: isIdentity,
logMatrix: logMatrix,
matrixMultiply: matrixMultiply,
MoveElementCommand: MoveElementCommand,
preventClickDefault: preventClickDefault,
recalculateAllSelectedDimensions: recalculateAllSelectedDimensions,
recalculateDimensions: recalculateDimensions,
remapElement: remapElement,
RemoveElementCommand: RemoveElementCommand,
removeUnusedGrads: removeUnusedGrads,
resetUndoStack: resetUndoStack,
round: round,
runExtensions: runExtensions,
sanitizeSvg: sanitizeSvg,
Selector: Selector,
SelectorManager: SelectorManager,
shortFloat: shortFloat,
svgCanvasToString: svgCanvasToString,
SVGEditTransformList: SVGEditTransformList,
svgToString: svgToString,
toString: toString,
toXml: toXml,
transformBox: transformBox,
transformListToTransform: transformListToTransform,
transformPoint: transformPoint,
transformToObj: transformToObj,
walkTree: walkTree
}
}
this.addExtension = function(name, ext_func) {
if(!(name in extensions)) {
// Provide private vars/funcs here. Is there a better way to do this?
var ext = ext_func($.extend(canvas.getPrivateMethods(), {
svgroot: svgroot,
svgcontent: svgcontent,
selectorManager: selectorManager
}));
extensions[name] = ext;
call("extension_added", ext);
} else {
console.log('Cannot add extension "' + name + '", an extension by that name already exists"');
}
};
// Test support for features/bugs // Test support for features/bugs
(function() { (function() {
// segList functions (for FF1.5 and 2.0) // segList functions (for FF1.5 and 2.0)

View File

@ -9,8 +9,7 @@
$(function() { $(function() {
svgCanvas.addExtension("Arrows", function(S) { svgCanvas.addExtension("Arrows", function(S) {
var svgcontent = S.content, var svgcontent = S.svgcontent,
getElem = S.getElem,
addElem = S.addSvgElementFromJson, addElem = S.addSvgElementFromJson,
selElems; selElems;
@ -64,7 +63,7 @@ $(function() {
function addMarker(id, type) { function addMarker(id, type) {
// TODO: Make marker (or use?) per arrow type, since refX can be different // TODO: Make marker (or use?) per arrow type, since refX can be different
var marker = getElem(id); var marker = S.getElem(id);
var pathdata = { var pathdata = {
se_arrow_fw: {d:"m0,0l10,5l-10,5l5,-5l-5,-5z", refx:8}, se_arrow_fw: {d:"m0,0l10,5l-10,5l5,-5l-5,-5z", refx:8},
@ -104,7 +103,8 @@ $(function() {
marker.setAttribute('refX', data.refx); marker.setAttribute('refX', data.refx);
} }
function setArrow(type) { function setArrow() {
var type = this.value;
resetMarker(); resetMarker();
if(type == "none") { if(type == "none") {
@ -114,7 +114,6 @@ $(function() {
var fw_id = "se_arrow_fw"; var fw_id = "se_arrow_fw";
var bk_id = "se_arrow_bk"; var bk_id = "se_arrow_bk";
// Set marker on element // Set marker on element
var id = fw_id; var id = fw_id;
if(type == "mid_bk") { if(type == "mid_bk") {
@ -134,24 +133,25 @@ $(function() {
S.call("changed", selElems); S.call("changed", selElems);
} }
// Init code
(function() {
var conn_tools = $('<div id="arrow_panel">\
<label><select id="arrow_list">\
<option value="none">No arrow</option>\
<option value="end">----&gt;</option>\
<option value="start">&lt;----</option>\
<option value="both">&lt;---&gt;</option>\
<option value="mid">--&gt;--</option>\
<option value="mid_bk">--&lt;--</option>\
</select></label></div>"').hide().appendTo("#tools_top");
$('#arrow_list').change(function() {
setArrow(this.value);
});
}());
return { return {
name: "Arrows", name: "Arrows",
context_panels: [{
type: "select",
id: "arrow_panel",
list_id: "arrow_list",
options: {
none: "No arrow",
end: "----&gt;",
start: "&lt;----",
both: "&lt;---&gt;",
mid: "--&gt;--",
mid_bk: "--&lt;--"
},
defopt: "none",
events: {
change: setArrow
}
}],
addLangData: function(lang) { addLangData: function(lang) {
return { return {
data: lang_list[lang] data: lang_list[lang]

View File

@ -9,8 +9,8 @@
$(function() { $(function() {
svgCanvas.addExtension("Connector", function(S) { svgCanvas.addExtension("Connector", function(S) {
var svgcontent = S.content, var svgcontent = S.svgcontent,
svgroot = S.root, svgroot = S.svgroot,
getNextId = S.getNextId, getNextId = S.getNextId,
getElem = S.getElem, getElem = S.getElem,
addElem = S.addSvgElementFromJson, addElem = S.addSvgElementFromJson,
@ -104,14 +104,29 @@ $(function() {
svgCanvas.removeFromSelection($(conn_sel).toArray()); svgCanvas.removeFromSelection($(conn_sel).toArray());
} }
// Loop through selected elements
while(i--) { while(i--) {
var elem = all_els[i]; var elem = all_els[i];
if(!elem) continue; if(!elem) continue;
// Element was deleted, so delete connector
var was_deleted = !elem.parentNode;
// Skip connector
if($(elem).data('c_start')) continue; if($(elem).data('c_start')) continue;
// Loop through connectors to see if one is connected to the element
connectors.each(function() { connectors.each(function() {
var start = $(this).data("c_start"); var start = $(this).data("c_start");
var end = $(this).data("c_end"); var end = $(this).data("c_end");
// Connector found for this element
if(start == elem.id || end == elem.id) { if(start == elem.id || end == elem.id) {
if(was_deleted) {
$(this).remove();
return;
}
var bb = svgCanvas.getStrokedBBox([elem]); var bb = svgCanvas.getStrokedBBox([elem]);
connections.push({ connections.push({
elem: elem, elem: elem,
@ -138,8 +153,8 @@ $(function() {
var line = conn.connector; var line = conn.connector;
var elem = conn.elem; var elem = conn.elem;
var pre = conn.is_start?'start':'end';
var sw = line.getAttribute('stroke-width'); var sw = line.getAttribute('stroke-width');
var pre = conn.is_start?'start':'end';
// Update bbox for this element // Update bbox for this element
var bb = svgCanvas.getStrokedBBox([elem]); var bb = svgCanvas.getStrokedBBox([elem]);