OSDN Git Service

Complete Setting Dialog Remote Add and Modify
authorFrank Li <lznuaa@gmail.com>
Wed, 1 Apr 2009 13:43:47 +0000 (21:43 +0800)
committerFrank Li <lznuaa@gmail.com>
Wed, 1 Apr 2009 13:43:47 +0000 (21:43 +0800)
Signed-off-by: Frank Li <lznuaa@gmail.com>
src/TortoiseProc/Settings/SettingGitRemote.cpp
src/TortoiseProc/Settings/SettingGitRemote.h

index 7c51ad8..51894a0 100644 (file)
@@ -19,7 +19,8 @@ CSettingGitRemote::CSettingGitRemote()
     , m_strUrl(_T(""))\r
     , m_strPuttyKeyfile(_T(""))\r
 {\r
-       m_bChanged=FALSE;\r
+\r
+       m_ChangedMask = 0;\r
 }\r
 \r
 CSettingGitRemote::~CSettingGitRemote()\r
@@ -75,7 +76,8 @@ BOOL CSettingGitRemote::OnInitDialog()
                        this->m_ctrlRemoteList.AddString(one);\r
 \r
        }while(start>=0);\r
-               \r
+       \r
+       this->GetDlgItem(IDC_EDIT_REMOTE)->EnableWindow(FALSE);\r
        this->UpdateData(FALSE);\r
        return TRUE;\r
 }\r
@@ -84,17 +86,42 @@ BOOL CSettingGitRemote::OnInitDialog()
 void CSettingGitRemote::OnBnClickedButtonBrowse()\r
 {\r
     // TODO: Add your control notification handler code here\r
+       CFileDialog dlg(TRUE,NULL,\r
+                                       NULL,\r
+                                       OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,\r
+                                       _T("Putty Private Key(*.ppk)|*.ppk|All Files(*.*)|*.*||"));\r
+       \r
+       this->UpdateData();\r
+       if(dlg.DoModal()==IDOK)\r
+       {\r
+               this->m_strPuttyKeyfile = dlg.GetPathName();\r
+               this->UpdateData(FALSE);\r
+               OnEnChangeEditPuttyKey();\r
+       }\r
+       \r
+\r
 }\r
 \r
 void CSettingGitRemote::OnBnClickedButtonAdd()\r
 {\r
     // TODO: Add your control notification handler code here\r
+       this->m_strRemote.Empty();\r
+       this->m_strUrl.Empty();\r
+       this->m_strPuttyKeyfile.Empty();\r
+       this->m_bAutoLoad.SetCheck(false);\r
+       this->UpdateData(FALSE);\r
+       this->GetDlgItem(IDC_EDIT_REMOTE)->EnableWindow(TRUE);\r
+       this->m_ChangedMask |= REMOTE_NAME;\r
+       this->m_ctrlRemoteList.SetCurSel(-1);\r
+       GetDlgItem(IDC_BUTTON_ADD)->EnableWindow(FALSE);\r
 }\r
 \r
 void CSettingGitRemote::OnLbnSelchangeListRemote()\r
 {\r
     // TODO: Add your control notification handler code here\r
-       if(m_bChanged)\r
+       CWaitCursor wait;\r
+\r
+       if(m_ChangedMask)\r
        {\r
                if(CMessageBox::Show(NULL,_T("Remote Config Changed\nDo you want to save change now or discard change"),\r
                                                                 _T("TortoiseGit"),MB_YESNO) == IDYES)\r
@@ -153,6 +180,9 @@ void CSettingGitRemote::OnLbnSelchangeListRemote()
                m_bAutoLoad.SetCheck(true);\r
        }\r
        \r
+       m_ChangedMask=0;\r
+\r
+       GetDlgItem(IDC_BUTTON_ADD)->EnableWindow(TRUE);\r
        this->UpdateData(FALSE);\r
 \r
 }\r
@@ -165,6 +195,10 @@ void CSettingGitRemote::OnEnChangeEditRemote()
     // with the ENM_CHANGE flag ORed into the mask.\r
 \r
     // TODO:  Add your control notification handler code here\r
+\r
+       m_ChangedMask|=REMOTE_NAME;\r
+\r
+       this->SetModified();\r
 }\r
 \r
 void CSettingGitRemote::OnEnChangeEditUrl()\r
@@ -175,11 +209,15 @@ void CSettingGitRemote::OnEnChangeEditUrl()
     // with the ENM_CHANGE flag ORed into the mask.\r
 \r
     // TODO:  Add your control notification handler code here\r
