public TransactedTreeBuilder (ExtensibleTreeView tree, TransactedNodeStore tstore, Gtk.TreeIter it)
			{
				this.tree = tree;
				this.tstore = tstore;
				navigator = new TreeNodeNavigator (tree, it);
				CheckNode ();
			}
示例#2
0
 public TransactedTreeBuilder(ExtensibleTreeView tree, TransactedNodeStore tstore, Gtk.TreeIter it)
 {
     this.tree   = tree;
     this.tstore = tstore;
     navigator   = new TreeNodeNavigator(tree, it);
     CheckNode();
 }
        void HandleOnEdit(object o, Gtk.EditedArgs e)
        {
            text_render.Editable = false;
            Gtk.TreeIter iter;
            if (!store.GetIterFromString (out iter, e.Path))
                throw new Exception("Error calculating iter for path " + e.Path);

            if (e.NewText == null || e.NewText.Length == 0) {
                return;
            }

            ITreeNavigator nav = new TreeNodeNavigator (this, iter);
            NodePosition pos = nav.CurrentPosition;

            NodeBuilder[] chain = (NodeBuilder[]) store.GetValue (iter, BuilderChainColumn);
            foreach (NodeBuilder b in chain) {
                NodeCommandHandler handler = b.CommandHandler;
                handler.SetCurrentNode (nav);
                handler.RenameItem (e.NewText);
                nav.MoveToPosition (pos);
            }
        }
        bool CheckAndDrop(int x, int y, bool drop, Gdk.DragContext ctx, object obj)
        {
            Gtk.TreePath path;
            Gtk.TreeViewDropPosition pos;
            if (!tree.GetDestRowAtPos (x, y, out path, out pos)) return false;

            Gtk.TreeIter iter;
            if (!store.GetIter (out iter, path)) return false;

            TreeNodeNavigator nav = new TreeNodeNavigator (this, iter);
            NodeBuilder[] chain = nav.BuilderChain;
            bool foundHandler = false;

            DragOperation oper = ctx.Action == Gdk.DragAction.Copy ? DragOperation.Copy : DragOperation.Move;

            foreach (NodeBuilder nb in chain) {
                NodeCommandHandler handler = nb.CommandHandler;
                handler.SetCurrentNode (nav);
                if (handler.CanDropNode (obj, oper)) {
                    foundHandler = true;
                    if (drop)
                        handler.OnNodeDrop (obj, oper);
                }
            }
            return foundHandler;
        }
 internal void NotifyInserted(Gtk.TreeIter it, object dataObject)
 {
     if (callbacks.Count > 0) {
         ArrayList list = callbacks [dataObject] as ArrayList;
         if (list != null) {
             ITreeNavigator nav = new TreeNodeNavigator (this, it);
             NodePosition pos = nav.CurrentPosition;
             foreach (TreeNodeCallback callback in list) {
                 callback (nav);
                 nav.MoveToPosition (pos);
             }
             callbacks.Remove (dataObject);
         }
     }
 }
        internal bool GetIterFromNamePath(string path, out Gtk.TreeIter iter)
        {
            if (!store.GetIterFirst (out iter))
                return false;

            TreeNodeNavigator nav = new TreeNodeNavigator (this, iter);
            string[] names = path.Split ('/');

            int n = 0;
            bool more;
            do {
                string name = names [n].Replace ("_%_","/");
                name = name.Replace ("%%","%");

                if (nav.NodeName == name) {
                    iter = nav.CurrentPosition._iter;
                    if (++n == names.Length) return true;
                    more = nav.MoveToFirstChild ();
                } else
                    more = nav.MoveNext ();
            } while (more);

            return false;
        }
        public virtual void Initialize(string label, string icon, NodeBuilder[] builders, TreePadOption[] options)
        {
            // Create default options

            this.options = options;
            globalOptions = new TreeOptions ();
            foreach (TreePadOption op in options)
                globalOptions [op.Id] = op.DefaultValue;

            globalOptions.Pad = this;

            // Check that there is only one node builder per type

            Hashtable bc = new Hashtable ();
            foreach (NodeBuilder nb in builders) {
                TypeNodeBuilder tnb = nb as TypeNodeBuilder;
                if (tnb != null) {
                    TypeNodeBuilder other = (TypeNodeBuilder) bc [tnb.NodeDataType];
                    if (other != null)
                        throw new ApplicationException (string.Format ("The type node builder {0} can't be used in this context because the type {1} is already handled by {2}", nb.GetType(), tnb.NodeDataType, other.GetType()));
                    bc [tnb.NodeDataType] = tnb;
                }
                else if (!(nb is NodeBuilderExtension))
                    throw new InvalidOperationException (string.Format ("Invalid NodeBuilder type: {0}. NodeBuilders must inherit either from TypeNodeBuilder or NodeBuilderExtension", nb.GetType()));
            }

            NodeBuilders = builders;
            Title = label;
            Icon = icon;

            builderContext = new TreeBuilderContext (this);

            tree = new Gtk.TreeView ();

            /*
            0 -- Text
            1 -- Icon (Open)
            2 -- Icon (Closed)
            3 -- Node Data
            4 -- Builder chain
            5 -- Pango weight
            6 -- Expanded
            */
            store = new Gtk.TreeStore (typeof (string), typeof (Gdk.Pixbuf), typeof (Gdk.Pixbuf), typeof (object), typeof (object), typeof(int), typeof(bool));
            tree.Model = store;

            tree.EnableModelDragDest (target_table, Gdk.DragAction.Copy | Gdk.DragAction.Move);
            Gtk.Drag.SourceSet (tree, Gdk.ModifierType.Button1Mask, target_table, Gdk.DragAction.Copy | Gdk.DragAction.Move);

            store.DefaultSortFunc = new Gtk.TreeIterCompareFunc (CompareNodes);
            store.SetSortColumnId (/* GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID */ -1, Gtk.SortType.Ascending);

            tree.HeadersVisible = false;
            tree.SearchColumn = 0;
            tree.EnableSearch = true;
            complete_column = new Gtk.TreeViewColumn ();
            complete_column.Title = "column";

            Gtk.CellRendererPixbuf pix_render = new Gtk.CellRendererPixbuf ();
            complete_column.PackStart (pix_render, false);
            complete_column.AddAttribute (pix_render, "pixbuf", OpenIconColumn);
            complete_column.AddAttribute (pix_render, "pixbuf-expander-open", OpenIconColumn);
            complete_column.AddAttribute (pix_render, "pixbuf-expander-closed", ClosedIconColumn);

            text_render = new Gtk.CellRendererText ();
            text_render.Edited += new Gtk.EditedHandler (HandleOnEdit);

            complete_column.PackStart (text_render, true);
            complete_column.AddAttribute (text_render, "text", TextColumn);
            complete_column.AddAttribute (text_render, "weight", WeightColumn);

            tree.AppendColumn (complete_column);

            Gtk.ScrolledWindow sw = new Gtk.ScrolledWindow ();
            sw.Add(tree);
            contentPanel = new Gtk.Frame ();
            contentPanel.Add(sw);

            tree.TestExpandRow += new Gtk.TestExpandRowHandler (OnTestExpandRow);
            tree.RowActivated += new Gtk.RowActivatedHandler(OnNodeActivated);

            contentPanel.ButtonReleaseEvent += new Gtk.ButtonReleaseEventHandler(OnButtonRelease);
            contentPanel.PopupMenu += new Gtk.PopupMenuHandler (OnPopupMenu);

            foreach (NodeBuilder nb in builders)
                nb.SetContext (builderContext);

            workNode = new TreeNodeNavigator (this);
            compareNode1 = new TreeNodeNavigator (this);
            compareNode2 = new TreeNodeNavigator (this);

            tree.DragBegin += new Gtk.DragBeginHandler (OnDragBegin);
            tree.DragDataReceived += new Gtk.DragDataReceivedHandler (OnDragDataReceived);
            tree.DragDrop += new Gtk.DragDropHandler (OnDragDrop);
            tree.DragEnd += new Gtk.DragEndHandler (OnDragEnd);
            tree.DragMotion += new Gtk.DragMotionHandler (OnDragMotion);

            tree.CursorChanged += new EventHandler (OnSelectionChanged);

            contentPanel.ShowAll ();
        }