예제 #1
0
        protected void OnUpClicked(object ob, EventArgs args)
        {
            TreeModel model;
            TreeIter  iter;

            if (listSelected.Selection.GetSelected(out model, out iter))
            {
                TreePath iterPath = storeSelected.GetPath(iter);
                TreeIter oldIter;
                if (storeSelected.GetIterFirst(out oldIter))
                {
                    if (storeSelected.GetPath(oldIter).Equals(iterPath))
                    {
                        return;
                    }

                    TreeIter prevIter;

                    do
                    {
                        prevIter = oldIter;
                        if (!storeSelected.IterNext(ref oldIter))
                        {
                            return;
                        }
                    }while (!storeSelected.GetPath(oldIter).Equals(iterPath));
                    storeSelected.Swap(prevIter, iter);
                }

                storeSelected.Swap(oldIter, iter);
            }
        }
예제 #2
0
        void downButton_Clicked(object sender, EventArgs e)
        {
            TreeIter  iter, next;
            TreeModel model;

            if (!itemTree.Selection.GetSelected(out model, out iter))
            {
                return;
            }

            //get next iter
            next = iter.Copy();
            if (!itemStore.IterNext(ref next))
            {
                return;
            }

            //swap the two
            itemStore.Swap(iter, next);

            //swap indices too
            object nextVal = itemStore.GetValue(next, 1);
            object iterVal = itemStore.GetValue(iter, 1);

            itemStore.SetValue(next, 1, iterVal);
            itemStore.SetValue(iter, 1, nextVal);
        }
예제 #3
0
		/// <summary>
		/// Moves the selected item up if possible.
		/// </summary>
		protected void OnButtonUpClicked (object sender, System.EventArgs e)
		{
			TreePath[] paths = treeview.Selection.GetSelectedRows ();
			if (paths.Length > 0) {
				TreePath p = paths [0];
				TreeIter it1, it2;
				listStore.GetIter (out it2, p);
				if (p.Prev () && listStore.GetIter (out it1, p)) {
					listStore.Swap (it1, it2);
				}
			}
		}
예제 #4
0
        void MovePackageSources(NotifyCollectionChangedEventArgs e)
        {
            TreeIter sourceIter      = GetTreeIter(e.NewItems[0] as PackageSourceViewModel);
            TreeIter destinationIter = GetTreeIter(e.NewStartingIndex);

            packageSourcesStore.Swap(sourceIter, destinationIter);
        }
        protected virtual void OnButtonUpClicked(object sender, System.EventArgs e)
        {
            TreeIter iter;

            if (!treeItems.Selection.GetSelected(out iter))
            {
                return;
            }

            TreePath tp = listStore.GetPath(iter);

            Gtk.TreeIter pi;
            if (tp.Prev() && listStore.GetIter(out pi, tp))
            {
                listStore.Swap(pi, iter);
                treeItems.ScrollToCell(listStore.GetPath(iter), treeItems.Columns[0], false, 0, 0);
                UpdateButtons();
            }
        }
