Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / System / Windows / Controls / CustomDictionarySources.cs / 1305600 / CustomDictionarySources.cs
//---------------------------------------------------------------------------- // // File: CustomDictionarySources.cs // // Copyright (C) Microsoft Corporation. All rights reserved. // // Description: Collection of Uri objects used to specify location of custom dictionaries. // //--------------------------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Text; using System.Windows.Markup; using System.Windows.Navigation; using System.Windows.Controls.Primitives; using System.Windows.Documents; namespace System.Windows.Controls { ////// Collection of ///objects representing local file system or UNC paths. /// Methods that modify the collection also call into Speller callbakcs to notify about the change, so Speller /// could load/unload appropriate dicitonary files. /// /// Implements IList interface with 1 restriction - does not allow double addition of same item to /// the collection. /// For all methods (except Inser) that modify the collection behavior is to ignore add/set request, /// but still notify the Speller. /// In case of Insert an exception is thrown if the item already exists in the collection. /// /// There is a restriction on kinds of supported Uri objects, which is enforced in internal class CustomDictionarySources : IListmethod. /// Refer to this method for supported types of URIs. /// , IList { //----------------------------------------------------- // // Constructors // //----------------------------------------------------- #region constructors internal CustomDictionarySources(TextBoxBase owner) { _owner = owner; _uriList = new List (); } #endregion constructors //------------------------------------------------------ // // Interface implementations // //----------------------------------------------------- #region Interface implementations #region IEnumerable Members public IEnumerator GetEnumerator() { return _uriList.GetEnumerator(); } #endregion #region IEnumerable Members IEnumerator IEnumerable.GetEnumerator() { return _uriList.GetEnumerator(); } #endregion #endregion Interface implementations #region IList Members int IList .IndexOf(Uri item) { return _uriList.IndexOf(item); } /// /// Implementation of Insert method. A restriction added by this implementation is that /// it will throw exception if the item was already added previously. /// This is to avoid ambiguity in respect to the expected position (index) of the inserted item. /// Caller will have to check first if item was already added. /// /// /// void IList.Insert(int index, Uri item) { if (_uriList.Contains(item)) { throw new ArgumentException(SR.Get(SRID.CustomDictionaryItemAlreadyExists), "item"); } ValidateUri(item); _uriList.Insert(index, item); if (Speller != null) { Speller.OnDictionaryUriAdded(item); } } void IList .RemoveAt(int index) { Uri uri = _uriList[index]; _uriList.RemoveAt(index); if (Speller != null) { Speller.OnDictionaryUriRemoved(uri); } } /// /// Sets value at specified index. /// Speller is notified that value at the index is being replaced, which means /// current value at given offset is removed, and new value is added at the same index. /// /// ///Uri IList .this[int index] { get { return _uriList[index]; } set { ValidateUri(value); Uri oldUri = _uriList[index]; if (Speller != null) { Speller.OnDictionaryUriRemoved(oldUri); } _uriList[index] = value; if (Speller != null) { Speller.OnDictionaryUriAdded(value); } } } #endregion #region ICollection Members /// /// Adds new item to the internal collection. /// Duplicate items ARE NOT added, but Speller is still notified. /// /// void ICollection.Add(Uri item) { ValidateUri(item); if (!_uriList.Contains(item)) { _uriList.Add(item); } if (Speller != null) { Speller.OnDictionaryUriAdded(item); } } void ICollection .Clear() { _uriList.Clear(); if (Speller != null) { Speller.OnDictionaryUriCollectionCleared(); } } bool ICollection .Contains(Uri item) { return _uriList.Contains(item); } void ICollection .CopyTo(Uri[] array, int arrayIndex) { _uriList.CopyTo(array, arrayIndex); } int ICollection .Count { get { return _uriList.Count; } } bool ICollection .IsReadOnly { get { return ((ICollection )_uriList).IsReadOnly; } } bool ICollection .Remove(Uri item) { bool removed = _uriList.Remove(item); if (removed && (Speller != null)) { Speller.OnDictionaryUriRemoved(item); } return removed; } #endregion #region IList Members /// /// See generic IList'Uri implementation notes. /// /// ///int IList.Add(object value) { ((IList )this).Add((Uri)value); return _uriList.IndexOf((Uri)value); } void IList.Clear() { ((IList )this).Clear(); } bool IList.Contains(object value) { return ((IList)_uriList).Contains(value); } int IList.IndexOf(object value) { return ((IList)_uriList).IndexOf(value); } void IList.Insert(int index, object value) { ((IList )this).Insert(index, (Uri)value); } bool IList.IsFixedSize { get { return ((IList)_uriList).IsFixedSize; } } bool IList.IsReadOnly { get { return ((IList)_uriList).IsReadOnly; } } void IList.Remove(object value) { ((IList )this).Remove((Uri)value); } void IList.RemoveAt(int index) { ((IList )this).RemoveAt(index); } object IList.this[int index] { get { return _uriList[index]; } set { ((IList )this)[index] = (Uri)value; } } #endregion #region ICollection Members void ICollection.CopyTo(Array array, int index) { ((ICollection)_uriList).CopyTo(array, index); } int ICollection.Count { get { return ((IList )this).Count; } } bool ICollection.IsSynchronized { get { return ((ICollection)_uriList).IsSynchronized; } } object ICollection.SyncRoot { get { return ((ICollection)_uriList).SyncRoot; } } #endregion //------------------------------------------------------ // // Private Properties // //------------------------------------------------------ #region Private Properties private Speller Speller { get { if (_owner.TextEditor == null) { return null; } return _owner.TextEditor.Speller; } } #endregion Private Properties //----------------------------------------------------- // // Private Methods // //------------------------------------------------------ #region Private Methods /// /// Makes sure Uri is of supported kind. Throws exception for unsupported URI type. /// Supported URI types [please keep this list updated] /// 1. Local path /// 2. Relative path /// 3. UNC path /// 4. Pack URI /// /// private static void ValidateUri(Uri item) { if (item == null) { throw new ArgumentException(SR.Get(SRID.CustomDictionaryNullItem)); } if (item.IsAbsoluteUri) { if (!(item.IsUnc || item.IsFile || System.IO.Packaging.PackUriHelper.IsPackUri(item))) { throw new NotSupportedException(SR.Get(SRID.CustomDictionarySourcesUnsupportedURI)); } } } #endregion Private Methods //----------------------------------------------------- // // Private Fields // //----------------------------------------------------- #region Private Fields private readonly List_uriList; private readonly TextBoxBase _owner; #endregion Private Fields } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //---------------------------------------------------------------------------- // // File: CustomDictionarySources.cs // // Copyright (C) Microsoft Corporation. All rights reserved. // // Description: Collection of Uri objects used to specify location of custom dictionaries. // //--------------------------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Text; using System.Windows.Markup; using System.Windows.Navigation; using System.Windows.Controls.Primitives; using System.Windows.Documents; namespace System.Windows.Controls { /// /// Collection of ///objects representing local file system or UNC paths. /// Methods that modify the collection also call into Speller callbakcs to notify about the change, so Speller /// could load/unload appropriate dicitonary files. /// /// Implements IList interface with 1 restriction - does not allow double addition of same item to /// the collection. /// For all methods (except Inser) that modify the collection behavior is to ignore add/set request, /// but still notify the Speller. /// In case of Insert an exception is thrown if the item already exists in the collection. /// /// There is a restriction on kinds of supported Uri objects, which is enforced in internal class CustomDictionarySources : IListmethod. /// Refer to this method for supported types of URIs. /// , IList { //----------------------------------------------------- // // Constructors // //----------------------------------------------------- #region constructors internal CustomDictionarySources(TextBoxBase owner) { _owner = owner; _uriList = new List (); } #endregion constructors //------------------------------------------------------ // // Interface implementations // //----------------------------------------------------- #region Interface implementations #region IEnumerable Members public IEnumerator GetEnumerator() { return _uriList.GetEnumerator(); } #endregion #region IEnumerable Members IEnumerator IEnumerable.GetEnumerator() { return _uriList.GetEnumerator(); } #endregion #endregion Interface implementations #region IList Members int IList .IndexOf(Uri item) { return _uriList.IndexOf(item); } /// /// Implementation of Insert method. A restriction added by this implementation is that /// it will throw exception if the item was already added previously. /// This is to avoid ambiguity in respect to the expected position (index) of the inserted item. /// Caller will have to check first if item was already added. /// /// /// void IList.Insert(int index, Uri item) { if (_uriList.Contains(item)) { throw new ArgumentException(SR.Get(SRID.CustomDictionaryItemAlreadyExists), "item"); } ValidateUri(item); _uriList.Insert(index, item); if (Speller != null) { Speller.OnDictionaryUriAdded(item); } } void IList .RemoveAt(int index) { Uri uri = _uriList[index]; _uriList.RemoveAt(index); if (Speller != null) { Speller.OnDictionaryUriRemoved(uri); } } /// /// Sets value at specified index. /// Speller is notified that value at the index is being replaced, which means /// current value at given offset is removed, and new value is added at the same index. /// /// ///Uri IList .this[int index] { get { return _uriList[index]; } set { ValidateUri(value); Uri oldUri = _uriList[index]; if (Speller != null) { Speller.OnDictionaryUriRemoved(oldUri); } _uriList[index] = value; if (Speller != null) { Speller.OnDictionaryUriAdded(value); } } } #endregion #region ICollection Members /// /// Adds new item to the internal collection. /// Duplicate items ARE NOT added, but Speller is still notified. /// /// void ICollection.Add(Uri item) { ValidateUri(item); if (!_uriList.Contains(item)) { _uriList.Add(item); } if (Speller != null) { Speller.OnDictionaryUriAdded(item); } } void ICollection .Clear() { _uriList.Clear(); if (Speller != null) { Speller.OnDictionaryUriCollectionCleared(); } } bool ICollection .Contains(Uri item) { return _uriList.Contains(item); } void ICollection .CopyTo(Uri[] array, int arrayIndex) { _uriList.CopyTo(array, arrayIndex); } int ICollection .Count { get { return _uriList.Count; } } bool ICollection .IsReadOnly { get { return ((ICollection )_uriList).IsReadOnly; } } bool ICollection .Remove(Uri item) { bool removed = _uriList.Remove(item); if (removed && (Speller != null)) { Speller.OnDictionaryUriRemoved(item); } return removed; } #endregion #region IList Members /// /// See generic IList'Uri implementation notes. /// /// ///int IList.Add(object value) { ((IList )this).Add((Uri)value); return _uriList.IndexOf((Uri)value); } void IList.Clear() { ((IList )this).Clear(); } bool IList.Contains(object value) { return ((IList)_uriList).Contains(value); } int IList.IndexOf(object value) { return ((IList)_uriList).IndexOf(value); } void IList.Insert(int index, object value) { ((IList )this).Insert(index, (Uri)value); } bool IList.IsFixedSize { get { return ((IList)_uriList).IsFixedSize; } } bool IList.IsReadOnly { get { return ((IList)_uriList).IsReadOnly; } } void IList.Remove(object value) { ((IList )this).Remove((Uri)value); } void IList.RemoveAt(int index) { ((IList )this).RemoveAt(index); } object IList.this[int index] { get { return _uriList[index]; } set { ((IList )this)[index] = (Uri)value; } } #endregion #region ICollection Members void ICollection.CopyTo(Array array, int index) { ((ICollection)_uriList).CopyTo(array, index); } int ICollection.Count { get { return ((IList )this).Count; } } bool ICollection.IsSynchronized { get { return ((ICollection)_uriList).IsSynchronized; } } object ICollection.SyncRoot { get { return ((ICollection)_uriList).SyncRoot; } } #endregion //------------------------------------------------------ // // Private Properties // //------------------------------------------------------ #region Private Properties private Speller Speller { get { if (_owner.TextEditor == null) { return null; } return _owner.TextEditor.Speller; } } #endregion Private Properties //----------------------------------------------------- // // Private Methods // //------------------------------------------------------ #region Private Methods /// /// Makes sure Uri is of supported kind. Throws exception for unsupported URI type. /// Supported URI types [please keep this list updated] /// 1. Local path /// 2. Relative path /// 3. UNC path /// 4. Pack URI /// /// private static void ValidateUri(Uri item) { if (item == null) { throw new ArgumentException(SR.Get(SRID.CustomDictionaryNullItem)); } if (item.IsAbsoluteUri) { if (!(item.IsUnc || item.IsFile || System.IO.Packaging.PackUriHelper.IsPackUri(item))) { throw new NotSupportedException(SR.Get(SRID.CustomDictionarySourcesUnsupportedURI)); } } } #endregion Private Methods //----------------------------------------------------- // // Private Fields // //----------------------------------------------------- #region Private Fields private readonly List_uriList; private readonly TextBoxBase _owner; #endregion Private Fields } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SafeCertificateContext.cs
- PointHitTestParameters.cs
- MenuItemStyle.cs
- StringToken.cs
- OrderedDictionary.cs
- IntegerValidator.cs
- TextServicesCompartmentEventSink.cs
- BinaryMessageFormatter.cs
- DockPanel.cs
- Pair.cs
- TextSelectionHelper.cs
- xmlsaver.cs
- followingsibling.cs
- TemplateBindingExtensionConverter.cs
- CallbackWrapper.cs
- UnsafeNativeMethods.cs
- PerspectiveCamera.cs
- PropertyMap.cs
- FactoryId.cs
- SubMenuStyle.cs
- WorkflowView.cs
- KeyEventArgs.cs
- BinaryMessageEncodingBindingElement.cs
- X509UI.cs
- BitmapImage.cs
- ControlEvent.cs
- LocalizableResourceBuilder.cs
- PartialCachingAttribute.cs
- OleDbParameter.cs
- xdrvalidator.cs
- ActivitiesCollection.cs
- ActivationArguments.cs
- SerialReceived.cs
- TextAdaptor.cs
- WebPartManager.cs
- RunClient.cs
- COM2ICategorizePropertiesHandler.cs
- NamedPermissionSet.cs
- DiagnosticTrace.cs
- RegexWriter.cs
- SqlConnectionHelper.cs
- SharedPersonalizationStateInfo.cs
- FileDialog.cs
- KnownBoxes.cs
- HandlerBase.cs
- IconEditor.cs
- ToolStripTextBox.cs
- ComponentEditorPage.cs
- precedingquery.cs
- AddingNewEventArgs.cs
- SourceCollection.cs
- ActivityInstance.cs
- TemplateControlBuildProvider.cs
- RotateTransform.cs
- _NtlmClient.cs
- ClientBuildManagerTypeDescriptionProviderBridge.cs
- StrokeNodeEnumerator.cs
- SqlMetaData.cs
- RuntimeEnvironment.cs
- Freezable.cs
- IRCollection.cs
- TextTrailingWordEllipsis.cs
- PersonalizableTypeEntry.cs
- UIPermission.cs
- SessionStateModule.cs
- PersonalizationProviderHelper.cs
- AutoGeneratedFieldProperties.cs
- PermissionRequestEvidence.cs
- BoundingRectTracker.cs
- Matrix3D.cs
- SimpleWebHandlerParser.cs
- HealthMonitoringSection.cs
- TextPointerBase.cs
- Vector3D.cs
- SqlUserDefinedTypeAttribute.cs
- MsmqHostedTransportConfiguration.cs
- Vector3D.cs
- DeflateEmulationStream.cs
- XmlSchemaInclude.cs
- Primitive.cs
- SettingsBase.cs
- OracleBFile.cs
- XmlSchemaExporter.cs
- LazyTextWriterCreator.cs
- XamlStyleSerializer.cs
- TerminatingOperationBehavior.cs
- ServiceModelConfigurationSectionCollection.cs
- KeyPressEvent.cs
- Preprocessor.cs
- querybuilder.cs
- XamlTemplateSerializer.cs
- ValidatingPropertiesEventArgs.cs
- Visitor.cs
- HostingEnvironmentWrapper.cs
- xamlnodes.cs
- AxHost.cs
- AttachedAnnotationChangedEventArgs.cs
- FieldToken.cs
- SR.Designer.cs
- LinqDataSourceStatusEventArgs.cs