Sublime Forum

Favorite Files

#1

I saw a post earlier today asking about a way to access favorite files that are not found in projects, and I thought that it would be a fairly easy plugin to write.

So here it is: github.com/facelessuser/FavoriteFiles

You can add and remove files via the command palette. And you can access your files via a quicklist with a command.

It keeps a json file in your User folder with all of your favorite files.

I just put it together, so let me know if you find any bugs or if you have any suggestions.

0 Likes

Favorite Files
Easy way to open multiple files? Keyboard-based
Some suggestions from an Ultraedit user
#2

[quote=ā€œfacelessuserā€]I saw a post earlier today asking about a way to access favorite files that are not found in projects, and I thought that it would be a fairly easy plugin to write.

So here it is: github.com/facelessuser/FavoriteFiles

You can add and remove files via the command palette. And you can access your files via a quicklist with a command.

It keeps a json file in your User folder with all of your favorite files.

I just put it together, so let me know if you find any bugs or if you have any suggestions.[/quote]

I told you youā€™d find something else to do :laughing:

The funny thing is, I was just thinking about this myself, yesterday. Though, in my imaginary world, I would be able to name groups of related files. For example, one of the projects I work on is a PHP application that uses Smarty for templating. While this particular application doesnā€™t use any kind of framework, I have been trying to bend it to my will over the past few years, applying what Iā€™ve learned about structure from other projects (Rails and such). I tend to have a PHP file that is something like a controller, another one that is something like a model, a JavaScript file, a CSS file, and the related Smarty templates. I have these collections for each functional area of the application. I was thinking it would be nice to be able to gather these files together in some settings file under a common name and be able to open them all at once, almost like subprojects but not quite.

Iā€™ll take a look (when I have time) at what you started and see if it might get me part of the way there.

0 Likes

#3

I didnā€™t mean toā€¦it just sounded like a good idea :smiley:.

So you would treat the group as one entry, and when selected open all the files under the group? Would this be an optional thing? What I mean is that a group could be opened all at once or each file individually on demand or always opened as a group?

Doesnā€™t sound like it would be too difficult thing to add.
I would probably opt to have it work either way. Allow the creation of groups for organization (probably only one level deep, but if people really want I could make it many levels deep), but also have an ā€œOpen Favorite Groupā€ command that would only display groups.

I also plan to add a command that can search your favorite list and remove files no longer available.

I will probably also make the reloading of the favorites file more robust. It really doesnā€™t reload if someone modifies the favorites file by hand (it just does it after so long), but I probably should allow that because people will do it anyways.

Iā€™ll keep playing with it before I submit it to Package Control. Good idea though, I will try to get it in there sometime soon.

0 Likes

#4

Thatā€™s the thing about programmers: reduced to the lowest level, we are just problem solvers, and when we encounter a problem that we think needs to be solved, not much can stop us ā€¦ except someone else solving the problem first, in an acceptable way of course :wink:

Yes, I was thinking of something pretty straightforward, like all open files in the active group can be saved under some label. I wouldnā€™t want it too complicated, or I wouldnā€™t use it.

Yes, definitely allow it work for saving individual files or groups. I will use both, a lot.

Iā€™m not exactly sure what you mean by ā€œmany levelsā€, but, speaking solely for myself, I canā€™t currently think of how multiple levels of favorites would be helpful. I can see individual files and groups of files. Unless you mean something like ā€œall payment processing filesā€ and then further refined as ā€œall paypal filesā€. If thatā€™s what you mean, I can see someone potentially using that, but that person could just open the specific files and create another saved favorite group. No need to make the plugin more complicated than it needs to be.

Good ideas. A keystroke sensitive live search like the Go Tos would be nice.

Let me know if you want a beta tester.

0 Likes

#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