complete context menu implementation (27ea6a8be9)
1. close menu when leaving drawing mode 2. open menu with 'popup-menu' key (doesn't work for closing) 3. update 'disable' methods
This commit is contained in:
parent
c04dd01b44
commit
2a0c6536f2
40
draw.js
40
draw.js
|
|
@ -175,6 +175,7 @@ var DrawingArea = new Lang.Class({
|
||||||
} else if (button == 2) {
|
} else if (button == 2) {
|
||||||
this.toggleShape();
|
this.toggleShape();
|
||||||
} else if (button == 3) {
|
} else if (button == 3) {
|
||||||
|
this._stopDrawing();
|
||||||
this.menu.open(x, y);
|
this.menu.open(x, y);
|
||||||
return Clutter.EVENT_STOP;
|
return Clutter.EVENT_STOP;
|
||||||
}
|
}
|
||||||
|
|
@ -182,6 +183,14 @@ var DrawingArea = new Lang.Class({
|
||||||
return Clutter.EVENT_PROPAGATE;
|
return Clutter.EVENT_PROPAGATE;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_onKeyboardPopupMenu: function() {
|
||||||
|
this._stopDrawing();
|
||||||
|
if (this.helper.visible)
|
||||||
|
this.helper.hideHelp();
|
||||||
|
this.menu.popup();
|
||||||
|
return Clutter.EVENT_STOP;
|
||||||
|
},
|
||||||
|
|
||||||
_onKeyPressed: function(actor, event) {
|
_onKeyPressed: function(actor, event) {
|
||||||
if (event.get_key_symbol() == Clutter.Escape) {
|
if (event.get_key_symbol() == Clutter.Escape) {
|
||||||
this.emitter.emit('stop-drawing');
|
this.emitter.emit('stop-drawing');
|
||||||
|
|
@ -485,6 +494,7 @@ var DrawingArea = new Lang.Class({
|
||||||
enterDrawingMode: function() {
|
enterDrawingMode: function() {
|
||||||
this.keyPressedHandler = this.connect('key-press-event', this._onKeyPressed.bind(this));
|
this.keyPressedHandler = this.connect('key-press-event', this._onKeyPressed.bind(this));
|
||||||
this.buttonPressedHandler = this.connect('button-press-event', this._onButtonPressed.bind(this));
|
this.buttonPressedHandler = this.connect('button-press-event', this._onButtonPressed.bind(this));
|
||||||
|
this._onKeyboardPopupMenuHandler = this.connect('popup-menu', this._onKeyboardPopupMenu.bind(this));
|
||||||
this.scrollHandler = this.connect('scroll-event', this._onScroll.bind(this));
|
this.scrollHandler = this.connect('scroll-event', this._onScroll.bind(this));
|
||||||
this.selectShape(Shapes.NONE);
|
this.selectShape(Shapes.NONE);
|
||||||
this.get_parent().set_background_color(this.hasBackground ? this.activeBackgroundColor : null);
|
this.get_parent().set_background_color(this.hasBackground ? this.activeBackgroundColor : null);
|
||||||
|
|
@ -500,6 +510,10 @@ var DrawingArea = new Lang.Class({
|
||||||
this.disconnect(this.buttonPressedHandler);
|
this.disconnect(this.buttonPressedHandler);
|
||||||
this.buttonPressedHandler = null;
|
this.buttonPressedHandler = null;
|
||||||
}
|
}
|
||||||
|
if (this._onKeyboardPopupMenuHandler) {
|
||||||
|
this.disconnect(this._onKeyboardPopupMenuHandler);
|
||||||
|
this._onKeyboardPopupMenuHandler = null;
|
||||||
|
}
|
||||||
if (this.motionHandler) {
|
if (this.motionHandler) {
|
||||||
this.disconnect(this.motionHandler);
|
this.disconnect(this.motionHandler);
|
||||||
this.motionHandler = null;
|
this.motionHandler = null;
|
||||||
|
|
@ -520,6 +534,7 @@ var DrawingArea = new Lang.Class({
|
||||||
this._stopCursorTimeout();
|
this._stopCursorTimeout();
|
||||||
this.dashedLine = false;
|
this.dashedLine = false;
|
||||||
this._redisplay();
|
this._redisplay();
|
||||||
|
this.menu.close();
|
||||||
this.get_parent().set_background_color(null);
|
this.get_parent().set_background_color(null);
|
||||||
if (save)
|
if (save)
|
||||||
this.saveAsJson();
|
this.saveAsJson();
|
||||||
|
|
@ -605,6 +620,7 @@ var DrawingArea = new Lang.Class({
|
||||||
|
|
||||||
disable: function() {
|
disable: function() {
|
||||||
this.erase();
|
this.erase();
|
||||||
|
this.menu.disable();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -982,13 +998,32 @@ var DrawingMenu = new Lang.Class({
|
||||||
this.menu.connect('open-state-changed', this._onMenuOpenStateChanged.bind(this));
|
this.menu.connect('open-state-changed', this._onMenuOpenStateChanged.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
disable: function() {
|
||||||
|
this.menuManager.removeMenu(this.menu);
|
||||||
|
Main.layoutManager.uiGroup.remove_actor(this.menu.actor);
|
||||||
|
this.menu.actor.destroy();
|
||||||
|
},
|
||||||
|
|
||||||
_onMenuOpenStateChanged: function(menu, open) {
|
_onMenuOpenStateChanged: function(menu, open) {
|
||||||
if (!open)
|
if (!open)
|
||||||
// actionMode has changed, set previous actionMode in order to keep internal shortcuts working
|
// actionMode has changed, set previous actionMode in order to keep internal shortcuts working
|
||||||
Main.actionMode = ExtensionJs.DRAWING_ACTION_MODE | Shell.ActionMode.NORMAL;
|
Main.actionMode = ExtensionJs.DRAWING_ACTION_MODE | Shell.ActionMode.NORMAL;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
popup: function() {
|
||||||
|
if (this.menu.isOpen) {
|
||||||
|
this.close();
|
||||||
|
} else {
|
||||||
|
this.open();
|
||||||
|
this.menu.actor.navigate_focus(null, Gtk.DirectionType.TAB_FORWARD, false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
open: function(x, y) {
|
open: function(x, y) {
|
||||||
|
if (this.menu.isOpen)
|
||||||
|
return;
|
||||||
|
if (x === undefined || y === undefined)
|
||||||
|
[x, y] = [this.area.monitor.x + this.area.monitor.width / 2, this.area.monitor.y + this.area.monitor.height / 2];
|
||||||
this._redisplay();
|
this._redisplay();
|
||||||
Main.layoutManager.setDummyCursorGeometry(x, y, 0, 0);
|
Main.layoutManager.setDummyCursorGeometry(x, y, 0, 0);
|
||||||
let monitor = this.area.monitor;
|
let monitor = this.area.monitor;
|
||||||
|
|
@ -997,6 +1032,11 @@ var DrawingMenu = new Lang.Class({
|
||||||
this.menuManager.ignoreRelease();
|
this.menuManager.ignoreRelease();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
close: function() {
|
||||||
|
if (this.menu.isOpen)
|
||||||
|
this.menu.close();
|
||||||
|
},
|
||||||
|
|
||||||
_redisplay: function() {
|
_redisplay: function() {
|
||||||
this.menu.removeAll();
|
this.menu.removeAll();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue