示例#1
0
        private void _TextChanged(object sender, TextChangedEventArgs e)
        {
            AmandaTagParser parser = new AmandaTagParser();

            parser.Parse(textBox.Text);

            // Set isEdited to true so the we can ask the user to save the file when he closes the program.
            //
            if (!IsEdited)
            {
                IsEdited = true;
            }

            e.ChangedRange.ClearStyle(KeywordStyle, CommentStyle, ConstantStyle, FunctionStyle);

            e.ChangedRange.SetStyle(KeywordStyle, @"\b(where|if|else|True|False|otherwise)\b");
            e.ChangedRange.SetStyle(CommentStyle, @"\|\|.*");                          //comments ||...
            e.ChangedRange.SetStyle(ConstantStyle, @"\b(\B-)?[0-9]+\b");               //numbers 123, -123, to be removed?
            e.ChangedRange.SetStyle(ConstantStyle, @"""[^""\\]*(?:\\.[^""\\]*)*""?");  //string "", source: stackoverflow
            e.ChangedRange.SetStyle(ConstantStyle, @"'[^'\\]*(?:\\.[^'\\]*)*'?");      //char ''

            foreach (string functionName in parser.AmandaTags.Select(q => q.Name))
            {
                e.ChangedRange.SetStyle(FunctionStyle, @"\b" + functionName + @"\b");
            }
        }
示例#2
0
        private void _AutoIndentNeeded(object sender, AutoIndentEventArgs e)
        {
            Match isOtherwiseRegex = Regex.Match(e.LineText.Trim(), ",* otherwise");
            int   currentIndent    = e.LineText.TakeWhile(q => q == ' ').Count(); //shouldn't be too inefficient
            int   at = e.LineText.IndexOf('=');

            AmandaTagParser tagParser = new AmandaTagParser();

            tagParser.Parse(textBox.Text);

            /*
             *              All these todo's might not be neccessary, it's pretty good right now
             */
            //If the line contains a where, we want the next lines to be indented by a tab
            if (Regex.IsMatch(e.LineText, "where"))
            {
                e.ShiftNextLines = e.TabLength;
            }

            //if the line is a condition, we want to find the '=' and indent to there, that's how youre supposed to do conditions in amanda
            else if (Regex.IsMatch(e.LineText.Trim(), ",* if"))
            {
                e.ShiftNextLines = at - currentIndent;
            }

            //If line is empty | prev line is empty | contains otherwise (which indicates the end of an if/else statement)
            else if (e.LineText.Trim() == "" || e.PrevLineText.Trim().Count() == 0 || Regex.IsMatch(e.LineText.Trim(), ",* otherwise") == true)
            {
                //Get the tag based on our current line, if we are at line 3, and there is a big function going from line 1-5, it will return that.
                AmandaTag tag = tagParser.GetTag(e.iLine);
                if (tag != null)
                {
                    e.ShiftNextLines = tag.BeginLocation.X - at;
                }

                //No function found? No problem, resort to a tab
                else
                {
                    e.ShiftNextLines = -e.TabLength;
                }
            }
        }
示例#3
0
        public FileEditorTab(string content)
        {
            Text = "Untitled";

            UseVisualStyleBackColor = true;
            textBox                   = new FastColoredTextBox();
            textBox.AllowDrop         = true;
            textBox.KeyDown          += _KeyDown;
            textBox.TextChanged      += _TextChanged;
            textBox.AutoIndentNeeded += _AutoIndentNeeded;
            textBox.Dock              = DockStyle.Fill;
            textBox.Text              = content;

            autocomplete = new AutocompleteMenu(textBox);
            autocomplete.MinFragmentLength = 1;
            autocomplete.Items.MaximumSize = new System.Drawing.Size(200, 300);
            autocomplete.Items.Width       = 400;

            amandaTagParser = new AmandaTagParser();

            saveDialog.Filter = "Amanda File|*.ama";

            Controls.Add(textBox);
        }
示例#4
0
        public FileEditorTab(string content)
        {
            Text = "Untitled";

            UseVisualStyleBackColor = true;
            textBox = new FastColoredTextBox();
            textBox.AllowDrop = true;
            textBox.KeyDown += _KeyDown;
            textBox.TextChanged += _TextChanged;
            textBox.AutoIndentNeeded += _AutoIndentNeeded;
            textBox.Dock = DockStyle.Fill;
            textBox.Text = content;

            autocomplete = new AutocompleteMenu(textBox);
            autocomplete.MinFragmentLength = 1;
            autocomplete.Items.MaximumSize = new System.Drawing.Size(200, 300);
            autocomplete.Items.Width = 400;

            amandaTagParser = new AmandaTagParser();

            saveDialog.Filter = "Amanda File|*.ama";

            Controls.Add(textBox);
        }
示例#5
0
        private void _TextChanged(object sender, TextChangedEventArgs e)
        {
            AmandaTagParser parser = new AmandaTagParser();
            parser.Parse(textBox.Text);

            // Set isEdited to true so the we can ask the user to save the file when he closes the program.
            //
            if (!IsEdited) IsEdited = true;

            e.ChangedRange.ClearStyle(KeywordStyle, CommentStyle, ConstantStyle, FunctionStyle);

            e.ChangedRange.SetStyle(KeywordStyle, @"\b(where|if|else|True|False|otherwise)\b");
            e.ChangedRange.SetStyle(CommentStyle, @"\|\|.*");                          //comments ||...
            e.ChangedRange.SetStyle(ConstantStyle, @"\b(\B-)?[0-9]+\b");                  //numbers 123, -123, to be removed?
            e.ChangedRange.SetStyle(ConstantStyle, @"""[^""\\]*(?:\\.[^""\\]*)*""?");   //string "", source: stackoverflow
            e.ChangedRange.SetStyle(ConstantStyle, @"'[^'\\]*(?:\\.[^'\\]*)*'?");       //char ''

            foreach(string functionName in parser.AmandaTags.Select(q => q.Name))
            {
                e.ChangedRange.SetStyle(FunctionStyle, @"\b" + functionName + @"\b" );
            }
        }
示例#6
0
        private void _AutoIndentNeeded(object sender, AutoIndentEventArgs e)
        {
            Match isOtherwiseRegex = Regex.Match(e.LineText.Trim(), ",* otherwise");
            int currentIndent = e.LineText.TakeWhile(q => q == ' ').Count();    //shouldn't be too inefficient
            int at = e.LineText.IndexOf('=');

            AmandaTagParser tagParser = new AmandaTagParser();
            tagParser.Parse(textBox.Text);

            /*
             *              All these todo's might not be neccessary, it's pretty good right now
             */
            //If the line contains a where, we want the next lines to be indented by a tab
            if (Regex.IsMatch(e.LineText, "where"))
            {
                e.ShiftNextLines = e.TabLength;
            }

            //if the line is a condition, we want to find the '=' and indent to there, that's how youre supposed to do conditions in amanda
            else if (Regex.IsMatch(e.LineText.Trim(), ",* if"))
            {
                e.ShiftNextLines = at - currentIndent;
            }

            //If line is empty | prev line is empty | contains otherwise (which indicates the end of an if/else statement)
            else if (e.LineText.Trim() == "" || e.PrevLineText.Trim().Count() == 0 || Regex.IsMatch(e.LineText.Trim(), ",* otherwise") == true)
            {
                //Get the tag based on our current line, if we are at line 3, and there is a big function going from line 1-5, it will return that.
                AmandaTag tag = tagParser.GetTag(e.iLine);
                if (tag != null)
                {
                    e.ShiftNextLines = tag.BeginLocation.X - at;
                }

                //No function found? No problem, resort to a tab
                else
                {
                    e.ShiftNextLines = -e.TabLength;
                }
            }
        }