예제 #6
0
        public override void LaunchDialogue()
        {
            //the Type in the collection
            IList  collection  = (IList)Value;
            string displayName = Inspector.DisplayName;

            //populate list with existing items
            ListStore itemStore = new ListStore(typeof(object), typeof(int), typeof(string));

            for (int i = 0; i < collection.Count; i++)
            {
                itemStore.AppendValues(collection [i], i, collection [i].ToString());
            }

            #region Building Dialogue

            TreeView      itemTree;
            InspectorGrid grid;
            TreeIter      previousIter = TreeIter.Zero;

            //dialogue and buttons
            Dialog dialog = new Dialog()
            {
                Title       = displayName + " Editor",
                Modal       = true,
                AllowGrow   = true,
                AllowShrink = true,
            };
            var toplevel = this.Container.Toplevel as Window;
            if (toplevel != null)
            {
                dialog.TransientFor = toplevel;
            }

            dialog.AddActionWidget(new Button(Stock.Cancel), ResponseType.Cancel);
            dialog.AddActionWidget(new Button(Stock.Ok), ResponseType.Ok);

            //three columns for items, sorting, PropGrid
            HBox hBox = new HBox();
            dialog.VBox.PackStart(hBox, true, true, 5);

            //propGrid at end
            grid = new InspectorGrid(base.EditorManager)
            {
                CurrentObject = null,
                WidthRequest  = 200,
                ShowHelp      = false
            };
            hBox.PackEnd(grid, true, true, 5);

            //followed by a ButtonBox
            VBox buttonBox = new VBox();
            buttonBox.Spacing = 6;
            hBox.PackEnd(buttonBox, false, false, 5);

            //add/remove buttons
            Button addButton = new Button(new Image(Stock.Add, IconSize.Button));
            buttonBox.PackStart(addButton, false, false, 0);
            if (types [0].IsAbstract)
            {
                addButton.Sensitive = false;
            }
            Button removeButton = new Button(new Gtk.Image(Stock.Remove, IconSize.Button));
            buttonBox.PackStart(removeButton, false, false, 0);

            //sorting buttons
            Button upButton = new Button(new Image(Stock.GoUp, IconSize.Button));
            buttonBox.PackStart(upButton, false, false, 0);
            Button downButton = new Button(new Image(Stock.GoDown, IconSize.Button));
            buttonBox.PackStart(downButton, false, false, 0);

            //Third column has list(TreeView) in a ScrolledWindow
            ScrolledWindow listScroll = new ScrolledWindow();
            listScroll.WidthRequest  = 200;
            listScroll.HeightRequest = 320;
            hBox.PackStart(listScroll, false, false, 5);

            itemTree = new TreeView(itemStore);
            itemTree.Selection.Mode = SelectionMode.Single;
            itemTree.HeadersVisible = false;
            listScroll.AddWithViewport(itemTree);

            //renderers and attribs for TreeView
            CellRenderer rdr = new CellRendererText();
            itemTree.AppendColumn(new TreeViewColumn("Index", rdr, "text", 1));
            rdr = new CellRendererText();
            itemTree.AppendColumn(new TreeViewColumn("Object", rdr, "text", 2));

            #endregion

            #region Events

            addButton.Clicked += delegate {
                //create the object
                object instance = System.Activator.CreateInstance(types[0]);

                //get existing selection and insert after it
                TreeIter oldIter, newIter;
                if (itemTree.Selection.GetSelected(out oldIter))
                {
                    newIter = itemStore.InsertAfter(oldIter);
                }
                //or append if no previous selection
                else
                {
                    newIter = itemStore.Append();
                }
                itemStore.SetValue(newIter, 0, instance);

                //select, set name and update all the indices
                itemTree.Selection.SelectIter(newIter);
                UpdateName(itemStore, newIter);
                UpdateIndices(itemStore);
            };

            removeButton.Clicked += delegate {
                //get selected iter and the replacement selection
                TreeIter iter, newSelection;
                if (!itemTree.Selection.GetSelected(out iter))
                {
                    return;
                }

                newSelection = iter;
                if (!IterPrev(itemStore, ref newSelection))
                {
                    newSelection = iter;
                    if (!itemStore.IterNext(ref newSelection))
                    {
                        newSelection = TreeIter.Zero;
                    }
                }

                //new selection. Zeroing previousIter prevents trying to update name of deleted iter.
                previousIter = TreeIter.Zero;
                if (itemStore.IterIsValid(newSelection))
                {
                    itemTree.Selection.SelectIter(newSelection);
                }

                //and the removal and index update
                itemStore.Remove(ref iter);
                UpdateIndices(itemStore);
            };

            upButton.Clicked += delegate {
                TreeIter iter, prev;
                if (!itemTree.Selection.GetSelected(out iter))
                {
                    return;
                }

                //get previous iter
                prev = iter;
                if (!IterPrev(itemStore, ref prev))
                {
                    return;
                }

                //swap the two
                itemStore.Swap(iter, prev);

                //swap indices too
                object prevVal = itemStore.GetValue(prev, 1);
                object iterVal = itemStore.GetValue(iter, 1);
                itemStore.SetValue(prev, 1, iterVal);
                itemStore.SetValue(iter, 1, prevVal);
            };

            downButton.Clicked += delegate {
                TreeIter iter, next;
                if (!itemTree.Selection.GetSelected(out iter))
                {
                    return;
                }

                //get next iter
                next = iter;
                if (!itemStore.IterNext(ref next))
                {
                    return;
                }

                //swap the two
                itemStore.Swap(iter, next);

                //swap indices too
                object nextVal = itemStore.GetValue(next, 1);
                object iterVal = itemStore.GetValue(iter, 1);
                itemStore.SetValue(next, 1, iterVal);
                itemStore.SetValue(iter, 1, nextVal);
            };

            itemTree.Selection.Changed += delegate {
                TreeIter iter;
                if (!itemTree.Selection.GetSelected(out iter))
                {
                    removeButton.Sensitive = false;
                    return;
                }
                removeButton.Sensitive = true;

                //update grid
                object obj = itemStore.GetValue(iter, 0);
                grid.CurrentObject = obj;

                //update previously selected iter's name
                UpdateName(itemStore, previousIter);

                //update current selection so we can update
                //name next selection change
                previousIter = iter;
            };

            grid.Changed += delegate {
                TreeIter iter;
                if (itemTree.Selection.GetSelected(out iter))
                {
                    UpdateName(itemStore, iter);
                }
            };

            TreeIter selectionIter;
            removeButton.Sensitive = itemTree.Selection.GetSelected(out selectionIter);

            dialog.ShowAll();
            grid.ShowToolbar = false;

            #endregion

            //if 'OK' put items back in collection
            if (GtkExtensions.ShowCustomDialog(dialog, toplevel) == (int)ResponseType.Ok)
            {
                DesignerTransaction tran = CreateTransaction(Instance);
                object old = collection;

                try {
                    collection.Clear();
                    foreach (object[] o in itemStore)
                    {
                        collection.Add(o[0]);
                    }
                    EndTransaction(Instance, tran, old, collection, true);
                }
                catch {
                    EndTransaction(Instance, tran, old, collection, false);
                    throw;
                }
            }
        }