Fixed issue 81: Source Editor needs Cancel/Save buttons

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@401 eee81c28-f429-11dd-99c0-75d572ba1ddd
This commit is contained in:
Alexis Deveria
2009-08-17 14:17:20 +00:00
parent e13c674692
commit 4e5a45642e
3 changed files with 40 additions and 11 deletions

View File

@@ -301,8 +301,17 @@ div.color_block {
#svg_source_textarea { #svg_source_textarea {
position: relative; position: relative;
width: 95%; width: 95%;
top: 35px; top: 5px;
height: 250px; height: 250px;
padding: 5px; padding: 5px;
font-size: 12px; font-size: 12px;
}
#tool_source_back {
text-align: left;
padding-left: 20px;
}
#tool_source_back button {
margin: 10px;
} }

View File

@@ -265,7 +265,10 @@
<div id="svg_source_editor"> <div id="svg_source_editor">
<div id="svg_source_overlay"></div> <div id="svg_source_overlay"></div>
<div id="svg_source_container"> <div id="svg_source_container">
<div id="tool_source_back" class="toolbar_button"></div> <div id="tool_source_back" class="toolbar_button">
<button id="tool_source_save">Save</button>
<button id="tool_source_cancel">Cancel</button>
</div>
<form> <form>
<textarea id="svg_source_textarea"></textarea> <textarea id="svg_source_textarea"></textarea>
</form> </form>

View File

@@ -506,19 +506,34 @@ function svg_edit_setup() {
var properlySourceSizeTextArea = function(){ var properlySourceSizeTextArea = function(){
// TODO: remove magic numbers here and get values from CSS // TODO: remove magic numbers here and get values from CSS
var height = ($(window).height() - 120)+'px'; var height = $('#svg_source_container').height() - 80;
$('#svg_source_textarea').css('height', height); $('#svg_source_textarea').css('height', height);
}; };
var hideSourceEditor = function(){ var saveSourceEditor = function(){
if (!editingsource) return; if (!editingsource) return;
var oldString = svgCanvas.getSvgString(); if (!svgCanvas.setSvgString($('#svg_source_textarea').val())) {
if (oldString != $('#svg_source_textarea').val()) { if( !confirm('There were parsing errors in your SVG source.\nRevert back to original SVG source?') ) {
if (!svgCanvas.setSvgString($('#svg_source_textarea').val())) { return false;
alert('There were parsing errors in your SVG source.\nReverting back to original SVG source.');
} }
} }
hideSourceEditor();
};
var cancelSourceEditor = function() {
if (!editingsource) return;
var oldString = svgCanvas.getSvgString();
if (oldString != $('#svg_source_textarea').val()) {
if( !confirm('Ignore changes made to SVG source?') ) {
return false;
}
}
hideSourceEditor();
};
var hideSourceEditor = function(){
$('#svg_source_editor').hide(); $('#svg_source_editor').hide();
editingsource = false; editingsource = false;
$('#svg_source_textarea').blur(); $('#svg_source_textarea').blur();
@@ -544,6 +559,8 @@ function svg_edit_setup() {
$('#tool_clear').click(clickClear); $('#tool_clear').click(clickClear);
$('#tool_save').click(clickSave); $('#tool_save').click(clickSave);
$('#tool_source').click(showSourceEditor); $('#tool_source').click(showSourceEditor);
$('#tool_source_cancel,#svg_source_overlay').click(cancelSourceEditor);
$('#tool_source_save').click(saveSourceEditor);
$('#tool_delete').click(deleteSelected); $('#tool_delete').click(deleteSelected);
$('#tool_delete_multi').click(deleteSelected); $('#tool_delete_multi').click(deleteSelected);
$('#tool_move_top').click(moveToTopSelected); $('#tool_move_top').click(moveToTopSelected);
@@ -629,7 +646,7 @@ function svg_edit_setup() {
$(document).bind('keydown', {combi:'6', disableInInput: true}, clickText); $(document).bind('keydown', {combi:'6', disableInInput: true}, clickText);
$(document).bind('keydown', {combi:'7', disableInInput: true}, clickPoly); $(document).bind('keydown', {combi:'7', disableInInput: true}, clickPoly);
$(document).bind('keydown', {combi:modKey+'N', disableInInput: true}, function(evt){clickClear();evt.preventDefault();}); $(document).bind('keydown', {combi:modKey+'N', disableInInput: true}, function(evt){clickClear();evt.preventDefault();});
$(document).bind('keydown', {combi:modKey+'S', disableInInput: true}, function(evt){clickSave();evt.preventDefault();}); $(document).bind('keydown', {combi:modKey+'S', disableInInput: true}, function(evt){editingsource?saveSourceEditor():clickSave();evt.preventDefault();});
$(document).bind('keydown', {combi:'del', disableInInput: true}, function(evt){deleteSelected();evt.preventDefault();}); $(document).bind('keydown', {combi:'del', disableInInput: true}, function(evt){deleteSelected();evt.preventDefault();});
$(document).bind('keydown', {combi:'backspace', disableInInput: true}, function(evt){deleteSelected();evt.preventDefault();}); $(document).bind('keydown', {combi:'backspace', disableInInput: true}, function(evt){deleteSelected();evt.preventDefault();});
$(document).bind('keydown', {combi:'shift+up', disableInInput: true}, moveToTopSelected); $(document).bind('keydown', {combi:'shift+up', disableInInput: true}, moveToTopSelected);
@@ -642,7 +659,7 @@ function svg_edit_setup() {
$(document).bind('keydown', {combi:modKey+'y', disableInInput: true}, function(evt){clickRedo();evt.preventDefault();}); $(document).bind('keydown', {combi:modKey+'y', disableInInput: true}, function(evt){clickRedo();evt.preventDefault();});
$(document).bind('keydown', {combi:modKey+'u', disableInInput: true}, function(evt){showSourceEditor();evt.preventDefault();}); $(document).bind('keydown', {combi:modKey+'u', disableInInput: true}, function(evt){showSourceEditor();evt.preventDefault();});
$(document).bind('keydown', {combi:modKey+'c', disableInInput: true}, function(evt){clickClone();evt.preventDefault();}); $(document).bind('keydown', {combi:modKey+'c', disableInInput: true}, function(evt){clickClone();evt.preventDefault();});
$(document).bind('keydown', {combi:'esc', disableInInput: false}, hideSourceEditor); $(document).bind('keydown', {combi:'esc', disableInInput: false}, cancelSourceEditor);
// TODO: fix opacity being updated // TODO: fix opacity being updated
// TODO: go back to the color boxes having white background-color and then setting // TODO: go back to the color boxes having white background-color and then setting