~ubuntu-branches/ubuntu/quantal/zeroc-ice/quantal

« back to all changes in this revision

Viewing changes to vsplugin/src/IceSilverlightConfigurationDialog.cs

  • Committer: Bazaar Package Importer
  • Author(s): Cleto Martin Angelina
  • Date: 2011-04-25 18:44:24 UTC
  • mfrom: (6.1.14 sid)
  • Revision ID: james.westby@ubuntu.com-20110425184424-sep9i9euu434vq4c
Tags: 3.4.1-7
* Bug fix: "libdb5.1-java.jar was renamed to db.jar", thanks to Ondřej
  Surý (Closes: #623555).
* Bug fix: "causes noise in php5", thanks to Jayen Ashar (Closes:
  #623533).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// **********************************************************************
 
2
//
 
3
// Copyright (c) 2003-2010 ZeroC, Inc. All rights reserved.
 
4
//
 
5
// This copy of Ice is licensed to you under the terms described in the
 
6
// ICE_LICENSE file included in this distribution.
 
7
//
 
8
// **********************************************************************
 
9
 
 
10
using System;
 
11
using System.Collections.Generic;
 
12
using System.ComponentModel;
 
13
using System.Data;
 
14
using System.Drawing;
 
15
using System.IO;
 
16
using System.Text;
 
17
using System.Windows.Forms;
 
18
 
 
19
using EnvDTE;
 
20
 
 
21
namespace Ice.VisualStudio
 
22
{
 
23
    public partial class IceSilverlightConfigurationDialog : Form
 
24
    {
 
25
        public IceSilverlightConfigurationDialog(Project project)
 
26
        {
 
27
            InitializeComponent();
 
28
            _project = project;
 
29
            
 
30
            //
 
31
            // Set the toolTip messages.
 
32
            //
 
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.");
 
37
 
 
38
 
 
39
            if(_project != null)
 
40
            {
 
41
                this.Text = "Ice Configuration - Project: " + _project.Name;
 
42
                bool enabled = Util.isSliceBuilderEnabled(project);
 
43
                setEnabled(enabled);
 
44
                chkEnableBuilder.Checked = enabled;
 
45
                load();
 
46
                _initialized = true;
 
47
            }
 
48
        }
 
49
        
 
50
        private void load()
 
51
        {
 
52
            Cursor = Cursors.WaitCursor;
 
53
            if(_project != null)
 
54
            {
 
55
                includeDirList.Items.Clear();
 
56
                txtIceHome.Text = Util.getIceHomeRaw(_project, false);
 
57
                txtExtraOptions.Text = Util.getProjectProperty(_project, Util.PropertyIceExtraOptions);
 
58
 
 
59
                chkIcePrefix.Checked = Util.getProjectPropertyAsBool(_project, Util.PropertyIcePrefix);
 
60
                chkConsole.Checked = Util.getProjectPropertyAsBool(_project, Util.PropertyConsoleOutput);
 
61
                
 
62
                IncludePathList list =
 
63
                    new IncludePathList(Util.getProjectProperty(_project, Util.PropertyIceIncludePath));
 
64
                foreach(String s in list)
 
65
                {
 
66
                    includeDirList.Items.Add(s.Trim());
 
67
                    if(Path.IsPathRooted(s.Trim()))
 
68
                    {
 
69
                        includeDirList.SetItemCheckState(includeDirList.Items.Count - 1, CheckState.Checked);
 
70
                    }
 
71
                }
 
72
 
 
73
                ComponentList selectedComponents = Util.getIceSilverlightComponents(_project);
 
74
                foreach(String s in Util.getSilverlightNames())
 
75
                {
 
76
                    if(selectedComponents.Contains(s))
 
77
                    {
 
78
                        checkComponent(s, true);
 
79
                    }
 
80
                    else
 
81
                    {
 
82
                        checkComponent(s, false);
 
83
                    }
 
84
                }
 
85
            }
 
86
            Cursor = Cursors.Default;
 
87
        }
 
88
 
 
89
        private void checkComponent(String component, bool check)
 
90
        {
 
91
            if(_editingIncludes)
 
92
            {
 
93
                endEditIncludeDir(false);
 
94
            }
 
95
            switch (component)
 
96
            {
 
97
                case "IceSL":
 
98
                {
 
99
                    chkIceSl.Checked = check;
 
100
                    break;
 
101
                }
 
102
                default:
 
103
                {
 
104
                    break;
 
105
                }
 
106
            }
 
107
        }
 
108
        private void chkEnableBuilder_CheckedChanged(object sender, EventArgs e)
 
109
        {
 
110
            Cursor = Cursors.WaitCursor;
 
111
            if(_editingIncludes)
 
112
            {
 
113
                endEditIncludeDir(false);
 
114
            }
 
115
            if(_initialized)
 
116
            {
 
117
                _initialized = false;
 
118
                setEnabled(false);
 
119
                chkEnableBuilder.Enabled = false;
 
120
                Builder builder = Connect.getBuilder();
 
121
                if(chkEnableBuilder.Checked)
 
122
                {
 
123
                    builder.addBuilderToProject(_project);
 
124
                }
 
125
                else
 
126
                {
 
127
                    builder.removeBuilderFromProject(_project);
 
128
                }
 
129
                load();
 
130
                chkEnableBuilder.Enabled = true;
 
131
                setEnabled(chkEnableBuilder.Checked);
 
132
                _initialized = true;
 
133
            }
 
134
            Cursor = Cursors.Default;
 
135
        }
 
136
        
 
137
        private void setEnabled(bool enabled)
 
138
        {
 
139
            txtIceHome.Enabled = enabled;
 
140
            btnSelectIceHome.Enabled = enabled;
 
141
 
 
142
            chkIcePrefix.Enabled = enabled;
 
143
            chkConsole.Enabled = enabled;
 
144
            
 
145
            includeDirList.Enabled = enabled;
 
146
            btnAddInclude.Enabled = enabled;
 
147
            btnEditInclude.Enabled = enabled;
 
148
            btnRemoveInclude.Enabled = enabled;
 
149
            btnMoveIncludeUp.Enabled = enabled;
 
150
            btnMoveIncludeDown.Enabled = enabled;
 
151
 
 
152
            txtExtraOptions.Enabled = enabled;
 
153
 
 
154
 
 
155
            chkIceSl.Enabled = enabled;
 
156
        }
 
157
 
 
158
        private void formClosing(object sender, EventArgs e)
 
159
        {
 
160
            Cursor = Cursors.WaitCursor;
 
161
            if(_editingIncludes)
 
162
            {
 
163
                endEditIncludeDir(false);
 
164
            }
 
165
            if(!_changed)
 
166
            {
 
167
                if(txtExtraOptions.Modified)
 
168
                {
 
169
                    _changed = true;
 
170
                }
 
171
                else if(txtIceHome.Modified)
 
172
                {
 
173
                    _changed = true;
 
174
                }
 
175
            }
 
176
 
 
177
            if(_changed && Util.isSliceBuilderEnabled(_project))
 
178
            {
 
179
                Builder builder = Connect.getBuilder();
 
180
                builder.cleanProject(_project);
 
181
                builder.buildProject(_project, true, vsBuildScope.vsBuildScopeProject);
 
182
            }
 
183
            Cursor = Cursors.Default;
 
184
        }
 
185
 
 
186
        private void btnCancel_Click(object sender, EventArgs e)
 
187
        {
 
188
            Close();
 
189
        }
 
190
 
 
191
        private void btnSelectIceHome_Click(object sender, EventArgs e)
 
192
        {
 
193
            if(_editingIncludes)
 
194
            {
 
195
                endEditIncludeDir(false);
 
196
            }
 
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)
 
202
            {
 
203
                Util.updateIceHome(_project, dialog.SelectedPath, false);
 
204
                load();
 
205
                _changed = true;
 
206
            }
 
207
        }
 
208
 
 
209
        private void txtIceHome_KeyPress(object sender, KeyPressEventArgs e)
 
210
        {
 
211
            if(e.KeyChar == (char)Keys.Return)
 
212
            {
 
213
                updateIceHome();
 
214
                e.Handled = true;
 
215
            }
 
216
        }
 
217
 
 
218
        private void txtIceHome_Focus(object sender, EventArgs e)
 
219
        {
 
220
            if(_editingIncludes)
 
221
            {
 
222
                endEditIncludeDir(false);
 
223
            }
 
224
        }
 
225
        
 
226
        private void txtIceHome_LostFocus(object sender, EventArgs e)
 
227
        {
 
228
            updateIceHome();
 
229
        }
 
230
 
 
231
        private void updateIceHome()
 
232
        {
 
233
            if(!_iceHomeUpdating)
 
234
            {
 
235
                _iceHomeUpdating = true;
 
236
                if(!txtIceHome.Text.Equals(Util.getProjectProperty(_project, Util.PropertyIceHome), 
 
237
                                           StringComparison.CurrentCultureIgnoreCase))
 
238
                {
 
239
                    Util.updateIceHome(_project, txtIceHome.Text, false);
 
240
                    load();
 
241
                    _changed = true;
 
242
                    txtIceHome.Modified = false;
 
243
                }
 
244
                _iceHomeUpdating = false;
 
245
            }
 
246
        }
 
247
 
 
248
        private void chkIcePrefix_CheckedChanged(object sender, EventArgs e)
 
249
        {
 
250
            Cursor = Cursors.WaitCursor;
 
251
            if(_editingIncludes)
 
252
            {
 
253
                endEditIncludeDir(false);
 
254
            }
 
255
            Util.setProjectProperty(_project, Util.PropertyIcePrefix, chkIcePrefix.Checked.ToString());
 
256
            _changed = true;
 
257
            Cursor = Cursors.Default;
 
258
        }
 
259
 
 
260
        private void saveSliceIncludes()
 
261
        {
 
262
            IncludePathList paths = new IncludePathList();
 
263
            foreach(String s in includeDirList.Items)
 
264
            {
 
265
                paths.Add(s.Trim());
 
266
            }
 
267
            String p = paths.ToString();
 
268
            Util.setProjectProperty(_project, Util.PropertyIceIncludePath, p);
 
269
            _changed = true;
 
270
        }
 
271
 
 
272
        private void btnAddInclude_Click(object sender, EventArgs e)
 
273
        {
 
274
            if(_editingIncludes)
 
275
            {
 
276
                endEditIncludeDir(false);
 
277
            }
 
278
            includeDirList.Items.Add("");
 
279
            includeDirList.SelectedIndex = includeDirList.Items.Count - 1;
 
280
            _editingIndex = includeDirList.SelectedIndex;
 
281
            beginEditIncludeDir();
 
282
        }
 
283
 
 
284
        private void btnRemoveInclude_Click(object sender, EventArgs e)
 
285
        {
 
286
            Cursor = Cursors.WaitCursor;
 
287
            int index = includeDirList.SelectedIndex;
 
288
            if(_editingIncludes)
 
289
            {
 
290
                index = _editingIndex;
 
291
                endEditIncludeDir(false);
 
292
            }
 
293
            if(index > -1 && index < includeDirList.Items.Count)
 
294
            {
 
295
                int selected = index;
 
296
                includeDirList.Items.RemoveAt(selected);
 
297
                if (includeDirList.Items.Count > 0)
 
298
                {
 
299
                    if (selected > 0)
 
300
                    {
 
301
                        selected -= 1;
 
302
                    }
 
303
                    includeDirList.SelectedIndex = selected;
 
304
                }
 
305
                saveSliceIncludes();
 
306
            }
 
307
            Cursor = Cursors.Default;
 
308
        }
 
309
 
 
310
        private void btnMoveIncludeUp_Click(object sender, EventArgs e)
 
311
        {
 
312
            Cursor = Cursors.WaitCursor;
 
313
            if(_editingIncludes)
 
314
            {
 
315
                endEditIncludeDir(false);
 
316
            }
 
317
            int index = includeDirList.SelectedIndex;
 
318
            if(index > 0)
 
319
            {
 
320
                string current = includeDirList.SelectedItem.ToString();
 
321
                includeDirList.Items.RemoveAt(index);
 
322
                includeDirList.Items.Insert(index - 1, current);
 
323
                includeDirList.SelectedIndex = index - 1;
 
324
                saveSliceIncludes();
 
325
            }
 
326
            resetIncludeDirChecks();
 
327
            Cursor = Cursors.Default;
 
328
        }
 
329
 
 
330
        private void btnMoveIncludeDown_Click(object sender, EventArgs e)
 
331
        {
 
332
            Cursor = Cursors.WaitCursor;
 
333
            if(_editingIncludes)
 
334
            {
 
335
                endEditIncludeDir(false);
 
336
            }
 
337
            int index = includeDirList.SelectedIndex;
 
338
            if(index < includeDirList.Items.Count - 1 && index > -1)
 
339
            {
 
340
                string current = includeDirList.SelectedItem.ToString();
 
341
                includeDirList.Items.RemoveAt(index);
 
342
                includeDirList.Items.Insert(index + 1, current);
 
343
                includeDirList.SelectedIndex = index + 1;
 
344
                saveSliceIncludes();
 
345
                resetIncludeDirChecks();
 
346
            }
 
347
            Cursor = Cursors.Default;
 
348
        }
 
349
 
 
350
        private void includeDirList_ItemCheck(object sender, ItemCheckEventArgs e)
 
351
        {
 
352
            if(_editingIncludes)
 
353
            {
 
354
                return;
 
355
            }
 
356
            string path = includeDirList.Items[e.Index].ToString();
 
357
            if(!Util.containsEnvironmentVars(path))
 
358
            {
 
359
                if(e.NewValue == CheckState.Unchecked)
 
360
                {
 
361
                    path = Util.relativePath(Path.GetDirectoryName(_project.FileName), path);
 
362
                }
 
363
                else if(e.NewValue == CheckState.Checked)
 
364
                {
 
365
                    if(!Path.IsPathRooted(path))
 
366
                    {
 
367
                        path = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(_project.FileName), path));
 
368
                    }
 
369
                }
 
370
            }
 
371
            includeDirList.Items[e.Index] = path;
 
372
            if(_initialized)
 
373
            {
 
374
                saveSliceIncludes();
 
375
            }
 
376
        }
 
377
 
 
378
        private void txtExtraOptions_Focus(object sender, EventArgs e)
 
379
        {
 
380
            if(_editingIncludes)
 
381
            {
 
382
                endEditIncludeDir(false);
 
383
            }
 
384
        }
 
385
 
 
386
        private void txtExtraOptions_LostFocus(object sender, EventArgs e)
 
387
        {
 
388
            if(txtExtraOptions.Modified)
 
389
            {
 
390
                Util.setProjectProperty(_project, Util.PropertyIceExtraOptions, txtExtraOptions.Text);
 
391
                _changed = true;
 
392
            }
 
393
        }
 
394
 
 
395
 
 
396
        private void chkIce_CheckedChanged(object sender, EventArgs e)
 
397
        {
 
398
            Cursor = Cursors.WaitCursor;
 
399
            if(_editingIncludes)
 
400
            {
 
401
                endEditIncludeDir(false);
 
402
            }
 
403
            if(_initialized)
 
404
            {
 
405
                if(chkIceSl.Checked)
 
406
                {
 
407
                    Util.addDotNetReference(_project, "IceSL");
 
408
                }
 
409
                else
 
410
                {
 
411
                    Util.removeDotNetReference(_project, "IceSL");
 
412
                }
 
413
                _changed = true;
 
414
            }
 
415
            Cursor = Cursors.Default;
 
416
        }
 
417
 
 
418
        private void chkConsole_CheckedChanged(object sender, EventArgs e)
 
419
        {
 
420
            Cursor = Cursors.WaitCursor;
 
421
            if(_editingIncludes)
 
422
            {
 
423
                endEditIncludeDir(false);
 
424
            }
 
425
            Util.setProjectProperty(_project, Util.PropertyConsoleOutput, chkConsole.Checked.ToString());
 
426
            Cursor = Cursors.Default;
 
427
        }
 
428
 
 
429
        private void btnEdit_Click(object sender, EventArgs e)
 
430
        {
 
431
            if(includeDirList.SelectedIndex != -1)
 
432
            {
 
433
                _editingIndex = includeDirList.SelectedIndex;
 
434
                beginEditIncludeDir();
 
435
            }
 
436
        }
 
437
 
 
438
        private void includeDirList_SelectedIndexChanged(object sender, EventArgs e)
 
439
        {
 
440
            if(_editingIncludes)
 
441
            {
 
442
                endEditIncludeDir(false);
 
443
            }
 
444
        }
 
445
 
 
446
        private void beginEditIncludeDir()
 
447
        {
 
448
            if(_editingIncludes)
 
449
            {
 
450
                endEditIncludeDir(false);
 
451
            }
 
452
            _editingIncludes = true;
 
453
            CancelButton = null;
 
454
            if(_editingIndex != -1)
 
455
            {
 
456
                _txtIncludeDir = new TextBox();
 
457
                _txtIncludeDir.Text = includeDirList.Items[includeDirList.SelectedIndex].ToString();
 
458
 
 
459
                includeDirList.SelectionMode = SelectionMode.One;
 
460
 
 
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);
 
468
 
 
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);
 
477
 
 
478
 
 
479
                _txtIncludeDir.Show();
 
480
                _txtIncludeDir.BringToFront();
 
481
                _txtIncludeDir.Focus();
 
482
 
 
483
                _btnSelectInclude.Show();
 
484
                _btnSelectInclude.BringToFront();
 
485
            }
 
