예제 #1
0
        private void syntaxEditorFilename_TriggerActivated(object sender, TriggerEventArgs e)
        {
            string      language = "";
            TokenStream stream   = syntaxEditorFilename.Document.GetTokenStream(syntaxEditorFilename.Document.Tokens.IndexOf(
                                                                                    syntaxEditorFilename.SelectedView.Selection.EndOffset - 1));
            string allWords = "";

            if (stream.Position > 0)
            {
                DynamicToken token = (DynamicToken)stream.ReadReverse();
                language = token.LexicalState.Language.Key;
                int endPos   = syntaxEditorFilename.SelectedView.Selection.EndOffset - 1;
                int startPos = syntaxEditorFilename.Document.Text.LastIndexOf('#', endPos) + 1;
                allWords = syntaxEditorFilename.Document.Text.Substring(startPos, endPos - startPos);
            }
            switch (e.Trigger.Key)
            {
            case "MemberListTrigger":
                SetupIntelliPromptList(allWords);

                // Show the list
                if (syntaxEditorFilename.IntelliPrompt.MemberList.Count > 0)
                {
                    syntaxEditorFilename.IntelliPrompt.MemberList.Show();
                }
                return;
            }
        }
예제 #2
0
        private void MarkError(ParserSyntaxError error)
        {
            //DocumentPosition pos = ;
            int                offset         = error.StartOffset == -1 ? editor.Document.PositionToOffset(new DocumentPosition(error.LineNumber, 0)) : error.StartOffset;
            DynamicToken       token          = (DynamicToken)editor.Document.Tokens.GetTokenAtOffset(offset);
            SpanIndicatorLayer indicatorLayer = editor.Document.SpanIndicatorLayers[ErrorLayerKey];
            SpanIndicator      indicator      = new WaveLineSpanIndicator("ErrorIndicator", Color.Red);

            if (indicatorLayer == null)
            {
                indicatorLayer = new SpanIndicatorLayer(ErrorLayerKey, 1);
                editor.Document.SpanIndicatorLayers.Add(indicatorLayer);
            }
            int startOffset = Math.Min(token.StartOffset, indicatorLayer.Document.Length - 1);
            int length      = Math.Max(token.Length, 1);

            if (startOffset < 0)
            {
                return;                 // don't add indicators for errors without an offset.
            }
            SpanIndicator[] indicators = indicatorLayer.GetIndicatorsForTextRange(new ActiproSoftware.SyntaxEditor.TextRange(startOffset, startOffset + length));
            foreach (SpanIndicator i in indicators)
            {
                // If there is already an error indicator on that word, don't add another one.
                if (i.TextRange.StartOffset == startOffset && i.TextRange.Length == length)
                {
                    continue;
                }
            }
            indicatorLayer.Add(indicator, startOffset, length);
        }
예제 #3
0
        /// <summary>Update the current context.</summary>
        public void UpdateContext(IContext globalContext)
        {
            // update config tokens
            foreach (IToken token in this.StandardContext.Tokens.Values)
            {
                if (token.IsMutable)
                {
                    token.UpdateContext(this);
                }
            }

            // reset dynamic tokens
            foreach (DynamicToken token in this.DynamicContext.Tokens.Values)
            {
                token.SetValidInContext(false);
            }
            foreach (DynamicTokenValue tokenValue in this.DynamicTokenValues)
            {
                if (tokenValue.Conditions.Values.All(p => p.IsMatch(this)))
                {
                    DynamicToken token = this.DynamicContext.Tokens[tokenValue.Name];
                    token.SetValue(tokenValue.Value);
                    token.SetValidInContext(true);
                }
            }
        }
예제 #4
0
        /// <summary>Add a dynamic token value to the context.</summary>
        /// <param name="tokenValue">The token to add.</param>
        public void Add(DynamicTokenValue tokenValue)
        {
            // validate
            if (this.ParentContext.Contains(tokenValue.Name, enforceContext: false))
            {
                throw new InvalidOperationException($"Can't register a '{tokenValue}' token because there's a global token with that name.");
            }
            if (this.LocalContext.Contains(tokenValue.Name, enforceContext: false))
            {
                throw new InvalidOperationException($"Can't register a '{tokenValue.Name}' dynamic token because there's a config token with that name.");
            }

            // get (or create) token
            if (!this.DynamicContext.Tokens.TryGetValue(tokenValue.Name, out DynamicToken token))
            {
                this.DynamicContext.Save(token = new DynamicToken(tokenValue.Name, this.Scope));
            }

            // add token value
            token.AddTokensUsed(tokenValue.GetTokensUsed());
            token.AddAllowedValues(tokenValue.Value);
            this.DynamicTokenValues.Add(tokenValue);

            // track tokens which should trigger an update to this token
            Queue <string>   tokenQueue = new Queue <string>(tokenValue.GetTokensUsed());
            InvariantHashSet visited    = new InvariantHashSet();

            while (tokenQueue.Any())
            {
                // get token name
                string tokenName = tokenQueue.Dequeue();
                if (!visited.Add(tokenName))
                {
                    continue;
                }

                // if the current token uses other tokens, they may affect the being added too
                IToken curToken = this.GetToken(tokenName, enforceContext: false);
                foreach (string name in curToken.GetTokensUsed())
                {
                    tokenQueue.Enqueue(name);
                }
                if (curToken is DynamicToken curDynamicToken)
                {
                    foreach (string name in curDynamicToken.GetPossibleTokensUsed())
                    {
                        tokenQueue.Enqueue(name);
                    }
                }

                // add dynamic value as a dependency of the current token
                if (!this.TokenDependents.TryGetValue(curToken.Name, out InvariantHashSet used))
                {
                    this.TokenDependents.Add(curToken.Name, used = new InvariantHashSet());
                }
                used.Add(tokenValue.Name);
            }
        }
예제 #5
0
		private void MarkErrorWord(SyntaxEditor editor, int lineNumber, int characterPos, string message)
		{
			string text = editor.Document.Lines[lineNumber].Text;
			string compileText = CompileHelper.ReplaceUserOptionCalls(text);
			string preceedingText = characterPos <= compileText.Length ? compileText.Substring(0, characterPos) : "";

			#region Find all GetUserOption calls and discount them

			int index = preceedingText.LastIndexOf("GetUserOption");
			int offsetUO = "GetUserOptionValue('')".Length - "UserOptions.".Length;
			int castEndPos = 0;
			int castStartPos = 0;

			while (index >= 0)
			{
				characterPos -= offsetUO;

				while (preceedingText[index] != ')')
				{
					castEndPos = index;
					index -= 1;
				}
				while (preceedingText[index] != '(')
				{
					castStartPos = index;
					index -= 1;
				}
				characterPos -= castEndPos - castStartPos + 1;
				index = preceedingText.LastIndexOf("GetUserOption", index);
			}

			#endregion

			DocumentPosition position = new DocumentPosition(lineNumber, characterPos);
			int offset = editor.Document.PositionToOffset(position);
			DynamicToken token = (DynamicToken)editor.Document.Tokens.GetTokenAtOffset(offset);
			SpanIndicator indicator = new WaveLineSpanIndicator("ErrorIndicator", Color.Red);
			indicator.Tag = message;
			SpanIndicatorLayer indicatorLayer = editor.Document.SpanIndicatorLayers[ErrorLayerKey];

			if (indicatorLayer == null)
			{
				indicatorLayer = new SpanIndicatorLayer(ErrorLayerKey, 1);
				editor.Document.SpanIndicatorLayers.Add(indicatorLayer);
			}
			int startOffset = Math.Min(token.StartOffset, indicatorLayer.Document.Length - 1);
			int length = Math.Max(token.Length, 1);
			SpanIndicator[] indicators = indicatorLayer.GetIndicatorsForTextRange(new TextRange(startOffset, startOffset + length));

			foreach (SpanIndicator i in indicators)
			{
				// If there is already an error indicator on that word, don't add another one.
				if (i.TextRange.StartOffset == startOffset && i.TextRange.Length == length)
					return;
			}
			indicatorLayer.Add(indicator, startOffset, length);
		}
