#include "wx/numdlg.h"
#include "wx/textdlg.h"
#include "wx/ffile.h"
+#include "wx/scopedptr.h"
#include "wx/stopwatch.h"
#include "wx/process.h"
void OnFileExec(wxCommandEvent& event);
void OnFileLaunch(wxCommandEvent& event);
void OnOpenURL(wxCommandEvent& event);
+ void OnShowCommandForExt(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
Exec_Shell,
Exec_POpen,
Exec_OpenFile,
+ Exec_ShowCommandForExt,
Exec_LaunchFile,
Exec_OpenURL,
Exec_DDEExec,
EVT_MENU(Exec_POpen, MyFrame::OnPOpen)
EVT_MENU(Exec_OpenFile, MyFrame::OnFileExec)
+ EVT_MENU(Exec_ShowCommandForExt, MyFrame::OnShowCommandForExt)
EVT_MENU(Exec_LaunchFile, MyFrame::OnFileLaunch)
EVT_MENU(Exec_OpenURL, MyFrame::OnOpenURL)
menuFile->AppendSeparator();
menuFile->Append(Exec_OpenFile, wxT("Open &file...\tCtrl-F"),
wxT("Launch the command to open this kind of files"));
+ menuFile->Append(Exec_ShowCommandForExt,
+ "Show association for extension...\tShift-Ctrl-A",
+ "Show the command associated with the given extension");
menuFile->Append(Exec_LaunchFile, wxT("La&unch file...\tShift-Ctrl-F"),
wxT("Launch the default application associated with the file"));
menuFile->Append(Exec_OpenURL, wxT("Open &URL...\tCtrl-U"),
DoAsyncExec(cmd);
}
+void MyFrame::OnShowCommandForExt(wxCommandEvent& WXUNUSED(event))
+{
+ static wxString s_ext;
+
+ wxString ext = wxGetTextFromUser
+ (
+ "Enter the extension without leading dot",
+ "Exec sample",
+ s_ext,
+ this
+ );
+ if ( ext.empty() )
+ return;
+
+ s_ext = ext;
+
+ wxScopedPtr<wxFileType>
+ ft(wxTheMimeTypesManager->GetFileTypeFromExtension(ext));
+ if ( !ft )
+ {
+ wxLogError("Information for extension \"%s\" not found", ext);
+ return;
+ }
+
+ const wxString cmd = ft->GetOpenCommand("file." + ext);
+ if ( cmd.empty() )
+ {
+ wxLogWarning("Open command for extension \"%s\" not defined.", ext);
+ return;
+ }
+
+ wxLogMessage("Open command for files of extension \"%s\" is\n%s",
+ ext, cmd);
+}
+
void MyFrame::OnFileLaunch(wxCommandEvent& WXUNUSED(event))
{
if ( !AskUserForFileName() )
wxLogNull nolog;
wxString strKey;
+ // Since Windows Vista the association used by Explorer is different from
+ // the association information stored in the traditional part of the
+ // registry. Unfortunately the new schema doesn't seem to be documented
+ // anywhere so using it involves a bit of guesswork:
+ //
+ // The information is stored under Explorer-specific key whose path is
+ // below. The interesting part is UserChoice subkey which is the only one
+ // we use so far but there is also OpenWithProgids subkey which can exist
+ // even if UserChoice doesn't. However in practice there doesn't seem to be
+ // any cases when OpenWithProgids values for the given extension are
+ // different from those found directly under HKCR\.ext, so for now we don't
+ // bother to use this, apparently the programs registering their file type
+ // associations do it in both places. We do use UserChoice because when the
+ // association is manually changed by the user it's only recorded there and
+ // so must override whatever value was created under HKCR by the setup
+ // program.
+
{
- wxRegKey explorerKey(wxRegKey::HKCU, wxT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\") + m_ext);
- if (explorerKey.Exists())
+ wxRegKey explorerKey
+ (
+ wxRegKey::HKCU,
+ wxT("Software\\Microsoft\\Windows\\CurrentVersion\\")
+ wxT("Explorer\\FileExts\\") +
+ m_ext +
+ wxT("\\UserChoice")
+ );
+ if ( explorerKey.Open(wxRegKey::Read) &&
+ explorerKey.QueryValue(wxT("Progid"), strKey) )
{
- if (explorerKey.Open(wxRegKey::Read))
- {
- if (explorerKey.QueryValue(wxT("Progid"), strKey))
- {
- strKey = wxFileTypeImplGetCurVer(strKey);
- }
- }
+ strKey = wxFileTypeImplGetCurVer(strKey);
}
}