OSDN Git Service

Update TortoiseUDiff to version 16491
authorFrank Li <lznuaa@gmail.com>
Thu, 4 Jun 2009 14:24:15 +0000 (22:24 +0800)
committerFrank Li <lznuaa@gmail.com>
Thu, 4 Jun 2009 14:24:15 +0000 (22:24 +0800)
Signed-off-by: Frank Li <lznuaa@gmail.com>
src/TortoiseUDiff/MainWindow.cpp
src/TortoiseUDiff/MainWindow.h
src/TortoiseUDiff/TortoiseUDiff.rc
src/TortoiseUDiff/resource.h
src/TortoiseUDiff/stdafx.h
src/Utils/registry.h

index d8b545f..fd93a06 100644 (file)
@@ -1,6 +1,6 @@
 // TortoiseSVN - a Windows shell extension for easy version control\r
 \r
-// Copyright (C) 2003-2008 - TortoiseSVN\r
+// Copyright (C) 2003-2009 - TortoiseSVN\r
 \r
 // This program is free software; you can redistribute it and/or\r
 // modify it under the terms of the GNU General Public License\r
@@ -126,9 +126,9 @@ LRESULT CALLBACK CMainWindow::WinMsgHandler(HWND hwnd, UINT uMsg, WPARAM wParam,
                break;\r
        case WM_CLOSE:\r
                {\r
-                       CRegStdWORD w = CRegStdWORD(_T("Software\\TortoiseGit\\UDiffViewerWidth"), (DWORD)CW_USEDEFAULT);\r
-                       CRegStdWORD h = CRegStdWORD(_T("Software\\TortoiseGit\\UDiffViewerHeight"), (DWORD)CW_USEDEFAULT);\r
-                       CRegStdWORD p = CRegStdWORD(_T("Software\\TortoiseGit\\UDiffViewerPos"), 0);\r
+                       CRegStdDWORD w = CRegStdDWORD(_T("Software\\TortoiseGit\\UDiffViewerWidth"), (DWORD)CW_USEDEFAULT);\r
+                       CRegStdDWORD h = CRegStdDWORD(_T("Software\\TortoiseGit\\UDiffViewerHeight"), (DWORD)CW_USEDEFAULT);\r
+                       CRegStdDWORD p = CRegStdDWORD(_T("Software\\TortoiseGit\\UDiffViewerPos"), 0);\r
 \r
                        RECT rect;\r
                        ::GetWindowRect(*this, &rect);\r
@@ -188,6 +188,78 @@ LRESULT CMainWindow::DoCommand(int id)
 {\r
        switch (id) \r
        {\r
+       case ID_FILE_OPEN:\r
+               {\r
+                       OPENFILENAME ofn = {0};                         // common dialog box structure\r
+                       TCHAR szFile[MAX_PATH] = {0};           // buffer for file name\r
+                       // Initialize OPENFILENAME\r
+                       ofn.lStructSize = sizeof(OPENFILENAME);\r
+                       ofn.hwndOwner = *this;\r
+                       ofn.lpstrFile = szFile;\r
+                       ofn.nMaxFile = sizeof(szFile)/sizeof(TCHAR);\r
+                       TCHAR filter[1024];\r
+                       LoadString(hResource, IDS_PATCHFILEFILTER, filter, sizeof(filter)/sizeof(TCHAR));\r
+                       TCHAR * pszFilters = filter;\r
+                       // Replace '|' delimiters with '\0's\r
+                       TCHAR *ptr = pszFilters + _tcslen(pszFilters);  //set ptr at the NULL\r
+                       while (ptr != pszFilters)\r
+                       {\r
+                               if (*ptr == '|')\r
+                                       *ptr = '\0';\r
+                               ptr--;\r
+                       }\r
+                       ofn.lpstrFilter = pszFilters;\r
+                       ofn.nFilterIndex = 1;\r
+                       ofn.lpstrFileTitle = NULL;\r
+                       ofn.nMaxFileTitle = 0;\r
+                       ofn.lpstrInitialDir = NULL;\r
+                       TCHAR opentitle[1024];\r
+                       LoadString(hResource, IDS_OPENPATCH, opentitle, sizeof(opentitle)/sizeof(TCHAR));\r
+                       ofn.lpstrTitle = opentitle;\r
+                       ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_ENABLESIZING | OFN_EXPLORER;\r
+                       // Display the Open dialog box. \r
+                       if (GetOpenFileName(&ofn)==TRUE)\r
+                       {\r
+                               LoadFile(ofn.lpstrFile);\r
+                       }\r
+               }\r
+               break;\r
+       case ID_FILE_SAVEAS:\r
+               {\r
+                       OPENFILENAME ofn = {0};                         // common dialog box structure\r
+                       TCHAR szFile[MAX_PATH] = {0};           // buffer for file name\r
+                       // Initialize OPENFILENAME\r
+                       ofn.lStructSize = sizeof(OPENFILENAME);\r
+                       ofn.hwndOwner = *this;\r
+                       ofn.lpstrFile = szFile;\r
+                       ofn.nMaxFile = sizeof(szFile)/sizeof(TCHAR);\r
+                       TCHAR filter[1024];\r
+                       LoadString(hResource, IDS_PATCHFILEFILTER, filter, sizeof(filter)/sizeof(TCHAR));\r
+                       TCHAR * pszFilters = filter;\r
+                       // Replace '|' delimiters with '\0's\r
+                       TCHAR *ptr = pszFilters + _tcslen(pszFilters);  //set ptr at the NULL\r
+                       while (ptr != pszFilters)\r
+                       {\r
+                               if (*ptr == '|')\r
+                                       *ptr = '\0';\r
+                               ptr--;\r
+                       }\r
+                       ofn.lpstrFilter = pszFilters;\r
+                       ofn.nFilterIndex = 1;\r
+                       ofn.lpstrFileTitle = NULL;\r
+                       ofn.nMaxFileTitle = 0;\r
+                       ofn.lpstrInitialDir = NULL;\r
+                       TCHAR savetitle[1024];\r
+                       LoadString(hResource, IDS_SAVEPATCH, savetitle, sizeof(savetitle)/sizeof(TCHAR));\r
+                       ofn.lpstrTitle = savetitle;\r
+                       ofn.Flags = OFN_OVERWRITEPROMPT | OFN_ENABLESIZING | OFN_EXPLORER;\r
+                       // Display the Open dialog box. \r
+                       if (GetSaveFileName(&ofn)==TRUE)\r
+                       {\r
+                               SaveFile(ofn.lpstrFile);\r
+                       }\r
+               }\r
+               break;\r
        case ID_FILE_EXIT:\r
                ::PostQuitMessage(0);\r
                return 0;\r
@@ -257,9 +329,9 @@ LRESULT CMainWindow::SendEditor(UINT Msg, WPARAM wParam, LPARAM lParam)
 \r
 bool CMainWindow::Initialize()\r
 {\r
-       CRegStdWORD pos(_T("Software\\TortoiseGit\\UDiffViewerPos"), 0);\r
-       CRegStdWORD width(_T("Software\\TortoiseGit\\UDiffViewerWidth"), (DWORD)640);\r
-       CRegStdWORD height(_T("Software\\TortoiseGit\\UDiffViewerHeight"), (DWORD)480);\r
+       CRegStdDWORD pos(_T("Software\\TortoiseGit\\UDiffViewerPos"), 0);\r
+       CRegStdDWORD width(_T("Software\\TortoiseGit\\UDiffViewerWidth"), (DWORD)640);\r
+       CRegStdDWORD height(_T("Software\\TortoiseGit\\UDiffViewerHeight"), (DWORD)480);\r
        if (DWORD(pos) && DWORD(width) && DWORD(height))\r
        {\r
                RECT rc;\r
@@ -304,7 +376,7 @@ bool CMainWindow::Initialize()
                // Reusing TortoiseBlame's setting which already have an user friendly\r
                // pane in TortoiseSVN's Settings dialog, while there is no such\r
                // pane for TortoiseUDiff.\r
-               CRegStdWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10),\r
+               CRegStdDWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10),\r
                WideToMultibyte(CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"))).c_str());\r
        SendEditor(SCI_SETTABWIDTH, 4);\r
        SendEditor(SCI_SETREADONLY, TRUE);\r
@@ -337,7 +409,7 @@ bool CMainWindow::LoadFile(LPCTSTR filename)
        {\r
                //SetTitle();\r
                char data[4096];\r
-               int lenFile = fread(data, 1, sizeof(data), fp);\r
+               size_t lenFile = fread(data, 1, sizeof(data), fp);\r
                bool bUTF8 = IsUTF8(data, lenFile);\r
                while (lenFile > 0) \r
                {\r
@@ -358,7 +430,6 @@ bool CMainWindow::LoadFile(LPCTSTR filename)
        SendEditor(EM_EMPTYUNDOBUFFER);\r
        SendEditor(SCI_SETSAVEPOINT);\r
        SendEditor(SCI_GOTOPOS, 0);\r
-       SendEditor(SCI_SETREADONLY, TRUE);\r
 \r
        SendEditor(SCI_CLEARDOCUMENTSTYLE, 0, 0);\r
        SendEditor(SCI_SETSTYLEBITS, 5, 0);\r
@@ -379,9 +450,31 @@ bool CMainWindow::LoadFile(LPCTSTR filename)
        return true;\r
 }\r
 \r
+bool CMainWindow::SaveFile(LPCTSTR filename)\r
+{\r
+       FILE *fp = NULL;\r
+       _tfopen_s(&fp, filename, _T("w+b"));\r
+       if (fp) \r
+       {\r
+               int len = SendEditor(SCI_GETTEXT, 0, 0);\r
+               char * data = new char[len+1];\r
+               SendEditor(SCI_GETTEXT, len, (LPARAM)data);\r
+               fwrite(data, sizeof(char), len-1, fp);\r
+               fclose(fp);\r
+       }\r
+       else \r
+       {\r
+               return false;\r
+       }\r
+\r
+       SendEditor(SCI_SETSAVEPOINT);\r
+       ::ShowWindow(m_hWndEdit, SW_SHOW);\r
+       return true;\r
+}\r
+\r
 void CMainWindow::SetTitle(LPCTSTR title)\r
 {\r
-       int len = _tcslen(title);\r
+       size_t len = _tcslen(title);\r
        TCHAR * pBuf = new TCHAR[len+40];\r
        _stprintf_s(pBuf, len+40, _T("%s - TortoiseUDiff"), title);\r
        SetWindowTitle(std::wstring(pBuf));\r
@@ -398,7 +491,7 @@ void CMainWindow::SetAStyle(int style, COLORREF fore, COLORREF back, int size, c
                SendEditor(SCI_STYLESETFONT, style, reinterpret_cast<LPARAM>(face));\r
 }\r
 \r
-bool CMainWindow::IsUTF8(LPVOID pBuffer, int cb)\r
+bool CMainWindow::IsUTF8(LPVOID pBuffer, size_t cb)\r
 {\r
        if (cb < 2)\r
                return true;\r
@@ -406,7 +499,7 @@ bool CMainWindow::IsUTF8(LPVOID pBuffer, int cb)
        UINT8 * pVal2 = (UINT8 *)(pVal+1);\r
        // scan the whole buffer for a 0x0000 sequence\r
        // if found, we assume a binary file\r
-       for (int i=0; i<(cb-2); i=i+2)\r
+       for (size_t i=0; i<(cb-2); i=i+2)\r
        {\r
                if (0x0000 == *pVal++)\r
                        return false;\r
@@ -423,7 +516,7 @@ bool CMainWindow::IsUTF8(LPVOID pBuffer, int cb)
        }\r
        // check for illegal UTF8 chars\r
        pVal2 = (UINT8 *)pBuffer;\r
-       for (int i=0; i<cb; ++i)\r
+       for (size_t i=0; i<cb; ++i)\r
        {\r
                if ((*pVal2 == 0xC0)||(*pVal2 == 0xC1)||(*pVal2 >= 0xF5))\r
                        return false;\r
@@ -431,7 +524,7 @@ bool CMainWindow::IsUTF8(LPVOID pBuffer, int cb)
        }\r
        pVal2 = (UINT8 *)pBuffer;\r
        bool bUTF8 = false;\r
-       for (int i=0; i<(cb-3); ++i)\r
+       for (size_t i=0; i<(cb-3); ++i)\r
        {\r
                if ((*pVal2 & 0xE0)==0xC0)\r
                {\r
index 820ae09..4356fc5 100644 (file)
@@ -1,6 +1,6 @@
 // TortoiseSVN - a Windows shell extension for easy version control\r
 \r
-// Copyright (C) 2007 - TortoiseUDiff\r
+// Copyright (C) 2007,2009 - TortoiseUDiff\r
 \r
 // This program is free software; you can redistribute it and/or\r
 // modify it under the terms of the GNU General Public License\r
@@ -47,6 +47,7 @@ public:
        LRESULT                         SendEditor(UINT Msg, WPARAM wParam = 0, LPARAM lParam = 0);\r
        HWND                            GetHWNDEdit() { return m_hWndEdit; }\r
        bool                            LoadFile(LPCTSTR filename);\r
+       bool                            SaveFile(LPCTSTR filename);\r
        void                            SetTitle(LPCTSTR title);\r
 \r
 protected:\r
@@ -58,9 +59,8 @@ protected:
        bool                            Initialize();\r
 \r
 private:\r
-       void                            SetAStyle(int style, COLORREF fore, COLORREF back=::GetSysColor(COLOR_WINDOW), \r
-               int size=-1, const char *face=0);\r
-       bool                IsUTF8(LPVOID pBuffer, int cb);\r
+       void                            SetAStyle(int style, COLORREF fore, COLORREF back=::GetSysColor(COLOR_WINDOW), int size=-1, const char *face=0);\r
+       bool                IsUTF8(LPVOID pBuffer, size_t cb);\r
 \r
 private:\r
        LRESULT                         m_directFunction;\r
index 7b8b7d1..09df153 100644 (file)
@@ -80,6 +80,9 @@ IDC_TORTOISEUDIFF MENU
 BEGIN\r
     POPUP "&File"\r
     BEGIN\r
+        MENUITEM "&Open",                       ID_FILE_OPEN\r
+        MENUITEM "&Save as",                    ID_FILE_SAVEAS\r
+        MENUITEM SEPARATOR\r
         MENUITEM "&Exit",                       ID_FILE_EXIT\r
     END\r
 END\r
@@ -112,6 +115,9 @@ STRINGTABLE
 BEGIN\r
     IDS_APP_TITLE           "TortoiseUDiff"\r
     IDS_COMMANDLINEHELP     "TortoiseUDiff: the unified diff viewer for TortoiseSVN\n\nAvailable command line parameters are:\n/patchfile:""path to unified diff file""\n/title:""title to show for the viewer"""\r
+    IDS_PATCHFILEFILTER     "Patchfiles (*.diff, *.patch)|*.diff;*.patch|All (*.*)|*.*||"\r
+    IDS_OPENPATCH           "Open patch file"\r
+    IDS_SAVEPATCH           "Save patch file"\r
     IDC_TORTOISEUDIFF       "TORTOISEUDIFF"\r
 END\r
 \r
@@ -146,12 +152,13 @@ BEGIN
     "#ifndef APSTUDIO_INVOKED\r\n"\r
     "#include ""TortoiseUDiff.rc2""\r\n"\r
     "#endif\r\n"\r
-    "#undef APSTUDIO_HIDDEN_SYMBOLS\r\n\0"\r
+    "#undef APSTUDIO_HIDDEN_SYMBOLS\r\n"\r
+    "\0"\r
 END\r
 \r
 3 TEXTINCLUDE \r
 BEGIN\r
-    "\r\0"\r
+    "\r\n\0"\r
 END\r
 \r
 #endif    // APSTUDIO_INVOKED\r
index b8979f7..f8f7f1a 100644 (file)
@@ -6,7 +6,10 @@
 #define IDS_APP_TITLE                   103\r
 #define IDM_ABOUT                       104\r
 #define IDS_COMMANDLINEHELP             104\r
+#define IDS_PATCHFILEFILTER             105\r
+#define IDS_OPENPATCH                   106\r
 #define IDI_TORTOISEUDIFF               107\r
+#define IDS_SAVEPATCH                   107\r
 #define IDC_TORTOISEUDIFF               109\r
 #define IDR_MAINFRAME                   128\r
 #define IDB_CANCELNORMAL                130\r
@@ -19,6 +22,8 @@
 #define IDC_MATCHCASECHECK              1021\r
 #define IDC_FINDEXIT                    1022\r
 #define ID_FILE_EXIT                    32771\r
+#define ID_FILE_SAVEAS                  32773\r
+#define ID_FILE_OPEN                    32774\r
 #define IDM_SHOWFINDBAR                 32787\r
 #define IDM_FINDNEXT                    32789\r
 #define IDM_FINDPREV                    32790\r
@@ -31,7 +36,7 @@
 #ifndef APSTUDIO_READONLY_SYMBOLS\r
 #define _APS_NO_MFC                     1\r
 #define _APS_NEXT_RESOURCE_VALUE        133\r
-#define _APS_NEXT_COMMAND_VALUE         32773\r
+#define _APS_NEXT_COMMAND_VALUE         32775\r
 #define _APS_NEXT_CONTROL_VALUE         1000\r
 #define _APS_NEXT_SYMED_VALUE           110\r
 #endif\r
index 73823ba..e4350e9 100644 (file)
@@ -33,6 +33,8 @@
 #include <memory.h>\r
 #include <tchar.h>\r
 \r
+#include <windows.h>\r
+#include <Commdlg.h>\r
 \r
 #define COMMITMONITOR_FINDMSGPREV       (WM_APP+1)\r
 #define COMMITMONITOR_FINDMSGNEXT       (WM_APP+2)\r
index 1e762d6..ce4669f 100644 (file)
@@ -855,6 +855,7 @@ typedef CRegStringCommon<CRegBase> CRegString;
 \r
 CRegDWORDCommon<CRegStdBase>;\r
 typedef CRegDWORDCommon<CRegStdBase> CRegStdWORD;\r
+typedef CRegDWORDCommon<CRegStdBase> CRegStdDWORD;\r
 CRegStringCommon<CRegStdBase>;\r
 typedef CRegStringCommon<CRegStdBase> CRegStdString;\r
 \r