/***************************************************************************/
/* NOTE: */
/* This document is copyright (c) by Oz Solomonovich, and is bound by the */
/* MIT open source license (www.opensource.org/licenses/mit-license.html). */
/* See License.txt for more information. */
/***************************************************************************/
// Options.cpp : implementation file
//
#include "stdafx.h"
#include "LineCount.h"
#include "Options.h"
#include "Config.h"
#include "InsertExtDlg.h"
#include "InsertFileDlg.h"
#include "Help\HelpIDs.h"
#include "Utils.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// COptionsSheet
IMPLEMENT_DYNAMIC(COptionsSheet, CHHPropSheet)
COptionsSheet::COptionsSheet(CWnd* pParentWnd, UINT iSelectPage)
: CHHPropSheet("Options", pParentWnd, iSelectPage)
{
AddPage(&m_FilesPage);
AddPage(&m_ExtPage);
AddPage(&m_OptionsPage);
}
COptionsSheet::~COptionsSheet()
{
}
BEGIN_MESSAGE_MAP(COptionsSheet, CHHPropSheet)
//{{AFX_MSG_MAP(COptionsSheet)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// COptionsSheet message handlers
/////////////////////////////////////////////////////////////////////////////
// CPageWithList class
IMPLEMENT_DYNCREATE(CPageWithList, CAutoPropPage)
CPageWithList::CPageWithList(CListBox& managedList, int iDelButton,
int iInsButton, UINT nIDTemplate, bool bAllowImplicit /*= true*/,
int iHelpID /*= -1*/, UINT nIDCaption /*= 0*/) :
CAutoPropPage(nIDTemplate, bAllowImplicit, iHelpID, nIDCaption),
m_pManagedList(&managedList), m_iDelButton(iDelButton),
m_iInsButton(iInsButton)
{
}
void CPageWithList::InitPageWithList()
{
m_pUndoWnd = GetDlgItem(IDC_UNDO);
SetLastUndo(none, "");
SetModified(FALSE);
}
void CPageWithList::DeleteString(CString str)
{
m_pManagedList->DeleteString(m_pManagedList->FindStringExact(0, str));
OnUpdateList();
SetLastUndo(del, str);
SetModified();
}
void CPageWithList::InsertString(CString str)
{
m_pManagedList->SetCurSel(m_pManagedList->AddString(str));
OnUpdateList();
SetLastUndo(ins, str);
HandlerImpl_OnSelChange();
SetModified();
}
void CPageWithList::SetLastUndo(undo_ops op, CString val)
{
m_LastUndoOp = op;
m_sLastUndoVal = val;
m_pUndoWnd->SetWindowText("Und&o");
m_pUndoWnd->EnableWindow(m_LastUndoOp != none);
}
void CPageWithList::HandlerImpl_OnSelChange()
{
BOOL bEnable = (m_pManagedList->GetCurSel() != LB_ERR);
GetDlgItem(m_iDelButton)->EnableWindow(bEnable);
}
void CPageWithList::HandlerImpl_OnUndo()
{
switch (m_LastUndoOp)
{
case del:
InsertString(m_sLastUndoVal);
m_LastUndoOp = ins;
break;
case ins:
DeleteString(m_sLastUndoVal);
m_LastUndoOp = del;
break;
default:
return;
}
m_pUndoWnd->SetWindowText("Red&o");
}
void CPageWithList::HandlerImpl_OnDelete()
{
CString sToDel;
int iCurSel = m_pManagedList->GetCurSel();
if (iCurSel < 0)
return;
m_pManagedList->GetText(iCurSel, sToDel);
DeleteString(sToDel);
if (iCurSel > m_pManagedList->GetCount()) iCurSel--;
if (iCurSel >= 0)
m_pManagedList->SetCurSel(iCurSel);
HandlerImpl_OnSelChange();
OnUpdateList();
}
int CPageWithList::HandlerImpl_OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex)
{
if (pListBox == m_pManagedList)
{
switch (nKey)
{
case VK_DELETE:
{
if (m_pManagedList->GetCurSel() != LB_ERR)
{
GetParent()->SendMessage(WM_COMMAND, m_iDelButton, NULL);
}
break;
}
case VK_INSERT:
{
GetParent()->SendMessage(WM_COMMAND, m_iInsButton, NULL);
break;
}
}
}
return CAutoPropPage::OnVKeyToItem(nKey, pListBox, nIndex);
}
/////////////////////////////////////////////////////////////////////////////
// CFilesPage property page
IMPLEMENT_DYNCREATE(CFilesPage, CPageWithList)
CFilesPage::CFilesPage() : CPageWithList(m_FileList, IDC_DELETEFILE,
IDC_INSERTFILE, CFilesPage::IDD)
{
//{{AFX_DATA_INIT(CFilesPage)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_iHelpID = IDH_OPT_FILES;
strpair strs[] =
{
{ &m_sFileList, &cfg_sFileIgnoreList }
};
InitAutoStrs(countof(strs), strs);
}
CFilesPage::~CFilesPage()
{
}
void CFilesPage::DoDataExchange(CDataExchange* pDX)
{
CPageWithList::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFilesPage)
DDX_Control(pDX, IDC_FILE_LIST, m_FileList);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFilesPage, CPageWithList)
//{{AFX_MSG_MAP(CFilesPage)
ON_BN_CLICKED(IDC_INSERTFILE, OnInsertfile)
ON_BN_CLICKED(IDC_DELETEFILE, OnDeletefile)
ON_BN_CLICKED(IDC_UNDO, OnUndo)
ON_BN_CLICKED(IDC_CLEARALLFILES, OnClearallfiles)
ON_LBN_SELCHANGE(IDC_FILE_LIST, OnSelchangeFileList)
ON_LBN_SELCANCEL(IDC_FILE_LIST, OnSelchangeFileList)
ON_WM_VKEYTOITEM()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFilesPage message handlers
BOOL CFilesPage::OnInitDialog()
{
CPageWithList::OnInitDialog();
InitPageWithList();
FillFileList();
return TRUE;
}
void CFilesPage::OnInsertfile()
{
CInsertFileDlg dlg;
if (dlg.DoModal() == IDOK)
{
InsertString(dlg.m_sFile);
}
}
void CFilesPage::OnDeletefile()
{
HandlerImpl_OnDelete();
}
void CFilesPage::OnUndo()
{
HandlerImpl_OnUndo();
}
void CFilesPage::OnClearallfiles()
{
m_sFileList = "";
FillFileList();
SetLastUndo(none, "");
}
void CFilesPage::OnSelchangeFileList()
{
HandlerImpl_OnSelChange();
}
int CFilesPage::OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex)
{
return HandlerImpl_OnVKeyToItem(nKey, pListBox, nIndex);
}
void CFilesPage::OnUpdateList()
{
m_sFileList.Empty();
const int items = m_FileList.GetCount();
CString cStr;
for (int i = 0; i < items; ++i)
{
if (!m_sFileList.IsEmpty())
{
m_sFileList += LIST_DELIMITER;
}
m_FileList.GetText(i, cStr);
m_sFileList += cStr;
}
}
void CFilesPage::FillFileList()
{
CStringList strList;
m_FileList.ResetContent();
String2StringList(m_sFileList, LIST_DELIMITER, strList);
POSITION p = strList.GetHeadPosition();
while (p)
{
m_FileList.AddString(strList.GetNext(p));
}
OnUpdateList();
OnSelchangeFileList();
SetModified();
}
/////////////////////////////////////////////////////////////////////////////
// CExtensionsPage property page
IMPLEMENT_DYNCREATE(CExtensionsPage, CPageWithList)
CExtensionsPage::CExtensionsPage() : CPageWithList(m_ExtList, IDC_DELETEEXT,
IDC_INSERTEXT, CExtensionsPage::IDD, true)
{
//{{AFX_DATA_INIT(CExtensionsPage)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_iHelpID = IDH_OPT_EXT;
strpair strs[] =
{
{ &m_sExtList, &cfg_sExtList }
};
InitAutoStrs(countof(strs), strs);
}
CExtensionsPage::~CExtensionsPage()
{
}
void CExtensionsPage::DoDataExchange(CDataExchange* pDX)
{
CPageWithList::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CExtensionsPage)
DDX_Control(pDX, IDC_EXT_LIST, m_ExtList);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CExtensionsPage, CPageWithList)
//{{AFX_MSG_MAP(CExtensionsPage)
ON_BN_CLICKED(IDC_RESET, OnReset)
ON_WM_VKEYTOITEM()
ON_BN_CLICKED(IDC_INSERTEXT, OnInsertext)
ON_BN_CLICKED(IDC_DELETEEXT, OnDeleteext)
ON_BN_CLICKED(IDC_UNDO, OnUndo)
ON_LBN_SELCANCEL(IDC_EXT_LIST, OnSelChange)
ON_LBN_SELCHANGE(IDC_EXT_LIST, OnSelChange)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CExtensionsPage message handlers
BOOL CExtensionsPage::OnInitDialog()
{
CPageWithList::OnInitDialog();
InitPageWithList();
FillExtList();
return TRUE;
}
void CExtensionsPage::OnSelChange()
{
HandlerImpl_OnSelChange();
}
void CExtensionsPage::OnReset()
{
m_sExtList = DEF_EXT_LIST;
FillExtList();
SetLastUndo(none, "");
}
void CExtensionsPage::OnInsertext()
{
CInsertExtDlg dlg;
if (dlg.DoModal() == IDOK)
{
InsertString(dlg.m_Ext);
}
}
void CExtensionsPage::OnDeleteext()
{
HandlerImpl_OnDelete();
}
void CExtensionsPage::OnUndo()
{
HandlerImpl_OnUndo();
}
void CExtensionsPage::OnUpdateList()
{
m_sExtList.Empty();
const int items = m_ExtList.GetCount();
CString cStr;
for (int i = 0; i < items; ++i)
{
if (!m_sExtList.IsEmpty())
{
m_sExtList += LIST_DELIMITER;
}
m_ExtList.GetText(i, cStr);
m_sExtList += cStr;
}
}
int CExtensionsPage::OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex)
{
return HandlerImpl_OnVKeyToItem(nKey, pListBox, nIndex);
}
void CExtensionsPage::FillExtList()
{
CStringList strList;
m_ExtList.ResetContent();
String2StringList(m_sExtList, LIST_DELIMITER, strList);
POSITION p = strList.GetHeadPosition();
while (p)
{
CString& sExt = strList.GetNext(p);
sExt.MakeUpper();
m_ExtList.AddString(sExt);
}
OnUpdateList();
OnSelChange();
SetModified();
}
/////////////////////////////////////////////////////////////////////////////
// COptionsPage property page
IMPLEMENT_DYNCREATE(COptionsPage, CAutoPropPage)
BEGIN_HELP_IDS(COptionsPage)
IDC_STATIC_DEFAULT_FILTER, IDC_DEFAULT_FILTER,
IDC_STATIC_DEFAULT_FILTER2, IDC_DEFAULT_FILTER,
IDC_STYLESHEET, IDC_XSL_FIXED
END_HELP_IDS()
COptionsPage::COptionsPage() : CAutoPropPage(COptionsPage::IDD)
{
//{{AFX_DATA_INIT(COptionsPage)
m_bCheckComments = FALSE;
m_bCountBlanks = FALSE;
m_XSLType = -1;
m_sXSLName = _T("");
//}}AFX_DATA_INIT
m_iHelpID = IDH_OPT_OPT;
varpair vars[] =
{
{ &m_bCountBlanks, &cfg_bProcessBlanks },
{ &m_bCheckComments, &cfg_bProcessCPPComments },
{ &m_iDefFilter, &cfg_iDefaultFilter },
{ &m_XSLType, (int *)&cfg_XSLTUsage },
};
strpair strs[] =
{
{ &m_sXSLName, &cfg_sXSLTTemplate }
};
InitAutoVars(countof(vars), vars);
InitAutoStrs(countof(strs), strs);
}
COptionsPage::~COptionsPage()
{
}
void COptionsPage::DoDataExchange(CDataExchange* pDX)
{
CAutoPropPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(COptionsPage)
DDX_Control(pDX, IDC_DEFAULT_FILTER, m_DefFilter);
DDX_Check(pDX, IDC_CHECKCOMMENTS, m_bCheckComments);
DDX_Check(pDX, IDC_COUNTBLANK, m_bCountBlanks);
DDX_Radio(pDX, IDC_XSL_NONE, m_XSLType);
DDX_Text(pDX, IDC_STYLESHEET, m_sXSLName);
//}}AFX_DATA_MAP
if (!pDX->m_bSaveAndValidate)
{
m_DefFilter.SetCurSel(m_iDefFilter);
}
else
{
m_iDefFilter = m_DefFilter.GetCurSel();
if (m_iDefFilter < 0 ||
m_iDefFilter > m_DefFilter.GetCount())
{
m_iDefFilter = 0;
}
}
}
BEGIN_MESSAGE_MAP(COptionsPage, CAutoPropPage)
//{{AFX_MSG_MAP(COptionsPage)
ON_BN_CLICKED(IDC_CHECKCOMMENTS, DoModified)
ON_BN_CLICKED(IDC_COUNTBLANK, DoModified)
ON_BN_CLICKED(IDC_ACTIVEONLY, DoModified)
ON_CBN_SELCHANGE(IDC_DEFAULT_FILTER, DoModified)
ON_BN_CLICKED(IDC_XSL_NONE, OnXSLSel)
ON_BN_CLICKED(IDC_XSL_SAMENAME, OnXSLSel)
ON_EN_CHANGE(IDC_STYLESHEET, DoModified)
ON_BN_CLICKED(IDC_XSL_FIXED, OnXSLSel)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// COptionsPage message handlers
BOOL COptionsPage::OnInitDialog()
{
CAutoPropPage::OnInitDialog();
OnXSLSel();
return TRUE;
}
void COptionsPage::DoModified()
{
SetModified();
}
void COptionsPage::OnXSLSel()
{
UpdateData();
DoModified();
GetDlgItem(IDC_STYLESHEET)->EnableWindow(m_XSLType == 2);
}