forked from ktvoelker/di
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed shift bug; added statusbar showing mode; added Bind type
- Loading branch information
Showing
9 changed files
with
129 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// | ||
// Bind.cs | ||
// | ||
// Author: | ||
// Karl Voelker <[email protected]> | ||
// | ||
// Copyright (c) 2010 Karl Voelker | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
using System; | ||
namespace Di | ||
{ | ||
public class Actor : IDisposable | ||
{ | ||
private Action action; | ||
|
||
public Actor(Action _action) | ||
{ | ||
action = _action; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
action(); | ||
} | ||
} | ||
|
||
public class Bind<P, V> | ||
{ | ||
public delegate void ValueChanged(P p, V v); | ||
|
||
private ValueChanged _changed; | ||
|
||
public event ValueChanged Changed | ||
{ | ||
add { _changed += value; } | ||
remove { _changed -= value; } | ||
} | ||
|
||
private P p; | ||
|
||
private V v; | ||
|
||
public V Value | ||
{ | ||
get { return v; } | ||
|
||
set | ||
{ | ||
v = value; | ||
_changed(p, v); | ||
} | ||
} | ||
|
||
public Bind(P _p) | ||
{ | ||
p = _p; | ||
} | ||
|
||
public Bind(P _p, V _v) : this(_p) | ||
{ | ||
v = _v; | ||
} | ||
|
||
public static implicit operator V(Bind<P, V> obj) | ||
{ | ||
return obj.v; | ||
} | ||
|
||
public IDisposable WithChange() | ||
{ | ||
return new Actor(() => _changed(p, v)); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters