Home Download Buy Blog Forum Support

Favorite Files

Re: Favorite Files

Postby tito on Fri Mar 23, 2012 3:53 am

I was able to create a solution for project related things with SideBarEnhancements
for example
Code: Select all
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.
Give APIs, let the community build the rest!
https://github.com/titoBouzout
tito
 
Posts: 850
Joined: Thu Sep 29, 2011 2:27 pm
Location: Montevideo, Uruguay

Re: Favorite Files

Postby facelessuser on Fri Mar 23, 2012 4:08 am

tito wrote:I was able to create a solution for project related things with SideBarEnhancements
for example
Code: Select all
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.


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.
Code: Select all
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).

Code: Select all
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.
facelessuser
 
Posts: 1542
Joined: Tue Apr 05, 2011 7:38 pm

Re: Favorite Files

Postby tito on Fri Mar 23, 2012 4:20 am

https://github.com/titoBouzout/SideBarE ... Project.py
If you can use that file great, if not fuck the apis.
Give APIs, let the community build the rest!
https://github.com/titoBouzout
tito
 
Posts: 850
Joined: Thu Sep 29, 2011 2:27 pm
Location: Montevideo, Uruguay

Re: Favorite Files

Postby facelessuser on Fri Mar 23, 2012 5:33 am

tito wrote:https://github.com/titoBouzout/SideBarEnhancements/blob/master/sidebar/SideBarProject.py
If you can use that file great, if not fuck the apis.

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 :). 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.
facelessuser
 
Posts: 1542
Joined: Tue Apr 05, 2011 7:38 pm

Re: Favorite Files

Postby tito on Fri Mar 23, 2012 8:49 am

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.
Give APIs, let the community build the rest!
https://github.com/titoBouzout
tito
 
Posts: 850
Joined: Thu Sep 29, 2011 2:27 pm
Location: Montevideo, Uruguay

Re: Favorite Files

Postby facelessuser on Fri Mar 23, 2012 12:58 pm

tito wrote: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.


I always tell my wife that the more direct she tells me something, the better chance I will pick up on it :) ...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.
facelessuser
 
Posts: 1542
Joined: Tue Apr 05, 2011 7:38 pm

Re: Favorite Files

Postby facelessuser on Fri Mar 23, 2012 9:43 pm

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.
facelessuser
 
Posts: 1542
Joined: Tue Apr 05, 2011 7:38 pm

Re: Favorite Files

Postby facelessuser on Sun Mar 25, 2012 7:07 am

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.
facelessuser
 
Posts: 1542
Joined: Tue Apr 05, 2011 7:38 pm

Re: Favorite Files

Postby facelessuser on Sun Mar 25, 2012 3:34 pm

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.
facelessuser
 
Posts: 1542
Joined: Tue Apr 05, 2011 7:38 pm

Re: Favorite Files

Postby vitaLee on Sun Mar 25, 2012 5:41 pm

@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 :)
vitaLee
 
Posts: 150
Joined: Tue Dec 27, 2011 11:10 pm

PreviousNext

Return to Plugin Announcements

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 15 guests