예제 #6
0
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="scope">The mod namespace in which the token is accessible.</param>
 /// <param name="parentContext">The initial parent context that provides non-patch-specific tokens, if any.</param>
 public SinglePatchContext(string scope, IContext parentContext = null)
 {
     this.LastParentContext = parentContext;
     this.CustomTokens      = new IToken[]
     {
         this.TargetToken            = new DynamicToken(ConditionType.Target.ToString(), scope),
         this.TargetWithoutPathToken = new DynamicToken(ConditionType.TargetWithoutPath.ToString(), scope)
     };
 }
예제 #7
0
        /// <summary>Set a dynamic token value.</summary>
        /// <param name="name">The token name.</param>
        /// <param name="value">The token value.</param>
        public void SetLocalValue(string name, ITokenString value)
        {
            if (!this.LocalTokens.TryGetValue(name, out DynamicToken token))
            {
                this.LocalTokens[name] = token = new DynamicToken(name, this.Scope);
            }

            token.SetValue(value);
            token.SetReady(true);
        }
        /// <summary>Update the current context.</summary>
        /// <param name="globalContext">The global token context.</param>
        /// <param name="globalChangedTokens">The global token values which changed, or <c>null</c> to update all tokens.</param>
        public void UpdateContext(IContext globalContext, InvariantHashSet globalChangedTokens)
        {
            // get affected tokens (or null to update all tokens)
            InvariantHashSet affectedTokens = null;

            if (globalChangedTokens != null)
            {
                affectedTokens = new InvariantHashSet();
                foreach (string globalToken in globalChangedTokens)
                {
                    foreach (string affectedToken in this.GetTokensAffectedBy(globalToken))
                    {
                        affectedTokens.Add(affectedToken);
                    }
                }

                if (!affectedTokens.Any())
                {
                    return;
                }
            }

            // update local standard tokens
            foreach (IToken token in this.LocalContext.Tokens.Values)
            {
                if (token.IsMutable && affectedTokens?.Contains(token.Name) != false)
                {
                    token.UpdateContext(this);
                }
            }

            // reset dynamic tokens
            // note: since token values are affected by the order they're defined, only updating tokens affected by globalChangedTokens is not trivial.
            foreach (DynamicToken token in this.DynamicContext.Tokens.Values)
            {
                token.SetValue(null);
                token.SetReady(false);
            }
            foreach (DynamicTokenValue tokenValue in this.DynamicTokenValues)
            {
                tokenValue.UpdateContext(this);
                if (tokenValue.IsReady && tokenValue.Conditions.All(p => p.IsMatch(this)))
                {
                    DynamicToken token = this.DynamicContext.Tokens[tokenValue.Name];
                    token.SetValue(tokenValue.Value);
                    token.SetReady(true);
                }
            }
        }
예제 #9
0
        public ActionResult IndexToken(int?page, int?pagesize, string name, string first)
        {
            dynamic data = new System.Dynamic.ExpandoObject();

            if (name == null)
            {
                name = "";
            }
            var list = _tokenRepos.GetTokenById(name);

            int _page     = page.HasValue ? page.Value : 1;
            int _pagesize = pagesize.HasValue ? pagesize.Value : 12;
            var vs        = list.ToPagedList(_page, _pagesize);
            var firstone  = new DynamicToken();

            if (first != null && first != "")
            {
                firstone = list.FirstOrDefault(p => p.TokenCode == first);
                var firspage = vs.IndexOf(firstone);
                if (firspage == -1)
                {
                    vs.Insert(0, firstone);
                }
                else if (firspage > 0)
                {
                    vs.Remove(firstone);
                    vs.Insert(0, firstone);
                }
            }
            data.name       = name;
            data.list       = vs;
            data.pageSize   = _pagesize;
            data.pageIndex  = _page;
            data.totalCount = vs.TotalCount;
            string otherparam = "";

            if (name != "")
            {
                otherparam += "&name=" + name;
            }
            data.otherParam = otherparam;
            return(PartialView(data));
        }
