示例#1
0
        /// <summary>
        /// Implements Intellisense dropdown.
        /// </summary>
        /// <param name="editor"></param>
        /// <param name="currentFunction"></param>
        public static void GetIntelliSenseList(ref SyntaxEditor editor, FunctionInfo currentFunction)
        {
            Editor = editor;

            if (Editor.IntelliPrompt.MemberList.ImageList == null)
            {
                Editor.IntelliPrompt.MemberList.ImageList = SyntaxEditor.ReflectionImageList;
            }
            Editor.IntelliPrompt.MemberList.HideOnParentFormDeactivate = true;
            Editor.IntelliPrompt.MemberList.MatchBasedOnItemPreText = true;
            Editor.IntelliPrompt.MemberList.Clear();
            string fullTypeString = GetFullString();

            if (fullTypeString == "UserOptions")
            {
                ListAllUserOptions(null);
                return;
            }
            if (fullTypeString.Length > 0)
            {
                // Process in order of least expensive to most expensive
                if (FindInUserOptions(fullTypeString)) { return; }
                if (FindInFunctions(fullTypeString)) { return; }
                if (FindInFunctionParameters(currentFunction, fullTypeString)) { return; }
                AddedProperties.Clear();
                if (FindInLocalVariables(fullTypeString, editor)) { return; }
                if (FindInAssemblies(fullTypeString)) { return; }
            }
        }
示例#2
0
        /// <summary>
        /// AutoCompletes the current word.
        /// </summary>
        /// <param name="editor"></param>
        /// <param name="currentFunction"></param>
        public static void AutoComplete(ref SyntaxEditor editor, FunctionInfo currentFunction)
        {
            try
            {
                InAutoCompleteMode = true;
                Editor = editor;

                if (Editor.IntelliPrompt.MemberList.ImageList == null)
                {
                    Editor.IntelliPrompt.MemberList.ImageList = SyntaxEditor.ReflectionImageList;
                }
                Editor.IntelliPrompt.MemberList.HideOnParentFormDeactivate = true;
                Editor.IntelliPrompt.MemberList.MatchBasedOnItemPreText = true;
                Editor.IntelliPrompt.MemberList.Clear();
                string fullTypeString = GetFullString();

                if (fullTypeString.Length > 0)
                {
                    // Process in order of least expensive to most expensive
                    AutoCompleteSpecialWords(fullTypeString);
                    AutoCompleteUserOptions(fullTypeString);
                    AutoCompleteConstants(fullTypeString);
                    AutoCompleteFunctions(fullTypeString);
                    AutoCompleteLocalVariables(fullTypeString, editor);
                    AutoCompleteFunctionParameters(currentFunction, fullTypeString);
                    if (FindInAssemblies(fullTypeString) && !InAutoCompleteMode) { return; }
                }
            }
            finally
            {
                InAutoCompleteMode = false;
            }
        }
示例#3
0
        private string GetText(FunctionInfo function, int startPos)
        {
            string body;

            for (int i = 0; i < SearchHelper.FoundLocations.Count; i++)
            {
                if (SearchHelper.FoundLocations[i].Function == function)
                {
                    body = SearchHelper.FoundLocations[i].Body;

                    if (body.Length == 0)
                    {
                        continue;
                    }
                    int lineStart = startPos;

                    // Find the start of the line
                    while (lineStart > 0 && lineStart < body.Length)
                    {
                        if (body[lineStart] == '\n' ||
                            body[lineStart] == '\r')
                        {
                            lineStart += 1;
                            break;
                        }
                        lineStart -= 1;
                    }
                    int lineEnd = lineStart;// startPos;

                    // Find the end of the line
                    while (lineEnd > 0 && lineEnd < body.Length)
                    {
                        if (body[lineEnd] == '\n' ||
                            body[lineEnd] == '\r')
                        {
                            //lineEnd -= 1;
                            break;
                        }
                        lineEnd += 1;
                    }
                    // Get the text of the line in question
                    int textLength = lineEnd - lineStart;
                    string returnVal = "";

                    if (textLength > 0 && lineStart > 0 && lineStart < body.Length && (lineStart + textLength) < body.Length)
                    {
                        returnVal = body.Substring(lineStart, textLength);

                        if (returnVal.Length > 0)
                        {
                            // Remove any tabs from the line text
                            returnVal = returnVal.Replace("\t", "  ");
                        }
                    }
                    return returnVal;
                }
            }
            return "";
        }
 public CompiledToTemplateLineLookup(FunctionInfo function, int templateLineNumber, int templateColumn, int compiledColumn, int snippetLength)
 {
     Function = function;
     TemplateLineNumber = templateLineNumber;
     TemplateColumn = templateColumn;
     CompiledColumn = compiledColumn;
     SnippetLength = snippetLength;
 }
