Ejemplo n.º 1
0
        void DocumentTextReplaced(object sender, Mono.TextEditor.ReplaceEventArgs e)
        {
            List <string> vars = template.ParseVariables(textEditor.Document.Text);

            foreach (string var in vars)
            {
                if (!variables.Any(v => v.Name == var) && !template.Variables.Any(v => v.Name == var))
                {
                    variables.Add(new CodeTemplateVariable(var)
                    {
                        Default = GettextCatalog.GetString("notset")
                    });
                }
            }
            for (int i = 0; i < variables.Count; i++)
            {
                CodeTemplateVariable var = variables[i];
                if (!vars.Any(v => v == var.Name))
                {
                    variables.RemoveAt(i);
                    i--;
                }
            }
            this.UpdateVariables();
        }
Ejemplo n.º 2
0
		public static CodeTemplate Read (XmlReader reader)
		{
			Debug.Assert (reader.LocalName == Node);
			
			CodeTemplate result = new CodeTemplate ();
			
			XmlReadHelper.ReadList (reader, Node, delegate () {
				//Console.WriteLine (reader.LocalName);
				switch (reader.LocalName) {
				case HeaderNode:
					XmlReadHelper.ReadList (reader, HeaderNode, delegate () {
						switch (reader.LocalName) {
						case GroupNode:
							result.Group = reader.ReadElementContentAsString ();
							return true;
						case VersionNode:
							result.Version = reader.ReadElementContentAsString ();
							return true;
						case MimeNode:
							result.MimeType = reader.ReadElementContentAsString ();
							return true;
						case ContextNode:
							result.CodeTemplateContext = (CodeTemplateContext)Enum.Parse (typeof (CodeTemplateContext), reader.ReadElementContentAsString ());
							return true;
						case ShortcutNode:
							result.Shortcut = reader.ReadElementContentAsString ();
							return true;
						case DescriptionNode:
							result.Description = reader.ReadElementContentAsString ();
							return true;
						case TemplateTypeNode:
							result.CodeTemplateType = (CodeTemplateType)Enum.Parse (typeof (CodeTemplateType), reader.ReadElementContentAsString ());
							return true;
						}
						return false;
					});
					return true;
				case VariablesNode:
					XmlReadHelper.ReadList (reader, VariablesNode, delegate () {
						//Console.WriteLine ("var:" + reader.LocalName);
						switch (reader.LocalName) {
						case CodeTemplateVariable.Node:
							CodeTemplateVariable var = CodeTemplateVariable.Read (reader);
							result.variableDecarations [var.Name] = var;
							return true;
						}
						return false;
					});
					return true;
				case CodeNode:
					result.Code = reader.ReadElementContentAsString ();
					return true;
				}
				return false;
			});
			//Console.WriteLine ("result:" + result);
			return result;
		}
Ejemplo n.º 3
0
        void CaretPositionChanged(object sender, Mono.TextEditor.DocumentLocationEventArgs e)
        {
            comboboxVariables.Active = -1;
            int offset = textEditor.Caret.Offset;
            int start  = offset;

            while (start >= 0 && start < textEditor.Document.Length)               // caret offset may be behind the text
            {
                char ch = textEditor.Document.GetCharAt(start);
                if (ch == '$')
                {
                    break;
                }
                if (!char.IsLetterOrDigit(ch) && ch != '_')
                {
                    return;
                }
                start--;
            }

            int end = offset;

            while (end < textEditor.Document.Length)
            {
                char ch = textEditor.Document.GetCharAt(end);
                if (ch == '$')
                {
                    break;
                }
                if (!char.IsLetterOrDigit(ch) && ch != '_')
                {
                    return;
                }
                end++;
            }
            if (start >= 0 && end < textEditor.Document.Length)
            {
                string   varName = textEditor.Document.GetTextBetween(start, end).Trim('$');
                TreeIter iter;
                if (variablesListStore.GetIterFirst(out iter))
                {
                    int i = -1;
                    do
                    {
                        i++;
                        CodeTemplateVariable var = (CodeTemplateVariable)variablesListStore.GetValue(iter, 1);
                        if (var.Name == varName)
                        {
                            comboboxVariables.Active = i;
                            break;
                        }
                    } while (variablesListStore.IterNext(ref iter));
                }
            }
        }
Ejemplo n.º 4
0
 public void AddVariable(CodeTemplateVariable var)
 {
     if (variableDecarations.ContainsKey(var.Name))
     {
         if (reportedVariables.Add(var.Name))
         {
             LoggingService.LogWarning("code template duplicate : " + var.Name);
         }
     }
     variableDecarations [var.Name] = var;
 }
        public static CodeTemplateVariable Read(XmlReader reader)
        {
            CodeTemplateVariable result = new CodeTemplateVariable();

            result.Name = reader.GetAttribute(nameAttribute);
            string isEditable = reader.GetAttribute(editableAttribute);

            if (!string.IsNullOrEmpty(isEditable))
            {
                result.IsEditable = Boolean.Parse(isEditable);
            }
            string isIdentifier = reader.GetAttribute(identifierAttribute);

            if (!string.IsNullOrEmpty(isIdentifier))
            {
                result.IsIdentifier = Boolean.Parse(isIdentifier);
            }
            XmlReadHelper.ReadList(reader, Node, delegate()
            {
                //Console.WriteLine ("ctv:" +reader.LocalName);
                switch (reader.LocalName)
                {
                case DefaultNode:
                    result.Default = reader.ReadElementContentAsString();
                    return(true);

                case TooltipNode:
                    result.ToolTip = reader.ReadElementContentAsString();
                    return(true);

                case ValuesNode:
                    XmlReadHelper.ReadList(reader, ValuesNode, delegate()
                    {
                        switch (reader.LocalName)
                        {
                        case ValueNode:
                            string icon = reader.GetAttribute(iconAttribute);
                            string val  = reader.ReadElementContentAsString();
                            result.Values.Add(new CodeTemplateVariableValue(val, icon));
                            return(true);
                        }
                        return(false);
                    });
                    return(true);

                case FunctionNode:
                    result.Function = reader.ReadElementContentAsString();
                    return(true);
                }
                return(false);
            });
            //Console.WriteLine ("return:" + result);
            return(result);
        }
Ejemplo n.º 6
0
 public void AddVariable(CodeTemplateVariable var)
 {
     variableDecarations.Add(var.Name, var);
 }
Ejemplo n.º 7
0
		public static CodeTemplateVariable Read (XmlReader reader)
		{
			CodeTemplateVariable result = new CodeTemplateVariable ();
			result.Name = reader.GetAttribute (nameAttribute);
			string isEditable = reader.GetAttribute (editableAttribute);
			if (!string.IsNullOrEmpty (isEditable))
				result.IsEditable = Boolean.Parse (isEditable);
			string isIdentifier = reader.GetAttribute (identifierAttribute);
			if (!string.IsNullOrEmpty (isIdentifier))
				result.IsIdentifier = Boolean.Parse (isIdentifier);
			XmlReadHelper.ReadList (reader, Node, delegate () {
				//Console.WriteLine ("ctv:" +reader.LocalName);
				switch (reader.LocalName) {
				case DefaultNode:
					result.Default = reader.ReadElementContentAsString ();
					return true;
				case TooltipNode:
					result.ToolTip = reader.ReadElementContentAsString ();
					return true;
				case ValuesNode:
					XmlReadHelper.ReadList (reader, ValuesNode, delegate () {
						switch (reader.LocalName) {
						case ValueNode:
							string icon = reader.GetAttribute (iconAttribute);
							string val  = reader.ReadElementContentAsString ();
							result.Values.Add (new CodeTemplateVariableValue (val, icon));
							return true;
						}
						return false;
					});
					return true;
				case FunctionNode:
					result.Function = reader.ReadElementContentAsString ();
					return true;
				}
				return false;
			});
			//Console.WriteLine ("return:" + result);
			return result;
		}
Ejemplo n.º 8
0
		public void AddVariable (CodeTemplateVariable var)
		{
			variableDecarations.Add (var.Name, var);
		}
Ejemplo n.º 9
0
 void FillVariableTree(CodeTemplateVariable var)
 {
     grid.CurrentObject = var;
 }
Ejemplo n.º 10
0
		void FillVariableTree (CodeTemplateVariable var)
		{
			grid.CurrentObject = var;
		}