5 * Created by Toshi Nagata on 09/11/21.
6 * Copyright 2009 Toshi Nagata. All rights reserved.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation version 2 of the License.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
18 #include "wx/filedlg.h"
19 #include "MyDocManager.h"
22 #include "../MolLib/Ruby_bind/Molby_extern.h"
24 BEGIN_EVENT_TABLE(MyDocManager, wxDocManager)
25 EVT_MENU(wxID_OPEN, MyDocManager::OnFileOpen)
26 EVT_MENU(wxID_SAVE, MyDocManager::OnFileSave)
27 EVT_MENU(wxID_SAVEAS, MyDocManager::OnFileSaveAs)
28 EVT_MENU(wxID_REVERT, MyDocManager::OnFileRevert)
31 static const char *sReadOnlyTypes[] = {
32 "out", "fchk", "log", "dat", "ins", "res", NULL
36 MyDocManager::SetDocumentTypesEnabled(const char **extensions, bool flag)
38 wxList &tlist = GetTemplates();
39 wxList::iterator iter;
40 for (iter = tlist.begin(); iter != tlist.end(); ++iter) {
42 wxDocTemplate *dt = (wxDocTemplate *)(*iter);
43 const char *p = (const char *)(dt->GetDefaultExtension().mb_str(WX_DEFAULT_CONV));
44 for (i = 0; extensions[i] != NULL; i++) {
45 if (strcmp(extensions[i], p) == 0) {
46 dt->SetFlags(flag ? wxTEMPLATE_VISIBLE : wxTEMPLATE_INVISIBLE);
54 MyDocManager::OnFileSave(wxCommandEvent& event)
56 SetDocumentTypesEnabled(sReadOnlyTypes, false);
57 wxDocManager::OnFileSave(event);
58 SetDocumentTypesEnabled(sReadOnlyTypes, true);
62 MyDocManager::OnFileSaveAs(wxCommandEvent& event)
64 SetDocumentTypesEnabled(sReadOnlyTypes, false);
65 wxDocManager::OnFileSaveAs(event);
66 SetDocumentTypesEnabled(sReadOnlyTypes, true);
70 MyDocManager::GetDocumentDescriptionAtIndex(int idx, wxString *outDescription, wxString *outFilter, wxString *outExtension)
72 wxList &tlist = GetTemplates();
73 if (idx >= 0 && idx < tlist.GetCount()) {
74 wxList::iterator iter;
75 wxDocTemplate *dt = (wxDocTemplate *)(tlist.Item(idx)->GetData());
76 if (outDescription != NULL)
77 *outDescription = dt->GetDescription();
78 if (outFilter != NULL)
79 *outFilter = dt->GetFileFilter();
80 if (outExtension != NULL)
81 *outExtension = dt->GetDefaultExtension();