Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
Completed XML code documentation and refactoring
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/shortcuts@4613 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
  • Loading branch information
sandrejev committed Aug 7, 2009
1 parent d0d39c4 commit 71770cf
Show file tree
Hide file tree
Showing 21 changed files with 684 additions and 436 deletions.
398 changes: 199 additions & 199 deletions SharpDevelop.Tests.sln

Large diffs are not rendered by default.

Expand Up @@ -69,17 +69,17 @@ public void LoadOptions()
{
shortcutsManagementOptionsPanel.searchTextBox.Focus();

if (Directory.Exists(UserGestureManager.UserGestureProfilesDirectory)) {
var dirInfo = new DirectoryInfo(UserGestureManager.UserGestureProfilesDirectory);
if (Directory.Exists(UserGestureProfileManager.UserGestureProfilesDirectory)) {
var dirInfo = new DirectoryInfo(UserGestureProfileManager.UserGestureProfilesDirectory);
var xmlFiles = dirInfo.GetFiles("*.xml");

foreach (var fileInfo in xmlFiles) {
var profile = new UserGestureProfile();
profile.Path = Path.Combine(UserGestureManager.UserGestureProfilesDirectory, fileInfo.Name);
var path = Path.Combine(UserGestureProfileManager.UserGestureProfilesDirectory, fileInfo.Name);
var profile = new UserGestureProfile(path);
profile.Load();
profiles.Add(profile);

if (UserGestureManager.CurrentProfile != null && profile.Name == UserGestureManager.CurrentProfile.Name) {
if (UserGestureProfileManager.CurrentProfile != null && profile.Name == UserGestureProfileManager.CurrentProfile.Name) {
SelectedProfile = profile;
}
}
Expand Down Expand Up @@ -237,7 +237,7 @@ public bool SaveOptions()
}
}

UserGestureManager.CurrentProfile = SelectedProfile;
UserGestureProfileManager.CurrentProfile = SelectedProfile;

profiles.ForEach(p => p.Save());

Expand Down Expand Up @@ -290,14 +290,11 @@ private void profilesTextBox_SelectionChanged(object sender, SelectionChangedEve
openDialog.FilterIndex = 1;
openDialog.RestoreDirectory = false;
if(true == openDialog.ShowDialog()) {
var loadedProfile = new UserGestureProfile();
loadedProfile.Path = openDialog.FileName;
var loadedProfilePath = Path.Combine(UserGestureProfileManager.UserGestureProfilesDirectory, Guid.NewGuid().ToString());
File.Copy(openDialog.FileName, loadedProfilePath);
var loadedProfile = new UserGestureProfile(loadedProfilePath);
loadedProfile.Load();

loadedProfile.Path = Path.Combine(
UserGestureManager.UserGestureProfilesDirectory,
Guid.NewGuid().ToString());

profiles.Add(loadedProfile);
SelectedProfile = loadedProfile;
}
Expand All @@ -315,17 +312,19 @@ private void profilesTextBox_SelectionChanged(object sender, SelectionChangedEve
if (promptWindow.DialogResult == true) {
UserGestureProfile newProfile;

var newProfileName = Guid.NewGuid().ToString();
newProfile = new UserGestureProfile(
Path.Combine(UserGestureProfileManager.UserGestureProfilesDirectory, newProfileName + ".xml"),
newProfileName,
promptWindow.Text,
false);

if (promptWindow.BaseProfile != null) {
newProfile = (UserGestureProfile) promptWindow.BaseProfile.Clone();
newProfile.Name = Guid.NewGuid().ToString();
newProfile.Text = promptWindow.Text;
newProfile.ReadOnly = false;
} else {
newProfile = new UserGestureProfile(Guid.NewGuid().ToString(), promptWindow.Text, false);
foreach(var pair in promptWindow.BaseProfile) {
newProfile[pair.Key] = pair.Value;
}
}

newProfile.Path = Path.Combine(UserGestureManager.UserGestureProfilesDirectory,
newProfile.Name + ".xml");
profiles.Add(newProfile);

SelectedProfile = newProfile;
Expand Down
Expand Up @@ -21,7 +21,7 @@ namespace ICSharpCode.Core.Presentation
public class BindingGroup
{
private string _name;
private HashSet<WeakReference> _attachedInstances = new HashSet<WeakReference>(new WeakReferenceEqualirtyComparer());
private HashSet<WeakReference> _attachedInstances = new HashSet<WeakReference>(new WeakReferenceTargetEqualirtyComparer());
private BindingGroupCollection _nestedGroups = new BindingGroupCollection();

/// <summary>
Expand Down Expand Up @@ -114,7 +114,7 @@ private void InvokeBindingUpdateHandlers(UIElement instance, bool attaching)

/// <summary>
/// From provided <see cref="ICollection{Type}" /> generate <see cref="ICollection{UIElement}" /> containing
/// instances of any of the provided types and registered in this or any nested group
/// instances created from one of the provided types and registered in this or any nested group
/// </summary>
/// <param name="instances">Collection of examined types</param>
/// <returns>Generated instances</returns>
Expand Down
Expand Up @@ -19,6 +19,7 @@ abstract public class BindingInfoBase
private string _ownerInstanceName;
private string _ownerTypeName;
private string routedCommandName;
private AddIn _addIn;

/// <summary>
/// Get or sets binding groups
Expand Down Expand Up @@ -66,34 +67,33 @@ public BindingGroupCollection Groups
}
}



/// <summary>
/// Stores name of named instance to which this binding belongs. When this binding is registered a
/// <see cref="InputBinding" /> is assigned to owner instance
/// Gets name of named owner instance as registered using <see cref="ICSharpCode.Core.Presentation.CommandManager.RegisterNamedUIElement" />
///
/// If this attribute is used <see cref="OwnerTypeName" /> can not be set
///
/// If this attribute is used <see cref="OwnerInstance" />, <see cref="OwnerType" /> and
/// <see cref="OwnerTypeName" /> can not be set
/// This attribute can't be set while <see cref="InputBindingInfo" /> or <see cref="CommandBindingInfo" />
/// is registered in <see cref="ICSharpCode.Core.Presentation.CommandManager" />
/// </summary>
public virtual string OwnerInstanceName {
get {
return _ownerInstanceName;
}
set {
if(_ownerInstanceName != null || _ownerTypeName != null) {
throw new ArgumentException("This binding already has an owner");
if(_ownerTypeName != null) {
throw new ArgumentException("This binding info already has an owner");
}

if(IsRegistered) {
throw new ArgumentException("Can not change owner while binding info is registered");
}

_ownerInstanceName = value;
}
}

/// <summary>
/// Stores owner instance to which this binding belongs. When this binding is registered a
/// <see cref="InputBinding" /> is assigned to owner instance
///
/// If this attribute is used <see cref="OwnerInstanceName" />, <see cref="OwnerType" /> and
/// <see cref="OwnerTypeName" /> can not be set
/// Gets collection of instances registered in <see cref="ICSharpCode.Core.Presentation.CommandManager" /> by name found in <see cref="OwnerInstanceName" /> property
/// </summary>
public ICollection<UIElement> OwnerInstances {
get {
Expand All @@ -106,32 +106,33 @@ public BindingGroupCollection Groups
}

/// <summary>
/// Stores name of owner type. Full name with assembly should be used. When this binding is
/// registered <see cref="InputBinding" /> is assigned to all instances of provided class
/// Gets name of named owner type as registered using <see cref="ICSharpCode.Core.Presentation.CommandManager.RegisterNamedUIType" />
///
/// If this attribute is used <see cref="OwnerInstanceName" /> can not be set
///
/// If this attribute is used <see cref="OwnerInstance" />, <see cref="OwnerInstanceName" /> and
/// <see cref="OwnerType" /> can not be set
/// This attribute can't be set while <see cref="InputBindingInfo" /> or <see cref="CommandBindingInfo" />
/// is registered in <see cref="ICSharpCode.Core.Presentation.CommandManager" />
/// </summary>
public virtual string OwnerTypeName
{
get {
return _ownerTypeName;
}
set {
if(_ownerInstanceName != null || _ownerTypeName != null) {
throw new ArgumentException("This binding already has an owner");
if(_ownerTypeName != null) {
throw new ArgumentException("This binding info already has an owner");
}

if(IsRegistered) {
throw new ArgumentException("Can not change owner while binding info is registered");
}

_ownerTypeName = value;
}
}

/// <summary>
/// Stores owner type. When this binding is registered <see cref="InputBinding" />
/// is assigned to all instances of provided class
///
/// If this attribute is used <see cref="OwnerInstance" />, <see cref="OwnerInstanceName" /> and
/// <see cref="OwnerTypeName" /> can not be set
/// Gets collection of types registered in <see cref="ICSharpCode.Core.Presentation.CommandManager" /> by name found in <see cref="OwnerInstanceName" /> property
/// </summary>
public ICollection<Type> OwnerTypes {
get {
Expand All @@ -144,50 +145,66 @@ public virtual string OwnerTypeName
}

/// <summary>
/// Routed command text
/// Gets name of <see cref="RoutedUICommand" /> associated with binding info as registered using
/// <see cref="ICSharpCode.Core.Presentation.CommandManager.RegisterRoutedUICommand" />
///
/// Override routed command text when displaying to user
/// </summary>
/// <seealso cref="RoutedCommand"></seealso>
public string RoutedCommandText {
get; set;
}


/// <summary>
/// Name of the routed command which will be invoked when this binding is triggered
/// This attribute can't be set while <see cref="InputBindingInfo" /> or <see cref="CommandBindingInfo" />
/// is registered in <see cref="ICSharpCode.Core.Presentation.CommandManager" />
/// </summary>
public virtual string RoutedCommandName {
get {
return routedCommandName;
}
set {
if(IsRegistered) {
throw new ArgumentException("Can not change routed command while binding info is registered");
}

routedCommandName = value;
}
}

/// <summary>
/// Routed command instance which will be invoked when this binding is triggered
/// Gets <see cref="RoutedUICommand" /> instance registered in <see cref="ICSharpCode.Core.Presentation.CommandManager" /> by name found in <see cref="RoutedCommandName" /> property
/// </summary>
public RoutedUICommand RoutedCommand {
get {
return SDCommandManager.GetRoutedUICommand(RoutedCommandName);
}
}

/// <summary>
/// Gets whether <see cref="CommandBindingInfo" /> or <see cref="InputBindingInfo" /> is registered in
/// <see cref="ICSharpCode.Core.Presentation.CommandManager" />
/// </summary>
public bool IsRegistered
{
get; set;
get; internal set;
}

/// <summary>
/// Add-in to which registered this input binding
/// Gets or sets add-in which created this <see cref="CommandBindingInfo" /> or <see cref="InputBindingInfo" />
///
/// In case of <see cref="CommandBindingInfo" /> this reference is used to create an instance of
/// associated command when doing lazy loading
///
/// This attribute can't be set while <see cref="InputBindingInfo" /> or <see cref="CommandBindingInfo" />
/// is registered in <see cref="ICSharpCode.Core.Presentation.CommandManager" />
/// </summary>
public AddIn AddIn {
get; set;
get {
return _addIn;
}
set {
if(IsRegistered) {
throw new ArgumentException("Can not change add-in while binding info is registered");
}

_addIn = value;
}
}

public void SetCollectionChanged<T>(IObservableCollection<T> oldObservableCollection, IObservableCollection<T> newObservableCollection, NotifyCollectionChangedEventHandler handler)
protected void SetCollectionChanged<T>(IObservableCollection<T> oldObservableCollection, IObservableCollection<T> newObservableCollection, NotifyCollectionChangedEventHandler handler)
{
newObservableCollection.CollectionChanged += handler;

Expand All @@ -209,8 +226,10 @@ public void SetCollectionChanged<T>(IObservableCollection<T> oldObservableCollec
}

/// <summary>
/// Updates owner bindings
/// Handles <see cref="ICSharpCode.Core.Presentation.CommandManager.BindingsChanged" /> event
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="args">Event data</param>
public void BindingsChangedHandler(object sender, NotifyBindingsChangedEventArgs args)
{
if(!IsRegistered || RoutedCommand == null || (OwnerTypes == null && OwnerInstances == null)) {
Expand Down Expand Up @@ -240,16 +259,48 @@ public void BindingsChangedHandler(object sender, NotifyBindingsChangedEventArgs
}
}

/// <summary>
/// Remove bindings currently assigned to <see cref="UIElement" /> or <see cref="Type" />
/// collection described in this binding info
/// </summary>
public void RemoveActiveBindings()
{
PopulateOwnerInstancesWithBindings(null);
PopulateOwnerTypesWithBindings(null);
}

/// <summary>
/// Represents instance of <see cref="BindingInfoBase" /> as string
/// </summary>
/// <returns></returns>
public override string ToString()
{
return string.Format(
"[{0}={1}, RoutedCommandName={2}, Hash={3}",
OwnerInstanceName != null ? "OwnerInstanceName" : "OwnerTypeName",
OwnerInstanceName != null ? OwnerInstanceName : OwnerTypeName,
RoutedCommandName,
GetHashCode());
}

/// <summary>
/// Generate up to date <see cref="InputBindings" /> collection in case of <see cref="InputBindingInfo" />
/// or <see cref="CommandBindings" /> collection in case of <see cref="CommandBindingInfo" />
/// </summary>
protected abstract void GenerateBindings();

/// <summary>
/// Fills <see cref="UIElement.CommandBindings" /> or <see cref="UIElement.InputBindings" /> collections
/// with generated <see cref="CommandBinding" /> or <see cref="InputBinding" /> collections
/// </summary>
/// <param name="newInstances">Collection of <see cref="UIElement" /></param>
protected abstract void PopulateOwnerInstancesWithBindings(ICollection<UIElement> newInstances);

/// <summary>
/// Using <see cref="System.Windows.Input.CommandManager.RegisterClassCommandBinding" /> or <see cref="System.Windows.Input.CommandManager.RegisterClassCommandBinding" /> methods
/// registers generated <see cref="CommandBinding" /> or <see cref="InputBinding" /> collections to collection of provided types
/// </summary>
/// <param name="newInstances">Collection of <see cref="Type" /></param>
protected abstract void PopulateOwnerTypesWithBindings(ICollection<Type> newtTypes);
}
}

0 comments on commit 71770cf

Please sign in to comment.