diff options
Diffstat (limited to 'Samples/common')
| -rw-r--r-- | Samples/common/src/Extensions.cs | 13 | ||||
| -rw-r--r-- | Samples/common/src/ImlParsing/Syntax.cs | 48 | ||||
| -rw-r--r-- | Samples/common/src/SampleBaseForEditor.cs | 7 | ||||
| -rw-r--r-- | Samples/common/ui/Interfaces/menuItem.itmp | 2 |
4 files changed, 40 insertions, 30 deletions
diff --git a/Samples/common/src/Extensions.cs b/Samples/common/src/Extensions.cs index 7647dbc9..02433011 100644 --- a/Samples/common/src/Extensions.cs +++ b/Samples/common/src/Extensions.cs @@ -1,20 +1,25 @@ +using System.IO; using System.Reflection; using Crow; namespace Samples { public static class Extensions { - public static CommandGroup GetCommands (this System.IO.DirectoryInfo di) => + public static CommandGroup GetCommands (this DirectoryInfo di) => new CommandGroup( - new ActionCommand ("Set as root", ()=> {SampleBaseForEditor.CurrentProgramInstance.CurrentDir = di.FullName;}) + new ActionCommand ("Set as root", ()=> {SampleBaseForEditor.CurrentProgramInstance.CurrentDir = di.FullName;})/*, + new ActionCommand ("New Directory", (sender0) => { + Directory.CreateDirectory (Path.Combine (di.FullName, "new directory")); + Widget listContainer = ((sender0 as Widget).LogicalParent as Widget).DataSource as Widget; + })*/ ); - public static CommandGroup GetCommands (this System.IO.FileInfo fi) => + public static CommandGroup GetCommands (this FileInfo fi) => new CommandGroup( new ActionCommand ("Delete", (sender0) => { MessageBox.ShowModal (SampleBaseForEditor.CurrentProgramInstance, MessageBox.Type.YesNo, $"Delete {fi.Name}?").Yes += (sender, e) => { - System.IO.File.Delete(fi.FullName); + File.Delete(fi.FullName); Widget listContainer = ((sender0 as Widget).LogicalParent as Widget).DataSource as Widget; (listContainer.Parent as Group).RemoveChild(listContainer); }; diff --git a/Samples/common/src/ImlParsing/Syntax.cs b/Samples/common/src/ImlParsing/Syntax.cs index 92c9eec3..ddbc6a92 100644 --- a/Samples/common/src/ImlParsing/Syntax.cs +++ b/Samples/common/src/ImlParsing/Syntax.cs @@ -8,13 +8,13 @@ using System.Linq; namespace Crow { public class SyntaxException : Exception { - public readonly Token Token; + public readonly Token Token; public SyntaxException(string message, Token token = default, Exception innerException = null) : base (message, innerException) { Token = token; } } - public class SyntaxAnalyser { + public class SyntaxAnalyser { XmlSource source; IEnumerable<Token> tokens => source.Tokens; public SyntaxNode Root => CurrentNode; @@ -44,7 +44,7 @@ namespace Crow throw new SyntaxException ("Unexpected end of source"); } - Token accept (IEnumerator<Token> iter, TokenType acceptedTokenType) { + Token accept (IEnumerator<Token> iter, TokenType acceptedTokenType) { if (iter.Current.Type == acceptedTokenType) return iter.Current; else @@ -58,7 +58,7 @@ namespace Crow Token eltOpen = iter.Current; moveNextOrThrow (iter); Token eltName = accept (iter, TokenType.ElementName); - + List<SyntaxNode> attributes = readAttributes (iter); if (iter.Current.Type == TokenType.EmptyElementClosing || iter.Current.Type == TokenType.ClosingSign) @@ -70,7 +70,7 @@ namespace Crow Token eltOpen = iter.Current; moveNextOrThrow (iter); Token eltName = accept (iter, TokenType.ElementName); - moveNextOrThrow (iter); + moveNextOrThrow (iter); return new ElementEndTagSyntax(source, eltOpen, eltName, accept (iter, TokenType.ClosingSign)); }*/ @@ -87,7 +87,7 @@ namespace Crow Exceptions = new List<SyntaxException> (); CurrentNode = new IMLRootSyntax (source); previousTok = default; - iter = tokens.GetEnumerator (); + iter = tokens.GetEnumerator (); bool notEndOfSource = iter.MoveNext (); while (notEndOfSource) { @@ -100,7 +100,7 @@ namespace Crow } else if (iter.Current.Type == TokenType.ElementName) tag.NameToken = iter.Current; else if (iter.Current.Type == TokenType.ClosingSign) { - tag.EndToken = iter.Current; + tag.EndToken = iter.Current; CurrentNode = tag.Parent; CurrentNode.RemoveChild (tag); CurrentNode = CurrentNode.AddChild (new ElementSyntax (tag)); @@ -113,13 +113,13 @@ namespace Crow Exceptions.Add (new SyntaxException ("Unexpected Token", iter.Current)); CurrentNode.EndToken = previousTok; CurrentNode = CurrentNode.Parent; - continue; + continue; } } else if (CurrentNode is ElementSyntax elt) { if (iter.Current.Type == TokenType.ElementOpen) CurrentNode = CurrentNode.AddChild (new ElementStartTagSyntax (iter.Current)); - else if (iter.Current.Type == TokenType.EndElementOpen) { - elt.EndTag = new ElementEndTagSyntax (iter.Current); + else if (iter.Current.Type == TokenType.EndElementOpen) { + elt.EndTag = new ElementEndTagSyntax (iter.Current); CurrentNode = elt.AddChild (elt.EndTag); } } else if (CurrentNode is AttributeSyntax attrib) { @@ -139,7 +139,7 @@ namespace Crow Exceptions.Add (new SyntaxException ("Unexpected Token", iter.Current)); CurrentNode.EndToken = previousTok; CurrentNode = CurrentNode.Parent; - continue; + continue; } } else if (CurrentNode is ElementEndTagSyntax eltEndTag) { if (iter.Current.Type == TokenType.ElementName) @@ -151,7 +151,7 @@ namespace Crow Exceptions.Add (new SyntaxException ("Unexpected Token", iter.Current)); eltEndTag.EndToken = eltEndTag.Parent.EndToken = previousTok; CurrentNode = CurrentNode.Parent.Parent; - continue; + continue; } } else if (CurrentNode is IMLRootSyntax) { switch (iter.Current.Type) { @@ -179,11 +179,11 @@ namespace Crow Exceptions.Add (new SyntaxException ("Unexpected Token", iter.Current)); pi.EndToken = previousTok; CurrentNode = CurrentNode.Parent; - continue; + continue; } } } - + previousTok = iter.Current; notEndOfSource = iter.MoveNext (); } @@ -191,16 +191,16 @@ namespace Crow if (!CurrentNode.EndToken.HasValue) CurrentNode.EndToken = previousTok; CurrentNode = CurrentNode.Parent; - } + } } } public class SyntaxNode { public SyntaxNode Parent { get; private set; } List<SyntaxNode> children = new List<SyntaxNode> (); - + public readonly Token StartToken; public Token? EndToken { get; internal set; } - public SyntaxNode (Token tokStart, Token? tokEnd = null) { + public SyntaxNode (Token tokStart, Token? tokEnd = null) { StartToken = tokStart; EndToken = tokEnd; } @@ -271,7 +271,7 @@ namespace Crow protected ElementTagSyntax (Token startTok) : base (startTok) { } - } + } public class ElementStartTagSyntax : ElementTagSyntax { public ElementStartTagSyntax (Token startTok) : base (startTok) { @@ -282,11 +282,11 @@ namespace Crow : base (startTok) { } } - + public class EmptyElementSyntax : SyntaxNode { public readonly ElementStartTagSyntax StartTag; public EmptyElementSyntax (ElementStartTagSyntax startNode) : base (startNode.StartToken, startNode.EndToken) { - StartTag = startNode; + StartTag = startNode; AddChild (StartTag); } } @@ -298,7 +298,7 @@ namespace Crow public override bool IsComplete => base.IsComplete & StartTag.IsComplete & (EndTag != null && EndTag.IsComplete); public ElementSyntax (ElementStartTagSyntax startTag) - : base (startTag.StartToken) { + : base (startTag.StartToken) { StartTag = startTag; AddChild (StartTag); } @@ -307,9 +307,9 @@ namespace Crow public class AttributeSyntax : SyntaxNode { public Token? NameToken { get; internal set; } public Token? EqualToken { get; internal set; } - public Token? ValueOpenToken { get; internal set; } - public Token? ValueCloseToken { get; internal set; } - public Token? ValueToken { get; internal set; } + public Token? ValueOpenToken { get; internal set; } + public Token? ValueCloseToken { get; internal set; } + public Token? ValueToken { get; internal set; } public AttributeSyntax (Token startTok) : base (startTok) {} public override bool IsComplete => base.IsComplete & NameToken.HasValue & EqualToken.HasValue & ValueToken.HasValue & ValueOpenToken.HasValue & ValueCloseToken.HasValue; } diff --git a/Samples/common/src/SampleBaseForEditor.cs b/Samples/common/src/SampleBaseForEditor.cs index b207eea3..5c87226d 100644 --- a/Samples/common/src/SampleBaseForEditor.cs +++ b/Samples/common/src/SampleBaseForEditor.cs @@ -127,7 +127,7 @@ namespace Samples public ActionCommand CMDNew, CMDOpen, CMDSave, CMDSaveAs, CMDQuit, CMDShowLeftPane, CMDUndo, CMDRedo, CMDCut, CMDCopy, CMDPaste, CMDHelp, CMDAbout, CMDOptions; - public CommandGroup EditorCommands => new CommandGroup (CMDUndo, CMDRedo, CMDCut, CMDCopy, CMDPaste, CMDSave, CMDSaveAs); + public CommandGroup EditorFileCommands, EditorEditCommands, EditorAllCommands; protected virtual void initCommands () { CMDNew = new ActionCommand ("New", new Action (onNewFile), "#Icons.blank-file.svg"); @@ -139,6 +139,11 @@ namespace Samples CMDCut = new ActionCommand ("Cut", new Action (cut), "#Icons.scissors.svg", false); CMDCopy = new ActionCommand ("Copy", new Action (copy), "#Icons.copy-file.svg", false); CMDPaste= new ActionCommand ("Paste", new Action (paste), "#Icons.paste-on-document.svg", false); + + EditorFileCommands = new CommandGroup ("File", CMDSave, CMDSaveAs, CMDQuit); + EditorEditCommands = new CommandGroup ("Edit", CMDUndo, CMDRedo, CMDCut, CMDCopy, CMDPaste); + + EditorAllCommands = new CommandGroup (EditorFileCommands, EditorEditCommands); } diff --git a/Samples/common/ui/Interfaces/menuItem.itmp b/Samples/common/ui/Interfaces/menuItem.itmp index 04bc10a6..a129769a 100644 --- a/Samples/common/ui/Interfaces/menuItem.itmp +++ b/Samples/common/ui/Interfaces/menuItem.itmp @@ -7,7 +7,7 @@ <Template> <Label Text="{./Caption}" Width="Stretched" Height="Stretched" Margin="3" Background="{./Background}"/> - </Template> + </Template> <VerticalStack Margin="0" Name="ItemsContainer" Fit="true" Background="Jet"/> </Popper> </ItemTemplate> |