File: WebPartVerb.cs

package info (click to toggle)
mono 6.14.1%2Bds2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,282,732 kB
  • sloc: cs: 11,182,461; xml: 2,850,281; ansic: 699,123; cpp: 122,919; perl: 58,604; javascript: 30,841; asm: 21,845; makefile: 19,602; sh: 10,973; python: 4,772; pascal: 925; sql: 859; sed: 16; php: 1
file content (312 lines) | stat: -rw-r--r-- 10,050 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
//------------------------------------------------------------------------------
// <copyright file="WebPartVerb.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//------------------------------------------------------------------------------

namespace System.Web.UI.WebControls.WebParts {

    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing.Design;
    using System.Globalization;
    using System.Web.UI.WebControls;
    using System.Web.Util;

    [
    TypeConverter(typeof(EmptyStringExpandableObjectConverter))
    ]
    public class WebPartVerb : IStateManager {
        private bool _isTrackingViewState;
        private StateBag _viewState;

        private bool _visible = true;

        private string _id;
        private string _clientClickHandler;
        private WebPartEventHandler _serverClickHandler;

        private string _eventArgument;

        // PERF: Don't create the EventArgument string until needed, when the verb is actually rendered.
        private string _eventArgumentPrefix;

        // Used when creating default verbs in WebPartZoneBase, CatalogZoneBase, EditorZoneBase. For these
        // verbs, the clientClickHandler and serverClickHandler are null. The zone has references
        // to these verbs and can render the verb and handle events by knowing which verb it is
        // rendering.
        internal WebPartVerb() {
        }

        private WebPartVerb(string id) {
            if (String.IsNullOrEmpty(id)) {
                throw ExceptionUtil.ParameterNullOrEmpty("id");
            }

            _id = id;
        }

        public WebPartVerb(string id, WebPartEventHandler serverClickHandler) : this(id) {
            if (serverClickHandler == null) {
                throw new ArgumentNullException("serverClickHandler");
            }
            _serverClickHandler = serverClickHandler;
        }

        public WebPartVerb(string id, string clientClickHandler) : this(id) {
            if (String.IsNullOrEmpty(clientClickHandler)) {
                throw new ArgumentNullException("clientClickHandler");
            }
            _clientClickHandler = clientClickHandler;
        }

        public WebPartVerb(string id, WebPartEventHandler serverClickHandler, string clientClickHandler) : this(id) {
            if (serverClickHandler == null) {
                throw new ArgumentNullException("serverClickHandler");
            }
            if (String.IsNullOrEmpty(clientClickHandler)) {
                throw new ArgumentNullException("clientClickHandler");
            }
            _serverClickHandler = serverClickHandler;
            _clientClickHandler = clientClickHandler;
        }

        [
        DefaultValue(false),
        NotifyParentProperty(true),
        Themeable(false),
        WebSysDescription(SR.WebPartVerb_Checked),
        ]
        public virtual bool Checked {
            get {
                object b = ViewState["Checked"];
                return (b != null) ? (bool)b : false  ;
            }
            set {
                ViewState["Checked"] = value;
            }
        }

        [
        Browsable(false),
        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
        ]
        public string ClientClickHandler {
            get {
                return (_clientClickHandler == null) ? String.Empty: _clientClickHandler;
            }
        }

        [
        Localizable(true),
        NotifyParentProperty(true),
        // Must use WebSysDefaultValue instead of DefaultValue, since it is overridden in extending classes
        WebSysDefaultValue(""),
        WebSysDescription(SR.WebPartVerb_Description),
        ]
        public virtual string Description {
            get {
                object o = ViewState["Description"];
                return (o == null) ? String.Empty : (string)o;
            }
            set {
                ViewState["Description"] = value;
            }
        }

        [
        DefaultValue(true),
        NotifyParentProperty(true),
        Themeable(false),
        WebSysDescription(SR.WebPartVerb_Enabled),
        ]
        public virtual bool Enabled {
            get {
                object b = ViewState["Enabled"];
                return (b != null) ? (bool)b : true;
            }
            set {
                ViewState["Enabled"] = value;
            }
        }

        /// <devdoc>
        /// Used to assign an event argument to the verb that will be rendered later.
        /// </devdoc>
        internal string EventArgument {
            get {
                return (_eventArgument != null) ? _eventArgument : String.Empty;
            }
            set {
                _eventArgument = value;
            }
        }

