]>
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"
32 #if wxUSE_DEBUGREPORT && wxUSE_XML
34 #include "wx/debugrpt.h"
37 #include "wx/filename.h"
39 #include "wx/mimetype.h"
41 #include "wx/statline.h"
42 #include "wx/stattext.h"
43 #include "wx/filedlg.h"
44 #include "wx/valtext.h"
46 // ----------------------------------------------------------------------------
47 // wxDumpPreviewDlg: simple class for showing ASCII preview of dump files
48 // ----------------------------------------------------------------------------
50 class wxDumpPreviewDlg
: public wxDialog
53 wxDumpPreviewDlg ( wxWindow
* parent
,
54 const wxString
& title
,
55 const wxString
& text
);
61 DECLARE_NO_COPY_CLASS ( wxDumpPreviewDlg
)
64 wxDumpPreviewDlg :: wxDumpPreviewDlg ( wxWindow
* parent
,
65 const wxString
& title
,
67 : wxDialog ( parent
, wxID_ANY
, title
,
68 wxDefaultPosition
, wxDefaultSize
,
69 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
74 // use wxTE_RICH2 style to avoid 64kB limit under MSW and display big files
75 // faster than with wxTE_RICH
76 m_text
= new wxTextCtrl ( this , wxID_ANY
, wxEmptyString
,
77 wxPoint ( 0 , 0 ), wxDefaultSize
,
82 m_text
-> SetValue ( text
);
84 // use fixed-width font
85 m_text
-> SetFont ( wxFont ( 12 , wxFONTFAMILY_TELETYPE
,
86 wxFONTSTYLE_NORMAL
, wxFONTWEIGHT_NORMAL
));
88 wxButton
* btnClose
= new wxButton ( this , wxID_CANCEL
, _ ( "Close" ));
94 wxSizer
* sizerTop
= new wxBoxSizer ( wxVERTICAL
),
95 * sizerBtns
= new wxBoxSizer ( wxHORIZONTAL
);
97 sizerBtns
-> Add ( btnClose
, 0 , 0 , 1 );
99 sizerTop
-> Add ( m_text
, 1 , wxEXPAND
);
100 sizerTop
-> Add ( sizerBtns
, 0 , wxALIGN_RIGHT
| wxTOP
| wxBOTTOM
| wxRIGHT
, 1 );
105 // make the text window bigger to show more contents of the file
106 sizerTop
-> SetItemMinSize ( m_text
, 600 , 300 );
115 // ----------------------------------------------------------------------------
116 // wxDumpOpenExternalDlg: choose a command for opening the given file
117 // ----------------------------------------------------------------------------
119 class wxDumpOpenExternalDlg
: public wxDialog
122 wxDumpOpenExternalDlg ( wxWindow
* parent
, const wxFileName
& filename
);
124 // return the command chosed by user to open this file
125 const wxString
& GetCommand () const { return m_command
; }
130 void OnBrowse ( wxCommandEvent
& event
);
132 DECLARE_EVENT_TABLE ()
133 DECLARE_NO_COPY_CLASS ( wxDumpOpenExternalDlg
)
136 BEGIN_EVENT_TABLE ( wxDumpOpenExternalDlg
, wxDialog
)
137 EVT_BUTTON ( wxID_MORE
, wxDumpOpenExternalDlg :: OnBrowse
)
141 wxDumpOpenExternalDlg :: wxDumpOpenExternalDlg ( wxWindow
* parent
,
142 const wxFileName
& filename
)
147 _ ( "Open file \" %s \" " ),
148 filename
. GetFullPath (). c_str ()
154 wxSizer
* sizerTop
= new wxBoxSizer ( wxVERTICAL
);
155 sizerTop
-> Add ( new wxStaticText ( this , wxID_ANY
,
158 _ ( "Enter command to open file \" %s \" :" ),
159 filename
. GetFullName (). c_str ()
161 wxSizerFlags (). Border ());
163 wxSizer
* sizerH
= new wxBoxSizer ( wxHORIZONTAL
);
165 wxTextCtrl
* command
= new wxTextCtrl
171 wxSize ( 250 , wxDefaultCoord
),
174 , wxTextValidator ( wxFILTER_NONE
, & m_command
)
178 wxSizerFlags ( 1 ). Align ( wxALIGN_CENTER_VERTICAL
));
179 wxButton
* browse
= new wxButton ( this , wxID_MORE
, wxT ( ">>" ),
180 wxDefaultPosition
, wxDefaultSize
,
183 wxSizerFlags ( 0 ). Align ( wxALIGN_CENTER_VERTICAL
). Border ( wxLEFT
));
185 sizerTop
-> Add ( sizerH
, wxSizerFlags ( 0 ). Expand (). Border ());
187 sizerTop
-> Add ( new wxStaticLine ( this ), wxSizerFlags (). Expand (). Border ());
189 sizerTop
-> Add ( CreateStdDialogButtonSizer ( wxOK
| wxCANCEL
),
190 wxSizerFlags (). Align ( wxALIGN_RIGHT
). Border ());
203 void wxDumpOpenExternalDlg :: OnBrowse ( wxCommandEvent
& )
205 wxFileName
fname ( m_command
);
206 wxFileDialog
dlg ( this ,
207 wxFileSelectorPromptStr
,
208 fname
. GetPathWithSep (),
211 , _ ( "Executable files (*.exe)|*.exe|All files (*.*)|*.*||" )
214 if ( dlg
. ShowModal () == wxID_OK
)
216 m_command
= dlg
. GetPath ();
217 TransferDataToWindow ();
222 // ----------------------------------------------------------------------------
223 // wxDebugReportDialog: class showing debug report to the user
224 // ----------------------------------------------------------------------------
226 class wxDebugReportDialog
: public wxDialog
229 wxDebugReportDialog ( wxDebugReport
& dbgrpt
);
231 virtual bool TransferDataToWindow ();
232 virtual bool TransferDataFromWindow ();
235 void OnView ( wxCommandEvent
& );
236 void OnViewUpdate ( wxUpdateUIEvent
& );
237 void OnOpen ( wxCommandEvent
& );
240 // small helper: add wxEXPAND and wxALL flags
241 static wxSizerFlags
SizerFlags ( int proportion
)
243 return wxSizerFlags ( proportion
). Expand (). Border ();
247 wxDebugReport
& m_dbgrpt
;
249 wxCheckListBox
* m_checklst
;
252 wxArrayString m_files
;
254 DECLARE_EVENT_TABLE ()
255 DECLARE_NO_COPY_CLASS ( wxDebugReportDialog
)
258 // ============================================================================
259 // wxDebugReportDialog implementation
260 // ============================================================================
262 BEGIN_EVENT_TABLE ( wxDebugReportDialog
, wxDialog
)
263 EVT_BUTTON ( wxID_VIEW_DETAILS
, wxDebugReportDialog :: OnView
)
264 EVT_UPDATE_UI ( wxID_VIEW_DETAILS
, wxDebugReportDialog :: OnViewUpdate
)
265 EVT_BUTTON ( wxID_OPEN
, wxDebugReportDialog :: OnOpen
)
266 EVT_UPDATE_UI ( wxID_OPEN
, wxDebugReportDialog :: OnViewUpdate
)
270 // ----------------------------------------------------------------------------
272 // ----------------------------------------------------------------------------
274 wxDebugReportDialog :: wxDebugReportDialog ( wxDebugReport
& dbgrpt
)
275 : wxDialog ( NULL
, wxID_ANY
,
276 wxString :: Format ( _ ( "Debug report \" %s \" " ),
277 dbgrpt
. GetReportName (). c_str ()),
280 wxDEFAULT_DIALOG_STYLE
| wxTHICK_FRAME
),
283 // upper part of the dialog: explanatory message
285 msg
<< _ ( "A debug report has been generated in the directory \n " )
287 << _T ( " \" " ) << dbgrpt
. GetDirectory () << _T ( " \"\n " )
289 << _ ( "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 " )
291 << _ ( "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 " )
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 report, please enter it here and it will be joined to it:" );
327 m_notes
= new wxTextCtrl ( this , wxID_ANY
, wxEmptyString
,
328 wxDefaultPosition
, wxDefaultSize
,
331 sizerNotes
-> Add ( CreateTextSizer ( msg
), flagsFixed
);
332 sizerNotes
-> Add ( m_notes
, flagsExpand
);
335 wxSizer
* sizerTop
= new wxBoxSizer ( wxVERTICAL
);
336 sizerTop
-> Add ( sizerPreview
, flagsExpand2
);
337 sizerTop
-> AddSpacer ( 5 );
338 sizerTop
-> Add ( sizerNotes
, flagsExpand
);
339 sizerTop
-> Add ( CreateStdDialogButtonSizer ( wxOK
| wxCANCEL
), flagsFixed
);
341 SetSizerAndFit ( sizerTop
);
346 // ----------------------------------------------------------------------------
348 // ----------------------------------------------------------------------------
350 bool wxDebugReportDialog :: TransferDataToWindow ()
352 // all files are included in the report by default
353 const size_t count
= m_dbgrpt
. GetFilesCount ();
354 for ( size_t n
= 0 ; n
< count
; n
++ )
358 if ( m_dbgrpt
. GetFile ( n
, & name
, & desc
) )
360 m_checklst
-> Append ( name
+ _T ( " (" ) + desc
+ _T ( ')' ));
361 m_checklst
-> Check ( n
);
370 bool wxDebugReportDialog :: TransferDataFromWindow ()
372 // any unchecked files should be removed from the report
373 const size_t count
= m_checklst
-> GetCount ();
374 for ( size_t n
= 0 ; n
< count
; n
++ )
376 if ( ! m_checklst
-> IsChecked ( n
) )
378 m_dbgrpt
. RemoveFile ( m_files
[ n
]);
382 // if the user entered any notes, add them to the report
383 const wxString notes
= m_notes
-> GetValue ();
384 if ( ! notes
. empty () )
386 // for now filename fixed, could make it configurable in the future...
387 m_dbgrpt
. AddText ( _T ( "notes.txt" ), notes
, _T ( "user notes" ));
393 // ----------------------------------------------------------------------------
395 // ----------------------------------------------------------------------------
397 void wxDebugReportDialog :: OnView ( wxCommandEvent
& )
399 const int sel
= m_checklst
-> GetSelection ();
400 wxCHECK_RET ( sel
!= - 1 , _T ( "invalid selection in OnView()" ) );
402 wxFileName
fn ( m_dbgrpt
. GetDirectory (), m_files
[ sel
]);
405 wxFFile
file ( fn
. GetFullPath ());
406 if ( file
. IsOpened () && file
. ReadAll (& str
) )
408 wxDumpPreviewDlg
dlg ( this , m_files
[ sel
], str
);
413 void wxDebugReportDialog :: OnOpen ( wxCommandEvent
& )
415 const int sel
= m_checklst
-> GetSelection ();
416 wxCHECK_RET ( sel
!= - 1 , _T ( "invalid selection in OnOpen()" ) );
418 wxFileName
fn ( m_dbgrpt
. GetDirectory (), m_files
[ sel
]);
420 // try to get the command to open this kind of files ourselves
424 ft
= wxTheMimeTypesManager
-> GetFileTypeFromExtension ( fn
. GetExt ());
427 command
= ft
-> GetOpenCommand ( fn
. GetFullPath ());
430 #endif // wxUSE_MIMETYPE
432 // if we couldn't, ask the user
433 if ( command
. empty () )
435 wxDumpOpenExternalDlg
dlg ( this , fn
);
436 if ( dlg
. ShowModal () == wxID_OK
)
438 // get the command chosen by the user and append file name to it
440 // if we don't have place marker for file name in the command...
441 wxString cmd
= dlg
. GetCommand ();
445 if ( cmd
. find ( _T ( '%' )) != wxString :: npos
)
447 command
= wxFileType :: ExpandCommand ( cmd
, fn
. GetFullPath ());
450 #endif // wxUSE_MIMETYPE
452 // append the file name to the end
453 command
<< cmd
<< _T ( " \" " ) << fn
. GetFullPath () << _T ( '"' );
459 if ( ! command
. empty () )
460 :: wxExecute ( command
);
463 void wxDebugReportDialog :: OnViewUpdate ( wxUpdateUIEvent
& event
)
465 int sel
= m_checklst
-> GetSelection ();
468 wxFileName
fn ( m_dbgrpt
. GetDirectory (), m_files
[ sel
]);
469 event
. Enable ( fn
. FileExists ());
476 // ============================================================================
477 // wxDebugReportPreviewStd implementation
478 // ============================================================================
480 bool wxDebugReportPreviewStd :: Show ( wxDebugReport
& dbgrpt
) const
482 if ( ! dbgrpt
. GetFilesCount () )
485 wxDebugReportDialog
dlg ( dbgrpt
);
487 return dlg
. ShowModal () == wxID_OK
&& dbgrpt
. GetFilesCount () != 0 ;
490 #endif // wxUSE_DEBUGREPORT