예제 #10
0
        private void MarkErrorWord(ActiproSoftware.SyntaxEditor.SyntaxEditor editor, int lineNumber, int characterPos, string message)
        {
            //string text = editor.Document.Lines[lineNumber].Text;
            //string preceedingText = characterPos <= compileText.Length ? compileText.Substring(0, characterPos) : "";

            ActiproSoftware.SyntaxEditor.DocumentPosition position = new ActiproSoftware.SyntaxEditor.DocumentPosition(lineNumber, characterPos);
            int          offset = editor.Document.PositionToOffset(position);
            DynamicToken token  = (DynamicToken)editor.Document.Tokens.GetTokenAtOffset(offset);

            ActiproSoftware.SyntaxEditor.SpanIndicator indicator = new ActiproSoftware.SyntaxEditor.WaveLineSpanIndicator("ErrorIndicator", Color.Red);
            indicator.Tag = message;
            ActiproSoftware.SyntaxEditor.SpanIndicatorLayer indicatorLayer = new ActiproSoftware.SyntaxEditor.SpanIndicatorLayer("kk", 1);
            editor.Document.SpanIndicatorLayers.Add(indicatorLayer);
            int startOffset = Math.Min(token.StartOffset, indicatorLayer.Document.Length - 1);
            int length      = Math.Max(token.Length, 1);

            indicatorLayer.Add(indicator, startOffset, length);

            syntaxEditor1.Document.Lines[lineNumber].BackColor = Slyce.Common.Colors.BackgroundColor;
            syntaxEditor1.SelectedView.GoToLine(lineNumber, (lineNumber > 2) ? 2 : 0); // Allow 2 blank lines above selection
        }
