Skip to content

Commit

Permalink
rename, refactor, documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
itagagaki committed Dec 10, 2023
1 parent 53a2063 commit f3c8c89
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 82 deletions.
3 changes: 1 addition & 2 deletions Charu3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1709,8 +1709,7 @@ void CCharu3App::Record(CString text)
}
}

m_pTree->addDataToRecordFolder(data, m_strPreviousRecordedToHistory);
m_strPreviousRecordedToHistory = text;
m_pTree->AddDataToHistoryFolders(data);

if (m_isStockMode && m_ini.m_nWindowCheckInterval > 0) {
SetTimer(m_pMainWnd->m_hWnd, TIMER_ACTIVE, m_ini.m_nWindowCheckInterval, NULL);
Expand Down
2 changes: 1 addition & 1 deletion Charu3.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class CCharu3App : public CWinApp
CMyTreeDialog* m_pTreeDlg;
HTREEITEM m_hSelectItemBkup;
DWORD m_dwDoubleKeyPopTime, m_dwDoubleKeyFifoTime;
CString m_strSavedClipboard, m_strPreviousStocked, m_strPreviousRecordedToHistory;
CString m_strSavedClipboard, m_strPreviousStocked;

COPYPASTE_KEY m_keySet;
std::vector<HOT_KEY_CODE> m_hotkeyVector;
Expand Down
155 changes: 77 additions & 78 deletions Charu3Tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,83 @@ HTREEITEM CCharu3Tree::AddData(HTREEITEM hTreeItem, STRING_DATA data, bool asChi
return InsertItem(&treeCtrlItem);
}

void CCharu3Tree::AddDataToHistoryFolders(STRING_DATA data)
{
int nSize = m_MyStringList.size(), nRirekiCount, nIsLock, i;
int nNumber = *m_pRecNumber;

STRING_DATA* parentData;
HTREEITEM hTreeItem, hStart = nullptr;

if (theApp.m_ini.m_bDebug) {
LOG(_T("addDataToRecordFolder"));
LOG(_T("hRootItem:%p TreeSize:%d"), GetRootItem(), nSize);
}
// hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_ROOT, 0);
for (hTreeItem = GetRootItem(), i = 0; i < nSize && hTreeItem && hTreeItem != hStart; i++, hTreeItem = GetTrueNextItem(hTreeItem)) {
parentData = getDataPtr(hTreeItem);
hStart = GetRootItem();
if ((parentData->m_cKind & KIND_RIREKI)
&& (
(data.m_strData != m_strPreviousRecordedToHistory)
|| !(getDataOption(parentData->m_strMacro, _T("duplicationcheck")))
)
) {
if (*m_pRecNumber == nNumber) nNumber++;

if (theApp.m_ini.m_bDebug) {
LOG(_T("number:%d handle:%p title:%s ID:%d"), i, hTreeItem, parentData->m_strTitle.GetString(), parentData->m_nMyID);
}

nIsLock = getDataOption(parentData->m_strMacro, _T("lock"));//履歴種別を取得
if (!nIsLock) data.m_cKind = KIND_ONETIME;
else data.m_cKind = KIND_LOCK;

nRirekiCount = getDataOption(parentData->m_strMacro, _T("count"));//履歴数を取得
if (nRirekiCount <= 0) nRirekiCount = 2;
int nDeleteCount = nRirekiCount;
deleteExcessChildren(GetChildItem(hTreeItem), &nDeleteCount);//余計な子を消す

int nTitleLength = getDataOption(parentData->m_strMacro, _T("titlelen"));//タイトルの文字数
CString strTitle;
if (nTitleLength > 0 && nTitleLength < 256) {
strTitle = makeTitle(data.m_strData, nTitleLength);
}
else
strTitle = makeTitle(data.m_strData);
data.m_strTitle = strTitle;

if (getDataOption(parentData->m_strMacro, _T("number"))) {//番号をつけるかどうか
data.m_strTitle.Format(_T("%02d : %s"), *m_pRecNumber, strTitle.GetString());
if (nNumber > nRirekiCount) nNumber = 0;
}

// archiving
{
int archiveBy;
if (hasDataOption(parentData->m_strMacro, _T("archiveunit"))) {
archiveBy = getDataOption(parentData->m_strMacro, _T("archiveunit"));
}
else {
archiveBy = getDataOption(parentData->m_strMacro, _T("classhistory")); // for historical compatibility
}
if (archiveBy > 0) {
archiveHistory(hTreeItem, archiveBy);
}
}

if (theApp.m_ini.m_bDebug) {
LOG(_T("AddDataToHistoryFolders %s %s %d"), data.m_strTitle.GetString(), data.m_strData.GetString(), nNumber);
}

AddData(hTreeItem, data, true);//追加
nSize = m_MyStringList.size();
}
}
*m_pRecNumber = nNumber;
m_strPreviousRecordedToHistory = data.m_strData;
}

void CCharu3Tree::DeleteData(HTREEITEM hTreeItem)
{
STRING_DATA* dataPtr = getDataPtr(hTreeItem);
Expand Down Expand Up @@ -1706,84 +1783,6 @@ CString CCharu3Tree::getDataOptionStr(CString strData, CString strKind)
return strRet;
}

//---------------------------------------------------
//関数名 addDataToRecordFolder(STRING_DATA data)
//機能 履歴処理をする
//---------------------------------------------------
void CCharu3Tree::addDataToRecordFolder(STRING_DATA data, CString strClipBkup)
{
int nSize = m_MyStringList.size(), nRirekiCount, nIsLock, i;
int nNumber = *m_pRecNumber;

STRING_DATA* parentData;
HTREEITEM hTreeItem, hStart = nullptr;

if (theApp.m_ini.m_bDebug) {
LOG(_T("addDataToRecordFolder"));
LOG(_T("hRootItem:%p TreeSize:%d"), GetRootItem(), nSize);
}
// hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_ROOT, 0);
for (hTreeItem = GetRootItem(), i = 0; i < nSize && hTreeItem && hTreeItem != hStart; i++, hTreeItem = GetTrueNextItem(hTreeItem)) {
parentData = getDataPtr(hTreeItem);
hStart = GetRootItem();
//履歴フォルダか判別
if (parentData->m_cKind & KIND_RIREKI) {
if ((strClipBkup != data.m_strData) || !(getDataOption(parentData->m_strMacro, _T("duplicationcheck")))) {
if (*m_pRecNumber == nNumber) nNumber++;

if (theApp.m_ini.m_bDebug) {
LOG(_T("number:%d handle:%p title:%s ID:%d"), i, hTreeItem, parentData->m_strTitle.GetString(), parentData->m_nMyID);
}

nIsLock = getDataOption(parentData->m_strMacro, _T("lock"));//履歴種別を取得
if (!nIsLock) data.m_cKind = KIND_ONETIME;
else data.m_cKind = KIND_LOCK;

nRirekiCount = getDataOption(parentData->m_strMacro, _T("count"));//履歴数を取得
if (nRirekiCount <= 0) nRirekiCount = 2;
int nDeleteCount = nRirekiCount;
deleteExcessChildren(GetChildItem(hTreeItem), &nDeleteCount);//余計な子を消す

int nTitleLength = getDataOption(parentData->m_strMacro, _T("titlelen"));//タイトルの文字数
CString strTitle;
if (nTitleLength > 0 && nTitleLength < 256) {
strTitle = makeTitle(data.m_strData, nTitleLength);
}
else
strTitle = makeTitle(data.m_strData);
data.m_strTitle = strTitle;

if (getDataOption(parentData->m_strMacro, _T("number"))) {//番号をつけるかどうか
data.m_strTitle.Format(_T("%02d : %s"), *m_pRecNumber, strTitle.GetString());
if (nNumber > nRirekiCount) nNumber = 0;
}

// archiving
{
int archiveBy;
if (hasDataOption(parentData->m_strMacro, _T("archiveunit"))) {
archiveBy = getDataOption(parentData->m_strMacro, _T("archiveunit"));
}
else {
archiveBy = getDataOption(parentData->m_strMacro, _T("classhistory")); // for historical compatibility
}
if (archiveBy > 0) {
archiveHistory(hTreeItem, archiveBy);
}
}

if (theApp.m_ini.m_bDebug) {
LOG(_T("addDataToRecordFolder \"%s\" %s %d"), data.m_strTitle.GetString(), data.m_strData.GetString(), nNumber);
}

AddData(hTreeItem, data, true);//追加
nSize = m_MyStringList.size();
}
}
}
*m_pRecNumber = nNumber;
}

//---------------------------------------------------
//関数名 archiveHistory(HTREEITEM hTreeItem)
//機能 履歴アーカイブ処理
Expand Down
8 changes: 7 additions & 1 deletion Charu3Tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ class CCharu3Tree : public CTreeCtrl
*/
HTREEITEM AddData(HTREEITEM hTreeItem, STRING_DATA data, bool asChild = false);

/**
* @brief Add a specified data to the history folders.
* @param data The data to add.
*/
void AddDataToHistoryFolders(STRING_DATA data);

/**
* @brief Delete a specified data.
* @param hTreeItem The tree item to delete.
Expand Down Expand Up @@ -210,7 +216,6 @@ class CCharu3Tree : public CTreeCtrl

int getDataOption(CString strData, CString strKind);
CString getDataOptionStr(CString strData, CString strKind);
void addDataToRecordFolder(STRING_DATA data, CString strClipBkup);
HTREEITEM moveFolderTop(HTREEITEM hTreeItem);
void ToggleItemCheck(HTREEITEM hItem);

Expand Down Expand Up @@ -265,6 +270,7 @@ class CCharu3Tree : public CTreeCtrl
int* m_pMaxID;
int* m_pSelectID;
int* m_pRecNumber;
CString m_strPreviousRecordedToHistory;

CImageList* m_ImageList;//イメージリスト

Expand Down

0 comments on commit f3c8c89

Please sign in to comment.