Sublime Forum

Favorite Files

#15

No biggie, I’ve just been overhauling a lot of stuff. Originally it was going to be super simple, but the suggestions you have made are great, but they required re-architecting the code. I may add these in once I get the basics ironed out; I still have per project support, and that seems like a bigger pain. From what I can tell, I would have to search the session to find the project file for the window I am in, and then parse the project file to find its root…then I can finally add per project favorites. I am going to play with it though. I kind of wish this was exposed in the API…who knows maybe it is and I just don’t know it yet.

That is what I meant by not sorting the JSON file. Currently when I store the paths, they are ordered because they are in a list, but then I sort the JSON and muck up the order. If I stop sorting it, they should remain in the order I add them, and I add them in the order ST2 gives them to me. I believe it gets them in tab order. And then new files get appended. I will look into an option for complete overwrite. I and I will look into a silent option for info dialogs and only show more critical dialogs.

Very kind words. Thanks! :smiley:

0 Likes

#16

New version

Version 0.3.0

  • Ensure favorites are opened in order they were saved
  • Add option to replace group
  • Remove dialogs alerting user that files already existed in favorites

This should give it a more reasonable feel.

Projects is next, but not tonight. I think I am going to require the user to add something to their per project settings to enable per project favorites; makes it much nice and easy to implement.

0 Likes

#17

[quote=“facelessuser”]New version

Version 0.3.0

  • Ensure favorites are opened in order they were saved
  • Add option to replace group
  • Remove dialogs alerting user that files already existed in favorites

This should give it a more reasonable feel.

Projects is next, but not tonight. I think I am going to require the user to add something to their per project settings to enable per project favorites; makes it much nice and easy to implement.[/quote]

Haven’t exercised it a great deal yet, but what I’ve seen so far works as I’d expect it to. Looking forward to the project-specific stuff. Keep it coming!

0 Likes

#18

Version 0.3.1
-Open files in active group

Seems like this wasn’t working on the last version, should work now.

Still rolling project specific ideas around. Would be a lot easier if certain settings were available from a window object. So far the ideas I have been rolling around seem to involve hunting through the session to find the windows project…ugh (seems like unneeded work and overhead). Or leaving some kind of variable in the projects’s settings section, but that is only accessible through a view, so if a view isn’t open…

It would be nice if the window object just had a project method like window.project() and it would just give you the path to the project file or None if it did not exist.

Oh well, I will keep giving it some thought.

0 Likes

#19

This probably isn’t a much better solution, but it is a possibility:

You could use sublime.active_window().folders() and look for *.sublime-project. In many cases, there will be only one folder as folders() appears to return only the root. I’m sure there are many people who will have additional folders added to the project, but I can’t imagine there would be so many that it would be noticeable looking for a single file. If you happen to find more than one project file (which would surprise me), you could pop up something and ask the user which one is correct. Gets a little clunky in that case, but again, I seriously doubt you will encounter too many cases where there are multiple project files. Seems like ST2 would have a problem with that anyway.

0 Likes

#20

[quote=“phillip.koebbe”]This probably isn’t a much better solution, but it is a possibility:

You could use sublime.active_window().folders() and look for *.sublime-project. In many cases, there will be only one folder as folders() appears to return only the root. I’m sure there are many people who will have additional folders added to the project, but I can’t imagine there would be so many that it would be noticeable looking for a single file. If you happen to find more than one project file (which would surprise me), you could pop up something and ask the user which one is correct. Gets a little clunky in that case, but again, I seriously doubt you will encounter too many cases where there are multiple project files. Seems like ST2 would have a problem with that anyway.[/quote]

I will consider it. There are a number of things I am trying to figure out. Do I present both global favorites and project favorites, or do I require the user to switch between them (like a toggle setting). I prefer to not have to ask each time for project favorites or global because that would probably get old. I also need an elegant way to switch between windows and switch project preferences or switch to global if there aren’t any. I will figure something out. After I get projects working I think I will submit it to Package Control.

The good news is, the generally functionality feels pretty good now. I just want to get the project part in without making it feel clunky.

0 Likes

#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