OSDN Git Service

DirView.*: Add IsDiffItemSpecial() function
authorTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sun, 30 May 2021 02:02:39 +0000 (11:02 +0900)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sun, 30 May 2021 02:02:39 +0000 (11:02 +0900)
Src/DirView.cpp
Src/DirView.h

index 5b41f24..f067156 100644 (file)
@@ -1417,7 +1417,7 @@ void CDirView::OpenSelection(SELECTIONTYPE selectionType /*= SELECTIONTYPE_NORMA
 
        // Now handle the various cases of what was selected
 
-       if (pos1 == (DIFFITEM *)SPECIAL_ITEM_POS)
+       if (IsDiffItemSpecial(pos1))
        {
                OpenSpecialItems(pos1, pos2, pos3);
                return;
@@ -1489,7 +1489,7 @@ void CDirView::OpenSelectionAs(UINT id)
 
        // Now handle the various cases of what was selected
 
-       if (pos1 == (DIFFITEM *)SPECIAL_ITEM_POS)
+       if (IsDiffItemSpecial(pos1))
        {
                ASSERT(false);
                return;
@@ -1647,7 +1647,7 @@ DIFFITEM &CDirView::GetDiffItem(int sel)
        DIFFITEM *diffpos = GetItemKey(sel);
 
        // If it is special item, return empty DIFFITEM
-       if (diffpos == (DIFFITEM *)SPECIAL_ITEM_POS)
+       if (IsDiffItemSpecial(diffpos))
        {
                return *DIFFITEM::GetEmptyItem();
        }
@@ -1657,7 +1657,7 @@ DIFFITEM &CDirView::GetDiffItem(int sel)
 void CDirView::DeleteItem(int sel, bool removeDIFFITEM)
 {
        DIFFITEM *diffpos = GetItemKey(sel);
-       if (diffpos == (DIFFITEM*)SPECIAL_ITEM_POS)
+       if (IsDiffItemSpecial(diffpos))
                return;
        if (m_bTreeMode)
        {
@@ -1722,7 +1722,7 @@ int CDirView::GetItemIndex(DIFFITEM *key)
 void CDirView::GetItemFileNames(int sel, String& strLeft, String& strRight) const
 {
        DIFFITEM *diffpos = GetItemKey(sel);
-       if (diffpos == (DIFFITEM *)SPECIAL_ITEM_POS)
+       if (IsDiffItemSpecial(diffpos))
        {
                strLeft.erase();
                strRight.erase();
@@ -1741,7 +1741,7 @@ void CDirView::GetItemFileNames(int sel, String& strLeft, String& strRight) cons
 void CDirView::GetItemFileNames(int sel, PathContext * paths) const
 {
        DIFFITEM *diffpos = GetItemKey(sel);
-       if (diffpos == (DIFFITEM *)SPECIAL_ITEM_POS)
+       if (IsDiffItemSpecial(diffpos))
        {
                for (int nIndex = 0; nIndex < GetDocument()->m_nDirs; nIndex++)
                        paths->SetPath(nIndex, _T(""));
@@ -1895,7 +1895,7 @@ void CDirView::DoUpdateOpen(SELECTIONTYPE selectionType, CCmdUI* pCmdUI, bool op
                if (!openableForDir)
                {
                        const DIFFITEM& di1 = GetDiffItem(sel1);
-                       if (di1.diffcode.isDirectory() || GetItemKey(sel1) == reinterpret_cast<DIFFITEM*>(SPECIAL_ITEM_POS))
+                       if (di1.diffcode.isDirectory() || IsDiffItemSpecial(GetItemKey(sel1)))
                        {
                                pCmdUI->Enable(FALSE);
                                return;
@@ -3014,7 +3014,7 @@ void CDirView::OnSelectAll()
                {
                        // Don't select special items (SPECIAL_ITEM_POS)
                        DIFFITEM *diffpos = GetItemKey(i);
-                       if (diffpos != (DIFFITEM *)SPECIAL_ITEM_POS)
+                       if (!IsDiffItemSpecial(diffpos))
                                m_pList->SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
                }
        }
@@ -3351,7 +3351,7 @@ void CDirView::OnUpdateStatusNum(CCmdUI* pCmdUI)
        {
                // Don't show number to special items
                DIFFITEM *pos = GetItemKey(focusItem);
-               if (pos != (DIFFITEM *)SPECIAL_ITEM_POS)
+               if (!IsDiffItemSpecial(pos))
                {
                        // If compare is non-recursive reduce special items count
                        bool bRecursive = GetDiffContext().m_bRecursive;
@@ -4045,7 +4045,7 @@ void CDirView::OnSearch()
        for (int currRow = nRows - 1; currRow >= 0; currRow--)
        {
                DIFFITEM *pos = GetItemKey(currRow);
-               if (pos == (DIFFITEM *)SPECIAL_ITEM_POS)
+               if (IsDiffItemSpecial(pos))
                        continue;
 
                bool bFound = false;
@@ -4257,7 +4257,7 @@ void CDirView::ReflectGetdispinfo(NMLVDISPINFO *pParam)
        int nIdx = pParam->item.iItem;
        int i = m_pColItems->ColPhysToLog(pParam->item.iSubItem);
        DIFFITEM *key = GetItemKey(nIdx);
-       if (key == (DIFFITEM *)SPECIAL_ITEM_POS)
+       if (IsDiffItemSpecial(key))
        {
                if (m_pColItems->IsColName(i))
                {
index 3b91abf..3132cb8 100644 (file)
@@ -86,6 +86,7 @@ public:
        void LoadColumnHeaderItems();
        DIFFITEM *GetItemKey(int idx) const;
        int GetItemIndex(DIFFITEM *key);
+       bool IsDiffItemSpecial(const DIFFITEM* diffpos) const { return diffpos == reinterpret_cast<DIFFITEM*>(SPECIAL_ITEM_POS); };
        // for populating list
        void DeleteItem(int sel, bool removeDIFFITEM = false);
        void DeleteAllDisplayItems();