OSDN Git Service

Save and restore column widths for log and blame in registry.
authorColin Law <colin@clanlaw.org.uk>
Thu, 29 Jan 2009 16:09:43 +0000 (16:09 +0000)
committerFrank Li <lznuaa@gmail.com>
Fri, 30 Jan 2009 03:20:47 +0000 (11:20 +0800)
src/TortoiseProc/AppUtils.cpp
src/TortoiseProc/AppUtils.h
src/TortoiseProc/GitLogListBase.cpp
src/TortoiseProc/GitLogListBase.h
src/TortoiseProc/LogDlg.cpp
src/TortoiseProc/LogDlg.h

index 8d680b4..deeeeef 100644 (file)
@@ -607,47 +607,6 @@ bool CAppUtils::LaunchTortoiseBlame(const CString& sBlameFile,CString Rev,const
        return LaunchApplication(viewer, IDS_ERR_EXTDIFFSTART, false);\r
 }\r
 \r
-void CAppUtils::ResizeAllListCtrlCols(CListCtrl * pListCtrl)\r
-{\r
-       int maxcol = ((CHeaderCtrl*)(pListCtrl->GetDlgItem(0)))->GetItemCount()-1;\r
-       int nItemCount = pListCtrl->GetItemCount();\r
-       TCHAR textbuf[MAX_PATH];\r
-       CHeaderCtrl * pHdrCtrl = (CHeaderCtrl*)(pListCtrl->GetDlgItem(0));\r
-       if (pHdrCtrl)\r
-       {\r
-               for (int col = 0; col <= maxcol; col++)\r
-               {\r
-                       HDITEM hdi = {0};\r
-                       hdi.mask = HDI_TEXT;\r
-                       hdi.pszText = textbuf;\r
-                       hdi.cchTextMax = sizeof(textbuf);\r
-                       pHdrCtrl->GetItem(col, &hdi);\r
-                       int cx = pListCtrl->GetStringWidth(hdi.pszText)+20; // 20 pixels for col separator and margin\r
-                       for (int index = 0; index<nItemCount; ++index)\r
-                       {\r
-                               // get the width of the string and add 14 pixels for the column separator and margins\r
-                               int linewidth = pListCtrl->GetStringWidth(pListCtrl->GetItemText(index, col)) + 14;\r
-                               if (index == 0)\r
-                               {\r
-                                       // add the image size\r
-                                       CImageList * pImgList = pListCtrl->GetImageList(LVSIL_SMALL);\r
-                                       if ((pImgList)&&(pImgList->GetImageCount()))\r
-                                       {\r
-                                               IMAGEINFO imginfo;\r
-                                               pImgList->GetImageInfo(0, &imginfo);\r
-                                               linewidth += (imginfo.rcImage.right - imginfo.rcImage.left);\r
-                                               linewidth += 3; // 3 pixels between icon and text\r
-                                       }\r
-                               }\r
-                               if (cx < linewidth)\r
-                                       cx = linewidth;\r
-                       }\r
-                       pListCtrl->SetColumnWidth(col, cx);\r
-\r
-               }\r
-       }\r
-}\r
-\r
 bool CAppUtils::FormatTextInRichEditControl(CWnd * pWnd)\r
 {\r
        CString sText;\r
index 626aaa8..799fd5c 100644 (file)
@@ -115,12 +115,6 @@ public:
                const CString& sBlameFile, CString Rev, const CString& sParams = CString());\r
        \r
        /**\r
-        * Resizes all columns in a list control. Considers also icons in columns\r
-        * with no text.\r
-        */\r
-       static void ResizeAllListCtrlCols(CListCtrl * pListCtrl);\r
-\r
-       /**\r
         * Formats text in a rich edit control (version 2).\r
         * text in between * chars is formatted bold\r
         * text in between ^ chars is formatted italic\r
index cc87122..d9c7ed6 100644 (file)
@@ -216,83 +216,31 @@ void CGitLogListBase::InsertGitColumn()
 \r
 }\r
 \r
+/**\r
+ * Resizes all columns in a list control to values in registry.\r
+ */\r
 void CGitLogListBase::ResizeAllListCtrlCols()\r
 {\r
-\r
-       const int nMinimumWidth = ICONITEMBORDER+16*4;\r
-       int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1;\r
-       int nItemCount = GetItemCount();\r
-       TCHAR textbuf[MAX_PATH];\r
-       CHeaderCtrl * pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));\r
+       // column max and min widths to allow\r
+       static const int nMinimumWidth = 10;\r
+       static const int nMaximumWidth = 1000;\r
+       CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));\r
        if (pHdrCtrl)\r
        {\r
-               for (int col = 0; col <= maxcol; col++)\r
+               int numcols = pHdrCtrl->GetItemCount();\r
+               for (int col = 0; col < numcols; col++)\r
                {\r
-                       HDITEM hdi = {0};\r
-                       hdi.mask = HDI_TEXT;\r
-                       hdi.pszText = textbuf;\r
-                       hdi.cchTextMax = sizeof(textbuf);\r
-                       pHdrCtrl->GetItem(col, &hdi);\r
-                       int cx = GetStringWidth(hdi.pszText)+20; // 20 pixels for col separator and margin\r
-                       for (int index = 0; index<nItemCount; ++index)\r
+                       // get width for this col last time from registry\r
+                       CString regentry;\r
+                       regentry.Format( _T("Software\\TortoiseGit\\log\\ColWidth%d"), col);\r
+                       CRegDWORD regwidth(regentry, 0);\r
+                       int cx = regwidth;\r
+                       if (cx < nMinimumWidth)\r
                        {\r
-                               // get the width of the string and add 14 pixels for the column separator and margins\r
-                               int linewidth = GetStringWidth(GetItemText(index, col)) + 14;\r
-                               if (index < m_arShownList.GetCount())\r
-                               {\r
-                                       GitRev * pCurLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(index));\r
-                                       if ((pCurLogEntry)&&(pCurLogEntry->m_CommitHash == m_wcRev.m_CommitHash))\r
-                                       {\r
-                                               // set the bold font and ask for the string width again\r
-                                               SendMessage(WM_SETFONT, (WPARAM)m_boldFont, NULL);\r
-                                               linewidth = GetStringWidth(GetItemText(index, col)) + 14;\r
-                                               // restore the system font\r
-                                               SendMessage(WM_SETFONT, NULL, NULL);\r
-                                       }\r
-                               }\r
-                               if (index == 0)\r
-                               {\r
-                                       // add the image size\r
-                                       CImageList * pImgList = GetImageList(LVSIL_SMALL);\r
-                                       if ((pImgList)&&(pImgList->GetImageCount()))\r
-                                       {\r
-                                               IMAGEINFO imginfo;\r
-                                               pImgList->GetImageInfo(0, &imginfo);\r
-                                               linewidth += (imginfo.rcImage.right - imginfo.rcImage.left);\r
-                                               linewidth += 3; // 3 pixels between icon and text\r
-                                       }\r
-                               }\r
-                               if (cx < linewidth)\r
-                                       cx = linewidth;\r
-                       }\r
-                       // Adjust columns "Actions" containing icons\r
-                       if (col == this->LOGLIST_ACTION)\r
-                       {\r
-                               if (cx < nMinimumWidth)\r
-                               {\r
-                                       cx = nMinimumWidth;\r
-                               }\r
-                       }\r
-                       \r
-                       if (col == this->LOGLIST_MESSAGE)\r
-                       {\r
-                               if (cx > LOGLIST_MESSAGE_MAX)\r
-                               {\r
-                                       cx = LOGLIST_MESSAGE_MAX;\r
-                               }\r
-                               if (cx < LOGLIST_MESSAGE_MIN)\r
-                               {\r
-                                       cx = LOGLIST_MESSAGE_MIN;\r
-                               }\r
-\r
-                       }\r
-                       // keep the bug id column small\r
-                       if ((col == 4)&&(m_bShowBugtraqColumn))\r
+                               cx = nMinimumWidth;\r
+                       } else if (cx > nMaximumWidth)\r
                        {\r
-                               if (cx > (int)(DWORD)m_regMaxBugIDColWidth)\r
-                               {\r
-                                       cx = (int)(DWORD)m_regMaxBugIDColWidth;\r
-                               }\r
+                               cx = nMaximumWidth;\r
                        }\r
 \r
                        SetColumnWidth(col, cx);\r