        [
        Browsable(false),
        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
        ]
        public string ID {
            get {
                return (_id != null) ? _id : String.Empty;
            }
        }

        [
        DefaultValue(""),
        Editor("System.Web.UI.Design.ImageUrlEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor)),
        NotifyParentProperty(true),
        UrlProperty(),
        WebSysDescription(SR.WebPartVerb_ImageUrl),
        ]
        public virtual string ImageUrl {
            get {
                object o = ViewState["ImageUrl"];
                return (o == null) ? String.Empty : (string)o;
            }
            set {
                ViewState["ImageUrl"] = value;
            }
        }

        protected virtual bool IsTrackingViewState {
            get {
                return _isTrackingViewState;
            }
        }

        [
        Browsable(false),
        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
        ]
        public WebPartEventHandler ServerClickHandler {
            get {
                return _serverClickHandler;
            }
        }

        /// <devdoc>
        /// The text to be displayed for the webPartVerb.
        /// </devdoc>
        [
        Localizable(true),
        NotifyParentProperty(true),
        // Must use WebSysDefaultValue instead of DefaultValue, since it is overridden in extending classes
        WebSysDefaultValue(""),
        WebSysDescription(SR.WebPartVerb_Text),
        ]
        public virtual string Text {
            get {
                object o = ViewState["Text"];
                return (o == null) ? String.Empty : (string)o;
            }
            set {
                ViewState["Text"] = value;
            }
        }

        [
        DefaultValue(true),
        NotifyParentProperty(true),
        Themeable(false),
        WebSysDescription(SR.WebPartVerb_Visible),
        ]
        public virtual bool Visible {
            get {
                return _visible;
            }
            set {
                _visible = value;
                ViewState["Visible"] = value;
            }
        }

        protected StateBag ViewState {
            get {
                if (_viewState == null) {
                    _viewState = new StateBag(false);
                    if (_isTrackingViewState) {
                        ((IStateManager)_viewState).TrackViewState();
                    }
                }
                return _viewState;
            }
        }

        // PERF: Don't create the EventArgument string until needed, when the verb is actually rendered.
        // Only called by WebPartChrome and WebPartMenu.  The verbs in CatalogZone, EditorZone, and
        // ConnectionsZone just use the EventArgument property.
        internal string GetEventArgument(string webPartID) {
            // If the prefix was never set, it means we are a user-specified verb with only a
            // client click handler.  So we should return String.Empty for our EventArgument.
            if (String.IsNullOrEmpty(_eventArgumentPrefix)) {
                return String.Empty;
            }
            else {
                if (_id == null) {
                    return _eventArgumentPrefix + webPartID;
                }
                else {
                    return _eventArgumentPrefix + _id +
                        WebPartZoneBase.EventArgumentSeparator + webPartID;
                }
            }
        }

        protected virtual void LoadViewState(object savedState) {
            if (savedState != null) {
                ((IStateManager)ViewState).LoadViewState(savedState);

                // Cache value of Visible
                object b = ViewState["Visible"];
                if (b != null) {
                    _visible = (bool)b;
                }
            }
        }

        protected virtual object SaveViewState() {
            if (_viewState != null) {
                return ((IStateManager)_viewState).SaveViewState();
            }
            return null;
        }

        // Only used by WebPartZoneBase for verbs rendered on a WebPart.
        internal void SetEventArgumentPrefix(string eventArgumentPrefix) {
            _eventArgumentPrefix = eventArgumentPrefix;
        }

        protected virtual void TrackViewState() {
            _isTrackingViewState = true;
            if (_viewState != null) {
                ((IStateManager)_viewState).TrackViewState();
            }
        }

        #region Implementation of IStateManager
        /// <internalonly/>
        bool IStateManager.IsTrackingViewState {
            get {
                return IsTrackingViewState;
            }
        }

        /// <internalonly/>
        void IStateManager.LoadViewState(object savedState) {
            LoadViewState(savedState);
        }

        /// <internalonly/>
        object IStateManager.SaveViewState() {
            return SaveViewState();
        }

        /// <internalonly/>
        void IStateManager.TrackViewState() {
            TrackViewState();
        }
        #endregion
    }
}