Ejemplo n.º 1
0
		public simple_node_editor(simple_element se,node_info ninf,NodeGenerator.NodeGenerator _ng)
		{
			InitializeComponent();
			if (se!=null)
			{
				extended_simple_element ese=se as extended_simple_element;
				if (ese!=null)
				{
					this.se=ese;
				}
				else
				{
					this.se=new extended_simple_element();
					this.se.val_field_type_name=se.val_field_type_name;
					this.se.field_name=se.field_name;
					this.se.field_type=se.field_type;
				}
			}
			if (this.se==null)
			{
				this.se=new extended_simple_element();
			}
			this.ninf=ninf;
			this.ng=_ng;

			set_element();
		}
Ejemplo n.º 2
0
        public simple_node_editor(simple_element se, node_info ninf, NodeGenerator.NodeGenerator _ng)
        {
            InitializeComponent();
            if (se != null)
            {
                extended_simple_element ese = se as extended_simple_element;
                if (ese != null)
                {
                    this.se = ese;
                }
                else
                {
                    this.se = new extended_simple_element();
                    this.se.val_field_type_name = se.val_field_type_name;
                    this.se.field_name          = se.field_name;
                    this.se.field_type          = se.field_type;
                }
            }
            if (this.se == null)
            {
                this.se = new extended_simple_element();
            }
            this.ninf = ninf;
            this.ng   = _ng;

            set_element();
        }
Ejemplo n.º 3
0
 public static method_info edit_element(method_info nm, node_info ninf, NodeGenerator.NodeGenerator _ng)
 {
     method_editor me = new method_editor(nm, ninf, _ng);
     if (me.ShowDialog() == DialogResult.OK && !string.IsNullOrEmpty(me.nm.method_text))
         snm = me.nm;
     else snm = null;
     return snm;
 }
Ejemplo n.º 4
0
        public method_editor(method_info nm, node_info ninf, NodeGenerator.NodeGenerator ng)
		{
			InitializeComponent();
            if (nm != null)
                this.nm = nm;
            else this.nm = new method_info();

            this.ninf=ninf;
			this.ng=ng;

			set_element();
		}
Ejemplo n.º 5
0
		public node_def(node_info ni,NodeGenerator.NodeGenerator ng)
		{
			InitializeComponent();
			this.ni=ni;
			sni=ni;
			
			base_class.Items.Clear();
			base_class.Items.AddRange((object[])ng.all_nodes.ToArray(typeof(object)));

			if (this.ni==null)
			{
				this.ni=new node_info();
			}
			this.ng=ng;
			set_node_info();
		}
Ejemplo n.º 6
0
        public method_editor(method_info nm, node_info ninf, NodeGenerator.NodeGenerator ng)
        {
            InitializeComponent();
            if (nm != null)
            {
                this.nm = nm;
            }
            else
            {
                this.nm = new method_info();
            }

            this.ninf = ninf;
            this.ng   = ng;

            set_element();
        }
Ejemplo n.º 7
0
		public subnode_editor(NodeGenerator.NodeGenerator ng,node_field_info nfi,node_info this_node)
		{
			InitializeComponent();
			ngen=ng;
			this.nfi=nfi;

			subnodes_types.Items.Clear();
			subnodes_types.Items.AddRange((object[])ngen.all_nodes.ToArray(typeof(object)));

			if (ngen.all_nodes.IndexOf(this_node)<0)
			{
				subnodes_types.Items.Insert(0,this_node);
			}

			if (this.nfi==null)
			{
				this.nfi=new node_field_info();
				this.nfi.field_type=(node_info)ng.all_nodes[0];
			}

			ninf=this_node;
			snfi=this.nfi;
			set_node_info();
		}
Ejemplo n.º 8
0
 private void nodes_list_MouseMove(object sender, MouseEventArgs e)
 {
     if (e.Button == System.Windows.Forms.MouseButtons.Left || e.Button == System.Windows.Forms.MouseButtons.Right)
     {
         int x = nodes_list.IndexFromPoint(nodes_list.PointToClient(Cursor.Position));
         if (x >= 0)
         {
             if (Control.ModifierKeys == Keys.Shift)
             {
                 int old_ind = nodes_list.Items.IndexOf(selected_node);
                 for (int i = Math.Min(old_ind, x); i < Math.Max(old_ind, x); i++)
                     nodes_list.SelectedIndices.Add(i);
             }
             else                        
                 nodes_list.SelectedIndices.Add(x);
             new_selected_node = (nodes_list.Items[x] as node_info);
         }
     }
                 
 }
