aboutsummaryrefslogtreecommitdiffstatsci
path: root/Samples/common/src
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2021-07-01 23:38:09 +0200
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>2021-07-01 23:38:09 +0200
commita4386e4844dbb85b804770d936b2d47c7584d258 (patch)
tree85113f4aa66fa77f2e4cde0d4e02bc8eeadbd962 /Samples/common/src
parent6c4bb7e2c26c3a4c612fdece4dee96282391007a (diff)
wip
Diffstat (limited to 'Samples/common/src')
-rw-r--r--Samples/common/src/Editor.cs85
-rw-r--r--Samples/common/src/ImlParsing/Syntax.cs2
-rw-r--r--Samples/common/src/ImlParsing/TokenType.cs12
-rw-r--r--Samples/common/src/ImlParsing/XmlSource.cs2
-rw-r--r--Samples/common/src/SampleBase.cs46
-rw-r--r--Samples/common/src/SampleBaseForEditor.cs14
6 files changed, 102 insertions, 59 deletions
diff --git a/Samples/common/src/Editor.cs b/Samples/common/src/Editor.cs
index 7b9d5c10..7b0f1f04 100644
--- a/Samples/common/src/Editor.cs
+++ b/Samples/common/src/Editor.cs
@@ -32,6 +32,7 @@ namespace Crow
}
ListBox overlay;
IList suggestions;
+ volatile bool disableSuggestions;
public IList Suggestions {
get => suggestions;
set {
@@ -67,7 +68,8 @@ namespace Crow
//Task.Run(()=>parse());
parse();
- if (HasFocus)
+
+ if (!disableSuggestions && HasFocus)
tryGetSuggestions ();
//Console.WriteLine ($"{pos}: {suggestionTok.AsString (_text)} {suggestionTok}");
@@ -78,7 +80,6 @@ namespace Crow
int pos = lines.GetAbsolutePosition (CurrentLoc.Value);
currentToken = source.FindTokenIncludingPosition (pos);
currentNode = source.FindNodeIncludingPosition (pos);
-
Console.WriteLine ($"Current Token: {currentToken} Current Node: {currentNode}");
if (currentToken.Type == TokenType.ElementOpen) {
@@ -96,7 +97,10 @@ namespace Crow
MemberInfo mi = getCrowTypeMember (
eltTag.NameToken.Value.AsString (_text), attribNode.NameToken.Value.AsString (_text));
if (mi is PropertyInfo pi) {
- if (pi.PropertyType.IsEnum)
+ if (pi.Name == "Style")
+ Suggestions = IFace.Styling.Keys
+ .Where (s => s.StartsWith (currentToken.AsString (_text), StringComparison.OrdinalIgnoreCase)).ToList ();
+ else if (pi.PropertyType.IsEnum)
Suggestions = Enum.GetNames (pi.PropertyType)
.Where (s => s.StartsWith (currentToken.AsString (_text), StringComparison.OrdinalIgnoreCase)).ToList ();
else if (pi.PropertyType == typeof(bool))
@@ -113,6 +117,8 @@ namespace Crow
MemberInfo mi = getCrowTypeMember (
eltTag.NameToken.Value.AsString (_text), attribNode.NameToken.Value.AsString (_text));
if (mi is PropertyInfo pi) {
+ if (pi.Name == "Style")
+ Suggestions = IFace.Styling.Keys.ToList ();
if (pi.PropertyType.IsEnum)
Suggestions = Enum.GetNames (pi.PropertyType).ToList ();
else if (pi.PropertyType == typeof(bool))
@@ -125,7 +131,7 @@ namespace Crow
}
}
}
- }
+ }
} else if (currentToken.Type != TokenType.AttributeValueClose &&
currentToken.Type != TokenType.EmptyElementClosing &&
currentToken.Type != TokenType.ClosingSign &&
@@ -133,8 +139,8 @@ namespace Crow
if (currentToken.Type == TokenType.AttributeName)
Suggestions = getAllCrowTypeMembers (eltStartTag.NameToken.Value.AsString (_text))
.Where (s => s.Name.StartsWith (currentToken.AsString (_text), StringComparison.OrdinalIgnoreCase)).ToList ();
- else
- Suggestions = getAllCrowTypeMembers (eltStartTag.NameToken.Value.AsString (_text)).ToList ();
+ //else if (currentToken.Type == TokenType.ElementName)
+ // Suggestions = getAllCrowTypeMembers (eltStartTag.NameToken.Value.AsString (_text)).ToList ();
} else {
/*SyntaxNode curNode = source.FindNodeIncludingPosition (pos);
Console.WriteLine ($"Current Node: {curNode}");
@@ -221,39 +227,42 @@ namespace Crow
public override void onKeyDown(object sender, KeyEventArgs e)
{
- if (suggestionsActive) {
- switch (e.Key) {
- case Key.Escape:
- hideOverlay ();
- return;
- case Key.Left:
- case Key.Right:
- hideOverlay ();
- break;
- case Key.End:
- case Key.Home:
- case Key.Down:
- case Key.Up:
- case Key.PageDown:
- case Key.PageUp:
- overlay.onKeyDown (this, e);
- return;
- case Key.Tab:
- case Key.Enter:
- case Key.KeypadEnter:
- completeToken ();
+ TextSpan selection = Selection;
+
+ if (SelectionIsEmpty) {
+ if (suggestionsActive) {
+ switch (e.Key) {
+ case Key.Escape:
+ hideOverlay ();
+ return;
+ case Key.Left:
+ case Key.Right:
+ hideOverlay ();
+ break;
+ case Key.End:
+ case Key.Home:
+ case Key.Down:
+ case Key.Up:
+ case Key.PageDown:
+ case Key.PageUp:
+ overlay.onKeyDown (this, e);
+ return;
+ case Key.Tab:
+ case Key.Enter:
+ case Key.KeypadEnter:
+ completeToken ();
+ return;
+ }
+ } else if (e.Key == Key.Space && IFace.Ctrl) {
+ tryGetSuggestions ();
return;
}
- } else if (e.Key == Key.Space && IFace.Ctrl) {
- tryGetSuggestions ();
- return;
- }
-
- TextSpan selection = Selection;
- if (e.Key == Key.Tab && !selection.IsEmpty) {
+ } else if (e.Key == Key.Tab && !selection.IsEmpty) {
int lineStart = lines.GetLocation (selection.Start).Line;
int lineEnd = lines.GetLocation (selection.End).Line;
+ disableSuggestions = true;
+
if (IFace.Shift) {
for (int l = lineStart; l <= lineEnd; l++) {
if (Text[lines[l].Start] == '\t')
@@ -270,13 +279,15 @@ namespace Crow
for (int l = lineStart; l <= lineEnd; l++)
update (new TextChange (lines[l].Start, 0, "\t"));
}
+
+ selectionStart = new CharLocation (lineStart, 0);
+ CurrentLoc = new CharLocation (lineEnd, lines[lineEnd].Length);
- selectionStart = new CharLocation (lineStart, 0);
- CurrentLoc = new CharLocation (lineEnd, lines[lineEnd].Length);
+ disableSuggestions = false;
return;
}
- base.onKeyDown(sender, e);
+ base.onKeyDown(sender, e);
}
protected override void drawContent (Context gr) {
diff --git a/Samples/common/src/ImlParsing/Syntax.cs b/Samples/common/src/ImlParsing/Syntax.cs
index a38e1558..92c9eec3 100644
--- a/Samples/common/src/ImlParsing/Syntax.cs
+++ b/Samples/common/src/ImlParsing/Syntax.cs
@@ -236,7 +236,7 @@ namespace Crow
public XmlSource Source => Root.source;
public bool Contains (int pos) =>
EndToken.HasValue ?
- StartToken.Start <= pos && EndToken.Value.End > pos : false;
+ StartToken.Start <= pos && EndToken.Value.End >= pos : false;
public void Dump (int level = 0) {
Console.WriteLine ($"{new string('\t', level)}{this}");
diff --git a/Samples/common/src/ImlParsing/TokenType.cs b/Samples/common/src/ImlParsing/TokenType.cs
index 3289d5ae..baf25f32 100644
--- a/Samples/common/src/ImlParsing/TokenType.cs
+++ b/Samples/common/src/ImlParsing/TokenType.cs
@@ -24,17 +24,17 @@ namespace Crow
Punctuation = 0x0400,
PI_Start = 0x0401,// '<?'
PI_End = 0x0402,// '?>'
- Operator = 0x0800,
- EqualSign = 0x0801,
- AttributeValue = 0x2000,
- AttributeValueOpen = 0x2001,
- AttributeValueClose = 0x2002,
- Keyword = 0x1000,
ElementOpen = 0x0403,// '<'
EndElementOpen = 0x0404,// '</'
EmptyElementClosing = 0x0405,// '/>'
ClosingSign = 0x0406,// '>'
DTDObjectOpen = 0x04A0,// '<!'
+ Operator = 0x0800,
+ EqualSign = 0x0801,
+ Keyword = 0x1000,
+ AttributeValue = 0x2000,
+ AttributeValueOpen = 0x2001,
+ AttributeValueClose = 0x2002,
Content,
}
} \ No newline at end of file
diff --git a/Samples/common/src/ImlParsing/XmlSource.cs b/Samples/common/src/ImlParsing/XmlSource.cs
index 0942486f..86eb1e24 100644
--- a/Samples/common/src/ImlParsing/XmlSource.cs
+++ b/Samples/common/src/ImlParsing/XmlSource.cs
@@ -39,7 +39,7 @@ namespace Crow
}
public Token FindTokenIncludingPosition (int pos) {
- if (tokens == null || tokens.Length == 0)
+ if (pos == 0 || tokens == null || tokens.Length == 0)
return default;
int idx = Array.BinarySearch (tokens, 0, tokens.Length, new Token () {Start = pos});
diff --git a/Samples/common/src/SampleBase.cs b/Samples/common/src/SampleBase.cs
index 0c381048..75f998cd 100644
--- a/Samples/common/src/SampleBase.cs
+++ b/Samples/common/src/SampleBase.cs
@@ -44,17 +44,28 @@ namespace Samples
public Version CrowVersion => Assembly.GetAssembly(typeof(Widget)).GetName().Version;
+ static void showMsgBox (object sender) {
+ Widget w = sender as Widget;
+ Command cmd = w.DataSource as Command;
+ MessageBox.ShowModal(w.IFace, MessageBox.Type.Information, $"{cmd.Caption} CLICKED");
+ }
+
#region Test values for Binding
public CommandGroup Commands, AllCommands;
public CommandGroup EditCommands = new CommandGroup("Edit Commands",
- new Command("Edit command 1", (sender) => MessageBox.ShowModal((sender as Widget).IFace, MessageBox.Type.Information, "Edit comand 1 clicked")),
- new Command("Edit command 2 a bit longer", (sender) => MessageBox.ShowModal((sender as Widget).IFace, MessageBox.Type.Information, "Edit comand 2 clicked"), null, false),
- new Command("Edit command three", (sender) => MessageBox.ShowModal((sender as Widget).IFace, MessageBox.Type.Information, "Edit comand 3 clicked"))
+ new Command("Edit command 1", (sender) => showMsgBox (sender)),
+ new Command("Edit command 2 a bit longer", (sender) => showMsgBox (sender), null, false),
+ new Command("Edit command three", (sender) => showMsgBox (sender)),
+ new CommandGroup("Subedit menu",
+ new Command("Subedit command 1", (sender) => showMsgBox (sender)),
+ new Command("Subedit command 2 a bit longer", (sender) => showMsgBox (sender), null, false),
+ new Command("Subedit command three", (sender) => showMsgBox (sender))
+ )
);
public CommandGroup FileCommands = new CommandGroup("File Commands",
- new Command("File command 1", (sender) => MessageBox.ShowModal((sender as Widget).IFace, MessageBox.Type.Information, "File comand 1 clicked")),
- new Command("File command 2 a bit longer", (sender) => MessageBox.ShowModal((sender as Widget).IFace, MessageBox.Type.Information, "File comand 2 clicked")),
- new Command("File command three", (sender) => MessageBox.ShowModal((sender as Widget).IFace, MessageBox.Type.Information, "File comand 3 clicked"))
+ new Command("File command 1", (sender) => showMsgBox (sender)),
+ new Command("File command 2 a bit longer", (sender) => showMsgBox (sender)),
+ new Command("File command three", (sender) => showMsgBox (sender))
);
void initCommands()
@@ -323,29 +334,38 @@ namespace Samples
string curSources = "";
+ bool boolVal = true;
public string CurSources
{
- get { return curSources; }
- set
- {
+ get => curSources;
+ set {
if (value == curSources)
return;
curSources = value;
NotifyValueChanged(curSources);
}
}
- bool boolVal = true;
public bool BoolVal
{
- get { return boolVal; }
- set
- {
+ get => boolVal;
+ set {
if (boolVal == value)
return;
boolVal = value;
NotifyValueChanged(boolVal);
}
}
+ public Color AllWidgetBackground {
+ get => Configuration.Global.Get<Color> (nameof(AllWidgetBackground));
+ set {
+ if (value == AllWidgetBackground)
+ return;
+ Configuration.Global.Set (nameof(AllWidgetBackground), value);
+ NotifyValueChanged (value);
+ }
+ }
+
+
diff --git a/Samples/common/src/SampleBaseForEditor.cs b/Samples/common/src/SampleBaseForEditor.cs
index 54ad8777..6c6b60b8 100644
--- a/Samples/common/src/SampleBaseForEditor.cs
+++ b/Samples/common/src/SampleBaseForEditor.cs
@@ -101,13 +101,23 @@ namespace Samples
public bool DebugLogToFile {
get => Configuration.Global.Get<bool> (nameof(DebugLogToFile));
set {
- if (DebugLogToFile != value)
+ if (DebugLogToFile == value)
return;
Configuration.Global.Set (nameof(DebugLogToFile), value);
NotifyValueChanged(DebugLogToFile);
DbgLogger.ConsoleOutput = !value;
}
}
+ public string DebugLogFilePath {
+ get => Configuration.Global.Get<string> (nameof (DebugLogFilePath));
+ set {
+ if (CurrentFile == value)
+ return;
+ Configuration.Global.Set (nameof (DebugLogFilePath), value);
+ NotifyValueChanged (DebugLogFilePath);
+ }
+ }
+
protected static void initDebugLog () {
DbgLogger.IncludeEvents = DbgEvtType.None;
DbgLogger.DiscardEvents = DbgEvtType.All;
@@ -279,6 +289,8 @@ namespace Samples
}
public void goUpDirClick (object sender, MouseButtonEventArgs e)
{
+ if (string.IsNullOrEmpty (CurrentDir))
+ return;
string root = Directory.GetDirectoryRoot (CurrentDir);
if (CurrentDir == root)
return;