aboutsummaryrefslogtreecommitdiffstatsci
path: root/src
diff options
context:
space:
mode:
authorjpbruyere <jp.bruyere@hotmail.com>2017-02-10 15:54:50 +0100
committerjpbruyere <jp.bruyere@hotmail.com>2017-02-10 15:54:50 +0100
commit20ca0a729160585ab649da52d3f63bf1dd7ad54c (patch)
tree42dc38f31028f3854f55a8203390ed922dd8cd5a /src
parentff1d0f42b546fec1f45887be8addaa07b9fb5571 (diff)
TextBox, Label, simpler SVG icon for file sys viewers (improve speed a lot), divers debug and code clean
Diffstat (limited to 'src')
-rw-r--r--src/Command.cs16
-rw-r--r--src/GraphicObjects/FileDialog.cs62
-rw-r--r--src/GraphicObjects/GraphicObject.cs22
-rw-r--r--src/GraphicObjects/Group.cs2
-rw-r--r--src/GraphicObjects/Label.cs18
-rw-r--r--src/GraphicObjects/MenuItem.cs12
-rw-r--r--src/GraphicObjects/TemplatedGroup.cs1
-rw-r--r--src/GraphicObjects/TextBox.cs7
8 files changed, 87 insertions, 53 deletions
diff --git a/src/Command.cs b/src/Command.cs
index f7a12465..1f744f84 100644
--- a/src/Command.cs
+++ b/src/Command.cs
@@ -45,17 +45,17 @@ namespace Crow
string caption;
Picture icon;
- bool isEnabled;
+ bool canExecute = true;
#region Public properties
[XmlAttributeAttribute][DefaultValue(true)]
- public virtual bool IsEnabled {
- get { return isEnabled; }
+ public virtual bool CanExecute {
+ get { return canExecute; }
set {
- if (isEnabled == value)
+ if (canExecute == value)
return;
- isEnabled = value;
- NotifyValueChanged ("IsEnabled", isEnabled);
+ canExecute = value;
+ NotifyValueChanged ("CanExecute", canExecute);
}
}
[XmlAttributeAttribute][DefaultValue("Unamed Command")]
@@ -82,11 +82,11 @@ namespace Crow
#endregion
public void Execute(){
- if (execute != null)
+ if (execute != null && CanExecute)
execute ();
}
internal void raiseAllValuesChanged(){
- NotifyValueChanged ("IsEnabled", isEnabled);
+ NotifyValueChanged ("CanExecute", canExecute);
NotifyValueChanged ("Icon", icon);
NotifyValueChanged ("Caption", caption);
}
diff --git a/src/GraphicObjects/FileDialog.cs b/src/GraphicObjects/FileDialog.cs
index 0ee78e13..f1e4b71d 100644
--- a/src/GraphicObjects/FileDialog.cs
+++ b/src/GraphicObjects/FileDialog.cs
@@ -31,7 +31,7 @@ namespace Crow
{
public class FileDialog: Window
{
- string searchPattern, curDirectory;
+ string searchPattern, curDir, _selectedFile, _selectedDir;
#region events
public event EventHandler OkClicked;
@@ -45,17 +45,17 @@ namespace Crow
[XmlAttributeAttribute][DefaultValue("/home")]
public virtual string CurrentDirectory {
- get { return curDirectory; }
+ get { return curDir; }
set {
- if (curDirectory == value)
+ if (curDir == value)
return;
- curDirectory = value;
- NotifyValueChanged ("CurrentDirectory", curDirectory);
-
+ curDir = value;
+ NotifyValueChanged ("CurrentDirectory", curDir);
+ SelectedDirectory = curDir;
}
}
- [XmlAttributeAttribute()][DefaultValue("*")]
+ [XmlAttributeAttribute][DefaultValue("*")]
public virtual string SearchPattern {
get { return searchPattern; }
set {
@@ -66,11 +66,8 @@ namespace Crow
}
}
- string _selectedFile;
- [XmlIgnore]public string SelectedFile {
- get {
- return _selectedFile;
- }
+ [XmlAttributeAttribute]public string SelectedFile {
+ get { return _selectedFile; }
set {
if (value == _selectedFile)
return;
@@ -78,19 +75,44 @@ namespace Crow
NotifyValueChanged ("SelectedFile", _selectedFile);
}
}
- public void onSelectedItemChanged (object sender, SelectionChangeEventArgs e){
+ [XmlAttributeAttribute]public string SelectedDirectory {
+ get { return _selectedDir; }
+ set {
+ if (value == _selectedDir)
+ return;
+ _selectedDir = value;
+ NotifyValueChanged ("SelectedDirectory", _selectedDir);
+ }
+ }
- string tmp = "";
+ public void onFVSelectedItemChanged (object sender, SelectionChangeEventArgs e){
+ if (e.NewValue != null) {
+ if (File.GetAttributes (e.NewValue.ToString ()).HasFlag (FileAttributes.Directory)) {
+ SelectedDirectory = e.NewValue.ToString ();
+ SelectedFile = "";
+ } else {
+ SelectedDirectory = Path.GetDirectoryName (e.NewValue.ToString ());
+ SelectedFile = Path.GetFileName (e.NewValue.ToString ());
+ }
+ }
+ }
+ public void onDVSelectedItemChanged (object sender, SelectionChangeEventArgs e){
if (e.NewValue != null)
- tmp = e.NewValue.ToString();
- if (tmp == SelectedFile)
+ SelectedDirectory = e.NewValue.ToString();
+ }
+ public void goUpDirClick (object sender, MouseButtonEventArgs e){
+ string root = Directory.GetDirectoryRoot(CurrentDirectory);
+ if (CurrentDirectory == root)
return;
- SelectedFile = tmp;
- //SelectedItemChanged.Raise (this, e);
+ CurrentDirectory = Directory.GetParent(CurrentDirectory).FullName;
}
void onFileSelect(object sender, MouseButtonEventArgs e){
- OkClicked.Raise (this, null);
- unloadDialog ((sender as GraphicObject).CurrentInterface);
+ if (string.IsNullOrEmpty (SelectedFile))
+ CurrentDirectory = SelectedDirectory;
+ else {
+ OkClicked.Raise (this, null);
+ unloadDialog ((sender as GraphicObject).CurrentInterface);
+ }
}
void onCancel(object sender, MouseButtonEventArgs e){
unloadDialog ((sender as GraphicObject).CurrentInterface);
diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs
index e468cce9..7aac41d7 100644
--- a/src/GraphicObjects/GraphicObject.cs
+++ b/src/GraphicObjects/GraphicObject.cs
@@ -1169,16 +1169,20 @@ namespace Crow
#region Mouse handling
public virtual bool MouseIsIn(Point m)
{
- if (!(Visible & isEnabled))
- return false;
- if (ScreenCoordinates (Slot).ContainsOrIsEqual (m)) {
- Scroller scr = Parent as Scroller;
- if (scr == null) {
- if (Parent is GraphicObject)
- return (Parent as GraphicObject).MouseIsIn (m);
- else return true;
+ try {
+ if (!(Visible & isEnabled))
+ return false;
+ if (ScreenCoordinates (Slot).ContainsOrIsEqual (m)) {
+ Scroller scr = Parent as Scroller;
+ if (scr == null) {
+ if (Parent is GraphicObject)
+ return (Parent as GraphicObject).MouseIsIn (m);
+ else return true;
+ }
+ return scr.MouseIsIn (scr.savedMousePos);
}
- return scr.MouseIsIn (scr.savedMousePos);
+ } catch (Exception ex) {
+ return false;
}
return false;
}
diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs
index 0defeabd..6e470b95 100644
--- a/src/GraphicObjects/Group.cs
+++ b/src/GraphicObjects/Group.cs
@@ -38,8 +38,8 @@ namespace Crow
}
public virtual void AddChild(GraphicObject g){
lock (children) {
- Children.Add (g);
g.Parent = this;
+ Children.Add (g);
}
g.RegisteredLayoutings = LayoutingType.None;
g.RegisterForLayouting (LayoutingType.Sizing | LayoutingType.ArrangeChildren);
diff --git a/src/GraphicObjects/Label.cs b/src/GraphicObjects/Label.cs
index 071dc79f..7a355f2d 100644
--- a/src/GraphicObjects/Label.cs
+++ b/src/GraphicObjects/Label.cs
@@ -44,6 +44,13 @@ namespace Crow
}
#endregion
+ public event EventHandler<TextChangeEventArgs> TextChanged;
+
+ public virtual void OnTextChanged(Object sender, TextChangeEventArgs e)
+ {
+ NotifyValueChanged ("Text", Text);
+ TextChanged.Raise (this, e);
+ }
//TODO:change protected to private
#region private and protected fields
@@ -147,7 +154,7 @@ namespace Crow
lines = getLines;
- NotifyValueChanged ("Text", _text);
+ OnTextChanged (this, new TextChangeEventArgs (Text));
RegisterForGraphicUpdate ();
}
}
@@ -363,7 +370,8 @@ namespace Crow
CurrentColumn = lines [CurrentLine].Length;
lines [CurrentLine] += lines [CurrentLine + 1];
lines.RemoveAt (CurrentLine + 1);
- NotifyValueChanged ("Text", Text);
+
+ OnTextChanged (this, new TextChangeEventArgs (Text));
return;
}
CurrentColumn--;
@@ -386,7 +394,7 @@ namespace Crow
SelBegin = -1;
SelRelease = -1;
}
- NotifyValueChanged ("Text", Text);
+ OnTextChanged (this, new TextChangeEventArgs (Text));
}
/// <summary>
/// Insert new string at caret position, should be sure no line break is inside.
@@ -409,7 +417,7 @@ namespace Crow
lines [CurrentLine] = lines [CurrentLine].Insert (CurrentColumn, str);
CurrentColumn += str.Length;
}
- NotifyValueChanged ("Text", Text);
+ OnTextChanged (this, new TextChangeEventArgs (Text));
}
/// <summary>
/// Insert a line break.
@@ -420,7 +428,7 @@ namespace Crow
lines [CurrentLine] = lines [CurrentLine].Substring (0, CurrentColumn);
CurrentLine++;
CurrentColumn = 0;
- NotifyValueChanged ("Text", Text);
+ OnTextChanged (this, new TextChangeEventArgs (Text));
}
#region GraphicObject overrides
diff --git a/src/GraphicObjects/MenuItem.cs b/src/GraphicObjects/MenuItem.cs
index b277194e..e317e0cb 100644
--- a/src/GraphicObjects/MenuItem.cs
+++ b/src/GraphicObjects/MenuItem.cs
@@ -79,6 +79,11 @@ namespace Crow
}
}
[XmlAttributeAttribute]
+ public override bool IsEnabled {
+ get { return Command == null ? base.IsEnabled : Command.CanExecute; }
+ set { base.IsEnabled = value; }
+ }
+ [XmlAttributeAttribute]
public override string Caption {
get { return Command == null ? base.Caption : Command.Caption; }
set { base.Caption = value; }
@@ -124,7 +129,10 @@ namespace Crow
void Command_ValueChanged (object sender, ValueChangeEventArgs e)
{
- NotifyValueChanged (e.MemberName, e.NewValue);
+ string mName = e.MemberName;
+ if (mName == "CanExecute")
+ mName = "IsEnabled";
+ NotifyValueChanged (mName, e.NewValue);
}
void onMI_Click (object sender, MouseButtonEventArgs e)
{
@@ -141,7 +149,7 @@ namespace Crow
}
public override bool MouseIsIn (Point m)
{
- return base.MouseIsIn (m) || child.MouseIsIn (m);
+ return IsEnabled ? base.MouseIsIn (m) || child.MouseIsIn (m) : false;
}
public override void onMouseEnter (object sender, MouseMoveEventArgs e)
{
diff --git a/src/GraphicObjects/TemplatedGroup.cs b/src/GraphicObjects/TemplatedGroup.cs
index 2e2eef47..5a702122 100644
--- a/src/GraphicObjects/TemplatedGroup.cs
+++ b/src/GraphicObjects/TemplatedGroup.cs
@@ -163,7 +163,6 @@ namespace Crow
loadingThread = new CrowThread (this, loading);
loadingThread.Finished += (object sender, EventArgs e) => (sender as TemplatedGroup).Loaded.Raise (sender, e);
loadingThread.Start ();
- //loadPage(1);
NotifyValueChanged ("SelectedIndex", _selectedIndex);
NotifyValueChanged ("SelectedItem", SelectedItem);
diff --git a/src/GraphicObjects/TextBox.cs b/src/GraphicObjects/TextBox.cs
index 44690342..ab84596b 100644
--- a/src/GraphicObjects/TextBox.cs
+++ b/src/GraphicObjects/TextBox.cs
@@ -58,13 +58,6 @@ namespace Crow
FontExtents fe = gr.FontExtents;
}
#endregion
-
- public event EventHandler<TextChangeEventArgs> TextChanged;
-
- public virtual void OnTextChanged(Object sender, TextChangeEventArgs e)
- {
- TextChanged.Raise (this, e);
- }
#region Keyboard handling
public override void onKeyDown (object sender, KeyboardKeyEventArgs e)