// Filterdlg.cpp : implementation of the CFilterDlg class
//
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "resource.h"
#include "filterdlg.h"
#include <string>
#include <algorithm>
using namespace std;
LRESULT CFilterDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
SendDlgItemMessage(IDC_FILTER01_LEVDIST_SPIN, UDM_SETRANGE, 0, MAKELONG(10, 1));
CenterWindow(GetParent());
m_bCaseSensitivity = FALSE;
m_bSimilarity = FALSE;
if (m_csAction.Find(L"NOT") > 0)
GetDlgItem(IDC_FILTER01_SIMILAR).EnableWindow(FALSE);
DoDataExchange(FALSE);
BOOL bDiscard;
OnSimilar(0, 0, 0, bDiscard);
CComboBox cbx = (CComboBox)GetDlgItem(IDC_FILTER01_SEARCH_TEXT_COMBO);
CRegKey key;
if(key.Open(HKEY_CURRENT_USER, _T("SOFTWARE\\AWS\\Harvester\\Selects"), KEY_READ) == ERROR_SUCCESS)
{
for (int i = 0; i < 1000; i++)
{
CString csValName, csVal;
csValName.Format(L"Select%04d", i);
ULONG dwcbNeeded = 0;
if(key.QueryValue(csValName, NULL, NULL, &dwcbNeeded) == ERROR_SUCCESS)
{
LPTSTR pszVal = csVal.GetBuffer(dwcbNeeded);
if (key.QueryStringValue(csValName, pszVal, &dwcbNeeded) == ERROR_SUCCESS)
{
csVal.ReleaseBuffer();
cbx.AddString(csVal);
m_setEntries.push_back(pszVal);
}
else
csVal.ReleaseBuffer(0);
}
}
key.Close();
}
DoDataExchange(FALSE);
cbx.SetCurSel(0);
return TRUE;
}
void CFilterDlg::SetValues(bool bInvertedAction, bool bCaseSensitivity, bool bSimilarity, int nMaxLevenstein)
{
m_csAction = _T("Select lines ");
m_csAction += bInvertedAction ? _T("NOT ") : _T("");
m_csAction += _T("containing following text");
m_bCaseSensitivity = bCaseSensitivity;
m_bSimilarity = bSimilarity;
m_nMaxLevensthein = nMaxLevenstein;
}
LRESULT CFilterDlg::OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
DoDataExchange(TRUE);
if (wID == IDOK)
{
reverse(m_setEntries.begin(),m_setEntries.end());
bool bPrio = false;
if (m_csSearchText.GetLength() && (find(m_setEntries.begin(), m_setEntries.end(), (wstring)m_csSearchText) == m_setEntries.end()) || !m_setEntries.size())
m_setEntries.push_back(m_csSearchText.GetBuffer(m_csSearchText.GetLength()));
else if (m_csSearchText.GetLength() && (find(m_setEntries.begin(), m_setEntries.end(), (wstring)m_csSearchText) != m_setEntries.end()))
bPrio = true;
CRegKey key;
if(key.Create(HKEY_CURRENT_USER, _T("SOFTWARE\\AWS\\Harvester\\Selects"), REG_NONE, REG_OPTION_NON_VOLATILE, KEY_WRITE) == ERROR_SUCCESS)
{
int i = 0;
if (bPrio)
{
key.SetStringValue(_T("Select0000"), m_csSearchText);
i++;
}
while (m_setEntries.size())
{
if (bPrio && m_setEntries.back() == (wstring)m_csSearchText)
{
m_setEntries.pop_back();
continue;
}
CString csVal;
csVal.Format(L"Select%04d", i++);
key.SetStringValue(csVal, m_setEntries.back().c_str());
m_setEntries.pop_back();
}
key.Close();
}
}
EndDialog(wID);
return 0;
}
LRESULT CFilterDlg::OnSimilar(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
DoDataExchange(TRUE);
GetDlgItem(IDC_FILTER01_LEVDIST_EDIT).EnableWindow(m_bSimilarity);
GetDlgItem(IDC_FILTER01_LEVDIST_SPIN).EnableWindow(m_bSimilarity);
GetDlgItem(IDC_FILTER01_LEVDIST_STATIC).EnableWindow(m_bSimilarity);
return 0;
}
LRESULT CFilterDlg::OnOR(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
DoDataExchange(TRUE);
m_csSearchText += _T("�");
DoDataExchange(FALSE);
GetDlgItem(IDC_FILTER01_SEARCH_TEXT_COMBO).SetFocus();
((CComboBox)GetDlgItem(IDC_FILTER01_SEARCH_TEXT_COMBO)).SetEditSel(m_csSearchText.GetLength(), m_csSearchText.GetLength());
return 0;
}