OSDN Git Service

Version browse in switch, export, new branch/tag and merge dialogs
authorColin Law <colin@clanlaw.org.uk>
Mon, 9 Feb 2009 09:58:48 +0000 (09:58 +0000)
committerFrank Li <lznuaa@gmail.com>
Tue, 10 Feb 2009 23:37:29 +0000 (07:37 +0800)
src/TortoiseProc/ChooseVersion.h
src/TortoiseProc/GitSwitchDlg.cpp
src/TortoiseProc/GitSwitchDlg.h
src/TortoiseProc/LogDlg.cpp
src/TortoiseProc/LogDlg.h

index 4d74f79..cb15d1e 100644 (file)
@@ -1,5 +1,6 @@
 #pragma once\r
 #include "afxwin.h"\r
 #pragma once\r
 #include "afxwin.h"\r
+#include "LogDlg.h"\r
 \r
 class CChooseVersion\r
 {\r
 \r
 class CChooseVersion\r
 {\r
@@ -32,7 +33,27 @@ protected:
                        this->m_ChooseVersioinVersion.EnableWindow(TRUE);                                               \r
                break;          \r
                }\r
                        this->m_ChooseVersioinVersion.EnableWindow(TRUE);                                               \r
                break;          \r
                }\r
+               // enable version browse button if Version is selected\r
+               m_pWin->GetDlgItem(IDC_BUTTON_SHOW)->EnableWindow(radio == IDC_RADIO_VERSION);\r
        }\r
        }\r
+\r
+       void OnBnClickedChooseVersion()\r
+       {\r
+               // use the git log to allow selection of a version\r
+               CLogDlg dlg;\r
+               // tell the dialog to use mode for selecting revisions\r
+               dlg.SetSelect(true);\r
+               // only one revision must be selected however\r
+               dlg.SingleSelection(true);\r
+               if ( dlg.DoModal() == IDOK )\r
+               {\r
+                       // get selected hash if any\r
+                       CString selectedHash = dlg.GetSelectedHash();\r
+                       // load into window, do this even if empty so that it is clear that nothing has been selected\r
+                       m_ChooseVersioinVersion.SetWindowText( selectedHash );\r
+               }\r
+       }\r
+\r
        void UpdateRevsionName()\r
        {                                                                                                                                                       \r
                int radio=m_pWin->GetCheckedRadioButton(IDC_RADIO_HEAD,IDC_RADIO_VERSION);              \r
        void UpdateRevsionName()\r
        {                                                                                                                                                       \r
                int radio=m_pWin->GetCheckedRadioButton(IDC_RADIO_HEAD,IDC_RADIO_VERSION);              \r
@@ -94,6 +115,7 @@ public:
        ON_BN_CLICKED(IDC_RADIO_HEAD,           OnBnClickedChooseRadioHost)\\r
        ON_BN_CLICKED(IDC_RADIO_BRANCH,         OnBnClickedChooseRadioHost)\\r
        ON_BN_CLICKED(IDC_RADIO_TAGS,           OnBnClickedChooseRadioHost)\\r
        ON_BN_CLICKED(IDC_RADIO_HEAD,           OnBnClickedChooseRadioHost)\\r
        ON_BN_CLICKED(IDC_RADIO_BRANCH,         OnBnClickedChooseRadioHost)\\r
        ON_BN_CLICKED(IDC_RADIO_TAGS,           OnBnClickedChooseRadioHost)\\r
+       ON_BN_CLICKED(IDC_BUTTON_SHOW,          OnBnClickedShow)\\r
        ON_BN_CLICKED(IDC_RADIO_VERSION,        OnBnClickedChooseRadioHost)\r
 \r
 #define CHOOSE_VERSION_ADDANCHOR                                                               \\r
        ON_BN_CLICKED(IDC_RADIO_VERSION,        OnBnClickedChooseRadioHost)\r
 \r
 #define CHOOSE_VERSION_ADDANCHOR                                                               \\r
@@ -106,4 +128,5 @@ public:
        }       \r
 \r
 #define CHOOSE_EVENT_RADIO() \\r
        }       \r
 \r
 #define CHOOSE_EVENT_RADIO() \\r
-       afx_msg void OnBnClickedChooseRadioHost(){OnBnClickedChooseRadio();}\r
+       afx_msg void OnBnClickedChooseRadioHost(){OnBnClickedChooseRadio();}\\r
+       afx_msg void OnBnClickedShow(){OnBnClickedChooseVersion();}\r
index 1513daa..1543ec6 100644 (file)
@@ -89,6 +89,11 @@ void CGitSwitchDlg::OnBnClickedChooseRadioHost()
        \r
 }\r
 \r
        \r
 }\r
 \r
