Esempio n. 1
0
        public void AddObject(Wrappers.Node parent, Wrappers.Wrapper wrapper, double x, double y)
        {
            wrapper.Allocation.X = x;
            wrapper.Allocation.Y = y;

            Do(new Undo.AddObject(parent, wrapper));
        }
Esempio n. 2
0
        private void HandleChildAdded(Wrappers.Node source, Wrappers.Wrapper child)
        {
            Gtk.Menu sub;

            if (child is Wrappers.Import)
            {
                d_map[child] = new TemplatesMenu.MenuInfo(null, d_map[source].Menu);

                foreach (Wrappers.Wrapper wrapper in (child as Wrappers.Node).Children)
                {
                    HandleChildAdded(child as Wrappers.Node, wrapper);
                }

                return;
            }

            if (d_map[source].Item == null)
            {
                sub = d_map[source].Menu;
            }
            else
            {
                sub = (Gtk.Menu)d_map[source].Item.Submenu;
            }

            AddTemplate(sub, child);
        }
Esempio n. 3
0
        private void AddTemplate(Gtk.Menu menu, Wrappers.Wrapper template)
        {
            if (!(d_filter == null || d_filter(template) || (template is Wrappers.Node && d_recursive)))
            {
                return;
            }

            string lbl = template.FullId.Replace("_", "__");

            Gtk.MenuItem item = new Gtk.MenuItem(lbl);
            item.Show();

            item.Activated += delegate {
                if (item.Submenu == null)
                {
                    Activated(this, template);
                }
            };

            menu.Append(item);

            d_map[template] = new MenuInfo(item, menu);

            if (d_recursive && template is Wrappers.Node)
            {
                Gtk.Menu sub = new Gtk.Menu();
                item.Submenu = sub;

                Traverse((Wrappers.Node)template, sub);
            }

            template.WrappedObject.AddNotification("id", HandleIdChanged);
        }
Esempio n. 4
0
 private void HideShowMenu(Wrappers.Node source, Wrappers.Wrapper child)
 {
     if (d_menu.Children.Length > 0)
     {
         d_menuProperty.SetValue(d_widget, d_menu, null);
         d_group.ChildAdded -= HideShowMenu;
     }
 }
Esempio n. 5
0
        private void HandleIdChanged(object source, GLib.NotifyArgs args)
        {
            Wrappers.Wrapper wrapped = Wrappers.Wrapper.Wrap((Cdn.Object)source);
            Gtk.MenuItem     item    = d_map[wrapped].Item;

            item.Remove(item.Child);
            Gtk.Label lbl = new Gtk.Label(wrapped.Id.Replace("_", "__"));
            lbl.Show();

            item.Add(lbl);
        }
Esempio n. 6
0
        private void RemoveFromMap(Wrappers.Wrapper child)
        {
            child.WrappedObject.RemoveNotification("id", HandleIdChanged);

            d_map.Remove(child);

            if (d_recursive && child is Wrappers.Node)
            {
                Wrappers.Node grp = (Wrappers.Node)child;

                foreach (Wrappers.Wrapper w in grp.Children)
                {
                    RemoveFromMap(w);
                }
            }
        }
Esempio n. 7
0
        private bool HasLinks(Wrappers.Wrapper grp)
        {
            if (grp.Links.Count != 0)
            {
                return(true);
            }

            foreach (Wrappers.Edge link in Utils.FilterLink(grp.Parent.Children))
            {
                if (link.Input == grp)
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 8
0
        private void HandleChildRemoved(Wrappers.Node source, Wrappers.Wrapper child)
        {
            if (!d_map.ContainsKey(child))
            {
                return;
            }

            Gtk.Menu sub = d_map[child].Menu;
            sub.Remove(d_map[child].Item);

            if (d_recursive && child is Wrappers.Node)
            {
                Wrappers.Node grp = (Wrappers.Node)child;

                grp.ChildAdded   -= HandleChildAdded;
                grp.ChildRemoved -= HandleChildRemoved;
            }

            RemoveFromMap(child);
        }
Esempio n. 9
0
        public void ApplyTemplate(Wrappers.Wrapper template, Wrappers.Wrapper[] selection)
        {
            if (selection.Length == 0)
            {
                return;
            }

            // Filter to what kind of things we can apply the template
            List <Wrappers.Wrapper> sel = new List <Wrappers.Wrapper>(selection);

            Type tempType = template.GetType();
            bool isGroup  = template is Wrappers.Node;

            sel.RemoveAll(delegate(Wrappers.Wrapper item) {
                if (isGroup && item is Wrappers.Object)
                {
                    return(false);
                }

                Type itemType = item.GetType();

                return(itemType != tempType && !itemType.IsSubclassOf(tempType));
            });

            if (sel.Count == 0)
            {
                throw new Exception(String.Format("The template type `{0}' cannot be applied to any of the selected objects", tempType.Name));
            }

            List <Undo.IAction> actions = new List <Undo.IAction>();

            foreach (Wrappers.Wrapper wrapper in sel)
            {
                actions.Add(new Undo.ApplyTemplate(wrapper, template));
            }

            Do(new Undo.Group(actions));
        }
Esempio n. 10
0
        private Wrappers.Wrapper[] MakeCopy(Wrappers.Wrapper[] selection)
        {
            List <Wrappers.Wrapper> sel = NormalizeSelection(selection);

            if (sel.Count == 0)
            {
                return(new Wrappers.Wrapper[] {});
            }

            Dictionary <Cdn.Object, Wrappers.Wrapper> map = new Dictionary <Cdn.Object, Wrappers.Wrapper>();
            List <Wrappers.Wrapper> copied = new List <Wrappers.Wrapper>();

            // Create copies and store in a map the mapping from the orig to the copy
            foreach (Wrappers.Wrapper wrapper in sel)
            {
                Wrappers.Wrapper copy = wrapper.Copy();

                map[wrapper] = copy;
                copied.Add(copy);
            }

            // Reconnect links
            foreach (Wrappers.Edge link in Utils.FilterLink(sel))
            {
                if ((link.Input != null && map.ContainsKey(link.Input)) &&
                    (link.Output != null && map.ContainsKey(link.Output)))
                {
                    Wrappers.Node from = map[link.Input] as Wrappers.Node;
                    Wrappers.Node to   = map[link.Output] as Wrappers.Node;

                    Wrappers.Edge target = (Wrappers.Edge)map[link.WrappedObject];
                    target.Attach(from, to);
                }
            }

            return(copied.ToArray());
        }
Esempio n. 11
0
 public void UnapplyTemplate(Wrappers.Wrapper obj, Wrappers.Wrapper template)
 {
     Do(new Undo.UnapplyTemplate(obj, template));
 }
Esempio n. 12
0
 public void AddObject(Wrappers.Node parent, Wrappers.Wrapper wrapper)
 {
     AddObject(parent, wrapper, wrapper.Allocation.X, wrapper.Allocation.Y);
 }