2007-03-27 17:47:10 +00:00
|
|
|
/*
|
|
|
|
* CiderPress
|
|
|
|
* Copyright (C) 2007 by faddenSoft, LLC. All Rights Reserved.
|
|
|
|
* See the file LICENSE for distribution terms.
|
|
|
|
*/
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "RenameVolumeDialog.h"
|
|
|
|
#include "DiskFSTree.h"
|
|
|
|
#include "DiskArchive.h"
|
|
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(RenameVolumeDialog, CDialog)
|
2014-11-04 00:26:53 +00:00
|
|
|
ON_NOTIFY(TVN_SELCHANGED, IDC_RENAMEVOL_TREE, OnSelChanged)
|
|
|
|
ON_BN_CLICKED(IDHELP, OnHelp)
|
|
|
|
ON_WM_HELPINFO()
|
2007-03-27 17:47:10 +00:00
|
|
|
END_MESSAGE_MAP()
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
BOOL RenameVolumeDialog::OnInitDialog(void)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
/* do the DoDataExchange stuff */
|
|
|
|
CDialog::OnInitDialog();
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
CTreeCtrl* pTree = (CTreeCtrl*) GetDlgItem(IDC_RENAMEVOL_TREE);
|
|
|
|
DiskImgLib::DiskFS* pDiskFS = fpArchive->GetDiskFS();
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(pTree != NULL);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
fDiskFSTree.fIncludeSubdirs = false;
|
|
|
|
fDiskFSTree.fExpandDepth = -1;
|
|
|
|
if (!fDiskFSTree.BuildTree(pDiskFS, pTree)) {
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI("Tree load failed!");
|
2014-11-04 00:26:53 +00:00
|
|
|
OnCancel();
|
|
|
|
}
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
int count = pTree->GetCount();
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI("ChooseAddTargetDialog tree has %d items", count);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
/* select the default text and set the focus */
|
|
|
|
CEdit* pEdit = (CEdit*) GetDlgItem(IDC_RENAMEVOL_NEW);
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(pEdit != NULL);
|
2014-11-04 00:26:53 +00:00
|
|
|
pEdit->SetSel(0, -1);
|
|
|
|
pEdit->SetFocus();
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
return FALSE; // we set the focus
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
void RenameVolumeDialog::DoDataExchange(CDataExchange* pDX)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
CString msg, failed;
|
|
|
|
//DiskImgLib::DiskFS* pDiskFS = fpArchive->GetDiskFS();
|
|
|
|
|
2014-12-16 19:04:31 +00:00
|
|
|
CheckedLoadString(&failed, IDS_MB_APP_NAME);
|
2014-11-04 00:26:53 +00:00
|
|
|
|
|
|
|
/* put fNewName last so it gets the focus after failure */
|
|
|
|
DDX_Text(pDX, IDC_RENAMEVOL_NEW, fNewName);
|
|
|
|
|
|
|
|
/* validate the path field */
|
|
|
|
if (pDX->m_bSaveAndValidate) {
|
|
|
|
/*
|
|
|
|
* Make sure they chose a volume that can be modified.
|
|
|
|
*/
|
|
|
|
CTreeCtrl* pTree = (CTreeCtrl*) GetDlgItem(IDC_RENAMEVOL_TREE);
|
|
|
|
CString errMsg, appName;
|
2014-12-16 19:04:31 +00:00
|
|
|
CheckedLoadString(&appName, IDS_MB_APP_NAME);
|
2014-11-04 00:26:53 +00:00
|
|
|
|
|
|
|
HTREEITEM selected;
|
|
|
|
selected = pTree->GetSelectedItem();
|
2014-11-18 05:13:13 +00:00
|
|
|
if (selected == NULL) {
|
2014-11-04 00:26:53 +00:00
|
|
|
errMsg = "Please select a disk to rename.";
|
|
|
|
MessageBox(errMsg, appName, MB_OK);
|
|
|
|
pDX->Fail();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DiskFSTree::TargetData* pTargetData;
|
|
|
|
pTargetData = (DiskFSTree::TargetData*) pTree->GetItemData(selected);
|
|
|
|
if (!pTargetData->selectable) {
|
|
|
|
errMsg = "You can't rename that volume.";
|
|
|
|
MessageBox(errMsg, appName, MB_OK);
|
|
|
|
pDX->Fail();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ASSERT(pTargetData->kind == DiskFSTree::kTargetDiskFS);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Verify that the new name is okay. (Do this *after* checking the
|
|
|
|
* volume above to avoid spurious complaints about unsupported
|
|
|
|
* filesystems.)
|
|
|
|
*/
|
|
|
|
if (fNewName.IsEmpty()) {
|
|
|
|
msg = "You must specify a new name.";
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
msg = fpArchive->TestVolumeName(pTargetData->pDiskFS, fNewName);
|
|
|
|
if (!msg.IsEmpty())
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Looks good. Fill in the answer.
|
|
|
|
*/
|
|
|
|
fpChosenDiskFS = pTargetData->pDiskFS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
|
|
|
fail:
|
2014-11-04 00:26:53 +00:00
|
|
|
ASSERT(!msg.IsEmpty());
|
|
|
|
MessageBox(msg, failed, MB_OK);
|
|
|
|
pDX->Fail();
|
|
|
|
return;
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
void RenameVolumeDialog::OnSelChanged(NMHDR* pnmh, LRESULT* pResult)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
CTreeCtrl* pTree = (CTreeCtrl*) GetDlgItem(IDC_RENAMEVOL_TREE);
|
|
|
|
HTREEITEM selected;
|
|
|
|
CString newText;
|
|
|
|
|
|
|
|
selected = pTree->GetSelectedItem();
|
2014-11-18 05:13:13 +00:00
|
|
|
if (selected != NULL) {
|
2014-11-04 00:26:53 +00:00
|
|
|
DiskFSTree::TargetData* pTargetData;
|
|
|
|
pTargetData = (DiskFSTree::TargetData*) pTree->GetItemData(selected);
|
|
|
|
if (pTargetData->selectable) {
|
|
|
|
newText = pTargetData->pDiskFS->GetBareVolumeName();
|
|
|
|
} else {
|
|
|
|
newText = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CEdit* pEdit = (CEdit*) GetDlgItem(IDC_RENAMEVOL_NEW);
|
2014-11-18 05:13:13 +00:00
|
|
|
ASSERT(pEdit != NULL);
|
2014-11-04 00:26:53 +00:00
|
|
|
pEdit->SetWindowText(newText);
|
|
|
|
pEdit->SetSel(0, -1);
|
|
|
|
|
|
|
|
*pResult = 0;
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|