Ejemplo n.º 9
0
        private void applyFilter(List<Tuple<int, int>> filter, bool renew)
        {
            nodes_list.SelectedIndexChanged -= nodes_list_SelectedIndexChanged;
            nodes_list.SelectedIndices.Clear();
            selected_node = null;
            selected_node_index = -1;

            if (renew)
                reload_nodes();
            List<object> to_remove = new List<object>();

            foreach (node_info i in nodes_list.Items)
            {
                foreach (var fltr in filter)
                    if (i.tags.Find(x => x.Item1 == fltr.Item1 && x.Item2 == fltr.Item2) == null)
                    {
                        to_remove.Add(i);
                        break;
                    }
            }

            foreach (var i in to_remove)
                nodes_list.Items.Remove(i);

            if (nodes_list.Items.Count > 0)
            {
                selected_node = nodes_list.Items[0] as node_info;
                selected_node_index = 0;
                set_node_info(nodes_list.Items[0] as node_info);
            }
            nodes_list.SelectedIndexChanged += nodes_list_SelectedIndexChanged;
        }
Ejemplo n.º 10
0
        private bool get_node_info(node_info ni)
        {
            ////pre-checking
            //parsing
            //brackets are needed, so the sample grammar works fine without in-grammar changes
            string src = parser_tech_data + scintilla1.Text + "}}";

            try
            {
                _parser.Parse(src, "<source>");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                throw;
            }

            ParseTree _parseTree = _parser.Context.CurrentParseTree;
            if (_parseTree.ParserMessages.Count > 0)
            {
                int show_mes_id = 0;
                while (_parseTree.ParserMessages.Count > show_mes_id) //"S109" "S315"
                    if (parser_errors_ignore_states.Contains(_parseTree.ParserMessages[show_mes_id].ParserState.Name))
                        show_mes_id++;
                    else break;

                if (show_mes_id < _parseTree.ParserMessages.Count)
                {

                    MessageBox.Show("Some Syntax Error @ Line " + _parseTree.ParserMessages[show_mes_id].Location.Line.ToString(),
                                    _parseTree.ParserMessages[show_mes_id].Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    scintilla1.Caret.LineNumber = _parseTree.ParserMessages[show_mes_id].Location.Line - 1;

                    scintilla1.Focus();
                    return false;
                }
            }

            //checking, if there are cycles in the deriving chain
            if (cycles_in_deriving(ni, base_class.SelectedItem as node_info))
            {
                MessageBox.Show("Base class is incorrect for this node, as this leads to cycles in the deriving chain!",
                                "Base class is incorrect", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }

            ////setters - work only if the first part is OK!!
            var root = get_node_info_get_class_body(_parseTree);
            get_node_info_get_subnodes_and_methods(root, ni, src);

            //node name & base class
            ni.node_name = node_name.Text;
            int t = base_class.SelectedIndex;
            if (t >= 0)
                ni.base_class = base_class.Items[t] as node_info;

            //help context
            node_gen.help_storage.get_help_context(ni.node_name).help_context = this.help_context.Text;

            //tags
            if (update_tags)
            {
                getTagItems(tagCategories.SelectedIndex);
                update_tags = true;
            }
            node_gen.reduce_ref_counts(ni);
            node_gen.set_tags_for_node(temp_tags, ni);
            if (update_tags)
            {
                fillInTagCategories(true);
                fill_in_filter_items();
                applyCurrentFilterForNode(selected_node);
                update_tags = false;
            }

            return true;
        }
Ejemplo n.º 11
0
		public static simple_element edit_element(simple_element se,node_info ninf,NodeGenerator.NodeGenerator _ng)
		{
			simple_node_editor sne=new simple_node_editor(se,ninf,_ng);
            var tmp = sne.se.field_name;
            if (sne.ShowDialog() != DialogResult.OK)
                sne.se.field_name = tmp;
			sse=sne.se;
			return sse;
		}
Ejemplo n.º 12
0
        public void generate_code(StreamWriter sw, node_info ni, HelpStorage hst)
        {
            string txt = "public "+method_text;
            var ss = txt.Split(new string[]{Environment.NewLine}, StringSplitOptions.None);
            txt = string.Join(Environment.NewLine + text_consts.tab + text_consts.tab, ss);
            sw.WriteLine(text_consts.tab + text_consts.tab + txt);
//            sw.WriteLine();
        }
Ejemplo n.º 13
0
		public void generate_code_property(StreamWriter sw,node_info ni,HelpStorage hst)
		{
			string prop=text_consts.create_property(field_type_name,property_name,field_code_name,
				hst.get_help_context(ni.node_name+"."+field_name).help_context);
			//sw.WriteLine();
			sw.WriteLine(prop);
			//sw.WriteLine();
		}
Ejemplo n.º 14
0
		public void add_node(node_info ni)
		{
			nodes.Add(ni);
		}
Ejemplo n.º 15
0
 public void set_tags_for_node(List<Tuple<int, string>> temp_tags, node_info ni)
 {
     ni.tags.Clear();            
     for (int i = 0; i < temp_tags.Count; i++)
     {
         if (temp_tags[i].Item2 == "") continue;
         int tag_id = tag_cats[temp_tags[i].Item1].tags.FindIndex(x => x.name == temp_tags[i].Item2);
         if (tag_id > -1) //if such a tag is already in scope
         {
             if (!ni.tags.Contains(new Tuple<int, int>(temp_tags[i].Item1, tag_id)))
             {
                 tag_cats[temp_tags[i].Item1].tags[tag_id].ref_count++;
                 ni.tags.Add(new Tuple<int, int>(temp_tags[i].Item1, tag_id));
             }
         }
         else
         {
             tag_cats[temp_tags[i].Item1].tags.Add(new FilterTag() { name = temp_tags[i].Item2, ref_count = 1 });
             ni.tags.Add(new Tuple<int, int>(temp_tags[i].Item1, tag_cats[temp_tags[i].Item1].tags.Count - 1));
         }
     }
 }
Ejemplo n.º 16
0
 public void reduce_ref_counts(node_info ni)
 {
     for (int i = 0; i < ni.tags.Count; i++)
         tag_cats[ni.tags[i].Item1].tags[ni.tags[i].Item2].ref_count--;
 }
Ejemplo n.º 17
0
        private bool cycles_in_deriving(node_info ni, node_info new_base_class)
        {
            if (new_base_class == null) return false;

            HashSet<node_info> chain = new HashSet<node_info>();

            chain.Add(ni);
            while (new_base_class.base_class != null)
            {
                if (chain.Contains(new_base_class))
                    return true;
                chain.Add(new_base_class);
                new_base_class = new_base_class.base_class;
            }

            return false;
        }
Ejemplo n.º 18
0
        private void set_nodes_information() // set - установить поля интерфейса по node_gen
        {
            if (node_gen == null)
            {
                node_gen = new NodeGenerator.NodeGenerator();
            }

            reload_nodes();

            fillInTagCategories();

            creation_mode = false;
            selected_tag_cat = -1;
            selected_node = null;
            selected_node_index = -1;
            selected_filter_cat = -1;
            is_filter_enabled = false;

            if (nodes_list.Items.Count > 0) { new_selected_node = (nodes_list.Items[0] as node_info); nodes_list.SelectedIndex = 0; }
            else
            {
                node_name.Text = "";
                base_class.Items.Clear();
                base_class.Text = "";
                scintilla1.Text = "";
                help_context.Text = "";
            }
        }
Ejemplo n.º 19
0
        private void applyFilterForNode(List<Tuple<int, int>> filter, node_info node)
        {
            nodes_list.SelectedIndexChanged -= nodes_list_SelectedIndexChanged;

            foreach (var fltr in filter)
                if (node.tags.Find(x => x.Item1 == fltr.Item1 && x.Item2 == fltr.Item2) == null)
                {
                    nodes_list.Items.Remove(node);
                }

            nodes_list.SelectedIndexChanged += nodes_list_SelectedIndexChanged;
        }
Ejemplo n.º 20
0
 private void add_Click(object sender, System.EventArgs e)
 {
     synchronize_node();
     creation_mode = true;
     selected_node = new node_info();
     set_node_info(selected_node);
     node_name.Focus();
 }
Ejemplo n.º 21
0
 private void applyCurrentFilterForNode(node_info node)
 {
     var lst = new List<Tuple<int, int>>();
     for (int i = 0; i < current_filter.Count; i++)
         for (int j = 0; j < current_filter[i].Count; j++)
             if (current_filter[i][j])
                 lst.Add(new Tuple<int, int>(i, j));
     applyFilterForNode(lst, node);
 }
Ejemplo n.º 22
0
        private void delete_Click(object sender, System.EventArgs e)
        {
            string messageBoxText = "Are you sure, you want to delete the selected node?";
            string caption = "Delete the nodes?";
            MessageBoxButtons button = MessageBoxButtons.YesNo;
            MessageBoxIcon icon = MessageBoxIcon.Warning;
            MessageBoxDefaultButton def_btn = MessageBoxDefaultButton.Button2;

            if (MessageBox.Show(messageBoxText, caption, button, icon, def_btn) == DialogResult.Yes)
            {                
                int ind = selected_node_index;
                new_selected_node = selected_node = null;
                selected_node_index = -1;
                delete_selected_items();                
                nodes_list.SelectedIndex = Math.Min(nodes_list.Items.Count - 1, ind);

                // Голову отрывать надо за такой небрежный код
                selected_node = nodes_list.SelectedItem as node_info;
                selected_node_index = nodes_list.SelectedIndex;
            }
            //update();
        }
Ejemplo n.º 23
0
 private void nodes_list_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Down)
     {
         var x = nodes_list.Items.IndexOf(selected_node);
         if (x + 1 < nodes_list.Items.Count)
             new_selected_node = (nodes_list.Items[x + 1] as node_info);
     }
     else
     if (e.KeyCode == Keys.Up)
     {
         var x = nodes_list.Items.IndexOf(selected_node);
         if (x - 1 >= 0)
             new_selected_node = (nodes_list.Items[x - 1] as node_info);
     }
 }
Ejemplo n.º 24
0
        private void fill_in_navigation_panel(node_info ni)
        {
            if (ni == null)
                return;

            var DropDownNodes = (NavigationPanel.Items[0] as ToolStripDropDownButton).DropDownItems;

            DropDownNodes.Clear();            
            while (NavigationPanel.Items.Count > 1)
                NavigationPanel.Items.RemoveAt(1);

            var l = new List<string>();
            var s = ni.node_name;
            bool add_dots = false;

            while (true && l.Count < 40) // 40 to prevent perpetum cycle, if recursive base classes
            {
                if (!add_dots)
                {
                    var nav_lbl = new ToolStripStatusLabel(s, null, ItemsClick);
                    nav_lbl.IsLink = true;
                    NavigationPanel.Items.Add(nav_lbl);
                    add_dots = remove_last_nav_label_if_hidden();
                    if (!add_dots)
                    {
                        NavigationPanel.Items.Add(new ToolStripStatusLabel("->"));
                        add_dots = remove_last_nav_label_if_hidden();
                    }
                }
                l.Add(ni.node_name);

                if (ni.base_class == null) break;

                ni = ni.base_class;
                s = ni.node_name;
            }
            if (NavigationPanel.Items.Count > 1)
                NavigationPanel.Items.RemoveAt(NavigationPanel.Items.Count - 1);
            if (add_dots)
                NavigationPanel.Items.Add(new ToolStripStatusLabel("..."));

            for (int i = l.Count - 1; i >= 0; i--)
            {
                DropDownNodes.Add(l[i]);
                DropDownNodes[DropDownNodes.Count - 1].Click += ItemsClick;
            }
        }
Ejemplo n.º 25
0
		public static node_field_info edit_field(node_field_info nfi,NodeGenerator.NodeGenerator ng,node_info this_node)
		{
			subnode_editor se=new subnode_editor(ng,nfi,this_node);
			se.ShowDialog();
			/*if (se.ShowDialog()==DialogResult.OK)
			{
				return snfi;
			}*/
			return snfi;
		}
Ejemplo n.º 26
0
        private void nodes_list_SelectedIndexChanged(object sender, EventArgs e)
        {                        
            if (nodes_list_SelectedIndexChanged_recur) return;
            if (nodes_list.SelectedItem == null) return;

            node_info item = null;
            if (new_selected_node != null)
            {
                item = new_selected_node;
                new_selected_node = null;
            }
            else item = (nodes_list.SelectedItem as node_info);

            nodes_list_SelectedIndexChanged_recur = true;

            //reload the item, no other actions required, if the same node was selected
            if (item == selected_node)
            {
                set_node_info(item);
            }
            else
            {
                //creation of a new node case
                if (creation_mode)
                {
                    if (node_name.Text != "")
                    {
                        if (!get_node_info(selected_node))
                        {
                            nodes_list_SelectedIndexChanged_recur = false;
                            return;
                        }
                        nodes_list.Items.Add(selected_node);
                        node_gen.add_node(selected_node);
                    }
                    creation_mode = false;
                }
                else
                    //default switch between nodes            
                    if (!synchronize_node())
                    {
                        nodes_list.SelectedItems.Remove(item);
                        nodes_list.SelectedItem = selected_node;                        
                        nodes_list_SelectedIndexChanged_recur = false;
                        return;
                    }

                fill_in_navigation_panel(item);
                set_node_info(item);
                selected_node = item;
                selected_node_index = nodes_list.Items.IndexOf(item);
            }

            nodes_list_SelectedIndexChanged_recur = false;
        }
Ejemplo n.º 27
0
		private void ok_Click(object sender, System.EventArgs e)
		{
			get_node_info();
			sni=ni;
			Close();
		}
Ejemplo n.º 28
0
        private void set_node_info_tags(node_info ni)
        {
            if (ni == null) return;

            tagItems.Clear();
            temp_tags.Clear();
            foreach (var tg in ni.tags)
            {
                temp_tags.Add(new Tuple<int, string>(tg.Item1, node_gen.tag_cats[tg.Item1].tags[tg.Item2].name));
            }
            tagCategories.SelectedIndexChanged -= tagCategories_SelectedIndexChanged;
            if (tagCategories.Items.Count > 0)
            {
                if (selected_tag_cat == -1)
                    selected_tag_cat = tagCategories.SelectedIndex = 0;
                else
                    tagCategories.SelectedIndex = selected_tag_cat;
                fillInTagItems(selected_tag_cat);
            }
            tagCategories.SelectedIndexChanged += tagCategories_SelectedIndexChanged;
            update_tags = false;
        }
Ejemplo n.º 29
0
		public static node_info show_modal(node_info ni,NodeGenerator.NodeGenerator ng)
		{
			node_def nd=new node_def(ni,ng);
			nd.ShowDialog();
			return sni;
		}
Ejemplo n.º 30
0
        private void set_node_info(node_info ni)
        {
            scintilla1.AutoComplete.List.Clear();
            for (int i = 0; i < nodes_list.Items.Count; i++)
                scintilla1.AutoComplete.List.Add(nodes_list.Items[i].ToString());
            scintilla1.AutoComplete.List.AddRange(autocompletion_list);
            scintilla1.AutoComplete.List.Sort();

            this.node_name.Text = ni.node_name;

            //setting base class
            base_class.Items.Clear();
            base_class.Items.AddRange((object[])node_gen.all_nodes.ToArray(typeof(object)));

            if (ni.base_class == null)
            {
                base_class.SelectedIndex = -1;
                base_class.Text = "";
            }
            else base_class.SelectedIndex = Math.Max(-1, base_class.Items.IndexOf(ni.base_class));
            
            //fields
            scintilla1.Text = "";
            for (int i = 0; i < ni.subnodes.Length; i++)
            {
                set_node_info_help_context(ni.node_name + '.' + ni.subnodes[i].field_name);

                scintilla1.Text += ni.subnodes[i];

                if (ni.subnodes[i] is extended_simple_element && (ni.subnodes[i] as extended_simple_element).create_var)
                    scintilla1.Text += " = new " + (ni.subnodes[i] as extended_simple_element).field_type_name + "();";

                if (scintilla1.Text[scintilla1.Text.Length - 1] != ';')
                    scintilla1.Text += ';';

                scintilla1.Text += "\n";
            }
            scintilla1.Text += "\n";
            
            //methods
            for (int i = 0; i < ni.methods.Length; i++)
            {
                set_node_info_help_context(ni.node_name + '.' + ni.methods[i].method_header);
                scintilla1.Text += ni.methods[i].method_text + "\n\n";
            }

            scintilla1.UndoRedo.EmptyUndoBuffer();

            //Help context
            this.help_context.Text = "";

            if (ni.node_name != null)
            {
                if (node_gen.help_storage.get_help_context(ni.node_name) == null)
                {
                    node_gen.help_storage.add_context(ni.node_name, new HelpContext());
                }
                this.help_context.Text = node_gen.help_storage.get_help_context(ni.node_name).help_context;
            }

            //tags
            set_node_info_tags(ni);
        }
