ciderpress/app/RenameVolumeDialog.cpp
Andy McFadden d8223dbcfd Relocate method comments
This moves method comments from the .cpp file to the .h file,
where users of the methods can find them.  This also makes it
possible for the IDE to show the comments when you mouse-hover over
the method name, though Visual Studio is a bit weak in this regard.

Also, added "override" keywords on overridden methods.  Reasonably
current versions of popular compilers seem to support this.

Also, don't have the return type on a separate line in the .cpp file.
The motivation for the practice -- quickly finding a method definition
with "^name" -- is less useful in C++ than C, and modern IDEs provide
more convenient ways to do the same thing.

Also, do some more conversion from unsigned types to uintXX_t.

This commit is primarily for the "app" directory.
2014-11-21 22:33:39 -08:00

149 lines
4.2 KiB
C++

/*
* 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"
#include "HelpTopics.h"
BEGIN_MESSAGE_MAP(RenameVolumeDialog, CDialog)
ON_NOTIFY(TVN_SELCHANGED, IDC_RENAMEVOL_TREE, OnSelChanged)
ON_BN_CLICKED(IDHELP, OnHelp)
ON_WM_HELPINFO()
END_MESSAGE_MAP()
BOOL RenameVolumeDialog::OnInitDialog(void)
{
/* do the DoDataExchange stuff */
CDialog::OnInitDialog();
CTreeCtrl* pTree = (CTreeCtrl*) GetDlgItem(IDC_RENAMEVOL_TREE);
DiskImgLib::DiskFS* pDiskFS = fpArchive->GetDiskFS();
ASSERT(pTree != NULL);
fDiskFSTree.fIncludeSubdirs = false;
fDiskFSTree.fExpandDepth = -1;
if (!fDiskFSTree.BuildTree(pDiskFS, pTree)) {
LOGI("Tree load failed!");
OnCancel();
}
int count = pTree->GetCount();
LOGI("ChooseAddTargetDialog tree has %d items", count);
/* select the default text and set the focus */
CEdit* pEdit = (CEdit*) GetDlgItem(IDC_RENAMEVOL_NEW);
ASSERT(pEdit != NULL);
pEdit->SetSel(0, -1);
pEdit->SetFocus();
return FALSE; // we set the focus
}
void RenameVolumeDialog::DoDataExchange(CDataExchange* pDX)
{
CString msg, failed;
//DiskImgLib::DiskFS* pDiskFS = fpArchive->GetDiskFS();
failed.LoadString(IDS_MB_APP_NAME);
/* 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;
appName.LoadString(IDS_MB_APP_NAME);
HTREEITEM selected;
selected = pTree->GetSelectedItem();
if (selected == NULL) {
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;
fail:
ASSERT(!msg.IsEmpty());
MessageBox(msg, failed, MB_OK);
pDX->Fail();
return;
}
void RenameVolumeDialog::OnSelChanged(NMHDR* pnmh, LRESULT* pResult)
{
CTreeCtrl* pTree = (CTreeCtrl*) GetDlgItem(IDC_RENAMEVOL_TREE);
HTREEITEM selected;
CString newText;
selected = pTree->GetSelectedItem();
if (selected != NULL) {
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);
ASSERT(pEdit != NULL);
pEdit->SetWindowText(newText);
pEdit->SetSel(0, -1);
*pResult = 0;
}
BOOL RenameVolumeDialog::OnHelpInfo(HELPINFO* lpHelpInfo)
{
WinHelp((DWORD) lpHelpInfo->iCtrlId, HELP_CONTEXTPOPUP);
return TRUE; // yes, we handled it
}
void RenameVolumeDialog::OnHelp(void)
{
WinHelp(HELP_TOPIC_RENAME_VOLUME, HELP_CONTEXT);
}