Skip to content

Commit

Permalink
Support handling of primary/secondary content edit action
Browse files Browse the repository at this point in the history
  • Loading branch information
dgthanhan committed May 10, 2017
1 parent 40a4976 commit 7a6a481
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/pencil-core/common/Canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -1393,7 +1393,7 @@ Canvas.prototype.handleKeyPress = function (event) {
event.preventDefault();
}
} else if (event.keyCode == DOM_VK_F2) {
if (this.currentController) {
if (this.currentController && !event.shiftKey && !event.ctrlKey && !event.altKey && !event.metaKey) {
Dom.emitEvent("p:TextEditingRequested", this.element, {
controller : this.currentController
});
Expand Down
25 changes: 25 additions & 0 deletions app/pencil-core/target/shape.js
Original file line number Diff line number Diff line change
Expand Up @@ -1252,3 +1252,28 @@ Shape.prototype.generateShortcutXML = function () {
}.bind(this)
});
};

Shape.prototype.getContentEditActions = function (event) {
var actions = [];
var editInfo = this.getTextEditingInfo(event);
if (editInfo) {
actions.push({
type: "text",
editInfo: editInfo
});
}
for (var action of this.def.actions) {
if (action.meta["content-action"] == "true") {
actions.push({
type: "action",
actionId: action.id
});
}
}

return actions;
};
Shape.prototype.handleOtherContentEditAction = function (action) {
if (action.type != "action") return;
this.performAction(action.actionId);
};
32 changes: 32 additions & 0 deletions app/views/editors/OnMenuEditor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
function OnMenuEditor() {
OnMenuEditor.globalSetup();
}

OnMenuEditor.globalSetupDone = false;
OnMenuEditor.globalSetup = function () {
if (OnMenuEditor.globalSetupDone) return;
OnMenuEditor.globalSetupDone = true;

OnMenuEditor.invokeSecondaryContentEditCommand = UICommandManager.register({
key: "invokeSecondaryContentEditCommand",
label: "invokeSecondaryContentEditCommand",
shortcut: "Shift+F2",
isAvailable: function () { return Pencil.activeCanvas && Pencil.activeCanvas.currentController && Pencil.activeCanvas.currentController.handleOtherContentEditAction },
run: function () {
var editActions = Pencil.activeCanvas.currentController.getContentEditActions();
if (editActions.length < 2) return;
Pencil.activeCanvas.currentController.handleOtherContentEditAction(editActions[1]);
}
});
};

OnMenuEditor.prototype.install = function (canvas) {
this.canvas = canvas;
this.canvas.contextMenuEditor = this;
Expand Down Expand Up @@ -154,6 +174,12 @@ OnMenuEditor.prototype.generateMenuItems = function () {

//actions
var actionItem = null;
var editActions = this.targetObject.getContentEditActions ? this.targetObject.getContentEditActions() : [];
var primaryActionId = null;
var secondaryActionId = null;
if (editActions.length > 0 && editActions[0].type == "action") primaryActionId = editActions[0].actionId;
if (editActions.length > 1 && editActions[1].type == "action") secondaryActionId = editActions[1].actionId;

if (this.targetObject.def && this.targetObject.performAction) {
for (var i in this.targetObject.def.actions) {
var action = this.targetObject.def.actions[i];
Expand All @@ -173,10 +199,16 @@ OnMenuEditor.prototype.generateMenuItems = function () {
subItems: []
}
}

var shortcut = null;
if (action.id == primaryActionId) shortcut = "F2";
if (action.id == secondaryActionId) shortcut = OnMenuEditor.invokeSecondaryContentEditCommand.shortcut;

actionItem.subItems.push({
label: action.displayName,
type: "Normal",
actionId: action.id,
shortcut: shortcut,
handleAction: function (){
thiz.targetObject.performAction(this.actionId);
thiz.canvas.invalidateEditors();
Expand Down
20 changes: 18 additions & 2 deletions app/views/editors/OnScreenRichTextEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,25 @@ OnScreenRichTextEditor.prototype.dettach = function () {

OnScreenRichTextEditor.prototype.handleShapeDoubleClicked = function (event) {
this.currentTarget = event.controller;
if (!this.currentTarget || !this.currentTarget.getTextEditingInfo) return;
if (!this.currentTarget) return;

this.textEditingInfo = this.currentTarget.getTextEditingInfo(event);
this.textEditingInfo = null;

if (this.currentTarget.getContentEditActions) {
var actions = this.currentTarget.getContentEditActions(event);
if (actions.length == 0) return;

var action = actions[0];
if (action.type == "text") {
this.textEditingInfo = action.editInfo;
} else {
this.currentTarget.handleOtherContentEditAction(action);
return;
}
} else {
if (!this.currentTarget.getTextEditingInfo) return;
this.textEditingInfo = this.currentTarget.getTextEditingInfo(event);
}

if (!this.textEditingInfo || this.textEditingInfo.readonly) return;

Expand Down

0 comments on commit 7a6a481

Please sign in to comment.