Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLOSED] Context Menu API, partial implementation #1006

Open
core-ai-bot opened this issue Aug 29, 2021 · 11 comments
Open

[CLOSED] Context Menu API, partial implementation #1006

core-ai-bot opened this issue Aug 29, 2021 · 11 comments

Comments

@core-ai-bot
Copy link
Member

Issue by tvoliter
Thursday Jun 07, 2012 at 20:57 GMT
Originally opened as adobe/brackets#1012


Ready for review


tvoliter included the following code: https://github.com/adobe/brackets/pull/1012/commits

@core-ai-bot
Copy link
Member Author

Comment by mikechambers
Thursday Jun 07, 2012 at 21:07 GMT


Can you provide a simple example of how an extension would create and open a context-menu?

@core-ai-bot
Copy link
Member Author

Comment by tvoliter
Thursday Jun 07, 2012 at 23:43 GMT


Sure, here is a hello world demo you can paste into a main.js file to try it out as a plugin

/_jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
/_global define, $, brackets, window */

/** Simple extension that adds a "File > Hello World" menu item */
define(function (require, exports, module) {
'use strict';

var CommandManager = brackets.getModule("command/CommandManager"),
    Menus          = brackets.getModule("command/Menus");


// Function to run when the menu item is clicked
function handleHelloWorld() {
    window.alert("Hello, world!");
}


// First, register a command - a UI-less object associating an id to a handler
var MY_COMMAND_ID = "helloworld.sayhello";
CommandManager.register("Hello World", MY_COMMAND_ID, handleHelloWorld);

// Register a new context menu
var cmenu = Menus.registerContextMenu("helloworld-context-menu");

// Get the menu object related to the context menu and add a MenuItem that will call your command
var menu = cmenu.getMenu();
menu.addMenuItem("mymenuid", MY_COMMAND_ID);

// Trigger the context meny by calling open(). Here we show it when right-clicking over the
// #projects div
$("#projects").mousedown(function (e) {
        if (e.which === 3) {
            cmenu.open(e.pageX, e.pageY);
        }
    });

});

-----Original Message-----
From: Mike Chambers [mailto:[email protected]]
Sent: Thursday, June 07, 2012 2:08 PM
To: Ty Voliter
Subject: Re: [brackets] Context Menu API (for review only) (#1012)

Can you provide a simple example of how an extension would create and open a context-menu?


Reply to this email directly or view it on GitHub:
adobe/brackets#1012 (comment)

@core-ai-bot
Copy link
Member Author

Comment by mikechambers
Thursday Jun 07, 2012 at 23:53 GMT


Could the x,y coords to open be optional, and if they are not passed in default to the correct position relative to the current position of the mouse?

Otherwise, there may be situations where the position of the menu should be different depending on the platform, that extension developers might not know about, or might not take into account.

Plus, it covers the primary use case and would make the api easier to use.

@core-ai-bot
Copy link
Member Author

Comment by redmunds
Friday Jun 08, 2012 at 00:03 GMT


@mikechambers On Windows, you can use the context-menu button to open a context-menu for the currently selected element (not at the mouse), so this is so both the keyboard and the mouse can be supported.

After that, Brackets will attempt to display the menu at the specified coordinates, but will adjust the menu position as necessary to fit it in the Brackets window.

@core-ai-bot
Copy link
Member Author

Comment by mikechambers
Friday Jun 08, 2012 at 00:05 GMT


@redmunds Sorry. What is the context-menu button?

@core-ai-bot
Copy link
Member Author

Comment by tvoliter
Friday Jun 08, 2012 at 00:13 GMT


Great suggestion!

-----Original Message-----
From: Mike Chambers [mailto:[email protected]]
Sent: Thursday, June 07, 2012 4:54 PM
To: Ty Voliter
Subject: Re: [brackets] Context Menu API (for review only) (#1012)

Could the x,y coords to open be optional, and if they are not passed in default to the correct position relative to the current position of the mouse?

Otherwise, there may be situations where the position of the menu should be different depending on the platform, that extension developers might not know about, or might not take into account.

Plus, it covers the primary use case and would make the api easier to use.


Reply to this email directly or view it on GitHub:
adobe/brackets#1012 (comment)

@core-ai-bot
Copy link
Member Author

Comment by mikechambers
Friday Jun 08, 2012 at 00:22 GMT


@redmunds Thanks. I didn't realize that you were referring to the context menu keyboard button on some windows keyboards. (I didn't even know such a thing existed).

@core-ai-bot
Copy link
Member Author

Comment by mikechambers
Friday Jun 08, 2012 at 00:33 GMT


What happens if multiple extensions want to work with the context menu and / or add items to it? For example, imagine a context menu opened when text selected and the user right clicks it. How will multiple extensions be able to add items to a single context menu?

Also, will there be default items (copy, cut, paste) that will always be in the context menu?

@core-ai-bot
Copy link
Member Author

Comment by tvoliter
Friday Jun 08, 2012 at 00:38 GMT


These are great questions and this is what I am actually investigating next. Early thoughts were that Brackets would have a few built in context menus tied to specific click areas like the editor, working set, file tree, etc. Plugins could add to these and could be more context sensitive by disabling/enabling items based on some criteria when the beforeContextMenuOpen event is triggered. I am also exploring how event bubbling and context menus will interact to see how Brackets will handle a general context menu that shows when clicking over a large div and a very specific context menu that shows when clicking on some small portion of that div.

What are your expectations on how this should work?

-----Original Message-----
From: Mike Chambers [mailto:[email protected]]
Sent: Thursday, June 07, 2012 5:33 PM
To: Ty Voliter
Subject: Re: [brackets] Context Menu API (for review only) (#1012)

What happens if multiple extensions want to work with the context menu and / or add items to it? For example, imagine a context menu opened when text selected and the user right clicks it. How will multiple extensions be able to add items to a single context menu?

Also, will there be default items (copy, cut, paste) that will always be in the context menu?


Reply to this email directly or view it on GitHub:
adobe/brackets#1012 (comment)

@core-ai-bot
Copy link
Member Author

Comment by mikechambers
Friday Jun 08, 2012 at 00:46 GMT


I would expect that my extension would add to an existing menu, and would not create a new one from scratch.

@core-ai-bot
Copy link
Member Author

Comment by tvoliter
Friday Jun 08, 2012 at 22:08 GMT


I did a bit of research and it seems it's not possible to query the current mouse position in browsers without an event. However, to make this API for friendly I changed it so it can take a MouseEvent or a specific location.

-----Original Message-----
From: Mike Chambers [mailto:[email protected]]
Sent: Thursday, June 07, 2012 4:54 PM
To: Ty Voliter
Subject: Re: [brackets] Context Menu API (for review only) (#1012)

Could the x,y coords to open be optional, and if they are not passed in default to the correct position relative to the current position of the mouse?

Otherwise, there may be situations where the position of the menu should be different depending on the platform, that extension developers might not know about, or might not take into account.

Plus, it covers the primary use case and would make the api easier to use.


Reply to this email directly or view it on GitHub:
adobe/brackets#1012 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant