OSDN Git Service

Handling key and mouse events in listctrl is improved
[molby/Molby.git] / wxSources / MyDocManager.cpp
1 /*
2  *  MyDocManager.cpp
3  *  Molby
4  *
5  *  Created by Toshi Nagata on 09/11/21.
6  *  Copyright 2009 Toshi Nagata. All rights reserved.
7  *
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.
11  
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.
16  */
17
18 #include "wx/filedlg.h"
19 #include "MyDocManager.h"
20 #include "MyMBConv.h"
21 #include "MyApp.h"
22 #include "../MolLib/Ruby_bind/Molby_extern.h"
23
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)
29 END_EVENT_TABLE()
30
31 static const char *sReadOnlyTypes[] = {
32         "out", "fchk", "log", "dat", "ins", "res", NULL
33 };
34
35 void
36 MyDocManager::SetDocumentTypesEnabled(const char **extensions, bool flag)
37 {
38         wxList &tlist = GetTemplates();
39         wxList::iterator iter;
40         for (iter = tlist.begin(); iter != tlist.end(); ++iter) {
41                 int i;
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);
47                                 break;
48                         }
49                 }
50         }
51 }
52
53 void
54 MyDocManager::OnFileSave(wxCommandEvent& event)
55 {
56         SetDocumentTypesEnabled(sReadOnlyTypes, false);
57         wxDocManager::OnFileSave(event);
58         SetDocumentTypesEnabled(sReadOnlyTypes, true);
59 }
60
61 void
62 MyDocManager::OnFileSaveAs(wxCommandEvent& event)
63 {
64         SetDocumentTypesEnabled(sReadOnlyTypes, false);
65         wxDocManager::OnFileSaveAs(event);
66         SetDocumentTypesEnabled(sReadOnlyTypes, true);
67 }
68
69 bool
70 MyDocManager::GetDocumentDescriptionAtIndex(int idx, wxString *outDescription, wxString *outFilter, wxString *outExtension)
71 {
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();
82                 return true;
83         } else return false;
84 }
85