]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/dbgrptg.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/dbgrptg.cpp
3 // Purpose: implementation of wxDebugReportPreviewStd
4 // Author: Vadim Zeitlin, Andrej Putrin
8 // Copyright: (c) 2005 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #include "wx/wxprec.h"
28 #include "wx/checklst.h"
29 #include "wx/textctrl.h"
34 #include "wx/debugrpt.h"
37 #include "wx/filename.h"
39 #include "wx/mimetype.h"
41 #include "wx/statline.h"
43 // ----------------------------------------------------------------------------
44 // wxDumpPreviewDlg: simple class for showing ASCII preview of dump files
45 // ----------------------------------------------------------------------------
47 class wxDumpPreviewDlg
: public wxDialog
50 wxDumpPreviewDlg(wxWindow
*parent
,
51 const wxString
& title
,
52 const wxString
& text
);
58 DECLARE_NO_COPY_CLASS(wxDumpPreviewDlg
)
61 wxDumpPreviewDlg::wxDumpPreviewDlg(wxWindow
*parent
,
62 const wxString
& title
,
64 : wxDialog(parent
, wxID_ANY
, title
,
65 wxDefaultPosition
, wxDefaultSize
,
66 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
71 // use wxTE_RICH2 style to avoid 64kB limit under MSW and display big files
72 // faster than with wxTE_RICH
73 m_text
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
,
74 wxPoint(0, 0), wxDefaultSize
,
79 m_text
->SetValue(text
);
81 // use fixed-width font
82 m_text
->SetFont(wxFont(12, wxFONTFAMILY_TELETYPE
,
83 wxFONTSTYLE_NORMAL
, wxFONTWEIGHT_NORMAL
));
85 wxButton
*btnClose
= new wxButton(this, wxID_CANCEL
, _("Close"));
91 wxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
),
92 *sizerBtns
= new wxBoxSizer(wxHORIZONTAL
);
94 sizerBtns
->Add(btnClose
, 0, 0, 1);
96 sizerTop
->Add(m_text
, 1, wxEXPAND
);
97 sizerTop
->Add(sizerBtns
, 0, wxALIGN_RIGHT
| wxTOP
| wxBOTTOM
| wxRIGHT
, 1);
102 // make the text window bigger to show more contents of the file
103 sizerTop
->SetItemMinSize(m_text
, 600, 300);
112 // ----------------------------------------------------------------------------
113 // wxDumpOpenExternalDlg: choose a command for opening the given file
114 // ----------------------------------------------------------------------------
116 class wxDumpOpenExternalDlg
: public wxDialog
119 wxDumpOpenExternalDlg(wxWindow
*parent
, const wxFileName
& filename
);
121 // return the command chosed by user to open this file
122 const wxString
& GetCommand() const { return m_command
; }
127 void OnBrowse(wxCommandEvent
& event
);
129 DECLARE_EVENT_TABLE()
130 DECLARE_NO_COPY_CLASS(wxDumpOpenExternalDlg
)
133 BEGIN_EVENT_TABLE(wxDumpOpenExternalDlg
, wxDialog
)
134 EVT_BUTTON(wxID_MORE
, wxDumpOpenExternalDlg::OnBrowse
)
138 wxDumpOpenExternalDlg::wxDumpOpenExternalDlg(wxWindow
*parent
,
139 const wxFileName
& filename
)
144 _("Open file \"%s\""),
145 filename
.GetFullPath().c_str()
151 wxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
152 sizerTop
->Add(new wxStaticText(this, wxID_ANY
,
155 _("Enter command to open file \"%s\":"),
156 filename
.GetFullName().c_str()
158 wxSizerFlags().Border());
160 wxSizer
*sizerH
= new wxBoxSizer(wxHORIZONTAL
);
162 wxTextCtrl
*command
= new wxTextCtrl
170 wxTextValidator(wxFILTER_NONE
, &m_command
)
173 wxSizerFlags(1).Align(wxALIGN_CENTER_VERTICAL
));
174 wxButton
*browse
= new wxButton(this, wxID_MORE
, wxT(">>"),
175 wxDefaultPosition
, wxDefaultSize
,
178 wxSizerFlags(0).Align(wxALIGN_CENTER_VERTICAL
). Border(wxLEFT
));
180 sizerTop
->Add(sizerH
, wxSizerFlags(0).Expand().Border());
182 sizerTop
->Add(new wxStaticLine(this), wxSizerFlags().Expand().Border());
184 sizerTop
->Add(CreateStdDialogButtonSizer(wxOK
| wxCANCEL
),
185 wxSizerFlags().Align(wxALIGN_RIGHT
).Border());
198 void wxDumpOpenExternalDlg::OnBrowse(wxCommandEvent
& )
200 wxFileName
fname(m_command
);
201 wxFileDialog
dlg(this,
202 wxFileSelectorPromptStr
,
203 fname
.GetPathWithSep(),
206 , _("Executable files (*.exe)|*.exe|All files (*.*)|*.*||")
209 if ( dlg
.ShowModal() == wxID_OK
)
211 m_command
= dlg
.GetPath();
212 TransferDataToWindow();
217 // ----------------------------------------------------------------------------
218 // wxDebugReportDialog: class showing debug report to the user
219 // ----------------------------------------------------------------------------
221 class wxDebugReportDialog
: public wxDialog
224 wxDebugReportDialog(wxDebugReport
& dbgrpt
);
226 virtual bool TransferDataToWindow();
227 virtual bool TransferDataFromWindow();
230 void OnView(wxCommandEvent
& );
231 void OnViewUpdate(wxUpdateUIEvent
& );
232 void OnOpen(wxCommandEvent
& );
235 // small helper: add wxEXPAND and wxALL flags
236 static wxSizerFlags
SizerFlags(int proportion
)
238 return wxSizerFlags(proportion
).Expand().Border();
242 wxDebugReport
& m_dbgrpt
;
244 wxCheckListBox
*m_checklst
;
247 wxArrayString m_files
;
249 DECLARE_EVENT_TABLE()
250 DECLARE_NO_COPY_CLASS(wxDebugReportDialog
)
253 // ============================================================================
254 // wxDebugReportDialog implementation
255 // ============================================================================
257 BEGIN_EVENT_TABLE(wxDebugReportDialog
, wxDialog
)
258 EVT_BUTTON(wxID_VIEW_DETAILS
, wxDebugReportDialog::OnView
)
259 EVT_UPDATE_UI(wxID_VIEW_DETAILS
, wxDebugReportDialog::OnViewUpdate
)
260 EVT_BUTTON(wxID_OPEN
, wxDebugReportDialog::OnOpen
)
261 EVT_UPDATE_UI(wxID_OPEN
, wxDebugReportDialog::OnViewUpdate
)
265 // ----------------------------------------------------------------------------
267 // ----------------------------------------------------------------------------
269 wxDebugReportDialog::wxDebugReportDialog(wxDebugReport
& dbgrpt
)
270 : wxDialog(NULL
, wxID_ANY
,
271 wxString::Format(_("Debug report \"%s\""),
272 dbgrpt
.GetReportName().c_str()),
275 wxDEFAULT_DIALOG_STYLE
| wxTHICK_FRAME
),
278 // upper part of the dialog: explanatory message
280 msg
<< _("A debug report has been generated in the directory\n")
282 << _T(" \"") << dbgrpt
.GetDirectory() << _T("\"\n")
284 << _("The report contains the files listed below. If any of these ")
285 << _("files contain private information,\n")
286 << _("please uncheck them and they will be removed from the report.\n")
288 << _("If you wish to suppress this debug report completely, please ")
289 << _("choose the \"Cancel\" button,\n")
290 << _("but be warned that it may hinder improving the program, so if\n")
291 << _("at all possible please do continue with the report generation.\n")
293 << _(" Thank you and we're sorry for the inconvenience!\n")
294 << _T("\n\n"); // just some white space to separate from other stuff
296 const wxSizerFlags
flagsFixed(SizerFlags(0));
297 const wxSizerFlags
flagsExpand(SizerFlags(1));
298 const wxSizerFlags
flagsExpand2(SizerFlags(2));
300 wxSizer
*sizerPreview
=
301 new wxStaticBoxSizer(wxVERTICAL
, this, _("&Debug report preview:"));
302 sizerPreview
->Add(CreateTextSizer(msg
), SizerFlags(0).Centre());
304 // ... and the list of files in this debug report with buttons to view them
305 wxSizer
*sizerFileBtns
= new wxBoxSizer(wxVERTICAL
);
306 sizerFileBtns
->AddStretchSpacer(1);
307 sizerFileBtns
->Add(new wxButton(this, wxID_VIEW_DETAILS
, _T("&View...")),
308 wxSizerFlags().Border(wxBOTTOM
));
309 sizerFileBtns
->Add(new wxButton(this, wxID_OPEN
, _T("&Open...")),
310 wxSizerFlags().Border(wxTOP
));
311 sizerFileBtns
->AddStretchSpacer(1);
313 m_checklst
= new wxCheckListBox(this, wxID_ANY
);
315 wxSizer
*sizerFiles
= new wxBoxSizer(wxHORIZONTAL
);
316 sizerFiles
->Add(m_checklst
, flagsExpand
);
317 sizerFiles
->Add(sizerFileBtns
, flagsFixed
);
319 sizerPreview
->Add(sizerFiles
, flagsExpand2
);
322 // lower part of the dialog: notes field
323 wxSizer
*sizerNotes
= new wxStaticBoxSizer(wxVERTICAL
, this, _("&Notes:"));
325 msg
= _("If you have any additional information pertaining to this bug\n");
326 msg
<< _("report, please enter it here and it will be joined to it:");
328 m_notes
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
,
329 wxDefaultPosition
, wxDefaultSize
,
332 sizerNotes
->Add(CreateTextSizer(msg
), flagsFixed
);
333 sizerNotes
->Add(m_notes
, flagsExpand
);
336 wxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
337 sizerTop
->Add(sizerPreview
, flagsExpand2
);
338 sizerTop
->AddSpacer(5);
339 sizerTop
->Add(sizerNotes
, flagsExpand
);
340 sizerTop
->Add(CreateStdDialogButtonSizer(wxOK
| wxCANCEL
), flagsFixed
);
342 SetSizerAndFit(sizerTop
);
347 // ----------------------------------------------------------------------------
349 // ----------------------------------------------------------------------------
351 bool wxDebugReportDialog::TransferDataToWindow()
353 // all files are included in the report by default
354 const size_t count
= m_dbgrpt
.GetFilesCount();
355 for ( size_t n
= 0; n
< count
; n
++ )
359 if ( m_dbgrpt
.GetFile(n
, &name
, &desc
) )
361 m_checklst
->Append(name
+ _T(" (") + desc
+ _T(')'));
362 m_checklst
->Check(n
);
371 bool wxDebugReportDialog::TransferDataFromWindow()
373 // any unchecked files should be removed from the report
374 const size_t count
= m_checklst
->GetCount();
375 for ( size_t n
= 0; n
< count
; n
++ )
377 if ( !m_checklst
->IsChecked(n
) )
379 m_dbgrpt
.RemoveFile(m_files
[n
]);
383 // if the user entered any notes, add them to the report
384 const wxString notes
= m_notes
->GetValue();
385 if ( !notes
.empty() )
387 // for now it's fixed, could make it configurable in the future...
388 const wxChar
*NOTES_FILE_NAME
= _T("notes.txt");
389 wxFileName
fn(m_dbgrpt
.GetDirectory(), NOTES_FILE_NAME
);
390 wxFFile
file(fn
.GetFullPath(), _T("w"));
391 if ( file
.IsOpened() && file
.Write(notes
) )
393 m_dbgrpt
.AddFile(NOTES_FILE_NAME
, _T("user notes"));
400 // ----------------------------------------------------------------------------
402 // ----------------------------------------------------------------------------
404 void wxDebugReportDialog::OnView(wxCommandEvent
& )
406 const int sel
= m_checklst
->GetSelection();
407 wxCHECK_RET( sel
!= -1, _T("invalid selection in OnView()") );
409 wxFileName
fn(m_dbgrpt
.GetDirectory(), m_files
[sel
]);
412 wxFFile
file(fn
.GetFullPath());
413 if ( file
.IsOpened() && file
.ReadAll(&str
) )
415 wxDumpPreviewDlg
dlg(this, m_files
[sel
], str
);
420 void wxDebugReportDialog::OnOpen(wxCommandEvent
& )
422 const int sel
= m_checklst
->GetSelection();
423 wxCHECK_RET( sel
!= -1, _T("invalid selection in OnOpen()") );
425 wxFileName
fn(m_dbgrpt
.GetDirectory(), m_files
[sel
]);
427 // try to get the command to open this kind of files ourselves
430 ft
= wxTheMimeTypesManager
->GetFileTypeFromExtension(fn
.GetExt());
433 command
= ft
->GetOpenCommand(fn
.GetFullPath());
436 // if we couldn't, ask the user
437 if ( command
.empty() )
439 wxDumpOpenExternalDlg
dlg(this, fn
);
440 if ( dlg
.ShowModal() == wxID_OK
)
442 // get the command chosen by the user and append file name to it
444 // if we don't have place marker for file name in the command...
445 wxString cmd
= dlg
.GetCommand();
446 if ( cmd
.find(_T('%')) == wxString::npos
)
449 cmd
+= _T(" \"%s\"");
452 command
= wxFileType::ExpandCommand(cmd
, fn
.GetFullPath());
456 if ( !command
.empty() )
457 ::wxExecute(command
);
460 void wxDebugReportDialog::OnViewUpdate(wxUpdateUIEvent
& event
)
462 int sel
= m_checklst
->GetSelection();
465 wxFileName
fn(m_dbgrpt
.GetDirectory(), m_files
[sel
]);
466 event
.Enable(fn
.FileExists());
473 // ============================================================================
474 // wxDebugReportPreviewStd implementation
475 // ============================================================================
477 bool wxDebugReportPreviewStd::Show(wxDebugReport
& dbgrpt
) const
479 if ( !dbgrpt
.GetFilesCount() )
482 wxDebugReportDialog
dlg(dbgrpt
);
484 return dlg
.ShowModal() == wxID_OK
&& dbgrpt
.GetFilesCount() != 0;
487 #endif // wxUSE_DEBUGREPORT