sublimehq / sublime_text

Issue tracker for Sublime Text
https://www.sublimetext.com
803 stars 39 forks source link

Fire event when view is renamed #771

Open kans opened 9 years ago

kans commented 9 years ago

It is currently possible to hook the rename_path window's command. However, only the original path is exposed. The other view hooks are insufficient to determine the new path. It would be great if the new path were exposed to the API.

FichteFoll commented 9 years ago

I have problems understanding the issue. Would you mind explaining with more details?

kans commented 9 years ago

@FichteFoll I want to know when a user renames a file. When a file is renamed, I want to know the new name. Currently, ST only tells plugins the original file path via hooking the rename_path event by way of the post window command. However, the command itself looks like it just opens a dialog (text input for the new path) and exits, so the window command hook never sees the new path (nor can it). Its possible to do crazy stuff with the views api (modified/activated) to guess at the new path, but these events are very inconsistent - perhaps because the text input is a special scratch buffer? At any rate, it shouldn't be a 300 line/2 day problem that only works 95% of the time. ST should just inform plugins about the new path. For that matter, the post command hook should only fire after the user enters a new path.

kans commented 9 years ago

A more general (better solution) would be to inform plugins whenever ST detects a change in the filesystem. I expect the change above is much easier to implement.

FichteFoll commented 9 years ago

Yes, sounds like a good idea. While #626 is ultimately the superior and more flexible approach, this request solves it in a different way that is preferrable in some situations and certainly easier to implement.

However, this could also be implemented by tracking a view's id and the associated View.file_name() manually and checking periodically. For saving under a different name, you could hook on_save or on_post_save, but that doesn't work for renaming obviously, which uses the View.retarget() API (I think). At least that's what SidebarEnhancement does.

I'm not sure how I would handle this, a new on_rename hook seems a bit over the top imo.

keith-hall commented 5 years ago

related: https://github.com/SublimeTextIssues/Core/issues/854