]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/dbgrptg.cpp
Change wxNotebook selection before sending page changed event in wxMSW.
[wxWidgets.git] / src / generic / dbgrptg.cpp
index d265f9eb3e11fc63e0cc4cd3dd5c4562ab85ade1..5d967fc7eb6976c415dca91def339524dec81fbd 100644 (file)
@@ -6,7 +6,7 @@
 // Created:     2005-01-21
 // RCS-ID:      $Id$
 // Copyright:   (c) 2005 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
-// License:     wxWindows licence
+// Licence:     wxWindows licence
 ///////////////////////////////////////////////////////////////////////////////
 
 // ============================================================================
     #pragma hdrstop
 #endif
 
+#if wxUSE_DEBUGREPORT && wxUSE_XML
+
+#include "wx/debugrpt.h"
+
 #ifndef WX_PRECOMP
     #include "wx/sizer.h"
     #include "wx/checklst.h"
     #include "wx/textctrl.h"
+    #include "wx/intl.h"
+    #include "wx/stattext.h"
+    #include "wx/filedlg.h"
+    #include "wx/valtext.h"
+    #include "wx/button.h"
 #endif // WX_PRECOMP
 
-#if wxUSE_DEBUGREPORT
-
-#include "wx/debugrpt.h"
-
-#include "wx/intl.h"
 #include "wx/filename.h"
 #include "wx/ffile.h"
 #include "wx/mimetype.h"
 
 #include "wx/statline.h"
 
+#ifdef __WXMSW__
+    #include "wx/evtloop.h"     // for SetCriticalWindow()
+    #include "wx/scopeguard.h"
+#endif // __WXMSW__
+
 // ----------------------------------------------------------------------------
 // wxDumpPreviewDlg: simple class for showing ASCII preview of dump files
 // ----------------------------------------------------------------------------
@@ -55,7 +64,7 @@ private:
     // the text we show
     wxTextCtrl *m_text;
 
-    DECLARE_NO_COPY_CLASS(wxDumpPreviewDlg)
+    wxDECLARE_NO_COPY_CLASS(wxDumpPreviewDlg);
 };
 
 wxDumpPreviewDlg::wxDumpPreviewDlg(wxWindow *parent,
@@ -124,14 +133,21 @@ public:
     wxString m_command;
 
 private:
+
+#if wxUSE_FILEDLG
     void OnBrowse(wxCommandEvent& event);
+#endif // wxUSE_FILEDLG
 
     DECLARE_EVENT_TABLE()
-    DECLARE_NO_COPY_CLASS(wxDumpOpenExternalDlg)
+    wxDECLARE_NO_COPY_CLASS(wxDumpOpenExternalDlg);
 };
 
 BEGIN_EVENT_TABLE(wxDumpOpenExternalDlg, wxDialog)
+
+#if wxUSE_FILEDLG
     EVT_BUTTON(wxID_MORE, wxDumpOpenExternalDlg::OnBrowse)
+#endif
+
 END_EVENT_TABLE()
 
 
@@ -165,18 +181,25 @@ wxDumpOpenExternalDlg::wxDumpOpenExternalDlg(wxWindow *parent,
                                 wxID_ANY,
                                 wxEmptyString,
                                 wxDefaultPosition,
-                                wxSize(250, -1),
-                                0,
-                                wxTextValidator(wxFILTER_NONE, &m_command)
+                                wxSize(250, wxDefaultCoord),
+                                0
+#if wxUSE_VALIDATORS
+                                ,wxTextValidator(wxFILTER_NONE, &m_command)
+#endif
                               );
     sizerH->Add(command,
                     wxSizerFlags(1).Align(wxALIGN_CENTER_VERTICAL));
+
+#if wxUSE_FILEDLG
+
     wxButton *browse = new wxButton(this, wxID_MORE, wxT(">>"),
                                     wxDefaultPosition, wxDefaultSize,
                                     wxBU_EXACTFIT);
     sizerH->Add(browse,
                 wxSizerFlags(0).Align(wxALIGN_CENTER_VERTICAL). Border(wxLEFT));
 
+#endif // wxUSE_FILEDLG
+
     sizerTop->Add(sizerH, wxSizerFlags(0).Expand().Border());
 
     sizerTop->Add(new wxStaticLine(this), wxSizerFlags().Expand().Border());
@@ -195,6 +218,8 @@ wxDumpOpenExternalDlg::wxDumpOpenExternalDlg(wxWindow *parent,
     command->SetFocus();
 }
 