+       m_ChangedMask|=REMOTE_URL;\r
+       this->SetModified();\r
 }\r
 \r
 void CSettingGitRemote::OnBnClickedCheckIsautoloadputtykey()\r
 {\r
     // TODO: Add your control notification handler code here\r
+       m_ChangedMask|=REMOTE_AUTOLOAD;\r
+       this->SetModified();\r
 }\r
 \r
 void CSettingGitRemote::OnEnChangeEditPuttyKey()\r
@@ -190,11 +228,59 @@ void CSettingGitRemote::OnEnChangeEditPuttyKey()
     // with the ENM_CHANGE flag ORed into the mask.\r
 \r
     // TODO:  Add your control notification handler code here\r
+       m_ChangedMask|=REMOTE_PUTTYKEY;\r
+       this->SetModified();\r
+}\r
+void CSettingGitRemote::Save(CString key,CString value)\r
+{\r
+       CString cmd,out;\r
+       cmd.Format(_T("git.exe config remote.%s.%s \"%s\""),this->m_strRemote,key,value);\r
+       if(g_Git.Run(cmd,&out,CP_ACP))\r
+       {\r
+               CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
+       }\r
 }\r
-\r
 BOOL CSettingGitRemote::OnApply()\r
 {\r
-  \r
+       CWaitCursor wait;\r
+       this->UpdateData();\r
+       if(m_ChangedMask & REMOTE_NAME)\r
+       {\r
+               //Add Remote\r
+               if( this->m_strRemote.IsEmpty() || this->m_strUrl.IsEmpty() )\r
+               {\r
+                       CMessageBox::Show(NULL,_T("Remote Name and URL can't be Empty"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
+                       return FALSE;\r
+               }\r
+               CString cmd,out;\r
+               cmd.Format(_T("git.exe remote add \"%s\" \"%s\""),m_strRemote,m_strUrl);\r
+               if(g_Git.Run(cmd,&out,CP_ACP))\r
+               {\r
+                       CMessageBox::Show(NULL,out,_T("TorotiseGit"),MB_OK|MB_ICONERROR);\r
+                       return FALSE;\r
+               }\r
+               m_ChangedMask &= ~REMOTE_URL;\r
+\r
+               this->m_ctrlRemoteList.AddString(m_strRemote);\r
+               GetDlgItem(IDC_BUTTON_ADD)->EnableWindow(TRUE);\r
+       }\r
+       if(m_ChangedMask & REMOTE_URL)\r
+       {\r
+               Save(_T("url"),this->m_strUrl);\r
+       }\r
+\r
+       if(m_ChangedMask & REMOTE_PUTTYKEY)\r
+       {\r
+               Save(_T("puttykey"),this->m_strPuttyKeyfile);\r
+       }\r
+\r
+       if(m_ChangedMask & REMOTE_AUTOLOAD)\r
+       {\r
+               Save(_T("puttykeyautoload"),this->m_bAutoLoad.GetCheck()?_T("true"):_T("false"));\r
+       }\r
+       this->GetDlgItem(IDC_EDIT_REMOTE)->EnableWindow(FALSE);\r
     SetModified(FALSE);\r
+\r
+       m_ChangedMask = 0;\r
        return ISettingsPropPage::OnApply();\r
 }
\ No newline at end of file
index e4a7c62..f8a4270 100644 (file)
@@ -6,12 +6,18 @@
 #include "afxwin.h"\r
 \r
 // CSettingGitRemote dialog\r
-\r
 class CSettingGitRemote : public ISettingsPropPage\r
 {\r
        DECLARE_DYNAMIC(CSettingGitRemote)\r
 \r
 public:\r
+       enum\r
+       {\r
+               REMOTE_NAME             =0x1,\r
+               REMOTE_URL              =0x2,\r
+               REMOTE_PUTTYKEY =0x4,\r
+               REMOTE_AUTOLOAD =0x8,\r
+       };\r
        CSettingGitRemote();\r
        virtual ~CSettingGitRemote();\r
        UINT GetIconID() {return IDI_GITREMOTE;}\r
@@ -26,7 +32,11 @@ protected:
        BOOL OnInitDialog();\r
     BOOL OnApply();\r
 \r
-       BOOL m_bChanged;\r
+protected:\r
+\r
+       void Save(CString key, CString value);\r
+\r
+       int      m_ChangedMask;\r
 \r
 public:\r
     CListBox m_ctrlRemoteList;\r