Develop and Download Open Source Software

Browse CVS Repository

Contents of /tombo/Tombo/Src/MemoManager.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.46 - (show annotations) (download) (as text)
Thu Feb 23 10:20:22 2006 UTC (18 years, 1 month ago) by hirami
Branch: MAIN
CVS Tags: Tombo_2_0b2, Tombo_2_0b3, Tombo_2_0b1, Tombo_2_0b4, B228, B229, B226, B227, B224, B225, B222, B223, B220, B231, B230, HEAD
Changes since 1.45: +12 -9 lines
File MIME type: text/x-c++src
- Refactoring about TreeViewItem
	- now each node have its URI

1 #include <windows.h>
2 #include <commctrl.h>
3 #include <tchar.h>
4 #include "Tombo.h"
5 #include "TString.h"
6 #include "MemoManager.h"
7 #include "MemoDetailsView.h"
8 #include "MemoSelectView.h"
9 #include "VarBuffer.h"
10 #include "MainFrame.h"
11 #include "UniConv.h"
12 #include "Property.h"
13 #include "TreeViewItem.h"
14 #include "SearchEngine.h"
15 #include "Message.h"
16 #include "TomboURI.h"
17 #include "AutoPtr.h"
18
19 #include "Repository.h"
20
21 /////////////////////////////////////////////
22 // ctor & dtor
23 /////////////////////////////////////////////
24
25 MemoManager::MemoManager() : pSearchEngineA(NULL), bMSSearchFlg(FALSE), bMDSearchFlg(FALSE)
26 {
27 }
28
29 MemoManager::~MemoManager()
30 {
31 if(pSearchEngineA) {
32 delete pSearchEngineA;
33 }
34 }
35
36 /////////////////////////////////////////////
37 // initialize
38 /////////////////////////////////////////////
39
40 BOOL MemoManager::Init(MainFrame *mf, MemoDetailsView *md, MemoSelectView *ms)
41 {
42 pMainFrame = mf;
43 pMemoDetailsView = md;
44 pMemoSelectView = ms;
45 return TRUE;
46 }
47
48 /////////////////////////////////////////////
49 // get current selected path
50 /////////////////////////////////////////////
51
52 BOOL MemoManager::GetCurrentSelectedPath(TString *pPath)
53 {
54 TString sURIstr;
55 TomboURI sURI;
56
57 if (pMemoDetailsView->GetCurrentURI()) {
58 sURI = (*pMemoDetailsView->GetCurrentURI());
59 } else {
60 if (pMemoSelectView->GetCurrentSelectedURI()) {
61 sURI = (*pMemoSelectView->GetCurrentSelectedURI());
62 } else {
63 return FALSE;
64 }
65 }
66
67 if (sURI.IsLeaf()) {
68 TomboURI sParent;
69 if (!sURI.GetParent(&sParent)) return FALSE;
70 if (!sParent.GetFilePath(pPath)) return FALSE;
71 } else {
72 if (!sURI.GetFilePath(pPath)) return FALSE;
73 }
74 ChopFileSeparator(pPath->Get());
75
76 return TRUE;
77 }
78
79 ////////////////////////////////////////////////////////
80 // Save notes
81 ////////////////////////////////////////////////////////
82 // Notes is not save if not modified or read only.
83 // Otherwise save notes after confirm.
84
85 BOOL MemoManager::SaveIfModify(LPDWORD pYNC, BOOL bDupMode)
86 {
87 if (pYNC) {
88 *pYNC = IDOK;
89 }
90
91 // skip saving if not modified or read only
92 if (!pMemoDetailsView->IsModify() || pMemoDetailsView->IsReadOnly()) {
93 pMemoDetailsView->StoreCursorPos();
94 return TRUE;
95 }
96
97 if (pYNC) {
98 if (!g_Property.GetDisableSaveDlg()) {
99 *pYNC = pMainFrame->MessageBox(MSG_MEMO_EDITED, MSG_CONFIRM_SAVE, MB_ICONQUESTION | MB_YESNOCANCEL | MB_APPLMODAL);
100 if (*pYNC == IDNO || *pYNC == IDCANCEL) return TRUE;
101 } else {
102 *pYNC = IDOK;
103 }
104 }
105
106 ////////////////////////////////////////////
107
108 // get memo data
109 LPTSTR pText = pMemoDetailsView->GetMemo();
110 SecureBufferAutoPointerT ap(pText);
111 if (pText == NULL) return FALSE;
112
113 ////////////////////////////////////////////
114
115 if (bDupMode) {
116 if (!AllocNewMemo(pText, TRUE)) return FALSE;
117 // duplicate mode notes are treated as update because pCurrentURI has set.
118 } else {
119 // Create node if the note is new
120 if (pMemoDetailsView->GetCurrentURI() == NULL) {
121 if (!AllocNewMemo(pText, FALSE)) return FALSE;
122 // change status because the note is not new note at this point.
123 pMainFrame->SetNewMemoStatus(FALSE);
124 }
125 }
126
127 ///////////////////////////////////////
128 // save notes and update treeview
129
130 TomboURI sCurrentURI(*(pMemoDetailsView->GetCurrentURI())); // to preserve it because it changed by method Save.
131
132 TomboURI sNewURI;
133 TString sNewHeadLine;
134
135 // save note contents
136 if (!pMemoDetailsView->Save(&sCurrentURI, &sNewURI, &sNewHeadLine, pText)) return FALSE;
137
138 // UpdateHeadLine causes TVN_SELCHANGING and call SaveIfModify.
139 // So if not ResetModify is called, infinite calling causes GPF.
140 // update treeview headline string
141 pMemoSelectView->UpdateHeadLine(sCurrentURI.GetFullURI(), &sNewURI, sNewHeadLine.Get());
142
143 // update window title
144 pMainFrame->SetWindowTitle(&sNewURI);
145
146 return TRUE;
147 }
148
149 ////////////////////////////////////////////////////////
150 // allocate new memo
151 ////////////////////////////////////////////////////////
152
153 BOOL MemoManager::AllocNewMemo(LPCTSTR pText, BOOL bCopy)
154 {
155 const TomboURI *pTemplateURI = NULL;
156 if (bCopy) {
157 pTemplateURI = pMemoDetailsView->GetCurrentURI();
158 }
159
160 // get note path
161 TomboURI sAttachFolder;
162 TomboURI sSelected;
163
164 const TomboURI *pCurSelectedURI = pMemoSelectView->GetCurrentSelectedURI();
165 if (pCurSelectedURI == NULL) return FALSE;
166 sSelected = *pCurSelectedURI;
167
168 if (!sSelected.GetAttachFolder(&sAttachFolder)) return FALSE;
169
170 // allocate new instance and associate to tree view
171 TString sHeadLine;
172 TomboURI sNewURI;
173
174 // get URI
175 if (!g_Repository.RequestAllocateURI(&sAttachFolder, pText, &sHeadLine, &sNewURI, pTemplateURI)) return FALSE;
176
177 // Insert new node to select view
178 HTREEITEM hParent;
179 hParent = pMemoSelectView->ShowItemByURI(&sAttachFolder, FALSE);
180 if (hParent == NULL) return FALSE;
181 HTREEITEM hNewItem = pMemoSelectView->InsertFile(hParent, &sNewURI, sHeadLine.Get(), FALSE, FALSE);
182
183 pMemoDetailsView->SetCurrentNote(&sNewURI);
184
185 return TRUE;
186 }
187
188 ////////////////////////////////////////////////////////
189 //
190 ////////////////////////////////////////////////////////
191
192 void MemoManager::InactiveDetailsView()
193 {
194 pMainFrame->LeaveDetailsView(TRUE);
195 }
196
197 ////////////////////////////////////////////////////////
198 //
199 ////////////////////////////////////////////////////////
200
201 void MemoManager::SetSearchEngine(SearchEngineA *p)
202 {
203 if (pSearchEngineA) {
204 delete pSearchEngineA;
205 }
206 pSearchEngineA = p;
207 }
208
209 void MemoManager::ChangeURINotify(const TomboURI *pNewURI)
210 {
211 pMemoDetailsView->SetCurrentNote(pNewURI);
212 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26