示例#5
0
 /// <summary>
 /// Copy constructor
 /// </summary>
 /// <param name="o"></param>
 public FunctionInfo(FunctionInfo o)
 {
     Name = o.Name;
     ReturnType = o.ReturnType;
     Parameters = o.Parameters;
     Body = o.Body;
     IsTemplateFunction = o.IsTemplateFunction;
     ScriptLanguage = o.ScriptLanguage;
     Description = o.Description;
     TemplateReturnLanguage = o.TemplateReturnLanguage;
     Category = o.Category;
     IsExtensionMethod = o.IsExtensionMethod;
     ExtendedType = o.ExtendedType;
 }
        public void The_Write_Method_Creates_The_Correct_XML()
        {
            ProjectSerialiserV1 serialiser = new ProjectSerialiserV1(fileController);
            FunctionInfo functionInfo = new FunctionInfo("Function", typeof(string), "Body", true, SyntaxEditorHelper.ScriptLanguageTypes.CSharp, "desc", "C#", "Gen");
            functionInfo.Parameters.Add(new ParamInfo("varName", typeof(int)){Modifiers = "static"});

            StringBuilder sb = new StringBuilder();
            XmlWriter writer = XmlWriter.Create(sb, new XmlWriterSettings{OmitXmlDeclaration = true});
            serialiser.WriteFunctionXML(functionInfo, writer);
            writer.Close();

            string output = XmlSqueezer.RemoveWhitespaceBetweenElements(sb.ToString());
            Assert.That(output, Is.EqualTo(expectedXml));
        }
        public frmFunctionWizard(FunctionInfo function, bool isNewFunction)
        {
            InitializeComponent();
            Instance = this;
            ucHeading1.Text = "";
            BackColor = Slyce.Common.Colors.BackgroundColor;

            IsDeleted = false;
            MustRefreshFunctionList = false;
            IsNewFunction = isNewFunction;
            CurrentFunction = function;
            // Clone the function.
            TempFunction =  new FunctionInfo(CurrentFunction);
            Controller.ShadeMainForm();
            bool dirtyStatus = Project.Instance.IsDirty;
            CurrentFunction = function;
            ContentItems.Add(new FunctionWizardScreens.Screen1());
            ContentItems.Add(new FunctionWizardScreens.Screen2());
            ContentItems.Add(new FunctionWizardScreens.Screen3());
            LoadScreen(ContentItems[0]);
            Project.Instance.IsDirty = dirtyStatus;
        }
        private void mnuItemEdit_Click(object sender, EventArgs e)
        {
            if (treeFiles.SelectedNodes.Count == 0)
            {
                MessageBox.Show(this, "Select a folder first.", "No Folder Selected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            if (treeFiles.SelectedNodes.Count > 1)
            {
                throw new Exception("Only one node can be selected.");
            }
            try
            {
                Node selectedNode = treeFiles.SelectedNodes[0];
                TagInfo ti = (TagInfo)selectedNode.Tag;

                if (ti.FileType == TagInfo.FileTypes.Folder)
                {
                    string id = ((TagInfo)selectedNode.Tag).Id;
                    OutputFolder folder = Project.Instance.FindFolder(id);
                    Wizards.frmOutputFileWizard.FileType = Wizards.frmOutputFileWizard.FileTypes.Folder;
                    Wizards.frmOutputFileWizard form = new Wizards.frmOutputFileWizard();
                    Wizards.frmOutputFileWizard.FileName = selectedNode.Text;
                    Wizards.frmOutputFileWizard.IterationType = folder.IteratorType;

                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        if (folder != null)
                        {
                            folder.Name = Wizards.frmOutputFileWizard.FileName;
                            folder.IteratorType = Wizards.frmOutputFileWizard.IterationType;
                        }
                        Project.Instance.IsDirty = true;
                        selectedNode.Text = folder.Name;
                        selectedNode.Cells[(int)CellTypes.Iterator].Text = folder.IteratorType == null ? "" : folder.IteratorType.FullName;
                    }
                }
                else //if (ti.FileType == TagInfo.FileTypes.ScriptFile)
                {
                    string id = ((TagInfo)selectedNode.Tag).Id;
                    OutputFile file = Project.Instance.FindFile(id);

                    Wizards.frmOutputFileWizard.StaticSkipFunction = Wizards.frmOutputFileWizard.SkipFunctionChoice.DontUse;

                    if (ti.FileType == TagInfo.FileTypes.ScriptFile)
                    {
                        Wizards.frmOutputFileWizard.FileType = Wizards.frmOutputFileWizard.FileTypes.Script;
                        Wizards.frmOutputFileWizard.FunctionName = selectedNode.Cells[(int)CellTypes.Function].Text;
                        Wizards.frmOutputFileWizard.StaticFileName = "";

                        if (!string.IsNullOrEmpty(file.IteratorTypes))
                        {
                            Wizards.frmOutputFileWizard.IterationType = Project.Instance.GetTypeFromReferencedAssemblies(file.IteratorTypes, false);
                        }
                        else
                        {
                            Wizards.frmOutputFileWizard.IterationType = null;
                        }
                    }
                    else
                    {
                        Wizards.frmOutputFileWizard.FileType = Wizards.frmOutputFileWizard.FileTypes.Static;
                        Wizards.frmOutputFileWizard.StaticFileName = file.StaticFileName;
                        Wizards.frmOutputFileWizard.FunctionName = file.StaticFileSkipFunctionName;
                        Wizards.frmOutputFileWizard.IterationType = file.StaticFileIterator;
                    }
                    Wizards.frmOutputFileWizard form = new Wizards.frmOutputFileWizard();
                    Wizards.frmOutputFileWizard.FileName = selectedNode.Text;
                    FunctionInfo func = Project.Instance.FindFunctionSingle(Wizards.frmOutputFileWizard.FunctionName);

                    if (func != null && func.Parameters.Count > 0)
                    {
                        Wizards.frmOutputFileWizard.IterationType = func.Parameters[0].DataType;
                    }
                    bool showFunctions = false;

                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        if (Wizards.frmOutputFileWizard.ShowNewFunctionWizardOnClose &&
                            Wizards.frmOutputFileWizard.StaticSkipFunction == Wizards.frmOutputFileWizard.SkipFunctionChoice.DontUse)
                        {
                            Controller.Instance.MainForm.Refresh();
                            FunctionInfo newFunc = Controller.Instance.MainForm.UcFunctions.NewFunction(Wizards.frmOutputFileWizard.IterationType);

                            if (newFunc != null)
                            {
                                Wizards.frmOutputFileWizard.FunctionName = newFunc.Name;
                                showFunctions = true;
                            }
                        }
                        else if (Wizards.frmOutputFileWizard.StaticSkipFunction == Wizards.frmOutputFileWizard.SkipFunctionChoice.CreateNew)
                        {
                            FunctionInfo newFunction = new FunctionInfo(
                                                            NamingHelper.CleanNameCSharp(Wizards.frmOutputFileWizard.StaticFileName) + "_SkipFile",
                                                                typeof(bool), "return false;", false, SyntaxEditorHelper.ScriptLanguageTypes.CSharp,
                                                                "Returns true if the static file should be skipped and not generated", "plain text", "Skip Static Files");

                            Project.Instance.AddFunction(newFunction);
                            Wizards.frmFunctionWizard functionForm = new Wizards.frmFunctionWizard(newFunction, true);

                            if (functionForm.ShowDialog(ParentForm) == DialogResult.Cancel)
                            {
                                Project.Instance.DeleteFunction(newFunction);
                                //OwnerTabStripPage.TabStrip.Pages.Remove(OwnerTabStripPage);
                            }
                            file.StaticFileSkipFunctionName = newFunction.Name;
                        }
                        else if (Wizards.frmOutputFileWizard.StaticSkipFunction == Wizards.frmOutputFileWizard.SkipFunctionChoice.UseExisting)
                        {
                            file.StaticFileSkipFunctionName = Wizards.frmOutputFileWizard.FunctionName;
                        }

                        file.Name = Wizards.frmOutputFileWizard.FileName;
                        file.ScriptName = Wizards.frmOutputFileWizard.FunctionName;
                        Project.Instance.IsDirty = true;
                        selectedNode.Text = file.Name;

                        switch (Wizards.frmOutputFileWizard.FileType)
                        {
                            case Wizards.frmOutputFileWizard.FileTypes.Script:
                                file.FileType = OutputFileTypes.Script;
                                ti.FileType = TagInfo.FileTypes.ScriptFile;
                                selectedNode.Cells[(int)CellTypes.Function].Text = file.ScriptName;
                                selectedNode.Cells[(int)CellTypes.Iterator].Text = file.IteratorTypes;
                                break;
                            case Wizards.frmOutputFileWizard.FileTypes.Static:
                                file.FileType = OutputFileTypes.File;
                                file.StaticFileIterator = Wizards.frmOutputFileWizard.IterationType;
                                ti.FileType = TagInfo.FileTypes.NormalFile;
                                selectedNode.Cells[(int)CellTypes.Function].Text = "[File] " + Wizards.frmOutputFileWizard.StaticFileName;

                                if (file.StaticFileIterator != null)
                                {
                                    selectedNode.Cells[(int)CellTypes.Iterator].Text = file.StaticFileIterator.FullName;
                                    selectedNode.Cells[(int)CellTypes.Iterator].StyleNormal = treeFiles.Styles["functionLinkStyle"];
                                    selectedNode.Cells[(int)CellTypes.Iterator].StyleMouseOver = treeFiles.Styles["functionLinkHoverStyle"];
                                    selectedNode.Cells[(int)CellTypes.Iterator].Cursor = Cursors.Hand;
                                }
                                if (string.IsNullOrEmpty(file.StaticFileSkipFunctionName) == false)
                                {
                                    selectedNode.Cells[(int)CellTypes.SkipFunction].Text = file.StaticFileSkipFunctionName;
                                    selectedNode.Cells[(int)CellTypes.SkipFunction].StyleNormal = treeFiles.Styles["functionLinkStyle"];
                                    selectedNode.Cells[(int)CellTypes.SkipFunction].StyleMouseOver = treeFiles.Styles["functionLinkHoverStyle"];
                                    selectedNode.Cells[(int)CellTypes.SkipFunction].Cursor = Cursors.Hand;
                                }
                                break;
                            default:
                                throw new NotImplementedException("Filetype not handled yet: " + Wizards.frmOutputFileWizard.FileType.ToString());
                        }
                        selectedNode.Tag = ti;

                    }
                    if (showFunctions)
                    {
                        Controller.Instance.MainForm.HidePanelControls(Controller.Instance.MainForm.UcFunctions);
                    }
                }
            }
            finally
            {
                Controller.Instance.MainForm.Activate();
            }
        }
示例#9
0
        /// <summary>
        /// Gets a comma-separated list of parameters and their data-types for the function signature.
        /// </summary>
        /// <param name="function"></param>
        /// <returns></returns>
        private string GetParameterListAsString(FunctionInfo function)
        {
            string paramList = "";

            for (int i = 0; i < function.Parameters.Count; i++)
            {
                ParamInfo param = function.Parameters[i];

                if (param.Modifiers.Length > 0)
                {
                    paramList += param.Modifiers + " ";
                }
                paramList +=
                    string.Format("{0} {1}",
                                  Utility.GetDemangledGenericTypeName(param.DataType, Project.Instance.Namespaces).Replace("+", "."),
                                  param.Name);

                if (i < function.Parameters.Count - 1)
                {
                    paramList += ", ";
                }
            }
            return paramList;
        }
示例#10
0
        private TabItem CreateNewFunctionTabPage(FunctionInfo function, bool allowEdit)
        {
            TabItem newPage = new TabItem();
            TabControlPanel panel = new TabControlPanel();
            panel.TabItem = newPage;
            panel.Dock = DockStyle.Fill;
            newPage.AttachedControl = panel;
            newPage.Text = function.Name;
            newPage.ImageIndex = 0;
            newPage.Tag = function;
            newPage.CloseButtonVisible = true;
            ucFunction funcPanel = new ucFunction();
            funcPanel.Dock = DockStyle.Fill;
            funcPanel.AllowEdit = allowEdit;
            newPage.AttachedControl.Controls.Add(funcPanel);
            funcPanel.FunctionName = function.Name;
            funcPanel.CurrentFunction = function;
            //funcPanel.DefaultValueFunction = defaultValueFunction;
            funcPanel.Populate();

            switch (SyntaxEditorHelper.GetScriptingLanguage(function.ScriptLanguage))
            {
                case TemplateContentLanguage.CSharp:
                    newPage.ImageIndex = 3;
                    break;
                case TemplateContentLanguage.VbDotNet:
                    newPage.ImageIndex = 5;
                    break;
                case TemplateContentLanguage.Sql:
                    newPage.ImageIndex = 0;
                    break;
                case TemplateContentLanguage.Html:
                    newPage.ImageIndex = 4;
                    break;
                case TemplateContentLanguage.Css:
                    newPage.ImageIndex = 2;
                    break;
                case TemplateContentLanguage.IniFile:
                    newPage.ImageIndex = 0;
                    break;
                case TemplateContentLanguage.JScript:
                    newPage.ImageIndex = 0;
                    break;
                case TemplateContentLanguage.Python:
                    newPage.ImageIndex = 0;
                    break;
                case TemplateContentLanguage.VbScript:
                    newPage.ImageIndex = 5;
                    break;
                case TemplateContentLanguage.Xml:
                    newPage.ImageIndex = 6;
                    break;
                case TemplateContentLanguage.PlainText:
                    newPage.ImageIndex = 0;
                    break;
                default:
                    throw new Exception("This function return type not handled yet in ShowFunction: " +
                                        funcPanel.ReturnType);
            }

            return newPage;
        }