+void CGitSwitchDlg::OnBnClickedShow()\r
+{\r
+       OnBnClickedChooseVersion();\r
+}\r
+\r
 void CGitSwitchDlg::OnBnClickedOk()\r
 {\r
        this->UpdateData(TRUE);\r
 void CGitSwitchDlg::OnBnClickedOk()\r
 {\r
        this->UpdateData(TRUE);\r
index e4bd45d..dab30bc 100644 (file)
@@ -29,6 +29,7 @@ protected:
        void OnBnClickedOk();\r
 \r
        afx_msg void OnBnClickedChooseRadioHost();\r
        void OnBnClickedOk();\r
 \r
        afx_msg void OnBnClickedChooseRadioHost();\r
+       afx_msg void OnBnClickedShow();\r
 \r
        DECLARE_MESSAGE_MAP()\r
 public:\r
 \r
        DECLARE_MESSAGE_MAP()\r
 public:\r
index 483d3b1..3525e9a 100644 (file)
@@ -315,14 +315,13 @@ BOOL CLogDlg::OnInitDialog()
        if (m_bSelect)\r
        {\r
                // the dialog is used to select revisions\r
        if (m_bSelect)\r
        {\r
                // the dialog is used to select revisions\r
-               if (m_bSelectionMustBeContinuous)\r
-                       DialogEnableWindow(IDOK, (m_LogList.GetSelectedCount()!=0)&&(m_LogList.IsSelectionContinuous()));\r
-               else\r
-                       DialogEnableWindow(IDOK, m_LogList.GetSelectedCount()!=0);\r
+               // enable the OK button if appropriate\r
+               EnableOKButton();\r
        }\r
        else\r
        {\r
                // the dialog is used to just view log messages\r
        }\r
        else\r
        {\r
                // the dialog is used to just view log messages\r
+               // hide the OK button and set text on Cancel button to OK\r
                GetDlgItemText(IDOK, temp);\r
                SetDlgItemText(IDCANCEL, temp);\r
                GetDlgItem(IDOK)->ShowWindow(SW_HIDE);\r
                GetDlgItemText(IDOK, temp);\r
                SetDlgItemText(IDCANCEL, temp);\r
                GetDlgItem(IDOK)->ShowWindow(SW_HIDE);\r
@@ -453,7 +452,12 @@ void CLogDlg::EnableOKButton()
        if (m_bSelect)\r
        {\r
                // the dialog is used to select revisions\r
        if (m_bSelect)\r
        {\r
                // the dialog is used to select revisions\r
-               if (m_bSelectionMustBeContinuous)\r
+               if (m_bSelectionMustBeSingle)\r
+               {\r
+                       // enable OK button if only a single revision is selected\r
+                       DialogEnableWindow(IDOK, (m_LogList.GetSelectedCount()==1));\r
+               }\r
+               else if (m_bSelectionMustBeContinuous)\r
                        DialogEnableWindow(IDOK, (m_LogList.GetSelectedCount()!=0)&&(m_LogList.IsSelectionContinuous()));\r
                else\r
                        DialogEnableWindow(IDOK, m_LogList.GetSelectedCount()!=0);\r
                        DialogEnableWindow(IDOK, (m_LogList.GetSelectedCount()!=0)&&(m_LogList.IsSelectionContinuous()));\r
                else\r
                        DialogEnableWindow(IDOK, m_LogList.GetSelectedCount()!=0);\r
@@ -628,24 +632,9 @@ void CLogDlg::SaveSplitterPos()
 void CLogDlg::OnCancel()\r
 {\r
        // canceling means stopping the working thread if it's still running.\r
 void CLogDlg::OnCancel()\r
 {\r
        // canceling means stopping the working thread if it's still running.\r
-       // we do this by using the Subversion cancel callback.\r
-       // But canceling can also mean just to close the dialog, depending on the\r
-       // text shown on the cancel button (it could simply read "OK").\r
-       CString temp, temp2;\r
-       GetDlgItemText(IDOK, temp);\r
-       temp2.LoadString(IDS_MSGBOX_CANCEL);\r
-       if ((temp.Compare(temp2)==0)||(this->IsThreadRunning()))\r
-       {\r
-               //m_bCancelled = true;\r
-               //return;\r
-               if(m_LogList.m_bThreadRunning)\r
-               {\r
-                       //m_LogList.m_bExitThread=true;\r
-                       //WaitForSingleObject(m_LogList.m_LoadingThread->m_hThread,INFINITE);\r
-                       m_LogList.TerminateThread();\r
-               }\r
-\r
-               //m_LogList.TerminateThread();\r
+       if (this->IsThreadRunning())\r
+       {\r
+               m_LogList.TerminateThread();\r
        }\r
        UpdateData();\r
        \r
        }\r
        UpdateData();\r
        \r
@@ -1059,11 +1048,36 @@ LRESULT CLogDlg::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
 \r
 void CLogDlg::OnOK()\r
 {\r
 \r
 void CLogDlg::OnOK()\r
 {\r
-#if 0 \r
        // since the log dialog is also used to select revisions for other\r
        // dialogs, we have to do some work before closing this dialog\r
        if (GetFocus() != GetDlgItem(IDOK))\r
                return; // if the "OK" button doesn't have the focus, do nothing: this prevents closing the dialog when pressing enter\r
        // since the log dialog is also used to select revisions for other\r
        // dialogs, we have to do some work before closing this dialog\r
        if (GetFocus() != GetDlgItem(IDOK))\r
                return; // if the "OK" button doesn't have the focus, do nothing: this prevents closing the dialog when pressing enter\r
+\r
+       \r
+       if (this->IsThreadRunning())\r
+       {\r
+               m_LogList.TerminateThread();\r
+       }\r
+       UpdateData();\r
+       // check that one and only one row is selected\r
+       if (m_LogList.GetSelectedCount() == 1)\r
+       {\r
+               // get the selected row\r
+               POSITION pos = m_LogList.GetFirstSelectedItemPosition();\r
+               int selIndex = m_LogList.GetNextSelectedItem(pos);\r
+               if (selIndex < m_LogList.m_arShownList.GetCount())\r
+               {\r
+                       // all ok, pick up the revision\r
+                       GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.GetAt(selIndex));\r
+                       // extract the hash\r
+                       m_sSelectedHash = pLogEntry->m_CommitHash;\r
+               }\r
+       }\r
+       UpdateData(FALSE);\r
+       SaveSplitterPos();\r
+       __super::OnOK();\r
+       \r
+       #if 0 \r
        if (!GetDlgItem(IDOK)->IsWindowVisible() && GetFocus() != GetDlgItem(IDCANCEL))\r
                return; // the Cancel button works as the OK button. But if the cancel button has not the focus, do nothing.\r
 \r
        if (!GetDlgItem(IDOK)->IsWindowVisible() && GetFocus() != GetDlgItem(IDCANCEL))\r
                return; // the Cancel button works as the OK button. But if the cancel button has not the focus, do nothing.\r
 \r
index 5585f76..f174d35 100644 (file)
@@ -89,7 +89,13 @@ public:
        void SetDialogTitle(const CString& sTitle) {m_sTitle = sTitle;}\r
        void SetSelect(bool bSelect) {m_bSelect = bSelect;}\r
        void ContinuousSelection(bool bCont = true) {m_bSelectionMustBeContinuous = bCont;}\r
        void SetDialogTitle(const CString& sTitle) {m_sTitle = sTitle;}\r
        void SetSelect(bool bSelect) {m_bSelect = bSelect;}\r
        void ContinuousSelection(bool bCont = true) {m_bSelectionMustBeContinuous = bCont;}\r
+       void SingleSelection(bool bSingle = true) {m_bSelectionMustBeSingle = bSingle;}\r
        void SetMergePath(const CTGitPath& mergepath) {m_mergePath = mergepath;}\r
        void SetMergePath(const CTGitPath& mergepath) {m_mergePath = mergepath;}\r
+       /**\r
+        * Provides selected commit hash if available, call after OK return from here\r
+        * Empty if none\r
+       **/\r
+       CString GetSelectedHash(){ return m_sSelectedHash; }\r
 \r
 //     const GitRevRangeArray& GetSelectedRevRanges() {return m_selectedRevs;}\r
 \r
 \r
 //     const GitRevRangeArray& GetSelectedRevRanges() {return m_selectedRevs;}\r
 \r
@@ -227,7 +233,9 @@ private:
        //GitRev                                m_wcRev;\r
 //     GitRevRangeArray        m_selectedRevs;\r
 //     GitRevRangeArray        m_selectedRevsOneRange;\r
        //GitRev                                m_wcRev;\r
 //     GitRevRangeArray        m_selectedRevs;\r
 //     GitRevRangeArray        m_selectedRevsOneRange;\r
+       CString                         m_sSelectedHash;        // set to selected commit hash on OK if appropriate\r
        bool                            m_bSelectionMustBeContinuous;\r
        bool                            m_bSelectionMustBeContinuous;\r
+       bool                            m_bSelectionMustBeSingle;\r
        long                            m_logcounter;\r
        bool                            m_bCancelled;\r
        \r
        long                            m_logcounter;\r
        bool                            m_bCancelled;\r
        \r