X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=src%2FTortoiseProc%2FAppUtils.cpp;h=c1c0f54172133cee229ac1e70da6889642ca53d8;hb=cbdf91082a0d7513a2b938cb36354abe07e62e2a;hp=456c4190baf6842c9e489682c5a6041fc064fbc6;hpb=ff62d31a9ad3b6cec313575f6b4695c7ff997763;p=tortoisegit%2FTortoiseGitJp.git
diff --git a/src/TortoiseProc/AppUtils.cpp b/src/TortoiseProc/AppUtils.cpp
index 456c419..c1c0f54 100644
--- a/src/TortoiseProc/AppUtils.cpp
+++ b/src/TortoiseProc/AppUtils.cpp
@@ -41,6 +41,10 @@
#include "CreateBranchTagDlg.h"
#include "GitSwitchDlg.h"
#include "ResetDlg.h"
+#include "DeleteConflictDlg.h"
+#include "ChangedDlg.h"
+#include "SendMailDlg.h"
+#include "SVNProgressDlg.h"
CAppUtils::CAppUtils(void)
{
@@ -50,6 +54,29 @@ CAppUtils::~CAppUtils(void)
{
}
+int CAppUtils::StashApply(CString ref)
+{
+ CString cmd,out;
+ cmd=_T("git.exe stash apply ");
+ cmd+=ref;
+
+ if(g_Git.Run(cmd,&out,CP_ACP))
+ {
+ CMessageBox::Show(NULL,CString(_T("Stash Apply Fail!!!\n"))+out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
+
+ }else
+ {
+ if(CMessageBox::Show(NULL,CString(_T("Stash Apply Success\nDo you want to show change?"))
+ ,_T("TortoiseGit"),MB_YESNO|MB_ICONINFORMATION) == IDYES)
+ {
+ CChangedDlg dlg;
+ dlg.m_pathList.AddPath(CTGitPath());
+ dlg.DoModal();
+ }
+ return 0;
+ }
+ return -1;
+}
bool CAppUtils::GetMimeType(const CTGitPath& file, CString& mimetype)
{
#if 0
@@ -589,7 +616,46 @@ bool CAppUtils::LaunchApplication(const CString& sCommandLine, UINT idErrMessage
CloseHandle(process.hProcess);
return true;
}
+bool CAppUtils::LaunchPAgent(CString *keyfile,CString * pRemote)
+{
+ CString key,remote;
+ CString cmd,out;
+ if( pRemote == NULL)
+ {
+ remote=_T("origin");
+ }else
+ {
+ remote=*pRemote;
+ }
+ if(keyfile == NULL)
+ {
+ cmd.Format(_T("git.exe config remote.%s.puttykeyfile"),remote);
+ g_Git.Run(cmd,&key,CP_ACP);
+ int start=0;
+ key = key.Tokenize(_T("\n"),start);
+ }
+ else
+ key=*keyfile;
+
+ if(key.IsEmpty())
+ return false;
+
+ CString proc=CPathUtils::GetAppDirectory();
+ proc += _T("pageant.exe \"");
+ proc += key;
+ proc += _T("\"");
+ return LaunchApplication(proc, IDS_ERR_PAGEANT, false);
+}
+bool CAppUtils::LaunchRemoteSetting()
+{
+ CString proc=CPathUtils::GetAppDirectory();
+ proc += _T("TortoiseProc.exe /command:settings");
+ proc += _T(" /path:\"");
+ proc += g_Git.m_CurrentDir;
+ proc += _T("\" /page:remote");
+ return LaunchApplication(proc, IDS_ERR_EXTDIFFSTART, false);
+}
/**
* Launch the external blame viewer
*/
@@ -607,47 +673,6 @@ bool CAppUtils::LaunchTortoiseBlame(const CString& sBlameFile,CString Rev,const
return LaunchApplication(viewer, IDS_ERR_EXTDIFFSTART, false);
}
-void CAppUtils::ResizeAllListCtrlCols(CListCtrl * pListCtrl)
-{
- int maxcol = ((CHeaderCtrl*)(pListCtrl->GetDlgItem(0)))->GetItemCount()-1;
- int nItemCount = pListCtrl->GetItemCount();
- TCHAR textbuf[MAX_PATH];
- CHeaderCtrl * pHdrCtrl = (CHeaderCtrl*)(pListCtrl->GetDlgItem(0));
- if (pHdrCtrl)
- {
- for (int col = 0; col <= maxcol; col++)
- {
- HDITEM hdi = {0};
- hdi.mask = HDI_TEXT;
- hdi.pszText = textbuf;
- hdi.cchTextMax = sizeof(textbuf);
- pHdrCtrl->GetItem(col, &hdi);
- int cx = pListCtrl->GetStringWidth(hdi.pszText)+20; // 20 pixels for col separator and margin
- for (int index = 0; indexGetStringWidth(pListCtrl->GetItemText(index, col)) + 14;
- if (index == 0)
- {
- // add the image size
- CImageList * pImgList = pListCtrl->GetImageList(LVSIL_SMALL);
- if ((pImgList)&&(pImgList->GetImageCount()))
- {
- IMAGEINFO imginfo;
- pImgList->GetImageInfo(0, &imginfo);
- linewidth += (imginfo.rcImage.right - imginfo.rcImage.left);
- linewidth += 3; // 3 pixels between icon and text
- }
- }
- if (cx < linewidth)
- cx = linewidth;
- }
- pListCtrl->SetColumnWidth(col, cx);
-
- }
- }
-}
-
bool CAppUtils::FormatTextInRichEditControl(CWnd * pWnd)
{
CString sText;
@@ -998,11 +1023,18 @@ bool CAppUtils::StartShowUnifiedDiff(HWND hWnd, const CTGitPath& url1, const git
CString cmd;
if(rev1 == GitRev::GetWorkingCopy())
{
- cmd.Format(_T("git.exe diff --stat -p %s"),rev2);
+ cmd.Format(_T("git.exe diff --stat -p %s "),rev2);
}else
{
cmd.Format(_T("git.exe diff-tree -r -p --stat %s %s"),rev1,rev2);
}
+
+ if( !url1.IsEmpty() )
+ {
+ cmd+=_T(" \"");
+ cmd+=url1.GetGitPathString();
+ cmd+=_T("\" ");
+ }
g_Git.RunLogFile(cmd,tempfile);
CAppUtils::StartUnifiedDiffViewer(tempfile,rev1.Left(6)+_T(":")+rev2.Left(6));
@@ -1118,10 +1150,10 @@ bool CAppUtils::CreateBranchTag(bool IsTag,CString *CommitHash)
CString force;
CString track;
if(dlg.m_bTrack)
- track=_T("--track");
+ track=_T(" --track ");
if(dlg.m_bForce)
- force=_T("-f");
+ force=_T(" -f ");
if(IsTag)
{
@@ -1147,6 +1179,14 @@ bool CAppUtils::CreateBranchTag(bool IsTag,CString *CommitHash)
{
CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
}
+ if( !IsTag && dlg.m_bSwitch )
+ {
+ // it is a new branch and the user has requested to switch to it
+ cmd.Format(_T("git.exe checkout %s"), dlg.m_BranchTagName);
+ g_Git.Run(cmd,&out,CP_UTF8);
+ CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
+ }
+
return TRUE;
}
@@ -1189,35 +1229,60 @@ bool CAppUtils::Switch(CString *CommitHash)
return FALSE;
}
-bool CAppUtils::IgnoreFile(CTGitPath &path,bool IsMask)
+bool CAppUtils::IgnoreFile(CTGitPathList &path,bool IsMask)
{
CString ignorefile;
- ignorefile=g_Git.m_CurrentDir;
- ignorefile+=path.GetDirectory().GetWinPathString()+_T("\\.gitignore");
+ ignorefile=g_Git.m_CurrentDir+_T("\\");
+
+ if(IsMask)
+ {
+ ignorefile+=path.GetCommonRoot().GetDirectory().GetWinPathString()+_T("\\.gitignore");
+
+ }else
+ {
+ ignorefile+=_T("\\.gitignore");
+ }
CStdioFile file;
- if(!file.Open(ignorefile,CFile::modeCreate|CFile::modeWrite))
+ if(!file.Open(ignorefile,CFile::modeCreate|CFile::modeReadWrite|CFile::modeNoTruncate))
{
CMessageBox::Show(NULL,ignorefile+_T(" Open Failure"),_T("TortoiseGit"),MB_OK);
return FALSE;
}
CString ignorelist;
- file.ReadString(ignorelist);
-
- if(IsMask)
+ CString mask;
+ try
{
- ignorelist+=_T("\n*.")+path.GetFileExtension();
- }else
+ //file.ReadString(ignorelist);
+ file.SeekToEnd();
+ for(int i=0;i= 3*365)
+ {
+ answer = ExpandRelativeTime( (int)ts.GetTotalDays()/365, IDS_YEAR_AGO, IDS_YEARS_AGO );
+ }
+ //Months
+ if(fabs(ts.GetTotalDays()) >= 60)
{
- datetime += _T(" ");
- GetTimeFormat(LOCALE_USER_DEFAULT, 0, &sysTime, NULL, buf, sizeof(buf)/sizeof(TCHAR)-1);
- datetime += buf;
+ answer = ExpandRelativeTime( (int)ts.GetTotalDays()/30, IDS_MONTH_AGO, IDS_MONTHS_AGO );
+ return answer;
}
- return datetime;
+ //Weeks
+ if(fabs(ts.GetTotalDays()) >= 14)
+ {
+ answer = ExpandRelativeTime( (int)ts.GetTotalDays()/7, IDS_WEEK_AGO, IDS_WEEKS_AGO );
+ return answer;
+ }
+ //Days
+ if(fabs(ts.GetTotalDays()) >= 2)
+ {
+ answer = ExpandRelativeTime( (int)ts.GetTotalDays(), IDS_DAY_AGO, IDS_DAYS_AGO );
+ return answer;
+ }
+ //hours
+ if(fabs(ts.GetTotalHours()) >= 2)
+ {
+ answer = ExpandRelativeTime( (int)ts.GetTotalHours(), IDS_HOUR_AGO, IDS_HOURS_AGO );
+ return answer;
+ }
+ //minutes
+ if(fabs(ts.GetTotalMinutes()) >= 2)
+ {
+ answer = ExpandRelativeTime( (int)ts.GetTotalMinutes(), IDS_MINUTE_AGO, IDS_MINUTES_AGO );
+ return answer;
+ }
+ //seconds
+ answer = ExpandRelativeTime( (int)ts.GetTotalSeconds(), IDS_SECOND_AGO, IDS_SECONDS_AGO );
+ return answer;
+}
+
+/**
+ * Passed a value and two resource string ids
+ * if count is 1 then FormatString is called with format_1 and the value
+ * otherwise format_2 is used
+ * the formatted string is returned
+*/
+CString CAppUtils::ExpandRelativeTime( int count, UINT format_1, UINT format_n )
+{
+ CString answer;
+ if ( count == 1 )
+ {
+ answer.FormatMessage( format_1, count );
+ }
+ else
+ {
+ answer.FormatMessage( format_n, count );
+ }
+ return answer;
+}
+
+bool CAppUtils::IsSSHPutty()
+{
+ CString sshclient=CRegString(_T("Software\\TortoiseGit\\SSH"));
+ sshclient=sshclient.MakeLower();
+ if(sshclient.Find(_T("plink.exe"),0)>=0)
+ {
+ return true;
+ }
+ return false;
+}
+
+CString CAppUtils::GetClipboardLink()
+{
+ if (!OpenClipboard(NULL))
+ return CString();
+
+ CString sClipboardText;
+ HGLOBAL hglb = GetClipboardData(CF_TEXT);
+ if (hglb)
+ {
+ LPCSTR lpstr = (LPCSTR)GlobalLock(hglb);
+ sClipboardText = CString(lpstr);
+ GlobalUnlock(hglb);
+ }
+ hglb = GetClipboardData(CF_UNICODETEXT);
+ if (hglb)
+ {
+ LPCTSTR lpstr = (LPCTSTR)GlobalLock(hglb);
+ sClipboardText = lpstr;
+ GlobalUnlock(hglb);
+ }
+ CloseClipboard();
+
+ if(!sClipboardText.IsEmpty())
+ {
+ if(sClipboardText[0] == _T('\"') && sClipboardText[sClipboardText.GetLength()-1] == _T('\"'))
+ sClipboardText=sClipboardText.Mid(1,sClipboardText.GetLength()-2);
+
+ if(sClipboardText.Find( _T("http://")) == 0)
+ return sClipboardText;
+
+ if(sClipboardText.Find( _T("https://")) == 0)
+ return sClipboardText;
+
+ if(sClipboardText.Find( _T("git://")) == 0)
+ return sClipboardText;
+
+ if(sClipboardText.Find( _T("ssh://")) == 0)
+ return sClipboardText;
+
+ if(sClipboardText.GetLength()>=2)
+ if( sClipboardText[1] == _T(':') )
+ if( (sClipboardText[0] >= 'A' && sClipboardText[0] <= 'Z')
+ || (sClipboardText[0] >= 'a' && sClipboardText[0] <= 'z') )
+ return sClipboardText;
+ }
+
+ return CString(_T(""));
+}
+
+CString CAppUtils::ChooseRepository(CString *path)
+{
+ CBrowseFolder browseFolder;
+ browseFolder.m_style = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
+ CString strCloneDirectory;
+ if(path)
+ strCloneDirectory=*path;
+
+ CString title;
+ title.LoadString(IDS_CHOOSE_REPOSITORY);
+
+ browseFolder.SetInfo(title);
+
+ if (browseFolder.Show(NULL, strCloneDirectory) == CBrowseFolder::OK)
+ {
+ return strCloneDirectory;
+
+ }else
+ {
+ return CString();
+ }
+
}
+
+bool CAppUtils::SendPatchMail(CTGitPathList &list,bool autoclose)
+{
+ CSendMailDlg dlg;
+
+ dlg.m_PathList = list;
+
+ if(dlg.DoModal()==IDOK)
+ {
+ if(dlg.m_PathList.GetCount() == 0)
+ return FALSE;
+
+ CGitProgressDlg progDlg;
+
+ theApp.m_pMainWnd = &progDlg;
+ progDlg.SetCommand(CGitProgressDlg::GitProgress_SendMail);
+
+ progDlg.SetAutoClose(autoclose);
+
+ progDlg.SetPathList(dlg.m_PathList);
+ //ProjectProperties props;
+ //props.ReadPropsPathList(dlg.m_pathList);
+ //progDlg.SetProjectProperties(props);
+ progDlg.SetItemCount(dlg.m_PathList.GetCount());
+
+ DWORD flags =0;
+ if(dlg.m_bAttachment)
+ flags |= SENDMAIL_ATTACHMENT;
+ if(dlg.m_bCombine)
+ flags |= SENDMAIL_COMBINED;
+
+ progDlg.SetSendMailOption(dlg.m_To,dlg.m_CC,dlg.m_Subject,flags);
+
+ progDlg.DoModal();
+
+ return true;
+ }
+ return false;
+}
+int CAppUtils::GetLogOutputEncode()
+{
+ CString cmd,output;
+ int start=0;
+ cmd=_T("git.exe config i18n.logOutputEncoding");
+ if(g_Git.Run(cmd,&output,CP_ACP))
+ {
+ cmd=_T("git.exe config i18n.commitencoding");
+ if(g_Git.Run(cmd,&output,CP_ACP))
+ return CP_UTF8;
+
+ int start=0;
+ output=output.Tokenize(_T("\n"),start);
+ return CUnicodeUtils::GetCPCode(output);
+
+ }else
+ {
+ output=output.Tokenize(_T("\n"),start);
+ return CUnicodeUtils::GetCPCode(output);
+ }
+}
+int CAppUtils::SaveCommitUnicodeFile(CString &filename, CString &message)
+{
+ CFile file(filename,CFile::modeReadWrite|CFile::modeCreate );
+ CString cmd,output;
+ int cp=CP_UTF8;
+
+ cmd=_T("git.exe config i18n.commitencoding");
+ if(g_Git.Run(cmd,&output,CP_ACP))
+ cp=CP_UTF8;
+
+ int start=0;
+ output=output.Tokenize(_T("\n"),start);
+ cp=CUnicodeUtils::GetCPCode(output);
+
+ int len=message.GetLength();
+
+ char * buf;
+ buf = new char[len*4 + 4];
+ SecureZeroMemory(buf, (len*4 + 4));
+
+ int lengthIncTerminator = WideCharToMultiByte(cp, 0, message, -1, buf, len*4, NULL, NULL);
+
+ file.Write(buf,lengthIncTerminator-1);
+ file.Close();
+ delete buf;
+ return 0;
+}
\ No newline at end of file