How to add a "Delete line" command to the context menu
-
Hi folks!
I was following the instructions in the ContextMenu.xml file to add commands to the context menu, but that only seems to work for commands that already appear in the top menu, like “Duplicate current line” etc.
That doesn’t seem to work for the scintilla command SCI_LINEDELETE (Ctrl+Shift+L). Is there a way to add that to the context menu?
Or if there is another guide/help that can help with this, I’d appreciate a link…Thank you for your help!
-
You could record+save a one-step macro for it.
Give it a name e.g. “Line Delete”
Then, in contextMenu.xml you could add such a line:<Item MenuEntryName="Macro" MenuItemName="Line Delete"/>
There are probably other ways to achieve this as well.
-
Thanks for the quick response Alan!
Sorry if this is a dumb question, but how do I give it a name? I tried typing in the Name box in the shortcut mapper but it’s not letting me change it there. -
Sorry, didn’t realize you were so “noob”. :-)
Forget Shortcut Mapper; nothing needed to do there.Use the Macro menu and start macro recording.
Press Shift+Ctrl+L.
Use the Macro menu to stop macro recording.
Use the Macro menu to save your macro, thusly:After doing that your Macro menu will contain it:
It is the appearing on the Macro menu that allows the contextMenu.xml entry that I showed before to work.
-
Yes i’m a complete noob, and thanks for taking the time to explain! So I created the macro like you showed me, but then I can’t seem to add that new command to the right-click context menu like you showed earlier.
I tried adding this in contextMenu.xml:<Item MenuEntryName="Edit" MenuItemName="Line Delete"/>
but it’s not showing up.
-
@R-J said in How to add a "Delete line" command to the context menu:
but it’s not showing up.
Well, again maybe my original glossed over some details, when talking to a “noob”.
You can’t just add it, like at the bottom.
You have to insert it, at a valid place.
Try inserting it around Copy or Paste since it is a similar function.Here’s where I did it (in yellow) and you can see it worked for me (circled in red):
-
Are you sure there isn’t an addition step I need to do for macros to appear in the context menu? As you can see, I added “Duplicate Current Line”, but the “Line Delete” isn’t showing up.
-
OK I just noticed you used “Macro” for the MenuEntryName instead of “Edit”. This worked. I wish this was explained somewhere.
Thanks for your help! -
FYI the location doesn’t seem to matter, Alan. It works fine anywhere in the menu. Every place there seems valid.
-
@R-J said in How to add a "Delete line" command to the context menu:
I just noticed you used “Macro” for the MenuEntryName instead of “Edit”.
Well…yea, I mean, computers are picky about doing what you tell them.
I used “Macro” from the beginning.
And it makes sense, because we are trying to run something on the “Macro” menu (something we placed there).I wish this was explained somewhere.
Well, it is.
See the user MANUAL for how to work with the context menu.
I mean, I guess I could have simply pointed you there in the beginning.the location doesn’t seem to matter, Alan. It works fine anywhere in the menu. Every place there seems valid.
Well, yea…
But it has to be at a valid point in the XML structures.
You’ll remember that originally I just said “add it to contextMenu.xml”.
Well, a “noob” might open the file, scroll to the end, and paste it there.
That’s what I would do if someone told me that.
But that wouldn’t work for this file (it would be “off the end” of the proper structures).
The smarter thing, and what I intended, would be to observe what is there, and place anything new similarly – which is what I think you’re doing now.Glad we finally got it worked out for you!
-
Ah yes, that seems like a useful reference in the manual, and I always prefer to read documentation and learn on my own instead of asking on forms. I actually did a search in the manual for “context menu” before asking here, but it didn’t seem to find anything related at first glance. Now I realize that it only finds the titles of sections that may mention the keword, without highlighting any results.
So the search in the documentation isn’t great, especially for new users who don’t understand how it works and may think that it’s not finding their topic.And what you said about the command location which has to be contained within a certain code structure, also makes perfect sense.
Thanks again.