Shortcut or menu path to "Rotate to right/left"

  • I use the “Customize Toolbar” plugin to add favorite commands to the toolbar. One button I’ve added is to split my windows. The way the plugin works, I define the N++ menu path to the command in the Customize Toolbar config file, along with a 16x16 icon to show on the toolbar i.e. “View,Move/Clone Current Document,Move to Other View,split.bmp”.

    I now want to add a button to rotate the view between horizontal and vertical. Unfortunately, those commands (“Rotate to right” and “Rotate to left”) are on the window splitter/grabber, not in the main menu structure. Is there a menu path or keyboard shortcut to those two rotate commands that I’ve missed somewhere?

    I’m obviously looking for a single-click rotate, instead of a right-click on the grabber followed by a left click on the rotate command.

  • Unfortunately, looking at the source code, it appears that the splitter-container hardcode-generates those commands, and I don’t think even the plugins communication system has any messages which talk directly with the SplitterContainer’s object. I couldn’t find any menu command ID’s which affect that either (though the move and clone to other view are there).

    Without a command ID or main menu position, you cannot record it in a macro. Without a published message ID, you’re not supposed to access those internal messages to manipulate it via a plugin.

    However, a clever PythonScript programmer could probably search through the child-windows of the main Notepad++ GUI window, until they found the SplitterContainer object’s HWND, and then SendMessage to that HWND to send a WM_COMMAND message to the SplitterContainer, with the lword as the left and right constants. Not that I would recommend someone do that 😉, since sending unpublished messages to internal hwnd objects is not guaranteed to stay consistently working from one version to the next (which is a risk you take by going beyond the published API).

  • Very much appreciated. It’s obviously not a major issue, but I wanted to make sure I wasn’t missing something obvious.

  • A python script might look like this

    import ctypes
    ROTATION_A_LEFT = 2000
    WM_COMMAND = 0x111
    def isSingleView():
        npp_hwnd = ctypes.windll.user32.FindWindowW(u'Notepad++', None)
        splitter_hwnd = ctypes.windll.user32.FindWindowExW(npp_hwnd, None, u'splitterContainer', None)
        return (not bool(ctypes.windll.user32.IsWindowVisible(splitter_hwnd)), splitter_hwnd)
    def LOWORD(value): return value & 0xFFFF
    single_view, hwnd = isSingleView()
    if not single_view:
        ctypes.windll.user32.SendMessageW(hwnd, WM_COMMAND, LOWORD(ROTATION_A_LEFT), 0)

    @PeterJones - thx - explanation was perfect - I did not even had to check the source :-)

  • Thank you! I’ve not done Python before, but with such clear code, I figured I’d give it a shot. :) Your code worked perfectly.

    Unfortunately, while I can run the script from the menu, when I try to assign it to “Customize Toolbar”, nothing happens when I press the new toolbar button. In case anyone sees something wrong with my last config line below, or knows something about a step I’m missing, I thought I’d post. All of the other commands below work as expected, it’s just that Rotate does nothing when the button is pressed.

    Edit,Line Operations,Sort Lines Lexicographically Ascending,sort.bmp
    Edit,Line Operations,Remove Consecutive Duplicate Lines,dedup.bmp
    Plugins,XML Tools,Pretty print (XML only),xml.bmp
    Plugins,JSON Viewer,Format JSON,json.bmp
    View,Move/Clone Current Document,Move to Other View,split.bmp
    Plugins,Python Script,Scripts,Rotate,rotate.bmp

    Thank you again.

  • @VTGroupGitHub ,

    I don’t use Customize Toolbar. However, something does jump out at me: the first 5 rows of your config have 3 levels of menu (main menu, submenu, command) followed by the icon/bmp; the last has 4 levels of menu (main, submenu, submenu, command) before the icon/bmp. It may be that Customize Toolbar cannot go that deep (I don’t know).

    PythonScript plugin has Plugins > Python Script > Configuration…, which allows you to add a script into the Menu Items list on the left – this is a prerequisite to configuring a Settings > Shortcut Mapper keyboard shortcut to a script, and it might also be necessary for the script to work with Customize Toolbar as well – because if the Rotate script were in the left-hand list, it would show up in Plugins > Python Script > Rotate – which could be accessed using:

    Plugins,Python Script,Rotate,rotate.bmp

    … which then has the same number of levels as your other commands.

    Aside from that, there’s also the right-hand pane in the same Configuration… dialog, which allows you do add a PythonScript script directly into the toolbar (complete with icon) without needing the Customize Toolbar plugin at all.

  • I don’t know how to explain what happened, but I restarted N++ one more time, and now the button works as expected.
    Very odd, as I’d done that a couple of times already. Thanks to everyone for the assistance!

    And regarding the same number of levels comment, it appears that tool we’re using to talk decides that back-to-back commas should be displayed as a single comma. In all but the last config line above, there are 2 commas before the .bmp. The second comma just didn’t render in my post.

  • @VTGroupGitHub said in Shortcut or menu path to "Rotate to right/left":

    tool we’re using to talk decides

    Yes, it uses markdown format – though I’ve never seen it eat commas before; I guess it depends on what other markdown you’re using.

    If you ever want text to come through literally, the best is to highlight the literal then press the </> toolbar button at the top:

    Edit,Line Operations,Sort Lines Lexicographically Ascending,,sort.bmp

  • What I think the problem was is that a newly created script hasn’t been assigned
    an ID known to npp. This is normally done during plugin initialization where npp
    asks for functions to register, hence the restart of npp solved it.

Log in to reply