SublimeText / AdvancedNewFile

File creation plugin for Sublime Text
MIT License
829 stars 93 forks source link

How to show side_bar menu #57

Closed orschiro closed 10 years ago

orschiro commented 10 years ago

Hello,

I would like to have an option to rename the currently opened file when right clicking on the file in the side bar.

Therefore I set "show_sidebar_menu": true but still I only have the option close when I right click on a file in the sidebar.

This is how it looks like:

skuroda commented 10 years ago

Added in f5c45be0ac4fb271b23c6afcd171d67aa1a7a775. You do have to add the side bar menu manually. To do this, see here. Thanks for using AdvancedNewFile. Please let me know if you run into any issues.

orschiro commented 10 years ago

Thanks a lot for implementing this nice feature!

However, it does not work yet. I created the following file but I still only have a close option when right-clicking on a file in the sidebar.

~ $ cat .config/sublime-text-3/Packages/User/Side\ Bar.sublime-menu 
[
    { "caption": "ANF: Rename", "command": "advanced_new_file_rename_at", "args": {"files": []}}
]
skuroda commented 10 years ago

Did you install the plugin with package control? If so, you may need to force it to update. I believe the command to do it (in the command palette) is Package Control: Upgrade Package You may also want to try restarting the editor. I still haven't quite figured out when you need to restart and when you don't.

orschiro commented 10 years ago

I did both now, upgraded the packages and restarted subl3 but still now success. How can I check the installed version of AdvancedNewFile?

skuroda commented 10 years ago

Is there any additional entry in the Side Bar context menu (perhaps just grayed out)? You can check the version by searching for Package Control: List Packages. I don't use any actual versioning (I probably should), but there should be something like v<year>.<month>.<day>.<hour>.<minute>.<second>

orschiro commented 10 years ago

Unfortunately no additional sidebar entry. See the screenshots below.

image image

skuroda commented 10 years ago

Ah okay I see the point of confusion. I don't generally display the open files so I didn't even think to try that. Apparently ST treats those differently than the navigation folders. I'll see if I can get it to appear there also, though I'm not sure that's supported. Another option (that I know would work) is adding a context menu for within the buffer itself. I was being bad and was doing it off what I remembered rather than coming back to the issue. Teach me to do that again.

Like I said though, I'll investigate the menu there as well. Thanks for the clarification.

orschiro commented 10 years ago

Thanks!

The context menu for within the buffer itself sounds already like a nice solution. Can you implement this in addition?

skuroda commented 10 years ago

Will do. Well more accurately, already done :smile: The code to implement this is already there. You just need to create a menu entry, as with the side bar. Create Context.sublime-menu in your User folder with the following content. I'll be sure to update the documentation in my next commit.

[
    {"caption": "ANF: Rename", "command": "advanced_new_file", "args": {"rename": true}}
]

As a side note, I couldn't find a menu file to add to the open files context menu. I'll keep an eye out though.

orschiro commented 10 years ago

Nice one! I created Context.sublime-menu but where can I find the rename entry now?

I cannot find it in the head bar menu.

skuroda commented 10 years ago

Context.sublime-menu is the context menu for the actual view. So, to bring it up, simply click in the view (or buffer if you prefer that name) itself. When you say head bar are you referring to the tabs or something else?

orschiro commented 10 years ago

@skuroda

Thanks. Now I understand what you were referring to. I actually never tried out the context menu in the buffer. Nice implementation!

Speaking about the head bar, I was referring to File, Edit, etc.

But I like your solution much more!

Two minor things:

image

I extended Context.sublime-menu as follows:

[
    {"caption": "ANF: Rename", "command": "advanced_new_file", "args": {"rename": true}},
    {"caption": "ANF: Delete", "command": "advanced_new_file", "args": {"delete": true}}
]

However, the delete command seems not to exist?

skuroda commented 10 years ago

If you want to create head bar menus, take a look at what I did in Main.sublime-menu. It's effectively a JSON object, where each level defines a new sub menu.

The start location is based off of the ANF settings. By default, it will be the top level folder in your project. As that is convenient for some people, you can do one of two things to get it to start from the projects current directory. The first is to simply enter a :. The second is to set relative_from_current in the ANF settings to true, then you can enter a ..

I haven't implemented a delete function, and do not plan to (in the scope of the plugin). That being said, it's pretty simple. Simple enough that I wrote a quick version for you. :smile:

import sublime
import sublime_plugin
import os

class MyDeleteViewCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        file_name = self.view.file_name()
        if file_name != None:
            self.view.window().run_command("delete_file", {"files": [file_name]})

    def is_visible(self):
        file_name = self.view.file_name()
        return file_name != None and os.path.exists(file_name)

Save the above in Packages/User as <something>.py. Only thing that matters is the extension. Then in the context menu, use my_delete_view as the command.

skuroda commented 10 years ago

Updated the documentation with renaming via context menus. Let me know if you run into any other issues. Thanks for using AdvancedNewFile.

orschiro commented 10 years ago

Your help and work on this excellent plugin is truly appreciated! Sorry for the troubles I am causing but I have a last question regarding the delete function. I added the my_delete_view to the context menu file but what is the args to use?

/home/orschiro/Dotfiles/subl3/.config/sublime-text-3/Packages/User/Context.sublime-menu

[
    {"caption": "Rename file", "command": "advanced_new_file", "args": {"rename": true}},
    {"caption": "Delete file", "command": "my_delete_view", "args": {"delete": true}}
]

Furthermore I created the folllowing delete-file.py:

/home/orschiro/Dotfiles/subl3/.config/sublime-text-3/Packages/User/delete-file.py

import sublime
import sublime_plugin
import os

class MyDeleteViewCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        file_name = self.view.file_name()
        if file_name != None:
            self.view.window().run_command("delete_file", {"files": [file_name]})

    def is_visible(self):
        file_name = self.view.file_name()
        return file_name != None and os.path.exists(file_name)
skuroda commented 10 years ago

No arguments are necessary for the delete function. It can be thought of as a completely separate plugin. Simply put, it looks at the file name of the view. If it's None (doesn't have a name), it deletes it. However, if it does have one, it runs the build in delete_file command.

orschiro commented 10 years ago

Yes! It is working now. Thanks so much.

[
    {"caption": "Rename file", "command": "advanced_new_file", "args": {"rename": true}},
    {"caption": "Delete file", "command": "my_delete_view"}
]
skuroda commented 10 years ago

@orschiro Just a heads up, it someone made a pull request to add the delete functionality in. A quick look over it looks like it integrates some git management. Don't know if that would be of interest to you, but thought I would let you know.

orschiro commented 10 years ago

@skuroda

Thanks for letting me know. And also that the delete functionality will be merged into master. Great!

I am also working with Git, though not very sophisticated, but I am fully appreciating the ideas of the pull request. :+1:

When do you estimate it will enter master? And do I have to remove my custom delete function then to avoid conflicts?

skuroda commented 10 years ago

Hopefully I'll get to it over the weekend. Nope you won't have to. So long as the command names don't conflict, you won't see any issues. If you want to use my command over yours, you will just need to update the command in the menus appropriately.