示例#11
0
        private void buttonAddPreGenerationFunction_Click(object sender, EventArgs e)
        {
            FunctionInfo function = new FunctionInfo(TemplateHelper.PreGenerationModelProcessingFunctionName, null, "", false,
                                                     SyntaxEditorHelper.ScriptLanguageTypes.CSharp,
                                                     "Initialises the Provider from the template before generation of the files",
                                                     "C#", "General");

            function.AddParameter(new ParamInfo("providerInfo", typeof(ProviderInfo)));
            function.AddParameter(new ParamInfo("data", typeof(PreGenerationData)));

            Project.Instance.AddFunction(function);

            Controller.Instance.MainForm.ShowFunction(function, this);
            RibbonBarController.RefreshButtonStatus(this);
        }
示例#12
0
        public ucFunction GetFunctionPanel(FunctionInfo function)
        {
            foreach (TabItem tab in tabStrip1.Tabs)
            {
                ucFunction functionScreen = (ucFunction)tab.AttachedControl.Controls["ucFunction"];

                if (functionScreen.CurrentFunction == function)
                {
                    return functionScreen;
                }
            }
            ShowFunction(function, null);

            foreach (TabItem tab in tabStrip1.Tabs)
            {
                ucFunction functionScreen = (ucFunction)tab.AttachedControl.Controls["ucFunction"];

                if (functionScreen.CurrentFunction == function)
                {
                    return functionScreen;
                }
            }
            throw new Exception("We shouldn't be here.");
        }
示例#13
0
 private static void FindInText(string text, string textToFind, Scope scope, FunctionInfo function, bool isTemplateFunction, FindReplaceOptions options)
 {
     FindInText(text, textToFind, scope, function, isTemplateFunction, options, -1, false);
 }
示例#14
0
        public FunctionInfo GetDisplayToUserFunction()
        {
            FunctionInfo function = new FunctionInfo(VariableName + "_DisplayToUser", typeof(bool), DisplayToUserFunctionBody, false,
                                                     SyntaxEditorHelper.ScriptLanguageTypes.CSharp, Description, "", Category);

            if (IteratorType != null)
            {
                function.Parameters.Add(new ParamInfo(IteratorType.Name.ToLower(), IteratorType));
            }

            return function;
        }
示例#15
0
        public FunctionInfo GetDefaultValueFunction()
        {
            FunctionInfo function = new FunctionInfo(VariableName + "_DefaultValue", VarType, DefaultValueFunctionBody, false,
                                                     SyntaxEditorHelper.ScriptLanguageTypes.CSharp, Description, "", Category);

            if(IteratorType != null)
            {
                function.Parameters.Add(new ParamInfo(IteratorType.Name.ToLower(), IteratorType));
            }

            return function;
        }
