Updates referencesource to .NET 4.7
[mono-project.git] / mcs / class / referencesource / System.Web.Mobile / UI / MobileControls / Design / AppliedDeviceFiltersDialog.cs
blob36cd8f5632fa6e30015b6cf2997fc8d7483c3937
1 //------------------------------------------------------------------------------
2 // <copyright file="AppliedDeviceFilterDialog.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 // </copyright>
5 //------------------------------------------------------------------------------
7 namespace System.Web.UI.Design.MobileControls
9 using System;
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;
16 using System.Drawing;
17 using System.Drawing.Design;
18 using System.IO;
19 using System.Reflection;
20 using System.Text;
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)
57 _designer = designer;
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);
70 _lblArgument.Text =
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(
76 this,
77 _designer,
78 mergingContext
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)
94 DeviceSpecific ds;
95 _designer.GetDeviceSpecific(_currentDeviceSpecificID, out ds);
96 LoadChoices(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);
118 UpdateUI();
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(
143 false, true, 16
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);
163 // _btnEditFilters
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";
169 // _cmdOK
171 this._cmdOK.Location = new System.Drawing.Point(120, 334);
172 this._cmdOK.Name = "_cmdOK";
174 // _pnlMain
176 this._pnlMain.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
177 this._pnlMain.Controls.AddRange(new System.Windows.Forms.Control[] {
178 this._tbArgument,
179 this._lblArgument,
180 this._appliedFiltersList,
181 this._cmdCancel,
182 this._cmdOK,
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);
191 // _tbArgument
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;
198 // _lblArgument
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);
204 // _cmdCancel
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;
223 // _btnApplyFilter
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[] {
236 this._pnlMain});
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);
254 catch (Exception e)
256 Debug.Fail(e.ToString());
257 // This is okay. They may still apply a default or external
258 // device filter.
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
293 if(state != null)
295 state.Restore(_appliedFiltersList.TvList);
296 EnsureDefaultFilterAvailableXorApplied();
297 return true;
300 else
302 _currentDeviceSpecificID = null;
304 return false;
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(
321 filterUsed,
322 runtimeChoice,
323 _designer
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)
346 CacheCurrentState();
348 foreach (DictionaryEntry entry in _cachedDeviceSpecifics)
350 AppliedFiltersCachedState state =
351 (AppliedFiltersCachedState) entry.Value;
352 state.SaveChoicesFromTreeView(
353 _designer,
354 (String) entry.Key
359 private void SelectFirstAvailableFilter()
361 if (_cbAvailableFilters.Items.Count > 0)
363 DeviceFilterNode filter =
364 (DeviceFilterNode) _cbAvailableFilters.Items[0];
365 _cbAvailableFilters.SelectedItem = filter;
367 else
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();
380 return;
383 int index = _cbAvailableFilters.Items.IndexOf(currentFilter);
384 if((index + 1) < _cbAvailableFilters.Items.Count)
386 _cbAvailableFilters.SelectedItem =
387 _cbAvailableFilters.Items[index + 1];
389 else if(index > 0)
391 _cbAvailableFilters.SelectedItem =
392 _cbAvailableFilters.Items[index - 1];
394 else
396 _cbAvailableFilters.SelectedItem = null;
397 _cbAvailableFilters.Text = String.Empty;
401 private DeviceFilterNode FindAvailableFilter(String name)
403 if(IsDefaultFilter(name))
405 name = "";
407 foreach(DeviceFilterNode filter in _cbAvailableFilters.Items)
409 if(filter.Name == name)
411 return filter;
414 return null;
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))
437 name = "";
439 foreach(ChoiceTreeNode choice in _appliedFiltersList.TvList.Nodes)
441 if(choice.Name == name)
443 return choice;
446 return null;
449 private void EnsureDefaultFilterAvailableXorApplied()
451 if(DefaultFilterIsApplied)
453 DeviceFilterNode filter = FindAvailableFilter("");
454 if(filter != null)
456 RemoveAvailableFilter(filter);
459 else if(!DefaultFilterIsAvailable)
461 _cbAvailableFilters.Items.Add(CreateExternalFilter(""));
465 private bool IsDefaultFilter(String name)
467 return(
468 name == null
469 || name.Length == 0
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;
507 else
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);
527 UpdateUI();
530 private void SetDirty(bool dirty)
532 if (dirty)
534 if (false == _isDirty)
536 _isDirty = true;
537 _cmdCancel.Text = SR.GetString(SR.GenericDialog_CancelBtnCaption);
540 else
542 if (true == _isDirty)
544 _isDirty = false;
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))
563 return false;
565 return true;
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()?");
581 return;
583 SelectedAppliedFilter.Argument = _tbArgument.Text;
584 SetDirty(true);
587 private void OnAfterLabelEdit(Object sender, NodeLabelEditEventArgs e)
589 // null still returned if label unmodified (verified 2310)
590 if(e.Label == null)
592 return;
595 String oldLabel = e.Node.Text;
596 String newLabel = e.Label;
598 bool labelIsLegal = true;
600 if(!DeviceFilterEditorDialog.NewLabelIsLegal(
601 _designer.UnderlyingControl.Site,
602 _appliedFiltersList,
603 oldLabel,
604 newLabel,
605 SR.GetString(SR.AppliedDeviceFiltersDialog_Title)
606 )) {
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;
618 if(!labelIsLegal)
620 e.CancelEdit = true;
621 return;
624 ((ChoiceTreeNode)e.Node).Name = newLabel;
625 EnsureDefaultFilterAvailableXorApplied();
626 SetDirty(true);
627 UpdateUI();
630 private void OnAvailableFilterSelected(Object sender, EventArgs e)
632 // NOTE: This event handler is registed for both ItemSelected and
633 // TextChanged events of _cbAvailableFilters.
634 UpdateUI();
637 private void OnAppliedFilterSelected(Object sender, TreeViewEventArgs e)
639 UpdateUI();
642 private void OnEditFilters(Object sender, EventArgs e)
644 if(!ValidateAppliedFilters())
646 return;
648 DeviceFilterEditorDialog dialog = null;
654 dialog = new DeviceFilterEditorDialog(
655 _designer.UnderlyingControl.Site,
656 _webConfig
659 catch (TargetInvocationException ex)
661 throw ex.InnerException;
664 catch (CheckoutException ex)
666 if (ex == CheckoutException.Canceled)
668 return;
670 throw;
672 catch (FileLoadException)
674 // This is how the constructor tells us it failed to read
675 // web.config.
676 return;
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;
691 // Fix for # 4667
692 // if (_currentDeviceSpecificID != null)
694 LoadAvailableFilters();
696 SaveChoices();
697 SetDirty(false);
699 finally
701 this.Cursor = oldCursor;
706 private void OnApplyFilter(Object sender, EventArgs e)
708 DeviceFilterNode filter = (DeviceFilterNode) _cbAvailableFilters.SelectedItem;
709 if(filter == null)
711 String name = _cbAvailableFilters.Text;
712 Debug.Assert(
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);
722 if(filter == null)
724 /* Removed for DCR 4240
725 if (!DesignerUtility.IsValidName(name))
727 GenericUI.ShowWarningMessage(
728 SR.GetString(SR.AppliedDeviceFiltersDialog_Title),
729 SR.GetString(
730 SR.AppliedDeviceFiltersDialog_InvalidFilterName,
731 _cbAvailableFilters.Text
734 return;
738 filter = CreateExternalFilter(_cbAvailableFilters.Text);
741 ChoiceTreeNode choice = new ChoiceTreeNode(
742 filter,
743 _designer
745 if(IsDefaultFilter(filter.Name))
747 if(DefaultFilterIsApplied)
749 // Do not allow user to apply default filter if already
750 // been applied.
751 GenericUI.ShowWarningMessage(
752 SR.GetString(SR.AppliedDeviceFiltersDialog_Title),
753 SR.GetString(SR.AppliedDeviceFiltersDialog_DefaultFilterAlreadyApplied)
756 else
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);
764 else
766 // All other filters are added to the beginning
767 _appliedFiltersList.TvList.Nodes.Insert(0, choice);
769 SetDirty(true);
770 UpdateUI();
773 private void OnAppliedFiltersReordered(Object sender, EventArgs e)
775 SetDirty(true);
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),
785 SR.GetString(
786 SR.AppliedDeviceFiltersDialog_AssociatedItemsWillBeLost
788 )) {
789 return;
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();
802 SetDirty(true);
803 UpdateUI();
806 private void OnOK(Object sender, EventArgs e)
808 if(!ValidateAppliedFilters())
810 return;
812 SaveChoices();
813 Close();
814 DialogResult = DialogResult.OK;
817 private void OnCancel(Object sender, EventArgs e)
819 Close();
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)
842 CacheCurrentState();
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);
850 UpdateUI();
853 void IRefreshableDeviceSpecificEditor.UnderlyingObjectsChanged()
855 SaveChoices();
856 SetDirty(false);
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)
876 CacheCurrentState();
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(
888 bool commitChanges)
890 Debug.Assert(InExternalCacheEditMode,
891 "Call to EndExternalDeviceSpecificEdit() while not in external "
892 + "cache edit mode.");
893 if(commitChanges)
895 _cachedDeviceSpecifics = _cacheBuffer;
897 _cacheBuffer = null;
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];
907 if(value != null)
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(
942 TreeView treeView
944 _cachedTreeView = new TreeNode[treeView.Nodes.Count];
945 treeView.Nodes.CopyTo(_cachedTreeView, 0);
948 internal TreeNode[] AppliedFilters
952 return _cachedTreeView;
956 internal void Restore(
957 TreeView treeView
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);
965 if(index >= 0)
967 treeView.SelectedNode = treeView.Nodes[index];
972 internal bool ChoiceExistsInTreeView(DeviceFilterNode filter)
974 foreach(ChoiceTreeNode appliedFilter in _cachedTreeView)
976 if(appliedFilter.Name == filter.Name)
978 return true;
981 return false;
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
1017 ) : base()
1019 Name = filter.Name;
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
1040 ) : base()
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
1065 return _filterName;
1070 Debug.Assert(value != null);
1071 _filterName = value;
1072 base.Text = ToString();
1076 internal String Argument
1080 return _argument;
1085 _argument = value;
1089 internal ChoicePropertyFilter Choice
1093 if(_choicePropertyFilter == null)
1095 _choicePropertyFilter = new ChoicePropertyFilter(
1096 _runtimeChoice,
1097 _designer,
1098 _designer.UnderlyingControl.Site
1101 return _choicePropertyFilter;
1105 internal void CommitChanges()
1107 RuntimeChoice.Filter = _filterName;
1108 RuntimeChoice.Argument = _argument;
1111 internal DeviceSpecificChoice RuntimeChoice
1115 Debug.Assert(
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 ////////////////////////////////////////////////////////////////////////////