1
// **********************************************************************
3 // Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
5 // This copy of Ice is licensed to you under the terms described in the
6 // ICE_LICENSE file included in this distribution.
8 // **********************************************************************
11 using System
.Collections
.Generic
;
12 using System
.ComponentModel
;
17 using System
.Windows
.Forms
;
23 namespace Ice
.VisualStudio
25 public partial class IncludePathView
: UserControl
27 public IncludePathView()
29 InitializeComponent();
34 sliceIncludeList
.Items
.Clear();
35 IncludePathList list
=
36 new IncludePathList(Util
.getProjectProperty(_project
, Util
.PropertyIceIncludePath
));
37 foreach(String s
in list
)
39 sliceIncludeList
.Items
.Add(s
.Trim());
40 if(Path
.IsPathRooted(s
.Trim()))
42 sliceIncludeList
.SetItemCheckState(sliceIncludeList
.Items
.Count
- 1, CheckState
.Checked
);
47 public void setEnabled(bool enabled
)
49 sliceIncludeList
.Enabled
= enabled
;
50 btnAdd
.Enabled
= enabled
;
51 btnEdit
.Enabled
= enabled
;
52 btnRemove
.Enabled
= enabled
;
53 btnUp
.Enabled
= enabled
;
54 btnDown
.Enabled
= enabled
;
57 public bool hasUnsavedChanges()
59 if(_editingIncludes
&&
60 !_txtIncludeDir
.Text
.Trim().TrimEnd(Path
.DirectorySeparatorChar
).Equals(_editingIncludeDir
))
65 if(!sliceIncludes().Equal(new IncludePathList(
66 Util
.getProjectProperty(_project
, Util
.PropertyIceIncludePath
))))
76 IncludePathList includes
= sliceIncludes();
77 if(!includes
.Equal(new IncludePathList(
78 Util
.getProjectProperty(_project
, Util
.PropertyIceIncludePath
))))
80 String s
= includes
.ToString();
81 Util
.setProjectProperty(_project
, Util
.PropertyIceIncludePath
, s
);
87 public void setIceConfigurationDialog(IceConfigurationDialog dialog
)
92 public bool editingIncludeDir()
94 return _editingIncludes
;
97 private void sliceIncludeList_SelectedIndexChanged(object sender
, EventArgs e
)
101 endEditIncludeDir(true);
105 private void beginEditIncludeDir()
109 endEditIncludeDir(true);
111 _editingIncludes
= true;
112 _dialog
.unsetCancelButton();
113 if(_editingIndex
!= -1)
115 _txtIncludeDir
= new TextBox();
116 _txtIncludeDir
.Text
= sliceIncludeList
.Items
[sliceIncludeList
.SelectedIndex
].ToString();
117 _editingIncludeDir
= _txtIncludeDir
.Text
;
118 sliceIncludeList
.SelectionMode
= SelectionMode
.One
;
120 Rectangle rect
= sliceIncludeList
.GetItemRectangle(sliceIncludeList
.SelectedIndex
);
121 _txtIncludeDir
.Location
= new Point(sliceIncludeList
.Location
.X
+ 2,
122 sliceIncludeList
.Location
.Y
+ rect
.Y
);
123 _txtIncludeDir
.Width
= sliceIncludeList
.Width
- 50;
124 _txtIncludeDir
.Parent
= sliceIncludeList
;
125 _txtIncludeDir
.KeyDown
+= new KeyEventHandler(includeDirKeyDown
);
126 _txtIncludeDir
.KeyUp
+= new KeyEventHandler(includeDirKeyUp
);
127 groupBox1
.Controls
.Add(_txtIncludeDir
);
129 _btnSelectInclude
= new Button();
130 _btnSelectInclude
.Text
= "...";
131 _btnSelectInclude
.Location
= new Point(sliceIncludeList
.Location
.X
+ _txtIncludeDir
.Width
,
132 sliceIncludeList
.Location
.Y
+ rect
.Y
);
133 _btnSelectInclude
.Width
= 49;
134 _btnSelectInclude
.Height
= _txtIncludeDir
.Height
;
135 _btnSelectInclude
.Click
+= new EventHandler(selectIncludeClicked
);
136 groupBox1
.Controls
.Add(_btnSelectInclude
);
139 _txtIncludeDir
.Show();
140 _txtIncludeDir
.BringToFront();
141 _txtIncludeDir
.Focus();
143 _btnSelectInclude
.Show();
144 _btnSelectInclude
.BringToFront();
148 public void endEditIncludeDir(bool saveChanges
)
150 if(!_editingIncludes
)
155 _editingIncludes
= false;
157 if(_editingIndex
> -1 && _editingIndex
< sliceIncludeList
.Items
.Count
)
159 path
= sliceIncludeList
.Items
[_editingIndex
].ToString();
164 _dialog
.setCancelButton();
165 if(_txtIncludeDir
== null || _btnSelectInclude
== null)
172 path
= _txtIncludeDir
.Text
;
179 this.groupBox1
.Controls
.Remove(_txtIncludeDir
);
180 _txtIncludeDir
= null;
182 this.groupBox1
.Controls
.Remove(_btnSelectInclude
);
183 _btnSelectInclude
= null;
186 if(String
.IsNullOrEmpty(path
))
188 if(_editingIndex
!= -1)
190 sliceIncludeList
.Items
.RemoveAt(_editingIndex
);
191 sliceIncludeList
.SelectedIndex
= sliceIncludeList
.Items
.Count
- 1;
195 else if(_editingIndex
!= -1 && saveChanges
)
197 if(!path
.Equals(sliceIncludeList
.Items
[_editingIndex
].ToString(),
198 StringComparison
.CurrentCultureIgnoreCase
))
200 IncludePathList includes
= sliceIncludes();
201 if(includes
.Count
> _editingIndex
)
204 // We don't want an item to be considered a duplicate of itself.
206 includes
.RemoveAt(_editingIndex
);
208 if(includes
.Contains(_project
, path
))
210 MessageBox
.Show(this, "The Slice Include Path doesn't allow duplicates.\n" +
211 "Value: `" + path
+ "' will be removed.\n",
212 "Ice Visual Studio Add-in", MessageBoxButtons
.OK
,
213 MessageBoxIcon
.Warning
, MessageBoxDefaultButton
.Button1
,
214 (MessageBoxOptions
)0);
215 sliceIncludeList
.Items
.RemoveAt(_editingIndex
);
216 sliceIncludeList
.SelectedIndex
= sliceIncludeList
.Items
.Count
- 1;
221 sliceIncludeList
.Items
[_editingIndex
] = path
;
222 if(Path
.IsPathRooted(path
))
224 sliceIncludeList
.SetItemCheckState(_editingIndex
, CheckState
.Checked
);
228 sliceIncludeList
.SetItemCheckState(_editingIndex
, CheckState
.Unchecked
);
233 resetIncludeDirChecks();
237 private void includeDirKeyDown(object sender
, KeyEventArgs e
)
239 if(e
.KeyCode
.Equals(Keys
.Escape
))
241 endEditIncludeDir(false);
243 else if(e
.KeyCode
.Equals(Keys
.Enter
))
245 endEditIncludeDir(true);
249 private void includeDirKeyUp(object sender
, KeyEventArgs e
)
251 if(!e
.KeyCode
.Equals(Keys
.Enter
) && !e
.KeyCode
.Equals(Keys
.Escape
) &&
258 private void selectIncludeClicked(object sender
, EventArgs e
)
260 FolderBrowserDialog dialog
= new FolderBrowserDialog();
261 string projectDir
= Path
.GetFullPath(Path
.GetDirectoryName(_project
.FileName
));
262 dialog
.SelectedPath
= projectDir
;
263 dialog
.Description
= "Slice Include Directory";
264 DialogResult result
= dialog
.ShowDialog();
265 if(result
== DialogResult
.OK
)
267 string path
= dialog
.SelectedPath
;
268 if(!Util
.containsEnvironmentVars(path
))
270 path
= Util
.relativePath(_project
, Path
.GetFullPath(path
));
272 _txtIncludeDir
.Text
= path
;
274 endEditIncludeDir(true);
277 private void btnAdd_Click(object sender
, EventArgs e
)
281 endEditIncludeDir(true);
283 sliceIncludeList
.Items
.Add("");
284 sliceIncludeList
.SelectedIndex
= sliceIncludeList
.Items
.Count
- 1;
285 _editingIndex
= sliceIncludeList
.SelectedIndex
;
286 beginEditIncludeDir();
289 private void btnEdit_Click(object sender
, EventArgs e
)
291 if(sliceIncludeList
.SelectedIndex
!= -1)
293 _editingIndex
= sliceIncludeList
.SelectedIndex
;
294 beginEditIncludeDir();
298 private void btnRemove_Click(object sender
, EventArgs e
)
300 Cursor
= Cursors
.WaitCursor
;
301 int index
= sliceIncludeList
.SelectedIndex
;
304 index
= _editingIndex
;
305 endEditIncludeDir(true);
307 if(index
> -1 && index
< sliceIncludeList
.Items
.Count
)
309 int selected
= index
;
310 sliceIncludeList
.Items
.RemoveAt(selected
);
311 if(sliceIncludeList
.Items
.Count
> 0)
317 sliceIncludeList
.SelectedIndex
= selected
;
321 Cursor
= Cursors
.Default
;
324 private IncludePathList
sliceIncludes()
326 IncludePathList paths
= new IncludePathList();
327 foreach(String s
in sliceIncludeList
.Items
)
334 private void btnUp_Click(object sender
, EventArgs e
)
336 Cursor
= Cursors
.WaitCursor
;
339 endEditIncludeDir(true);
341 int index
= sliceIncludeList
.SelectedIndex
;
344 string current
= sliceIncludeList
.SelectedItem
.ToString();
345 sliceIncludeList
.Items
.RemoveAt(index
);
346 sliceIncludeList
.Items
.Insert(index
- 1, current
);
347 sliceIncludeList
.SelectedIndex
= index
- 1;
348 resetIncludeDirChecks();
351 Cursor
= Cursors
.Default
;
354 private void btnDown_Click(object sender
, EventArgs e
)
356 Cursor
= Cursors
.WaitCursor
;
359 endEditIncludeDir(true);
361 int index
= sliceIncludeList
.SelectedIndex
;
362 if(index
< sliceIncludeList
.Items
.Count
- 1 && index
> -1)
364 string current
= sliceIncludeList
.SelectedItem
.ToString();
365 sliceIncludeList
.Items
.RemoveAt(index
);
366 sliceIncludeList
.Items
.Insert(index
+ 1, current
);
367 sliceIncludeList
.SelectedIndex
= index
+ 1;
368 resetIncludeDirChecks();
371 Cursor
= Cursors
.Default
;
375 // Reset the include dir checkboxes that indicate if the path
376 // is absolute or relative. This should be called after the list
377 // is populated or the includes list order is modified.
379 private void resetIncludeDirChecks()
381 for(int i
= 0; i
< sliceIncludeList
.Items
.Count
; ++i
)
383 String path
= sliceIncludeList
.Items
[i
].ToString();
384 if(String
.IsNullOrEmpty(path
))
389 if(Path
.IsPathRooted(path
))
391 sliceIncludeList
.SetItemCheckState(i
, CheckState
.Checked
);
395 sliceIncludeList
.SetItemCheckState(i
, CheckState
.Unchecked
);
400 private void sliceIncludeList_ItemCheck(object sender
, ItemCheckEventArgs e
)
406 string path
= sliceIncludeList
.Items
[e
.Index
].ToString();
407 if(Util
.containsEnvironmentVars(path
))
412 if(e
.NewValue
== CheckState
.Unchecked
)
414 path
= Util
.relativePath(_project
, path
);
416 else if(e
.NewValue
== CheckState
.Checked
)
418 if(!Path
.IsPathRooted(path
))
420 path
= Util
.absolutePath(_project
, path
);
424 sliceIncludeList
.Items
[e
.Index
] = path
;
429 public void init(IceConfigurationDialog dialog
, Project project
)
435 private Project _project
;
436 private IceConfigurationDialog _dialog
;
437 private int _editingIndex
= -1;
438 private bool _editingIncludes
;
439 private string _editingIncludeDir
= null;
440 private TextBox _txtIncludeDir
;
441 private Button _btnSelectInclude
;