Page 1 of 1

Close tab and delete file

Posted: Fri Aug 29, 2014 9:58 pm
by sfeldner
I've used Zeus for years but I'm still a nubie -- so excuse me if this is a stupid question. I'm trying to write a macro and I'm also looking to add that macro to the file tab, if possible.

This is what I want to do: Right-click file tab and choose a function: "Close Document and Delete File".

I often find myself creating test files while I'm working on something and by the time I'm done, I have way too many test files (Documents) open in Zeus. I want to be able to clean-up after myself by closing some tabs and having the underlying file deleted as well.

I have been unable to find a macro command to delete a file and I have no idea if a macro could be attached to a file tab (which would not be a big deal if it can't be done).

Is this a stupid idea? Is there some functionality that I'm missing. I very seldom use Workspaces or Source Control so I haven't even looked there for an answer -- I'd rather it be a simple one or two clicks or maybe a key combination (wouldn't be as nice).

Thanks much for any help!

Posted: Sat Aug 30, 2014 2:09 am
by jussij
This is what I want to do: Right-click file tab and choose a function:
"Close Document and Delete File".
There really is no way to attach a macro to the file tab.

But there is a way to attach a macro to the document window list (View, Document List menu).

In that dialog there is a Run Trigger option and that button will run whatever macro in defined in the Document Listing entry field of the Options, Editor Options menu, Triggers panel.

Code: Select all

I want to be able to clean-up after myself by closing some tabs and having the underlying file deleted as well.
Using this macro as a guide:

Code: Select all

zScript\event_window_list.lua
Here is a macro that can be used to delete the files using the Document List dialog:

Code: Select all

function key_macro()

    local items = "These files have been selected for deletion:\n\n"

    local indent = "    "

    for i = 1, argc(), 1 do
        items = items .. indent .. argv(i - 1) .. "\n"
    end

    items = items .. "\n\n"
    items = items .. "Are you sure you want to delete these files?"

    result = message_box(4, items, "Delete Selected Files")

    -- return values from the message box
    local yes = 6
    local no  = 7

    if (yes == result) then
        -- delete the selected files
        for i = 1, argc(), 1 do
            file_name = argv(i - 1)

            -- activate the window
            window_activate_name(file_name)

            if os.remove(file_name) == true then
                -- close the active window
                FileClose()
            end
        end

        message("The selected files have been deleted.")
    else
        message("Operation cancelled by user.")
    end
end

key_macro() -- run the macro
To use this macro just save the code to a delete_files.lua file in the zScript folder and then add it to the Triggers section mention above.
I'd rather it be a simple one or two clicks or maybe a key combination (wouldn't be as nice).
To use the macro all you have to do is:
  1. Alt+B to bring up the Document Window dialog
  2. Multi-select the files that you want to remove
  3. Hit the Run Trigger button.
Cheers Jussi