~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/Designer/TextItemDesigner.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 System;
 
5
using System.ComponentModel;
 
6
using System.ComponentModel.Design;
 
7
using System.Windows.Forms;
 
8
using System.Windows.Forms.Design;
 
9
 
 
10
using ICSharpCode.Reports.Core;
 
11
using ICSharpCode.Reports.Core.Dialogs;
 
12
using ICSharpCode.Reports.Core.Interfaces;
 
13
 
 
14
namespace ICSharpCode.Reports.Addin.Designer
 
15
{
 
16
        /// <summary>
 
17
        /// Description of ReportItemDesigner.
 
18
        /// </summary>
 
19
        public class TextItemDesigner:ControlDesigner
 
20
        {
 
21
                
 
22
                private ISelectionService selectionService;
 
23
                private IComponentChangeService componentChangeService;
 
24
                private BaseTextItem ctrl;
 
25
                
 
26
                public override void Initialize(IComponent component)
 
27
                {
 
28
                        base.Initialize(component);
 
29
                        GetService();
 
30
                        this.ctrl = (BaseTextItem) component;
 
31
                }
 
32
                
 
33
                protected override void PostFilterProperties(System.Collections.IDictionary properties)
 
34
                {
 
35
                        DesignerHelper.RemoveProperties(properties);
 
36
                        base.PostFilterProperties(properties);
 
37
                }
 
38
                
 
39
                
 
40
                private void GetService ()
 
41
                {
 
42
                        selectionService = GetService(typeof(ISelectionService)) as ISelectionService;
 
43
                        if (selectionService != null)
 
44
                        {
 
45
                                selectionService.SelectionChanged += OnSelectionChanged;
 
46
 
 
47
                        }
 
48
                        
 
49
                        componentChangeService = (IComponentChangeService)GetService(typeof(IComponentChangeService));
 
50
                        if (componentChangeService != null) {
 
51
                                componentChangeService.ComponentRename += new ComponentRenameEventHandler(OnComponentRename);
 
52
                        }
 
53
                        
 
54
                }
 
55
                
 
56
                
 
57
                private void OnSelectionChanged(object sender, EventArgs e)
 
58
                {
 
59
                        Control.Invalidate( );
 
60
                }
 
61
                
 
62
                
 
63
                private void OnComponentRename(object sender,ComponentRenameEventArgs e) {
 
64
                        if (e.Component == this.Component) {
 
65
                                Control.Name = e.NewName;
 
66
                                Control.Invalidate();
 
67
                        }
 
68
                }
 
69
 
 
70
                
 
71
                
 
72
                #region SmartTag
 
73
                
 
74
                public override DesignerActionListCollection ActionLists {
 
75
                        get {
 
76
                                DesignerActionListCollection actions = new DesignerActionListCollection ();
 
77
                                actions.Add (new TextBasedDesignerActionList(this.Component));
 
78
                                return actions;
 
79
                        }
 
80
                }
 
81
                
 
82
                #endregion
 
83
                
 
84
                #region ContextMenu
 
85
                
 
86
                public override DesignerVerbCollection Verbs {
 
87
                        get {
 
88
                                DesignerVerbCollection verbs = new DesignerVerbCollection();
 
89
                                DesignerVerb v1 = new DesignerVerb ("TextEditor",OnRunTextEditor);
 
90
                                verbs.Add (v1);
 
91
                                return verbs;
 
92
                        }
 
93
                }
 
94
                
 
95
                
 
96
                private void OnRunTextEditor (object sender,EventArgs e)
 
97
                {
 
98
                        IStringBasedEditorDialog ed = new TextEditorDialog (ctrl.Text,ctrl.Name);
 
99
                        if (ed.ShowDialog() == DialogResult.OK) {
 
100
                                ctrl.Text = ed.TextValue;
 
101
                                this.SetProperty ("Name",ed.TextValue);
 
102
                        }
 
103
                }
 
104
                
 
105
                
 
106
                private void SetProperty (string prop, object value)
 
107
                {
 
108
                        PropertyDescriptor p = TypeDescriptor.GetProperties(Control)[prop];
 
109
                        if (p == null) {
 
110
                                throw new ArgumentException (this.ctrl.Text);
 
111
                        } else {
 
112
                                p.SetValue (Control,value);
 
113
                        }
 
114
                }
 
115
                
 
116
                
 
117
                #endregion
 
118
                
 
119
                protected override void Dispose(bool disposing)
 
120
                {
 
121
                        if (this.selectionService != null) {
 
122
                                selectionService.SelectionChanged -= OnSelectionChanged;
 
123
                        }
 
124
                        
 
125
                        if (componentChangeService != null) {
 
126
                                componentChangeService.ComponentRename -= OnComponentRename;
 
127
                        }
 
128
                        base.Dispose(disposing);
 
129
                }
 
130
        }
 
131
}