+#if wxUSE_FILEDLG
+
 void wxDumpOpenExternalDlg::OnBrowse(wxCommandEvent& )
 {
     wxFileName fname(m_command);
@@ -213,6 +238,7 @@ void wxDumpOpenExternalDlg::OnBrowse(wxCommandEvent& )
     }
 }
 
+#endif // wxUSE_FILEDLG
 
 // ----------------------------------------------------------------------------
 // wxDebugReportDialog: class showing debug report to the user
@@ -247,7 +273,7 @@ private:
     wxArrayString m_files;
 
     DECLARE_EVENT_TABLE()
-    DECLARE_NO_COPY_CLASS(wxDebugReportDialog)
+    wxDECLARE_NO_COPY_CLASS(wxDebugReportDialog);
 };
 
 // ============================================================================
@@ -272,26 +298,30 @@ wxDebugReportDialog::wxDebugReportDialog(wxDebugReport& dbgrpt)
                               dbgrpt.GetReportName().c_str()),
                               wxDefaultPosition,
                               wxDefaultSize,
-                              wxDEFAULT_DIALOG_STYLE | wxTHICK_FRAME),
+                              wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER),
                      m_dbgrpt(dbgrpt)
 {
     // upper part of the dialog: explanatory message
     wxString msg;
+    wxString debugDir = dbgrpt.GetDirectory();
+
+    // The temporary directory can be the short form on Windows;
+    // normalize it for the benefit of users.
+#ifdef __WXMSW__
+    wxFileName debugDirFilename(debugDir, wxEmptyString);
+    debugDirFilename.Normalize(wxPATH_NORM_LONG);
+    debugDir = debugDirFilename.GetPath();
+#endif
     msg << _("A debug report has been generated in the directory\n")
-        << _T('\n')
-        << _T("             \"") << dbgrpt.GetDirectory() << _T("\"\n")
-        << _T('\n')
-        << _("The report contains the files listed below. If any of these ")
-        << _("files contain private information,\n")
-        << _("please uncheck them and they will be removed from the report.\n")
-        << _T('\n')
-        << _("If you wish to suppress this debug report completely, please ")
-        << _("choose the \"Cancel\" button,\n")
-        << _("but be warned that it may hinder improving the program, so if\n")
-        << _("at all possible please do continue with the report generation.\n")
-        << _T('\n')
+        << wxT('\n')
+        << wxT("             \"") << debugDir << wxT("\"\n")
+        << wxT('\n')
+        << _("The report contains the files listed below. If any of these files contain private information,\nplease uncheck them and they will be removed from the report.\n")
+        << wxT('\n')
+        << _("If you wish to suppress this debug report completely, please choose the \"Cancel\" button,\nbut be warned that it may hinder improving the program, so if\nat all possible please do continue with the report generation.\n")
+        << wxT('\n')
         << _("              Thank you and we're sorry for the inconvenience!\n")
-        << _T("\n\n"); // just some white space to separate from other stuff
+        << wxT("\n\n"); // just some white space to separate from other stuff
 
     const wxSizerFlags flagsFixed(SizerFlags(0));
     const wxSizerFlags flagsExpand(SizerFlags(1));
@@ -304,9 +334,9 @@ wxDebugReportDialog::wxDebugReportDialog(wxDebugReport& dbgrpt)
     // ... and the list of files in this debug report with buttons to view them
     wxSizer *sizerFileBtns = new wxBoxSizer(wxVERTICAL);
     sizerFileBtns->AddStretchSpacer(1);
-    sizerFileBtns->Add(new wxButton(this, wxID_VIEW_DETAILS, _T("&View...")),
+    sizerFileBtns->Add(new wxButton(this, wxID_VIEW_DETAILS, _("&View...")),
                         wxSizerFlags().Border(wxBOTTOM));
-    sizerFileBtns->Add(new wxButton(this, wxID_OPEN, _T("&Open...")),
+    sizerFileBtns->Add(new wxButton(this, wxID_OPEN, _("&Open...")),
                         wxSizerFlags().Border(wxTOP));
     sizerFileBtns->AddStretchSpacer(1);
 
@@ -322,8 +352,7 @@ wxDebugReportDialog::wxDebugReportDialog(wxDebugReport& dbgrpt)
     // lower part of the dialog: notes field
     wxSizer *sizerNotes = new wxStaticBoxSizer(wxVERTICAL, this, _("&Notes:"));
 
-    msg = _("If you have any additional information pertaining to this bug\n");
-    msg << _("report, please enter it here and it will be joined to it:");
+    msg = _("If you have any additional information pertaining to this bug\nreport, please enter it here and it will be joined to it:");
 
     m_notes = new wxTextCtrl(this, wxID_ANY, wxEmptyString,
                              wxDefaultPosition, wxDefaultSize,
@@ -358,7 +387,7 @@ bool wxDebugReportDialog::TransferDataToWindow()
             desc;
         if ( m_dbgrpt.GetFile(n, &name, &desc) )
         {
-            m_checklst->Append(name + _T(" (") + desc + _T(')'));
+            m_checklst->Append(name + wxT(" (") + desc + wxT(')'));
             m_checklst->Check(n);
 
             m_files.Add(name);
@@ -384,14 +413,8 @@ bool wxDebugReportDialog::TransferDataFromWindow()
     const wxString notes = m_notes->GetValue();
     if ( !notes.empty() )
     {
-        // for now it's fixed, could make it configurable in the future...
-        const wxChar *NOTES_FILE_NAME = _T("notes.txt");
-        wxFileName fn(m_dbgrpt.GetDirectory(), NOTES_FILE_NAME);
-        wxFFile file(fn.GetFullPath(), _T("w"));
-        if ( file.IsOpened() && file.Write(notes) )
-        {
-            m_dbgrpt.AddFile(NOTES_FILE_NAME, _T("user notes"));
-        }
+        // for now filename fixed, could make it configurable in the future...
+        m_dbgrpt.AddText(wxT("notes.txt"), notes, wxT("user notes"));
     }
 
     return true;
@@ -404,7 +427,7 @@ bool wxDebugReportDialog::TransferDataFromWindow()
 void wxDebugReportDialog::OnView(wxCommandEvent& )
 {
     const int sel = m_checklst->GetSelection();
-    wxCHECK_RET( sel != -1, _T("invalid selection in OnView()") );
+    wxCHECK_RET( sel != wxNOT_FOUND, wxT("invalid selection in OnView()") );
 
     wxFileName fn(m_dbgrpt.GetDirectory(), m_files[sel]);
     wxString str;
@@ -420,18 +443,21 @@ void wxDebugReportDialog::OnView(wxCommandEvent& )
 void wxDebugReportDialog::OnOpen(wxCommandEvent& )
 {
     const int sel = m_checklst->GetSelection();
-    wxCHECK_RET( sel != -1, _T("invalid selection in OnOpen()") );
+    wxCHECK_RET( sel != wxNOT_FOUND, wxT("invalid selection in OnOpen()") );
 
     wxFileName fn(m_dbgrpt.GetDirectory(), m_files[sel]);
 
     // try to get the command to open this kind of files ourselves
     wxString command;
+#if wxUSE_MIMETYPE
     wxFileType *
         ft = wxTheMimeTypesManager->GetFileTypeFromExtension(fn.GetExt());
     if ( ft )
     {
         command = ft->GetOpenCommand(fn.GetFullPath());
+        delete ft;
     }
+#endif // wxUSE_MIMETYPE
 
     // if we couldn't, ask the user
     if ( command.empty() )
@@ -443,13 +469,20 @@ void wxDebugReportDialog::OnOpen(wxCommandEvent& )
 
             // if we don't have place marker for file name in the command...
             wxString cmd = dlg.GetCommand();
-            if ( cmd.find(_T('%')) == wxString::npos )
+            if ( !cmd.empty() )
             {
-                // ...add it
-                cmd += _T(" \"%s\"");
+#if wxUSE_MIMETYPE
+                if ( cmd.find(wxT('%')) != wxString::npos )
+                {
+                    command = wxFileType::ExpandCommand(cmd, fn.GetFullPath());
+                }
+                else // no %s nor %1
+#endif // wxUSE_MIMETYPE
+                {
+                    // append the file name to the end
+                    command << cmd << wxT(" \"") << fn.GetFullPath() << wxT('"');
+                }
             }
-
-            command = wxFileType::ExpandCommand(cmd, fn.GetFullPath());
         }
     }
 
@@ -481,8 +514,16 @@ bool wxDebugReportPreviewStd::Show(wxDebugReport& dbgrpt) const
 
     wxDebugReportDialog dlg(dbgrpt);
 
+#ifdef __WXMSW__
+    // before entering the event loop (from ShowModal()), block the event
+    // handling for all other windows as this could result in more crashes
+    wxEventLoop::SetCriticalWindow(&dlg);
+
+    wxON_BLOCK_EXIT1( wxEventLoop::SetCriticalWindow,
+                        static_cast<wxWindow *>(NULL) );
+#endif // __WXMSW__
+
     return dlg.ShowModal() == wxID_OK && dbgrpt.GetFilesCount() != 0;
 }
 
-#endif // wxUSE_DEBUGREPORT
-
+#endif // wxUSE_DEBUGREPORT && wxUSE_XML