1 //------------------------------------------------------------------------------
2 // <copyright file="AppliedDeviceFilterDialog.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //------------------------------------------------------------------------------
7 namespace System
.Web
.UI
.Design
.MobileControls
10 using System
.Collections
;
11 using System
.Collections
.Specialized
;
12 using System
.ComponentModel
;
13 using System
.ComponentModel
.Design
;
14 using System
.ComponentModel
.Design
.Serialization
;
15 using System
.Diagnostics
;
17 using System
.Drawing
.Design
;
19 using System
.Reflection
;
21 using System
.Windows
.Forms
;
22 using System
.Windows
.Forms
.Design
;
24 using System
.Web
.UI
.MobileControls
;
25 using System
.Web
.UI
.Design
.MobileControls
.Util
;
28 System
.Security
.Permissions
.SecurityPermission(System
.Security
.Permissions
.SecurityAction
.Demand
,
29 Flags
=System
.Security
.Permissions
.SecurityPermissionFlag
.UnmanagedCode
)
31 [Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
32 internal sealed class AppliedDeviceFiltersDialog
:
33 DesignerForm
, IRefreshableDeviceSpecificEditor
35 private bool _isDirty
= true;
36 private IDeviceSpecificDesigner _designer
= null;
37 private WebConfigManager _webConfig
= null;
38 private IDictionary _cachedDeviceSpecifics
=
39 new HybridDictionary(true /* make case-insensitive */ );
40 private String _currentDeviceSpecificID
= null;
42 private System
.Windows
.Forms
.Label _lblAvailableFilters
;
43 private System
.Windows
.Forms
.Button _btnEditFilters
;
44 private System
.Windows
.Forms
.ComboBox _cbAvailableFilters
;
45 private System
.Windows
.Forms
.Button _btnApplyFilter
;
46 private System
.Windows
.Forms
.Button _cmdCancel
;
47 private System
.Windows
.Forms
.Button _cmdOK
;
48 private System
.Windows
.Forms
.Panel _pnlMain
;
49 private System
.Windows
.Forms
.Label _lblArgument
;
50 private System
.Windows
.Forms
.TextBox _tbArgument
;
51 private EditableTreeList _appliedFiltersList
;
53 internal AppliedDeviceFiltersDialog(
54 IDeviceSpecificDesigner designer
,
55 int mergingContext
) : base (designer
.UnderlyingControl
.Site
)
58 _designer
.SetDeviceSpecificEditor(this);
60 // Required for Win Form Designer support
61 InitializeComponent();
63 _lblAvailableFilters
.Text
=
64 SR
.GetString(SR
.AppliedDeviceFiltersDialog_AvailableDeviceFilters
);
65 _appliedFiltersList
.LblTitle
.Text
=
66 SR
.GetString(SR
.AppliedDeviceFiltersDialog_AppliedDeviceFilters
);
67 _btnEditFilters
.Text
= SR
.GetString(SR
.GenericDialog_Edit
);
68 _btnApplyFilter
.Text
=
69 SR
.GetString(SR
.AppliedDeviceFiltersDialog_ApplyDeviceFilter
);
71 SR
.GetString(SR
.AppliedDeviceFiltersDialog_Argument
);
72 _cmdOK
.Text
= SR
.GetString(SR
.GenericDialog_OKBtnCaption
);
73 _cmdCancel
.Text
= SR
.GetString(SR
.GenericDialog_CancelBtnCaption
);
75 int tabOffset
= GenericUI
.InitDialog(
81 this.Text
= _designer
.UnderlyingControl
.ID
82 + " - " + SR
.GetString(SR
.AppliedDeviceFiltersDialog_Title
);
83 SetTabIndexes(tabOffset
);
84 _webConfig
= new WebConfigManager(_designer
.UnderlyingControl
.Site
);
85 LoadAvailableFilters();
87 // Note that the following can cause an
88 // IDeviceSpecificDesigner.Refresh() to occur as a side-effect.
89 _designer
.RefreshHeader(mergingContext
);
91 _currentDeviceSpecificID
= _designer
.CurrentDeviceSpecificID
;
92 if(_currentDeviceSpecificID
!= null)
95 _designer
.GetDeviceSpecific(_currentDeviceSpecificID
, out ds
);
99 // Register Event Handlers
100 _cbAvailableFilters
.SelectedIndexChanged
+= new EventHandler(
101 OnAvailableFilterSelected
103 _cbAvailableFilters
.TextChanged
+= new EventHandler(
104 OnAvailableFilterSelected
106 _btnApplyFilter
.Click
+= new EventHandler(OnApplyFilter
);
107 _btnEditFilters
.Click
+= new EventHandler(OnEditFilters
);
108 _appliedFiltersList
.TvList
.AfterSelect
+= new TreeViewEventHandler(OnAppliedFilterSelected
);
109 _appliedFiltersList
.TvList
.AfterLabelEdit
+= new NodeLabelEditEventHandler(OnAfterLabelEdit
);
110 _appliedFiltersList
.BtnUp
.Click
+= new EventHandler(OnAppliedFiltersReordered
);
111 _appliedFiltersList
.BtnDown
.Click
+= new EventHandler(OnAppliedFiltersReordered
);
112 _appliedFiltersList
.BtnRemove
.Click
-= _appliedFiltersList
.RemoveHandler
;
113 _appliedFiltersList
.BtnRemove
.Click
+= new EventHandler(OnRemove
);
114 _tbArgument
.TextChanged
+= new EventHandler(OnArgumentChanged
);
115 _cmdOK
.Click
+= new EventHandler(OnOK
);
116 _cmdCancel
.Click
+= new EventHandler(OnCancel
);
121 protected override string HelpTopic
{
122 get { return "net.Mobile.AppliedDeviceFiltersDialog"; }
125 internal void SetTabIndexes(int tabOffset
)
127 _pnlMain
.TabIndex
= ++tabOffset
;
128 _lblAvailableFilters
.TabIndex
= ++tabOffset
;
129 _cbAvailableFilters
.TabIndex
= ++tabOffset
;
130 _btnEditFilters
.TabIndex
= ++tabOffset
;
131 _btnApplyFilter
.TabIndex
= ++tabOffset
;
132 _appliedFiltersList
.TabIndex
= ++tabOffset
;
133 _lblArgument
.TabIndex
= ++tabOffset
;
134 _tbArgument
.TabIndex
= ++tabOffset
;
135 _cmdOK
.TabIndex
= ++tabOffset
;
136 _cmdCancel
.TabIndex
= ++tabOffset
;
139 private void InitializeComponent()
141 this._appliedFiltersList
=
142 new System
.Web
.UI
.Design
.MobileControls
.Util
.EditableTreeList(
145 this._btnEditFilters
= new System
.Windows
.Forms
.Button();
146 this._cmdOK
= new System
.Windows
.Forms
.Button();
147 this._pnlMain
= new System
.Windows
.Forms
.Panel();
148 this._tbArgument
= new System
.Windows
.Forms
.TextBox();
149 this._lblArgument
= new System
.Windows
.Forms
.Label();
150 this._cmdCancel
= new System
.Windows
.Forms
.Button();
151 this._lblAvailableFilters
= new System
.Windows
.Forms
.Label();
152 this._cbAvailableFilters
= new System
.Windows
.Forms
.ComboBox();
153 this._btnApplyFilter
= new System
.Windows
.Forms
.Button();
154 this._pnlMain
.SuspendLayout();
155 this.SuspendLayout();
157 // _appliedFiltersList
159 this._appliedFiltersList
.Location
= new System
.Drawing
.Point(0, 74);
160 this._appliedFiltersList
.Name
= "_appliedFiltersList";
161 this._appliedFiltersList
.Size
= new System
.Drawing
.Size(275, 208);
165 this._btnEditFilters
.Location
= new System
.Drawing
.Point(201, 15);
166 this._btnEditFilters
.Size
= new System
.Drawing
.Size(75, 23);
167 this._btnEditFilters
.Name
= "_btnEditFilters";
171 this._cmdOK
.Location
= new System
.Drawing
.Point(120, 334);
172 this._cmdOK
.Name
= "_cmdOK";
176 this._pnlMain
.Anchor
= (System
.Windows
.Forms
.AnchorStyles
.Bottom
| System
.Windows
.Forms
.AnchorStyles
.Left
);
177 this._pnlMain
.Controls
.AddRange(new System
.Windows
.Forms
.Control
[] {
180 this._appliedFiltersList
,
183 this._lblAvailableFilters
,
184 this._btnEditFilters
,
185 this._cbAvailableFilters
,
186 this._btnApplyFilter
});
187 this._pnlMain
.Location
= new System
.Drawing
.Point(6, 8);
188 this._pnlMain
.Name
= "_pnlMain";
189 this._pnlMain
.Size
= new System
.Drawing
.Size(276, 357);
193 this._tbArgument
.Location
= new System
.Drawing
.Point(0, 306);
194 this._tbArgument
.Name
= "_tbArgument";
195 this._tbArgument
.Size
= new System
.Drawing
.Size(275, 20);
196 this._tbArgument
.Text
= String
.Empty
;
200 this._lblArgument
.Location
= new System
.Drawing
.Point(0, 290);
201 this._lblArgument
.Name
= "_lblArgument";
202 this._lblArgument
.Size
= new System
.Drawing
.Size(275, 16);
206 this._cmdCancel
.DialogResult
= System
.Windows
.Forms
.DialogResult
.Cancel
;
207 this._cmdCancel
.Location
= new System
.Drawing
.Point(201, 334);
208 this._cmdCancel
.Name
= "_cmdCancel";
210 // _lblAvailableFilters
212 this._lblAvailableFilters
.Name
= "_lblAvailableFilters";
213 this._lblAvailableFilters
.Size
= new System
.Drawing
.Size(198, 16);
215 // _cbAvailableFilters
217 this._cbAvailableFilters
.DropDownWidth
= 195;
218 this._cbAvailableFilters
.Location
= new System
.Drawing
.Point(0, 16);
219 this._cbAvailableFilters
.Name
= "_cbAvailableFilters";
220 this._cbAvailableFilters
.Size
= new System
.Drawing
.Size(195, 21);
221 this._cbAvailableFilters
.Sorted
= true;
225 this._btnApplyFilter
.Location
= new System
.Drawing
.Point(0, 44);
226 this._btnApplyFilter
.Name
= "_btnApplyFilter";
227 this._btnApplyFilter
.Size
= new System
.Drawing
.Size(195, 23);
229 // AppliedDeviceFiltersDialog
231 this.AcceptButton
= this._cmdOK
;
232 this.AutoScaleBaseSize
= new System
.Drawing
.Size(5, 13);
233 this.CancelButton
= this._cmdCancel
;
234 this.ClientSize
= new System
.Drawing
.Size(285, 373);
235 this.Controls
.AddRange(new System
.Windows
.Forms
.Control
[] {
237 this.Name
= "AppliedDeviceFiltersDialog";
238 this._pnlMain
.ResumeLayout(false);
239 this.ResumeLayout(false);
242 private void LoadAvailableFilters()
244 _cbAvailableFilters
.Items
.Clear();
247 ArrayList filterList
= _webConfig
.ReadDeviceFilters();
248 _cbAvailableFilters
.Sorted
= false;
249 foreach(DeviceFilterNode node
in filterList
)
251 _cbAvailableFilters
.Items
.Add(node
);
256 Debug
.Fail(e
.ToString());
257 // This is okay. They may still apply a default or external
260 _cbAvailableFilters
.Sorted
= true;
261 EnsureDefaultFilterAvailableXorApplied();
263 // If there is no filter selected, or there was a filter selected
264 // but that filter no longer exists
265 if( _cbAvailableFilters
.Text
.Length
== 0
266 || FindAvailableFilter(_cbAvailableFilters
.Text
) == null)
268 SelectFirstAvailableFilter();
272 private void CacheState(String deviceSpecificID
)
274 _cachedDeviceSpecifics
[deviceSpecificID
] = new AppliedFiltersCachedState(
275 _appliedFiltersList
.TvList
279 private void CacheCurrentState()
281 CacheState(_currentDeviceSpecificID
);
284 private bool RestoreState(String deviceSpecificID
)
286 if (null != deviceSpecificID
)
288 _currentDeviceSpecificID
= deviceSpecificID
;
289 AppliedFiltersCachedState state
=
290 (AppliedFiltersCachedState
) _cachedDeviceSpecifics
[
291 _currentDeviceSpecificID
295 state
.Restore(_appliedFiltersList
.TvList
);
296 EnsureDefaultFilterAvailableXorApplied();
302 _currentDeviceSpecificID
= null;
307 private DeviceFilterNode
CreateExternalFilter(String name
)
309 DeviceFilterNode externalFilter
;
310 externalFilter
= new DeviceFilterNode(_webConfig
);
311 externalFilter
.Name
= name
;
312 return externalFilter
;
315 private void LoadChoice(DeviceSpecificChoice runtimeChoice
)
317 DeviceFilterNode filterUsed
=
318 FindAvailableFilter(runtimeChoice
.Filter
);
320 ChoiceTreeNode choice
= new ChoiceTreeNode(
325 _appliedFiltersList
.TvList
.Nodes
.Add(choice
);
328 private void LoadChoices(DeviceSpecific deviceSpecific
)
330 _appliedFiltersList
.TvList
.Nodes
.Clear();
332 if(deviceSpecific
!= null)
334 foreach(DeviceSpecificChoice runtimeChoice
in deviceSpecific
.Choices
)
336 LoadChoice(runtimeChoice
);
339 EnsureDefaultFilterAvailableXorApplied();
342 private void SaveChoices()
344 if(_currentDeviceSpecificID
!= null)
348 foreach (DictionaryEntry entry
in _cachedDeviceSpecifics
)
350 AppliedFiltersCachedState state
=
351 (AppliedFiltersCachedState
) entry
.Value
;
352 state
.SaveChoicesFromTreeView(
359 private void SelectFirstAvailableFilter()
361 if (_cbAvailableFilters
.Items
.Count
> 0)
363 DeviceFilterNode filter
=
364 (DeviceFilterNode
) _cbAvailableFilters
.Items
[0];
365 _cbAvailableFilters
.SelectedItem
= filter
;
369 _cbAvailableFilters
.Text
= String
.Empty
;
373 private void SelectNextAvailableFilter(DeviceFilterNode currentFilter
)
375 // if an externally defined filter is selected, let
376 // SelectFirstAvailableFitler handle this.
377 if(currentFilter
== null)
379 SelectFirstAvailableFilter();
383 int index
= _cbAvailableFilters
.Items
.IndexOf(currentFilter
);
384 if((index
+ 1) < _cbAvailableFilters
.Items
.Count
)
386 _cbAvailableFilters
.SelectedItem
=
387 _cbAvailableFilters
.Items
[index
+ 1];
391 _cbAvailableFilters
.SelectedItem
=
392 _cbAvailableFilters
.Items
[index
- 1];
396 _cbAvailableFilters
.SelectedItem
= null;
397 _cbAvailableFilters
.Text
= String
.Empty
;
401 private DeviceFilterNode
FindAvailableFilter(String name
)
403 if(IsDefaultFilter(name
))
407 foreach(DeviceFilterNode filter
in _cbAvailableFilters
.Items
)
409 if(filter
.Name
== name
)
417 private bool DefaultFilterIsApplied
421 return FindAppliedFilter("") != null;
425 private bool DefaultFilterIsAvailable
429 return FindAvailableFilter("") != null;
433 private ChoiceTreeNode
FindAppliedFilter(String name
)
435 if(IsDefaultFilter(name
))
439 foreach(ChoiceTreeNode choice
in _appliedFiltersList
.TvList
.Nodes
)
441 if(choice
.Name
== name
)
449 private void EnsureDefaultFilterAvailableXorApplied()
451 if(DefaultFilterIsApplied
)
453 DeviceFilterNode filter
= FindAvailableFilter("");
456 RemoveAvailableFilter(filter
);
459 else if(!DefaultFilterIsAvailable
)
461 _cbAvailableFilters
.Items
.Add(CreateExternalFilter(""));
465 private bool IsDefaultFilter(String name
)
470 || name
== SR
.GetString(SR
.DeviceFilter_DefaultChoice
)
474 private bool AvailableFilterIsSelected
478 return _cbAvailableFilters
.Text
!= null &&
479 _cbAvailableFilters
.Text
.Length
> 0;
483 private bool AppliedFilterIsSelected
487 return SelectedAppliedFilter
!= null;
491 private ChoiceTreeNode SelectedAppliedFilter
495 return (ChoiceTreeNode
) _appliedFiltersList
.TvList
.SelectedNode
;
499 private void UpdateUI()
501 if(AppliedFilterIsSelected
502 && !IsDefaultFilter(SelectedAppliedFilter
.Name
))
504 _tbArgument
.Enabled
= true;
505 _tbArgument
.Text
= SelectedAppliedFilter
.Argument
;
509 _tbArgument
.Enabled
= false;
510 _tbArgument
.Text
= String
.Empty
;
512 _btnApplyFilter
.Enabled
=
513 AvailableFilterIsSelected
&& (_designer
.UnderlyingObject
!= null);
514 _cbAvailableFilters
.Enabled
= (_designer
.UnderlyingObject
!= null);
515 _appliedFiltersList
.UpdateButtonsEnabling();
518 private bool ChoiceHasContent(DeviceSpecificChoice runtimeChoice
)
520 return (runtimeChoice
.Contents
.Count
> 0) || runtimeChoice
.HasTemplates
;
523 private void RemoveAvailableFilter(DeviceFilterNode filter
)
525 SelectNextAvailableFilter(filter
);
526 _cbAvailableFilters
.Items
.Remove(filter
);
530 private void SetDirty(bool dirty
)
534 if (false == _isDirty
)
537 _cmdCancel
.Text
= SR
.GetString(SR
.GenericDialog_CancelBtnCaption
);
542 if (true == _isDirty
)
545 _cmdCancel
.Text
= SR
.GetString(SR
.GenericDialog_CloseBtnCaption
);
550 private bool ValidateAppliedFilters()
552 StringCollection duplicateChoices
=
553 DesignerUtility
.GetDuplicateChoiceTreeNodes(
554 _appliedFiltersList
.TvList
.Nodes
556 if(duplicateChoices
.Count
> 0)
558 GenericUI
.ShowWarningMessage(
559 SR
.GetString(SR
.AppliedDeviceFiltersDialog_Title
),
560 SR
.GetString(SR
.AppliedDeviceFiltersDialog_DuplicateChoices
,
561 GenericUI
.BuildCommaDelimitedList(duplicateChoices
))
568 ////////////////////////////////////////////////////////////////////////
569 // Begin Event Handling
570 ////////////////////////////////////////////////////////////////////////
572 private void OnArgumentChanged(Object sender
, EventArgs e
)
574 if(!AppliedFilterIsSelected
)
576 // UpdateUI sets to empty string when no filter selected.
577 Debug
.Assert(_tbArgument
.Text
.Length
== 0,
578 "Not a side effect of clearing the argument. "
579 + "Arugment changed with no applied filter selected. "
580 + "Missing a call to UpdateUI()?");
583 SelectedAppliedFilter
.Argument
= _tbArgument
.Text
;
587 private void OnAfterLabelEdit(Object sender
, NodeLabelEditEventArgs e
)
589 // null still returned if label unmodified (verified 2310)
595 String oldLabel
= e
.Node
.Text
;
596 String newLabel
= e
.Label
;
598 bool labelIsLegal
= true;
600 if(!DeviceFilterEditorDialog
.NewLabelIsLegal(
601 _designer
.UnderlyingControl
.Site
,
605 SR
.GetString(SR
.AppliedDeviceFiltersDialog_Title
)
607 labelIsLegal
= false;
609 else if(IsDefaultFilter(newLabel
))
611 GenericUI
.ShowWarningMessage(
612 SR
.GetString(SR
.AppliedDeviceFiltersDialog_Title
),
613 SR
.GetString(SR
.DeviceFilterEditorDialog_IllegalDefaultName
)
615 labelIsLegal
= false;
624 ((ChoiceTreeNode
)e
.Node
).Name
= newLabel
;
625 EnsureDefaultFilterAvailableXorApplied();
630 private void OnAvailableFilterSelected(Object sender
, EventArgs e
)
632 // NOTE: This event handler is registed for both ItemSelected and
633 // TextChanged events of _cbAvailableFilters.
637 private void OnAppliedFilterSelected(Object sender
, TreeViewEventArgs e
)
642 private void OnEditFilters(Object sender
, EventArgs e
)
644 if(!ValidateAppliedFilters())
648 DeviceFilterEditorDialog dialog
= null;
654 dialog
= new DeviceFilterEditorDialog(
655 _designer
.UnderlyingControl
.Site
,
659 catch (TargetInvocationException ex
)
661 throw ex
.InnerException
;
664 catch (CheckoutException ex
)
666 if (ex
== CheckoutException
.Canceled
)
672 catch (FileLoadException
)
674 // This is how the constructor tells us it failed to read
679 if(AvailableFilterIsSelected
)
681 dialog
.SelectFilterByName(_cbAvailableFilters
.Text
);
683 if (dialog
.ShowDialog() == DialogResult
.OK
)
685 Cursor oldCursor
= null;
688 oldCursor
= this.Cursor
;
689 this.Cursor
= Cursors
.WaitCursor
;
692 // if (_currentDeviceSpecificID != null)
694 LoadAvailableFilters();
701 this.Cursor
= oldCursor
;
706 private void OnApplyFilter(Object sender
, EventArgs e
)
708 DeviceFilterNode filter
= (DeviceFilterNode
) _cbAvailableFilters
.SelectedItem
;
711 String name
= _cbAvailableFilters
.Text
;
713 ((name
!= null) && (name
.Length
> 0)),
714 "Should not be trying to apply a filter with none selected. "
715 + "Missed a call to UpdateUI()?"
718 // If the user typed the name of a filter which exists in their
719 // web.config, we need to find the original rather than create
720 // a new external filter.
721 filter
= FindAvailableFilter(name
);
724 /* Removed for DCR 4240
725 if (!DesignerUtility.IsValidName(name))
727 GenericUI.ShowWarningMessage(
728 SR.GetString(SR.AppliedDeviceFiltersDialog_Title),
730 SR.AppliedDeviceFiltersDialog_InvalidFilterName,
731 _cbAvailableFilters.Text
738 filter
= CreateExternalFilter(_cbAvailableFilters
.Text
);
741 ChoiceTreeNode choice
= new ChoiceTreeNode(
745 if(IsDefaultFilter(filter
.Name
))
747 if(DefaultFilterIsApplied
)
749 // Do not allow user to apply default filter if already
751 GenericUI
.ShowWarningMessage(
752 SR
.GetString(SR
.AppliedDeviceFiltersDialog_Title
),
753 SR
.GetString(SR
.AppliedDeviceFiltersDialog_DefaultFilterAlreadyApplied
)
758 // Add the default filter to the end of the list and
759 // remove it from list of available filters.
760 _appliedFiltersList
.TvList
.Nodes
.Add(choice
);
761 RemoveAvailableFilter(filter
);
766 // All other filters are added to the beginning
767 _appliedFiltersList
.TvList
.Nodes
.Insert(0, choice
);
773 private void OnAppliedFiltersReordered(Object sender
, EventArgs e
)
778 private void OnRemove(Object sender
, EventArgs e
)
780 ChoiceTreeNode choice
= (ChoiceTreeNode
) _appliedFiltersList
.TvList
.SelectedNode
;
781 if(ChoiceHasContent(choice
.RuntimeChoice
))
783 if(!GenericUI
.ConfirmYesNo(
784 SR
.GetString(SR
.AppliedDeviceFiltersDialog_Title
),
786 SR
.AppliedDeviceFiltersDialog_AssociatedItemsWillBeLost
792 _appliedFiltersList
.TvList
.Nodes
.Remove(_appliedFiltersList
.TvList
.SelectedNode
);
794 // If it was the default filter, and it a duplicate is not still
795 // still applied (error in HTML view), return it to the list of
796 // available filters.
797 if(IsDefaultFilter(choice
.Name
))
799 EnsureDefaultFilterAvailableXorApplied();
801 _appliedFiltersList
.UpdateButtonsEnabling();
806 private void OnOK(Object sender
, EventArgs e
)
808 if(!ValidateAppliedFilters())
814 DialogResult
= DialogResult
.OK
;
817 private void OnCancel(Object sender
, EventArgs e
)
820 DialogResult
= DialogResult
.Cancel
;
823 ////////////////////////////////////////////////////////////////////////
824 // End Event Handling
825 ////////////////////////////////////////////////////////////////////////
827 ////////////////////////////////////////////////////////////////////////
828 // Begin IRefreshableDeviceSpecificEditor Implementation
829 ////////////////////////////////////////////////////////////////////////
831 bool IRefreshableDeviceSpecificEditor
.RequestRefresh()
833 return ValidateAppliedFilters();
836 void IRefreshableDeviceSpecificEditor
.Refresh(
837 String deviceSpecificID
,
838 DeviceSpecific deviceSpecific
840 if (_currentDeviceSpecificID
!= null)
844 if(!RestoreState(deviceSpecificID
))
846 // If we could not restore the state, we have not edited
847 // this DeviceSpecific yet and need to load choices.
848 LoadChoices(deviceSpecific
);
853 void IRefreshableDeviceSpecificEditor
.UnderlyingObjectsChanged()
859 private bool InExternalCacheEditMode
863 return _cacheBuffer
!= null;
867 private IDictionary _cacheBuffer
= null;
869 void IRefreshableDeviceSpecificEditor
.BeginExternalDeviceSpecificEdit()
871 Debug
.Assert(!InExternalCacheEditMode
,
872 "Call to BeginExternalDeviceSpecificEdit() while already in external "
873 + "cache edit mode.");
874 if(_currentDeviceSpecificID
!= null)
877 _currentDeviceSpecificID
= null;
879 _cacheBuffer
= new HybridDictionary(
880 true /* make case-insensitive*/ );
881 foreach(DictionaryEntry entry
in _cachedDeviceSpecifics
)
883 _cacheBuffer
.Add(entry
.Key
, entry
.Value
);
887 void IRefreshableDeviceSpecificEditor
.EndExternalDeviceSpecificEdit(
890 Debug
.Assert(InExternalCacheEditMode
,
891 "Call to EndExternalDeviceSpecificEdit() while not in external "
892 + "cache edit mode.");
895 _cachedDeviceSpecifics
= _cacheBuffer
;
900 void IRefreshableDeviceSpecificEditor
.DeviceSpecificRenamed(
901 String oldDeviceSpecificID
, String newDeviceSpecificID
)
903 Debug
.Assert(InExternalCacheEditMode
,
904 "Call to DeviceSpecificRenamed() while not in external "
905 + "cache edit mode.");
906 Object
value = _cacheBuffer
[oldDeviceSpecificID
];
909 _cacheBuffer
.Remove(oldDeviceSpecificID
);
910 _cacheBuffer
.Add(newDeviceSpecificID
, value);
914 void IRefreshableDeviceSpecificEditor
.DeviceSpecificDeleted(
915 String deviceSpecificID
)
917 Debug
.Assert(InExternalCacheEditMode
,
918 "Call to DeviceSpecificDeleted() while not in external "
919 + "cache edit mode.");
920 _cacheBuffer
.Remove(deviceSpecificID
);
923 ////////////////////////////////////////////////////////////////////////
924 // End IRefeshableComponentEditorPage Implementation
925 ////////////////////////////////////////////////////////////////////////
928 ////////////////////////////////////////////////////////////////////////////
929 // Begin Internal Class
930 ////////////////////////////////////////////////////////////////////////////
933 System
.Security
.Permissions
.SecurityPermission(System
.Security
.Permissions
.SecurityAction
.Demand
,
934 Flags
=System
.Security
.Permissions
.SecurityPermissionFlag
.UnmanagedCode
)
936 [Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
937 internal class AppliedFiltersCachedState
: DeviceSpecificDialogCachedState
939 private TreeNode
[] _cachedTreeView
= null;
941 internal AppliedFiltersCachedState(
944 _cachedTreeView
= new TreeNode
[treeView
.Nodes
.Count
];
945 treeView
.Nodes
.CopyTo(_cachedTreeView
, 0);
948 internal TreeNode
[] AppliedFilters
952 return _cachedTreeView
;
956 internal void Restore(
959 TreeNode selectedNode
= treeView
.SelectedNode
;
960 treeView
.Nodes
.Clear();
961 treeView
.Nodes
.AddRange(_cachedTreeView
);
962 if(selectedNode
!= null)
964 int index
= treeView
.Nodes
.IndexOf(selectedNode
);
967 treeView
.SelectedNode
= treeView
.Nodes
[index
];
972 internal bool ChoiceExistsInTreeView(DeviceFilterNode filter
)
974 foreach(ChoiceTreeNode appliedFilter
in _cachedTreeView
)
976 if(appliedFilter
.Name
== filter
.Name
)
984 internal void SaveChoicesFromTreeView(
985 IDeviceSpecificDesigner designer
,
986 String deviceSpecificID
988 SaveChoices(designer
, deviceSpecificID
, _cachedTreeView
);
992 ////////////////////////////////////////////////////////////////////////////
993 // End Internal Class
994 ////////////////////////////////////////////////////////////////////////////
996 ////////////////////////////////////////////////////////////////////////////
997 // Begin Internal Class
998 ////////////////////////////////////////////////////////////////////////////
1001 System
.Security
.Permissions
.SecurityPermission(System
.Security
.Permissions
.SecurityAction
.Demand
,
1002 Flags
=System
.Security
.Permissions
.SecurityPermissionFlag
.UnmanagedCode
)
1004 [Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
1005 internal class ChoiceTreeNode
: TreeNode
1007 private IDeviceSpecificDesigner _designer
;
1008 private ChoicePropertyFilter _choicePropertyFilter
= null;
1009 private DeviceSpecificChoice _runtimeChoice
= null;
1010 private String _filterName
;
1011 private String _argument
;
1012 private bool _includeArgument
= false;
1014 internal ChoiceTreeNode(
1015 DeviceFilterNode filter
,
1016 IDeviceSpecificDesigner designer
1020 _designer
= designer
;
1021 _runtimeChoice
= new DeviceSpecificChoice();
1022 _runtimeChoice
.Filter
= filter
.Name
;
1025 // This looks like circular reasoning, but the designer is a
1026 // IDeviceSpecificDesigner and we are interested in the
1027 // type of the designer's parent control.
1028 Adapters
.DesignerAdapterUtil
.ControlDesigner(designer
.UnderlyingControl
)
1029 is MobileTemplatedControlDesigner
1032 _runtimeChoice
.Xmlns
= SR
.GetString(SR
.MarkupSchema_HTML32
);
1036 internal ChoiceTreeNode(
1037 DeviceFilterNode filter
,
1038 DeviceSpecificChoice runtimeChoice
,
1039 IDeviceSpecificDesigner designer
1042 _designer
= designer
;
1043 _runtimeChoice
= runtimeChoice
;
1044 Name
= _runtimeChoice
.Filter
;
1045 Argument
= _runtimeChoice
.Argument
;
1048 internal bool IncludeArgument
1052 return _includeArgument
;
1057 _includeArgument
= value;
1061 internal new String Name
1070 Debug
.Assert(value != null);
1071 _filterName
= value;
1072 base.Text
= ToString();
1076 internal String Argument
1089 internal ChoicePropertyFilter Choice
1093 if(_choicePropertyFilter
== null)
1095 _choicePropertyFilter
= new ChoicePropertyFilter(
1098 _designer
.UnderlyingControl
.Site
1101 return _choicePropertyFilter
;
1105 internal void CommitChanges()
1107 RuntimeChoice
.Filter
= _filterName
;
1108 RuntimeChoice
.Argument
= _argument
;
1111 internal DeviceSpecificChoice RuntimeChoice
1116 (_choicePropertyFilter
== null)
1117 || (_runtimeChoice
== _choicePropertyFilter
.RuntimeChoice
),
1118 "Local runtime choice object out of sync."
1120 return _runtimeChoice
;
1124 // This done so that these TreeNodes will display correctly when
1125 // inserted in a ComboBox.
1126 public override String
ToString()
1128 StringBuilder name
= new StringBuilder(_filterName
);
1130 if(name
== null || name
.Length
== 0)
1132 name
= new StringBuilder(
1133 SR
.GetString(SR
.DeviceFilter_DefaultChoice
)
1136 else if(_includeArgument
)
1138 name
.Append( " (\"" + _runtimeChoice
.Argument
+ "\")" );
1140 return name
.ToString();
1144 ////////////////////////////////////////////////////////////////////////////
1145 // End Internal Class
1146 ////////////////////////////////////////////////////////////////////////////