| 1 |
#include <windows.h> |
| 2 |
#include <commctrl.h> |
| 3 |
#include <tchar.h> |
| 4 |
#include "Tombo.h" |
| 5 |
#include "TreeViewItem.h" |
| 6 |
#include "MemoSelectView.h" |
| 7 |
#include "TString.h" |
| 8 |
#include "TomboURI.h" |
| 9 |
#include "UniConv.h" |
| 10 |
#include "Property.h" |
| 11 |
#include "MemoManager.h" |
| 12 |
#include "MainFrame.h" |
| 13 |
#include "DirectoryScanner.h" |
| 14 |
#include "Message.h" |
| 15 |
#include "VFStream.h" |
| 16 |
#include "TSParser.h" |
| 17 |
#include "VarBuffer.h" |
| 18 |
#include "VFManager.h" |
| 19 |
#include "AutoPtr.h" |
| 20 |
#include "URIScanner.h" |
| 21 |
|
| 22 |
#include "Repository.h" |
| 23 |
|
| 24 |
#if defined(PLATFORM_BE500) |
| 25 |
#include "COShellAPI.h" |
| 26 |
#endif |
| 27 |
|
| 28 |
#define ITEM_ORDER_FILE 1 |
| 29 |
#define ITEM_ORDER_FOLDER 0 |
| 30 |
|
| 31 |
///////////////////////////////////////////// |
| 32 |
///////////////////////////////////////////// |
| 33 |
// TreeViewItem |
| 34 |
///////////////////////////////////////////// |
| 35 |
///////////////////////////////////////////// |
| 36 |
|
| 37 |
TreeViewItem::TreeViewItem(BOOL bItem) : bHasMultiItem(bItem), hItem(NULL) |
| 38 |
{ |
| 39 |
} |
| 40 |
|
| 41 |
TreeViewItem::~TreeViewItem() |
| 42 |
{ |
| 43 |
} |
| 44 |
|
| 45 |
HTREEITEM TreeViewItem::GetViewItem() |
| 46 |
{ |
| 47 |
return hItem; |
| 48 |
} |
| 49 |
|
| 50 |
void TreeViewItem::SetViewItem(HTREEITEM h) |
| 51 |
{ |
| 52 |
hItem = h; |
| 53 |
} |
| 54 |
|
| 55 |
BOOL TreeViewItem::IsOperationEnabled(MemoSelectView *pView, OpType op) |
| 56 |
{ |
| 57 |
DWORD nOpMatrix = OpNewMemo | OpNewFolder | OpCut | OpCopy | OpPaste; |
| 58 |
return (nOpMatrix & op) != 0; |
| 59 |
} |
| 60 |
|
| 61 |
BOOL TreeViewItem::IsUseDetailsView() |
| 62 |
{ |
| 63 |
return FALSE; |
| 64 |
} |
| 65 |
|
| 66 |
BOOL TreeViewItem::OpenMemo(MemoSelectView *pView, DWORD nOption) |
| 67 |
{ |
| 68 |
return TRUE; |
| 69 |
} |
| 70 |
|
| 71 |
BOOL TreeViewItem::LoadMemo(MemoSelectView *pView, BOOL bAskPass) |
| 72 |
{ |
| 73 |
return TRUE; |
| 74 |
} |
| 75 |
|
| 76 |
void TreeViewItem::SetURI(const TomboURI *p) |
| 77 |
{ |
| 78 |
loc.set(p); |
| 79 |
} |
| 80 |
|
| 81 |
TreeViewItem::Locator::~Locator() |
| 82 |
{ |
| 83 |
delete pURI; |
| 84 |
} |
| 85 |
|
| 86 |
void TreeViewItem::Locator::set(const TomboURI *p) |
| 87 |
{ |
| 88 |
delete pURI; |
| 89 |
pURI = new TomboURI(*p); // share string buffer |
| 90 |
} |
| 91 |
|
| 92 |
///////////////////////////////////////////// |
| 93 |
///////////////////////////////////////////// |
| 94 |
// File |
| 95 |
///////////////////////////////////////////// |
| 96 |
///////////////////////////////////////////// |
| 97 |
|
| 98 |
TreeViewFileItem::TreeViewFileItem() : TreeViewItem(FALSE) |
| 99 |
{ |
| 100 |
} |
| 101 |
|
| 102 |
TreeViewFileItem::~TreeViewFileItem() |
| 103 |
{ |
| 104 |
} |
| 105 |
|
| 106 |
BOOL TreeViewFileItem::CopyMove(BOOL bCopy, MemoManager *pMgr, MemoSelectView *pView) |
| 107 |
{ |
| 108 |
TomboURI sCopyToURI; |
| 109 |
TomboURI sCurURI; |
| 110 |
|
| 111 |
const TomboURI *pCurSelURI = pView->GetCurrentSelectedURI(); |
| 112 |
if (pCurSelURI == NULL) return FALSE; |
| 113 |
sCurURI = *pCurSelURI; |
| 114 |
|
| 115 |
if (!g_Repository.GetAttachURI(&sCurURI, &sCopyToURI)) return FALSE; |
| 116 |
|
| 117 |
HTREEITEM hParent = pView->ShowItemByURI(&sCopyToURI, FALSE, FALSE); |
| 118 |
URIOption opt; |
| 119 |
if (bCopy) { |
| 120 |
if (!g_Repository.Copy(loc.getURI(), &sCopyToURI, &opt)) return FALSE; |
| 121 |
} else { |
| 122 |
if (!g_Repository.Move(loc.getURI(), &sCopyToURI, &opt)) return FALSE; |
| 123 |
} |
| 124 |
|
| 125 |
pView->InsertFile(hParent, opt.pNewURI, opt.pNewHeadLine->Get(), FALSE, FALSE); |
| 126 |
return TRUE; |
| 127 |
} |
| 128 |
|
| 129 |
BOOL TreeViewFileItem::Move(MemoManager *pMgr, MemoSelectView *pView, LPCTSTR *ppErr) |
| 130 |
{ |
| 131 |
return CopyMove(FALSE, pMgr, pView); |
| 132 |
} |
| 133 |
|
| 134 |
BOOL TreeViewFileItem::Copy(MemoManager *pMgr, MemoSelectView *pView, LPCTSTR *ppErr) |
| 135 |
{ |
| 136 |
return CopyMove(TRUE, pMgr, pView); |
| 137 |
} |
| 138 |
|
| 139 |
BOOL TreeViewFileItem::Delete(MemoManager *pMgr, MemoSelectView *pView) |
| 140 |
{ |
| 141 |
// Confirm |
| 142 |
if (TomboMessageBox(NULL, MSG_CONFIRM_DELETE, MSG_DELETE_TTL, MB_ICONQUESTION | MB_OKCANCEL) != IDOK) return FALSE; |
| 143 |
|
| 144 |
if (g_Property.GetUseTwoPane() && pMgr->GetDetailsView()->IsNoteDisplayed(loc.getURI())) { |
| 145 |
// close current note |
| 146 |
pMgr->GetDetailsView()->DiscardMemo(); |
| 147 |
} |
| 148 |
|
| 149 |
URIOption opt; |
| 150 |
if (!g_Repository.Delete(loc.getURI(), &opt)) { |
| 151 |
TomboMessageBox(NULL, MSG_DELETE_FAILED, TEXT("ERROR"), MB_ICONSTOP | MB_OK); |
| 152 |
return FALSE; |
| 153 |
} |
| 154 |
return TRUE; |
| 155 |
} |
| 156 |
|
| 157 |
BOOL TreeViewFileItem::Encrypt(MemoManager *pMgr, MemoSelectView *pView) |
| 158 |
{ |
| 159 |
// if this note is encrypted, ignore. |
| 160 |
if (g_Repository.IsEncrypted(loc.getURI())) return TRUE; |
| 161 |
|
| 162 |
// if the note is opened, close it. |
| 163 |
if (g_Property.GetUseTwoPane() && pMgr->GetDetailsView()->IsNoteDisplayed(loc.getURI())) { |
| 164 |
pMgr->InactiveDetailsView(); |
| 165 |
} |
| 166 |
|
| 167 |
URIOption opt(NOTE_OPTIONMASK_ENCRYPTED); |
| 168 |
opt.bEncrypt = TRUE; |
| 169 |
if (!g_Repository.SetOption(loc.getURI(), &opt)) { |
| 170 |
switch(GetLastError()) { |
| 171 |
case ERROR_TOMBO_W_DELETEOLD_FAILED: |
| 172 |
MessageBox(NULL, MSG_DELETE_PREV_CRYPT_MEMO_FAILED, TOMBO_APP_NAME, MB_ICONWARNING | MB_OK); |
| 173 |
break; |
| 174 |
default: |
| 175 |
MessageBox(NULL, MSG_ENCRYPT_FAILED, TOMBO_APP_NAME, MB_ICONERROR | MB_OK); |
| 176 |
break; |
| 177 |
} |
| 178 |
return FALSE; |
| 179 |
} |
| 180 |
// replace URI that TreeViewItem have |
| 181 |
loc.set(opt.pNewURI); |
| 182 |
pView->GetManager()->ChangeURINotify(opt.pNewURI); |
| 183 |
|
| 184 |
// update icon and headline string |
| 185 |
if (!pView->UpdateItemStatusNotify(this, opt.pNewHeadLine->Get())) { |
| 186 |
MessageBox(NULL, TEXT("UpdateItemStatusNotify failed"), TEXT("DEBUG"), MB_OK); |
| 187 |
return FALSE; |
| 188 |
} |
| 189 |
return TRUE; |
| 190 |
} |
| 191 |
|
| 192 |
BOOL TreeViewFileItem::Decrypt(MemoManager *pMgr, MemoSelectView *pView) |
| 193 |
{ |
| 194 |
// if the note is plain text, ignore it |
| 195 |
if (!g_Repository.IsEncrypted(loc.getURI())) return TRUE; |
| 196 |
|
| 197 |
// if the note is opened, close it. |
| 198 |
if (g_Property.GetUseTwoPane() && pMgr->GetDetailsView()->IsNoteDisplayed(loc.getURI())) { |
| 199 |
pMgr->InactiveDetailsView(); |
| 200 |
} |
| 201 |
|
| 202 |
// decrypt |
| 203 |
URIOption opt(NOTE_OPTIONMASK_ENCRYPTED); |
| 204 |
opt.bEncrypt = FALSE; |
| 205 |
if (!g_Repository.SetOption(loc.getURI(), &opt)) { |
| 206 |
switch(GetLastError()) { |
| 207 |
case ERROR_TOMBO_W_DELETEOLD_FAILED: |
| 208 |
MessageBox(NULL, MSG_DEL_PREV_DECRYPT_MEMO_FAILED, TOMBO_APP_NAME, MB_ICONWARNING | MB_OK); |
| 209 |
break; |
| 210 |
default: |
| 211 |
MessageBox(NULL, MSG_DECRYPT_FAILED, TOMBO_APP_NAME, MB_ICONERROR | MB_OK); |
| 212 |
break; |
| 213 |
} |
| 214 |
return FALSE; |
| 215 |
} |
| 216 |
|
| 217 |
// replace URI that TreeViewItem have |
| 218 |
loc.set(opt.pNewURI); |
| 219 |
pView->GetManager()->ChangeURINotify(opt.pNewURI); |
| 220 |
|
| 221 |
// update icon and headline string |
| 222 |
if (!pView->UpdateItemStatusNotify(this, opt.pNewHeadLine->Get())) { |
| 223 |
return FALSE; |
| 224 |
} |
| 225 |
return TRUE; |
| 226 |
} |
| 227 |
|
| 228 |
BOOL TreeViewFileItem::IsOperationEnabled(MemoSelectView *pView, OpType op) |
| 229 |
{ |
| 230 |
URIOption opt(NOTE_OPTIONMASK_ENCRYPTED); |
| 231 |
const TomboURI *pURI = GetRealURI(); |
| 232 |
if (!g_Repository.GetOption(pURI, &opt)) return FALSE; |
| 233 |
|
| 234 |
if (op == OpEncrypt) { |
| 235 |
return !opt.bEncrypt; |
| 236 |
} else if (op == OpDecrypt) { |
| 237 |
return opt.bEncrypt; |
| 238 |
} else { |
| 239 |
DWORD nOpMatrix = OpDelete | OpRename | OpNewMemo | OpNewFolder | OpCut | OpCopy | OpPaste; |
| 240 |
return (nOpMatrix & op) != 0; |
| 241 |
} |
| 242 |
} |
| 243 |
|
| 244 |
BOOL TreeViewFileItem::Rename(MemoManager *pMgr, MemoSelectView *pView, LPCTSTR pNewHeadLine) |
| 245 |
{ |
| 246 |
URIOption opt; |
| 247 |
if (!g_Repository.ChangeHeadLine(loc.getURI(), pNewHeadLine, &opt)) { |
| 248 |
switch(GetLastError()) { |
| 249 |
case ERROR_NO_DATA: |
| 250 |
TomboMessageBox(NULL, MSG_NO_FILENAME, TOMBO_APP_NAME, MB_ICONWARNING | MB_OK); |
| 251 |
break; |
| 252 |
case ERROR_ALREADY_EXISTS: |
| 253 |
TomboMessageBox(NULL, MSG_SAME_FILE, TOMBO_APP_NAME, MB_ICONWARNING | MB_OK); |
| 254 |
break; |
| 255 |
case ERROR_TOMBO_I_OPERATION_NOT_PERFORMED: |
| 256 |
return TRUE; |
| 257 |
default: |
| 258 |
{ |
| 259 |
TCHAR buf[MAX_PATH]; |
| 260 |
wsprintf(buf, MSG_RENAME_FAILED, GetLastError()); |
| 261 |
TomboMessageBox(NULL, buf, TOMBO_APP_NAME, MB_ICONERROR | MB_OK); |
| 262 |
} |
| 263 |
} |
| 264 |
return FALSE; |
| 265 |
} |
| 266 |
|
| 267 |
loc.set(opt.pNewURI); |
| 268 |
pView->GetManager()->ChangeURINotify(opt.pNewURI); |
| 269 |
return TRUE; |
| 270 |
} |
| 271 |
|
| 272 |
DWORD TreeViewFileItem::GetIcon(MemoSelectView *, DWORD nStatus) |
| 273 |
{ |
| 274 |
URIOption opt(NOTE_OPTIONMASK_ENCRYPTED); |
| 275 |
const TomboURI *pURI = GetRealURI(); |
| 276 |
if (!g_Repository.GetOption(pURI, &opt)) return FALSE; |
| 277 |
|
| 278 |
if (nStatus & MEMO_VIEW_STATE_INIT) { |
| 279 |
if (opt.bEncrypt) { |
| 280 |
return IMG_ARTICLE_ENCRYPTED; |
| 281 |
} else { |
| 282 |
return IMG_ARTICLE; |
| 283 |
} |
| 284 |
} |
| 285 |
|
| 286 |
if (nStatus & MEMO_VIEW_STATE_CLIPED_SET) { |
| 287 |
if (opt.bEncrypt) { |
| 288 |
return IMG_ARTICLE_ENC_MASKED; |
| 289 |
} else { |
| 290 |
return IMG_ARTICLE_MASKED; |
| 291 |
} |
| 292 |
} else { |
| 293 |
if (opt.bEncrypt) { |
| 294 |
return IMG_ARTICLE_ENCRYPTED; |
| 295 |
} else { |
| 296 |
return IMG_ARTICLE; |
| 297 |
} |
| 298 |
} |
| 299 |
} |
| 300 |
|
| 301 |
DWORD TreeViewFileItem::ItemOrder() |
| 302 |
{ |
| 303 |
return ITEM_ORDER_FILE; |
| 304 |
} |
| 305 |
|
| 306 |
BOOL TreeViewFileItem::OpenMemo(MemoSelectView *pView, DWORD nOption) |
| 307 |
{ |
| 308 |
pView->GetManager()->GetMainFrame()->OpenDetailsView(loc.getURI(), nOption); |
| 309 |
return TRUE; |
| 310 |
} |
| 311 |
|
| 312 |
BOOL TreeViewFileItem::LoadMemo(MemoSelectView *pView, BOOL bAskPass) |
| 313 |
{ |
| 314 |
pView->GetManager()->GetMainFrame()->LoadMemo(loc.getURI(), bAskPass); |
| 315 |
return TRUE; |
| 316 |
} |
| 317 |
|
| 318 |
BOOL TreeViewFileItem::ExecApp(MemoManager *pMgr, MemoSelectView *pView, ExeAppType nType) |
| 319 |
{ |
| 320 |
if(!g_Repository.ExecuteAssoc(loc.getURI(), nType)) return FALSE; |
| 321 |
return TRUE; |
| 322 |
} |
| 323 |
|
| 324 |
///////////////////////////////////////////// |
| 325 |
///////////////////////////////////////////// |
| 326 |
// Folder |
| 327 |
///////////////////////////////////////////// |
| 328 |
///////////////////////////////////////////// |
| 329 |
|
| 330 |
TreeViewFolderItem::TreeViewFolderItem() : TreeViewItem(TRUE) |
| 331 |
{ |
| 332 |
} |
| 333 |
|
| 334 |
static BOOL IsSubFolder(LPCTSTR pSrc, LPCTSTR pDst) |
| 335 |
{ |
| 336 |
DWORD n = _tcslen(pSrc); |
| 337 |
if (_tcsncmp(pSrc, pDst, n) == 0) return TRUE; |
| 338 |
return FALSE; |
| 339 |
} |
| 340 |
|
| 341 |
BOOL TreeViewFolderItem::CopyMove(BOOL bCopy, MemoManager *pMgr, MemoSelectView *pView, LPCTSTR *ppErr) |
| 342 |
{ |
| 343 |
// Inactivate edit view |
| 344 |
pMgr->InactiveDetailsView(); |
| 345 |
if (!bCopy) { |
| 346 |
pView->TreeCollapse(GetViewItem()); |
| 347 |
} |
| 348 |
|
| 349 |
// convert to URI |
| 350 |
TomboURI sSrcURI, sDstURI; |
| 351 |
HTREEITEM hSrcItem = GetViewItem(); |
| 352 |
sSrcURI = *GetRealURI(); |
| 353 |
|
| 354 |
TomboURI sSelURI; |
| 355 |
const TomboURI *pCurSel = pView->GetCurrentSelectedURI(); |
| 356 |
if (pCurSel == NULL) return FALSE; |
| 357 |
sSelURI = *pCurSel; |
| 358 |
|
| 359 |
if (!g_Repository.GetAttachURI(&sSelURI, &sDstURI)) return FALSE; |
| 360 |
HTREEITEM hParentX = pView->ShowItemByURI(&sDstURI, FALSE, FALSE); |
| 361 |
|
| 362 |
URIOption opt; |
| 363 |
BOOL bResult; |
| 364 |
if (bCopy) { |
| 365 |
bResult = g_Repository.Copy(&sSrcURI, &sDstURI, &opt); |
| 366 |
} else { |
| 367 |
bResult = g_Repository.Move(&sSrcURI, &sDstURI, &opt); |
| 368 |
} |
| 369 |
if (!bResult) { |
| 370 |
if (GetLastError() == ERROR_TOMBO_W_OPERATION_NOT_PERMITTED) { |
| 371 |
*ppErr = MSG_DST_FOLDER_IS_SRC_SUBFOLDER; |
| 372 |
} |
| 373 |
return FALSE; |
| 374 |
} |
| 375 |
|
| 376 |
TString sHL; |
| 377 |
if (!g_Repository.GetHeadLine(&sSrcURI, &sHL)) return FALSE; |
| 378 |
pView->CreateNewFolder(hParentX, sHL.Get()); |
| 379 |
return TRUE; |
| 380 |
} |
| 381 |
|
| 382 |
BOOL TreeViewFolderItem::Move(MemoManager *pMgr, MemoSelectView *pView, LPCTSTR *ppErr) |
| 383 |
{ |
| 384 |
return CopyMove(FALSE, pMgr, pView, ppErr); |
| 385 |
} |
| 386 |
|
| 387 |
BOOL TreeViewFolderItem::Copy(MemoManager *pMgr, MemoSelectView *pView, LPCTSTR *ppErr) |
| 388 |
{ |
| 389 |
return CopyMove(TRUE, pMgr, pView, ppErr); |
| 390 |
} |
| 391 |
|
| 392 |
BOOL TreeViewFolderItem::Delete(MemoManager *pMgr, MemoSelectView *pView) |
| 393 |
{ |
| 394 |
TomboURI sURI; |
| 395 |
sURI = *GetRealURI(); |
| 396 |
|
| 397 |
if (sURI.IsRoot()) return TRUE; |
| 398 |
if (TomboMessageBox(NULL, MSG_CONFIRM_DEL_FOLDER, MSG_DEL_FOLDER_TTL, MB_ICONQUESTION | MB_OKCANCEL) != IDOK) return FALSE; |
| 399 |
|
| 400 |
// inactivate notes |
| 401 |
pMgr->InactiveDetailsView(); |
| 402 |
|
| 403 |
// Collapse tree |
| 404 |
pView->TreeCollapse(GetViewItem()); |
| 405 |
|
| 406 |
URIOption opt; |
| 407 |
if (!g_Repository.Delete(&sURI, &opt)) { |
| 408 |
switch(GetLastError()) { |
| 409 |
case ERROR_TOMBO_W_OTHERFILE_EXISTS: |
| 410 |
MessageBox(NULL, MSG_OTHER_FILE_EXISTS, TOMBO_APP_NAME, MB_ICONWARNING | MB_OK); |
| 411 |
break; |
| 412 |
case ERROR_TOMBO_E_RMFILE_FAILED: |
| 413 |
MessageBox(NULL, MSG_RMFILE_FAILED, TOMBO_APP_NAME, MB_ICONERROR | MB_OK); |
| 414 |
break; |
| 415 |
case ERROR_TOMBO_E_RMDIR_FAILED: |
| 416 |
MessageBox(NULL, MSG_RMDIR_FAILED, TOMBO_APP_NAME, MB_ICONERROR | MB_OK); |
| 417 |
break; |
| 418 |
default: |
| 419 |
MessageBox(NULL, MSG_DELETE_FAILED, TOMBO_APP_NAME, MB_ICONERROR | MB_OK); |
| 420 |
break; |
| 421 |
} |
| 422 |
return FALSE; |
| 423 |
} |
| 424 |
return TRUE; |
| 425 |
} |
| 426 |
|
| 427 |
BOOL TreeViewFolderItem::Encrypt(MemoManager *pMgr, MemoSelectView *pView) |
| 428 |
{ |
| 429 |
TomboURI sURI; |
| 430 |
sURI = *GetRealURI(); |
| 431 |
|
| 432 |
if (sURI.IsRoot()) return TRUE; |
| 433 |
if (TomboMessageBox(NULL, MSG_CONFIRM_ENCRYPT_FOLDER, MSG_CONFIRM_ENCRYPT_FOLDER_TTL, MB_ICONQUESTION | MB_OKCANCEL) != IDOK) return TRUE; |
| 434 |
|
| 435 |
pMgr->InactiveDetailsView(); |
| 436 |
pView->TreeCollapse(GetViewItem()); |
| 437 |
|
| 438 |
// encrypt request to repository |
| 439 |
URIOption opt(NOTE_OPTIONMASK_ENCRYPTED); |
| 440 |
opt.bEncrypt = TRUE; |
| 441 |
if (!g_Repository.SetOption(&sURI, &opt)) { |
| 442 |
switch(GetLastError()) { |
| 443 |
case ERROR_TOMBO_I_GET_PASSWORD_CANCELED: |
| 444 |
MessageBox(NULL, MSG_GET_PASS_FAILED, TOMBO_APP_NAME, MB_ICONINFORMATION | MB_OK); |
| 445 |
return TRUE; |
| 446 |
default: |
| 447 |
MessageBox(NULL, MSG_ENCRYPT_FAILED, TOMBO_APP_NAME, MB_ICONERROR | MB_OK); |
| 448 |
return FALSE; |
| 449 |
} |
| 450 |
} |
| 451 |
return TRUE; |
| 452 |
} |
| 453 |
|
| 454 |
BOOL TreeViewFolderItem::Decrypt(MemoManager *pMgr, MemoSelectView *pView) |
| 455 |
{ |
| 456 |
TomboURI sURI; |
| 457 |
sURI = *GetRealURI(); |
| 458 |
|
| 459 |
if (sURI.IsRoot()) return TRUE; |
| 460 |
if (TomboMessageBox(NULL, MSG_CONFIRM_DECRYPT_FOLDER, MSG_CONFIRM_DECRYPT_FOLDER_TTL, MB_ICONQUESTION | MB_OKCANCEL) != IDOK) return TRUE; |
| 461 |
|
| 462 |
pMgr->InactiveDetailsView(); |
| 463 |
pView->TreeCollapse(GetViewItem()); |
| 464 |
|
| 465 |
// decrypt request to repository |
| 466 |
URIOption opt(NOTE_OPTIONMASK_ENCRYPTED); |
| 467 |
opt.bEncrypt = FALSE; |
| 468 |
if (!g_Repository.SetOption(&sURI, &opt)) { |
| 469 |
switch(GetLastError()) { |
| 470 |
case ERROR_TOMBO_I_GET_PASSWORD_CANCELED: |
| 471 |
MessageBox(NULL, MSG_GET_PASS_FAILED, TOMBO_APP_NAME, MB_ICONINFORMATION | MB_OK); |
| 472 |
return TRUE; |
| 473 |
default: |
| 474 |
MessageBox(NULL, MSG_DECRYPT_FAILED, TOMBO_APP_NAME, MB_ICONERROR | MB_OK); |
| 475 |
return FALSE; |
| 476 |
} |
| 477 |
} |
| 478 |
return TRUE; |
| 479 |
} |
| 480 |
|
| 481 |
DWORD TreeViewFolderItem::GetIcon(MemoSelectView *pView, DWORD nStatus) |
| 482 |
{ |
| 483 |
if (nStatus & MEMO_VIEW_STATE_INIT) { |
| 484 |
return IMG_FOLDER; |
| 485 |
} |
| 486 |
|
| 487 |
// �X�e�[�^�X������ |
| 488 |
TV_ITEM ti; |
| 489 |
ti.mask = TVIF_STATE | TVIF_IMAGE; |
| 490 |
ti.hItem = GetViewItem(); |
| 491 |
ti.stateMask = TVIS_EXPANDED; |
| 492 |
pView->GetItem(&ti); |
| 493 |
|
| 494 |
BOOL bExpanded = ti.state & TVIS_EXPANDED; |
| 495 |
BOOL bCliped = pView->IsCliped(this); |
| 496 |
|
| 497 |
if (nStatus & MEMO_VIEW_STATE_CLIPED_SET) { |
| 498 |
bCliped = TRUE; |
| 499 |
} |
| 500 |
if (nStatus & MEMO_VIEW_STATE_CLIPED_CLEAR) { |
| 501 |
bCliped = FALSE; |
| 502 |
} |
| 503 |
if (nStatus & MEMO_VIEW_STATE_OPEN_SET) { |
| 504 |
bExpanded = TRUE; |
| 505 |
} |
| 506 |
if (nStatus & MEMO_VIEW_STATE_OPEN_CLEAR) { |
| 507 |
bExpanded = FALSE; |
| 508 |
} |
| 509 |
|
| 510 |
if (bCliped) { |
| 511 |
if (bExpanded) { |
| 512 |
return IMG_FOLDER_SEL_MASKED; |
| 513 |
} else { |
| 514 |
return IMG_FOLDER_MASKED; |
| 515 |
} |
| 516 |
} else { |
| 517 |
if (bExpanded) { |
| 518 |
return IMG_FOLDER_SEL; |
| 519 |
} else { |
| 520 |
return IMG_FOLDER; |
| 521 |
} |
| 522 |
} |
| 523 |
} |
| 524 |
|
| 525 |
BOOL TreeViewFolderItem::IsOperationEnabled(MemoSelectView *pView, OpType op) |
| 526 |
{ |
| 527 |
if (op == OpDelete || op == OpRename || op == OpCut || op == OpCopy) { |
| 528 |
HTREEITEM hParent = pView->GetParentItem(GetViewItem()); |
| 529 |
if (hParent == NULL) return FALSE; |
| 530 |
return TRUE; |
| 531 |
} else { |
| 532 |
DWORD nOpMatrix = OpEncrypt | OpDecrypt | OpNewMemo | OpNewFolder | OpPaste | OpGrep; |
| 533 |
return (nOpMatrix & op) != 0; |
| 534 |
} |
| 535 |
} |
| 536 |
|
| 537 |
BOOL TreeViewFolderItem::Rename(MemoManager *pMgr, MemoSelectView *pView, LPCTSTR pNewName) |
| 538 |
{ |
| 539 |
TomboURI sCurrentURI; |
| 540 |
sCurrentURI = *GetRealURI(); |
| 541 |
|
| 542 |
if (sCurrentURI.IsRoot()) return FALSE; |
| 543 |
|
| 544 |
pMgr->InactiveDetailsView(); |
| 545 |
pView->TreeCollapse(GetViewItem()); |
| 546 |
|
| 547 |
URIOption opt; |
| 548 |
if (!g_Repository.ChangeHeadLine(&sCurrentURI, pNewName, &opt)) { |
| 549 |
DWORD nErr = GetLastError(); |
| 550 |
switch (nErr) { |
| 551 |
case ERROR_NO_DATA: |
| 552 |
TomboMessageBox(NULL, MSG_NO_FOLDERNAME, TOMBO_APP_NAME, MB_ICONWARNING | MB_OK); |
| 553 |
break; |
| 554 |
case ERROR_ALREADY_EXISTS: |
| 555 |
TomboMessageBox(NULL, MSG_SAME_FOLDER, TOMBO_APP_NAME, MB_ICONWARNING | MB_OK); |
| 556 |
break; |
| 557 |
default: |
| 558 |
{ |
| 559 |
TCHAR buf[MAX_PATH]; |
| 560 |
wsprintf(buf, MSG_REN_FOLDER_FAILED, nErr); |
| 561 |
TomboMessageBox(NULL, buf, TOMBO_APP_NAME, MB_ICONERROR | MB_OK); |
| 562 |
} |
| 563 |
} |
| 564 |
return FALSE; |
| 565 |
} |
| 566 |
return TRUE; |
| 567 |
} |
| 568 |
|
| 569 |
DWORD TreeViewFolderItem::ItemOrder() |
| 570 |
{ |
| 571 |
return ITEM_ORDER_FOLDER; |
| 572 |
} |
| 573 |
|
| 574 |
|
| 575 |
BOOL TreeViewFolderItem::Expand(MemoSelectView *pView) |
| 576 |
{ |
| 577 |
HTREEITEM hParent = GetViewItem(); |
| 578 |
|
| 579 |
TomboURI sURI; |
| 580 |
sURI = *GetRealURI(); |
| 581 |
|
| 582 |
BOOL bLoose; |
| 583 |
URIList *pURIList = g_Repository.GetChild(&sURI, FALSE, TRUE, &bLoose); |
| 584 |
if (pURIList == NULL) return FALSE; |
| 585 |
AutoPointer<URIList> ap(pURIList); |
| 586 |
|
| 587 |
if (bLoose) { |
| 588 |
MessageBox(NULL, MSG_DECRYPT_IS_PARTIAL, TEXT("Warning"), MB_ICONWARNING | MB_OK); |
| 589 |
} |
| 590 |
|
| 591 |
DWORD n = pURIList->GetSize(); |
| 592 |
for (DWORD i = 0; i < n; i++) { |
| 593 |
URIOption opt(NOTE_OPTIONMASK_VALID); |
| 594 |
if (!g_Repository.GetOption(pURIList->GetURI(i), &opt)) return FALSE; |
| 595 |
if (opt.bFolder) { |
| 596 |
TreeViewFolderItem *pItem = new TreeViewFolderItem(); |
| 597 |
pItem->SetURI(pURIList->GetURI(i)); |
| 598 |
pView->InsertFolder(hParent, pURIList->GetTitle(i), pItem, TRUE); |
| 599 |
} else { |
| 600 |
if (!pView->InsertFile(hParent, pURIList->GetURI(i), pURIList->GetTitle(i), TRUE, FALSE)) return FALSE; |
| 601 |
} |
| 602 |
} |
| 603 |
|
| 604 |
return TRUE; |
| 605 |
} |
| 606 |
|
| 607 |
BOOL TreeViewFolderItem::ExecApp(MemoManager *pMgr, MemoSelectView *pView, ExeAppType nType) |
| 608 |
{ |
| 609 |
TomboURI sURI; |
| 610 |
sURI = *GetRealURI(); |
| 611 |
g_Repository.ExecuteAssoc(&sURI, nType); |
| 612 |
return TRUE; |
| 613 |
} |
| 614 |
|
| 615 |
///////////////////////////////////////////// |
| 616 |
///////////////////////////////////////////// |
| 617 |
// File link |
| 618 |
///////////////////////////////////////////// |
| 619 |
///////////////////////////////////////////// |
| 620 |
|
| 621 |
BOOL TreeViewFileLink::IsOperationEnabled(MemoSelectView *pView, OpType op) |
| 622 |
{ |
| 623 |
DWORD nOpMatrix = OpNewMemo | OpLink; |
| 624 |
return (nOpMatrix & op) != 0; |
| 625 |
} |
| 626 |
|
| 627 |
///////////////////////////////////////////// |
| 628 |
///////////////////////////////////////////// |
| 629 |
// Virtual folder(Root) |
| 630 |
///////////////////////////////////////////// |
| 631 |
///////////////////////////////////////////// |
| 632 |
|
| 633 |
TreeViewVirtualFolderRoot::TreeViewVirtualFolderRoot() : TreeViewFolderItem(), pDefaultURI(NULL) |
| 634 |
{ |
| 635 |
} |
| 636 |
|
| 637 |
TreeViewVirtualFolderRoot::~TreeViewVirtualFolderRoot() |
| 638 |
{ |
| 639 |
delete pDefaultURI; |
| 640 |
} |
| 641 |
|
| 642 |
BOOL TreeViewVirtualFolderRoot::Init(const TomboURI *pURI, VFManager *p) |
| 643 |
{ |
| 644 |
pDefaultURI = new TomboURI(); |
| 645 |
pDefaultURI->Init(TEXT("tombo://default/")); |
| 646 |
pManager = p; |
| 647 |
SetURI(pURI); |
| 648 |
return TRUE; |
| 649 |
} |
| 650 |
|
| 651 |
DWORD TreeViewVirtualFolderRoot::GetIcon(MemoSelectView *pView, DWORD nStatus) |
| 652 |
{ |
| 653 |
if (nStatus & MEMO_VIEW_STATE_INIT) { |
| 654 |
return IMG_VFOLDER; |
| 655 |
} |
| 656 |
|
| 657 |
// Get status |
| 658 |
TV_ITEM ti; |
| 659 |
ti.mask = TVIF_STATE | TVIF_IMAGE; |
| 660 |
ti.hItem = GetViewItem(); |
| 661 |
ti.stateMask = TVIS_EXPANDED; |
| 662 |
pView->GetItem(&ti); |
| 663 |
|
| 664 |
BOOL bExpanded = ti.state & TVIS_EXPANDED; |
| 665 |
|
| 666 |
if (nStatus & MEMO_VIEW_STATE_OPEN_SET) { |
| 667 |
bExpanded = TRUE; |
| 668 |
} |
| 669 |
if (nStatus & MEMO_VIEW_STATE_OPEN_CLEAR) { |
| 670 |
bExpanded = FALSE; |
| 671 |
} |
| 672 |
|
| 673 |
if (bExpanded) { |
| 674 |
return IMG_VFOLDER_SEL; |
| 675 |
} else { |
| 676 |
return IMG_VFOLDER; |
| 677 |
} |
| 678 |
} |
| 679 |
|
| 680 |
BOOL TreeViewVirtualFolderRoot::InsertVirtualFolder(MemoSelectView *pView, LPCTSTR pName, VFDirectoryGenerator *pGen, VFStore *pStore) |
| 681 |
{ |
| 682 |
HTREEITEM hParent = GetViewItem(); |
| 683 |
|
| 684 |
TreeViewVirtualFolder *pVf = new TreeViewVirtualFolder(); |
| 685 |
if (pVf == NULL) return FALSE; |
| 686 |
|
| 687 |
pVf->SetGenerator(pGen); |
| 688 |
pVf->SetStore(pStore); |
| 689 |
|
| 690 |
if (!pView->InsertFolder(hParent, pName, pVf, TRUE)) return FALSE; |
| 691 |
return TRUE; |
| 692 |
} |
| 693 |
|
| 694 |
class VFExpandListener : public VirtualFolderEnumListener { |
| 695 |
TreeViewVirtualFolderRoot *pRoot; |
| 696 |
MemoSelectView *pView; |
| 697 |
public: |
| 698 |
VFExpandListener(MemoSelectView *pv, TreeViewVirtualFolderRoot *pr) : pView(pv), pRoot(pr) {} |
| 699 |
|
| 700 |
BOOL ProcessStream(LPCTSTR pName, BOOL bPersit, VFDirectoryGenerator *pGen, VFStore *pStore); |
| 701 |
}; |
| 702 |
|
| 703 |
BOOL VFExpandListener::ProcessStream(LPCTSTR pName, BOOL bPersit, VFDirectoryGenerator *pGen, VFStore *pStore) |
| 704 |
{ |
| 705 |
return pRoot->InsertVirtualFolder(pView, pName, pGen, pStore); |
| 706 |
} |
| 707 |
|
| 708 |
BOOL TreeViewVirtualFolderRoot::Expand(MemoSelectView *pView) |
| 709 |
{ |
| 710 |
VFExpandListener vfel(pView, this); |
| 711 |
pManager->Enum(&vfel); |
| 712 |
|
| 713 |
return TRUE; |
| 714 |
} |
| 715 |
|
| 716 |
BOOL TreeViewVirtualFolderRoot::AddSearchResult(MemoSelectView *pView, const VFInfo *pInfo) |
| 717 |
{ |
| 718 |
HTREEITEM hParent = GetViewItem(); |
| 719 |
if (!pView->IsExpand(hParent)) { |
| 720 |
pView->ToggleExpandFolder(hParent, 0); |
| 721 |
} else { |
| 722 |
// insert tree manually |
| 723 |
VFExpandListener vfel(pView, this); |
| 724 |
pManager->RetrieveInfo(pInfo, &vfel); |
| 725 |
} |
| 726 |
return TRUE; |
| 727 |
} |
| 728 |
|
| 729 |
|
| 730 |
BOOL TreeViewVirtualFolderRoot::IsOperationEnabled(MemoSelectView *pView, OpType op) |
| 731 |
{ |
| 732 |
DWORD nOpMatrix = OpNewMemo; |
| 733 |
return (nOpMatrix & op) != 0; |
| 734 |
} |
| 735 |
|
| 736 |
const TomboURI *TreeViewVirtualFolderRoot::GetRealURI() const |
| 737 |
{ |
| 738 |
return pDefaultURI; |
| 739 |
} |
| 740 |
|
| 741 |
///////////////////////////////////////////// |
| 742 |
///////////////////////////////////////////// |
| 743 |
// Virtual folder (non-root) |
| 744 |
///////////////////////////////////////////// |
| 745 |
///////////////////////////////////////////// |
| 746 |
|
| 747 |
TreeViewVirtualFolder::TreeViewVirtualFolder() : TreeViewFolderItem(), pGenerator(NULL), pStore(NULL), pDefaultURI(NULL) |
| 748 |
{ |
| 749 |
pDefaultURI = new TomboURI(); |
| 750 |
pDefaultURI->Init(TEXT("tombo://default/")); |
| 751 |
} |
| 752 |
|
| 753 |
TreeViewVirtualFolder::~TreeViewVirtualFolder() |
| 754 |
{ |
| 755 |
if (pGenerator) { |
| 756 |
pGenerator->FreeObject(); |
| 757 |
delete pGenerator; |
| 758 |
} |
| 759 |
delete pDefaultURI; |
| 760 |
} |
| 761 |
|
| 762 |
DWORD TreeViewVirtualFolder::GetIcon(MemoSelectView *pView, DWORD nStatus) |
| 763 |
{ |
| 764 |
if (nStatus & MEMO_VIEW_STATE_INIT) { |
| 765 |
return IMG_VFOLDER; |
| 766 |
} |
| 767 |
|
| 768 |
// Get status |
| 769 |
TV_ITEM ti; |
| 770 |
ti.mask = TVIF_STATE | TVIF_IMAGE; |
| 771 |
ti.hItem = GetViewItem(); |
| 772 |
ti.stateMask = TVIS_EXPANDED; |
| 773 |
pView->GetItem(&ti); |
| 774 |
|
| 775 |
BOOL bExpanded = ti.state & TVIS_EXPANDED; |
| 776 |
|
| 777 |
if (nStatus & MEMO_VIEW_STATE_OPEN_SET) { |
| 778 |
bExpanded = TRUE; |
| 779 |
} |
| 780 |
if (nStatus & MEMO_VIEW_STATE_OPEN_CLEAR) { |
| 781 |
bExpanded = FALSE; |
| 782 |
} |
| 783 |
|
| 784 |
if (bExpanded) { |
| 785 |
return IMG_VFOLDER_SEL; |
| 786 |
} else { |
| 787 |
return IMG_VFOLDER; |
| 788 |
} |
| 789 |
} |
| 790 |
|
| 791 |
BOOL TreeViewVirtualFolder::SetGenerator(VFDirectoryGenerator *p) |
| 792 |
{ |
| 793 |
pGenerator = p; |
| 794 |
return TRUE; |
| 795 |
} |
| 796 |
|
| 797 |
BOOL TreeViewVirtualFolder::SetStore(VFStore *p) |
| 798 |
{ |
| 799 |
pStore = p; |
| 800 |
return TRUE; |
| 801 |
} |
| 802 |
|
| 803 |
BOOL TreeViewVirtualFolder::Expand(MemoSelectView *pView) |
| 804 |
{ |
| 805 |
HTREEITEM hItem = GetViewItem(); |
| 806 |
|
| 807 |
// scanning. |
| 808 |
if (!pGenerator || !pStore || |
| 809 |
!pGenerator->Prepare() || |
| 810 |
!pGenerator->Activate() || |
| 811 |
!pGenerator->PostActivate()) { |
| 812 |
return FALSE; |
| 813 |
} |
| 814 |
|
| 815 |
// Insert notes to tree |
| 816 |
DWORD n = pStore->NumItem(); |
| 817 |
VFNote *pNote; |
| 818 |
for (DWORD i = 0; i < n; i++) { |
| 819 |
pNote = pStore->GetNote(i); |
| 820 |
LPCTSTR pTitle = pNote->GetTitle(); |
| 821 |
pView->InsertFile(hItem, pNote->GetURI(), pTitle, TRUE, TRUE); |
| 822 |
} |
| 823 |
pStore->FreeArray(); |
| 824 |
return TRUE; |
| 825 |
} |
| 826 |
|
| 827 |
BOOL TreeViewVirtualFolder::IsOperationEnabled(MemoSelectView *pView, OpType op) |
| 828 |
{ |
| 829 |
DWORD nOpMatrix = OpNewMemo; |
| 830 |
return (nOpMatrix & op) != 0; |
| 831 |
} |
| 832 |
|
| 833 |
const TomboURI *TreeViewVirtualFolder::GetRealURI() const |
| 834 |
{ |
| 835 |
return pDefaultURI; |
| 836 |
} |