NCBI C++ ToolKit
save_dlg.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: save_dlg.cpp 47479 2023-05-02 13:24:02Z ucko $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors:
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
34 ////@begin includes
35 ////@end includes
36 
37 #include <gui/core/save_dlg.hpp>
38 
39 #include <gui/core/document.hpp>
43 
44 #include <serial/iterator.hpp>
45 
47 
48 #include <wx/sizer.h>
49 #include <wx/checkbox.h>
50 #include <wx/stattext.h>
51 #include <wx/statbox.h>
52 #include <wx/bitmap.h>
53 #include <wx/icon.h>
54 #include <wx/checklst.h>
55 #include <wx/button.h>
56 #include <wx/wupdlock.h>
57 #include <wx/msgdlg.h>
58 
59 
62 
63 
65 : m_ShowNoButton(false)
66 {
67 }
68 
69 
70 IMPLEMENT_DYNAMIC_CLASS( CSaveDlg, CDialog )
71 
72 BEGIN_EVENT_TABLE( CSaveDlg, CDialog )
73 ////@begin CSaveDlg event table entries
74  EVT_INIT_DIALOG( CSaveDlg::OnInitDialog )
75 
76  EVT_CHECKLISTBOX( ID_PRJ_LIST, CSaveDlg::OnPrjListToggled )
77 
78  EVT_BUTTON( ID_SELECT_CHANGED, CSaveDlg::OnSelectChangedClick )
79 
81 
82  EVT_BUTTON( ID_CLEAR_ALL, CSaveDlg::OnClearAllClick )
83 
84  EVT_BUTTON( wxID_SAVE, CSaveDlg::OnSaveClick )
85 
86  EVT_BUTTON( wxID_NO, CSaveDlg::OnNoClick )
87 
88 ////@end CSaveDlg event table entries
90 
92 : m_Wrapped(false), m_WS(0)
93 {
94  Init();
95 }
96 
97 
98 CSaveDlg::CSaveDlg( CGBWorkspace& ws, wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
99  : m_WS(&ws)
100 {
101  Init();
102  Create(parent, id, caption, pos, size, style);
103 }
104 
105 
106 bool CSaveDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
107 {
108 ////@begin CSaveDlg creation
109  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
110  CDialog::Create( parent, id, caption, pos, size, style );
111 
112  CreateControls();
113  if (GetSizer())
114  {
115  GetSizer()->SetSizeHints(this);
116  }
117  Centre();
118 ////@end CSaveDlg creation
119  return true;
120 }
121 
122 
124 {
125 ////@begin CSaveDlg destruction
126 ////@end CSaveDlg destruction
127 }
128 
129 
131 {
132 ////@begin CSaveDlg member initialisation
133  m_RootSizer = NULL;
134  m_DescrText = NULL;
136  m_BtnSizer = NULL;
137  m_SaveBtn = NULL;
138 ////@end CSaveDlg member initialisation
139 }
140 
141 
143 {
144  return m_Params;
145 }
146 
147 
149 {
150  m_Params = params;
151 }
152 
153 
155 {
156 ////@begin CSaveDlg content construction
157  CSaveDlg* itemCDialog1 = this;
158 
159  m_RootSizer = new wxBoxSizer(wxVERTICAL);
160  itemCDialog1->SetSizer(m_RootSizer);
161 
162  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
163  m_RootSizer->Add(itemBoxSizer3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
164 
165  m_DescrText = new wxStaticText( itemCDialog1, wxID_STATIC, wxEmptyString, wxDefaultPosition, wxSize(itemCDialog1->ConvertDialogToPixels(wxSize(200, -1)).x, -1), 0 );
166  itemBoxSizer3->Add(m_DescrText, 0, wxGROW|wxALL, 5);
167 
168  wxStaticBox* itemStaticBoxSizer5Static = new wxStaticBox(itemCDialog1, wxID_ANY, _("Projects to save:"));
169  wxStaticBoxSizer* itemStaticBoxSizer5 = new wxStaticBoxSizer(itemStaticBoxSizer5Static, wxVERTICAL);
170  m_RootSizer->Add(itemStaticBoxSizer5, 1, wxGROW|wxALL, 5);
171 
172  wxArrayString m_ProjectListStrings;
173  m_ProjectList = new wxCheckListBox( itemStaticBoxSizer5->GetStaticBox(), ID_PRJ_LIST, wxDefaultPosition, wxSize(-1, itemStaticBoxSizer5->GetStaticBox()->ConvertDialogToPixels(wxSize(-1, 48)).y), m_ProjectListStrings, wxLB_EXTENDED );
174  itemStaticBoxSizer5->Add(m_ProjectList, 1, wxGROW|wxALL, 5);
175 
176  wxBoxSizer* itemBoxSizer7 = new wxBoxSizer(wxHORIZONTAL);
177  itemStaticBoxSizer5->Add(itemBoxSizer7, 0, wxALIGN_RIGHT, 5);
178 
179  wxButton* itemButton8 = new wxButton( itemStaticBoxSizer5->GetStaticBox(), ID_SELECT_CHANGED, _("Select Changed"), wxDefaultPosition, wxDefaultSize, 0 );
180  itemBoxSizer7->Add(itemButton8, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
181 
182  wxButton* itemButton9 = new wxButton( itemStaticBoxSizer5->GetStaticBox(), ID_SELECT_ALL, _("Select All"), wxDefaultPosition, wxDefaultSize, 0 );
183  itemBoxSizer7->Add(itemButton9, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
184 
185  wxButton* itemButton10 = new wxButton( itemStaticBoxSizer5->GetStaticBox(), ID_CLEAR_ALL, _("Clear All"), wxDefaultPosition, wxDefaultSize, 0 );
186  itemBoxSizer7->Add(itemButton10, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
187 
188  m_BtnSizer = new wxStdDialogButtonSizer;
189 
190  m_RootSizer->Add(m_BtnSizer, 0, wxALIGN_RIGHT|wxALL, 5);
191  wxButton* itemButton12 = new wxButton( itemCDialog1, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
192  m_BtnSizer->AddButton(itemButton12);
193 
194  m_SaveBtn = new wxButton( itemCDialog1, wxID_SAVE, _("&Save Selected"), wxDefaultPosition, wxDefaultSize, 0 );
195  m_BtnSizer->AddButton(m_SaveBtn);
196 
197  wxButton* itemButton14 = new wxButton( itemCDialog1, wxID_NO, _("&No"), wxDefaultPosition, wxDefaultSize, 0 );
198  m_BtnSizer->AddButton(itemButton14);
199 
200  m_BtnSizer->Realize();
201 
202  // Set validators
203  m_ProjectList->SetValidator( wxGenericValidator(& m_Params.m_ProjectsToSave) );
204 ////@end CSaveDlg content construction
205 
206 }
207 
208 
209 void CSaveDlg::OnInitDialog( wxInitDialogEvent& event )
210 {
211  // one-time initialization of the dialog at start-up
212 
213  if(m_Params.m_Description.empty()) {
214  m_DescrText->Hide();
215  } else {
217  }
218 
219  // prepare Project List
220  for( size_t i = 0; i < m_Params.m_ProjectIds.size(); i++ ) {
221  auto id = m_Params.m_ProjectIds[i];
222  CGBDocument* doc = dynamic_cast<CGBDocument*>(m_WS->GetProjectFromId(id));
223 
224  string s = doc->GetDescr().GetTitle();
225  if(doc->IsDirty()) {
226  s += (doc->GetFilename().empty() ? + "* (New)" : "* (Modified)");
227  }
228  m_ProjectList->Append(ToWxString(s));
229  }
230 
231  // hide No button, if needed
232  if( ! m_Params.m_ShowNoButton) {
233  FindWindow(wxID_NO)->Hide();
234  }
235 
236  x_UpdateButtons();
237 
238  wxDialog::OnInitDialog(event);
239 
240  int w = m_DescrText->ConvertDialogToPixels(wxPoint(200, 0)).x;
241  m_DescrText->Wrap(w);
242 
243  m_RootSizer->Layout();
244 }
245 
246 
247 void CSaveDlg::OnPrjListToggled( wxCommandEvent& event )
248 {
249  TransferDataFromWindow();
250  x_UpdateButtons();
251 }
252 
253 
254 // check items for changed (modified or new) projects
255 void CSaveDlg::OnSelectChangedClick( wxCommandEvent& event )
256 {
257  m_Params.m_ProjectsToSave.Clear();
258  for( size_t i = 0; i < m_Params.m_ProjectIds.size(); i++ ) {
259  auto id = m_Params.m_ProjectIds[i];
260  CGBDocument* doc = dynamic_cast<CGBDocument*>(m_WS->GetProjectFromId(id));
261 
262  if(doc->IsDirty()) {
263  m_Params.m_ProjectsToSave.Add((int)i);
264  }
265  }
266 
267  TransferDataToWindow();
268  x_UpdateButtons();
269 }
270 
271 
272 // check items for all projects
273 void CSaveDlg::OnSelectAllClick( wxCommandEvent& event )
274 {
275  m_Params.m_ProjectsToSave.Clear();
276  size_t n = m_Params.m_ProjectIds.size();
277  for( size_t i = 0; i < n; i++ ) {
278  m_Params.m_ProjectsToSave.Add((int)i);
279  }
280 
281  TransferDataToWindow();
282  x_UpdateButtons();
283 }
284 
285 
286 // clear items for all projects
287 void CSaveDlg::OnClearAllClick( wxCommandEvent& event )
288 {
289  m_Params.m_ProjectsToSave.Clear();
290  TransferDataToWindow();
291  x_UpdateButtons();
292 }
293 
294 
295 void CSaveDlg::OnSaveClick( wxCommandEvent& event )
296 {
297  TransferDataFromWindow();
298  EndModal(wxID_SAVE);
299 }
300 
301 
302 void CSaveDlg::OnNoClick( wxCommandEvent& event )
303 {
304  EndModal(wxID_NO);
305 }
306 
307 
309 {
310  return true;
311 }
312 
313 
314 wxBitmap CSaveDlg::GetBitmapResource( const wxString& name )
315 {
316  // Bitmap retrieval
317 ////@begin CSaveDlg bitmap retrieval
318  wxUnusedVar(name);
319  return wxNullBitmap;
320 ////@end CSaveDlg bitmap retrieval
321 }
322 
323 
324 wxIcon CSaveDlg::GetIconResource( const wxString& name )
325 {
326  // Icon retrieval
327 ////@begin CSaveDlg icon retrieval
328  wxUnusedVar(name);
329  return wxNullIcon;
330 ////@end CSaveDlg icon retrieval
331 }
332 
334 {
335  bool en = !m_Params.m_ProjectsToSave.empty();
336  m_SaveBtn->Enable(en);
337 }
338 
User-defined methods of the data storage class.
User-defined methods of the data storage class.
#define false
Definition: bool.h:36
CDialog.
Definition: dialog.hpp:47
virtual void EndModal(int retCode)
Definition: dialog.cpp:142
CGBDocument.
Definition: document.hpp:113
CGBWorkspace.
Definition: GBWorkspace.hpp:63
CSaveDlg - a dialog for saving workspace and projects.
Definition: save_dlg.hpp:86
void x_UpdateButtons()
Definition: save_dlg.cpp:333
wxBoxSizer * m_RootSizer
Definition: save_dlg.hpp:132
void OnPrjListToggled(wxCommandEvent &event)
Definition: save_dlg.cpp:247
void OnSelectChangedClick(wxCommandEvent &event)
Definition: save_dlg.cpp:255
objects::CGBWorkspace * m_WS
Definition: save_dlg.hpp:157
wxIcon GetIconResource(const wxString &name)
Definition: save_dlg.cpp:324
wxBitmap GetBitmapResource(const wxString &name)
Definition: save_dlg.cpp:314
wxStdDialogButtonSizer * m_BtnSizer
Definition: save_dlg.hpp:135
void OnSelectAllClick(wxCommandEvent &event)
Definition: save_dlg.cpp:273
wxButton * m_SaveBtn
Definition: save_dlg.hpp:136
wxCheckListBox * m_ProjectList
Definition: save_dlg.hpp:134
void SetParams(const SSaveProjectsDlgParams &value)
Definition: save_dlg.cpp:148
wxStaticText * m_DescrText
Definition: save_dlg.hpp:133
void CreateControls()
Definition: save_dlg.cpp:154
SSaveProjectsDlgParams m_Params
Definition: save_dlg.hpp:138
void OnSaveClick(wxCommandEvent &event)
Definition: save_dlg.cpp:295
const SSaveProjectsDlgParams & GetParams() const
Definition: save_dlg.cpp:142
void OnClearAllClick(wxCommandEvent &event)
Definition: save_dlg.cpp:287
CSaveDlg()
Definition: save_dlg.cpp:91
static bool ShowToolTips()
Definition: save_dlg.cpp:308
void Init()
Definition: save_dlg.cpp:130
void OnInitDialog(wxInitDialogEvent &event)
Definition: save_dlg.cpp:209
@ ID_SELECT_ALL
Definition: save_dlg.hpp:143
@ ID_CLEAR_ALL
Definition: save_dlg.hpp:144
@ ID_PRJ_LIST
Definition: save_dlg.hpp:141
@ ID_SELECT_CHANGED
Definition: save_dlg.hpp:142
void OnNoClick(wxCommandEvent &event)
Definition: save_dlg.cpp:302
bool Create(wxWindow *parent, wxWindowID id=ID_CSAVEDLG, const wxString &caption=_("Save"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Definition: save_dlg.cpp:106
wxArrayInt m_ProjectsToSave
indices of the projects to save (checked items)
Definition: save_dlg.hpp:68
vector< objects::CGBProjectHandle::TId > m_ProjectIds
Definition: save_dlg.hpp:65
#define _(proto)
Definition: ct_nlmzip_i.h:78
static void Init(void)
Definition: cursor6.c:76
#define NULL
Definition: ncbistd.hpp:225
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
END_EVENT_TABLE()
int i
yy_size_t n
const struct ncbi::grid::netcache::search::fields::SIZE size
#define ID_SELECT_ALL
USING_SCOPE(objects)
static static static wxID_ANY
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
Modified on Mon Feb 26 04:02:39 2024 by modify_doxy.py rev. 669887