]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/dbgrptg.cpp
efb75d241b0c6c3d9d73433ad15a999cbab2a68d
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"
47 #include "wx/evtloop.h" // for SetCriticalWindow()
50 // ----------------------------------------------------------------------------
51 // wxDumpPreviewDlg: simple class for showing ASCII preview of dump files
52 // ----------------------------------------------------------------------------
54 class wxDumpPreviewDlg
: public wxDialog
57 wxDumpPreviewDlg ( wxWindow
* parent
,
58 const wxString
& title
,
59 const wxString
& text
);
65 DECLARE_NO_COPY_CLASS ( wxDumpPreviewDlg
)
68 wxDumpPreviewDlg :: wxDumpPreviewDlg ( wxWindow
* parent
,
69 const wxString
& title
,
71 : wxDialog ( parent
, wxID_ANY
, title
,
72 wxDefaultPosition
, wxDefaultSize
,
73 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
78 // use wxTE_RICH2 style to avoid 64kB limit under MSW and display big files
79 // faster than with wxTE_RICH
80 m_text
= new wxTextCtrl ( this , wxID_ANY
, wxEmptyString
,
81 wxPoint ( 0 , 0 ), wxDefaultSize
,
86 m_text
-> SetValue ( text
);
88 // use fixed-width font
89 m_text
-> SetFont ( wxFont ( 12 , wxFONTFAMILY_TELETYPE
,
90 wxFONTSTYLE_NORMAL
, wxFONTWEIGHT_NORMAL
));
92 wxButton
* btnClose
= new wxButton ( this , wxID_CANCEL
, _ ( "Close" ));
98 wxSizer
* sizerTop
= new wxBoxSizer ( wxVERTICAL
),
99 * sizerBtns
= new wxBoxSizer ( wxHORIZONTAL
);
101 sizerBtns
-> Add ( btnClose
, 0 , 0 , 1 );
103 sizerTop
-> Add ( m_text
, 1 , wxEXPAND
);
104 sizerTop
-> Add ( sizerBtns
, 0 , wxALIGN_RIGHT
| wxTOP
| wxBOTTOM
| wxRIGHT
, 1 );
109 // make the text window bigger to show more contents of the file
110 sizerTop
-> SetItemMinSize ( m_text
, 600 , 300 );
119 // ----------------------------------------------------------------------------
120 // wxDumpOpenExternalDlg: choose a command for opening the given file
121 // ----------------------------------------------------------------------------
123 class wxDumpOpenExternalDlg
: public wxDialog
126 wxDumpOpenExternalDlg ( wxWindow
* parent
, const wxFileName
& filename
);
128 // return the command chosed by user to open this file
129 const wxString
& GetCommand () const { return m_command
; }
134 void OnBrowse ( wxCommandEvent
& event
);
136 DECLARE_EVENT_TABLE ()
137 DECLARE_NO_COPY_CLASS ( wxDumpOpenExternalDlg
)
140 BEGIN_EVENT_TABLE ( wxDumpOpenExternalDlg
, wxDialog
)
141 EVT_BUTTON ( wxID_MORE
, wxDumpOpenExternalDlg :: OnBrowse
)
145 wxDumpOpenExternalDlg :: wxDumpOpenExternalDlg ( wxWindow
* parent
,
146 const wxFileName
& filename
)
151 _ ( "Open file \" %s \" " ),
152 filename
. GetFullPath (). c_str ()
158 wxSizer
* sizerTop
= new wxBoxSizer ( wxVERTICAL
);
159 sizerTop
-> Add ( new wxStaticText ( this , wxID_ANY
,
162 _ ( "Enter command to open file \" %s \" :" ),
163 filename
. GetFullName (). c_str ()
165 wxSizerFlags (). Border ());
167 wxSizer
* sizerH
= new wxBoxSizer ( wxHORIZONTAL
);
169 wxTextCtrl
* command
= new wxTextCtrl
175 wxSize ( 250 , wxDefaultCoord
),
178 , wxTextValidator ( wxFILTER_NONE
, & m_command
)
182 wxSizerFlags ( 1 ). Align ( wxALIGN_CENTER_VERTICAL
));
183 wxButton
* browse
= new wxButton ( this , wxID_MORE
, wxT ( ">>" ),
184 wxDefaultPosition
, wxDefaultSize
,
187 wxSizerFlags ( 0 ). Align ( wxALIGN_CENTER_VERTICAL
). Border ( wxLEFT
));
189 sizerTop
-> Add ( sizerH
, wxSizerFlags ( 0 ). Expand (). Border ());
191 sizerTop
-> Add ( new wxStaticLine ( this ), wxSizerFlags (). Expand (). Border ());
193 sizerTop
-> Add ( CreateStdDialogButtonSizer ( wxOK
| wxCANCEL
),
194 wxSizerFlags (). Align ( wxALIGN_RIGHT
). Border ());
207 void wxDumpOpenExternalDlg :: OnBrowse ( wxCommandEvent
& )
209 wxFileName
fname ( m_command
);
210 wxFileDialog
dlg ( this ,
211 wxFileSelectorPromptStr
,
212 fname
. GetPathWithSep (),
215 , _ ( "Executable files (*.exe)|*.exe|All files (*.*)|*.*||" )
218 if ( dlg
. ShowModal () == wxID_OK
)
220 m_command
= dlg
. GetPath ();
221 TransferDataToWindow ();
226 // ----------------------------------------------------------------------------
227 // wxDebugReportDialog: class showing debug report to the user
228 // ----------------------------------------------------------------------------
230 class wxDebugReportDialog
: public wxDialog
233 wxDebugReportDialog ( wxDebugReport
& dbgrpt
);
235 virtual bool TransferDataToWindow ();
236 virtual bool TransferDataFromWindow ();
239 void OnView ( wxCommandEvent
& );
240 void OnViewUpdate ( wxUpdateUIEvent
& );
241 void OnOpen ( wxCommandEvent
& );
244 // small helper: add wxEXPAND and wxALL flags
245 static wxSizerFlags
SizerFlags ( int proportion
)
247 return wxSizerFlags ( proportion
). Expand (). Border ();
251 wxDebugReport
& m_dbgrpt
;
253 wxCheckListBox
* m_checklst
;
256 wxArrayString m_files
;
258 DECLARE_EVENT_TABLE ()
259 DECLARE_NO_COPY_CLASS ( wxDebugReportDialog
)
262 // ============================================================================
263 // wxDebugReportDialog implementation
264 // ============================================================================
266 BEGIN_EVENT_TABLE ( wxDebugReportDialog
, wxDialog
)
267 EVT_BUTTON ( wxID_VIEW_DETAILS
, wxDebugReportDialog :: OnView
)
268 EVT_UPDATE_UI ( wxID_VIEW_DETAILS
, wxDebugReportDialog :: OnViewUpdate
)
269 EVT_BUTTON ( wxID_OPEN
, wxDebugReportDialog :: OnOpen
)
270 EVT_UPDATE_UI ( wxID_OPEN
, wxDebugReportDialog :: OnViewUpdate
)
274 // ----------------------------------------------------------------------------
276 // ----------------------------------------------------------------------------
278 wxDebugReportDialog :: wxDebugReportDialog ( wxDebugReport
& dbgrpt
)
279 : wxDialog ( NULL
, wxID_ANY
,
280 wxString :: Format ( _ ( "Debug report \" %s \" " ),
281 dbgrpt
. GetReportName (). c_str ()),
284 wxDEFAULT_DIALOG_STYLE
| wxTHICK_FRAME
),
287 // upper part of the dialog: explanatory message
289 msg
<< _ ( "A debug report has been generated in the directory \n " )
291 << _T ( " \" " ) << dbgrpt
. GetDirectory () << _T ( " \"\n " )
293 << _ ( "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 " )
295 << _ ( "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 " )
297 << _ ( " Thank you and we're sorry for the inconvenience! \n " )
298 << _T ( " \n\n " ); // just some white space to separate from other stuff
300 const wxSizerFlags
flagsFixed ( SizerFlags ( 0 ));
301 const wxSizerFlags
flagsExpand ( SizerFlags ( 1 ));
302 const wxSizerFlags
flagsExpand2 ( SizerFlags ( 2 ));
304 wxSizer
* sizerPreview
=
305 new wxStaticBoxSizer ( wxVERTICAL
, this , _ ( "&Debug report preview:" ));
306 sizerPreview
-> Add ( CreateTextSizer ( msg
), SizerFlags ( 0 ). Centre ());
308 // ... and the list of files in this debug report with buttons to view them
309 wxSizer
* sizerFileBtns
= new wxBoxSizer ( wxVERTICAL
);
310 sizerFileBtns
-> AddStretchSpacer ( 1 );
311 sizerFileBtns
-> Add ( new wxButton ( this , wxID_VIEW_DETAILS
, _T ( "&View..." )),
312 wxSizerFlags (). Border ( wxBOTTOM
));
313 sizerFileBtns
-> Add ( new wxButton ( this , wxID_OPEN
, _T ( "&Open..." )),
314 wxSizerFlags (). Border ( wxTOP
));
315 sizerFileBtns
-> AddStretchSpacer ( 1 );
317 m_checklst
= new wxCheckListBox ( this , wxID_ANY
);
319 wxSizer
* sizerFiles
= new wxBoxSizer ( wxHORIZONTAL
);
320 sizerFiles
-> Add ( m_checklst
, flagsExpand
);
321 sizerFiles
-> Add ( sizerFileBtns
, flagsFixed
);
323 sizerPreview
-> Add ( sizerFiles
, flagsExpand2
);
326 // lower part of the dialog: notes field
327 wxSizer
* sizerNotes
= new wxStaticBoxSizer ( wxVERTICAL
, this , _ ( "&Notes:" ));
329 msg
= _ ( "If you have any additional information pertaining to this bug \n report, please enter it here and it will be joined to it:" );
331 m_notes
= new wxTextCtrl ( this , wxID_ANY
, wxEmptyString
,
332 wxDefaultPosition
, wxDefaultSize
,
335 sizerNotes
-> Add ( CreateTextSizer ( msg
), flagsFixed
);
336 sizerNotes
-> Add ( m_notes
, flagsExpand
);
339 wxSizer
* sizerTop
= new wxBoxSizer ( wxVERTICAL
);
340 sizerTop
-> Add ( sizerPreview
, flagsExpand2
);
341 sizerTop
-> AddSpacer ( 5 );
342 sizerTop
-> Add ( sizerNotes
, flagsExpand
);
343 sizerTop
-> Add ( CreateStdDialogButtonSizer ( wxOK
| wxCANCEL
), flagsFixed
);
345 SetSizerAndFit ( sizerTop
);
350 // ----------------------------------------------------------------------------
352 // ----------------------------------------------------------------------------
354 bool wxDebugReportDialog :: TransferDataToWindow ()
356 // all files are included in the report by default
357 const size_t count
= m_dbgrpt
. GetFilesCount ();
358 for ( size_t n
= 0 ; n
< count
; n
++ )
362 if ( m_dbgrpt
. GetFile ( n
, & name
, & desc
) )
364 m_checklst
-> Append ( name
+ _T ( " (" ) + desc
+ _T ( ')' ));
365 m_checklst
-> Check ( n
);
374 bool wxDebugReportDialog :: TransferDataFromWindow ()
376 // any unchecked files should be removed from the report
377 const size_t count
= m_checklst
-> GetCount ();
378 for ( size_t n
= 0 ; n
< count
; n
++ )
380 if ( ! m_checklst
-> IsChecked ( n
) )
382 m_dbgrpt
. RemoveFile ( m_files
[ n
]);
386 // if the user entered any notes, add them to the report
387 const wxString notes
= m_notes
-> GetValue ();
388 if ( ! notes
. empty () )
390 // for now filename fixed, could make it configurable in the future...
391 m_dbgrpt
. AddText ( _T ( "notes.txt" ), notes
, _T ( "user notes" ));
397 // ----------------------------------------------------------------------------
399 // ----------------------------------------------------------------------------
401 void wxDebugReportDialog :: OnView ( wxCommandEvent
& )
403 const int sel
= m_checklst
-> GetSelection ();
404 wxCHECK_RET ( sel
!= - 1 , _T ( "invalid selection in OnView()" ) );
406 wxFileName
fn ( m_dbgrpt
. GetDirectory (), m_files
[ sel
]);
409 wxFFile
file ( fn
. GetFullPath ());
410 if ( file
. IsOpened () && file
. ReadAll (& str
) )
412 wxDumpPreviewDlg
dlg ( this , m_files
[ sel
], str
);
417 void wxDebugReportDialog :: OnOpen ( wxCommandEvent
& )
419 const int sel
= m_checklst
-> GetSelection ();
420 wxCHECK_RET ( sel
!= - 1 , _T ( "invalid selection in OnOpen()" ) );
422 wxFileName
fn ( m_dbgrpt
. GetDirectory (), m_files
[ sel
]);
424 // try to get the command to open this kind of files ourselves
428 ft
= wxTheMimeTypesManager
-> GetFileTypeFromExtension ( fn
. GetExt ());
431 command
= ft
-> GetOpenCommand ( fn
. GetFullPath ());
434 #endif // wxUSE_MIMETYPE
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 ();
449 if ( cmd
. find ( _T ( '%' )) != wxString :: npos
)
451 command
= wxFileType :: ExpandCommand ( cmd
, fn
. GetFullPath ());
454 #endif // wxUSE_MIMETYPE
456 // append the file name to the end
457 command
<< cmd
<< _T ( " \" " ) << fn
. GetFullPath () << _T ( '"' );
463 if ( ! command
. empty () )
464 :: wxExecute ( command
);
467 void wxDebugReportDialog :: OnViewUpdate ( wxUpdateUIEvent
& event
)
469 int sel
= m_checklst
-> GetSelection ();
472 wxFileName
fn ( m_dbgrpt
. GetDirectory (), m_files
[ sel
]);
473 event
. Enable ( fn
. FileExists ());
480 // ============================================================================
481 // wxDebugReportPreviewStd implementation
482 // ============================================================================
484 bool wxDebugReportPreviewStd :: Show ( wxDebugReport
& dbgrpt
) const
486 if ( ! dbgrpt
. GetFilesCount () )
489 wxDebugReportDialog
dlg ( dbgrpt
);
492 // before entering the event loop (from ShowModal()), block the event
493 // handling for all other windows as this could result in more crashes
494 wxEventLoop :: SetCriticalWindow (& dlg
);
497 return dlg
. ShowModal () == wxID_OK
&& dbgrpt
. GetFilesCount () != 0 ;
500 #endif // wxUSE_DEBUGREPORT