1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
|
// PanelFolderChange.cpp
#include "StdAfx.h"
#include "Common/StringConvert.h"
#include "Common/Wildcard.h"
#include "Windows/PropVariant.h"
#include "../../PropID.h"
#ifdef UNDER_CE
#include "FSFolder.h"
#else
#include "FSDrives.h"
#endif
#include "LangUtils.h"
#include "ListViewDialog.h"
#include "Panel.h"
#include "RootFolder.h"
#include "ViewSettings.h"
#include "resource.h"
using namespace NWindows;
using namespace NFile;
using namespace NFind;
void CPanel::SetToRootFolder()
{
_folder.Release();
_library.Free();
CRootFolder *rootFolderSpec = new CRootFolder;
_folder = rootFolderSpec;
rootFolderSpec->Init();
}
HRESULT CPanel::BindToPath(const UString &fullPath, const UString &arcFormat, bool &archiveIsOpened, bool &encrypted)
{
archiveIsOpened = false;
encrypted = false;
CDisableTimerProcessing disableTimerProcessing1(*this);
printf("CPanel::BindToPath(%ls)\n",(const wchar_t *)fullPath);
if (_parentFolders.Size() > 0)
{
const UString &virtPath = _parentFolders.Back().VirtualPath;
if (fullPath.Left(virtPath.Length()) == virtPath)
{
for (;;)
{
CMyComPtr<IFolderFolder> newFolder;
HRESULT res = _folder->BindToParentFolder(&newFolder);
if (!newFolder || res != S_OK)
break;
_folder = newFolder;
}
UStringVector parts;
SplitPathToParts(fullPath.Mid(virtPath.Length()), parts);
for (int i = 0; i < parts.Size(); i++)
{
const UString &s = parts[i];
if ((i == 0 || i == parts.Size() - 1) && s.IsEmpty())
continue;
CMyComPtr<IFolderFolder> newFolder;
HRESULT res = _folder->BindToFolder(s, &newFolder);
if (!newFolder || res != S_OK)
break;
_folder = newFolder;
}
return S_OK;
}
}
CloseOpenFolders();
UString sysPath = fullPath;
CFileInfoW fileInfo;
UStringVector reducedParts;
while (!sysPath.IsEmpty())
{
if (fileInfo.Find(sysPath))
break;
int pos = sysPath.ReverseFind(WCHAR_PATH_SEPARATOR);
if (pos < 0)
sysPath.Empty();
else
{
if (reducedParts.Size() > 0 || pos < sysPath.Length() - 1)
reducedParts.Add(sysPath.Mid(pos + 1));
sysPath = sysPath.Left(pos);
}
}
SetToRootFolder();
CMyComPtr<IFolderFolder> newFolder;
if (sysPath.IsEmpty())
{
if (_folder->BindToFolder(fullPath, &newFolder) == S_OK)
_folder = newFolder;
}
else if (fileInfo.IsDir())
{
NName::NormalizeDirPathPrefix(sysPath);
if (_folder->BindToFolder(sysPath, &newFolder) == S_OK)
_folder = newFolder;
}
else
{
UString dirPrefix;
if (!NDirectory::GetOnlyDirPrefix(sysPath, dirPrefix))
dirPrefix.Empty();
if (_folder->BindToFolder(dirPrefix, &newFolder) == S_OK)
{
_folder = newFolder;
LoadFullPath();
UString fileName;
if (NDirectory::GetOnlyName(sysPath, fileName))
{
HRESULT res = OpenItemAsArchive(fileName, arcFormat, encrypted);
if (res != S_FALSE)
{
RINOK(res);
}
/*
if (res == E_ABORT)
return res;
*/
if (res == S_OK)
{
archiveIsOpened = true;
for (int i = reducedParts.Size() - 1; i >= 0; i--)
{
CMyComPtr<IFolderFolder> newFolder;
_folder->BindToFolder(reducedParts[i], &newFolder);
if (!newFolder)
break;
_folder = newFolder;
}
}
}
}
}
return S_OK;
}
HRESULT CPanel::BindToPathAndRefresh(const UString &path)
{
CDisableTimerProcessing disableTimerProcessing1(*this);
bool archiveIsOpened, encrypted;
RINOK(BindToPath(path, UString(), archiveIsOpened, encrypted));
RefreshListCtrl(UString(), -1, true, UStringVector());
return S_OK;
}
void CPanel::SetBookmark(int index)
{
_appState->FastFolders.SetString(index, _currentFolderPrefix);
}
void CPanel::OpenBookmark(int index)
{
BindToPathAndRefresh(_appState->FastFolders.GetString(index));
}
UString GetFolderPath(IFolderFolder *folder)
{
NCOM::CPropVariant prop;
if (folder->GetFolderProperty(kpidPath, &prop) == S_OK)
if (prop.vt == VT_BSTR)
return (wchar_t *)prop.bstrVal;
return UString();
}
void CPanel::LoadFullPath()
{
_currentFolderPrefix.Empty();
for (int i = 0; i < _parentFolders.Size(); i++)
{
const CFolderLink &folderLink = _parentFolders[i];
_currentFolderPrefix += GetFolderPath(folderLink.ParentFolder);
_currentFolderPrefix += folderLink.ItemName;
_currentFolderPrefix += WCHAR_PATH_SEPARATOR;
}
if (_folder)
_currentFolderPrefix += GetFolderPath(_folder);
}
static int GetRealIconIndex(LPCWSTR path, DWORD attributes)
{
int index = -1;
if (GetRealIconIndex(path, attributes, index) != 0)
return index;
return -1;
}
void CPanel::LoadFullPathAndShow()
{
LoadFullPath();
_appState->FolderHistory.AddString(_currentFolderPrefix);
#ifdef _WIN32
_headerComboBox.SetText(_currentFolderPrefix);
#else
{
extern const TCHAR * nameWindowToUnix(const TCHAR * lpFileName);
UString tmp = nameWindowToUnix(_currentFolderPrefix);
_headerComboBox.SetText(tmp);
}
#endif
#ifdef _WIN32 // FIXME
COMBOBOXEXITEM item;
item.mask = 0;
UString path = _currentFolderPrefix;
if (path.Length() >
#ifdef _WIN32
3
#else
1
#endif
&& path[path.Length() - 1] == WCHAR_PATH_SEPARATOR)
path.Delete(path.Length() - 1);
CFileInfoW info;
DWORD attrib = FILE_ATTRIBUTE_DIRECTORY;
if (info.Find(path))
attrib = info.Attrib;
item.iImage = GetRealIconIndex(path, attrib);
if (item.iImage >= 0)
{
item.iSelectedImage = item.iImage;
item.mask |= (CBEIF_IMAGE | CBEIF_SELECTEDIMAGE);
}
item.iItem = -1;
_headerComboBox.SetItem(&item);
#endif
RefreshTitle();
}
#ifndef UNDER_CE
LRESULT CPanel::OnNotifyComboBoxEnter(const UString &s)
{
if (BindToPathAndRefresh(GetUnicodeString(s)) == S_OK)
{
// FIXME PostMessage(kSetFocusToListView);
return TRUE;
}
return FALSE;
}
bool CPanel::OnNotifyComboBoxEndEdit(PNMCBEENDEDITW info, LRESULT &result)
{
if (info->iWhy == CBENF_ESCAPE)
{
_headerComboBox.SetText(_currentFolderPrefix);
// FIXME PostMessage(kSetFocusToListView);
result = FALSE;
return true;
}
/*
if (info->iWhy == CBENF_DROPDOWN)
{
result = FALSE;
return true;
}
*/
if (info->iWhy == CBENF_RETURN)
{
// When we use Edit control and press Enter.
UString s;
_headerComboBox.GetText(s);
result = OnNotifyComboBoxEnter(s);
return true;
}
return false;
}
#endif
#ifndef _UNICODE
bool CPanel::OnNotifyComboBoxEndEdit(PNMCBEENDEDIT info, LRESULT &result)
{
if (info->iWhy == CBENF_ESCAPE)
{
_headerComboBox.SetText(_currentFolderPrefix);
PostMessage(kSetFocusToListView);
result = FALSE;
return true;
}
/*
if (info->iWhy == CBENF_DROPDOWN)
{
result = FALSE;
return true;
}
*/
if (info->iWhy == CBENF_RETURN)
{
UString s;
_headerComboBox.GetText(s);
// GetUnicodeString(info->szText)
result = OnNotifyComboBoxEnter(s);
return true;
}
return false;
}
#endif
#ifdef _WIN32
void CPanel::AddComboBoxItem(const UString &name, int iconIndex, int indent, bool addToList)
{
#ifdef UNDER_CE
UString s;
iconIndex = iconIndex;
for (int i = 0; i < indent; i++)
s += L" ";
_headerComboBox.AddString(s + name);
#else
COMBOBOXEXITEMW item;
item.mask = CBEIF_TEXT | CBEIF_INDENT;
item.iSelectedImage = item.iImage = iconIndex;
if (iconIndex >= 0)
item.mask |= (CBEIF_IMAGE | CBEIF_SELECTEDIMAGE);
item.iItem = -1;
item.iIndent = indent;
item.pszText = (LPWSTR)(LPCWSTR)name;
_headerComboBox.InsertItem(&item);
#endif
if (addToList)
ComboBoxPaths.Add(name);
}
extern UString RootFolder_GetName_Computer(int &iconIndex);
extern UString RootFolder_GetName_Network(int &iconIndex);
extern UString RootFolder_GetName_Documents(int &iconIndex);
#endif
bool CPanel::OnComboBoxCommand(UINT code, LPARAM /* param */, LRESULT &result)
{
#ifdef _WIN32 // FIXME
result = FALSE;
switch(code)
{
case CBN_DROPDOWN:
{
ComboBoxPaths.Clear();
_headerComboBox.ResetContent();
int i;
UStringVector pathParts;
SplitPathToParts(_currentFolderPrefix, pathParts);
UString sumPass;
if (!pathParts.IsEmpty())
pathParts.DeleteBack();
for (i = 0; i < pathParts.Size(); i++)
{
UString name = pathParts[i];
sumPass += name;
sumPass += WCHAR_PATH_SEPARATOR;
CFileInfoW info;
DWORD attrib = FILE_ATTRIBUTE_DIRECTORY;
if (info.Find(sumPass))
attrib = info.Attrib;
AddComboBoxItem(name.IsEmpty() ? L"\\" : name, GetRealIconIndex(sumPass, attrib), i, false);
ComboBoxPaths.Add(sumPass);
}
#ifndef UNDER_CE
int iconIndex;
UString name;
name = RootFolder_GetName_Documents(iconIndex);
AddComboBoxItem(name, iconIndex, 0, true);
name = RootFolder_GetName_Computer(iconIndex);
AddComboBoxItem(name, iconIndex, 0, true);
UStringVector driveStrings;
MyGetLogicalDriveStrings(driveStrings);
for (i = 0; i < driveStrings.Size(); i++)
{
UString s = driveStrings[i];
ComboBoxPaths.Add(s);
int iconIndex = GetRealIconIndex(s, 0);
if (s.Length() > 0 && s[s.Length() - 1] == WCHAR_PATH_SEPARATOR)
s.Delete(s.Length() - 1);
AddComboBoxItem(s, iconIndex, 1, false);
}
name = RootFolder_GetName_Network(iconIndex);
AddComboBoxItem(name, iconIndex, 0, true);
#endif
return false;
}
case CBN_SELENDOK:
{
code = code;
int index = _headerComboBox.GetCurSel();
if (index >= 0)
{
UString pass = ComboBoxPaths[index];
_headerComboBox.SetCurSel(-1);
// _headerComboBox.SetText(pass); // it's fix for seclecting by mouse.
if (BindToPathAndRefresh(pass) == S_OK)
{
PostMessage(kSetFocusToListView);
#ifdef UNDER_CE
PostMessage(kRefreshHeaderComboBox);
#endif
return true;
}
}
return false;
}
/*
case CBN_CLOSEUP:
{
LoadFullPathAndShow();
true;
}
case CBN_SELCHANGE:
{
// LoadFullPathAndShow();
return true;
}
*/
}
#endif
return false;
}
bool CPanel::OnNotifyComboBox(LPNMHDR header, LRESULT &result)
{
#ifndef UNDER_CE
switch(header->code)
{
case CBEN_BEGINEDIT:
{
_lastFocusedIsList = false;
_panelCallback->PanelWasFocused();
break;
}
#ifdef _WIN32
#ifndef _UNICODE
case CBEN_ENDEDIT:
{
return OnNotifyComboBoxEndEdit((PNMCBEENDEDIT)header, result);
}
#endif
#endif // #ifdef _WIN32
case CBEN_ENDEDITW:
{
return OnNotifyComboBoxEndEdit((PNMCBEENDEDITW)header, result);
}
}
#endif
return false;
}
void CPanel::FoldersHistory()
{
CListViewDialog listViewDialog;
listViewDialog.DeleteIsAllowed = true;
listViewDialog.Title = LangString(IDS_FOLDERS_HISTORY, 0x03020260);
_appState->FolderHistory.GetList(listViewDialog.Strings);
if (listViewDialog.Create(GetParent()) == IDCANCEL)
return;
UString selectString;
if (listViewDialog.StringsWereChanged)
{
_appState->FolderHistory.RemoveAll();
for (int i = listViewDialog.Strings.Size() - 1; i >= 0; i--)
_appState->FolderHistory.AddString(listViewDialog.Strings[i]);
if (listViewDialog.FocusedItemIndex >= 0)
selectString = listViewDialog.Strings[listViewDialog.FocusedItemIndex];
}
else
{
if (listViewDialog.FocusedItemIndex >= 0)
selectString = listViewDialog.Strings[listViewDialog.FocusedItemIndex];
}
if (listViewDialog.FocusedItemIndex >= 0)
BindToPathAndRefresh(selectString);
}
void CPanel::OpenParentFolder()
{
printf("CPanel::OpenParentFolder\n");
LoadFullPath(); // Maybe we don't need it ??
UString focucedName;
if (!_currentFolderPrefix.IsEmpty() &&
_currentFolderPrefix.Back() == WCHAR_PATH_SEPARATOR)
{
focucedName = _currentFolderPrefix;
focucedName.DeleteBack();
if (focucedName != L"\\\\.")
{
int pos = focucedName.ReverseFind(WCHAR_PATH_SEPARATOR);
if (pos >= 0)
focucedName = focucedName.Mid(pos + 1);
}
}
printf("CPanel::OpenParentFolder focucedName=%ls\n",(const wchar_t *)focucedName);
CDisableTimerProcessing disableTimerProcessing1(*this);
CMyComPtr<IFolderFolder> newFolder;
_folder->BindToParentFolder(&newFolder);
if (newFolder)
_folder = newFolder;
else
{
if (_parentFolders.IsEmpty())
{
SetToRootFolder();
if (focucedName.IsEmpty())
focucedName = GetItemName(0);
}
else
{
_folder.Release();
_library.Free();
CFolderLink &link = _parentFolders.Back();
_folder = link.ParentFolder;
_library.Attach(link.Library.Detach());
focucedName = link.ItemName;
if (_parentFolders.Size() > 1)
OpenParentArchiveFolder();
_parentFolders.DeleteBack();
if (_parentFolders.IsEmpty())
_flatMode = _flatModeForDisk;
}
}
UStringVector selectedItems;
/*
if (!focucedName.IsEmpty())
selectedItems.Add(focucedName);
*/
LoadFullPath();
// ::SetCurrentDirectory(::_currentFolderPrefix);
RefreshListCtrl(focucedName, -1, true, selectedItems);
_listView.EnsureVisible(_listView.GetFocusedItem(), false);
RefreshStatusBar();
printf("CPanel::OpenParentFolder-end\n");
}
void CPanel::CloseOpenFolders()
{
while (_parentFolders.Size() > 0)
{
_folder.Release();
_library.Free();
_folder = _parentFolders.Back().ParentFolder;
_library.Attach(_parentFolders.Back().Library.Detach());
if (_parentFolders.Size() > 1)
OpenParentArchiveFolder();
_parentFolders.DeleteBack();
}
_flatMode = _flatModeForDisk;
_folder.Release();
_library.Free();
}
void CPanel::OpenRootFolder()
{
CDisableTimerProcessing disableTimerProcessing1(*this);
_parentFolders.Clear();
SetToRootFolder();
RefreshListCtrl(UString(), -1, true, UStringVector());
// ::SetCurrentDirectory(::_currentFolderPrefix);
/*
BeforeChangeFolder();
_currentFolderPrefix.Empty();
AfterChangeFolder();
SetCurrentPathText();
RefreshListCtrl(UString(), 0, UStringVector());
_listView.EnsureVisible(_listView.GetFocusedItem(), false);
*/
}
void CPanel::OpenDrivesFolder()
{
CloseOpenFolders();
#ifdef UNDER_CE
NFsFolder::CFSFolder *folderSpec = new NFsFolder::CFSFolder;
_folder = folderSpec;
folderSpec->InitToRoot();
#else
CFSDrives *folderSpec = new CFSDrives;
_folder = folderSpec;
folderSpec->Init();
#endif
RefreshListCtrl();
}
void CPanel::OpenFolder(int index)
{
if (index == kParentIndex)
{
OpenParentFolder();
return;
}
CMyComPtr<IFolderFolder> newFolder;
_folder->BindToFolder(index, &newFolder);
if (!newFolder)
return;
_folder = newFolder;
LoadFullPath();
// ::SetCurrentDirectory(::_currentFolderPrefix);
RefreshListCtrl();
UINT state = LVIS_SELECTED;
_listView.SetItemState(_listView.GetFocusedItem(), state, state);
_listView.EnsureVisible(_listView.GetFocusedItem(), false);
}
|