|
|
|
@ -23,16 +23,26 @@ namespace ICSharpCode.AvalonEdit.AddIn.Snippets |
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// A code snippet.
|
|
|
|
/// A code snippet.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public class CodeSnippet : INotifyPropertyChanged |
|
|
|
public class CodeSnippet : INotifyPropertyChanged, IEquatable<CodeSnippet> |
|
|
|
{ |
|
|
|
{ |
|
|
|
string name, description, text, keyword; |
|
|
|
string name, description, text, keyword; |
|
|
|
bool isUserModified; |
|
|
|
|
|
|
|
|
|
|
|
public CodeSnippet() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public CodeSnippet(CodeSnippet copy) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
this.name = copy.name; |
|
|
|
|
|
|
|
this.description = copy.description; |
|
|
|
|
|
|
|
this.text = copy.text; |
|
|
|
|
|
|
|
this.keyword = copy.keyword; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public string Name { |
|
|
|
public string Name { |
|
|
|
get { return name; } |
|
|
|
get { return name; } |
|
|
|
set { |
|
|
|
set { |
|
|
|
if (name != value) { |
|
|
|
if (name != value) { |
|
|
|
isUserModified = true; |
|
|
|
|
|
|
|
name = value; |
|
|
|
name = value; |
|
|
|
OnPropertyChanged("Name"); |
|
|
|
OnPropertyChanged("Name"); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -43,7 +53,6 @@ namespace ICSharpCode.AvalonEdit.AddIn.Snippets |
|
|
|
get { return text; } |
|
|
|
get { return text; } |
|
|
|
set { |
|
|
|
set { |
|
|
|
if (text != value) { |
|
|
|
if (text != value) { |
|
|
|
isUserModified = true; |
|
|
|
|
|
|
|
text = value; |
|
|
|
text = value; |
|
|
|
OnPropertyChanged("Text"); |
|
|
|
OnPropertyChanged("Text"); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -54,7 +63,6 @@ namespace ICSharpCode.AvalonEdit.AddIn.Snippets |
|
|
|
get { return description; } |
|
|
|
get { return description; } |
|
|
|
set { |
|
|
|
set { |
|
|
|
if (description != value) { |
|
|
|
if (description != value) { |
|
|
|
isUserModified = true; |
|
|
|
|
|
|
|
description = value; |
|
|
|
description = value; |
|
|
|
OnPropertyChanged("Description"); |
|
|
|
OnPropertyChanged("Description"); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -73,23 +81,12 @@ namespace ICSharpCode.AvalonEdit.AddIn.Snippets |
|
|
|
get { return keyword; } |
|
|
|
get { return keyword; } |
|
|
|
set { |
|
|
|
set { |
|
|
|
if (keyword != value) { |
|
|
|
if (keyword != value) { |
|
|
|
isUserModified = true; |
|
|
|
|
|
|
|
keyword = value; |
|
|
|
keyword = value; |
|
|
|
OnPropertyChanged("Keyword"); |
|
|
|
OnPropertyChanged("Keyword"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public bool IsUserModified { |
|
|
|
|
|
|
|
get { return isUserModified; } |
|
|
|
|
|
|
|
set { |
|
|
|
|
|
|
|
if (isUserModified != value) { |
|
|
|
|
|
|
|
isUserModified = value; |
|
|
|
|
|
|
|
OnPropertyChanged("IsUserModified"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged; |
|
|
|
public event PropertyChangedEventHandler PropertyChanged; |
|
|
|
|
|
|
|
|
|
|
|
protected virtual void OnPropertyChanged(string propertyName) |
|
|
|
protected virtual void OnPropertyChanged(string propertyName) |
|
|
|
@ -241,12 +238,42 @@ namespace ICSharpCode.AvalonEdit.AddIn.Snippets |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public override int GetHashCode() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
int hashCode = 0; |
|
|
|
|
|
|
|
unchecked { |
|
|
|
|
|
|
|
if (name != null) |
|
|
|
|
|
|
|
hashCode += 1000000007 * name.GetHashCode(); |
|
|
|
|
|
|
|
if (description != null) |
|
|
|
|
|
|
|
hashCode += 1000000009 * description.GetHashCode(); |
|
|
|
|
|
|
|
if (text != null) |
|
|
|
|
|
|
|
hashCode += 1000000021 * text.GetHashCode(); |
|
|
|
|
|
|
|
if (keyword != null) |
|
|
|
|
|
|
|
hashCode += 1000000033 * keyword.GetHashCode(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return hashCode; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public override bool Equals(object obj) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
CodeSnippet other = obj as CodeSnippet; |
|
|
|
|
|
|
|
return Equals(other); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public bool Equals(CodeSnippet other) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (other == null) |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
return this.name == other.name && this.description == other.description && this.text == other.text && this.keyword == other.keyword; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Reports the snippet usage to UDC
|
|
|
|
/// Reports the snippet usage to UDC
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
internal void TrackUsage(string activationMethod) |
|
|
|
internal void TrackUsage(string activationMethod) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Core.AnalyticsMonitorService.TrackFeature(typeof(CodeSnippet), IsUserModified ? "usersnippet" : Name, activationMethod); |
|
|
|
bool isUserModified = !SnippetManager.defaultSnippets.Any(g => g.Snippets.Contains(this)); |
|
|
|
|
|
|
|
Core.AnalyticsMonitorService.TrackFeature(typeof(CodeSnippet), isUserModified ? "usersnippet" : Name, activationMethod); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|