File: TStoreAllDialog.cpp

package info (click to toggle)
gentle 1.9+cvs20100605+dfsg1-5
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 12,224 kB
  • ctags: 6,214
  • sloc: cpp: 41,569; ansic: 3,978; sh: 1,420; makefile: 243
file content (144 lines) | stat: -rw-r--r-- 5,138 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "TStoreAllDialog.h"

BEGIN_EVENT_TABLE(TStoreAllDialog, wxDialog )
    EVT_BUTTON(wxID_OK,TStoreAllDialog::OnOK)
    EVT_BUTTON(SAD_ALL,TStoreAllDialog::OnAll)
    EVT_BUTTON(SAD_NONE,TStoreAllDialog::OnNone)
    EVT_BUTTON(SAD_INVERT,TStoreAllDialog::OnInvert)
//    EVT_CHECKLISTBOX(SAD_LIST,TStoreAllDialog::OnListChange)
END_EVENT_TABLE()

TStoreAllDialog::TStoreAllDialog ( wxWindow *_parent , const wxString& title )
    : wxDialog ( _parent , -1 , title )
{
   wxSize size ( 400 , 300 ) ;
   SetSize ( size ) ;

   wxSizer *v0 = new wxBoxSizer ( wxVERTICAL ) ;
   wxSizer *h0 = new wxBoxSizer ( wxHORIZONTAL ) ;
   wxSizer *h1 = new wxBoxSizer ( wxHORIZONTAL ) ;
   wxSizer *h2 = new wxBoxSizer ( wxHORIZONTAL ) ;
   wxSizer *h3 = new wxBoxSizer ( wxHORIZONTAL ) ;
   
   list = new wxCheckListBox ( this , SAD_LIST ) ;
   database = new wxChoice ( this , -1 ) ;

   wxButton *b_all = new wxButton ( this , SAD_ALL , txt("b_all") ) ;
   wxButton *b_none = new wxButton ( this , SAD_NONE , txt("b_none") ) ;
   wxButton *b_invert = new wxButton ( this , SAD_INVERT , txt("b_invert") ) ;
   wxButton *b_ok = new wxButton ( this , wxID_OK , txt("b_ok") ) ;
   wxButton *b_cancel = new wxButton ( this , wxID_CANCEL , txt("b_cancel") ) ;
   
   force_db = new wxCheckBox ( this , -1 , txt("t_sad_force_database") ) ;
   auto_overwrite = new wxCheckBox ( this , -1 , txt("t_sad_auto_overwrite") ) ;

   h0->Add ( b_all , 1 , wxEXPAND|wxALL , 2 ) ;
   h0->Add ( b_none , 1 , wxEXPAND|wxALL , 2 ) ;
   h0->Add ( b_invert , 1 , wxEXPAND|wxALL , 2 ) ;
   
   h1->Add ( b_ok , 1 , wxEXPAND|wxALL , 2 ) ;
   h1->Add ( b_cancel , 1 , wxEXPAND|wxALL , 2 ) ;
   
   h2->Add ( auto_overwrite , 0 , wxEXPAND|wxALL , 2 ) ;   
   h2->Add ( force_db , 0 , wxEXPAND|wxALL , 2 ) ;

   h3->Add ( new wxStaticText ( this , -1 , _T("t_default_database") ) , 0 , wxEXPAND|wxALL , 2 ) ;
   h3->Add ( database , 1 , wxEXPAND|wxALL , 2 ) ;
   
   v0->Add ( list , 1 , wxEXPAND|wxALL , 2 ) ;
   v0->Add ( h3 , 0 , wxEXPAND|wxALL , 2 ) ;
   v0->Add ( h2 , 0 , wxEXPAND|wxALL , 2 ) ;
   v0->Add ( h0 , 0 , wxEXPAND|wxALL , 2 ) ;
   v0->Add ( h1 , 0 , wxEXPAND|wxALL , 2 ) ;
   
   PopulateList() ;
   database->SetStringSelection ( defdb ) ;
   auto_overwrite->SetValue ( true ) ;
   b_ok->SetDefault() ;

   SetSizer ( v0 ) ;
   v0->Fit ( this ) ;
}

TStoreAllDialog::~TStoreAllDialog ()
{
}

void TStoreAllDialog::PopulateList ()
{
     unsigned int a ;
     children.clear() ;
     for ( a = 0 ; a < myapp()->frame->children.GetCount() ; a++ )
     {
         wxString def = myapp()->frame->children[a]->def ;
         if ( def != _T("ABIviewer") && 
              def != _T("dna") && 
              def != _T("alignment") && 
              def != _T("AminoAcids") ) continue ;
         if ( !myapp()->frame->children[a]->vec ) continue ;
         
         int pos = list->Append ( myapp()->frame->children[a]->getName() ) ;
         children.push_back ( myapp()->frame->children[a] ) ;
         if ( def == _T("dna") && !myapp()->frame->children[a]->HasUndoData() ) continue ;
         list->Check ( pos ) ;
     }

    defdb = myapp()->frame->LS->getDatabaseList ( db_name , db_file ) ;
    database->Clear () ;
    for ( a = 0 ; a < db_name.GetCount() ; a++ )
        database->Append ( db_name[a] ) ;
}

void TStoreAllDialog::OnOK ( wxCommandEvent &ev )
{
     unsigned int a ;
     wxString sel_db = database->GetStringSelection() ;
     for ( a = 0 ; a < list->GetCount() ; a++ )
     {
         if ( !list->IsChecked ( a ) ) continue ; // Entry not checked
         
         wxString name , db ;
         name = children[a]->getName() ;
         if ( children[a]->vec && !children[a]->vec->getDatabase().IsEmpty() ) db = children[a]->vec->getDatabase() ;
         else db = sel_db ;
         if ( force_db->GetValue() ) db = sel_db ;

         TManageDatabaseDialog mdd ( children[a] , _T("") , ACTION_MODE_SAVE|ACTION_MODE_STARTUP , children[a]->vec ) ;
         mdd.silent_overwrite = auto_overwrite->GetValue() ;
         mdd.pm_name->SetValue ( name ) ;
         mdd.pm_dd_save->SetStringSelection ( db ) ;
         mdd.do_save_DNA () ;
     }
     
     EndModal ( wxID_OK ) ; //wxDialog::OnOK ( ev ) ;
}

void TStoreAllDialog::OnAll ( wxCommandEvent &ev )
{
     unsigned int a ;
     for ( a = 0 ; a < list->GetCount() ; a++ )
         list->Check ( a , true ) ;
}

void TStoreAllDialog::OnNone ( wxCommandEvent &ev )
{
     unsigned int a ;
     for ( a = 0 ; a < list->GetCount() ; a++ )
         list->Check ( a , false ) ;
}

void TStoreAllDialog::OnInvert ( wxCommandEvent &ev )
{
     unsigned int a ;
     for ( a = 0 ; a < list->GetCount() ; a++ )
         list->Check ( a , !list->IsChecked(a) ) ;
}

void TStoreAllDialog::OnCharHook ( wxKeyEvent& event )
    {
    int k = event.GetKeyCode () ;
    wxCommandEvent ev ;
    if ( k == WXK_ESCAPE ) EndModal ( wxID_CANCEL ) ; //OnCancel ( ev ) ;
    else if ( k == WXK_F1 ) myapp()->frame->OnHelp(ev) ;
    else event.Skip() ;
    }