Sublime Forum

Favorite Files

#11

Hey facelessuser,

Thanks for all you’re doing, not only on this plugin, but for the ST2 community at large. Very much appreciated!

Sorry to inform you, though, that the groups functionality doesn’t seem to be working. I created 4 four files and saved them to the filesystem (though I did leave them blank), and then tried to add them to a favorites group. They didn’t get added, but the favorites group name did get saved (somewhere) because it was available to me during later attempts at saving the files to a group. I also added a little content to each file and tried again, but with the same results.

And I did restart ST2 at some point after installing the plugin. It may have been after the first attempt at saving a group, though. I can’t remember.

I doubt that it will be very helpful, but I recorded a short screencast [1] illustrating the process. In the video, I mention that I didn’t see a settings file of any kind in the project directory (though I’m not sure why I expected one there), but I did see the favorite_files_list.json in Packages/User, but it was empty except for what appears to be default content:

{
    "files": {},
    "groups": {},
    "version": 1
}

When you save a group of files, are you making any attempt at storing the view indexes? It would be nice if the files were opened in the same order they were in when the favorite group was saved.

[1] http://www.youtube.com/watch?v=1NZMWm_uCfM)

0 Likes

#12

Whoops! I switched from using a dictionary to a list but forgot two lines of code that is still trying to access a dictionary. Update your branch and delete the old list file.

I allow you to save all views in a group or all views in a window. I would have a difficult time predicting your layout setup (I might just ignore layouts). And I would have to switch back yet again to using dictionaries. Let me make sure groups is working in general, then I will evaluate this request. Oh, also you can append to a group, so view index would mean less and less as you add more.

I currently sort the json, so I could probably stop that, that would at least leave the files in the order they were saved (group 0 -> last group and view 0 -> last view).

0 Likes

#13

Just confirmed now working :smile:


0 Likes

#14

I’ve wondered a few times if it would somehow be possible to TDD one of these plugins…

[quote=“facelessuser”]

I allow you to save all views in a group or all views in a window. I would have a difficult time predicting your layout setup (I might just ignore layouts). And I would have to switch back yet again to using dictionaries. Let me make sure groups is working in general, then I will evaluate this request. Oh, also you can append to a group, so view index would mean less and less as you add more.

I currently sort the json, so I could probably stop that, that would at least leave the files in the order they were saved (group 0 -> last group and view 0 -> last view).[/quote]

I certainly don’t want to seem too demanding. And I understand what you’re saying about the difficulty in knowing layout and adding files to the group. Let me use the current feature set for a while and see how it goes. If it seems like not having them restored in a particular order is causing me too much pain, I’ll have a go at implementing that myself. If you weren’t so blasted fast, I was going to have a go at this plugin myself anyway. :smile:

One thing you could do is store them in the order they are initially in, then append new files to the end. If you reopen them in that same order, that would suffice. Is it possible to overwrite an existing group definition? If so, I could just overwrite it when I rearrange my files. Seems like that might be a decent win-win: I (and people like me) get the ability to reopen files in something like the order they were in when last opened, and you don’t have to worry about recording specific groups/indexes from ST2.

[Later … ]

Okay, during the forum’s downtime, I experimented a bit with the new code. It appears that when I save a group of files to an existing group, any files that aren’t already in the group are appended to the list. If there was an option to completely overwrite the list so it would get redefined, I’d be content with not having a specific piece of “ensure order on reopen” functionality. Oh, and an option to suppress the “6 files already in the group” message.

Very nice work, facelessuser. I’m going to have to pull myself away from the other things I’m doing and study your code. I’m sure I’ll learn something.

0 Likes

#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