Hey guys,
I couldnât find anything regarding this in the APIs. Can someone tell me if itâs possible to:
a) Determine if a project is currently open
b) If so, retrieve its rootâs path
Cheers,
Burn
Hey guys,
I couldnât find anything regarding this in the APIs. Can someone tell me if itâs possible to:
a) Determine if a project is currently open
b) If so, retrieve its rootâs path
Cheers,
Burn
The API is rather limited in regards to project support.
To determine whether a project has been loaded, you may trap the onProjectLoad event. I donât think you can tell what project file has been loaded, though.
Too bad I really wanted to get all Tortoise (svn/git) options in a quickSelect panel, I guess Iâll have it only work per file for now, and stick to global shortcuts for the rest, there I can get the $ProjectDir. Hope weâll get more access to information in the APIs later on.
I recently created a TortoiseSVN plugin that is on the community wiki. I only use key bindings/menus for now, but I think converting it to use a quickpanel would be nice. I really just use $ProjectDir right in my bindings. Actually, the plugin is ONLY bindings, so thats why I donât have the issue you are experiencing. It would be nice to have access to all the same sublime vars from within plugin code thought too.
[quote=âburnâ]a) Determine if a project is currently open
b) If so, retrieve its rootâs path
[/quote]
âwindow.project()â will tell you if a project is open
âwindow.project().fileName()â will tell you its path
I donât think itâs documented, so itâs possible it changes in the future.
Anyways, you can get more hidden info like that by introspecting variables. Try âdir(window)â and âdir(window.project())â
Cool! I was too lazy to check. Also, looking into Packages/Default may help to learn other undocumented API calls.
Just re-asking here for this thread was more discussed than the previous one: does anyone know the project() was changed for Sublime 2? Iâm pretty sure it doesnât exist in the window instances anymoreâŚ
From what I can tell, the only project information available in the api is window.folders(), which gives you a list of the project folders.
Right. But if youâre working on a project which its containing folder is not in your sublime-project file, then you still canât know the path of your project.
The sublime.Window Class has a project_file_name() function, but is missing a corresponding set_project_file_name(). Is this a thing that can be added?
Why set_project_data(data)
is not enough? Or what do you actually would like to do?
When a new person joins the project and opens sublime, I want to load a specific .sublime-project file for them based on their discipline.
Ideally, I would like to open a sublime project from a python script, such that sublime.Window project_file_name() returns the file name of the project I opened.
My problem with set_project_data() is that since itâs not associated with a file, I can never be sure if the windowâs project data actually contains the data I want, or if the data is outdated.
Iâm not sure I fully understand your use case here, but you can add any arbitrary keys that you want to the project data (as you can in the sublime-project
file), so you could use that to add something to the anonymous project data to allow you to distinguish it in a manner similar to asking Sublime what file it was loaded from.