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

Is it possible to set the position of the menu item in the context menu? #313

Closed
aybe opened this issue Nov 4, 2019 · 7 comments · Fixed by #316
Closed

Is it possible to set the position of the menu item in the context menu? #313

aybe opened this issue Nov 4, 2019 · 7 comments · Fixed by #316
Labels
docs related to documentation at /docs/ or needs to be added feature-request rather a new feature request or request of change than an issue with existing features keep-open-please The problem/task is solved but please keep the issue open for related changes/docs/work question only a question, not a problem, might not be sharpshell specific

Comments

@aybe
Copy link

aybe commented Nov 4, 2019

Version of SharpShell used: 2.7.1

Related type(s) of SharpShell-Server: Directory, DirectoryBackground

As you can see below, the menu item sits at the very top of the context menu, which while nice, breaks a bit UX. Ideally, I would like it to sit below View, Sort by, Group by, Refresh, Customize this folder..., Paste, i.e. where all non-system menu items are.

2019-11-04_19-30-03

Here's current code:

using System.Linq;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using DOSBoxCTX.Properties;
using SharpShell.Attributes;
using SharpShell.SharpContextMenu;

namespace DOSBoxCTX
{
    [ComVisible(true)]
    [COMServerAssociation(AssociationType.Directory)]
    [COMServerAssociation(AssociationType.DirectoryBackground)]
    public class DosBoxContextMenu : SharpContextMenu
    {
        protected override bool CanShowMenu()
        {
            return true;
        }

        protected override ContextMenuStrip CreateMenu()
        {
            var menu = new ContextMenuStrip();

            var root = new ToolStripMenuItem
            {
                Name = "DOSBox-X", // prevents double menu items: https://github.com/dwmkerr/sharpshell/issues/277
                Text = @"DOSBox-X",
                Image = Resources.DosBox
            };

            var pick = new ToolStripMenuItem("Pick as C drive");
            pick.Click += (sender, args) =>
            {
                var path = SelectedItemPaths?.FirstOrDefault() ?? FolderPath;

                MessageBox.Show(path);
            };

            root.DropDownItems.Add(pick);

            menu.Items.Add(root);

            return menu;
        }
    }
}

Is this possible somehow?

Thank you.

@Countryen
Copy link
Collaborator

Hey @aybe, good question, sadly yet there is no clear way to do this.
From the just closed duplicate issue:

You can sort of define the position of an item manually in the registry subkey via a "Position" REG_SZ" attribute,
like so for the directory background:

HKEY_CLASSES_ROOT
   Directory
      Background
         shell
            Test {Position=Bottom}

This should be more or less directly above the "Properties"-entry (above the line).
Don't know if you can define the position further, haven't found a way yet.

Source:
docs.microsoft.com

Also, reading a bit more at MS docs, these resources could help you do it.
I don't think there is yet a feature that supports that, but if possible, we can add that.

If you can, try to overwrite/change the implementation to use the index and set the index where you want it to be. Never tryed yet. Maybe you want to try it and make a PR implementing that feature if working, would help tons ❤️.

@Countryen Countryen added duplicate question only a question, not a problem, might not be sharpshell specific docs related to documentation at /docs/ or needs to be added feature-request rather a new feature request or request of change than an issue with existing features and removed duplicate labels Nov 4, 2019
@aybe
Copy link
Author

aybe commented Nov 4, 2019

There you go:

#314

Needs more testing but so far works as expected!

@Countryen
Copy link
Collaborator

Great 👍 will look into it more tomorrow as it's almost midnight here :D

Question: How do you specify "uint itemIndex" now? Or is the one from the system okay for you?
Can you show an example code/registry?

@aybe
Copy link
Author

aybe commented Nov 4, 2019

To me, the value IContextMenu.QueryContextMenu gets from the system is just fine.

Not sure I understand what you mean, I did nothing more than implementing a context menu, nothing at all in registry (it just works out of the box).

I did a quick test, copy pasted a context menu many times, looks like it's working fine:

2019-11-05_00-26-56

I think it's just best to leave it as it is, it addresses most cases if not all, so why bother ? :)

@aybe aybe closed this as completed Nov 5, 2019
@Countryen
Copy link
Collaborator

Hey @aybe thanks for clearing that in your PR.
I want to keep this open to add it (how to position items) to the docs with a reference to your comment (314), why specifying the index manually is usually a bad idea. I will close it, after checking the docs.

@Countryen Countryen reopened this Nov 5, 2019
@Countryen Countryen added the keep-open-please The problem/task is solved but please keep the issue open for related changes/docs/work label Nov 5, 2019
@aybe
Copy link
Author

aybe commented Nov 5, 2019 via email

@shahshyam
Copy link

ure I understand what you mea

To me, the value IContextMenu.QueryContextMenu gets from the system is just fine.

Not sure I understand what you mean, I did nothing more than implementing a context menu, nothing at all in registry (it just works out of the box).

I did a quick test, copy pasted a context menu many times, looks like it's working fine:

2019-11-05_00-26-56

I think it's just best to leave it as it is, it addresses most cases if not all, so why bother ? :)

Have you tried in windows 11? . I am struggling to set option in window 11. It is showing context menu but I need to click on show more options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs related to documentation at /docs/ or needs to be added feature-request rather a new feature request or request of change than an issue with existing features keep-open-please The problem/task is solved but please keep the issue open for related changes/docs/work question only a question, not a problem, might not be sharpshell specific
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants