Added keyboard shortcut option for extension buttons, made import of connectors work, fixed issue 442

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1286 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Alexis Deveria 2010-01-27 21:03:43 +00:00
parent ee393cd933
commit 363eef5d57
4 changed files with 45 additions and 4 deletions

View File

@ -1,6 +1,5 @@
$(function() { $(function() {
svgCanvas.addExtension("Connector", function(vars) { svgCanvas.addExtension("Connector", function(vars) {
var svgcontent = vars.content, var svgcontent = vars.content,
svgroot = vars.root, svgroot = vars.root,
getNextId = vars.getNextId, getNextId = vars.getNextId,
@ -144,6 +143,7 @@ $(function() {
type: "mode", type: "mode",
icon: "images/cut.png", icon: "images/cut.png",
title: "Connect two objects", title: "Connect two objects",
key: "L",
events: { events: {
'click': function() { 'click': function() {
svgCanvas.setMode("connector"); svgCanvas.setMode("connector");
@ -198,7 +198,6 @@ $(function() {
var i = elems.length; var i = elems.length;
var connectors = $(svgcontent).find("." + conn_class); var connectors = $(svgcontent).find("." + conn_class);
if(!connectors.length) return; if(!connectors.length) return;
connections = []; connections = [];
while(i--) { while(i--) {
@ -349,6 +348,14 @@ $(function() {
showPanel(false); showPanel(false);
} }
} }
},
elementChanged: function(opts) {
var elem = opts.elems[0];
if (elem && elem.tagName == 'svg' && elem.id == "svgcontent") {
// Update svgcontent (can change on import)
svgcontent = elem;
}
} }
}; };
}); });

View File

@ -18,7 +18,7 @@
<script type="text/javascript" src="locale/locale.js"></script> <script type="text/javascript" src="locale/locale.js"></script>
<script type="text/javascript" src="svgcanvas.js"></script> <script type="text/javascript" src="svgcanvas.js"></script>
<script type="text/javascript" src="svg-editor.js"></script> <script type="text/javascript" src="svg-editor.js"></script>
<!-- <script type="text/javascript" src="ext-connector.js"></script> --> <script type="text/javascript" src="ext-connector.js"></script>
<!-- Release version of script tags: > <!-- Release version of script tags: >
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>

View File

@ -235,6 +235,10 @@ function svg_edit_setup() {
// we tell it to skip focusing the text control if the // we tell it to skip focusing the text control if the
// text element was previously in focus // text element was previously in focus
updateContextPanel(); updateContextPanel();
svgCanvas.runExtensions("elementChanged", {
elems: elems
});
}; };
var zoomChanged = function(window, bbox, autoCenter) { var zoomChanged = function(window, bbox, autoCenter) {
@ -307,6 +311,24 @@ function svg_edit_setup() {
// Add given events to button // Add given events to button
$.each(btn.events, function(name, func) { $.each(btn.events, function(name, func) {
if(name == "click") {
if(btn.type == 'mode') {
var new_func = function() {
if (toolButtonClick('#' + id)) {
func();
}
}
button.bind(name, new_func);
if(btn.key) {
$(document).bind('keydown', {combi: btn.key}, new_func);
if(btn.title) button.attr("title", btn.title + ' ['+btn.key+']');
}
}
} else {
button.bind(name, func);
}
button.bind(name, function() { button.bind(name, function() {
if(name == "click" && btn.type == 'mode') { if(name == "click" && btn.type == 'mode') {
if (toolButtonClick('#' + id)) { if (toolButtonClick('#' + id)) {

View File

@ -78,6 +78,7 @@ var isOpera = !!window.opera,
return $('<p/>').html(str).text(); return $('<p/>').html(str).text();
}; };
var unit_types = {'em':0,'ex':0,'px':1,'cm':35.43307,'mm':3.543307,'in':90,'pt':1.25,'pc':15,'%':0};
// These command objects are used for the Undo/Redo stack // These command objects are used for the Undo/Redo stack
// attrs contains the values that the attributes had before the change // attrs contains the values that the attributes had before the change
@ -4432,6 +4433,7 @@ function BatchCommand(text) {
current_mode = "select"; current_mode = "select";
removeAllPointGripsFromPath(); removeAllPointGripsFromPath();
canvas.clearSelection(); canvas.clearSelection();
pathActions.clear();
if(selPath) { if(selPath) {
call("selected", [elem]); call("selected", [elem]);
canvas.addToSelection([elem], true); canvas.addToSelection([elem], true);
@ -7248,6 +7250,16 @@ function BatchCommand(text) {
rect.setAttribute('x',.1); rect.setAttribute('x',.1);
var crect = rect.cloneNode(false); var crect = rect.cloneNode(false);
support.goodDecimals = (crect.getAttribute('x').indexOf(',') == -1); support.goodDecimals = (crect.getAttribute('x').indexOf(',') == -1);
// Get correct em/ex values
var rect = document.createElementNS(svgns,'rect');
rect.setAttribute('width',"1em");
rect.setAttribute('height',"1ex");
svgcontent.appendChild(rect);
var bb = rect.getBBox();
unit_types.em = bb.width;
unit_types.ex = bb.height;
svgcontent.removeChild(rect);
}()); }());
} }
// Static class for various utility functions // Static class for various utility functions