Sublime Forum

API: Get path of selected node in side bar

#1

Hello,

Getting the path of selected node in side bar would be very helpful for many file manipulation plugins and user uses. Please consider adding it to the API.

Related post:
viewtopic.php?f=6&t=12025&start=0&hilit=sidebar+node

Thank you,
Mark.

0 Likes

#2

Problem with that, is that when you switch of view, it automatically changes your selection in the sidebar (thing that Is really annoying [to not say other things :stuck_out_tongue:])

0 Likes

#3

I don’t see that as much of a problem, as my use case for that API (being able to operate on folders, and creating files in empty folders) would not be affected. I would focus on the sidebar, select the node I want, and operate on it. Then when the focus goes back to a view, I don’t care what the current node is.

(Although I suspect the implementation of this API would include something like “focusing on a view does not change the currently selected node in the sidebar”)

0 Likes

#4

[quote=“MarkVilla”]Hello,

Getting the path of selected node in side bar would be very helpful for many file manipulation plugins and user uses. Please consider adding it to the API.[/quote]

WindowCommand methods are passed an array of full paths to the selected nodes in paths. For example:

def run(self, paths=]):
0 Likes

#5

[quote=“aparajita”]

[quote=“MarkVilla”]Hello,

Getting the path of selected node in side bar would be very helpful for many file manipulation plugins and user uses. Please consider adding it to the API.[/quote]

WindowCommand methods are passed an array of full paths to the selected nodes in paths. For example:

def run(self, paths=]): [/quote]

You are right, but as far as I know, that only works when you can that command from a .sublime-menu entry.

If you try to bind it to a .sublime-keymap shortcut, the array is always empty.

0 Likes

#6

[quote=“MarkVilla”]You are right, but as far as I know, that only works when you can that command from a .sublime-menu entry.

If you try to bind it to a .sublime-keymap shortcut, the array is always empty.[/quote]

Then give your command the logic to determine how its been launched. If you get a non empty paths array, you know you are probably getting the call from the sidebar menu and you can use the array, if you get a group and index, you are probably getting a call from a tab context menu and can select the view at the group and index and get the required info from the view, if you get none of those, then you probably are getting the call from either a view context menu, command palette, or keymap so you can just call active_view from the window object to get the view and get the info you need. I actually do this in some of my plugins.

[pre=#FAFDFF] def run(self, external=False, paths=], group=-1, index=-1):
self.external = external
self.set_view(paths, group, index)

def set_view(self, paths, group=-1, index=-1, open_file=True):
    if len(paths):
        file_path = get_target(paths)
        if file_path is None:
            return
        if open_file:
            self.view = self.window.open_file(file_path)
    elif index != -1:
        self.view = get_group_view(self.window, group, index)
    else:
        self.view = self.window.active_view()[/pre]
0 Likes

#7

Obviously this doesn’t work if your hoping to get a folder’s info via command palette or keymap.

0 Likes

#8

Is this ever going to be implemented?

It is the main reason holding me back from using Sublime Text, as It prevents me from using it 100% with my keyboard.

0 Likes

#9

If ST respected the context menu key in the sidebar (which it seemingly does not, only in views) you could have done that, but it doesn’t.

Essentially, what you are requesting (and what would be useful imo) is the ability to define key bindings in a sidebar context so that you get handed a list of selected folders or files. If this was implemented, then the context menu could probably be made available via keybinding there as well since it’s just an entry in the default keybindings mapping.

0 Likes

#10

First
Focusing the sidebar requires two clicks #300 github.com/SublimeTextIssues/Core/issues/300
So you have “preview_on_click” set to “false”, still requires two clicks! :confused:

Second
Click in a folder in sidebar expands the folder instead of selecting it. #302 github.com/SublimeTextIssues/Core/issues/302
Good luck selecting the folder

Third
As the file you are currently in has kind of “automatic selection” using shift/ctrl will append what you click to the selection, if you are lucky to notice this behaviour… github.com/SublimeTextIssues/Core/issues/517
Good luck selecting what you want.

Four
Sidebar selection of file and or folders is lost when focusing a tab/view #301 github.com/SublimeTextIssues/Core/issues/301
Made a mistake? reselect all over again

Five
SideBar “contextmenu” key binding ineffective #355 github.com/SublimeTextIssues/Core/issues/355
key binding does not work.

Six
There is no API to get what you request, because the selection simply does not exists, or does whatever it wants IT DOES NOT RESPECT USERS by introducing behaviour that one person evaluates or consider as “handy” for his only use case.

So, yes, the path of selected node in side bar is almost always the focused file. If not, that means you have preview_on_click set to false and you are experiencing all the above problems. preview_on_click saves only 1 click by introduce an incredible amount of problems. Same with automatic locate of focused file, save two clicks, and introduce an incredible amount of problems. ST is a great text editor, but the file tree “automatic behaviours” SUCKS. SUCKS.

0 Likes