/***************************************************************************/
/* NOTE: */
/* This document is copyright (c) by Oz Solomonovich. All non-commercial */
/* use is allowed, as long as this document is not altered in any way, and */
/* due credit is given. */
/***************************************************************************/
// Options.cpp : implementation file
//
#include "stdafx.h"
#include "LineCount.h"
#include "Options.h"
#include "Config.h"
#include "InsertExtDlg.h"
#include "Help\HelpIDs.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_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
/////////////////////////////////////////////////////////////////////////////
// CFilesPage property page
IMPLEMENT_DYNCREATE(CFilesPage, CAutoPropPage)
CFilesPage::CFilesPage() : CAutoPropPage(CFilesPage::IDD, true)
{
//{{AFX_DATA_INIT(CFilesPage)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_SavedExtList = m_sExtList = cfg_sExtList;
}
CFilesPage::~CFilesPage()
{
}
void CFilesPage::DoDataExchange(CDataExchange* pDX)
{
CAutoPropPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFilesPage)
DDX_Control(pDX, IDC_EXT_LIST, m_ExtList);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFilesPage, CAutoPropPage)
//{{AFX_MSG_MAP(CFilesPage)
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()
/////////////////////////////////////////////////////////////////////////////
// CFilesPage message handlers
BOOL CFilesPage::OnInitDialog()
{
CHHPropPage::OnInitDialog();
m_pUndoWnd = GetDlgItem(IDC_UNDO);
SetLastUndo(none, "");
FillExtList();
SetModified(FALSE);
return TRUE;
}
BOOL CFilesPage::OnApply()
{
if (!UpdateData())
return FALSE;
cfg_sExtList = m_sExtList;
return CHHPropPage::OnApply();
}
void CFilesPage::OnCancel()
{
m_sExtList = m_SavedExtList;
UpdateData(FALSE);
OnApply();
}
void CFilesPage::OnSelChange()
{
BOOL bEnable = (m_ExtList.GetCurSel() != LB_ERR);
GetDlgItem(IDC_DELETEEXT)->EnableWindow(bEnable);
}
void CFilesPage::OnReset()
{
m_sExtList = DEF_EXT_LIST;
FillExtList();
UpdateConfigList();
SetLastUndo(none, "");
}
void CFilesPage::OnInsertext()
{
CInsertExtDlg dlg;
if (dlg.DoModal() == IDOK && !dlg.m_Ext.IsEmpty())
{
InsertString(dlg.m_Ext);
}
}
void CFilesPage::OnDeleteext()
{
CString sToDel;
int iCurSel = m_ExtList.GetCurSel();
if (iCurSel < 0)
return;
m_ExtList.GetText(iCurSel, sToDel);
DeleteString(sToDel);
if (iCurSel > m_ExtList.GetCount()) iCurSel--;
if (iCurSel >= 0)
m_ExtList.SetCurSel(iCurSel);
}
void CFilesPage::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");
}
int CFilesPage::OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex)
{
switch (nKey)
{
case VK_DELETE:
{
if (m_ExtList.GetCurSel() != LB_ERR)
OnDeleteext();
break;
}
case VK_INSERT:
{
OnInsertext();
break;
}
}
return CHHPropPage::OnVKeyToItem(nKey, pListBox, nIndex);
}
void CFilesPage::DeleteString(CString str)
{
m_StrList.RemoveAt(m_StrList.Find(str));
m_ExtList.DeleteString(m_ExtList.FindStringExact(0, str));
UpdateConfigList();
SetLastUndo(del, str);
}
void CFilesPage::InsertString(CString str)
{
m_ExtList.SetCurSel(m_ExtList.AddString(str));
m_StrList.AddHead(str);
UpdateConfigList();
SetLastUndo(ins, str);
OnSelChange();
}
void CFilesPage::SetLastUndo(undo_ops op, CString val)
{
m_LastUndoOp = op;
m_sLastUndoVal = val;
m_pUndoWnd->SetWindowText("Und&o");
m_pUndoWnd->EnableWindow(m_LastUndoOp != none);
}
void CFilesPage::UpdateConfigList()
{
POSITION p = m_StrList.GetHeadPosition();
CString cStr;
m_sExtList.Empty();
while (p)
{
cStr = m_StrList.GetNext(p);
if (!m_sExtList.IsEmpty())
{
m_sExtList += ';';
}
m_sExtList += cStr;
}
}
void CFilesPage::FillExtList()
{
CString cStr, cExt;
int p;
m_StrList.RemoveAll();
m_ExtList.ResetContent();
cStr = m_sExtList;
do
{
p = cStr.Find(';');
if (p >= 0)
{
cExt = cStr.Left(p);
cStr = cStr.Mid(p + 1);
}
else
{
cExt = cStr;
}
if (!cExt.IsEmpty())
{
cExt.MakeUpper();
m_StrList.AddTail(cExt);
m_ExtList.AddString(cExt);
}
} while (p >= 0);
SetModified();
OnSelChange();
}
/////////////////////////////////////////////////////////////////////////////
// COptionsPage property page
IMPLEMENT_DYNCREATE(COptionsPage, CAutoPropPage)
COptionsPage::COptionsPage() : CAutoPropPage(COptionsPage::IDD)
{
//{{AFX_DATA_INIT(COptionsPage)
m_bCheckComments = FALSE;
m_bCountBlanks = FALSE;
m_bActiveProjOnly = FALSE;
//}}AFX_DATA_INIT
varpair vars[] =
{
{ &m_bCountBlanks, &cfg_bProcessBlanks },
{ &m_bCheckComments, &cfg_bProcessCPPComments },
{ &m_bActiveProjOnly, &cfg_bActiveProjOnly }
};
InitAutoVars(countof(vars), vars);
}
COptionsPage::~COptionsPage()
{
}
void COptionsPage::DoDataExchange(CDataExchange* pDX)
{
CAutoPropPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(COptionsPage)
DDX_Check(pDX, IDC_CHECKCOMMENTS, m_bCheckComments);
DDX_Check(pDX, IDC_COUNTBLANK, m_bCountBlanks);
DDX_Check(pDX, IDC_ACTIVEONLY, m_bActiveProjOnly);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(COptionsPage, CAutoPropPage)
//{{AFX_MSG_MAP(COptionsPage)
ON_BN_CLICKED(IDC_CHECKCOMMENTS, DoModified)
ON_BN_CLICKED(IDC_COUNTBLANK, DoModified)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// COptionsPage message handlers
BOOL COptionsPage::OnInitDialog()
{
CAutoPropPage::OnInitDialog();
return TRUE;
}
void COptionsPage::DoModified()
{
SetModified();
}