@@ -1505,9 +1453,9 @@ UINT CGitLogListBase::LogThread()
                return 0;\r
 \r
        RedrawItems(0, m_arShownList.GetCount());\r
-       SetRedraw(false);\r
-       ResizeAllListCtrlCols();\r
-       SetRedraw(true);\r
+//     SetRedraw(false);\r
+//     ResizeAllListCtrlCols();\r
+//     SetRedraw(true);\r
 \r
        if ( m_pStoreSelection )\r
        {\r
@@ -1858,9 +1806,9 @@ void CGitLogListBase::RemoveFilter()
        DeleteAllItems();\r
        SetItemCountEx(ShownCountWithStopped());\r
        RedrawItems(0, ShownCountWithStopped());\r
-       SetRedraw(false);\r
-       ResizeAllListCtrlCols();\r
-       SetRedraw(true);\r
+//     SetRedraw(false);\r
+//     ResizeAllListCtrlCols();\r
+//     SetRedraw(true);\r
 \r
        InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
 }\r
@@ -1880,11 +1828,33 @@ void CGitLogListBase::Clear()
 \r
 void CGitLogListBase::OnDestroy()\r
 {\r
+       // save the column widths to the registry\r
+       SaveColumnWidths();\r
        while(m_LogCache.SaveCache())\r
        {\r
-               if(CMessageBox::Show(NULL,_T("Can Save Log Cache to Disk,click yes for retry, click no for give up"),_T("TortoiseGit"),\r
+               if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk,click yes for retry, click no for give up"),_T("TortoiseGit"),\r
                                                        MB_YESNO) == IDNO)\r
                                                        break;\r
        }\r
        CHintListCtrl::OnDestroy();\r
+}\r
+\r
+/**\r
+ * Save column widths to the registry\r
+ */\r
+void CGitLogListBase::SaveColumnWidths()\r
+{\r
+       CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));\r
+       if (pHdrCtrl)\r
+       {\r
+               int numcols = pHdrCtrl->GetItemCount();\r
+               for (int col = 0; col < numcols; col++)\r
+               {\r
+                       int width = GetColumnWidth( col );\r
+                       CString regentry;\r
+                       regentry.Format( _T("Software\\TortoiseGit\\log\\ColWidth%d"), col);\r
+                       CRegDWORD regwidth(regentry, 0);\r
+                       regwidth = width;       // this writes it to reg\r
+               }\r
+       }\r
 }
