📄 options.cpp
字号:
/***************************************************************************/
/* 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"
#include "ParserManager.h"
#include "WorkspaceInfo.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_StatsPage);
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, CAutoPropPage)
CExtensionsPage::CExtensionsPage() : CAutoPropPage(CExtensionsPage::IDD, true)
{
//{{AFX_DATA_INIT(CExtensionsPage)
//}}AFX_DATA_INIT
m_iHelpID = IDH_OPT_EXT;
CParserManager::Get().GetState(m_OldPMState);
}
CExtensionsPage::~CExtensionsPage()
{
}
void CExtensionsPage::DoDataExchange(CDataExchange* pDX)
{
CAutoPropPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CExtensionsPage)
DDX_Control(pDX, IDC_EXT_LIST, m_ExtList);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CExtensionsPage, CAutoPropPage)
//{{AFX_MSG_MAP(CExtensionsPage)
ON_BN_CLICKED(IDC_RESET, OnResetList)
ON_WM_VKEYTOITEM()
ON_BN_CLICKED(IDC_INSERTEXT, OnInsertext)
ON_BN_CLICKED(IDC_DELETEEXT, OnDeleteext)
ON_BN_CLICKED(IDC_UNDO, OnUndo)
ON_NOTIFY(LVN_ITEMCHANGED, IDC_EXT_LIST, OnItemchangedExtList)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CExtensionsPage message handlers
BOOL CExtensionsPage::OnInitDialog()
{
CAutoPropPage::OnInitDialog();
m_ExtList.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
m_ExtList.InsertColumn(0, "Extension", LVCFMT_LEFT, 100);
m_ExtList.InsertColumn(1, "Parser", LVCFMT_LEFT, 200);
m_pUndoWnd = GetDlgItem(IDC_UNDO);
m_pUndoWnd->EnableWindow(FALSE);
FillExtList();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -