<commit_before>﻿/*
 * Copyright © 2017 EDDiscovery development team
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
 * file except in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under
 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
 * ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 * 
 * EDDiscovery is not affiliated with Frontier Developments plc.
 */
using BaseUtils.Win32Constants;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Conditions;

namespace ActionLanguage
{
    public partial class ActionPackEditorForm : ExtendedControls.DraggableForm
    {
        ActionFile actionfile;      // file we are editing
        string applicationfolder;   // folder where the file is
        ActionCoreController actioncorecontroller;  // need this for some access to data
        List<ActionEvent> events;   // list of events, UIs
        List<string> grouptypenames;    // groupnames extracted from events
        Dictionary<string, List<string>> groupeventlist;    // events per group name, extracted from events
        string initialtitle;

        const int panelxmargin = 3;
        const int panelymargin = 1;

        class Group     // this top level form has a list of groups, each containing a grouptype CBC, a delete button, and a UC containing its controls
        {
            public Panel panel;
            public ExtendedControls.ComboBoxCustom grouptype;
            public ExtendedControls.ButtonExt delete;
            public ActionPackEditBase usercontrol;              
        }

        List<Group> groups; // the groups

        public Func<string, List<string>> AdditionalNames;                          // Call back when we need more variable names, by event string
        public Func<string, Condition, ActionPackEditBase> CreateActionPackEdit;    // must set, given a group and condition, what editor do you want? change the condition if you need to

        #region Init

        public ActionPackEditorForm() 
        {
            InitializeComponent();
        }

        public void Init(string t, Icon ic, ActionCoreController cp, string appfolder, ActionFile file, List<ActionEvent> evlist)       // here, change to using events
        {
            this.Icon = ic;
            actioncorecontroller = cp;
            applicationfolder = appfolder;
            actionfile = file;
            events = evlist;

            grouptypenames = (from e in events select e.uiclass).ToList().Distinct().ToList();      // here we extract from events relevant data
            groupeventlist = new Dictionary<string, List<string>>();
            foreach (string s in grouptypenames)
                groupeventlist.Add(s, (from e in events where e.uiclass == s select e.triggername).ToList());

            bool winborder = ExtendedControls.ThemeableFormsInstance.Instance.ApplyToForm(this, SystemFonts.DefaultFont);
            statusStripCustom.Visible = panelTop.Visible = panelTop.Enabled = !winborder;
            initialtitle = this.Text = label_index.Text = t;

            ConditionLists clist = actionfile.actioneventlist;          // now load the initial conditions from the action file
            groups = new List<Group>();

            for (int i = 0; i < clist.Count; i++)       // for ever event, find the condition, create the group, theme
            {
                Condition cd = clist.Get(i);
                Group g = CreateGroup(cd);
                groups.Add(g);
                ExtendedControls.ThemeableFormsInstance.Instance.ApplyToControls(g.panel, SystemFonts.DefaultFont);
            }

            foreach (Group g in groups)     // add the groups to the vscroller
                panelVScroll.Controls.Add(g.panel);

            PositionGroups(true);       //repositions all items<commit_msg>Maybe Resolve #1292<commit_after>﻿/*
 * Copyright © 2017 EDDiscovery development team
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
 * file except in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under
 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
 * ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 * 
 * EDDiscovery is not affiliated with Frontier Developments plc.
 */
using BaseUtils.Win32Constants;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Conditions;

namespace ActionLanguage
{
    public partial class ActionPackEditorForm : ExtendedControls.DraggableForm
    {
        ActionFile actionfile;      // file we are editing
        string applicationfolder;   // folder where the file is
        ActionCoreController actioncorecontroller;  // need this for some access to data
        List<ActionEvent> events;   // list of events, UIs
        List<string> grouptypenames;    // groupnames extracted from events
        Dictionary<string, List<string>> groupeventlist;    // events per group name, extracted from events
        string initialtitle;

        const int panelxmargin = 3;
        const int panelymargin = 1;

        class Group     // this top level form has a list of groups, each containing a grouptype CBC, a delete button, and a UC containing its controls
        {
            public Panel panel;
            public ExtendedControls.ComboBoxCustom grouptype;
            public ExtendedControls.ButtonExt delete;
            public ActionPackEditBase usercontrol;              
        }

        List<Group> groups; // the groups

        public Func<string, List<string>> AdditionalNames;                          // Call back when we need more variable names, by event string
        public Func<string, Condition, ActionPackEditBase> CreateActionPackEdit;    // must set, given a group and condition, what editor do you want? change the condition if you need to

        #region Init

        public ActionPackEditorForm() 
        {
            groups = new List<Group>();
            InitializeComponent();
        }

        public void Init(string t, Icon ic, ActionCoreController cp, string appfolder, ActionFile file, List<ActionEvent> evlist)       // here, change to using events
        {
            this.Icon = ic;
            actioncorecontroller = cp;
            applicationfolder = appfolder;
            actionfile = file;
            events = evlist;

            grouptypenames = (from e in events select e.uiclass).ToList().Distinct().ToList();      // here we extract from events relevant data
            groupeventlist = new Dictionary<string, List<string>>();
            foreach (string s in grouptypenames)
                groupeventlist.Add(s, (from e in events where e.uiclass == s select e.triggername).ToList());

            bool winborder = ExtendedControls.ThemeableFormsInstance.Instance.ApplyToForm(this, SystemFonts.DefaultFont);
            statusStripCustom.Visible = panelTop.Visible = panelTop.Enabled = !winborder;
            initialtitle = this.Text = label_index.Text = t;

            ConditionLists clist = actionfile.actioneventlist;          // now load the initial conditions from the action file

            for (int i = 0; i < clist.Count; i++)       // for ever event, find the condition, create the group, theme
            {
                Condition cd = clist.Get(i);
                Group g = CreateGroup(cd);
                groups.Add(g);
                ExtendedControls.ThemeableFormsInstance.Instance.ApplyToControls(g.panel, SystemFonts.DefaultFont);
            }

            foreach (Group g in groups)     // add the groups to the vscroller
                panelVScroll.Controls.Add(g.panel);

            PositionGroups(true);       //repositions all items
{'fraction_non_alphanumeric': 0.0716295427901524, 'fraction_numerical': 0.0035169988276670576, 'mean_word_length': 2.4863097670617083, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '671283', 'n_tokens_mistral': 2118, 'n_tokens_neox': 2045, 'n_words': 785}