Sublime Forum

Favorite Files

#5

Cool, I can do that.

Great!

Because I am using the quick panel, you should automatically get the fuzzy search stuff.

A tester would be great. I’ll let you know when I get all of the above items in.

0 Likes

#6

Some updates:

The biggest thing is I made FavoriteFiles more forgiving of people mucking around with the file list. It will now accept C style comments like other settings files, but it will also be forgiving of those pesky trailing commas. It now will also auto-reload only if the file list has been modified. There was also an issue where if you canceled the quick lists (open file or remove favorite) it would not actually cancel.

I will try to play around with groups tonight.

0 Likes

#7

More forgiving is good. Really good.

Um, I just thought of something I’d really, really like to be able to do, and since you are always saying, ‘Oh, that should be easy’ …

I’d like to save favorites by project. Yes, I know that the original intent was to save favorites that aren’t part of a project, but let me explain my thinking here. I work on one project that is sports-related and I would like to have favorite groups for seasons, leagues, teams, coaches, etc. I work on another project that has nothing to do with any of those things, and being the Type A personality that I am, I don’t want to see them when they are not applicable.

Doable?

On an ever-so-slightly-related note, I’d also like to have command line history that is directory-dependent. I’ve done some searching around and experimenting, but haven’t found anything that works. If you (or anyone else) come across something that works, puh-lease let me know.

0 Likes

#8

Be strict on output, but easy on input :wink:. Seems to be the best way to do things.

Doable…yes. The problem is how would I approach it. I will tell you how I would like to approach it if I did this (this would happen after I get the basics all finished). By default, a project would have no favorites or support for favorites, but if you enabled favorites for that project, I would store the favorites file in the root of the project. Then when you request a favorite, you would first be presented with a menu asking if you want to see Global or Project favorites, and the appropriate list would be displayed depending on your answer.

[quote=“phillip.koebbe”]
On an ever-so-slightly-related note, I’d also like to have command line history that is directory-dependent. I’ve done some searching around and experimenting, but haven’t found anything that works. If you (or anyone else) come across something that works, puh-lease let me know.[/quote]

I’ll let you know if I come across something that works, but I don’t know when/if I would get around to looking into something like that.

0 Likes

#9

Groups is going to require a re-factoring of the code…sigh. The current format for saving favorites is getting trashed.

I think I am going to remove requiring the user to give an alias for favorite files. If you want to add a bunch of files to a group in one shot, needing aliases is just not going to work. I will manage them internally. When you open your list in the quick panel. Each file will be listed like so. Or something like this. I am going to have to play around to see the best way to show these.

file_name full/path/to/file

Groups will probably be listed something like:

Group: name 7 files

A simple project slowly getting more complicated. Oh well, it is for the better :smile: .

I then plan on having two commands for opening files. (this might also get reduced to one command that then gives you the option to open the entire group when you select the group)
-Open File
-Open Group

I then plan on having two set commands. (this might also get reduced to one command that then gives you the option)
-Add File
-Add All Open Files

The open commad(s) will just open a menu and with three options (probably No Group first):
-Create Group
-Add to Group
-No Group

All required user interaction will be quick panel driven except for entering the group name. Hopefully this will all work out well.

0 Likes

#10

Groups is in.

Version 0.2.0

  • File list now reloads on modification only
  • File list is forgiving if modified by hand
  • Fix issues with canceling quick list
  • Added groups
  • favorite_files.json renamed to favorite_files_list.json (new format)

If you were using this already you can delete favorite_files.json from User. The new file is favorite_files_list.json. Had to change the format to support groups.

You can now add the current file, all files in a window group, or all files in a window. You can add the files to the global favorite list, an existing favorite group, or a new favorite group. You can open a file from a group or a file from the global list, or you can open all files in a favorite group.

And that is all I am doing tonight.

Please give it a test and let me know how it works. Let me know about bugs or suggestions.

0 Likes

#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