~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/Analysis/CodeAnalysis/Src/AnalysisIdeOptionsPanel.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.IO;
 
7
using System.Windows.Forms;
 
8
using ICSharpCode.Core;
 
9
using ICSharpCode.SharpDevelop.Gui;
 
10
 
 
11
namespace ICSharpCode.CodeAnalysis
 
12
{
 
13
        /// <summary>
 
14
        /// Option panel to choose the FxCop path from.
 
15
        /// </summary>
 
16
        public class AnalysisIdeOptionsPanel : XmlFormsOptionPanel
 
17
        {
 
18
                public override void LoadPanelContents()
 
19
                {
 
20
                        SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("ICSharpCode.CodeAnalysis.Resources.AnalysisIdeOptionPanel.xfrm"));
 
21
                        
 
22
                        ShowStatus();
 
23
                        Get<Button>("findFxCopPath").Click += FindFxCopPathClick;
 
24
                }
 
25
                
 
26
                void ShowStatus()
 
27
                {
 
28
                        string path = FxCopWrapper.FindFxCopPath();
 
29
                        if (path == null) {
 
30
                                Get<Label>("status").Text = StringParser.Parse("${res:ICSharpCode.CodeAnalysis.IdeOptions.FxCopNotFound}");
 
31
                        } else {
 
32
                                Get<Label>("status").Text = StringParser.Parse("${res:ICSharpCode.CodeAnalysis.IdeOptions.FxCopFoundInPath}")
 
33
                                        + Environment.NewLine + path;
 
34
                        }
 
35
                }
 
36
                
 
37
                void FindFxCopPathClick(object sender, EventArgs e)
 
38
                {
 
39
                        using (OpenFileDialog dlg = new OpenFileDialog()) {
 
40
                                dlg.DefaultExt = "exe";
 
41
                                dlg.Filter = StringParser.Parse("FxCop|fxcop.exe|${res:SharpDevelop.FileFilter.AllFiles}|*.*");
 
42
                                if (dlg.ShowDialog() == DialogResult.OK) {
 
43
                                        string path = Path.GetDirectoryName(dlg.FileName);
 
44
                                        if (FxCopWrapper.IsFxCopPath(path)) {
 
45
                                                FxCopPath = path;
 
46
                                        } else {
 
47
                                                MessageService.ShowError("${res:ICSharpCode.CodeAnalysis.IdeOptions.DirectoryDoesNotContainFxCop}");
 
48
                                        }
 
49
                                }
 
50
                        }
 
51
                        ShowStatus();
 
52
                }
 
53
                
 
54
                public static string FxCopPath {
 
55
                        get {
 
56
                                return PropertyService.Get("CodeAnalysis.FxCopPath");
 
57
                        }
 
58
                        set {
 
59
                                PropertyService.Set("CodeAnalysis.FxCopPath", value);
 
60
                        }
 
61
                }
 
62
        }
 
63
}