예제 #11
0
        /// <summary>Add a dynamic token value to the context.</summary>
        /// <param name="tokenValue">The token to add.</param>
        public void Add(DynamicTokenValue tokenValue)
        {
            // validate
            if (this.GlobalContext.Contains(tokenValue.Name, enforceContext: false))
            {
                throw new InvalidOperationException($"Can't register a '{tokenValue.Name}' token because there's a global token with that name.");
            }
            if (this.StandardContext.Contains(tokenValue.Name, enforceContext: false))
            {
                throw new InvalidOperationException($"Can't register a '{tokenValue.Name}' dynamic token because there's a config token with that name.");
            }

            // get (or create) token
            if (!this.DynamicContext.Tokens.TryGetValue(tokenValue.Name, out DynamicToken token))
            {
                this.DynamicContext.Save(token = new DynamicToken(tokenValue.Name));
            }

            // add token value
            token.AddAllowedValues(tokenValue.Value);
            this.DynamicTokenValues.Add(tokenValue);
        }
        public void AddContentPack(ContentPackObject contentPack)
        {
            Dictionary <string, DynamicToken> configTokens = new Dictionary <string, DynamicToken>();

            foreach (var entry in contentPack.Config)
            {
                DynamicToken token = new DynamicToken(entry.Key);
                token.AddValue(new TokenValue(entry.Value, true));
                configTokens.Add(entry.Key, token);
            }

            if (contentPack.Config.Count < 1)
            {
                foreach (var token in contentPack.Content.ConfigSchema)
                {
                    if (token.Value.Default != null)
                    {
                        contentPack.Config.Add(token.Key, token.Value.Default);
                    }
                    else if (token.Value.AllowValues != null)
                    {
                        contentPack.Config.Add(token.Key, token.Value.AllowValues.Split(',')[0]);
                    }
                }
            }

            foreach (var dynamicToken in contentPack.Content.DynamicTokens)
            {
                if (!this.DynamicTokenManager.DynamicTokens.TryGetValue(dynamicToken.Name, out var token))
                {
                    token = new DynamicToken(dynamicToken.Name);
                    this.DynamicTokenManager.AddToken(token);
                }

                List <TokenEntry> parsedWhen = new List <TokenEntry>();
                foreach (var entry in dynamicToken.When)
                {
                    parsedWhen.Add(new TokenEntry(entry.Key, entry.Value));
                }

                List <TokenEntry> when = new List <TokenEntry>();

                bool enabled = true;
                foreach (var entry in parsedWhen)
                {
                    if (contentPack.Config.TryGetValue(entry.Name, out var value))
                    {
                        if ((entry.IsConditional && entry.Condition.RawString.Equals(value) != value.ToLower().Equals("true")) ||
                            !entry.Values.Contains(value))
                        {
                            enabled = false;
                            break;
                        }
                    }
                    else
                    {
                        when.Add(entry);
                    }
                }

                token.AddValue(new DynamicTokenValue(dynamicToken.Value, enabled, this.DynamicTokenManager, when));
            }

            foreach (var change in contentPack.Content.Changes)
            {
                if (!(change.Action.Equals("Load") || change.Action.Equals("EditImage")) ||
                    change.Enabled.ToLower().Equals("false") ||
                    !change.FromFile.ToLower().EndsWith(".png"))
                {
                    continue;
                }

                List <TokenEntry> parsedWhen = new List <TokenEntry>();
                foreach (var entry in change.When)
                {
                    parsedWhen.Add(new TokenEntry(entry.Key, entry.Value));
                }

                List <TokenEntry> when = new List <TokenEntry>();

                bool enabled = true;
                foreach (var entry in parsedWhen)
                {
                    if (contentPack.Config.TryGetValue(entry.Name, out var value))
                    {
                        if ((entry.IsConditional && entry.Condition.Parse(this.DynamicTokenManager.DynamicTokens).Equals(value) != value.ToLower().Equals("true")) ||
                            !entry.Values.Contains(value))
                        {
                            enabled = false;
                            break;
                        }
                    }
                    else
                    {
                        when.Add(entry);
                    }
                }
                if (!enabled)
                {
                    continue;
                }

                string[] targetSplit = change.Target.Split(',');
                foreach (string targetStr in targetSplit)
                {
                    string targetStrFix = targetStr;
                    if (targetStr.StartsWith(" "))
                    {
                        targetStrFix = targetStr.Substring(1);
                    }

                    StringWithTokens target  = new StringWithTokens(targetStrFix.Replace("/", $"\\")).Parse(configTokens);
                    StringWithTokens file    = new StringWithTokens(change.FromFile).Parse(configTokens);
                    bool             overlay = change.Patchmode.ToLower().Equals("overlay");

                    Rectangle fromArea = new Rectangle(change.FromArea.X * 2, change.FromArea.Y * 2, change.FromArea.Width * 2, change.FromArea.Height * 2);
                    Rectangle toArea   = new Rectangle(change.ToArea.X * 2, change.ToArea.Y * 2, change.ToArea.Width * 2, change.ToArea.Height * 2);

                    ContentPackAsset asset = new ContentPackAsset(this, contentPack, target, file, when, fromArea, toArea, overlay);

                    this.ContentPackAssets.Add(asset);
                }
            }
        }
예제 #13
0
        public ActionResult IndexToken(int? page, int? pagesize, string name,string first)
        {
            dynamic data = new System.Dynamic.ExpandoObject();
            if (name == null) name = "";
            var list = _tokenRepos.GetTokenById(name);

            int _page = page.HasValue ? page.Value : 1;
            int _pagesize = pagesize.HasValue ? pagesize.Value : 12;
            var vs = list.ToPagedList(_page, _pagesize);
            var firstone = new DynamicToken();
            if (first != null && first != "")
            {
                firstone = list.FirstOrDefault(p => p.TokenCode == first);
                var firspage = vs.IndexOf(firstone);
                if (firspage == -1)
                {
                    vs.Insert(0, firstone);
                }
                else if (firspage > 0)
                {
                    vs.Remove(firstone);
                    vs.Insert(0, firstone);
                }
            }
            data.name = name;
            data.list = vs;
            data.pageSize = _pagesize;
            data.pageIndex = _page;
            data.totalCount = vs.TotalCount;
            string otherparam = "";
            if (name != "") otherparam += "&name=" + name;
            data.otherParam = otherparam;
            return PartialView(data);
        }