Ejemplo n.º 31
0
		public static simple_element edit_element(simple_element se,node_info ninf,NodeGenerator.NodeGenerator _ng)
		{
			simple_node_editor sne=new simple_node_editor(se,ninf,_ng);
			sne.ShowDialog();
			sse=sne.se;
			return sse;
		}
Ejemplo n.º 32
0
        //root - class body with fields and methods; node - class itself; src - whole source (with namespace)
        private void get_node_info_get_subnodes_and_methods(ParseTreeNode root, node_info node, string src)
        {
            List<node_field_info> subnodes = new List<node_field_info>();
            List<method_info> methods = new List<method_info>();

            var lines = src.Split('\n');
            var nodes = new List<node_info>();
            nodes.AddRange(node_gen.all_nodes.Cast<node_info>());

            for (int i = 0; i < root.ChildNodes.Count; i++)
            {
                HelpContext help_context = null;
                if (root.ChildNodes[i].Term.Name == "field_declaration")
                {
                    var subnode_type = get_node_info_get_subnode_type(root.ChildNodes[i], src);
                    var subnode = nodes.Find(x => x.node_name == subnode_type);

                    if (subnode == null)
                        subnodes.Add(new extended_simple_element()
                        {
                            val_field_type_name = subnode_type,
                            field_name = get_node_info_get_subnode_name(root.ChildNodes[i]),
                            create_var = get_node_info_has_constructor(root.ChildNodes[i]) // lines[root.ChildNodes[i].Span.Location.Line].Contains("new List")
                        });
                    else
                        subnodes.Add(new node_field_info()
                        {
                            field_name = get_node_info_get_subnode_name(root.ChildNodes[i]),
                            field_type = subnode
                        });

                    help_context = node_gen.help_storage.get_help_context(node.node_name + "." + subnodes[subnodes.Count - 1].field_name);
                }
                else
                    if (root.ChildNodes[i].Term.Name == "constructor_declaration" || root.ChildNodes[i].Term.Name == "method_declaration")
                    {
                        methods.Add(new method_info(src.Substring(root.ChildNodes[i].Span.Location.Position, root.ChildNodes[i].Span.Length)));
                        help_context = node_gen.help_storage.get_help_context(node.node_name + "." + methods[methods.Count - 1].method_header);
                    }
                else continue;

                //help context
                help_context.help_context = "";
                int help_cur_line = root.ChildNodes[i].Span.Location.Line - 1;
                while (lines[help_cur_line].Length > 2 && lines[help_cur_line].Substring(0, 2) == "//")
                {
                    help_context.help_context = lines[help_cur_line].Substring(2, lines[help_cur_line].Length - 2).Trim() + help_context.help_context;
                    help_cur_line--;
                }
            }

            node.set_subnodes(subnodes);
            node.set_methods(methods);
        }