excludedlg.cpp

00001 
00002 // Name:        excludedlg.cpp
00003 // Purpose:     wxPackageExcludeDialog
00004 // Author:      Francesco Montorsi
00005 // Modified by:
00006 // Created:     26/12/2006 23:17:17
00007 // RCS-ID:      $Id: excludedlg.cpp,v 1.6 2007/01/01 20:06:20 frm Exp $
00008 // Copyright:   (c) 2006 Francesco Montorsi
00009 // Licence:     wxWidgets license
00011 
00012 
00013 // For compilers that support precompilation, includes "wx/wx.h".
00014 #include "wx/wxprec.h"
00015 
00016 #ifdef __BORLANDC__
00017 #pragma hdrstop
00018 #endif
00019 
00020 #ifndef WX_PRECOMP
00021 #include "wx/wx.h"
00022 #endif
00023 
00024 #include <wx/filename.h>
00025 #include <wx/dir.h>
00026 
00027 #include "guipkg/excludedlg.h"
00028 #include "wx/checkedlistctrl.h"
00029 
00030 #include "guipkg/proppanel.h"   // for IsSelected() utility
00031 
00032 
00033 // ----------------------------------------------------------------------------
00034 // wxPackageExcludeDlg
00035 // ----------------------------------------------------------------------------
00036 
00037 IMPLEMENT_DYNAMIC_CLASS( wxPackageExcludeDlg, wxDialog )
00038 BEGIN_EVENT_TABLE( wxPackageExcludeDlg, wxDialog )
00039     EVT_TEXT( ID_EXCLUDEDLG_PATTERN, wxPackageExcludeDlg::OnText )
00040 END_EVENT_TABLE()
00041 
00042 wxPackageExcludeDlg::wxPackageExcludeDlg( )
00043 {
00044 }
00045 
00046 wxPackageExcludeDlg::wxPackageExcludeDlg( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
00047 {
00048     Create(parent, id, caption, pos, size, style);
00049 }
00050 
00051 bool wxPackageExcludeDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
00052 {
00054     m_pChoiceBook = NULL;
00055     m_pFileList = NULL;
00056     m_pDirList = NULL;
00057     m_pPattern = NULL;
00058     m_pPatternList = NULL;
00060 
00061     SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS);
00062     wxDialog::Create( parent, id, caption, pos, size, style );
00063 
00064     CreateControls();
00065     if (GetSizer())
00066     {
00067         GetSizer()->SetSizeHints(this);
00068 
00069         // set a min size bigger than default minsize
00070         SetMinSize(GetMinSize().Scale(1.2, 1.6));
00071     }
00072     CentreOnScreen();
00073 
00074     return true;
00075 }
00076 
00077 void wxPackageExcludeDlg::CreateControls()
00078 {    
00080     wxPackageExcludeDlg* itemDialog1 = this;
00081 
00082     wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
00083     itemDialog1->SetSizer(itemBoxSizer2);
00084 
00085     m_pChoiceBook = new wxChoicebook( itemDialog1, ID_EXCLUDEDLG_CHOICEBOOK, wxDefaultPosition, wxDefaultSize, wxCHB_DEFAULT );
00086 
00087     wxPanel* itemPanel4 = new wxPanel( m_pChoiceBook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
00088     wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxVERTICAL);
00089     itemPanel4->SetSizer(itemBoxSizer5);
00090 
00091     wxStaticText* itemStaticText6 = new wxStaticText( itemPanel4, wxID_STATIC, _("Select one or more files and then click OK to exclude them from the package:"), wxDefaultPosition, wxDefaultSize, 0 );
00092     itemBoxSizer5->Add(itemStaticText6, 0, wxALIGN_LEFT|wxALL|wxADJUST_MINSIZE, 5);
00093 
00094     m_pFileList = new wxListCtrl( itemPanel4, ID_EXCLUDEDLG_FILES, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxLC_REPORT|wxLC_HRULES  );
00095     itemBoxSizer5->Add(m_pFileList, 1, wxGROW|wxALL, 5);
00096 
00097     m_pChoiceBook->AddPage(itemPanel4, _("Exclude file(s)"));
00098 
00099     wxPanel* itemPanel8 = new wxPanel( m_pChoiceBook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
00100     wxBoxSizer* itemBoxSizer9 = new wxBoxSizer(wxVERTICAL);
00101     itemPanel8->SetSizer(itemBoxSizer9);
00102 
00103     wxStaticText* itemStaticText10 = new wxStaticText( itemPanel8, wxID_STATIC, _("Select one or more directories and then click OK to exclude them from the package:"), wxDefaultPosition, wxDefaultSize, 0 );
00104     itemBoxSizer9->Add(itemStaticText10, 0, wxALIGN_LEFT|wxALL|wxADJUST_MINSIZE, 5);
00105 
00106     m_pDirList = new wxListCtrl( itemPanel8, ID_EXCLUDEDLG_DIRECTORIES, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxLC_REPORT );
00107     itemBoxSizer9->Add(m_pDirList, 1, wxGROW|wxALL, 5);
00108 
00109     m_pChoiceBook->AddPage(itemPanel8, _("Exclude directory(s)"));
00110 
00111     wxPanel* itemPanel12 = new wxPanel( m_pChoiceBook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
00112     wxBoxSizer* itemBoxSizer13 = new wxBoxSizer(wxVERTICAL);
00113     itemPanel12->SetSizer(itemBoxSizer13);
00114 
00115     wxBoxSizer* itemBoxSizer14 = new wxBoxSizer(wxHORIZONTAL);
00116     itemBoxSizer13->Add(itemBoxSizer14, 0, wxGROW, 5);
00117     wxStaticText* itemStaticText15 = new wxStaticText( itemPanel12, wxID_STATIC, _("Pattern:"), wxDefaultPosition, wxDefaultSize, 0 );
00118     itemBoxSizer14->Add(itemStaticText15, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
00119 
00120     m_pPattern = new wxTextCtrl( itemPanel12, ID_EXCLUDEDLG_PATTERN, _T(""), wxDefaultPosition, wxDefaultSize, 0 );
00121     itemBoxSizer14->Add(m_pPattern, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
00122 
00123     itemBoxSizer13->Add(5, 5, 0, wxALIGN_CENTER_HORIZONTAL|wxLEFT|wxRIGHT, 5);
00124 
00125     wxStaticText* itemStaticText18 = new wxStaticText( itemPanel12, wxID_STATIC, _("Files matched by the pattern:"), wxDefaultPosition, wxDefaultSize, 0 );
00126     itemBoxSizer13->Add(itemStaticText18, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5);
00127 
00128     m_pPatternList = new wxListCtrl( itemPanel12, ID_EXCLUDEDLG_PATTERN_LIST, wxDefaultPosition, wxDefaultSize, wxLC_REPORT );
00129     itemBoxSizer13->Add(m_pPatternList, 1, wxGROW|wxALL, 5);
00130 
00131     m_pChoiceBook->AddPage(itemPanel12, _("Exclude files with a pattern"));
00132 
00133     itemBoxSizer2->Add(m_pChoiceBook, 1, wxGROW|wxALL, 5);
00134 
00135     wxStdDialogButtonSizer* itemStdDialogButtonSizer20 = new wxStdDialogButtonSizer;
00136 
00137     itemBoxSizer2->Add(itemStdDialogButtonSizer20, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
00138     wxButton* itemButton21 = new wxButton( itemDialog1, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
00139     itemStdDialogButtonSizer20->AddButton(itemButton21);
00140 
00141     wxButton* itemButton22 = new wxButton( itemDialog1, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
00142     itemStdDialogButtonSizer20->AddButton(itemButton22);
00143 
00144     itemStdDialogButtonSizer20->Realize();
00145 
00147 
00148     // file list
00149     m_pFileList->InsertColumn(0, wxT("File path"), wxLIST_FORMAT_LEFT, 250);
00150     m_pFileList->InsertColumn(1, wxT("Size"));
00151 
00152     // dir list
00153     m_pDirList->InsertColumn(0, wxT("Directory path"), wxLIST_FORMAT_LEFT, 250);
00154     m_pDirList->InsertColumn(1, wxT("Size"));
00155 
00156     // pattern list
00157     m_pPatternList->InsertColumn(0, wxT("File path"), wxLIST_FORMAT_LEFT, 250);
00158     m_pPatternList->InsertColumn(1, wxT("Size"));
00159 }
00160 
00161 bool wxPackageExcludeDlg::ShowToolTips()
00162 {
00163     return true;
00164 }
00165 
00166 #define ADD_TO_LISTCTRL(list, prefix, arr, getsize)                 \
00167     unsigned long size, l = prefix.Len();                           \
00168     if (prefix.Last() != wxFileName::GetPathSeparator()) l++;       \
00169     for (size_t i=0; i<arr.GetCount(); i++)                         \
00170     {                                                               \
00171         wxULongLong sz = getsize;                                   \
00172         wxString szstr = wxFileName::GetHumanReadableSize(sz);      \
00173         long szl = sz == wxInvalidSize ? -1 : sz.ToULong();         \
00174                                                                     \
00175         /* add i-th file */                                         \
00176         list->InsertItem(i, arr[i].Right(arr[i].Len() - l));        \
00177         list->SetItem(i, 1, szstr);                                 \
00178         list->SetItemData(i, szl);                                  \
00179     }
00180 
00181 
00182 void wxPackageExcludeDlg::SetFileList(const wxString &prefix, 
00183                                       const wxArrayString &arr)
00184 {
00185     ADD_TO_LISTCTRL(m_pFileList, prefix, arr, 
00186                     wxFileName::GetSize(arr[i]));
00187 }
00188 
00189 void wxPackageExcludeDlg::SetDirList(const wxString &prefix, 
00190                                      const wxArrayString &arr)
00191 {
00192     ADD_TO_LISTCTRL(m_pDirList, prefix, arr, 
00193                     wxDir::GetTotalSize(arr[i]));
00194 }
00195 
00196 wxArrayString wxPackageExcludeDlg::GetSelectedFiles() const
00197 {
00198     wxArrayString ret;
00199     for (int i=0; i<m_pFileList->GetItemCount(); i++)
00200         if (IsSelected(m_pFileList, i))
00201             ret.Add(m_pFileList->GetItemText(i));
00202     return ret;
00203 }
00204 
00205 wxArrayString wxPackageExcludeDlg::GetSelectedDirs() const
00206 {
00207     wxArrayString ret;
00208     for (int i=0; i<m_pDirList->GetItemCount(); i++)
00209         if (IsSelected(m_pDirList, i))
00210             ret.Add(m_pDirList->GetItemText(i));
00211     return ret;
00212 }
00213 
00214 wxArrayString wxPackageExcludeDlg::GetMatchingFiles(wxArrayLong *sz) const
00215 {
00216     // see which files of m_pFileList matches the user pattern
00217     wxString pattern = GetPattern();
00218     wxArrayString ret;
00219     for (int i=0; i<m_pFileList->GetItemCount(); i++)
00220     {
00221         wxString curr = m_pFileList->GetItemText(i);
00222         if (wxMatchWild(pattern, curr, false))
00223         {
00224             ret.Add(curr);
00225             if (sz)
00226                 sz->Add(m_pFileList->GetItemData(i));
00227         }
00228     }
00229 
00230     return ret;
00231 }
00232 
00233 
00234 // ----------------------------------------------------------------------------
00235 // wxPackageExcludeDlg - event handlers
00236 // ----------------------------------------------------------------------------
00237 
00238 void wxPackageExcludeDlg::OnText(wxCommandEvent& event)
00239 {
00240     // update the file list of the matching files
00241     wxArrayLong sz;
00242     wxArrayString files = GetMatchingFiles(&sz);
00243     wxString pattern = GetPattern();
00244 
00245     // reset the contents of the list control
00246     m_pPatternList->DeleteAllItems();
00247     for (size_t i=0; i<files.GetCount(); i++)
00248     {
00249         m_pPatternList->InsertItem(i, files[i]);
00250         m_pPatternList->SetItem(i, 1, 
00251             wxFileName::GetHumanReadableSize(wxULongLong(sz[i])));
00252     }
00253 }
00254 

Generated on Thu Feb 1 22:14:30 2007 for wxWidgets Package Manager by  doxygen 1.5.1-p1