area._stopAll
* pros: the function is shared and it decreases bugs. * cons: drawing/writing/transfo are not deleted if unfinished.
This commit is contained in:
parent
324c066685
commit
eb87714adc
73
area.js
73
area.js
|
|
@ -367,7 +367,8 @@ var DrawingArea = new Lang.Class({
|
||||||
} else if (button == 2) {
|
} else if (button == 2) {
|
||||||
this.switchFill();
|
this.switchFill();
|
||||||
} else if (button == 3) {
|
} else if (button == 3) {
|
||||||
this._stopDrawing();
|
this._stopAll();
|
||||||
|
|
||||||
this.menu.open(x, y);
|
this.menu.open(x, y);
|
||||||
return Clutter.EVENT_STOP;
|
return Clutter.EVENT_STOP;
|
||||||
}
|
}
|
||||||
|
|
@ -376,7 +377,8 @@ var DrawingArea = new Lang.Class({
|
||||||
},
|
},
|
||||||
|
|
||||||
_onKeyboardPopupMenu: function() {
|
_onKeyboardPopupMenu: function() {
|
||||||
this._stopDrawing();
|
this._stopAll();
|
||||||
|
|
||||||
if (this.helper.visible)
|
if (this.helper.visible)
|
||||||
this.toggleHelp();
|
this.toggleHelp();
|
||||||
this.menu.popup();
|
this.menu.popup();
|
||||||
|
|
@ -832,6 +834,21 @@ var DrawingArea = new Lang.Class({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// A priori there is nothing to stop, except transformations, if there is no current element.
|
||||||
|
// 'force' argument is passed when leaving drawing mode to ensure all is clean, as a workaround for possible bugs.
|
||||||
|
_stopAll: function(force) {
|
||||||
|
if (this.grabbedElement)
|
||||||
|
this._stopTransforming();
|
||||||
|
|
||||||
|
if (!this.currentElement && !force)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (this.isWriting)
|
||||||
|
this._stopWriting();
|
||||||
|
|
||||||
|
this._stopDrawing();
|
||||||
|
},
|
||||||
|
|
||||||
erase: function() {
|
erase: function() {
|
||||||
this.deleteLastElement();
|
this.deleteLastElement();
|
||||||
this.elements = [];
|
this.elements = [];
|
||||||
|
|
@ -840,21 +857,8 @@ var DrawingArea = new Lang.Class({
|
||||||
},
|
},
|
||||||
|
|
||||||
deleteLastElement: function() {
|
deleteLastElement: function() {
|
||||||
if (this.currentElement) {
|
this._stopAll();
|
||||||
if (this.motionHandler) {
|
|
||||||
this.disconnect(this.motionHandler);
|
|
||||||
this.motionHandler = null;
|
|
||||||
}
|
|
||||||
if (this.buttonReleasedHandler) {
|
|
||||||
this.disconnect(this.buttonReleasedHandler);
|
|
||||||
this.buttonReleasedHandler = null;
|
|
||||||
}
|
|
||||||
if (this.isWriting)
|
|
||||||
this._stopWriting();
|
|
||||||
this.currentElement = null;
|
|
||||||
} else {
|
|
||||||
this.elements.pop();
|
this.elements.pop();
|
||||||
}
|
|
||||||
this._redisplay();
|
this._redisplay();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -1085,25 +1089,16 @@ var DrawingArea = new Lang.Class({
|
||||||
this.disconnect(this.keyboardPopupMenuHandler);
|
this.disconnect(this.keyboardPopupMenuHandler);
|
||||||
this.keyboardPopupMenuHandler = null;
|
this.keyboardPopupMenuHandler = null;
|
||||||
}
|
}
|
||||||
if (this.motionHandler) {
|
|
||||||
this.disconnect(this.motionHandler);
|
|
||||||
this.motionHandler = null;
|
|
||||||
}
|
|
||||||
if (this.buttonReleasedHandler) {
|
|
||||||
this.disconnect(this.buttonReleasedHandler);
|
|
||||||
this.buttonReleasedHandler = null;
|
|
||||||
}
|
|
||||||
if (this.scrollHandler) {
|
if (this.scrollHandler) {
|
||||||
this.disconnect(this.scrollHandler);
|
this.disconnect(this.scrollHandler);
|
||||||
this.scrollHandler = null;
|
this.scrollHandler = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.currentElement = null;
|
this._stopAll(true);
|
||||||
this._stopTextCursorTimeout();
|
|
||||||
if (erase)
|
if (erase)
|
||||||
this.erase();
|
this.erase();
|
||||||
else
|
|
||||||
this._redisplay();
|
|
||||||
this.closeMenu();
|
this.closeMenu();
|
||||||
this.get_parent().set_background_color(null);
|
this.get_parent().set_background_color(null);
|
||||||
Files.Images.reset();
|
Files.Images.reset();
|
||||||
|
|
@ -1143,12 +1138,7 @@ var DrawingArea = new Lang.Class({
|
||||||
},
|
},
|
||||||
|
|
||||||
exportToSvg: function() {
|
exportToSvg: function() {
|
||||||
// stop drawing or writing
|
this._stopAll();
|
||||||
if (this.currentElement && this.currentElement.shape == Shapes.TEXT && this.isWriting) {
|
|
||||||
this._stopWriting();
|
|
||||||
} else if (this.currentElement && this.currentElement.shape != Shapes.TEXT) {
|
|
||||||
this._stopDrawing();
|
|
||||||
}
|
|
||||||
|
|
||||||
let prefixes = 'xmlns="http://www.w3.org/2000/svg"';
|
let prefixes = 'xmlns="http://www.w3.org/2000/svg"';
|
||||||
if (this.elements.some(element => element.shape == Shapes.IMAGE))
|
if (this.elements.some(element => element.shape == Shapes.IMAGE))
|
||||||
|
|
@ -1181,12 +1171,7 @@ var DrawingArea = new Lang.Class({
|
||||||
},
|
},
|
||||||
|
|
||||||
_saveAsJson: function(json, notify, callback) {
|
_saveAsJson: function(json, notify, callback) {
|
||||||
// stop drawing or writing
|
this._stopAll();
|
||||||
if (this.currentElement && this.currentElement.shape == Shapes.TEXT && this.isWriting) {
|
|
||||||
this._stopWriting();
|
|
||||||
} else if (this.currentElement && this.currentElement.shape != Shapes.TEXT) {
|
|
||||||
this._stopDrawing();
|
|
||||||
}
|
|
||||||
|
|
||||||
// do not use "content = JSON.stringify(this.elements, null, 2);", neither "content = JSON.stringify(this.elements);"
|
// do not use "content = JSON.stringify(this.elements, null, 2);", neither "content = JSON.stringify(this.elements);"
|
||||||
// do compromise between disk usage and human readability
|
// do compromise between disk usage and human readability
|
||||||
|
|
@ -1225,12 +1210,8 @@ var DrawingArea = new Lang.Class({
|
||||||
},
|
},
|
||||||
|
|
||||||
_loadJson: function(json, notify) {
|
_loadJson: function(json, notify) {
|
||||||
// stop drawing or writing
|
this._stopAll();
|
||||||
if (this.currentElement && this.currentElement.shape == Shapes.TEXT && this.isWriting) {
|
|
||||||
this._stopWriting();
|
|
||||||
} else if (this.currentElement && this.currentElement.shape != Shapes.TEXT) {
|
|
||||||
this._stopDrawing();
|
|
||||||
}
|
|
||||||
this.elements = [];
|
this.elements = [];
|
||||||
this.currentElement = null;
|
this.currentElement = null;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue