Jump to content

How to hook into the OpenFile menu and get the associated file path?


klepto2
 Share

Go to solution Solved by Josh,

Recommended Posts

I want to add some additional handling to some files. (lets say i want to add support for a certain kind of filetype)

I can succesfully  hook into the EVENT_WIDGETACTION when the "Open File" menu is clicked, but how do i get the item and the needed info for what this is "Open File"-action is triggered?

this is the simple hook i use:

function extension.hook(event, extension)
    if event.id == EVENT_WIDGETACTION then
        local widget = Widget(event.source)
        if widget ~= nil and event.text == "Open File" and event.extra ~= nil then
            local obj = Widget(event.extra)
            Print(event.text)
            return true
        end
    end
end

 

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Link to comment
Share on other sites

So you want to get the file path the user selects? Or do you want to override the file requester with your own? Or just add some additional extensions to the dialog?

This is how the code works:

        else if (text == "Open")
        {
            auto filter = GetFilePattern(FILECATEGORY_SCENE);
            auto file = RequestFile(L"Open File", CurrentDir() + L"/Maps/", filter, 10000);
            if (not file.empty())
            {

The get file pattern function creates the file pattern string for a category of files. For textures, it will iterate through the loaded plugins and return a file pattern that includes all of them, plus the natively supported format DDS and RAW.

For maps (FILECATEGORY_SCENE) the routine just returns a hard-coded string for Ultra maps and Leadwerks maps.

I have not yet thought about how additional scene loading formats should be handled.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

  • Solution

Check for this:

EmitEvent(EVENT_OPENASSET, Self(), 0, 0, 0, 0, 0, filepath->package, filepath->path);

EVENT_OPENASSET is not currently exposed, but it equals 11011.

Self() is the asset browser object, but there's only one of those so you can just specify nil for the source in ListenEvent().

  • Thanks 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...