Skip to content
This repository has been archived by the owner on Sep 4, 2019. It is now read-only.

Exposed methods for disabling/enabling platform menu items in the contex... #476

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions ext/ui.contextmenu/client.js
Expand Up @@ -119,6 +119,18 @@ contextmenu.defineCustomContext = function (customContext, options) {
window.webworks.execAsync(_ID, 'defineCustomContext', {context: customContext, options: options});
};

contextmenu.disablePlatformItem = function (context, actionId) {
return window.webworks.execSync(_ID, 'disablePlatformItem', {context: context, actionId: actionId});
};

contextmenu.enablePlatformItem = function (context, actionId) {
return window.webworks.execSync(_ID, 'enablePlatformItem', {context: context, actionId: actionId});
};

contextmenu.listDisabledPlatformItems = function () {
return window.webworks.execSync(_ID, 'listDisabledPlatformItems');
};

defineReadOnlyContext("ALL");
defineReadOnlyContext("LINK");
defineReadOnlyContext("IMAGE_LINK");
Expand All @@ -138,5 +150,6 @@ defineReadOnlyActions("SAVE_IMAGE", "SaveImage");
defineReadOnlyActions("COPY_IMAGE_LINK", "CopyImageLink");
defineReadOnlyActions("VIEW_IMAGE", "ViewImage");
defineReadOnlyActions("INSPECT_ELEMENT", "InspectElement");
defineReadOnlyActions("MENU_SERVICE", "MenuService");

module.exports = contextmenu;
19 changes: 19 additions & 0 deletions ext/ui.contextmenu/index.js
Expand Up @@ -74,12 +74,31 @@ function defineCustomContext(success, fail, args, env) {
_overlayWebView.contextMenu.defineCustomContext(args.context, args.options);
}

function disablePlatformItem(success, fail, args) {
args.context = JSON.parse(decodeURIComponent(args.context));
args.actionId = JSON.parse(decodeURIComponent(args.actionId));
success(_overlayWebView.contextMenu.disablePlatformItem(args.context, args.actionId));
}

function enablePlatformItem(success, fail, args) {
args.context = JSON.parse(decodeURIComponent(args.context));
args.actionId = JSON.parse(decodeURIComponent(args.actionId));
success(_overlayWebView.contextMenu.enablePlatformItem(args.context, args.actionId));
}

function listDisabledPlatformItems(success) {
success(_overlayWebView.contextMenu.listDisabledPlatformItems());
}

contextmenu = {
enabled: enabled,
addItem: addItem,
removeItem: removeItem,
overrideItem: overrideItem,
clearOverride: clearOverride,
disablePlatformItem: disablePlatformItem,
enablePlatformItem: enablePlatformItem,
listDisabledPlatformItems: listDisabledPlatformItems,
defineCustomContext: defineCustomContext
};

Expand Down
21 changes: 20 additions & 1 deletion test/unit/ext/ui.contextmenu/client.js
Expand Up @@ -72,12 +72,12 @@ describe("blackberry.ui.contextmenu client", function () {
expect(client.ACTION_COPY_LINK).toEqual("CopyLink");
expect(client.ACTION_CUT).toEqual("Cut");
expect(client.ACTION_INSPECT_ELEMENT).toEqual("InspectElement");
expect(client.ACTION_OPEN_LINK).toEqual("OpenLink");
expect(client.ACTION_PASTE).toEqual("Paste");
expect(client.ACTION_SAVE_IMAGE).toEqual("SaveImage");
expect(client.ACTION_SAVE_LINK_AS).toEqual("SaveLinkAs");
expect(client.ACTION_VIEW_IMAGE).toEqual("ViewImage");
expect(client.ACTION_SELECT).toEqual("Select");
expect(client.ACTION_MENU_SERVICE).toEqual("MenuService");
});

it("Cannot add a menu item without a context", function () {
Expand Down Expand Up @@ -125,4 +125,23 @@ describe("blackberry.ui.contextmenu client", function () {
client.clearOverride(actionId);
expect(mockedWebworks.execSync).toHaveBeenCalledWith(_ID, 'clearOverride', {actionId: actionId});
});

it("can disable a platform provided item", function () {
var context = client.CONTEXT_ALL,
actionId = client.ACTION_OPEN_LINK;
client.disablePlatformItem(context, actionId);
expect(mockedWebworks.execSync).toHaveBeenCalledWith(_ID, 'disablePlatformItem', {context: context, actionId: actionId});
});

it("can enable a disabled platform provided item", function () {
var context = client.CONTEXT_ALL,
actionId = client.ACTION_OPEN_LINK;
client.enablePlatformItem(context, actionId);
expect(mockedWebworks.execSync).toHaveBeenCalledWith(_ID, 'enablePlatformItem', {context: context, actionId: actionId});
});

it("can list the disabled platform provided item", function () {
client.listDisabledPlatformItems();
expect(mockedWebworks.execSync).toHaveBeenCalledWith(_ID, 'listDisabledPlatformItems');
});
});
25 changes: 25 additions & 0 deletions test/unit/ext/ui.contextmenu/index.js
Expand Up @@ -25,6 +25,9 @@ var _extDir = __dirname + "./../../../../ext/",
overrideItem: jasmine.createSpy(),
clearOverride: jasmine.createSpy(),
defineCustomContext: jasmine.createSpy(),
disablePlatformItem: jasmine.createSpy(),
enablePlatformItem: jasmine.createSpy(),
listDisabledPlatformItems: jasmine.createSpy(),
enabled : true
},
mockedQnx = {
Expand Down Expand Up @@ -195,4 +198,26 @@ describe("blackberry.ui.contextmenu index", function () {
expect(mockedContextMenu.clearOverride).toHaveBeenCalledWith('MenuService-Share');
});

it("can disable a platform menu item", function () {
var args = {
actionId: encodeURIComponent(JSON.stringify('Paste')),
context: encodeURIComponent(JSON.stringify('INPUT'))
};
contextmenu.disablePlatformItem(success, fail, args);
expect(mockedContextMenu.disablePlatformItem).toHaveBeenCalledWith(args.context, args.actionId);
});

it("can enable a disabled platform menu item", function () {
var args = {
actionId: encodeURIComponent(JSON.stringify('Paste')),
context: encodeURIComponent(JSON.stringify('INPUT'))
};
contextmenu.enablePlatformItem(success, fail, args);
expect(mockedContextMenu.enablePlatformItem).toHaveBeenCalledWith(args.context, args.actionId);
});

it("can list all disabled platform menu items", function () {
contextmenu.listDisabledPlatformItems(success);
expect(mockedContextMenu.listDisabledPlatformItems).toHaveBeenCalled();
});
});