ZeroBraneStudio icon indicating copy to clipboard operation
ZeroBraneStudio copied to clipboard

Request: Save project related informations in a file located in the project

Open jjvbsag opened this issue 5 years ago • 6 comments

I would like to reopen #518 and go a bit more into details. Every other IDE I know, saves all information related to a specific project into a file located inside the project. Ok, in #518 we discussed setting the interpreter per project and it can be set in user.lua using the package projectsettings. This is fine.

But now I refer to informations like openfiles, startfile, arguments and similar. I'd really prefer to have these saved into a file (e.g. <project>/.zerobranestudio ) inside the project instead of ~/.ZeroBraneStudio in the home directory. This would also make it easier to implement #1015.

Rationale: If I rename a project directory and open the renamed project in ZBS, then all this information (especially startfile and arguments) is lost. The same is true, if a project is zipped and moved to another system.

On the other side, if a project directory is removed, ~/.ZeroBraneStudio may be filled with obsolete data. Saving projectrelated information in <project>/.zerobranestudio would also solve this.

jjvbsag avatar Sep 30 '19 06:09 jjvbsag

You can always have a shortcut that launches the IDE with a specific .ini file where all the configuration is saved (see the ini setting https://studio.zerobrane.com/doc-general-preferences#general).

I personally dislike saving all configuration in a project specific location, as things like tab configuration, window/frame size/position, and other similar things are transient and can be easily re-configured. All the significant settings can still be set in user.lua (or similarly named file). If you do want to save the settings locally, you can set the ini file as described above.

pkulchenko avatar Sep 30 '19 15:09 pkulchenko

I am trying to add some file association my Lua project with ZBStudio on Windows platform. Assume project file name like "ProjX.zbproj", clicking the zbproj file will execute zbstudio and load all related Lua files. Associating ".zbproj" file extension and loading Lua files is done via registering zbstudio.exe -cfg "%1" as shell command and the ProjX.zbproj file like following:

showmemoryusage = true

ide.filenames = {
    "ProjXIOLib.lua",
    "ProjXSubs.lua",
    "ProjXMain.lua",
}

But I can not figure out how to set "the project directory" (and the directory tree) and starting lua file and command argument. I have to set them manually each time I switch to other Lua project in other directory.

Setting "ide.config.path.projectdir="C:/Users/AAA/XDir" won't work. We need some way to set the project related info like directory, starting Lua file, and argument in configure file read by -cfg command line option. Getting directory path of the "zbproj" config file would be handy to set current project directory.

qqkookie avatar Nov 23 '19 15:11 qqkookie

As far as I remember, you can set the project dir by passing the directory path (including terminating path separator!) as start argument. I did this in thunar (file manager in linux) by adding a user action for lua zbstudio %F %d/ Where %F is a list of all selected files, and %d is the directory of the first selected file. In a dos batchfile you can get the directory of an argument with %~dp1, I don't know, if this also works with shell command.¹) It would then be zbstudio.exe -cfg "%1" "%~dp1\\" or something like this. IF it does not work in registry, then you'll have to make a wrapper batchfile.

Regarding the startfile: the method is ide:GetProjectTree():SetStartFile(path), but I'm not sure, if this is already available when the config file is loaded.

¹) I cannot verify, because I finally switched from win7 to xubuntu. I wont let the win10 spyware have any look at me.

jjvbsag avatar Nov 24 '19 07:11 jjvbsag

@qqkookie, @jjvbsag is correct in his suggestion: you can pass the directory name as one of the parameters to zbstudio launch command. You may want to set the directory first, as it will recognize file names relative to that directory.

Setting the file name may not be available, but it should be possible to add an onAppLoad event to trigger that: package{onAppLoad=function()ide:GetProjectTree():SetStartFile(path)end}. You can add this to the config file or pass as part of the cfg argument.

pkulchenko avatar Nov 24 '19 07:11 pkulchenko

OK, Thank you for your help. Now it works like this:

The Windows Registry: (Windows 10)

[HKEY_CLASSES_ROOT\Applications\zbstudio.exe\shell\open\command]
@="\"C:\\Program File\\ZeroBraneStudio\\zbstudio.exe\"  -cfg \"%1\" \"%CD%\""

[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.zbproj\UserChoice]
"ProgId"="Applications\\zbstudio.exe"
"Hash"="QQB1S++u8Ao="

Project config file: "ProjX.zbproj"

showmemoryusage = true

ide.filenames = {
    ide.arg[3] .."/",       -- "%CD%"
    "ProjXIOLib.lua",
    "ProjXSubs.lua",
    "ProjXMain.lua",
 }

local _startfile = "ProjXMain.lua"
local _params = "parm1 param2 param3 "
local _interpreter = "luadeb53"

package {
    onAppLoad=
        function() 
            ide:GetProjectTree():SetStartFile(_startfile)
            ide:SetCommandLineParameters(_params)
            ide:SetInterpreter(_interpreter)
        end
 }

Hard part was figuring out "luadeb53" as interpreter name.

qqkookie avatar Nov 24 '19 19:11 qqkookie

@qqkookie, looks good; thank you for the update.

pkulchenko avatar Nov 24 '19 19:11 pkulchenko