Share

wxWidgets

Tracker: Feature Requests

3 Function for displaying a file - ID: 1784007
Last Update: Comment added ( robind )

Hi!

It would be nice to have a function that can open a file in the associated
program.
html->browser,
doc->Ms WORD
PDF->Acrobat reader ect.

I have written a function for that, because you have to ask the
mime-manager for every opening. So I created a function that does that for
me. But it's not in wxw-style, maybe it can be a suggestion:

void wxDisplayFile(const wxString& FileName)
{
// Is the ile actually there?
if(!wxFileExists(FileName))
throw file_not_found(FileName);

// Retrieve open command using mime-types manager
wxFileName fn(FileName);
wxString ext = fn.GetExt();
boost::scoped_ptr<wxFileType>
ft(wxTheMimeTypesManager->GetFileTypeFromExtension(ext));
if(ft == NULL)
throw std::runtime_error(str(boost::format("Datei %s kann nicht geöffnet
werden.\n"
"Es konnte keine Standardanwendung für den Dateityp gefunden werden!") %
FileName).c_str());

wxString cmd = ft->GetOpenCommand(FileName);

if(cmd.Len())
wxExecute(cmd);
else
throw std::runtime_error(str(boost::format("Datei %s kann nicht geöffnet
werden.\n"
"Es konnte keine Standardanwendung für den Dateityp gefunden werden!") %
FileName).c_str());
}


Maximilian Matthé ( maximatthe ) - 2007-08-29 13:21

3

Open

None

Nobody/Anonymous

None

None

Public


Comments ( 3 )

Date: 2008-05-20 21:51
Sender: robindProject Admin


The wxWidgets trackers have moved to http://trac.wxwidgets.org/. Please
update your bookmarks, and go there to update your tracker items.


Date: 2008-02-27 07:59
Sender: moonkid


I would be very pleased to have this in wx.


Date: 2008-02-27 02:22
Sender: vadzProject AdminAccepting Donations


I'd actually put this into wxFileType, e.g.

// open the file using the default command associated with it
//
// return true if the file was opened, false if we couldn't find
// the command for it or if it failed
static bool OpenFile(const wxString& filename);

Of course, the function is still rather trivial so I'm not sure how useful
is it to add it...


Attached File

No Files Currently Attached

Change ( 1 )

Field Old Value Date By
priority 5 2008-02-27 02:22 vadz