ciderpress/app/ChooseDirDialog.cpp

200 lines
5.3 KiB
C++
Raw Normal View History

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.
*/
/*
* Support for "choose a directory" dialog.
*/
#include "stdafx.h"
#include "ChooseDirDialog.h"
#include "NewFolderDialog.h"
#include "DiskFSTree.h"
#include "HelpTopics.h"
BEGIN_MESSAGE_MAP(ChooseDirDialog, CDialog)
ON_NOTIFY(TVN_SELCHANGED, IDC_CHOOSEDIR_TREE, OnSelChanged)
ON_BN_CLICKED(IDC_CHOOSEDIR_EXPAND_TREE, OnExpandTree)
ON_BN_CLICKED(IDC_CHOOSEDIR_NEW_FOLDER, OnNewFolder)
ON_WM_HELPINFO()
//ON_COMMAND(ID_HELP, OnIDHelp)
ON_BN_CLICKED(IDHELP, OnHelp)
2007-03-27 17:47:10 +00:00
END_MESSAGE_MAP()
/*
* Initialize dialog components.
*/
BOOL
ChooseDirDialog::OnInitDialog(void)
{
CDialog::OnInitDialog();
/* set up the "new folder" button */
fNewFolderButton.ReplaceDlgCtrl(this, IDC_CHOOSEDIR_NEW_FOLDER);
fNewFolderButton.SetBitmapID(IDB_NEW_FOLDER);
/* replace the tree control with a ShellTree */
if (fShellTree.ReplaceDlgCtrl(this, IDC_CHOOSEDIR_TREE) != TRUE) {
WMSG0("WARNING: ShellTree replacement failed\n");
ASSERT(false);
}
//enable images
fShellTree.EnableImages();
//populate for the with Shell Folders for the first time
fShellTree.PopulateTree(/*CSIDL_DRIVES*/);
if (fPathName.IsEmpty()) {
// start somewhere reasonable
fShellTree.ExpandMyComputer();
} else {
CString msg("");
fShellTree.TunnelTree(fPathName, &msg);
if (!msg.IsEmpty()) {
/* failed */
Large set of changes to restore CiderPress build. CiderPress and MDC now compile, and execute far enough to open their respective "about" boxes, but I doubt they'll do much more than that. * Switch from MBCS to UNICODE APIs Microsoft switched to UTF-16 (by way of UCS-2) a long time ago, and the support for MBCS seems to be getting phased out. So it's time to switch to wide strings. This is a bit awkward for CiderPress because it works with disk and file archives with 8-bit filenames, and I want NufxLib and DiskImgLib to continue to work on Linux (which has largely taken the UTF-8 approach to Unicode). The libraries will continue to work with 8-bit filenames, with CiderPress/MDC doing the conversion at the appropriate point. There were a couple of places where strings from a structure handed back by one of the libraries were used directly in the UI, or vice-versa, which is a problem because we have nowhere to store the result of the conversion. These currently have fixed place-holder "xyzzy" strings. All UI strings are now wide. Various format strings now use "%ls" and "%hs" to explicitly specify wide and narrow. This doesn't play well with gcc, so only the Windows-specific parts use those. * Various updates to vcxproj files The project-file conversion had some cruft that is now largely gone. The build now has a common output directory for the EXEs and libraries, avoiding the old post-build copy steps. * Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots The old "prebuilts" directory is now gone. The libraries are now built as part of building the apps. I added a minimal set of files for zlib, and a full set for nufxlib. The Linux-specific nufxlib goodies are included for the benefit of the Linux utilities, which are currently broken (don't build). * Replace symbols used for include guards Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
WMSG2("TunnelTree failed on '%ls' (%ls), using MyComputer instead\n",
(LPCWSTR) fPathName, (LPCWSTR) msg);
fShellTree.ExpandMyComputer();
}
}
fShellTree.SetFocus();
return FALSE; // leave focus on shell tree
2007-03-27 17:47:10 +00:00
}
/*
* Special keypress handling.
*/
BOOL
ChooseDirDialog::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN &&
2007-03-27 17:47:10 +00:00
pMsg->wParam == VK_RETURN)
{
//WMSG0("RETURN!\n");
if (GetFocus() == GetDlgItem(IDC_CHOOSEDIR_PATHEDIT)) {
OnExpandTree();
return TRUE;
}
}
return CDialog::PreTranslateMessage(pMsg);
2007-03-27 17:47:10 +00:00
}
/*
* F1 key hit, or '?' button in title bar used to select help for an
* item in the dialog.
*/
BOOL
ChooseDirDialog::OnHelpInfo(HELPINFO* lpHelpInfo)
{
DWORD context = lpHelpInfo->iCtrlId;
WinHelp(context, HELP_CONTEXTPOPUP);
return TRUE; // indicate success??
2007-03-27 17:47:10 +00:00
}
/*
* User pressed Ye Olde Helppe Button.
*/
void
ChooseDirDialog::OnHelp(void)
{
WinHelp(HELP_TOPIC_CHOOSE_FOLDER, HELP_CONTEXT);
2007-03-27 17:47:10 +00:00
}
/*
* Replace the ShellTree's default SELCHANGED handler with this so we can
* track changes to the edit control.
*/
void
ChooseDirDialog::OnSelChanged(NMHDR* pnmh, LRESULT* pResult)
{
CString path;
CWnd* pWnd = GetDlgItem(IDC_CHOOSEDIR_PATH);
ASSERT(pWnd != nil);
if (fShellTree.GetFolderPath(&path))
fPathName = path;
else
Large set of changes to restore CiderPress build. CiderPress and MDC now compile, and execute far enough to open their respective "about" boxes, but I doubt they'll do much more than that. * Switch from MBCS to UNICODE APIs Microsoft switched to UTF-16 (by way of UCS-2) a long time ago, and the support for MBCS seems to be getting phased out. So it's time to switch to wide strings. This is a bit awkward for CiderPress because it works with disk and file archives with 8-bit filenames, and I want NufxLib and DiskImgLib to continue to work on Linux (which has largely taken the UTF-8 approach to Unicode). The libraries will continue to work with 8-bit filenames, with CiderPress/MDC doing the conversion at the appropriate point. There were a couple of places where strings from a structure handed back by one of the libraries were used directly in the UI, or vice-versa, which is a problem because we have nowhere to store the result of the conversion. These currently have fixed place-holder "xyzzy" strings. All UI strings are now wide. Various format strings now use "%ls" and "%hs" to explicitly specify wide and narrow. This doesn't play well with gcc, so only the Windows-specific parts use those. * Various updates to vcxproj files The project-file conversion had some cruft that is now largely gone. The build now has a common output directory for the EXEs and libraries, avoiding the old post-build copy steps. * Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots The old "prebuilts" directory is now gone. The libraries are now built as part of building the apps. I added a minimal set of files for zlib, and a full set for nufxlib. The Linux-specific nufxlib goodies are included for the benefit of the Linux utilities, which are currently broken (don't build). * Replace symbols used for include guards Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
fPathName = L"";
pWnd->SetWindowText(fPathName);
// disable the "Select" button when there's no path ready
pWnd = GetDlgItem(IDOK);
ASSERT(pWnd != nil);
pWnd->EnableWindow(!fPathName.IsEmpty());
// It's confusing to have two different paths showing, so wipe out the
// free entry field when the selection changes.
pWnd = GetDlgItem(IDC_CHOOSEDIR_PATHEDIT);
Large set of changes to restore CiderPress build. CiderPress and MDC now compile, and execute far enough to open their respective "about" boxes, but I doubt they'll do much more than that. * Switch from MBCS to UNICODE APIs Microsoft switched to UTF-16 (by way of UCS-2) a long time ago, and the support for MBCS seems to be getting phased out. So it's time to switch to wide strings. This is a bit awkward for CiderPress because it works with disk and file archives with 8-bit filenames, and I want NufxLib and DiskImgLib to continue to work on Linux (which has largely taken the UTF-8 approach to Unicode). The libraries will continue to work with 8-bit filenames, with CiderPress/MDC doing the conversion at the appropriate point. There were a couple of places where strings from a structure handed back by one of the libraries were used directly in the UI, or vice-versa, which is a problem because we have nowhere to store the result of the conversion. These currently have fixed place-holder "xyzzy" strings. All UI strings are now wide. Various format strings now use "%ls" and "%hs" to explicitly specify wide and narrow. This doesn't play well with gcc, so only the Windows-specific parts use those. * Various updates to vcxproj files The project-file conversion had some cruft that is now largely gone. The build now has a common output directory for the EXEs and libraries, avoiding the old post-build copy steps. * Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots The old "prebuilts" directory is now gone. The libraries are now built as part of building the apps. I added a minimal set of files for zlib, and a full set for nufxlib. The Linux-specific nufxlib goodies are included for the benefit of the Linux utilities, which are currently broken (don't build). * Replace symbols used for include guards Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
pWnd->SetWindowText(L"");
*pResult = 0;
2007-03-27 17:47:10 +00:00
}
/*
* User pressed "Expand Tree" button.
*/
void
ChooseDirDialog::OnExpandTree(void)
{
CWnd* pWnd;
CString str;
CString msg;
pWnd = GetDlgItem(IDC_CHOOSEDIR_PATHEDIT);
ASSERT(pWnd != nil);
pWnd->GetWindowText(str);
if (!str.IsEmpty()) {
fShellTree.TunnelTree(str, &msg);
if (!msg.IsEmpty()) {
CString failed;
failed.LoadString(IDS_FAILED);
MessageBox(msg, failed, MB_OK | MB_ICONERROR);
}
}
2007-03-27 17:47:10 +00:00
}
/*
* User pressed "New Folder" button.
*/
void
ChooseDirDialog::OnNewFolder(void)
{
if (fPathName.IsEmpty()) {
Large set of changes to restore CiderPress build. CiderPress and MDC now compile, and execute far enough to open their respective "about" boxes, but I doubt they'll do much more than that. * Switch from MBCS to UNICODE APIs Microsoft switched to UTF-16 (by way of UCS-2) a long time ago, and the support for MBCS seems to be getting phased out. So it's time to switch to wide strings. This is a bit awkward for CiderPress because it works with disk and file archives with 8-bit filenames, and I want NufxLib and DiskImgLib to continue to work on Linux (which has largely taken the UTF-8 approach to Unicode). The libraries will continue to work with 8-bit filenames, with CiderPress/MDC doing the conversion at the appropriate point. There were a couple of places where strings from a structure handed back by one of the libraries were used directly in the UI, or vice-versa, which is a problem because we have nowhere to store the result of the conversion. These currently have fixed place-holder "xyzzy" strings. All UI strings are now wide. Various format strings now use "%ls" and "%hs" to explicitly specify wide and narrow. This doesn't play well with gcc, so only the Windows-specific parts use those. * Various updates to vcxproj files The project-file conversion had some cruft that is now largely gone. The build now has a common output directory for the EXEs and libraries, avoiding the old post-build copy steps. * Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots The old "prebuilts" directory is now gone. The libraries are now built as part of building the apps. I added a minimal set of files for zlib, and a full set for nufxlib. The Linux-specific nufxlib goodies are included for the benefit of the Linux utilities, which are currently broken (don't build). * Replace symbols used for include guards Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
MessageBox(L"You can't create a folder in this part of the tree.",
L"Bad Location", MB_OK | MB_ICONERROR);
return;
}
NewFolderDialog newFolderDlg;
newFolderDlg.fCurrentFolder = fPathName;
if (newFolderDlg.DoModal() == IDOK) {
if (newFolderDlg.GetFolderCreated()) {
/*
* They created a new folder. We want to add it to the tree
* and then select it. This is not too hard because we know
* that the folder was created under the currently-selected
* tree node.
*/
if (fShellTree.AddFolderAtSelection(newFolderDlg.fNewFolder)) {
CString msg;
Large set of changes to restore CiderPress build. CiderPress and MDC now compile, and execute far enough to open their respective "about" boxes, but I doubt they'll do much more than that. * Switch from MBCS to UNICODE APIs Microsoft switched to UTF-16 (by way of UCS-2) a long time ago, and the support for MBCS seems to be getting phased out. So it's time to switch to wide strings. This is a bit awkward for CiderPress because it works with disk and file archives with 8-bit filenames, and I want NufxLib and DiskImgLib to continue to work on Linux (which has largely taken the UTF-8 approach to Unicode). The libraries will continue to work with 8-bit filenames, with CiderPress/MDC doing the conversion at the appropriate point. There were a couple of places where strings from a structure handed back by one of the libraries were used directly in the UI, or vice-versa, which is a problem because we have nowhere to store the result of the conversion. These currently have fixed place-holder "xyzzy" strings. All UI strings are now wide. Various format strings now use "%ls" and "%hs" to explicitly specify wide and narrow. This doesn't play well with gcc, so only the Windows-specific parts use those. * Various updates to vcxproj files The project-file conversion had some cruft that is now largely gone. The build now has a common output directory for the EXEs and libraries, avoiding the old post-build copy steps. * Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots The old "prebuilts" directory is now gone. The libraries are now built as part of building the apps. I added a minimal set of files for zlib, and a full set for nufxlib. The Linux-specific nufxlib goodies are included for the benefit of the Linux utilities, which are currently broken (don't build). * Replace symbols used for include guards Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
WMSG1("Success, tunneling to '%ls'\n",
(LPCWSTR) newFolderDlg.fNewFullPath);
fShellTree.TunnelTree(newFolderDlg.fNewFullPath, &msg);
if (!msg.IsEmpty()) {
Large set of changes to restore CiderPress build. CiderPress and MDC now compile, and execute far enough to open their respective "about" boxes, but I doubt they'll do much more than that. * Switch from MBCS to UNICODE APIs Microsoft switched to UTF-16 (by way of UCS-2) a long time ago, and the support for MBCS seems to be getting phased out. So it's time to switch to wide strings. This is a bit awkward for CiderPress because it works with disk and file archives with 8-bit filenames, and I want NufxLib and DiskImgLib to continue to work on Linux (which has largely taken the UTF-8 approach to Unicode). The libraries will continue to work with 8-bit filenames, with CiderPress/MDC doing the conversion at the appropriate point. There were a couple of places where strings from a structure handed back by one of the libraries were used directly in the UI, or vice-versa, which is a problem because we have nowhere to store the result of the conversion. These currently have fixed place-holder "xyzzy" strings. All UI strings are now wide. Various format strings now use "%ls" and "%hs" to explicitly specify wide and narrow. This doesn't play well with gcc, so only the Windows-specific parts use those. * Various updates to vcxproj files The project-file conversion had some cruft that is now largely gone. The build now has a common output directory for the EXEs and libraries, avoiding the old post-build copy steps. * Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots The old "prebuilts" directory is now gone. The libraries are now built as part of building the apps. I added a minimal set of files for zlib, and a full set for nufxlib. The Linux-specific nufxlib goodies are included for the benefit of the Linux utilities, which are currently broken (don't build). * Replace symbols used for include guards Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
WMSG1("TunnelTree failed: %ls\n", (LPCWSTR) msg);
}
} else {
WMSG0("AddFolderAtSelection FAILED\n");
ASSERT(false);
}
} else {
WMSG0("NewFolderDialog returned IDOK but no create\n");
}
}
2007-03-27 17:47:10 +00:00
}