OSDN Git Service

Finish Submodule Add Command
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / SubmoduleAddDlg.cpp
1 // SubmoduleAddDlg.cpp : implementation file\r
2 //\r
3 \r
4 #include "stdafx.h"\r
5 #include "resource.h"\r
6 #include "SubmoduleAddDlg.h"\r
7 #include "BrowseFolder.h"\r
8 #include "MessageBox.h"\r
9 \r
10 // CSubmoduleAddDlg dialog\r
11 \r
12 IMPLEMENT_DYNAMIC(CSubmoduleAddDlg, CResizableStandAloneDialog)\r
13 \r
14 CSubmoduleAddDlg::CSubmoduleAddDlg(CWnd* pParent /*=NULL*/)\r
15         : CResizableStandAloneDialog(CSubmoduleAddDlg::IDD, pParent)\r
16         , m_bBranch(FALSE)\r
17         , m_strBranch(_T(""))\r
18 {\r
19 \r
20 }\r
21 \r
22 CSubmoduleAddDlg::~CSubmoduleAddDlg()\r
23 {\r
24 }\r
25 \r
26 void CSubmoduleAddDlg::DoDataExchange(CDataExchange* pDX)\r
27 {\r
28         CDialog::DoDataExchange(pDX);\r
29         DDX_Control(pDX, IDC_COMBOBOXEX_REPOSITORY, m_Repository);\r
30         DDX_Control(pDX, IDC_COMBOBOXEX_PATH, m_PathCtrl);\r
31         DDX_Check(pDX, IDC_BRANCH_CHECK, m_bBranch);\r
32         DDX_Text(pDX, IDC_SUBMODULE_BRANCH, m_strBranch);\r
33 }\r
34 \r
35 \r
36 BEGIN_MESSAGE_MAP(CSubmoduleAddDlg, CResizableStandAloneDialog)\r
37         ON_COMMAND(IDC_REP_BROWSE,                      OnRepBrowse)\r
38         ON_COMMAND(IDC_BUTTON_PATH_BROWSE,      OnPathBrowse)\r
39         ON_COMMAND(IDC_BRANCH_CHECK,            OnBranchCheck)\r
40 END_MESSAGE_MAP()\r
41 \r
42 \r
43 // CSubmoduleAddDlg message handlers\r
44 \r
45 BOOL CSubmoduleAddDlg::OnInitDialog()\r
46 {\r
47         CResizableStandAloneDialog::OnInitDialog();\r
48 \r
49         AddAnchor(IDOK,BOTTOM_RIGHT);\r
50         AddAnchor(IDCANCEL,BOTTOM_RIGHT);\r
51         AddAnchor(IDC_GROUP_SUBMODULE,TOP_LEFT,BOTTOM_RIGHT);\r
52         AddAnchor(IDC_COMBOBOXEX_REPOSITORY,TOP_LEFT,TOP_RIGHT);\r
53         AddAnchor(IDC_COMBOBOXEX_PATH,TOP_LEFT,TOP_RIGHT);\r
54         AddAnchor(IDC_REP_BROWSE,TOP_RIGHT);\r
55         AddAnchor(IDC_BUTTON_PATH_BROWSE,TOP_RIGHT);    \r
56         AddAnchor(IDC_BRANCH_CHECK,BOTTOM_LEFT);\r
57         AddAnchor(IDC_SUBMODULE_BRANCH,BOTTOM_LEFT,BOTTOM_RIGHT);\r
58 \r
59 \r
60         AddOthersToAnchor();\r
61 \r
62         EnableSaveRestore(_T("SubmoduleAddDlg"));\r
63 \r
64         m_Repository.SetURLHistory(true);\r
65         m_PathCtrl.SetPathHistory(true);\r
66 \r
67         m_Repository.LoadHistory(_T("Software\\TortoiseGit\\History\\SubModuleRepoURLS"), _T("url"));\r
68         m_PathCtrl.LoadHistory(_T("Software\\TortoiseGit\\History\\SubModulePath"), _T("url"));\r
69         m_PathCtrl.SetWindowText(m_strPath);\r
70         m_Repository.SetCurSel(0);\r
71 \r
72         GetDlgItem(IDC_GROUP_SUBMODULE)->SetWindowText(CString(_T("Submodule of Project: "))+m_strProject);\r
73         \r
74         return TRUE;\r
75 }\r
76 \r
77 void CSubmoduleAddDlg::OnRepBrowse()\r
78 {\r
79         CBrowseFolder browseFolder;\r
80         browseFolder.m_style = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;\r
81         CString strDirectory;\r
82         this->m_Repository.GetWindowTextW(strDirectory);\r
83         if (browseFolder.Show(GetSafeHwnd(), strDirectory) == CBrowseFolder::OK) \r
84         {\r
85                 this->m_Repository.SetWindowTextW(strDirectory);\r
86         }\r
87 }\r
88 void CSubmoduleAddDlg::OnPathBrowse()\r
89 {\r
90         CBrowseFolder browseFolder;\r
91         browseFolder.m_style = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;\r
92         CString strDirectory;\r
93         this->m_PathCtrl.GetWindowTextW(strDirectory);\r
94         if (browseFolder.Show(GetSafeHwnd(), strDirectory,g_Git.m_CurrentDir) == CBrowseFolder::OK) \r
95         {\r
96                 this->m_PathCtrl.SetWindowTextW(strDirectory);\r
97         }\r
98 }\r
99 void CSubmoduleAddDlg::OnBranchCheck()\r
100 {\r
101         this->UpdateData();\r
102         if(this->m_bBranch)\r
103         {\r
104                 this->GetDlgItem(IDC_SUBMODULE_BRANCH)->ShowWindow(TRUE);               \r
105         }else\r
106         {\r
107                 this->GetDlgItem(IDC_SUBMODULE_BRANCH)->ShowWindow(FALSE);              \r
108         }\r
109 }\r
110 \r
111 void CSubmoduleAddDlg::OnOK()\r
112 {\r
113         this->UpdateData();\r
114         if(m_bBranch)\r
115         {\r
116                 m_strBranch.Trim();\r
117                 if(m_strBranch.IsEmpty())\r
118                 {\r
119                         CMessageBox::Show(NULL,_T("Branch can't be empty"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
120                         return ;\r
121                 }\r
122         }\r
123         m_Repository.SaveHistory();\r
124         m_PathCtrl.SaveHistory();\r
125 \r
126         this->m_strPath=m_PathCtrl.GetString();\r
127         this->m_strRepos=m_Repository.GetString();\r
128 \r
129         m_strPath.Trim();\r
130         m_strRepos.Trim();\r
131         if(m_strPath.IsEmpty())\r
132         {\r
133                 CMessageBox::Show(NULL,_T("Path can't be empty"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
134                         return ;\r
135         }\r
136         if(m_strRepos.IsEmpty())\r
137         {\r
138                 CMessageBox::Show(NULL,_T("Repository can't be empty"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
139                         return ;\r
140         }\r
141         __super::OnOK();\r
142 }