1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002-2011 Drager
6 //
7 // Any parts of this program derived from the xMule, lMule or eMule project,
8 // or contributed by third-party developers are copyrighted by their
9 // respective authors.
10 //
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
15 //
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
24 //
25 
26 #include <wx/dialog.h>		// Needed for wxDialog	// Do_not_auto_remove
27 #include <wx/sizer.h>		// Needed for wxBoxSizer
28 #include <wx/file.h>		// Needed for wxFile
29 #include <wx/log.h>		// Needed for wxLogSysError
30 #include <wx/textctrl.h>
31 
32 #include "EditServerListDlg.h"	// Interface declarations
33 
BEGIN_EVENT_TABLE(EditServerListDlg,wxDialog)34 BEGIN_EVENT_TABLE(EditServerListDlg, wxDialog)
35     EVT_BUTTON(wxID_OK, EditServerListDlg::OnOK)
36 END_EVENT_TABLE()
37 
38 
39 EditServerListDlg::EditServerListDlg(wxWindow *parent,
40                                      const wxString& caption,
41                                      const wxString& message,
42 				     const wxString& filename) : wxDialog(parent, -1, caption,
43 								      wxDefaultPosition, wxSize(400,200),
44 								      wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
45 {
46   m_file = filename;
47 
48   wxBeginBusyCursor();
49 
50   wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
51 
52   topsizer->Add( CreateTextSizer( message ), 0, wxALL, 10 );
53 
54   m_textctrl = new wxTextCtrl(this, -1, wxEmptyString,
55 			      wxDefaultPosition,
56 			      wxDefaultSize,
57 			      wxTE_MULTILINE);
58   topsizer->Add( m_textctrl, 1, wxEXPAND | wxLEFT|wxRIGHT, 15 );
59 
60   topsizer->Add( CreateButtonSizer( wxOK | wxCANCEL ), 0, wxCENTRE | wxALL, 10 );
61 
62   SetAutoLayout( TRUE );
63   SetSizer( topsizer );
64 
65   Centre( wxBOTH );
66 
67   if (wxFile::Exists(filename))
68 	m_textctrl->LoadFile(filename);
69 
70   m_textctrl->SetFocus();
71 
72   wxEndBusyCursor();
73 }
74 
~EditServerListDlg()75 EditServerListDlg::~EditServerListDlg()
76 {
77 }
78 
OnOK(wxCommandEvent & WXUNUSED (event))79 void EditServerListDlg::OnOK(wxCommandEvent& WXUNUSED(event) )
80 {
81 	if (m_textctrl->SaveFile(m_file))
82 		EndModal(1);
83 	else
84 		wxLogSysError(wxT("Can't write to file '") +  m_file + wxT("'"));
85 }
86 // File_checked_for_headers
87