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 "RenameEntryDialog.h"
|
|
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(RenameEntryDialog, CDialog)
|
2014-11-04 00:26:53 +00:00
|
|
|
ON_WM_HELPINFO()
|
|
|
|
ON_COMMAND(IDHELP, OnHelp)
|
|
|
|
ON_BN_CLICKED(IDC_RENAME_SKIP, OnSkip)
|
2007-03-27 17:47:10 +00:00
|
|
|
END_MESSAGE_MAP()
|
|
|
|
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
BOOL RenameEntryDialog::OnInitDialog(void)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
ASSERT(fBasePath.IsEmpty());
|
|
|
|
fOldFile = fOldName;
|
|
|
|
fFssepStr = fFssep;
|
|
|
|
|
|
|
|
CEdit* pEdit = (CEdit*) GetDlgItem(IDC_RENAME_PATHSEP);
|
|
|
|
pEdit->SetReadOnly(!fCanChangeFssep);
|
|
|
|
pEdit->LimitText(1);
|
|
|
|
|
|
|
|
/* if they can't rename the full path, only give them the file name */
|
|
|
|
if (fCanRenameFullPath || fFssep == '\0') {
|
|
|
|
fNewName = fOldName;
|
|
|
|
// fBasePath is empty
|
|
|
|
} else {
|
|
|
|
int offset;
|
|
|
|
|
|
|
|
offset = fOldName.ReverseFind(fFssep);
|
|
|
|
if (offset < fOldName.GetLength()) {
|
|
|
|
fBasePath = fOldName.Left(offset);
|
|
|
|
fNewName = fOldName.Right(fOldName.GetLength() - (offset+1));
|
|
|
|
} else {
|
|
|
|
/* weird -- filename ended with an fssep? */
|
|
|
|
ASSERT(false); // debugbreak
|
|
|
|
// fBasePath is empty
|
|
|
|
fNewName = fOldName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* do the DoDataExchange stuff */
|
|
|
|
CDialog::OnInitDialog();
|
|
|
|
|
|
|
|
/* select the editable text and set the focus */
|
|
|
|
pEdit = (CEdit*) GetDlgItem(IDC_RENAME_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();
|
|
|
|
|
|
|
|
return FALSE; // we set the focus
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:18:20 +00:00
|
|
|
void RenameEntryDialog::DoDataExchange(CDataExchange* pDX)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
CString msg, failed;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-12-16 19:04:31 +00:00
|
|
|
CheckedLoadString(&failed, IDS_MB_APP_NAME);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
/* fNewName must come last, or the focus will be set on the wrong field
|
|
|
|
when we return after failure */
|
|
|
|
DDX_Text(pDX, IDC_RENAME_OLD, fOldFile);
|
|
|
|
DDX_Text(pDX, IDC_RENAME_PATHSEP, fFssepStr);
|
|
|
|
DDX_Text(pDX, IDC_RENAME_NEW, fNewName);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
/* validate the path field */
|
|
|
|
if (pDX->m_bSaveAndValidate) {
|
|
|
|
if (fNewName.IsEmpty()) {
|
|
|
|
msg = "You must specify a new name.";
|
|
|
|
goto fail;
|
|
|
|
}
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
msg = fpArchive->TestPathName(fpEntry, fBasePath, fNewName, fFssep);
|
|
|
|
if (!msg.IsEmpty())
|
|
|
|
goto fail;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
if (fFssepStr.IsEmpty())
|
|
|
|
fFssep = '\0';
|
|
|
|
else
|
2014-11-18 22:30:51 +00:00
|
|
|
fFssep = (char) fFssepStr.GetAt(0); // could be '\0', that's okay
|
2014-11-04 00:26:53 +00:00
|
|
|
}
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
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 RenameEntryDialog::OnSkip(void)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-21 21:18:20 +00:00
|
|
|
/*
|
|
|
|
* User pressed the "skip" button, which causes us to bail with a result that
|
|
|
|
* skips the rename but continues with the series.
|
|
|
|
*/
|
2014-11-04 00:26:53 +00:00
|
|
|
EndDialog(IDIGNORE);
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|