2 using System.Collections.Generic;
\r
3 using System.Drawing;
\r
4 using System.Windows.Forms;
\r
6 using NaGet.Packages;
\r
8 namespace AppliStation
\r
13 public partial class UserPrefForm : Form
\r
15 private List<RepositoryInfo> repos;
\r
17 private bool isRepoListChanged;
\r
22 public UserPrefForm()
\r
24 repos = new List<RepositoryInfo>();
\r
26 InitializeComponent();
\r
34 public void loadCurrentPref()
\r
36 this.RepositoriesListSetting = NaGet.Utils.GetDeserializedObject<RepositoriesList>(NaGet.Env.RepositoriesListFile);
\r
38 NaGet.NaGetLibPref userPref = NaGet.Env.Pref;
\r
39 this.ProxyAddress = userPref.ProxyAddress;
\r
42 #region レポジトリリスト設定関連
\r
45 /// レポジトリリストの設定を読み書きする
\r
47 public RepositoriesList RepositoriesListSetting {
\r
49 RepositoriesList repoList = new RepositoriesList();
\r
50 repoList.Repositories = repos.ToArray();
\r
55 repos.AddRange(value.Repositories);
\r
60 isRepoListChanged = false;
\r
65 /// ListBoxへ表示するレポジトリ表現文字列を返す
\r
67 /// <param name="repo">対象レポジトリ</param>
\r
68 /// <returns>ListBoxに表示すべき文字列</returns>
\r
69 private string repoListCheckedListBoxRenderer(RepositoryInfo repo) {
\r
70 return string.Format("{0}[{1}]", repo.Name, repo.Url.Href);
\r
74 /// ListBoxの内容を更新(再構築)する。
\r
76 private void updateRepos()
\r
78 repoListCheckedListBox.Items.Clear();
\r
80 foreach (RepositoryInfo repo in repos) {
\r
81 string label = repoListCheckedListBoxRenderer(repo);
\r
82 repoListCheckedListBox.Items.Add(label, repo.Enabled);
\r
86 void RepoListCheckedListBoxSelectedIndexChanged(object sender, EventArgs e)
\r
88 int selectedIndex = repoListCheckedListBox.SelectedIndex;
\r
89 bool selected = (selectedIndex >= 0);
\r
91 removeRepoButton.Enabled = selected;
\r
92 upRepoButton.Enabled = selected && ((1 <= selectedIndex) && (selectedIndex < repos.Count));
\r
93 downRepoButton.Enabled = selected && ((0 <= selectedIndex) && (selectedIndex < (repos.Count-1)));
\r
94 repoUrlLabel.Enabled = selected;
\r
95 repoUrlTextBox.Enabled = selected;
\r
97 repoUrlTextBox.Text = repos[repoListCheckedListBox.SelectedIndex].Url.Href;
\r
98 repoUrlTextBox.SelectAll();
\r
100 repoUrlTextBox.Clear();
\r
104 void AddRepoButtonClick(object sender, EventArgs e)
\r
106 RepositoryInfo repo = new RepositoryInfo();
\r
107 repo.Name = string.Format("新しいレポジトリ");
\r
108 repo.Url = new LocationEntry();
\r
109 repo.Enabled = true;
\r
114 repoListCheckedListBox.SelectedIndex = repos.Count - 1;
\r
116 isRepoListChanged = true;
\r
119 void RepoListCheckedListBoxItemCheck(object sender, ItemCheckEventArgs e)
\r
121 repos[e.Index].Enabled = (e.NewValue == CheckState.Checked);
\r
123 isRepoListChanged = true;
\r
126 void RemoveRepoButtonClick(object sender, EventArgs e)
\r
128 int selectedIndex = repoListCheckedListBox.SelectedIndex;
\r
129 if ((0 <= selectedIndex) && (selectedIndex < repos.Count)) {
\r
130 string text = string.Format("本当にレポジトリ「{0}」を消去しますか?", repos[selectedIndex].Name);
\r
131 DialogResult result = MessageBox.Show(text, "レポジトリの削除", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
\r
132 if (result == DialogResult.OK) {
\r
133 repos.RemoveAt(selectedIndex);
\r
134 repoListCheckedListBox.Items.RemoveAt(selectedIndex);
\r
136 isRepoListChanged = true;
\r
141 void UpRepoButtonClick(object sender, EventArgs e)
\r
143 int selectedIndex = repoListCheckedListBox.SelectedIndex;
\r
144 if ((1 <= selectedIndex) && (selectedIndex < repos.Count)) {
\r
145 NaGet.Utils.ListSwap(repos, selectedIndex-1, selectedIndex);
\r
146 AppliStation.Util.GUIUtils.CheckedListBox_SwapItems(repoListCheckedListBox, selectedIndex-1, selectedIndex);
\r
147 repoListCheckedListBox.SelectedIndex --;
\r
149 isRepoListChanged = true;
\r
153 void DownRepoButtonClick(object sender, EventArgs e)
\r
155 int selectedIndex = repoListCheckedListBox.SelectedIndex;
\r
156 if ((0 <= selectedIndex) && (selectedIndex < (repos.Count-1))) {
\r
157 NaGet.Utils.ListSwap(repos, selectedIndex, selectedIndex+1);
\r
158 AppliStation.Util.GUIUtils.CheckedListBox_SwapItems(repoListCheckedListBox, selectedIndex, selectedIndex+1);
\r
159 repoListCheckedListBox.SelectedIndex ++;
\r
161 isRepoListChanged = true;
\r
165 void RepoUrlTextBoxLeave(object sender, EventArgs e)
\r
167 int selectedIndex = repoListCheckedListBox.SelectedIndex;
\r
168 if ((0 <= selectedIndex) && (selectedIndex < repos.Count)) {
\r
169 if (repoUrlTextBox.Text != repos[selectedIndex].Url.Href) {
\r
170 repos[selectedIndex].Url = new LocationEntry(repoUrlTextBox.Text);
\r
171 repoListCheckedListBox.Items[selectedIndex] = repoListCheckedListBoxRenderer(repos[selectedIndex]);
\r
173 isRepoListChanged = true;
\r
179 /// レポジトリリストが編集されたか否かのフラグ
\r
181 /// <remarks>ソフトリストの再読み込みが必要か否かの判断に使われる</remarks>
\r
182 public bool IsRepositoryListSettingChanged {
\r
183 get { return isRepoListChanged; }
\r
187 /// レポジトリリストの設定を反映する
\r
189 private void commitRepositoryListSetting()
\r
191 if (isRepoListChanged) {
\r
192 NaGet.Utils.PutSerializeObject<RepositoriesList>(NaGet.Env.RepositoriesListFile, this.RepositoriesListSetting);
\r
198 #region プロキシサーバ設定関連
\r
201 /// プロキシアドレスを設定あるいは取得する
\r
203 public string ProxyAddress {
\r
205 if (proxySameAsIERadioButton.Checked) {
\r
206 return string.Empty;
\r
207 } else if (directConnRadioButton.Checked) {
\r
210 return proxyURLTextBox.Text;
\r
214 if (string.IsNullOrEmpty(value)) {
\r
215 proxySameAsIERadioButton.Checked = true;
\r
216 } else if ("-" == value) {
\r
217 directConnRadioButton.Checked = true;
\r
219 specifyProxyRadioButton.Checked = true;
\r
220 proxyURLTextBox.Text = value;
\r
223 updateProxyURLEnability();
\r
228 /// ProxyURLのテキストボックス領域の有効状態を切り替える
\r
230 private void updateProxyURLEnability()
\r
232 bool isSpecifiedProxy = specifyProxyRadioButton.Checked;
\r
234 proxyURLLabel.Enabled = isSpecifiedProxy;
\r
235 proxyURLTextBox.Enabled = isSpecifiedProxy;
\r
238 void ProxyRadioButtonsCheckedChanged(object sender, EventArgs e)
\r
240 updateProxyURLEnability();
\r
244 /// プロキシ設定を、指定された設定オブジェクトに設定する。
\r
246 /// <param name="pref">設定オブジェクト</param>
\r
247 private void commitProxySetting(NaGet.NaGetLibPref pref)
\r
249 pref.ProxyAddress = this.ProxyAddress;
\r
255 /// 指定された設定オブジェクトをファイルとして保存する
\r
257 /// <param name="pref">設定ファイル</param>
\r
258 private void commitNaGetLibPref(NaGet.NaGetLibPref pref)
\r
261 string path = NaGet.Env.PrefPath;
\r
262 NaGet.Utils.PutSerializeObject<NaGet.NaGetLibPref>(path, pref);
\r
264 // 設定についてファイルから設定を再読み込みさせる
\r
265 NaGet.Env.LoadPref();
\r
268 void OkButtonClick(object sender, EventArgs e)
\r
270 NaGet.NaGetLibPref pref = NaGet.Env.Pref;
\r
272 commitRepositoryListSetting();
\r
273 commitProxySetting(pref);
\r
275 commitNaGetLibPref(pref);
\r
278 void CancelButtonClick(object sender, EventArgs e)
\r