Sublime Forum

Favorite Files

#21

I was able to create a solution for project related things with SideBarEnhancements
for example

from sidebar.SideBarProject import SideBarProject 
SideBarProject().getPreference('folders')

That will return “folders” value of the project file.

it would be nice if you can use that api if available and fit your needs. I’ll appreciate contributions to that file.
You may can include a copy of that file in your package and load it only if SideBarProject is not already defined.

0 Likes

#22

[quote=“tito”]I was able to create a solution for project related things with SideBarEnhancements
for example

from sidebar.SideBarProject import SideBarProject 
SideBarProject().getPreference('folders')

That will return “folders” value of the project file.

it would be nice if you can use that api if available and fit your needs. I’ll appreciate contributions to that file.
You may can include a copy of that file in your package and load it only if SideBarProject is not already defined.[/quote]

Pretty cool. Are you searching the session as well or are you doing it differently? I did throw together a simple solution. It isn’t a lot of code, I just didn’t want to have to parse the session.

def get_project(win_id): project = None try: with open(join(sublime.packages_path(), "..", "Settings", "Session.sublime_session")) as f: j = json.load(f) for w in j'windows']: if w'window_id'] == win_id: if "workspace_name" in w: project = w"workspace_name"] break except: pass return project

Now with this I track the windows IDs that have been toggled to use per project favorites and I pair them in a dictionary with their project file path. Then you can also prune the them when the windows get closed (assuming my logic isn’t off).

def prune_projects(projects): dead = set(projects.keys()) - set([x.id() for x in sublime.windows()]) for key in dead: del projects[key]

I am considering just using the settings section in the project to store per project favorites. That way I don’t have to guess what folder to put them in. And that is what the settings section in the project file is for…per project settings. Still playing around though.

0 Likes

#23

github.com/titoBouzout/SideBarE … Project.py
If you can use that file great, if not fuck the apis.

0 Likes

#24

[quote=“tito”]https://github.com/titoBouzout/SideBarEnhancements/blob/master/sidebar/SideBarProject.py
If you can use that file great, if not fuck the apis.[/quote]

I see what you are doing. Looks like I am not the only one digging around in the session. I am with you on the APIs. If they can’t do what you need, you have to be creative.

Well I got per projects working, but the code is rough. I need to clean it up before I try and push this to the branch.
It detects when you are in a different project, you can toggle between global and projects, but the code is fugly.

No more tonight though. Your going to have to wait till I clean up this mess :smile:. And I need to test this real good too. By default per projects will be disabled, but if you want them, you can turn it on in the settings file.

0 Likes

#25

A more direct message:
I was trying to say that if you are going to digg around the project files, use the code I’ve wrote.
Because you can benefit from what’s already done, and users can benefit from the changes or improvement you may add. But ignore me.

0 Likes

#26

[quote=“tito”]A more direct message:
I was trying to say that if you are going to dig around the project files, use the code I’ve wrote.
Because you can benefit from what’s already done, and users can benefit from the changes or improvement you may add. But ignore me.[/quote]

I always tell my wife that the more direct she tells me something, the better chance I will pick up on it :smile: …yeah, I see what you are saying now. It was getting late and I was already bulldozing in one direction; I had more code written than I probably let on, and I didn’t pick up on what you were saying.

But on that note, I have often considered it would probably nice if there was a plugin of API enhancements. Something more general to aide in geting around common pitfalls. Tapping into SideBarEnhancement is good, but it requires people to also install SideBarEnhancement, and while I like and use SideBarEnhancement, not everyone might; they may pick up features they aren’t keen on. Something more general that simply provides scripts to tap in to or do commonly wanted and used things would be cool. The downside is that your plugin becomes dependent on other maintainers not breaking functionality and to upkeep it for your plugin to work. It has both pluses and minuses. By having a plugin self contained, you have better quality assurance, but not as many people may benefit from the things you have figured out, or you may get stuck on something someone else has figured out.

0 Likes

#27

I got everything all working, but sadly I cannot release it just yet. While it is true I can detect projects and store the current favorite settings within, it isn’t without its limitations.