示例#16
0
        public FunctionInfo NewFunction(Type parameterTypeForNewScriptFunction)
        {
            FunctionInfo newFunction =
                new FunctionInfo("NewFunction", typeof(string), "", true,
                                         SyntaxEditorHelper.ScriptLanguageTypes.CSharp, "", "plain text", "");

            if (parameterTypeForNewScriptFunction != null)
            {
                string paramName = parameterTypeForNewScriptFunction.Name.Replace("[]", "s");
                paramName = paramName.Substring(0, 1).ToLower() + paramName.Substring(1);

                if (paramName.IndexOf("List<") == 0)
                {
                    paramName = paramName.Replace("List<", "").Replace(">", "") + "s";
                }
                string cleanParamName = "";

                for (int i = 0; i < paramName.Length; i++)
                {
                    if (char.IsLetterOrDigit(paramName[i]))
                    {
                        cleanParamName += paramName[i];
                    }
                }

                newFunction.Parameters.Add(new ParamInfo(cleanParamName, parameterTypeForNewScriptFunction));
            }
            Project.Instance.AddFunction(newFunction);
            frmFunctionWizard form = new frmFunctionWizard(newFunction, true);

            if (form.ShowDialog(ParentForm) == DialogResult.Cancel)
            {
                Project.Instance.DeleteFunction(newFunction);
                //OwnerTabStripPage.TabStrip.Pages.Remove(OwnerTabStripPage);
                return null;
            }
            ShowFunction(frmFunctionWizard.CurrentFunction, true, null);
            return newFunction;
        }
示例#17
0
        private static bool FindInFunctionParameters(FunctionInfo function, string fullString)
        {
            string[] words = fullString.Split('.');

            if (function != null)
            {
                for (int i = 0; i < function.Parameters.Count; i++)
                {
                    // Get the full type
                    ParamInfo param = function.Parameters[i];

                    if (param.Name == words[0])
                    {
                        //Type parentType = GetTypeFromAssemblies(param.DataType, words.Length == 1);
                        Type parentType = param.DataType;

                        if (parentType != null)
                        {
                            string[] subWords = new string[words.Length - 1];
                            Array.Copy(words, 1, subWords, 0, words.Length - 1);

                            return ProcessChildren(parentType, subWords);
                        }
                    }
                }
            }
            return false;
        }
示例#18
0
 public void ShowFunction(FunctionInfo function, Control callingControl)
 {
     if (function != null)
     {
         ShowFunction(function, true, callingControl);
     }
 }
示例#19
0
        private static void AutoCompleteFunctionParameters(FunctionInfo function, string fullString)
        {
            string[] words = fullString.ToLower().Split('.');

            for (int i = 0; i < function.Parameters.Count; i++)
            {
                if (words.Length == 1 && function.Parameters[i].Name.ToLower().IndexOf(words[0]) == 0)
                {
                    // AutoComplete
                    IntelliPromptMemberListItem item = new IntelliPromptMemberListItem(function.Parameters[i].Name, (int)ActiproSoftware.Products.SyntaxEditor.IconResource.PublicField, "(parameter) " + function.Parameters[i].DataType + " " + function.Parameters[i].Name);
                    bool alreadyExists = false;

                    for (int itemCounter = 0; itemCounter < Editor.IntelliPrompt.MemberList.Count; itemCounter++)
                    {
                        if (Editor.IntelliPrompt.MemberList[itemCounter].Text == function.Parameters[i].Name)
                        {
                            alreadyExists = true;
                            break;
                        }
                    }
                    if (!alreadyExists)
                    {
                        Editor.IntelliPrompt.MemberList.Add(item);
                    }
                }
            }
        }
