OSDN Git Service

Fixed issue #188: Add Git Properties tab into Windows File Properties
[tortoisegit/TortoiseGitJp.git] / src / TortoiseShell / SVNPropertyPage.cpp
index cc87844..874cbfb 100644 (file)
@@ -1,4 +1,4 @@
-// TortoiseGit - a Windows shell extension for easy version control\r
+// TortoiseSVN - a Windows shell extension for easy version control\r
 \r
 // Copyright (C) 2003-2008 - TortoiseGit\r
 \r
@@ -219,6 +219,81 @@ void CGitPropertyPage::Time64ToTimeString(__time64_t time, TCHAR * buf, size_t b
 \r
 void CGitPropertyPage::InitWorkfileView()\r
 {\r
+       CString username;\r
+       //can't git.exe when create process\r
+       g_Git.Run(_T("tgit config user.name"),&username,CP_ACP);\r
+       CString useremail;\r
+       g_Git.Run(_T("tgit config user.email"),&useremail,CP_ACP);\r
+       CString autocrlf;\r
+       g_Git.Run(_T("tgit config core.autocrlf"),&autocrlf,CP_ACP);\r
+       CString safecrlf;\r
+       g_Git.Run(_T("tgit config core.safecrlf"),&safecrlf,CP_ACP);\r
+\r
+       CString branch;\r
+       CString headhash;\r
+\r
+       BYTE_VECTOR logout;\r
+\r
+       CString cmd,log;\r
+       cmd=_T("tgit log -z --topo-order -n1 --parents --pretty=format:\"");\r
+       \r
+       g_Git.BuildOutputFormat(log,true);\r
+\r
+       cmd += log;\r
+       cmd += CString(_T("\"  "));\r
+\r
+       g_Git.Run(cmd,&logout);\r
+       GitRev rev;\r
+       rev.ParserFromLog(logout);\r
+\r
+       SetDlgItemText(m_hwnd,IDC_CONFIG_USERNAME,username);\r
+       SetDlgItemText(m_hwnd,IDC_CONFIG_USEREMAIL,useremail);\r
+       SetDlgItemText(m_hwnd,IDC_CONFIG_AUTOCRLF,autocrlf);\r
+       SetDlgItemText(m_hwnd,IDC_CONFIG_SAFECRLF,safecrlf);\r
+\r
+       SetDlgItemText(m_hwnd,IDC_HEAD_HASH,rev.m_CommitHash);\r
+       SetDlgItemText(m_hwnd,IDC_HEAD_SUBJECT,rev.m_Subject);\r
+       SetDlgItemText(m_hwnd,IDC_HEAD_AUTHOR,rev.m_AuthorName);\r
+       SetDlgItemText(m_hwnd,IDC_HEAD_DATE,rev.m_AuthorDate.Format(_T("%Y-%m-%d %H:%M:%S")));\r
+\r
+       if (filenames.size() == 1)\r
+       {\r
+               CTGitPath path(filenames.front().c_str());\r
+               CTGitPath relatepath;\r
+               CString strpath=path.GetWinPathString();\r
+               CString ProjectTopDir;\r
+\r
+               if(!path.HasAdminDir(&ProjectTopDir))\r
+                       return;\r
+               \r
+               if(ProjectTopDir[ProjectTopDir.GetLength()-1] == _T('\\'))\r
+               {\r
+                       relatepath.SetFromWin( strpath.Right(strpath.GetLength()-ProjectTopDir.GetLength()));\r
+               }else\r
+               {\r
+                       relatepath.SetFromWin( strpath.Right(strpath.GetLength()-ProjectTopDir.GetLength()-1));\r
+               }\r
+\r
+               cmd+=_T("-- \"");\r
+               cmd+=relatepath.GetGitPathString();     \r
+               cmd+=_T("\"");\r
+\r
+               logout.clear();\r
+               g_Git.Run(cmd,&logout);\r
+               rev.Clear();\r
+               rev.ParserFromLog(logout);\r
+\r
+               SetDlgItemText(m_hwnd,IDC_LAST_HASH,rev.m_CommitHash);\r
+               SetDlgItemText(m_hwnd,IDC_LAST_SUBJECT,rev.m_Subject);\r
+               SetDlgItemText(m_hwnd,IDC_LAST_AUTHOR,rev.m_AuthorName);\r
+               SetDlgItemText(m_hwnd,IDC_LAST_DATE,rev.m_AuthorDate.Format(_T("%Y-%m-%d %H:%M:%S")));\r
+\r
+       }else\r
+       {\r
+\r
+       }\r
+\r
+#if 0\r
        GitStatus svn = GitStatus();\r
        TCHAR tbuf[MAX_STRING_LENGTH];\r
        if (filenames.size() == 1)\r
@@ -361,7 +436,72 @@ void CGitPropertyPage::InitWorkfileView()
                                ShowWindow(GetDlgItem(m_hwnd, IDC_REPOURLUNESCAPED), SW_HIDE);\r
                        }\r
                }\r