So “Session.sublime_session” only gets updated on close, so I cannot grab the most recent sessions there. But wait, there is “Auto Save Session.sublime_session”, this gets updated every time a file gets saved, so you get fairly recent window info and project info…but it still isn’t enough. Lets say you create a new window, and then you save a project for it…neither sublime_session gets updated. sigh…

So while everything is in place, it will have hiccups that just aren’t acceptable. Anything placed in a view setting won’t help either, because then it requires an actual file to be open. So my last option is to possibly search the projects root folder(s) for an existing favorite list and give options for which file to use if it finds more, same goes for enabling it for a project; not really ideal. There is a slim possibility I can make an API request to get access to the project file path. I will take that route first and see if I get a bite, but I might not.

If I do this, I just want to do it well.

0 Likes

#28

Version 0.4.0

  • Added code to support per project favorites (disabled by default due to circumstances where project cannot be determined)

I added the code for per project but it is disabled by default. Because I cannot yet 100% always tell when I am in an actual saved project, there are times when you cannot switch to per project favorites because it cannot find the project file. I am hoping we will be able to sometime soon get the project file path in a reliable fashion. I want to be able to use the project file for the settings so I don’t have to search around in projects etc., and it makes sense to put the info there. I don’t want to clutter up a project with adding new files.

If you feel like playing with it, you can by enabling it in the settings file, but like I said, there are some situations, where it just can’t find the project file.

0 Likes

#29

Not quite out of tricks just yet. I figured out a way to get the project path pretty reliable now. Is it ugly and hackish? Yes and yes. But does it work? Yes.

So I should sometime today have a version of per project favorites that I am okay with turning on. I have a couple of things to shake out, but I think it will work pretty good. Am I still hoping for an API method to give project path? Oh yes; I feel dirty doing what I am doing currently, but I am limited right now on my choices.

Stay tuned.

0 Likes

#30

@facelessuser i haven’t tried this plugin yet but ‘project specific favorites’ feature reminded me i thought some weeks ago that similar feature would be useful in RegReplace. in a way to avoid polluting menu with replace commands specific to some projects.
i know it’s not the right place to mention this idea but anyway im dropping it :smile:

0 Likes

#31

[quote=“vitaLee”]@facelessuser i haven’t tried this plugin yet but ‘project specific favorites’ feature reminded me i thought some weeks ago that similar feature would be useful in RegReplace. in a way to avoid polluting menu with replace commands specific to some projects.
i know it’s not the right place to mention this idea but anyway im dropping it :smile:[/quote]

Maybe in the future. I would have to think about how to do it. You can not have project specific commands. But if you had maybe one command that could read a list of some command, you could do it, but that would take some refactoring.

In all honesty I probably should have had Favorite Files under the development section. I released a real simple version, and I thought I was done, but @phillip.koebbe had different ideas :smile: .

Even now I am still going back and forth on whether to store the settings in the project file, or create a separate file in the same folder as the project file. I just started thinking that people may be version controlling their project file and might not want their favorites stored in it. Had I known I was going to add all of these I would have held off on a release thread.

I will consider RegReplace in the future for project stuff, but I don’t imagine jumping straight into it.

0 Likes

#32

Okay, this is it.

I decided to store settings in the same directory as the project settings, but not in the project settings file. This is because people might be version controlling their project file, and I don’t want to put stuff in it they don’t like.

I added some code to perform a session refresh so I can find project files. So, if I can’t find a project file, I will refresh the session and try 1 more time. If the window does have a project file, I can then find it. You might see a tab pop up and disappear when performing the refresh. This is only needed on newly opened projects when no file has been saved since opening the project.

Basically, I am opening a dummy file, performing a save, and then I close it to refresh the session. If there are no views open, I will not close the dummy file so your window will not automatically close. It will look like this:

[code] ______ _ __ _______ __
/ / __ ______ _____() /____ / () / _____
/ /
/ __ `/ | / / __ / / / _/ _ \ / / / / / _ / /
/ __/ / /
/ /| |/ / /
/ / / / / /
/ __/ / __/ / / / ( )
/
/ _
,
/ |/_// //_/_/ // ///___/____/

Attemping to refresh session…

This view is used to refresh your session in order to find the project file if it exists.
To prevent the window from closing, this view will remain open if only one view remains.[/code]

That is it. By doing this ridiculous little task, I am able to update the Auto Save Session.sublime_session file, and then can find where the project file is and store the favorites file with it.

Per project favorites must be toggled on in a project, so by default, you are using the global list. When you want to see project specific favs, you use the “Favorite Files: Toggle Per Project” command. This now will load per project files instead of global. You can toggle back and forth.

If/when Jon adds some method to get the project file path, this will no longer be needed, but until then this is what I plan on doing.

Try it out and let me know if you like it. Let me know if you have any suggestions. Right now, this is what I am planning to submit to Package Control (assuming there are no bugs).

Version 0.5.0

  • Abandon storing favs in project settings file, but store the settings in a file in the same directory as project settings.
  • Force refresh of session if project cannot be found and try to locate project again.
0 Likes

#33

Most people have never made the association, but I’m also known as thorn.nyersyd :smile:

This is great news! I’ll be trying out the project-specific stuff tomorrow. Thanks again for all the work. Though, I do wonder if you have a real job or if you exist just to write ST2 plugins :wink:

0 Likes

#34

It makes so much more sense now. :smile:

0 Likes

#35

Known bugs:

  1. Windows returns “.” instead of “” for no project, this makes Favorite Files think it has a project. I will fix this later today.
  2. Renamed projects will try and store settings in the old settings. I will probably tweak toggling to verify if the project favorite file exists, and if not create it, and then catch missing project fav files for all other actions and maybe try and get the new project name.

**Edit: ** Update bug explanation.

0 Likes

#36

[quote=“facelessuser”]Known bugs:

  1. Windows returns “.” instead of “” for no project, this makes Favorite Files think it has a project. I will fix this later today.
    [/quote]

This issue is now fixed.

Version 0.5.1

  • More explicit match for finding project files
0 Likes

#37

This should really do it this time. Man this per project stuff has been a headache. I sure hope we get some method to get the project file path in the future.

Version 0.5.2

  • Rework logic to catch renamed projects
  • Strip tabs from session which can break the parsing
0 Likes

#38

Version 0.5.3

  • Catch project rename when when opening or removing items from list (will only catch after a file has been saved).

I plan on submitting this to package control by the end of the week. @phillip.koebbe, if you have any outstanding issues, please let me know; actually, give me whatever feedback you can so I know if this solution is acceptable. I think this covers all scenarios now, but I want to know how useable the solution is from other people before I decide to leave per project on by default.

I am now catching project renames when opening favorite files or removing them. This catch is only triggered after a file has been saved, I have purposely opted not to refresh during file open commands etc, because I think it would be too annoying. I only refresh when toggling between global to per project. If you rename a project and have saved a file, Favorite Files will alert you that it thinks the project name has changed, and it will revert to the global list. Toggling back to per project will create a list for the new project name.

0 Likes

#39

Feedback has disappeared for this, so I have decided to disable the “Per Project Favorites” setting until I get some good feedback on this feature. It is still there, but you have to enable it via the settings file if you want to try it out.

Version 0.6.0

  • Disable “Per Project Favorites” by default
  • Update documentation
  • Prep for official release

I will be requesting inclusion into Package Control soon.

0 Likes

#40

[quote=“facelessuser”]Feedback has disappeared for this, so I have decided to disable the “Per Project Favorites” setting until I get some good feedback on this feature. It is still there, but you have to enable it via the settings file if you want to try it out.

Version 0.6.0

  • Disable “Per Project Favorites” by default
  • Update documentation
  • Prep for official release

I will be requesting inclusion into Package Control soon.[/quote]

Sorry, been kind of busy the past few days. I’ve been using it, and it seems to work fine. I’m not using it as extensively as I will at other times due to the nature of my work. When I add new pieces of functionality, as I’m currently doing, I don’t need it quite as much.

Again, I appreciate your work on this. If I run into anything, I’ll certainly let you know. I guess you could almost go by the adage, “No news is good news.”

0 Likes