示例#20
0
        private void MarkErrorsForFunction(FunctionInfo function, ListViewItem clickedNode)
        {
            if (!Controller.Instance.MainForm.ShowFunction(function, null))
            {
                return;
            }
            int line;
            //string charPosString;
            SyntaxEditor editor = ((ucFunction)Controller.Instance.MainForm.UcFunctions.tabStrip1.SelectedTab.AttachedControl.Controls["ucFunction"]).syntaxEditor1;

            foreach (ListViewItem node in listErrors.Items)
            {
                if (node.Tag != function)
                {
                    // Not the correct function, so skip
                    continue;
                }

                if (int.TryParse(node.SubItems[(int)ErrorListColumns.Line].Text, out line))
                {
                    int charPos;
                    if (int.TryParse(node.SubItems[(int)ErrorListColumns.CharPos].Text, out charPos) && charPos >= 0)
                    {
                        MarkErrorWord(editor, line, charPos, node.SubItems[(int)ErrorListColumns.Description].Text);
                    }
                }
            }
            // Highlight the line referred to by the clicked node
            if (int.TryParse(clickedNode.SubItems[(int)ErrorListColumns.Line].Text, out line))
            {
                int startOffset = editor.Document.Lines[line].StartOffset;
                editor.SelectedView.Selection.StartOffset = startOffset;
                editor.SelectedView.Selection.EndOffset = editor.SelectedView.Selection.StartOffset;
                editor.SelectedView.Selection.SelectToLineStart();
                editor.SelectedView.Selection.SelectToLineEnd();
                editor.SelectedView.ScrollLineToVisibleMiddle();
            }
        }
        public void AddNewFile()
        {
            if (treeFiles.SelectedNodes.Count == 0)
            {
                MessageBox.Show(this, "Select a folder to add this file to first.", "No Folder Selected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            if (treeFiles.SelectedNodes.Count > 1)
            {
                throw new Exception("Only one node can be selected.");
            }

            Node selectedNode = treeFiles.SelectedNodes[0];
            TagInfo ti = (TagInfo)selectedNode.Tag;

            if (ti.FileType != TagInfo.FileTypes.Folder)
            {
                MessageBox.Show(this, "A file cannot be added as a child of a file. Select a parent folder", "No Folder Selected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            Cursor = Cursors.WaitCursor;

            try
            {
                Refresh();
                Wizards.frmOutputFileWizard.IterationType = null;
                Wizards.frmOutputFileWizard.FileType = Wizards.frmOutputFileWizard.FileTypes.Script;
                Wizards.frmOutputFileWizard.FileName = "";
                Wizards.frmOutputFileWizard.StaticFileName = "";
                Wizards.frmOutputFileWizard.FunctionName = "";
                Wizards.frmOutputFileWizard form = new Wizards.frmOutputFileWizard();
                bool showFunctions = false;

                if (form.ShowDialog() == DialogResult.OK)
                {
                    var createNewFunction = Wizards.frmOutputFileWizard.ShowNewFunctionWizardOnClose &&
                            (Wizards.frmOutputFileWizard.StaticSkipFunction == Wizards.frmOutputFileWizard.SkipFunctionChoice.DontUse
                            || Wizards.frmOutputFileWizard.FileType == Wizards.frmOutputFileWizard.FileTypes.Script);
                    if (createNewFunction)
                    {
                        Controller.Instance.MainForm.Refresh();
                        FunctionInfo newFunc = Controller.Instance.MainForm.UcFunctions.NewFunction(Wizards.frmOutputFileWizard.IterationType);

                        if (newFunc != null)
                        {
                            Wizards.frmOutputFileWizard.FunctionName = newFunc.Name;
                            showFunctions = true;
                        }
                    }
                    else if (Wizards.frmOutputFileWizard.StaticSkipFunction == Wizards.frmOutputFileWizard.SkipFunctionChoice.CreateNew)
                    {
                        FunctionInfo newFunction = new FunctionInfo(
                                                        NamingHelper.CleanNameCSharp(Wizards.frmOutputFileWizard.StaticFileName) + "_SkipFile",
                                                            typeof(bool), "return false;", false, SyntaxEditorHelper.ScriptLanguageTypes.CSharp,
                                                            "Returns true if the static file should be skipped and not generated", "plain text", "Skip Static Files");

                        Project.Instance.AddFunction(newFunction);
                        Wizards.frmFunctionWizard functionForm = new Wizards.frmFunctionWizard(newFunction, true);

                        if (functionForm.ShowDialog(ParentForm) == DialogResult.Cancel)
                        {
                            Project.Instance.DeleteFunction(newFunction);
                            //OwnerTabStripPage.TabStrip.Pages.Remove(OwnerTabStripPage);
                        }
                    }

                    string id = ((TagInfo)selectedNode.Tag).Id;

                    OutputFolder folder = Project.Instance.FindFolder(id);

                    if (folder != null)
                    {
                        OutputFile file;

                        if (Wizards.frmOutputFileWizard.FileType == Wizards.frmOutputFileWizard.FileTypes.Static)
                        {
                            file = new OutputFile(Wizards.frmOutputFileWizard.FileName, OutputFileTypes.File, "", Guid.NewGuid().ToString());
                            file.StaticFileName = Wizards.frmOutputFileWizard.StaticFileName;
                            file.StaticFileIterator = Wizards.frmOutputFileWizard.IterationType;
                            file.StaticFileSkipFunctionName = Wizards.frmOutputFileWizard.StaticSkipFunctionName;
                        }
                        else if (Wizards.frmOutputFileWizard.FileType == Wizards.frmOutputFileWizard.FileTypes.Script)
                        {
                            file = new OutputFile(Wizards.frmOutputFileWizard.FileName, OutputFileTypes.Script, Wizards.frmOutputFileWizard.FunctionName, Guid.NewGuid().ToString());
                            file.IteratorFunction = Project.Instance.FindFunctionSingle(Wizards.frmOutputFileWizard.FunctionName);
                        }
                        else
                        {
                            throw new NotImplementedException("Not catered for yet.");
                        }
                        folder.AddFile(file);
                        Node newFileNode = AddFileNode(selectedNode, file);
                        selectedNode.Expanded = true;
                        treeFiles.SelectedNode = newFileNode;
                    }
                    else
                    {
                        MessageBox.Show(this, "No matching folder found.", "No matching folder", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                    Project.Instance.IsDirty = true;
                }
                if (showFunctions)
                {
                    Controller.Instance.MainForm.HidePanelControls(Controller.Instance.MainForm.UcFunctions);
                }
            }
            finally
            {
                Controller.Instance.MainForm.Activate();
                Cursor = Cursors.Default;
            }
        }
示例#22
0
 public FoundLocation(FunctionInfo function, int startPos, int length)
 {
     Function = function;
     StartPos = startPos;
     Length = length;
 }
示例#23
0
        public FunctionInfo GetValidatorFunction()
        {
            FunctionInfo function = new FunctionInfo(VariableName + "_Validator", typeof(bool), ValidatorFunctionBody, false,
                                                     SyntaxEditorHelper.ScriptLanguageTypes.CSharp, Description, "", Category);

            if (IteratorType != null)
            {
                function.Parameters.Add(new ParamInfo(IteratorType.Name.ToLower(), IteratorType));
            }
            function.Parameters.Add(new ParamInfo("failReason", typeof(string), "out"));
            return function;
        }
示例#24
0
        /// <summary>
        /// Fills FoundLocations with positions in the text.
        /// </summary>
        /// <param name="text"></param>
        /// <param name="textToFind"></param>
        /// <param name="scope"></param>
        /// <param name="function"></param>
        /// <param name="isTemplateFunction"></param>
        /// <param name="options"></param>
        /// <param name="userOffset"></param>
        /// <param name="findOneOnly"></param>
        /// <returns></returns>
        private static bool FindInText(string text, string textToFind, Scope scope, FunctionInfo function, bool isTemplateFunction, FindReplaceOptions options, int userOffset, bool findOneOnly)
        {
            text = text.Replace("\r\n", "\n");
            // TODO: this function is in dire need of refactoring. The searching code is repeated in multiple places.
            bool found = false;

            if (string.IsNullOrEmpty(textToFind))
            {
                return false;
            }
            if (!isTemplateFunction)
            {
                // Only template functions should have 'script' and 'output'
                scope = Scope.Both;
            }
            if (!options.MatchCase)
            {
                text = text.ToLower();
                textToFind = textToFind.ToLower();
            }
            int scriptStartPos = 0;
            int scriptEndPos = 0;
            int nextPos;

            switch (scope)
            {
                case Scope.ScriptOnly:
                    for (int i = 0; i < text.Length; i++)
                    {
                        if (text[i] == '<' &&
                            text.Length > (i + 1) &&
                            text[i + 1] == '%')
                        {
                            scriptStartPos = i + 2;
                        }
                        else if (text[i] == '%' &&
                            text.Length > (i + 1) &&
                            text[i + 1] == '>')
                        {
                            scriptEndPos = i;
                            // Replace text
                            string script = text.Substring(scriptStartPos, scriptEndPos - scriptStartPos);
                            nextPos = script.IndexOf(textToFind);

                            while (nextPos >= 0)
                            {
                                if (!options.MatchWholeWord ||
                                    (options.MatchWholeWord && IsWholeWord(ref script, ref textToFind, ref nextPos)))
                                {
                                    m_foundLocations.Add(new FoundLocation(function, scriptStartPos + nextPos, textToFind.Length));

                                    if (scriptStartPos + nextPos > userOffset)
                                    {
                                        found = true;

                                        if (findOneOnly)
                                        {
                                            m_foundLocations.Clear();
                                            m_foundLocations.Add(new FoundLocation(function, scriptStartPos + nextPos, textToFind.Length));
                                            return found;
                                        }
                                    }
                                }
                                nextPos = script.IndexOf(textToFind, nextPos + 1);
                            }
                            i = scriptEndPos + 2;
                        }
                    }
                    break;
                case Scope.OutputOnly:
                    scriptStartPos = 0; // This works for template functions only

                    for (int i = 0; i < text.Length; i++)
                    {
                        if (text[i] == '%' &&
                            text.Length > (i + 1) &&
                            text[i + 1] == '>')
                        {
                            scriptStartPos = i + 2;
                        }
                        else if (text[i] == '<' &&
                            text.Length > (i + 1) &&
                            text[i + 1] == '%')
                        {
                            scriptEndPos = i;
                            // Replace text
                            string script = text.Substring(scriptStartPos, scriptEndPos - scriptStartPos);
                            nextPos = script.IndexOf(textToFind);

                            while (nextPos >= 0)
                            {
                                if (!options.MatchWholeWord ||
                                    (options.MatchWholeWord && IsWholeWord(ref text, ref textToFind, ref nextPos)))
                                {
                                    m_foundLocations.Add(new FoundLocation(function, scriptStartPos + nextPos, textToFind.Length));

                                    if (scriptStartPos + nextPos > userOffset)
                                    {
                                        found = true;

                                        if (findOneOnly)
                                        {
                                            m_foundLocations.Clear();
                                            m_foundLocations.Add(new FoundLocation(function, scriptStartPos + nextPos, textToFind.Length));
                                            return found;
                                        }
                                    }
                                }
                                nextPos = script.IndexOf(textToFind, nextPos + 1);
                            }
                            i = scriptEndPos + 2;
                        }
                    }
                    // Search the remaining text
                    if (scriptEndPos < text.Length)
                    {
                        string script = text.Substring(scriptStartPos);
                        nextPos = script.IndexOf(textToFind);

                        while (nextPos >= 0)
                        {
                            if (!options.MatchWholeWord ||
                                    (options.MatchWholeWord && IsWholeWord(ref text, ref textToFind, ref nextPos)))
                            {
                                m_foundLocations.Add(new FoundLocation(function, scriptStartPos + nextPos, textToFind.Length));

                                if (scriptStartPos + nextPos > userOffset)
                                {
                                    found = true;

                                    if (findOneOnly)
                                    {
                                        m_foundLocations.Clear();
                                        m_foundLocations.Add(new FoundLocation(function, scriptStartPos + nextPos, textToFind.Length));
                                        return found;
                                    }
                                }
                            }
                            nextPos = script.IndexOf(textToFind, nextPos + 1);
                        }
                    }
                    break;
                case Scope.Both:
                    nextPos = text.IndexOf(textToFind);

                    while (nextPos >= 0)
                    {
                        if (!options.MatchWholeWord ||
                                    (options.MatchWholeWord && IsWholeWord(ref text, ref textToFind, ref nextPos)))
                        {
                            m_foundLocations.Add(new FoundLocation(function, nextPos, textToFind.Length));

                            if (scriptStartPos + nextPos > userOffset)
                            {
                                found = true;

                                if (findOneOnly)
                                {
                                    m_foundLocations.Clear();
                                    m_foundLocations.Add(new FoundLocation(function, nextPos, textToFind.Length));
                                    return found;
                                }
                            }
                        }
                        nextPos = text.IndexOf(textToFind, nextPos + 1);
                    }
                    break;
                default:
                    throw new NotImplementedException("Not coded yet");
            }
            return found;
        }
 protected virtual string GetFilenameFor(FunctionInfo func)
 {
     return(func.Name + ".function.xml");
 }
        public void The_Create_Method_Writes_One_File()
        {
            IProjectSerialiser serialiser = new ProjectSerialiserV1(fileController);
            FunctionInfo functionInfo = new FunctionInfo("Function", typeof(string), "Body", true, SyntaxEditorHelper.ScriptLanguageTypes.CSharp, "desc", "C#", "Gen");
            serialiser.CreateFunctionFiles(new []{functionInfo}, "Folder");

            fileController.AssertWasCalled(f => f.WriteAllText(Arg<string>.Is.Equal("Folder\\Function.function.xml"), Arg<string>.Is.NotNull));
        }
示例#27
0
        public static FunctionInfo CreateFunctionInfoFrom(ApiExtensionMethod extMethod)
        {
            MethodInfo method = extMethod.ExtendedMethod;

            string formattedCode = extMethod.OverridingFunctionBody;

            if (extMethod.HasOverride == false && string.IsNullOrEmpty(extMethod.DefaultCode) == false)
            {
                CSharpParser parser = new CSharpParser();
                parser.FormatSettings.MaintainWhitespace = false;

                string methodText = string.Format("public void {0} () {{ {1} }}", method.Name, extMethod.DefaultCode);

                var bc = parser.ParseSingleConstruct(methodText, BaseConstructType.MethodDeclaration);

                // Remove the start and end braces
                formattedCode = Utility.StandardizeLineBreaks(bc.ToString(), "\n");
                // + 1 to get past the {, +1 to remove the first line break.
                formattedCode = formattedCode.Substring(formattedCode.IndexOf('{')+2);
                formattedCode = formattedCode.Substring(0, formattedCode.LastIndexOf('}')-1);

                formattedCode = RemoveTabs(formattedCode);
            }

            FunctionInfo fi = new FunctionInfo(
                method.Name,
                method.ReturnType,
                formattedCode,
                true,
                SyntaxEditorHelper.ScriptLanguageTypes.CSharp,
                extMethod.Description,
                "C#",
                "Extension Methods");

            return fi;
        }
示例#28
0
        private void buttonAddLoadFunction_Click(object sender, EventArgs e)
        {
            FunctionInfo function = new FunctionInfo(TemplateHelper.LoadFunctionName, null, "", false,
                                                     SyntaxEditorHelper.ScriptLanguageTypes.CSharp,
                                                     "Loads any additional information from an existing Workbench project",
                                                     "C#", "General");

            function.AddParameter(new ParamInfo("outputFolder", typeof(string)));
            function.AddParameter(new ParamInfo("provider", typeof(IEnumerable<ProviderInfo>)));
            function.AddParameter(new ParamInfo("extraData", typeof(TemplateData)));

            Project.Instance.AddFunction(function);

            Controller.Instance.MainForm.ShowFunction(function, this);
            RibbonBarController.RefreshButtonStatus(this);
        }
示例#29
0
 /// <summary>
 /// Determines and sets the language of the 'text' or 'ASP' text is. This
 /// allows us to use the correct syntax file to display syntax highlighting
 /// in CreateDirectiveXmlToCSharpLanguage.
 /// </summary>
 private void SetTextLanguage(FunctionInfo currentFunction)
 {
     if (currentFunction.IsTemplateFunction)
     {
         Project.Instance.TextLanguage =
             SyntaxEditorHelper.LanguageEnumFromName(currentFunction.TemplateReturnLanguage);
     }
     else
     {
         // TODO: create plain text syntax file and set it here
         Project.Instance.TextLanguage = TemplateContentLanguage.CSharp;
     }
 }
示例#30
0
        private void buttonAddProjectScreensFunction_Click(object sender, EventArgs e)
        {
            FunctionInfo function = new FunctionInfo(TemplateHelper.CustomNewProjectScreensFunctionName, null, "", false,
                                                     SyntaxEditorHelper.ScriptLanguageTypes.CSharp,
                                                     "Creates a list of custom screens that should be shown during the creation of new Workbench projects.",
                                                     "C#", "General");

            function.AddParameter(new ParamInfo("screens", typeof(List<INewProjectScreen>), "out"));

            Project.Instance.AddFunction(function);

            Controller.Instance.MainForm.ShowFunction(function, this);
            RibbonBarController.RefreshButtonStatus(this);
        }
示例#31
0
        public bool ShowFunction(FunctionInfo function,
									bool allowEdit,
									Control callingControl)
        {
            if (function == null) return false;

            try
            {
                Cursor = Cursors.WaitCursor;
                CallingControl = callingControl;
                lblStatus.Visible = false;
                tabStrip1.Visible = true;

                for (int i = 0; i < tabStrip1.Tabs.Count; i++)
                {
                    if (GetFunctionScreenByTabIndex(i).CurrentFunction == function)
                    {
                        tabStrip1.SelectedTabIndex = i;
                        Controller.Instance.MainForm.MenuItemDebug.Enabled = true;
                        return true;
                    }
                }
                TabItem newPage = CreateNewFunctionTabPage(function, allowEdit);
                newPage.MouseUp += newPage_MouseUp;
                tabStrip1.Controls.Add(newPage.AttachedControl);
                tabStrip1.Tabs.Insert(0, newPage);
                tabStrip1.SelectedTabIndex = 0;
                Controller.Instance.MainForm.MenuItemDebug.Enabled = true;
                Controller.Instance.MainForm.ShowMenuBarFor(this);
            }
            finally
            {
                Cursor = Cursors.Default;
            }
            return true;
        }