\ No newline at end of file
index 9b27658..47d78a2 100644 (file)
@@ -191,7 +191,10 @@ protected:
        void paintGraphLane(HDC hdc,int laneHeight, int type, int x1, int x2,\r
                                       const COLORREF& col,int top) ; \r
        void DrawLine(HDC hdc, int x1, int y1, int x2, int y2){::MoveToEx(hdc,x1,y1,NULL);::LineTo(hdc,x2,y2);}\r
-\r
+       /**\r
+       * Save column widths to the registry\r
+       */\r
+       void SaveColumnWidths();        // save col widths to the registry\r
 \r
        BOOL IsEntryInDateRange(int i);\r
 \r
index e2bb8a1..226983a 100644 (file)
@@ -581,7 +581,6 @@ void CLogDlg::FillLogMessageCtrl(bool bShow /* = true*/)
                m_ChangedFileListCtrl.Invalidate();\r
        }\r
 #endif\r
-       CAppUtils::ResizeAllListCtrlCols(&m_ChangedFileListCtrl);\r
        // sort according to the settings\r
        if (m_nSortColumnPathList > 0)\r
                SetSortArrow(&m_ChangedFileListCtrl, m_nSortColumnPathList, m_bAscendingPathList);\r
@@ -2683,89 +2682,6 @@ int CLogDlg::SortCompare(const void * pElem1, const void * pElem2)
        return 0;\r
 }\r
 \r
