Adding a file to workspace automatically

Get help with the installation and running of the Zeus IDE. Please do not post bug reports or feature requests here. When in doubt post your question here.
Post Reply
rbc
Posts: 15
Joined: Thu Feb 17, 2022 3:22 pm

Adding a file to workspace automatically

Post by rbc »

Upon creation of a new file, is there a way that it can get added to the workspace automatically? I saw the Help file for the function "FileAddToWorkspace" but was unable to find an example for it. I saw the option to add the current file to active project but it doesn't show up in the workspace navigator. Any hints would be helpful.
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Re: Adding a file to workspace automatically

Post by jussij »

If you are running the latest version of Zeus you can create a new workspace (using the Workspace, New menu) that is dynamic as shown below:
new_workspace.png
new_workspace.png (134.73 KiB) Viewed 15650 times
When that dynamic option is used any file or folder created or deleted from the workspace directory or any sub-directory will be automatically reflected in the workspace structure.
Zeus also has the following project/workspace related scripting functions:

Code: Select all

string project_active()
void project_file_add(project, file, [folder])
void project_folder_add(project, folder)
Here is an example of a Lua macro that uses those functions to add the current file to the workspace:

Code: Select all

local utils = require "utils"

function key_macro()
    -- macro only works for documents
    local document = is_document()

    if (document == 0) then
        message("This macro only works for document files.");
        beep();
        return;
    end

    if (is_workspace_open() == 0) then
        message("No workspace is currently open.");
        beep();
        return;
    end

    local project = project_active();

    if (string.len(project) > 0) then
        -- full name of currently active file
        local file_name = macro_tag("$fn")

        if (string.len(file_name) > 0) then
            -- add the file to the project root folder
            project_file_add(project, file_name)

            -- add the file to the project 'My Code' folder
            project_file_add(project, file_name, "My Code")
        else
            message("No currently active file.");
            beep();
        end
    else
        message("Now workspace is currently open.");
        beep();
    end
end

key_macro() -- run the macro
You can bind that macro to a keyboard key or you could also bind it to a trigger event.

For example if you ad it to the save as trigger in the default document type all new files will get added to the workspace once they are saved.

The problem with using a trigger is it will file for all cases which means it could fire for cases when it should not fire, so you will need to make the macro smarter to cover those false alarms.

To get a feel for these triggers refer to the event_* macro examples in the zScript folder.

Cheers Jussi
rbc
Posts: 15
Joined: Thu Feb 17, 2022 3:22 pm

Re: Adding a file to workspace automatically

Post by rbc »

Thank you for your prompt reply. : )
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Re: Adding a file to workspace automatically

Post by jussij »

I just noticed the second part of your question:
I saw the option to add the current file to active project but it doesn't show up in the workspace navigator.
Are you referring to the option shown in the image below :?:
add_file.png
add_file.png (179.03 KiB) Viewed 15581 times
I ran a test using that option and for me it worked as expected, adding the current file to the active project with the result file showing up in the navigator tree.

The only thing you do need to be careful off is if you use this option to add files to a workspace that has been defined as dynamic.

That will not work as expected only because the next time the project is refreshed (which is done automatically) the project tree will lose all those manual additions.

For a dynamic workspace the file needs to added to the disk itself and then it will get added automatically to the navigator structure.

You can also change a workspace so that it is not dynamic by opening the .zwi file and changing the changing the folder_based option to No.

Code: Select all

<Workspace name="Active" sorted="Yes" autosynch="Yes" folder_based="Yes" filename="" st_mtime="0" type="Unknown">
Cheers Jussi
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Re: Adding a file to workspace automatically

Post by jussij »

The latest Zeus release adds a warning message for this scenario letting the user know why this is happening and it also offers a suggestion on how to fix the issue.

That latest version can be downloaded form here: https://www.zeusedit.com/download.html

Cheers Jussi
rbc
Posts: 15
Joined: Thu Feb 17, 2022 3:22 pm

Re: Adding a file to workspace automatically

Post by rbc »

The dynamic monitoring option is great, so thank you for that. However I frequently also feel the need to have "Ignore folders of files" specified with this, like *.pyc for .git. Is there a particular reason why that configuration gets disabled when dynamic monitoring is enabled?
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Re: Adding a file to workspace automatically

Post by jussij »

They only reason, these are two distinct features built over an extended period of time.

The original version was non-dynamic, and it did nothing more than take a folder location and extension filtering to build a static workspace.

The dynamic feature was added some time later, and it is built around the Windows file system watcher, and it build a workspace by watching a specific folder location.

Now that dynamic watcher also does some automatic filtering as it ignores any files Zeus thinks are binary, but there is no user configurable option on that filtering.

I will have to see if adding something like doable and how difficult an addition it will be ;)

Cheers Jussi
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Re: Adding a file to workspace automatically

Post by jussij »

Having looked into this, there is no easy way to have these filter options feed into the dynamic folder creation Zeus feature.

However, the dynamic folder creation already had an Ignore Folders option controlled via INI file, so an Ignore Files option has been added as well.

These changes can be found in the latest version found here: https://www.zeusedit.com/download.html

These are control via the following INI file:

Code: Select all

C:\Users\<User ID>\AppData\Local\Programs\Zeus (x64)\xSolution.ini
The values in that file should be as shown below:

Code: Select all

[Ignore Files]
Extensions=".pyc"

[Ignore Folders]
1=.cache
2=.ccls-cache
3=.git
4=.idea
5=.metadata
6=.nuke
7=.run
8=.svn
9=backup
10=debug
11=obj
12=release
13=temp
14=tmp
15=x64
16=x86
So in the example above the .pyc file extension has been added as a file extension to be ignored.

ADDITIONAL NOTES:
1. The [Ignore Folders] shown above are the default values automatically set by Zeus
2. These defaults can be remove by replacing that [Ignore Folders] section with the following:

Code: Select all

[Ignore Folders]
Use Defaults=0
2. The Ignore Files, Extensions option is a semicolon delimited string, which allows multiple file extension to be added. For example:

Code: Select all

[Ignore Files]
Extensions=".pyc;*.obj;*.res"
3. By default that Extensions value will be empty.
4. There is also a long list of file extensions that Zeus considers to be binary files. There is no option to override that default list, as this extensions option only adds to that default list.

Now having said all of this, what is confusing, is that default list of Zeus binary files already defines the .pyc file extension as a binary file, meaning by default files with that extension are already ignored.

Are you sure file with that extension are showing up in your dynamic workspace :?:
rbc
Posts: 15
Joined: Thu Feb 17, 2022 3:22 pm

Re: Adding a file to workspace automatically

Post by rbc »

Thank you for the information Jussi. I'll use the INI file settings.

You are indeed right, I'm unable to find a .pyc in the default workspace. I'm not sure what file extension it was now, a Python venv comes with all sorts of assorted file extensions. Nonetheless, I now have a way of filtering those out, which is great. Thanks again.
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Re: Adding a file to workspace automatically

Post by jussij »

If you come across a file that is a known binary file, I'd also suggest posting that extension to the end of this thread, as it then and can be added to that internal list of Zeus know binary files.

That internal list is used in other places by Zeus, so getting it added to that list is also a good idea.

Cheers Jussi
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Re: Adding a file to workspace automatically

Post by jussij »

Just to make a small correction. Adding the files to the INI file is making a change to that internal binary list of file extensions so it does work across the whole editor.

However, by reporting these additional binary files means the default Zeus installation will also know about these files, so it will help out other Zeus users ;)

Cheers Jussi
Post Reply