Browse Source

VariableCollection made mutable

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@735 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
David Srbecký 20 years ago
parent
commit
ab7901dbf5
  1. 4
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/PropertyVariable.cs
  2. 6
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Variable.cs
  3. 134
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/VariableCollection.cs
  4. 2
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/VariableEventArgs.cs

4
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/PropertyVariable.cs

@ -91,7 +91,7 @@ namespace Debugger @@ -91,7 +91,7 @@ namespace Debugger
void EvalStarted(object sender, EvalEventArgs args)
{
OnValueChanged(new VariableEventArgs(debugger, this));
OnValueChanged(new VariableEventArgs(this));
}
void EvalComplete(object sender, EvalEventArgs args)
@ -100,7 +100,7 @@ namespace Debugger @@ -100,7 +100,7 @@ namespace Debugger
eval.Result.Name = this.Name;
}
OnValueEvaluated();
OnValueChanged(new VariableEventArgs(debugger, this));
OnValueChanged(new VariableEventArgs(this));
}
protected void OnValueEvaluated()

6
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Variable.cs

@ -30,6 +30,12 @@ namespace Debugger @@ -30,6 +30,12 @@ namespace Debugger
}
}
public NDebugger Debugger {
get {
return debugger;
}
}
public string Name {
get{
return name;

134
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/VariableCollection.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
// <file>
// <file>
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
// <license see="prj:///doc/license.txt">GNU General Public License</license>
// <owner name="David Srbecký" email="dsrbecky@gmail.com"/>
@ -16,14 +16,35 @@ namespace Debugger @@ -16,14 +16,35 @@ namespace Debugger
public class VariableCollection: ReadOnlyCollectionBase
{
public static VariableCollection Empty;
bool readOnly = false;
public event EventHandler<VariableEventArgs> VariableAdded;
public event EventHandler<VariableEventArgs> VariableRemoved;
internal event EventHandler Updating;
internal VariableCollection()
{
}
/// <summary>
/// Creates new collection and fills it by calling 'updating' delegate
/// </summary>
/// <param name="updating"></param>
/// <returns></returns>
internal VariableCollection(EventHandler updating)
{
this.Updating += updating;
this.Update();
}
static VariableCollection()
{
Empty = new VariableCollection();
Empty.readOnly = true;
}
public bool Contains(Variable variable)
{
foreach (Variable v in InnerList) {
@ -33,7 +54,7 @@ namespace Debugger @@ -33,7 +54,7 @@ namespace Debugger
}
return false;
}
public bool Contains(string variableName)
{
foreach (Variable v in InnerList) {
@ -43,23 +64,40 @@ namespace Debugger @@ -43,23 +64,40 @@ namespace Debugger
}
return false;
}
static VariableCollection()
{
Empty = new VariableCollection();
Empty.readOnly = true;
}
internal void Add(Variable variable)
{
if (readOnly) {
throw new DebuggerException("VariableCollection is marked as readOnly");
throw new DebuggerException("VariableCollection is marked as read only");
}
if (variable != null) {
InnerList.Add(variable);
OnVariableAdded(new VariableEventArgs(variable));
}
}
internal void Remove(Variable variable)
{
if (readOnly) {
throw new DebuggerException("VariableCollection is marked as read only");
}
if (variable != null) {
InnerList.Remove(variable);
OnVariableRemoved(new VariableEventArgs(variable));
}
}
/// <summary>
/// Removes all variables from collection and resets the updating function
/// </summary>
internal void Clear()
{
foreach(Variable variable in InnerList) {
Remove(variable);
}
Updating = null;
}
public Variable this[int index] {
get {
return (Variable) InnerList[index];
@ -84,24 +122,80 @@ namespace Debugger @@ -84,24 +122,80 @@ namespace Debugger
throw new DebuggerException("Variable \"" + variableName + "\" is not in collection");
}
}
public void Update()
{
OnUpdating(EventArgs.Empty);
}
/// <summary>
/// Updates the given collections and changes the state of this collection so that it matches the given collections.
/// </summary>
/// <param name="collections"></param>
public void UpdateTo(params VariableCollection[] collections)
{
VariableCollection mergedCollection = VariableCollection.Merge(collections);
}
protected virtual void OnVariableAdded(VariableEventArgs e)
{
if (VariableAdded != null) {
VariableAdded(this, e);
}
}
protected virtual void OnVariableRemoved(VariableEventArgs e)
{
if (VariableRemoved != null) {
VariableRemoved(this, e);
}
}
protected virtual void OnUpdating(EventArgs e)
{
if (Updating != null) {
Updating(this, e);
}
}
public override string ToString() {
string txt = "";
foreach(Variable v in this) {
txt += v.ToString() + "\n";
}
return txt;
}
public static VariableCollection Merge(params VariableCollection[] collections)
{
VariableCollection mergedCollection = new VariableCollection();
VariableCollection newCollection = new VariableCollection();
newCollection.MergeWith(collections);
return newCollection;
}
public void MergeWith(params VariableCollection[] collections)
{
// Add items of subcollections and ensure the stay in sync
foreach(VariableCollection collection in collections) {
foreach(Variable variable in collection) {
mergedCollection.Add(variable);
this.Add(variable);
}
collection.VariableAdded += delegate(object sender, VariableEventArgs e) {
this.Add(e.Variable);
};
collection.VariableRemoved += delegate(object sender, VariableEventArgs e) {
this.Remove(e.Variable);
};
}
return mergedCollection;
// Update subcollections at update
this.Updating += delegate {
foreach(VariableCollection collection in collections) {
collection.Update();
};
};
}
}
}

2
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/VariableEventArgs.cs

@ -23,7 +23,7 @@ namespace Debugger @@ -23,7 +23,7 @@ namespace Debugger
}
}
public VariableEventArgs(NDebugger debugger, Variable variable): base(debugger)
public VariableEventArgs(Variable variable): base(variable.Debugger)
{
this.variable = variable;
}

Loading…
Cancel
Save