OSDN Git Service

PATCH: [ 1229867 ] RFE [ 1205516 ], RFE [ 887948 ], and other issues
authorKimmo Varis <kimmov@gmail.com>
Thu, 30 Jun 2005 16:30:50 +0000 (16:30 +0000)
committerKimmo Varis <kimmov@gmail.com>
Thu, 30 Jun 2005 16:30:50 +0000 (16:30 +0000)
  Submitted by Jochen, apply some parts now:
  Misc cleanups and optimizations

Src/DirDoc.cpp
Src/DirDoc.h
Src/DirView.cpp
Src/DirView.h
Src/readme.txt

index f3d14b4..dd54063 100644 (file)
@@ -563,15 +563,14 @@ BOOL CDirDoc::ReusingDirDoc()
 
        // clear diff display
        ASSERT(m_pDirView);
-       m_pDirView->DeleteAllDisplayItems();
+       m_pDirView->ReusingDirView();
 
        // hide the floating state bar
        CDirFrame *pf = m_pDirView->GetParentFrame();
        pf->ShowProcessingBar(FALSE);
 
        // delete comparison parameters and results
-       if (m_pCtxt != NULL)
-               delete m_pCtxt;
+       delete m_pCtxt;
        m_pCtxt = NULL;
 
        return TRUE;
@@ -798,7 +797,7 @@ bool CDirDoc::IsCurrentScanAbortable() const
 /**
  * @brief Set directory description texts shown in headerbar
  */
-void CDirDoc::SetDescriptions(CString strLeftDesc, CString strRightDesc)
+void CDirDoc::SetDescriptions(const CString &strLeftDesc, const CString &strRightDesc)
 {
        m_strLeftDesc = strLeftDesc;
        m_strRightDesc = strRightDesc;
index 9f06731..c320a7c 100644 (file)
@@ -110,7 +110,8 @@ public:
        void UpdateHeaderPath(BOOL bLeft);
        void AbortCurrentScan();
        bool IsCurrentScanAbortable() const;
-       void SetDescriptions(CString strLeftDesc, CString strRightDesc);
+       void SetDescriptions(const CString &strLeftDesc, const CString &strRightDesc);
+
        void SetPluginPrediffSetting(const CString & filteredFilenames, int newsetting);
        void FetchPluginInfos(const CString& filteredFilenames, 
                              PackingInfo ** infoUnpacker, PrediffingInfo ** infoPrediffer);
index 4bcba4b..db34a09 100644 (file)
@@ -167,6 +167,7 @@ BEGIN_MESSAGE_MAP(CDirView, CListViewEx)
        ON_UPDATE_COMMAND_UI(ID_DIR_MOVE_LEFT_TO_BROWSE, OnUpdateCtxtDirMoveLeftTo)
        ON_COMMAND(ID_DIR_MOVE_RIGHT_TO_BROWSE, OnCtxtDirMoveRightTo)
        ON_UPDATE_COMMAND_UI(ID_DIR_MOVE_RIGHT_TO_BROWSE, OnUpdateCtxtDirMoveRightTo)
+       ON_UPDATE_COMMAND_UI(ID_DIR_HIDE_FILENAMES, OnUpdateHideFilenames)
        ON_WM_SIZE()
        ON_COMMAND(ID_MERGE_DELETE, OnDelete)
        ON_UPDATE_COMMAND_UI(ID_MERGE_DELETE, OnUpdateDelete)
@@ -1170,6 +1171,15 @@ void CDirView::DeleteAllDisplayItems()
 }
 
 /**
+ * @brief Prepare for reuse.
+ *
+ */
+void CDirView::ReusingDirView()
+{
+       DeleteAllDisplayItems();
+}
+
+/**
  * @brief Given key, get index of item which has it stored.
  * This function searches from list in UI.
  */
@@ -2091,7 +2101,7 @@ int CDirView::AddSpecialItems()
        if (paths_DoesPathExist(leftParent) == IS_EXISTING_DIR &&
                paths_DoesPathExist(rightParent) == IS_EXISTING_DIR)
        {
-               int bEnable = AllowUpwardDirectory(leftPath, rightPath); 
+               BOOL bEnable = AllowUpwardDirectory(leftPath, rightPath); 
                AddParentFolderItem(bEnable);
                retVal = 1;
        }
@@ -2106,7 +2116,7 @@ int CDirView::AddSpecialItems()
  * FALSE : upward RESTRICTED : both paths have a different rightmost subdirectory, 
  * the move can not be reversed (probably these are the original comparison directories)
  */
