~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/Analysis/CodeCoverage/Project/Src/CodeCoverageOptionsPanel.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
 
3
 
 
4
using ICSharpCode.SharpDevelop.Gui.OptionPanels;
 
5
using System;
 
6
using System.Drawing;
 
7
using System.Windows.Forms;
 
8
using ICSharpCode.Core;
 
9
using ICSharpCode.SharpDevelop.Gui;
 
10
 
 
11
namespace ICSharpCode.CodeCoverage
 
12
{
 
13
        public class CodeCoverageOptionsPanel : XmlFormsOptionPanel
 
14
        {
 
15
                static readonly string foregroundCustomColourButtonName = "foregroundCustomColourButton";
 
16
                static readonly string backgroundCustomColourButtonName = "backgroundCustomColourButton";
 
17
                static readonly string foregroundColourComboBoxName = "foregroundColorPickerComboBox";
 
18
                static readonly string backgroundColourComboBoxName = "backgroundColorPickerComboBox";
 
19
                static readonly string displayItemsListBoxName = "displayItemsListBox";
 
20
                static readonly string sampleTextLabelName = "sampleTextLabel";
 
21
 
 
22
                ColorPickerComboBox foregroundColorPickerComboBox;
 
23
                ColorPickerComboBox backgroundColorPickerComboBox;
 
24
                ListBox displayItemsListBox;
 
25
                Label sampleTextLabel;
 
26
 
 
27
                public override void LoadPanelContents()
 
28
                {
 
29
                        SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("ICSharpCode.CodeCoverage.Resources.CodeCoverageOptionsPanel.xfrm"));
 
30
                                                
 
31
                        ControlDictionary[foregroundCustomColourButtonName].Click += ForegroundCustomColourButtonClick;
 
32
                        ControlDictionary[backgroundCustomColourButtonName].Click += BackgroundCustomColourButtonClick;
 
33
                        
 
34
                        foregroundColorPickerComboBox = (ColorPickerComboBox)ControlDictionary[foregroundColourComboBoxName];
 
35
                        foregroundColorPickerComboBox.SelectedIndexChanged += ForegroundColorPickerComboBoxSelectedIndexChanged;
 
36
                        
 
37
                        backgroundColorPickerComboBox = (ColorPickerComboBox)ControlDictionary[backgroundColourComboBoxName];
 
38
                        backgroundColorPickerComboBox.SelectedIndexChanged += BackgroundColorPickerComboBoxSelectedIndexChanged;
 
39
 
 
40
                        sampleTextLabel = (Label)ControlDictionary[sampleTextLabelName];
 
41
                                                
 
42
                        displayItemsListBox = (ListBox)ControlDictionary[displayItemsListBoxName];
 
43
                        displayItemsListBox.Items.Add(new CodeCoverageDisplayItem(StringParser.Parse("${res:ICSharpCode.CodeCoverage.CodeCovered}"), CodeCoverageOptions.VisitedColorProperty, CodeCoverageOptions.VisitedColor, CodeCoverageOptions.VisitedForeColorProperty, CodeCoverageOptions.VisitedForeColor));
 
44
                        displayItemsListBox.Items.Add(new CodeCoverageDisplayItem(StringParser.Parse("${res:ICSharpCode.CodeCoverage.CodeNotCovered}"), CodeCoverageOptions.NotVisitedColorProperty, CodeCoverageOptions.NotVisitedColor, CodeCoverageOptions.NotVisitedForeColorProperty, CodeCoverageOptions.NotVisitedForeColor));
 
45
                        displayItemsListBox.SelectedIndexChanged += DisplayItemsListBoxSelectedIndexChanged;
 
46
                        displayItemsListBox.SelectedIndex = 0;
 
47
                }
 
48
 
 
49
                public override bool StorePanelContents()
 
50
                {
 
51
                        bool codeCoverageColorsChanged = false;
 
52
                
 
53
                        foreach (CodeCoverageDisplayItem item in displayItemsListBox.Items) {
 
54
                                CodeCoverageOptions.Properties.Set<Color>(item.ForeColorPropertyName, item.ForeColor);
 
55
                                CodeCoverageOptions.Properties.Set<Color>(item.BackColorPropertyName, item.BackColor);
 
56
                                if (item.HasChanged) {
 
57
                                        codeCoverageColorsChanged = true;
 
58
                                }
 
59
                        }
 
60
 
 
61
                        if (codeCoverageColorsChanged) {
 
62
                                CodeCoverageService.RefreshCodeCoverageHighlights();
 
63
                        }
 
64
 
 
65
                        return true;
 
66
                }
 
67
                
 
68
                void ForegroundCustomColourButtonClick(object sender, EventArgs e)
 
69
                {
 
70
                        SelectCustomColour(foregroundColorPickerComboBox);
 
71
                }
 
72
                
 
73
                void BackgroundCustomColourButtonClick(object sender, EventArgs e)
 
74
                {
 
75
                        SelectCustomColour(backgroundColorPickerComboBox);
 
76
                }
 
77
                
 
78
                void SelectCustomColour(ColorPickerComboBox comboBox)
 
79
                {
 
80
                        using (SharpDevelopColorDialog colorDialog = new SharpDevelopColorDialog()) {
 
81
                                colorDialog.FullOpen = true;
 
82
                                colorDialog.Color = comboBox.SelectedColor;
 
83
                                if (colorDialog.ShowDialog() == DialogResult.OK) {
 
84
                                        comboBox.SelectedColor = colorDialog.Color;     
 
85
                                }
 
86
                        }
 
87
                }
 
88
                
 
89
                void DisplayItemsListBoxSelectedIndexChanged(object sender, EventArgs e)
 
90
                {
 
91
                        CodeCoverageDisplayItem item = (CodeCoverageDisplayItem)displayItemsListBox.SelectedItem;
 
92
                        sampleTextLabel.BackColor = item.BackColor;
 
93
                        sampleTextLabel.ForeColor = item.ForeColor;
 
94
                        foregroundColorPickerComboBox.SelectedColor = item.ForeColor;
 
95
                        backgroundColorPickerComboBox.SelectedColor = item.BackColor;
 
96
                }
 
97
                
 
98
                void ForegroundColorPickerComboBoxSelectedIndexChanged(object sender, EventArgs e)
 
99
                {
 
100
                        CodeCoverageDisplayItem item = (CodeCoverageDisplayItem)displayItemsListBox.SelectedItem;
 
101
                        sampleTextLabel.ForeColor = foregroundColorPickerComboBox.SelectedColor;
 
102
                        item.ForeColor = foregroundColorPickerComboBox.SelectedColor;
 
103
                }
 
104
                
 
105
                void BackgroundColorPickerComboBoxSelectedIndexChanged(object sender, EventArgs e)
 
106
                {
 
107
                        CodeCoverageDisplayItem item = (CodeCoverageDisplayItem)displayItemsListBox.SelectedItem;
 
108
                        sampleTextLabel.BackColor = backgroundColorPickerComboBox.SelectedColor;
 
109
                        item.BackColor = backgroundColorPickerComboBox.SelectedColor;
 
110
                }
 
111
        }
 
112
}