-       } \r
+       }\r
+#endif\r
 }\r
 \r
 \r
+// CShellExt member functions (needed for IShellPropSheetExt)\r
+STDMETHODIMP CShellExt::AddPages (LPFNADDPROPSHEETPAGE lpfnAddPage,\r
+                                  LPARAM lParam)\r
+{\r
+\r
+       CString ProjectTopDir;\r
+\r
+       for (std::vector<stdstring>::iterator I = files_.begin(); I != files_.end(); ++I)\r
+       {\r
+               /*\r
+               GitStatus svn = GitStatus();\r
+               if (svn.GetStatus(CTGitPath(I->c_str())) == (-2))\r
+                       return NOERROR;                 // file/directory not under version control\r
+\r
+               if (svn.status->entry == NULL)\r
+                       return NOERROR;\r
+               */\r
+               if( CTGitPath(I->c_str()).HasAdminDir(&ProjectTopDir))\r
+                       break;\r
+               else\r
+                       return NOERROR;\r
+       }\r
+\r
+       if (files_.size() == 0)\r
+               return NOERROR;\r
+\r
+       LoadLangDll();\r
+    PROPSHEETPAGE psp;\r
+       SecureZeroMemory(&psp, sizeof(PROPSHEETPAGE));\r
+       HPROPSHEETPAGE hPage;\r
+       CGitPropertyPage *sheetpage = new CGitPropertyPage(files_);\r
+\r
+    psp.dwSize = sizeof (psp);\r
+    psp.dwFlags = PSP_USEREFPARENT | PSP_USETITLE | PSP_USEICONID | PSP_USECALLBACK;   \r
+       psp.hInstance = g_hResInst;\r
+       psp.pszTemplate = MAKEINTRESOURCE(IDD_PROPPAGE);\r
+    psp.pszIcon = MAKEINTRESOURCE(IDI_APPSMALL);\r
+    psp.pszTitle = _T("Git");\r
+    psp.pfnDlgProc = (DLGPROC) PageProc;\r
+    psp.lParam = (LPARAM) sheetpage;\r
+    psp.pfnCallback = PropPageCallbackProc;\r
+    psp.pcRefParent = &g_cRefThisDll;\r
+\r
+    hPage = CreatePropertySheetPage (&psp);\r
+\r
+       if (hPage != NULL)\r
+       {\r
+        if (!lpfnAddPage (hPage, lParam))\r
+        {\r
+            delete sheetpage;\r
+            DestroyPropertySheetPage (hPage);\r
+        }\r
+       }\r
+\r
+    return NOERROR;\r
+}\r
+\r
+\r
+\r
+STDMETHODIMP CShellExt::ReplacePage (UINT /*uPageID*/, LPFNADDPROPSHEETPAGE /*lpfnReplaceWith*/, LPARAM /*lParam*/)\r
+{\r
+    return E_FAIL;\r
+}\r
+\r