Open a file from inside wxApp in system file manager. Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
apoorv569
Super wx Problem Solver
Super wx Problem Solver
Posts: 426
Joined: Tue Oct 20, 2020 3:35 pm

Open a file from inside wxApp in system file manager.

Post by apoorv569 »

Is there some way to open a file in system file manager from inside the wxApp provided the absolute path for file?
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Open a file from inside wxApp in system file manager.

Post by PB »

There is wxLaunchDefaultApplication():
https://docs.wxwidgets.org/trunk/group_ ... f82b2d66c3

But that does what its description does. I am no sure it is what you want, i.e., "open a file in system file manager". That looks like a Linux-specific thing, there is no such thing in MS Windows (aside from launching File Explorer in a specified folder).
apoorv569
Super wx Problem Solver
Super wx Problem Solver
Posts: 426
Joined: Tue Oct 20, 2020 3:35 pm

Re: Open a file from inside wxApp in system file manager.

Post by apoorv569 »

PB wrote: Thu Mar 18, 2021 6:18 am There is wxLaunchDefaultApplication():
https://docs.wxwidgets.org/trunk/group_ ... f82b2d66c3

But that does what its description does. I am no sure it is what you want, i.e., "open a file in system file manager". That looks like a Linux-specific thing, there is no such thing in MS Windows (aside from launching File Explorer in a specified folder).
wxLaunchDefaultApplication() is, if I understand correctly, it will open the default application for type of file it is, say user clicks on a video file, and the default video player for the system is set to VLC then it will open VLC, then it is not what I want.

I want that if a user right clicks on a file that is inserted into say a wxDVLC and choose something like open/show file in explorer, it just opens the file explorer with the path to where the selected file is located.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Open a file from inside wxApp in system file manager.

Post by PB »

I see. I am not aware of any such portable function in wxWidgets. That is what FireFox in Download Manager on Window when right-clicking on a file calls "Open Containing Folder".

AFAIK, for example MS Windows does not have a concept of "default file manager". You can set default application for example for Web Browser or Media Player but not for Shell Manager, so I cannot set Total Commander I am using as my file manager, Microsoft's File Explorer is always the one and one would have to do something like this.

I suppose this may be different on Linux, where one can select a file manager as the default, e.g. Double Commander instead of whatever the distribution offers as its default?

But perhaps it could be possible to implement portable wxBrowseToFile() function...
apoorv569
Super wx Problem Solver
Super wx Problem Solver
Posts: 426
Joined: Tue Oct 20, 2020 3:35 pm

Re: Open a file from inside wxApp in system file manager.

Post by apoorv569 »

PB wrote: Thu Mar 18, 2021 8:05 am I see. I am not aware of any such portable function in wxWidgets. That is what FireFox in Download Manager on Window when right-clicking on a file calls "Open Containing Folder".

AFAIK, for example MS Windows does not have a concept of "default file manager". You can set default application for example for Web Browser or Media Player but not for Shell Manager, so I cannot set Total Commander I am using as my file manager, Microsoft's File Explorer is always the one and one would have to do something like this.

I suppose this may be different on Linux, where one can select a file manager as the default, e.g. Double Commander instead of whatever the distribution offers as its default?

But perhaps it could be possible to implement portable wxBrowseToFile() function...
There is a command in Linux xdg-open, which opens the default application for the file type, passed as the second argument. The system's default file manager in my case, as I only pass the path to a folder. I am handling this problem with,

Code: Select all

            wxExecute(wxString::Format("xdg-open '%s'", sample_path.BeforeLast('/')));
So this solves the problem. I haven't noticed any problem so far, I have tested this on 2 different machines with different Linux distributions on them. So I think this post is resolved for now. Here are some useful links in case anybody in future finds this,

https://unix.stackexchange.com/question ... pen-a-file
https://linux.die.net/man/1/xdg-open
Post Reply