486
        }
 
487
 
 
488
        private void endEditIncludeDir(bool saveChanges)
 
489
        {
 
490
            _initialized = false;
 
491
            if(!_editingIncludes)
 
492
            {
 
493
                _initialized = true;
 
494
                return;
 
495
            }
 
496
            _editingIncludes = false;
 
497
            String path = null;
 
498
            if(_editingIndex > -1 && _editingIndex < includeDirList.Items.Count)
 
499
            {
 
500
                path = includeDirList.Items[_editingIndex].ToString();
 
501
            }
 
502
 
 
503
            lock(this)
 
504
            {
 
505
                CancelButton = btnClose;
 
506
                if(_txtIncludeDir == null || _btnSelectInclude == null)
 
507
                {
 
508
                    _initialized = true;
 
509
                    return;
 
510
                }
 
511
                if(saveChanges)
 
512
                {
 
513
                    path = _txtIncludeDir.Text;
 
514
                    if(path != null)
 
515
                    {
 
516
                        path = path.Trim();
 
517
                    }
 
518
                }
 
519
 
 
520
                this.groupBox1.Controls.Remove(_txtIncludeDir);
 
521
                _txtIncludeDir = null;
 
522
 
 
523
                this.groupBox1.Controls.Remove(_btnSelectInclude);
 
524
                _btnSelectInclude = null;
 
525
            }
 
526
 
 
527
            if(String.IsNullOrEmpty(path))
 
528
            {
 
529
                if(_editingIndex != -1)
 
530
                {
 
531
                    includeDirList.Items.RemoveAt(_editingIndex);
 
532
                    includeDirList.SelectedIndex = includeDirList.Items.Count - 1;
 
533
                    _editingIndex = -1;
 
534
                    saveSliceIncludes();
 
535
                }
 
536
            }
 
537
            else if(_editingIndex != -1 && saveChanges)
 
538
            {
 
539
                if(!path.Equals(includeDirList.Items[_editingIndex].ToString(),
 
540
                                               StringComparison.CurrentCultureIgnoreCase))
 
541
                {
 
542
                    includeDirList.Items[_editingIndex] = path;
 
543
                    if(Path.IsPathRooted(path))
 
544
                    {
 
545
                        includeDirList.SetItemCheckState(_editingIndex, CheckState.Checked);
 
546
                    }
 
547
                    else
 
548
                    {
 
549
                        includeDirList.SetItemCheckState(_editingIndex, CheckState.Unchecked);
 
550
                    }
 
551
                    saveSliceIncludes();
 
552
                }
 
553
            }
 
554
            resetIncludeDirChecks();
 
555
        }
 