-#if 0\r
-void CLogDlg::ResizeAllListCtrlCols()\r
-{\r
-\r
-       const int nMinimumWidth = ICONITEMBORDER+16*4;\r
-       int maxcol = ((CHeaderCtrl*)(m_LogList.GetDlgItem(0)))->GetItemCount()-1;\r
-       int nItemCount = m_LogList.GetItemCount();\r
-       TCHAR textbuf[MAX_PATH];\r
-       CHeaderCtrl * pHdrCtrl = (CHeaderCtrl*)(m_LogList.GetDlgItem(0));\r
-       if (pHdrCtrl)\r
-       {\r
-               for (int col = 0; col <= maxcol; col++)\r
-               {\r
-                       HDITEM hdi = {0};\r
-                       hdi.mask = HDI_TEXT;\r
-                       hdi.pszText = textbuf;\r
-                       hdi.cchTextMax = sizeof(textbuf);\r
-                       pHdrCtrl->GetItem(col, &hdi);\r
-                       int cx = m_LogList.GetStringWidth(hdi.pszText)+20; // 20 pixels for col separator and margin\r
-                       for (int index = 0; index<nItemCount; ++index)\r
-                       {\r
-                               // get the width of the string and add 14 pixels for the column separator and margins\r
-                               int linewidth = m_LogList.GetStringWidth(m_LogList.GetItemText(index, col)) + 14;\r
-                               if (index < m_arShownList.GetCount())\r
-                               {\r
-                                       GitRev * pCurLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(index));\r
-                                       if ((pCurLogEntry)&&(pCurLogEntry->m_CommitHash == m_wcRev.m_CommitHash))\r
-                                       {\r
-                                               // set the bold font and ask for the string width again\r
-                                               m_LogList.SendMessage(WM_SETFONT, (WPARAM)m_boldFont, NULL);\r
-                                               linewidth = m_LogList.GetStringWidth(m_LogList.GetItemText(index, col)) + 14;\r
-                                               // restore the system font\r
-                                               m_LogList.SendMessage(WM_SETFONT, NULL, NULL);\r
-                                       }\r
-                               }\r
-                               if (index == 0)\r
-                               {\r
-                                       // add the image size\r
-                                       CImageList * pImgList = m_LogList.GetImageList(LVSIL_SMALL);\r
-                                       if ((pImgList)&&(pImgList->GetImageCount()))\r
-                                       {\r
-                                               IMAGEINFO imginfo;\r
-                                               pImgList->GetImageInfo(0, &imginfo);\r
-                                               linewidth += (imginfo.rcImage.right - imginfo.rcImage.left);\r
-                                               linewidth += 3; // 3 pixels between icon and text\r
-                                       }\r
-                               }\r
-                               if (cx < linewidth)\r
-                                       cx = linewidth;\r
-                       }\r
-                       // Adjust columns "Actions" containing icons\r
-                       if (col == this->LOGLIST_ACTION)\r
-                       {\r
-                               if (cx < nMinimumWidth)\r
-                               {\r
-                                       cx = nMinimumWidth;\r
-                               }\r
-                       }\r
-                       \r
-                       if (col == this->LOGLIST_MESSAGE)\r
-                       {\r
-                               if (cx > LOGLIST_MESSAGE_MAX)\r
-                               {\r
-                                       cx = LOGLIST_MESSAGE_MAX;\r
-                               }\r
-\r
-                       }\r
-                       // keep the bug id column small\r
-                       if ((col == 4)&&(m_bShowBugtraqColumn))\r
-                       {\r
-                               if (cx > (int)(DWORD)m_regMaxBugIDColWidth)\r
-                               {\r
-                                       cx = (int)(DWORD)m_regMaxBugIDColWidth;\r
-                               }\r
-                       }\r
-\r
-                       m_LogList.SetColumnWidth(col, cx);\r
-               }\r
-       }\r
-\r
-}\r
-#endif\r
-\r
 void CLogDlg::OnBnClickedHidepaths()\r
 {\r
        FillLogMessageCtrl();\r
index fa42a04..0ec6952 100644 (file)
@@ -197,8 +197,6 @@ private:
        virtual LRESULT DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam);\r
        static int __cdecl      SortCompare(const void * pElem1, const void * pElem2);  ///< sort callback function\r
 \r
-       void ResizeAllListCtrlCols();\r
-\r
        void ShowContextMenuForRevisions(CWnd* pWnd, CPoint point);\r
        void ShowContextMenuForChangedpaths(CWnd* pWnd, CPoint point);\r
 public:\r