1
// **********************************************************************
3
// Copyright (c) 2003-2010 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;
21
namespace Ice.VisualStudio
23
public partial class IceSilverlightConfigurationDialog : Form
25
public IceSilverlightConfigurationDialog(Project project)
27
InitializeComponent();
31
// Set the toolTip messages.
33
toolTip.SetToolTip(txtIceHome, "Ice Installation Directory.");
34
toolTip.SetToolTip(btnSelectIceHome, "Ice Installation Directory.");
35
toolTip.SetToolTip(chkIcePrefix, "Allow Ice prefix (--ice).");
36
toolTip.SetToolTip(chkConsole, "Enable console output.");
41
this.Text = "Ice Configuration - Project: " + _project.Name;
42
bool enabled = Util.isSliceBuilderEnabled(project);
44
chkEnableBuilder.Checked = enabled;
52
Cursor = Cursors.WaitCursor;
55
includeDirList.Items.Clear();
56
txtIceHome.Text = Util.getIceHomeRaw(_project, false);
57
txtExtraOptions.Text = Util.getProjectProperty(_project, Util.PropertyIceExtraOptions);
59
chkIcePrefix.Checked = Util.getProjectPropertyAsBool(_project, Util.PropertyIcePrefix);
60
chkConsole.Checked = Util.getProjectPropertyAsBool(_project, Util.PropertyConsoleOutput);
62
IncludePathList list =
63
new IncludePathList(Util.getProjectProperty(_project, Util.PropertyIceIncludePath));
64
foreach(String s in list)
66
includeDirList.Items.Add(s.Trim());
67
if(Path.IsPathRooted(s.Trim()))
69
includeDirList.SetItemCheckState(includeDirList.Items.Count - 1, CheckState.Checked);
73
ComponentList selectedComponents = Util.getIceSilverlightComponents(_project);
74
foreach(String s in Util.getSilverlightNames())
76
if(selectedComponents.Contains(s))
78
checkComponent(s, true);
82
checkComponent(s, false);
86
Cursor = Cursors.Default;
89
private void checkComponent(String component, bool check)
93
endEditIncludeDir(false);
99
chkIceSl.Checked = check;
108
private void chkEnableBuilder_CheckedChanged(object sender, EventArgs e)
110
Cursor = Cursors.WaitCursor;
113
endEditIncludeDir(false);
117
_initialized = false;
119
chkEnableBuilder.Enabled = false;
120
Builder builder = Connect.getBuilder();
121
if(chkEnableBuilder.Checked)
123
builder.addBuilderToProject(_project);
127
builder.removeBuilderFromProject(_project);
130
chkEnableBuilder.Enabled = true;
131
setEnabled(chkEnableBuilder.Checked);
134
Cursor = Cursors.Default;
137
private void setEnabled(bool enabled)
139
txtIceHome.Enabled = enabled;
140
btnSelectIceHome.Enabled = enabled;
142
chkIcePrefix.Enabled = enabled;
143
chkConsole.Enabled = enabled;
145
includeDirList.Enabled = enabled;
146
btnAddInclude.Enabled = enabled;
147
btnEditInclude.Enabled = enabled;
148
btnRemoveInclude.Enabled = enabled;
149
btnMoveIncludeUp.Enabled = enabled;
150
btnMoveIncludeDown.Enabled = enabled;
152
txtExtraOptions.Enabled = enabled;
155
chkIceSl.Enabled = enabled;
158
private void formClosing(object sender, EventArgs e)
160
Cursor = Cursors.WaitCursor;
163
endEditIncludeDir(false);
167
if(txtExtraOptions.Modified)
171
else if(txtIceHome.Modified)
177
if(_changed && Util.isSliceBuilderEnabled(_project))
179
Builder builder = Connect.getBuilder();
180
builder.cleanProject(_project);
181
builder.buildProject(_project, true, vsBuildScope.vsBuildScopeProject);
183
Cursor = Cursors.Default;
186
private void btnCancel_Click(object sender, EventArgs e)
191
private void btnSelectIceHome_Click(object sender, EventArgs e)
195
endEditIncludeDir(false);
197
FolderBrowserDialog dialog = new FolderBrowserDialog();
198
dialog.SelectedPath = Util.getAbsoluteIceHome(_project);
199
dialog.Description = "Select Ice Home Installation Directory";
200
DialogResult result = dialog.ShowDialog();
201
if(result == DialogResult.OK)
203
Util.updateIceHome(_project, dialog.SelectedPath, false);
209
private void txtIceHome_KeyPress(object sender, KeyPressEventArgs e)
211
if(e.KeyChar == (char)Keys.Return)
218
private void txtIceHome_Focus(object sender, EventArgs e)
222
endEditIncludeDir(false);
226
private void txtIceHome_LostFocus(object sender, EventArgs e)
231
private void updateIceHome()
233
if(!_iceHomeUpdating)
235
_iceHomeUpdating = true;
236
if(!txtIceHome.Text.Equals(Util.getProjectProperty(_project, Util.PropertyIceHome),
237
StringComparison.CurrentCultureIgnoreCase))
239
Util.updateIceHome(_project, txtIceHome.Text, false);
242
txtIceHome.Modified = false;
244
_iceHomeUpdating = false;
248
private void chkIcePrefix_CheckedChanged(object sender, EventArgs e)
250
Cursor = Cursors.WaitCursor;
253
endEditIncludeDir(false);
255
Util.setProjectProperty(_project, Util.PropertyIcePrefix, chkIcePrefix.Checked.ToString());
257
Cursor = Cursors.Default;
260
private void saveSliceIncludes()
262
IncludePathList paths = new IncludePathList();
263
foreach(String s in includeDirList.Items)
267
String p = paths.ToString();
268
Util.setProjectProperty(_project, Util.PropertyIceIncludePath, p);
272
private void btnAddInclude_Click(object sender, EventArgs e)
276
endEditIncludeDir(false);
278
includeDirList.Items.Add("");
279
includeDirList.SelectedIndex = includeDirList.Items.Count - 1;
280
_editingIndex = includeDirList.SelectedIndex;
281
beginEditIncludeDir();
284
private void btnRemoveInclude_Click(object sender, EventArgs e)
286
Cursor = Cursors.WaitCursor;
287
int index = includeDirList.SelectedIndex;
290
index = _editingIndex;
291
endEditIncludeDir(false);
293
if(index > -1 && index < includeDirList.Items.Count)
295
int selected = index;
296
includeDirList.Items.RemoveAt(selected);
297
if (includeDirList.Items.Count > 0)
303
includeDirList.SelectedIndex = selected;
307
Cursor = Cursors.Default;
310
private void btnMoveIncludeUp_Click(object sender, EventArgs e)
312
Cursor = Cursors.WaitCursor;
315
endEditIncludeDir(false);
317
int index = includeDirList.SelectedIndex;
320
string current = includeDirList.SelectedItem.ToString();
321
includeDirList.Items.RemoveAt(index);
322
includeDirList.Items.Insert(index - 1, current);
323
includeDirList.SelectedIndex = index - 1;
326
resetIncludeDirChecks();
327
Cursor = Cursors.Default;
330
private void btnMoveIncludeDown_Click(object sender, EventArgs e)
332
Cursor = Cursors.WaitCursor;
335
endEditIncludeDir(false);
337
int index = includeDirList.SelectedIndex;
338
if(index < includeDirList.Items.Count - 1 && index > -1)
340
string current = includeDirList.SelectedItem.ToString();
341
includeDirList.Items.RemoveAt(index);
342
includeDirList.Items.Insert(index + 1, current);
343
includeDirList.SelectedIndex = index + 1;
345
resetIncludeDirChecks();
347
Cursor = Cursors.Default;
350
private void includeDirList_ItemCheck(object sender, ItemCheckEventArgs e)
356
string path = includeDirList.Items[e.Index].ToString();
357
if(!Util.containsEnvironmentVars(path))
359
if(e.NewValue == CheckState.Unchecked)
361
path = Util.relativePath(Path.GetDirectoryName(_project.FileName), path);
363
else if(e.NewValue == CheckState.Checked)
365
if(!Path.IsPathRooted(path))
367
path = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(_project.FileName), path));
371
includeDirList.Items[e.Index] = path;
378
private void txtExtraOptions_Focus(object sender, EventArgs e)
382
endEditIncludeDir(false);
386
private void txtExtraOptions_LostFocus(object sender, EventArgs e)
388
if(txtExtraOptions.Modified)
390
Util.setProjectProperty(_project, Util.PropertyIceExtraOptions, txtExtraOptions.Text);
396
private void chkIce_CheckedChanged(object sender, EventArgs e)
398
Cursor = Cursors.WaitCursor;
401
endEditIncludeDir(false);
407
Util.addDotNetReference(_project, "IceSL");
411
Util.removeDotNetReference(_project, "IceSL");
415
Cursor = Cursors.Default;
418
private void chkConsole_CheckedChanged(object sender, EventArgs e)
420
Cursor = Cursors.WaitCursor;
423
endEditIncludeDir(false);
425
Util.setProjectProperty(_project, Util.PropertyConsoleOutput, chkConsole.Checked.ToString());
426
Cursor = Cursors.Default;
429
private void btnEdit_Click(object sender, EventArgs e)
431
if(includeDirList.SelectedIndex != -1)
433
_editingIndex = includeDirList.SelectedIndex;
434
beginEditIncludeDir();
438
private void includeDirList_SelectedIndexChanged(object sender, EventArgs e)
442
endEditIncludeDir(false);
446
private void beginEditIncludeDir()
450
endEditIncludeDir(false);
452
_editingIncludes = true;
454
if(_editingIndex != -1)
456
_txtIncludeDir = new TextBox();
457
_txtIncludeDir.Text = includeDirList.Items[includeDirList.SelectedIndex].ToString();
459
includeDirList.SelectionMode = SelectionMode.One;
461
Rectangle rect = includeDirList.GetItemRectangle(includeDirList.SelectedIndex);
462
_txtIncludeDir.Location = new Point(includeDirList.Location.X + 2,
463
includeDirList.Location.Y + rect.Y);
464
_txtIncludeDir.Width = includeDirList.Width - 50;
465
_txtIncludeDir.Parent = includeDirList;
466
_txtIncludeDir.KeyDown += new KeyEventHandler(includeDirKeyDown);
467
groupBox1.Controls.Add(_txtIncludeDir);
469
_btnSelectInclude = new Button();
470
_btnSelectInclude.Text = "...";
471
_btnSelectInclude.Location = new Point(includeDirList.Location.X + _txtIncludeDir.Width,
472
includeDirList.Location.Y + rect.Y);
473
_btnSelectInclude.Width = 49;
474
_btnSelectInclude.Height = _txtIncludeDir.Height;
475
_btnSelectInclude.Click += new EventHandler(selectIncludeClicked);
476
groupBox1.Controls.Add(_btnSelectInclude);
479
_txtIncludeDir.Show();
480
_txtIncludeDir.BringToFront();
481
_txtIncludeDir.Focus();
483
_btnSelectInclude.Show();
484
_btnSelectInclude.BringToFront();
488
private void endEditIncludeDir(bool saveChanges)
490
_initialized = false;
491
if(!_editingIncludes)
496
_editingIncludes = false;
498
if(_editingIndex > -1 && _editingIndex < includeDirList.Items.Count)
500
path = includeDirList.Items[_editingIndex].ToString();
505
CancelButton = btnClose;
506
if(_txtIncludeDir == null || _btnSelectInclude == null)
513
path = _txtIncludeDir.Text;
520
this.groupBox1.Controls.Remove(_txtIncludeDir);
521
_txtIncludeDir = null;
523
this.groupBox1.Controls.Remove(_btnSelectInclude);
524
_btnSelectInclude = null;
527
if(String.IsNullOrEmpty(path))
529
if(_editingIndex != -1)
531
includeDirList.Items.RemoveAt(_editingIndex);
532
includeDirList.SelectedIndex = includeDirList.Items.Count - 1;
537
else if(_editingIndex != -1 && saveChanges)
539
if(!path.Equals(includeDirList.Items[_editingIndex].ToString(),
540
StringComparison.CurrentCultureIgnoreCase))
542
includeDirList.Items[_editingIndex] = path;
543
if(Path.IsPathRooted(path))
545
includeDirList.SetItemCheckState(_editingIndex, CheckState.Checked);
549
includeDirList.SetItemCheckState(_editingIndex, CheckState.Unchecked);
554
resetIncludeDirChecks();
557
private void resetIncludeDirChecks()
559
_initialized = false;
560
for(int i = 0; i < includeDirList.Items.Count; i++)
562
String path = includeDirList.Items[i].ToString();
563
if(String.IsNullOrEmpty(path))
568
if(Path.IsPathRooted(path))
570
includeDirList.SetItemCheckState(i, CheckState.Checked);
574
includeDirList.SetItemCheckState(i, CheckState.Unchecked);
580
private void includeDirKeyDown(object sender, KeyEventArgs e)
582
if(e.KeyCode.Equals(Keys.Escape))
584
endEditIncludeDir(false);
586
if(e.KeyCode.Equals(Keys.Enter))
588
endEditIncludeDir(true);
592
private void selectIncludeClicked(object sender, EventArgs e)
594
FolderBrowserDialog dialog = new FolderBrowserDialog();
595
string projectDir = Path.GetFullPath(Path.GetDirectoryName(_project.FileName));
596
dialog.SelectedPath = projectDir;
597
dialog.Description = "Slice Include Directory";
598
DialogResult result = dialog.ShowDialog();
599
if(result == DialogResult.OK)
601
string path = dialog.SelectedPath;
602
if(!Util.containsEnvironmentVars(path))
604
path = Util.relativePath(projectDir, Path.GetFullPath(path));
606
_txtIncludeDir.Text = path;
608
endEditIncludeDir(true);
611
private int _editingIndex = -1;
612
private bool _editingIncludes;
613
private bool _initialized;
614
private bool _changed;
615
private Project _project;
616
private bool _iceHomeUpdating;
617
private TextBox _txtIncludeDir;
618
private Button _btnSelectInclude;