alanbernstein/treemonger

Feature Request: Right click on any square and provide basic options

Opened this issue · 6 comments

I saw your reception on the Qdirstat Github, sorry, and think its really great you decided to make this anyways.
No other program does what yours does, and it is fantastic, so thank you. Treemonger should get much more recognition.

I would really appreciate it if you would consider adding the ability to right click on each square and allow the user to perform the following actions via context menu:

  1. Open Externally (in file browser)
  2. Copy Path
  3. Delete/ Move to .trash

Just these alone would be immensely useful.

I can see from the output that you are already part of the way there with identifying the file/folder left clicked as well as key up key down events.

Thanks so much!

If you wanted to get fancy, you could add the zoom in and out feature as well.

Thanks, I'm glad you like it.

Obviously this little tool is a long way from being a full-featured GUI. I have plenty of ideas to move in that direction, which I never quite find the time for (because it's "good enough" for me in its current state, even though it bugs me when I need to quit, delete stuff, and re-run). Your suggestion to add more functionality through additional mouse events is great, because it's a low-effort way to get started on some of those new features. I should have thought of it a long time ago.

It looks like a context menu should be easy enough, but just to start seeing how these actions work on different platforms, I made a quick update to add:

  • middle click to copy path
  • right click to open file

Adding delete and zoom actions would be great, those are some of the features I've never quite found the time for... revisiting the code, I recall that it's already set up to re-render on resize, so maybe it won't be that much work after all.

If you have any suggestions for a zoom in/out interface, please feel free to share. I may try it out with scroll up/down or just with some keyboard events.

At the moment I can only easily test this on Linux, but of course I'd like it to work equally well on at least Mac and Windows too. What platforms do you use this on?

I'm glad this suggestion was useful to you!
Your additions make sense.
Regarding zoom, for now since you already have the click mouse events set up to identify the path on click you could just have the user hold ctrl and click to zoom in causing a refresh with the new "root" directory being the parent path of clicked file or the clicked directory itself. And then you could use any event you want, without needed coordinates, to go up a directory (like ctrl right click anywhere). What I would additionally suggest is make one keydown, for instance 'r' or even 'ctrl-r', trigger an automatic refresh of current path with or without progress bar. That way any user who right clicked to open path and ended up deleting something can trigger Treemonger to display the change without restarting the application. You could also make one key down, for instance 'u' or 'ctrl-u', to allow the user to return to the originally scanned directory.

To summarize:

  1. ctrl-click to zoom in, ctrl-right click anywhere to go up
  2. 'r' to refresh current view
  3. 'u' to return to originally scanned path

To me this would be the lowest barrier way to getting these functions in and useable.
Hope this helps!

I am using this in linux too.

Actually, for some reason due to the introduction of ipdb, I cannot run Treemonger anymore

After 'sudo apt install python3-ipdb' or 'pipx install ipdb' I get:

`$ python3 ./treemonger.py
FileNotFoundError(2, 'No such file or directory')

/home/user0/treemonger/treemonger.py(144)parse_config()
143 def parse_config():
--> 144 with open(config_file_path) as f:
145 config = json.load(f)

ipdb>
`

In a venv with pip install datetime ipdb python-magic pyperclip I get the same issue as above.

Any ideas on how to get this to run?

I'm not sure if ipdb is your problem, but committing that was unintentional, I've removed it. The config error should be resolved now.

I've also added a few small UI features, including zooming (might need some behavior tweaks). Check out the updated readme for the current state of things.

As for the delete/refresh behavior, unfortunately it will require some refactor work first. I will take a crack at that next.

Context menu and modifier keys seem doable, but I haven't looked into that yet since it turns out keystrokes and mouse buttons cover a lot for me.

I've added basic support for deleting files; it currently does a full rescan before rerendering, rather than updating the internal representation of the tree. So, probably slow for large trees.

Please note that there is a possible failure mode where the internal render of the treemap has been updated, but the UI canvas has not, so the click/key event coordinates do not correspond to the expected file. This means you might accidentally delete the wrong file. If you'd like to try this out, I suggest testing with the make-test-tree.sh script first, and using e.g. the i key to print file info before deleting anything.

TBH, right now I would not suggest using the delete action if you are working in a directory with any data you can't afford to lose. I would like to improve on this and test it a bit more, before I'd be comfortable using it or recommending it for that kind of usage.

I've added basic support for modifier keys, and a context menu, with behavior that can be customized in config.json. Let me know how well it works for you.

Wow, great progress, seems like you have done quite a bit in a short amount of time! Thanks for breathing even more life into this.

I have tried to go through and test what I can. Please see below.

Works as expected:-----------------------------------------------------------------------------------------------------------
mouse<1>: info (left click in ubuntu)
mouse<2>: copy_path (middle click in ubuntu)
"c": copy_path
"i": info
"q": quit

Did not test:-----------------------------------------------------------------------------------------------------------
"d": delete_tree ()
"m": cycle_mode (not yet implemented)-----

Does not work as expected:-----------------------------------------------------------------------------------------------------------
mouse<3>: context_menu (right click in ubuntu)----
Seems to mostly work as expected, however it seems that once the context menu is open, the use must click an option for it to close. Clicking outside the context menu, will not cause it to close, but WILL still register whetever was clicked in the tree. Ideal behaviour is that once context menu is open, clicking outside the menu on the tree will cause the menu to close and not register a click on whatever part of the tree was clicked at the time.

ctrl+mouse<1>: info------
This seems to work, but maybe that is just because Mouse 1 is also info. I receive this output after releasing RCtrl

['ctrl'] Control_R
('ctrl', 'control_r')
keyup: "Control_R" (('ctrl', 'control_r'))
event "('ctrl', 'control_r')": no action defined

"o": open_location------
This works as expected for files, but if a sub directory has been clicked and then one presses 'o' or right clicks on it and does 'open location' it will open the parent of the sub directory, instead of the selected sub directory itself.

mouse<5>: zoom_in (wheel down in ubuntu)-----
After clicking on a sub directory, and including without clicking at all first, zooming in with Mouse 5 does not cause any rendering changes. Though it does output a rendering message. One scroll also produces several Mouse 5 inputs registered. (With touchpad)

mouse<4>: zoom_out (wheel up in ubuntu)-----
Zooming out with Mouse 4 at any time seems to cause the program to become unresponsive to all other interaction for minutes before program becomes responsive again. No rendering changes. One scroll produces several mouse 4 inputs registered. (With touchpad)

"Down": zoom_in (down arrow)-----
Produced rendering message, but no visible changes or zoom in.

"Up": zoom_out (up arrow)-----
Performs like Mouse 4, but program unlocks faster, presumably because, it doesn't accidentally get multiple Up keydowns, unlike the Mouse 4 Scroll which produces multiple events.

"r": refresh-----
Receive 'no action defined'

"ctrl+r": refresh
"t": zoom_top -----
Seem to work because it triggers a refresh, but as I cannot zoom in, I cannot fully test

Notes:-----------------------------------------------------------------------------------------------------------
I would suggest changing the default zoom in and zoom out keys to "+" and "-".
Another thing that might help is to make the terminal output visible as part of the main window. Like a small 1-3 line area at bottom that will show what is happening.

Hope this is helpful and thanks again!