Skip to content

Commit

Permalink
More export dialog fixes
Browse files Browse the repository at this point in the history
If no items are selected when the user clicks Export,
assume they want to export all files.

This commit also adds a new Dialog base class, to avoid
code duplication, and removes old export code
  • Loading branch information
chrisn committed Jan 14, 2023
1 parent 03280db commit 917bced
Show file tree
Hide file tree
Showing 10 changed files with 253 additions and 249 deletions.
2 changes: 1 addition & 1 deletion Src/BeebEm.rc
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ CAPTION "BeebEm Disc Export"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "Export Files",IDOK,63,280,60,14
PUSHBUTTON "Cancel",IDCANCEL,149,280,50,14
PUSHBUTTON "Close",IDCANCEL,149,280,50,14
CONTROL "",IDC_EXPORTFILELIST,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP,7,18,250,258
LTEXT "Select the files to export:",IDC_STATIC,7,7,258,9
END
Expand Down
2 changes: 2 additions & 0 deletions Src/BeebEm.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
<ClCompile Include="csw.cpp" />
<ClCompile Include="Debug.cpp" />
<ClCompile Include="DebugTrace.cpp" />
<ClCompile Include="Dialog.cpp" />
<ClCompile Include="DirectSoundStreamer.cpp" />
<ClCompile Include="disc1770.cpp" />
<ClCompile Include="disc8271.cpp" />
Expand Down Expand Up @@ -338,6 +339,7 @@
<ClInclude Include="csw.h" />
<ClInclude Include="Debug.h" />
<ClInclude Include="DebugTrace.h" />
<ClInclude Include="Dialog.h" />
<ClInclude Include="DirectSoundStreamer.h" />
<ClInclude Include="disc1770.h" />
<ClInclude Include="disc8271.h" />
Expand Down
6 changes: 6 additions & 0 deletions Src/BeebEm.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@
<ClCompile Include="DebugTrace.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Dialog.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="DirectSoundStreamer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down Expand Up @@ -302,6 +305,9 @@
<ClInclude Include="DebugTrace.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Dialog.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DirectSoundStreamer.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down
81 changes: 81 additions & 0 deletions Src/Dialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/****************************************************************
BeebEm - BBC Micro and Master 128 Emulator
Copyright (C) 2023 Chris Needham
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with this program; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
****************************************************************/

#include <windows.h>

#include "Dialog.h"

/****************************************************************************/

Dialog::Dialog(HINSTANCE hInstance,
HWND hwndParent,
int DialogID) :
m_hInstance(hInstance),
m_hwndParent(hwndParent),
m_DialogID(DialogID),
m_hwnd(nullptr)
{
}

/****************************************************************************/

bool Dialog::DoModal()
{
// Show dialog box
int Result = DialogBoxParam(m_hInstance,
MAKEINTRESOURCE(m_DialogID),
m_hwndParent,
sDlgProc,
reinterpret_cast<LPARAM>(this));

return Result == IDOK;
}

/****************************************************************************/

INT_PTR CALLBACK Dialog::sDlgProc(HWND hwnd,
UINT nMessage,
WPARAM wParam,
LPARAM lParam)
{
Dialog* dialog;

if (nMessage == WM_INITDIALOG)
{
SetWindowLongPtr(hwnd, DWLP_USER, lParam);
dialog = reinterpret_cast<Dialog*>(lParam);
dialog->m_hwnd = hwnd;
}
else
{
dialog = reinterpret_cast<Dialog*>(
GetWindowLongPtr(hwnd, DWLP_USER)
);
}

if (dialog)
{
return dialog->DlgProc(nMessage, wParam, lParam);
}
else
{
return FALSE;
}
}
57 changes: 57 additions & 0 deletions Src/Dialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/****************************************************************
BeebEm - BBC Micro and Master 128 Emulator
Copyright (C) 2023 Chris Needham
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with this program; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
****************************************************************/

#ifndef DIALOG_HEADER
#define DIALOG_HEADER

class Dialog
{
public:
Dialog(
HINSTANCE hInstance,
HWND hwndParent,
int DialogID
);

public:
bool DoModal();

private:
static INT_PTR CALLBACK sDlgProc(
HWND hwnd,
UINT nMessage,
WPARAM wParam,
LPARAM lParam
);

virtual INT_PTR DlgProc(
UINT nMessage,
WPARAM wParam,
LPARAM lParam
) = 0;

protected:
HINSTANCE m_hInstance;
HWND m_hwndParent;
int m_DialogID;
HWND m_hwnd;
};

#endif
111 changes: 36 additions & 75 deletions Src/ExportFileDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,20 @@ Boston, MA 02110-1301, USA.
#include "StringUtils.h"
#include "DebugTrace.h"

ExportFileDialog::ExportFileDialog(
HINSTANCE hInstance,
HWND hwndParent,
const char* szDiscFile,
int NumSides,
int Side,
DFS_DISC_CATALOGUE* dfsCat,
const char* ExportPath) :
m_hInstance(hInstance),
m_hwndParent(hwndParent),
/****************************************************************************/

ExportFileDialog::ExportFileDialog(HINSTANCE hInstance,
HWND hwndParent,
const char* szDiscFile,
int NumSides,
int Side,
DFS_DISC_CATALOGUE* dfsCat,
const char* ExportPath) :
Dialog(hInstance, hwndParent, IDD_DISCEXPORT),
m_DiscFile(szDiscFile),
m_NumSides(NumSides),
m_Side(Side),
m_ExportPath(ExportPath),
m_hwnd(nullptr),
m_hwndListView(nullptr),
m_NumSelected(0)
{
Expand All @@ -68,23 +67,6 @@ ExportFileDialog::ExportFileDialog(
}
}

bool ExportFileDialog::DoModal()
{
// Show export dialog
int Result = DialogBoxParam(m_hInstance,
MAKEINTRESOURCE(IDD_DISCEXPORT),
m_hwndParent,
sDlgProc,
reinterpret_cast<LPARAM>(this));

if (Result != IDOK || m_NumSelected == 0)
{
return false;
}

return true;
}

/****************************************************************************/

static LPCTSTR Columns[] = {
Expand All @@ -95,17 +77,13 @@ static LPCTSTR Columns[] = {
"Host File name"
};

INT_PTR ExportFileDialog::DlgProc(
HWND hwnd,
UINT nMessage,
WPARAM wParam,
LPARAM lParam)
INT_PTR ExportFileDialog::DlgProc(UINT nMessage,
WPARAM wParam,
LPARAM lParam)
{
switch (nMessage)
{
case WM_INITDIALOG: {
m_hwnd = hwnd;

m_hwndListView = GetDlgItem(m_hwnd, IDC_EXPORTFILELIST);

ListView_SetExtendedListViewStyle(m_hwndListView, LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
Expand Down Expand Up @@ -200,51 +178,27 @@ INT_PTR ExportFileDialog::DlgProc(

/****************************************************************************/

INT_PTR CALLBACK ExportFileDialog::sDlgProc(
HWND hwnd,
UINT nMessage,
WPARAM wParam,
LPARAM lParam)
{
ExportFileDialog* dialog;

if (nMessage == WM_INITDIALOG)
{
SetWindowLongPtr(hwnd, DWLP_USER, lParam);
dialog = reinterpret_cast<ExportFileDialog*>(lParam);
}
else
{
dialog = reinterpret_cast<ExportFileDialog*>(
GetWindowLongPtr(hwnd, DWLP_USER)
);
}

return dialog->DlgProc(hwnd, nMessage, wParam, lParam);
}

int ExportFileDialog::GetNumSelected() const
{
return m_NumSelected;
}

std::string ExportFileDialog::GetPath() const
{
return m_ExportPath;
}

const int* ExportFileDialog::GetFilesSelected() const
{
return m_FilesSelected;
}
/****************************************************************************/

void ExportFileDialog::ExportSelectedFiles()
{
m_NumSelected = ListView_GetSelectedCount(m_hwndListView);

if (m_NumSelected == 0)
{
return;
int Count = ListView_GetItemCount(m_hwndListView);

for (int i = 0; i < Count; i++)
{
ListView_SetItemState(m_hwndListView, i, LVIS_SELECTED, LVIS_SELECTED);
}

m_NumSelected = Count;
}

// Get folder to export to
Expand All @@ -254,14 +208,19 @@ void ExportFileDialog::ExportSelectedFiles()

FolderSelectDialog::Result Result = Dialog.DoModal();

if (Result == FolderSelectDialog::Result::OK)
{
m_ExportPath = Dialog.GetFolder();
}
else if (Result == FolderSelectDialog::Result::InvalidFolder)
switch (Result)
{
mainWin->Report(MessageType::Warning, "Invalid folder selected");
return;
case FolderSelectDialog::Result::OK:
m_ExportPath = Dialog.GetFolder();
break;

case FolderSelectDialog::Result::InvalidFolder:
mainWin->Report(MessageType::Warning, "Invalid folder selected");
return;

case FolderSelectDialog::Result::Cancel:
default:
return;
}

int Item = ListView_GetNextItem(m_hwndListView, -1, LVNI_SELECTED);
Expand Down Expand Up @@ -307,6 +266,8 @@ void ExportFileDialog::ExportSelectedFiles()
mainWin->Report(MessageType::Info, "Files successfully exported: %d", Count);
}

/****************************************************************************/

bool ExportFileDialog::ExportFile(DFS_FILE_ATTR* DfsAttrs, const char* LocalFileName)
{
char szErrStr[512];
Expand Down
Loading

0 comments on commit 917bced

Please sign in to comment.