Jump to content

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


Go to solution Solved by Josh,

Recommended Posts

Posted

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
Posted

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.

Posted

I want to hook directly into the open file action or double-check event and retrieve the path from the object which has triggered the action. ( in the map tab) .

 

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Posted

Okay...so I guess you want to override some file types, and let the editor still load the defaults? Is this for loading a new map file format?

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

Posted

No, I want to open a certain window if the file type is of a certain type. (lets just assume its a shader file ;) ) like you do by opening the modelviewer when you double click on a model.

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Posted

That is exactly what i want to do. But currently there is no way to do it. (no access to most functions or to retreive the actual node which was selected)

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
  • Solution
Posted

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.

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.

×
×
  • Create New...