-BOOL CDirView::AllowUpwardDirectory(CString leftPath, CString rightPath)
+BOOL CDirView::AllowUpwardDirectory(const CString &leftPath, const CString &rightPath)
 {
        int lastSegmentPos = leftPath.ReverseFind(_T('/'));
        if (lastSegmentPos == -1 || leftPath.ReverseFind(_T('\\')) > lastSegmentPos)
@@ -2402,30 +2412,20 @@ void CDirView::OnCopyFilenames()
 void CDirView::OnHideFilenames()
 {
        int sel = -1;
-       int Cnt = 0, Max = 1000;
-       int *pCells = new int[Max];
-       // Build a dynamic int array, storing a sorted list of selected cells
+       m_pList->SetRedraw(FALSE);      // Turn off updating (better performance)
        while ((sel = m_pList->GetNextItem(sel, LVNI_SELECTED)) != -1)
        {
-               if (Cnt == Max)
-               {
-                       Max += 1000;    // Grow the array of selections
-                       int *pCellsTmp = new int[Max];
-                       memcpy(pCellsTmp, pCells, sizeof(int)*Cnt);
-                       delete[] pCells;
-                       pCells = pCellsTmp;
-               }
-               pCells[Cnt++] = sel;
-       }
-       if (Cnt)
-       {
-               // Remove cells in reverse order (largest to smallest count).
-               m_pList->SetRedraw(FALSE);      // Turn off updating (better performance)
-               while (Cnt--)
-                       m_pList->DeleteItem(pCells[Cnt]);
-               m_pList->SetRedraw(TRUE);       // Turn updating back on
+               m_pList->DeleteItem(sel--);
        }
-       delete[] pCells;
+       m_pList->SetRedraw(TRUE);       // Turn updating back on
+}
+
+/**
+ * @brief update menu item
+ */
+void CDirView::OnUpdateHideFilenames(CCmdUI* pCmdUI) 
+{
+       pCmdUI->Enable(m_pList->GetSelectedCount() != 0);
 }
 
 /// User chose (context menu) Move left to...
@@ -2510,7 +2510,7 @@ void CDirView::OnItemChanged(NMHDR* pNMHDR, LRESULT* pResult)
                        VERIFY(msg.LoadString(IDS_STATUS_SELITEM1));
                else
                {
-                       TCHAR num[8] = {0};
+                       TCHAR num[20] = {0};
                        _itot(items, num, 10);
                        AfxFormatString1(msg, IDS_STATUS_SELITEMS, num);
                }
index 3dff1a3..e6e929f 100644 (file)
@@ -94,6 +94,7 @@ public:
        int GetItemIndex(DWORD key);
        // for populating list
        void DeleteAllDisplayItems();
+       void ReusingDirView();
        void SetColumnWidths();
 
        void SortColumnsAppropriately();
@@ -103,7 +104,7 @@ public:
        //DIFFITEM GetNextSelectedInd(int &ind);
        DIFFITEM GetItemAt(int ind);
        int AddSpecialItems();
-       BOOL AllowUpwardDirectory(CString leftPath, CString rightPath);
+       BOOL AllowUpwardDirectory(const CString &leftPath, const CString &rightPath);
        void AddParentFolderItem(BOOL bEnable);
        void RefreshOptions();
 
@@ -323,6 +324,7 @@ protected:
        afx_msg void OnUpdateCtxtDirMoveLeftTo(CCmdUI* pCmdUI);
        afx_msg void OnCtxtDirMoveRightTo();
        afx_msg void OnUpdateCtxtDirMoveRightTo(CCmdUI* pCmdUI);
+       afx_msg void OnUpdateHideFilenames(CCmdUI* pCmdUI);
        afx_msg void OnDelete();
        afx_msg void OnUpdateDelete(CCmdUI* pCmdUI);
        afx_msg void OnMarkedRescan();
index 1b84a36..66fbfed 100644 (file)
@@ -11,6 +11,8 @@
    Src: DiffItem.cpp DiffItem.h
   Add missing ProgressBar initialisation
    Src: DirCompStateBar.cpp
+  Misc cleanups and optimizations
+   Src: DirDoc.cpp DirDoc.h DirView.cpp DirView.h
 
 2005-06-29 Perry
  PATCH: [ 1220421 ] warning in cvs trunk (probably a bool/BOOL mismatch)