From 82e516cd378aa40f90e9a39835e31aea2a60cf6b Mon Sep 17 00:00:00 2001 From: Alexis Deveria Date: Fri, 21 Aug 2009 13:39:23 +0000 Subject: [PATCH] Fixed issue 102: Allow selection of next child/previous child with a key and issue 107: Creating an object selects it automatically and switches to the Select tool git-svn-id: http://svg-edit.googlecode.com/svn/trunk@430 eee81c28-f429-11dd-99c0-75d572ba1ddd --- editor/svg-editor.js | 20 ++++++++++++++++---- editor/svgcanvas.js | 45 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 56 insertions(+), 9 deletions(-) diff --git a/editor/svg-editor.js b/editor/svg-editor.js index f4d3f92b..5a522271 100644 --- a/editor/svg-editor.js +++ b/editor/svg-editor.js @@ -80,7 +80,7 @@ function svg_edit_setup() { updateToolbar(); } // if (elem != null) - updateContextPanel(true); + updateContextPanel(); }; // called when any element has changed @@ -101,7 +101,7 @@ function svg_edit_setup() { // we tell it to skip focusing the text control if the // text element was previously in focus - updateContextPanel(false); + updateContextPanel(); }; // updates the toolbar (colors, opacity, etc) based on the selected element @@ -182,7 +182,7 @@ function svg_edit_setup() { }; // updates the context panel tools based on the selected element - var updateContextPanel = function(shouldHighlightText) { + var updateContextPanel = function() { var elem = selectedElement; $('#selected_panel').hide(); $('#multiselected_panel').hide(); @@ -244,7 +244,7 @@ function svg_edit_setup() { $('#font_family').val(elem.getAttribute("font-family")); $('#font_size').val(elem.getAttribute("font-size")); $('#text').val(elem.textContent); - if (shouldHighlightText) { + if (svgCanvas.addedNew) { $('#text').focus(); $('#text').select(); } @@ -268,6 +268,8 @@ function svg_edit_setup() { else { $('#tool_redo').addClass( 'tool_button_disabled'); } + + svgCanvas.addedNew = false; }; $('#text').focus( function(){ textBeingEntered = true; } ); @@ -476,6 +478,14 @@ function svg_edit_setup() { svgCanvas.moveSelectedElements(dx,dy); } }; + + var selectNext = function() { + svgCanvas.cycleElement(1); + } + + var selectPrev = function() { + svgCanvas.cycleElement(0); + } var clickClear = function(){ if( confirm('Do you want to clear the drawing?\nThis will also erase your undo history!') ) { @@ -684,6 +694,8 @@ function svg_edit_setup() { ['backspace', function(evt){deleteSelected();evt.preventDefault();}], ['shift+up', moveToTopSelected], ['shift+down', moveToBottomSelected], + ['shift+9', selectPrev], + ['shift+0', selectNext], ['up', function(evt){moveSelected(0,-1);evt.preventDefault();}], ['down', function(evt){moveSelected(0,1);evt.preventDefault();}], ['left', function(evt){moveSelected(-1,0);evt.preventDefault();}], diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index 882859d8..42418bd5 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -263,7 +263,6 @@ function SvgCanvas(c) offset += 2; } var bbox = bbox || canvas.getBBox(this.selectedElement); - console.log(bbox); var l=bbox.x-offset, t=bbox.y-offset, w=bbox.width+(offset<<1), h=bbox.height+(offset<<1); // TODO: use suspendRedraw() here selectedBox.setAttribute("x", l); @@ -978,7 +977,7 @@ function SvgCanvas(c) call("selected", selectedElements); }; - this.addToSelection = function(elemsToAdd) { + this.addToSelection = function(elemsToAdd, showGrips) { if (elemsToAdd.length == 0) { return; } // find the first null in our selectedElements array @@ -1004,6 +1003,10 @@ function SvgCanvas(c) call("selected", selectedElements); } } + + if(showGrips) { + selectorManager.requestSelector(selectedElements[0]).showGrips(elem.tagName != "text"); + } }; // @@ -1722,7 +1725,6 @@ function SvgCanvas(c) case "text": keep = true; canvas.clearSelection(); - canvas.addToSelection([element]); break; case "poly": // set element to null here so that it is not removed nor finalized @@ -1847,6 +1849,8 @@ function SvgCanvas(c) element.parentNode.removeChild(element); element = null; } else if (element != null) { + canvas.addedNew = true; + canvas.addToSelection([element], true); element.setAttribute("opacity", current_opacity); cleanupElement(element); selectorManager.update(); @@ -2034,7 +2038,7 @@ function SvgCanvas(c) }; this.setFillColor = function(val) { - if(selectedElements.length && selectedElements[0].nodeName == 'text') { + if(selectedElements[0] != null && selectedElements[0].nodeName == 'text') { current_text_fill = val; } else { current_fill = val; @@ -2171,7 +2175,7 @@ function SvgCanvas(c) }; this.setStrokeWidth = function(val) { - if(selectedElements.length && selectedElements[0].nodeName == 'text') { + if(selectedElements[0] != null && selectedElements[0].nodeName == 'text') { current_text_stroke_width = val; } else { current_stroke_width = val; @@ -2618,6 +2622,37 @@ function SvgCanvas(c) } }; + this.cycleElement = function(next) { + var cur_elem = selectedElements[0]; + var elem = false; + if (cur_elem == null) { + if(next) { + var elem = svgroot.firstChild; + if (elem.tagName == 'defs') { + elem = elem.nextSibling; + } + } else { + var elem = svgroot.lastChild; + var id = elem.getAttribute('id'); + if(!id || id.indexOf('svg_') != 0){ + elem = elem.previousSibling; + } + } + } else { + var type = next?'next':'previous'; + var elem = cur_elem[type + 'Sibling']; + if(!elem) return; + + var id = elem.getAttribute('id'); + if(!id || id.indexOf('svg_') != 0) { + return; + } + } + canvas.clearSelection(); + canvas.addToSelection([elem], true); + call("selected", selectedElements); + } + var resetUndoStack = function() { undoStack = []; undoStackPointer = 0;