556
        
 
557
        private void resetIncludeDirChecks()
 
558
        {
 
559
            _initialized = false;
 
560
            for(int i = 0; i < includeDirList.Items.Count; i++)
 
561
            {
 
562
                String path = includeDirList.Items[i].ToString();
 
563
                if(String.IsNullOrEmpty(path))
 
564
                {
 
565
                    continue;
 
566
                }
 
567
 
 
568
                if(Path.IsPathRooted(path))
 
569
                {
 
570
                    includeDirList.SetItemCheckState(i, CheckState.Checked);
 
571
                }
 
572
                else
 
573
                {
 
574
                    includeDirList.SetItemCheckState(i, CheckState.Unchecked);
 
575
                }
 
576
            }
 
577
            _initialized = true;
 
578
        }
 
579
 
 
580
        private void includeDirKeyDown(object sender, KeyEventArgs e)
 
581
        {
 
582
            if(e.KeyCode.Equals(Keys.Escape))
 
583
            {
 
584
                endEditIncludeDir(false);
 
585
            }
 
586
            if(e.KeyCode.Equals(Keys.Enter))
 
587
            {
 
588
                endEditIncludeDir(true);
 
589
            }
 
590
        }
 
591
 
 
592
        private void selectIncludeClicked(object sender, EventArgs e)
 
593
        {
 
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)
 
600
            {
 
601
                string path = dialog.SelectedPath;
 
602
                if(!Util.containsEnvironmentVars(path))
 
603
                {
 
604
                    path = Util.relativePath(projectDir, Path.GetFullPath(path));
 
605
                }
 
606
                _txtIncludeDir.Text = path;
 
607
            }
 
608
            endEditIncludeDir(true);
 
609
        }
 
610
 
 
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;
 
619
 
 
620
    }
 
621
}