简体   繁体   中英

How to navigate to parent folder of current file in Project Explorer view using keyboard shortcut in Eclipse IDE?

INFO: Problem occured on Ubuntu.

In Eclipse IDE, having a current file opened in editor, and having Project Explorer view linked to editor.

I would like to navigate back from parent to parent folder in Explorer view, using keyboard only . (where each folder may have hundreds of files)

Alternately, I would like to toggle (close) parent folder of selected file in Explorer view.

To demonstrate with a screenshot, here is the start state: 在此处输入图像描述

and where I want to go, parent folder selected / or closed. 在此处输入图像描述

Mouse workaround

As a workaround, my current workflow is use mouse to scroll up explorer until parent folder, then I close it using - button to its left.

Because of linked with editor mode, Explorer view is scrolled down to current file, which makes parent folder not visible in explorer.

Having to do this makes the mouse way not very effective.

Another keyboard workaround

Navigate approximatively to parent using key PAGE-UP to scroll up, but depending on files count, it is also not effective.

Is there an existing keyboard, or a way to do it?

Note: using Oxygen.3a Release (4.7.3a) on Ubuntu 18.04.1 LTS

Finally, I found the answer! I combined answers from this post , restarted GNOME shell, restarted eclipse and it worked:

Edit ~/.config/gtk-3.0/gtk.css (create if doesn't exist):

@binding-set MyTreeViewBinding
{
    bind "<shift>Left"        { "select-cursor-parent" () };
    bind "Left"     { "expand-collapse-cursor-row" (0,0,0) };
    bind "Right"    { "expand-collapse-cursor-row" (0,1,0) };
}

treeview
{
   -gtk-key-bindings: MyTreeViewBinding;
}

To restart the GNOME shell: hit ALT + F2 .

Applying this solution will add the following functionality:

  • SHIFT + : Go to parent.
  • : collapse current item.
  • : expand current item.

I came up with the steps of restarting GNOME shell and eclipse. Not sure if just changing the configurations would do the trick right away or not. Haven't tried it :D

I'm using GNU/Linux Ubuntu 18.04.4 LTS.

joker's answer worked for me, Thanks joker! I've tested this in Arch Linux and Eclipse 2022-03.After making changes in gtk.css file, restarting the eclipse applied the changes.

Instead of using Shift + Left to go parent node. I've modified it like this. This way the cursor goes to parent node and collapses the node.

@binding-set MyTreeViewBinding
{
    bind "Left"     {
        "select-cursor-parent" ()
        "expand-collapse-cursor-row" (0,0,0)
    };
    bind "Right"    { "expand-collapse-cursor-row" (0,1,0) };
}

treeview
{
   -gtk-key-bindings: MyTreeViewBinding;
}

There is a key binding named "show in (project explorer)".(*) Define a key for this in Preferences->General->Keys menu. This will select the file you working on in the project explorer. (alternatively you can manually select by mouse)

After this You can use left arrow key ( ) to go to parent of the currently selected file. Pressing this key again will close the currently selected folder. (and pressing again will go up a level in the project explorer tree)

Ps: Right arrow key ( ) can be used to open the currently selected folder.

(*) If you want to do this in package explorer tree, define a key for "show in (package explorer)". (Rest is the same)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM