Ejemplo n.º 1
0
        protected ICategory GetSelectedCategory()
        {
            ICategory foundCategory = null;

            string cat = Application.Preferences.Get(
                Preferences.SelectedCategoryKey);

            if (cat != null)
            {
                TreeIter  iter;
                TreeModel model = Application.Backend.Categories;

                if (model.GetIterFirst(out iter))
                {
                    do
                    {
                        ICategory category = model.GetValue(iter, 0) as ICategory;
                        if (category.Name.CompareTo(cat) == 0)
                        {
                            foundCategory = category;
                            break;
                        }
                    } while (model.IterNext(ref iter));
                }
            }

            return(foundCategory);
        }
Ejemplo n.º 2
0
        List <Command> FindBindings(string accel)
        {
            List <Command> bindings = new List <Command> ();
            TreeModel      model    = (TreeModel)keyStore;
            TreeIter       iter;

            if (!model.GetIterFirst(out iter))
            {
                return(bindings);
            }
            do
            {
                TreeIter citer;
                model.IterChildren(out citer, iter);
                do
                {
                    string binding = (string)model.GetValue(citer, bindingCol);
                    if (Conflicts(binding, accel))
                    {
                        Command command = (Command)model.GetValue(citer, commandCol);
                        bindings.Add(command);
                    }
                } while (model.IterNext(ref citer));
            } while (model.IterNext(ref iter));
            return(bindings);
        }
Ejemplo n.º 3
0
        public CustomerSelectDialog(Gtk.Window parent, List <string> customerList, List <string> selectedCustomers)
        {
            this.Build();
            this.TransientFor = parent;
            this.SetPosition(WindowPosition.CenterAlways);
            m_customerList = customerList;

            treeview_customer_list.AppendColumn("图片", new CellRendererPixbuf(), "pixbuf", 0);
            treeview_customer_list.AppendColumn("名称", new CellRendererText(), "text", 1);
            treeview_customer_list.Selection.Mode = SelectionMode.Multiple;
            Utils.ShowCustomerList(m_customerList, treeview_customer_list);

            if (selectedCustomers != null && selectedCustomers.Count > 0)
            {
                TreeIter  iter;
                TreeModel model = treeview_customer_list.Model;
                if (model.GetIterFirst(out iter))
                {
                    do
                    {
                        if (selectedCustomers.Contains((string)model.GetValue(iter, 2)))
                        {
                            treeview_customer_list.Selection.SelectIter(iter);
                        }
                    } while (model.IterNext(ref iter));
                }
            }
        }
Ejemplo n.º 4
0
        //generally useful function... why not in model already?
        private bool IterPrev(TreeModel model, ref TreeIter iter)
        {
            TreeIter prev, next;

            if (!model.GetIterFirst(out prev))
            {
                return(false);
            }

            do
            {
                next = prev.Copy();

                if (!itemStore.IterNext(ref next))
                {
                    return(false);
                }

                //if next one on from prev is our iter
                //then 'prev' is correct previous iter
                if (next.Equals(iter))
                {
                    iter = prev;
                    return(true);
                }
            } while (itemStore.IterNext(ref prev));

            return(false);
        }
Ejemplo n.º 5
0
        private void BuildGroupButtonsView()
        {
            TreeIter iter;

            Logger.Debug("GroupWindow.BuildGroupButtonsView adding {0} groups",
                         groupTreeModel.IterNChildren());

            // Loop through the model, create buttons, and add them into the
            // groupButtonsVBox.
            if (groupTreeModel.GetIterFirst(out iter))
            {
                do
                {
                    PersonGroup group =
                        groupTreeModel.GetValue(iter, 0) as PersonGroup;
                    if (group == null)
                    {
                        continue;
                    }

                    AddGroupButton(new GroupButton(group),
                                   groupTreeModel.GetPath(iter));
                } while (groupTreeModel.IterNext(ref iter));
            }
        }
Ejemplo n.º 6
0
        public int AppendColumn(GridViewColumn col)
        {
            col.VisibilityChanged +=
                new EventHandler(OnColumnVisibilityChanged);

            if (col.Visible)
            {
                if (orientation == Orientation.Vertical)
                {
                    widths.Add(0);
                }
                else
                {
                    heights.Add(0);
                }

                visible.Add(col);

                TreeIter i;

                if (model != null && model.GetIterFirst(out i))
                {
                    do
                    {
                        TreePath path = model.GetPath(i);
                        MeasureCell(path, col);
                    } while (model.IterNext(ref i));
                }

                if (Visible)
                {
                    UpdateDrawingAreaSizeRequests();
                }
            }

            int ret = columns.Add(col);

            if (ColumnsChanged != null)
            {
                ColumnsChanged(this, EventArgs.Empty);
            }

            return(ret);
        }
Ejemplo n.º 7
0
 bool System.Collections.IEnumerator.MoveNext()
 {
     if (mModel == null)
     {
         return(false);
     }
     return(mIter.Equals(TreeIter.Zero)
        ? mModel.GetIterFirst(out mIter)
        : mModel.IterNext(ref mIter));
 }
Ejemplo n.º 8
0
        IEnumerable <TreeIter> WalkStore(TreeModel model)
        {
            TreeIter iter;
            bool     valid = model.GetIterFirst(out iter);

            while (valid)
            {
                yield return(iter);

                valid = model.IterNext(ref iter);
            }
        }
Ejemplo n.º 9
0
        public static bool GetIterLast(this TreeModel model, out TreeIter iter)
        {
            iter = TreeIter.Zero;
            TreeIter result;

            if (!model.GetIterFirst(out result))
            {
                return(false);
            }
            iter = result;
            while (model.IterNext(ref result))
            {
                iter = result;
            }
            return(true);
        }
Ejemplo n.º 10
0
        public override List <AppResult> Children(bool recursive = true)
        {
            if (resultIter == null || !resultIter.HasValue)
            {
                List <AppResult> children = new List <AppResult> ();
                TreeIter         topIter;
                if (TModel.GetIterFirst(out topIter))
                {
                    var child = new GtkTreeModelResult(ParentWidget, TModel, Column, topIter);
                    children.Add(child);
                    this.FirstChild  = child;
                    child.ParentNode = this;

                    if (recursive)
                    {
                        var topIterChildren = FetchIterChildren(topIter, child, recursive);
                        child.FirstChild = topIterChildren.FirstOrDefault();
                        children.AddRange(topIterChildren);
                    }

                    GtkTreeModelResult previousSibling = child;
                    while (TModel.IterNext(ref topIter))
                    {
                        var nextSibling = new GtkTreeModelResult(ParentWidget, TModel, Column, topIter);
                        children.Add(nextSibling);

                        nextSibling.PreviousSibling = previousSibling;
                        previousSibling.NextSibling = nextSibling;
                        nextSibling.ParentNode      = this;

                        if (recursive)
                        {
                            var topIterChildren = FetchIterChildren(topIter, nextSibling, recursive);
                            nextSibling.FirstChild = topIterChildren.FirstOrDefault();
                            children.AddRange(topIterChildren);
                        }
                    }
                }

                DisposeWithResult(FirstChild);
                return(children);
            }

            TreeIter currentIter = (TreeIter)resultIter;

            return(FetchIterChildren(currentIter, this, recursive));
        }
Ejemplo n.º 11
0
        // finds the specified item:
        // - select owner volume
        // - expand the treeview path to the item
        //   and select the item
        public void FindItem(VolumeItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            // get path of volume ids to item
            Stack <long> path = new Stack <long>();
            VolumeItem   tmp  = item;

            while (tmp.ItemID != 1)               // skip root item
            {
                path.Push(tmp.ItemID);
                tmp = database.GetVolumeItem(tmp.VolumeID, tmp.ParentID);
            }

            // find and select volume of specified item
            TreeModel model = tvVolumes.Model;
            TreeIter  iter;
            long      volumeID     = item.VolumeID;
            bool      hasMoreIters = true;

            model.GetIterFirst(out iter);

            while (hasMoreIters)
            {
                Volume vol = tvVolumes.GetVolume(iter);

                if (vol.VolumeID == volumeID)
                {
                    // select owner volume
                    tvVolumes.Selection.SelectIter(iter);
                    tvVolumes.ScrollToCell(model.GetPath(iter), null, false, .0f, .0f);

                    if (path.Count > 0)
                    {
                        // find and select specified item
                        tvItems.Model.GetIterFirst(out iter);
                        FindItemRecursive(iter, path);
                    }                     // else : specified item is the root item so select nothing
                    break;
                }

                hasMoreIters = model.IterNext(ref iter);
            }
        }
Ejemplo n.º 12
0
        private void PopulatePersonView()
        {
            List <Widget> children = new List <Widget> (vbox.Children);

            foreach (Widget child in children)
            {
                vbox.Remove(child);
                try {
                    child.Destroy();
                } catch {}
            }

            // personCardMap.Clear ();

            if (model == null)
            {
                Logger.Debug("PersonView.PopulatePersonView returning since the model is null.");
                return;
            }

            TreeIter iter;

            // Loop through the model, create the PersonCard objects and add
            // them into the vbox.
            if (model.GetIterFirst(out iter))
            {
                do
                {
                    Person person = model.GetValue(iter, 0) as Person;
                    if (person == null)
                    {
                        continue;
                    }

                    TreePath   path = model.GetPath(iter);
                    PersonCard card = new PersonCard(person);
                    card.Size = personCardSize;
                    card.ShowAll();
                    vbox.PackStart(card, false, false, 0);
                    vbox.ReorderChild(card, path.Indices [0]);
                    // personCardMap[iter] = card;
                } while (model.IterNext(ref iter));
            }
        }
Ejemplo n.º 13
0
        List <String> GetConfigFromTreeview(TreeView tv)
        {
            TreeIter      iter;
            List <String> config = new List <string> ();

            try {
                TreeModel model = tv.Model;
                model.GetIterFirst(out iter);
                do
                {
                    config.Add(model.GetValue(iter, 0).ToString());
                } while (model.IterNext(ref iter));
                return(config);
            } catch (Exception ex) {
                MainClass.log.Error("Load config from treeview failed");
                MainClass.log.Debug(ex.Message);
                MainClass.log.Debug(ex.StackTrace);
                return(config = new List <string> ());
            }
        }
Ejemplo n.º 14
0
        void DoTheExport(MiscHelpers.TemplateType type)
        {
            TreeModel model = treeDebaters.Model;
            TreeIter  iter;

            if (model.GetIterFirst(out iter))
            {
                try {
                    ITemplate  tmpl         = MiscHelpers.GetTemplate("debaters", type);
                    ITmplBlock tmplDebaters = tmpl.ParseBlock("DEBATERS");
                    int        n            = 0;
                    do
                    {
                        n++;
                        TreeIter        storeIter = ConvertModelIterToStoreIter(iter);
                        EditableDebater d         = (EditableDebater)store.GetValue(storeIter, 0);
                        tmplDebaters.Assign("NUM", n.ToString());
                        tmplDebaters.Assign("NAME", d.Name.ToString());
                        tmplDebaters.Assign("CLUB", d.Club.ToString());
                        tmplDebaters.Assign("AGE", d.Age.ToString());
                        tmplDebaters.Assign("ROLE", EscapeString(d.Role.ToString(), type));
                        tmplDebaters.Assign("BLACKLIST", EscapeString(d.BlackList.ToString(), type));
                        tmplDebaters.Assign("WHITELIST", EscapeString(d.WhiteList.ToString(), type));
                        tmplDebaters.Assign("EXTRAINFO", EscapeString(d.ExtraInfo.ToString(), type));
                        tmplDebaters.Out();
                    }while(model.IterNext(ref iter));
                    MiscHelpers.AskShowTemplate(this,
                                                "Debaters successfully generated, see " +
                                                "pdfs/debaters.(pdf|csv)",
                                                MiscHelpers.MakeExportFromTemplate()
                                                );
                }
                catch (Exception ex) {
                    MiscHelpers.ShowMessage(this, "Could not export Debaters: " + ex.Message, MessageType.Error);
                }
            }
        }
Ejemplo n.º 15
0
        // returns true if the model contains no rows
        public static bool IsEmpty(this TreeModel model)
        {
            TreeIter iter;

            return(!model.GetIterFirst(out iter) || iter.Equals(TreeIter.Zero));
        }
Ejemplo n.º 16
0
        private void Redraw(Cairo.Context cr)
        {
            // Clear the background
            cr.Rectangle(0, 0, Allocation.Width, Allocation.Height);
            Gdk.CairoHelper.SetSourceColor(cr, Style.Base(State));
            cr.Fill();

            if (model == null)
            {
                if (hadj != null)
                {
                    hadj.Upper = hadj.Lower = 0;
                    hadj.Change();
                }

                if (vadj != null)
                {
                    vadj.Upper = 0;
                    vadj.Change();
                }
                return;
            }

            if (rows == 0 || cols == 0)
            {
                return;
            }

            Gdk.Rectangle background_area = cell_size;
            background_area.Width  += padding;
            background_area.Height += padding;

            TreeIter iter;

            if (model.GetIterFirst(out iter))
            {
                do
                {
                    TreePath path = model.GetPath(iter);

                    int x, y;
                    GetCellPosition(path.Indices[0], out x, out y);

                    if (hadj != null &&
                        (x + cell_size.Width < hadj.Value ||
                         x > hadj.Value + hadj.PageSize))
                    {
                        continue;
                    }

                    if (vadj != null &&
                        (y + cell_size.Height < vadj.Value ||
                         y > vadj.Value + vadj.PageSize))
                    {
                        continue;
                    }

                    if (data_func != null)
                    {
                        data_func(this, renderer, model, iter);
                    }

                    cell_size.X = x;
                    cell_size.Y = y;

                    if (hadj != null)
                    {
                        cell_size.X -= (int)hadj.Value;
                    }

                    if (vadj != null)
                    {
                        cell_size.Y -= (int)vadj.Value;
                    }

                    background_area.X = cell_size.X - (padding / 2);
                    background_area.Y = cell_size.Y - (padding / 2);

                    cr.Rectangle(background_area.X, background_area.Y,
                                 background_area.Width, background_area.Height);
                    cr.Clip();

                    renderer.Render(cr, this, background_area,
                                    cell_size, GetCellState(path));

                    cr.ResetClip();
                } while (model.IterNext(ref iter));
            }

            if (have_rubberband_selection)
            {
                int hadj_val = (hadj != null) ? (int)hadj.Value : 0;
                int vadj_val = (vadj != null) ? (int)vadj.Value : 0;

                cr.Rectangle(sel_rect.X - hadj_val + 0.5f, sel_rect.Y - vadj_val + 0.5f,
                             sel_rect.Width, sel_rect.Height);

                Cairo.Color sel_cairo_color = CairoHelper.GetCairoColor(Style.Background(StateType.Selected));



                //cr.Color = sel_cairo_color;
                cr.SetSourceRGBA(sel_cairo_color.R, sel_cairo_color.G, sel_cairo_color.B, sel_cairo_color.A);

                cr.LineWidth = 1.0f;
                cr.StrokePreserve();

                sel_cairo_color.A = 0.3f;
                //cr.Color = sel_cairo_color;
                cr.SetSourceRGBA(sel_cairo_color.R, sel_cairo_color.G, sel_cairo_color.B, sel_cairo_color.A);

                cr.Fill();
            }
        }
Ejemplo n.º 17
0
            private static bool UpdateGameInModel(PGNChessGame
							       game,
							       PGNChessGame
							       replace,
							       TreeModel
							       model)
            {
                TreeIter iter;
                bool ret;
                for (ret = model.GetIterFirst (out iter); ret;
                     ret = model.IterNext (ref iter))
                  {
                      PGNChessGame g =
                          (PGNChessGame) model.
                          GetValue (iter, 0);
                      if (g.Equals (game))
                        {
                            model.SetValue (iter, 0,
                                    replace);
                            return true;
                        }
                  }

                return false;
            }
Ejemplo n.º 18
0
        protected void OnButton45Clicked(object sender, EventArgs e)
        {
            TcpClient client                  = new TcpClient(ServerIp, Int32.Parse(TcpPort));
            object    content                 = AssignmentChange;
            Type      contentType             = AssignmentChange.GetType();
            Protocol  submitAssignmentChanges = new Protocol(client, ConstValues.PROTOCOL_FN_SAVE_ASSIGNMENT, contentType, content);

            submitAssignmentChanges.Start();
            if ((String)submitAssignmentChanges.ResultObject == "True")
            {
                List <Dictionary <String, String> > assignmentList = new List <Dictionary <string, string> > ();
                TreeIter  iter;
                TreeModel model    = treeview6.Model;
                string    agent_id = combobox2.ActiveText.Split(':') [1];
                if (model.GetIterFirst(out iter))
                {
                    do
                    {
                        Dictionary <String, String> gpuAssign = new Dictionary <string, string> ();
                        gpuAssign.Add("agent_id", agent_id);
                        gpuAssign.Add("resource_ip", model.GetValue(iter, 0).ToString());
                        gpuAssign.Add("gpu_id", model.GetValue(iter, 1).ToString());
                        assignmentList.Add(gpuAssign);
                    } while(model.IterNext(ref iter));
                }
                List <String> rCudaClientRuntimeConfig = Configuration.GenerateRcudaClientRuntimeConfig(assignmentList);
                TcpClient     client2                   = new TcpClient(ServerIp, Int32.Parse(TcpPort));
                object        contentConfig             = rCudaClientRuntimeConfig;
                Type          contentTypeConfig         = rCudaClientRuntimeConfig.GetType();
                Protocol      uploadRuntimeClientConfig = new Protocol(client2, ConstValues.PROTOCOL_FN_SAVE_RCUDA_CLIENT_CONFIG, contentTypeConfig, contentConfig);
                uploadRuntimeClientConfig.Start();
                if ((String)uploadRuntimeClientConfig.ResultObject == "True")
                {
                    MessageDialog msg = new MessageDialog(null, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, "Resource assignment and Runtime Config has been saved");
                    msg.Response += (o, args) => {
                        if (args.ResponseId == ResponseType.Ok)
                        {
                            combobox2.Sensitive = true;
                            button48.Sensitive  = true;
                            button43.Sensitive  = false;
                            button44.Sensitive  = false;
                            button45.Sensitive  = false;
                            button46.Sensitive  = false;
                            gpuAssignView       = null;
                            AssignmentInProcess = false;
                            combobox2.Active    = -1;
                            foreach (var column in treeview6.Columns)
                            {
                                treeview6.RemoveColumn(column);
                            }
                            LoadAllGpuList();
                            msg.Destroy();
                        }
                    };
                    msg.Show();
                }
                else
                {
                    MessageDialog msg = new MessageDialog(null, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "Save Runtime Config Failed");
                    msg.Response += (o, args) => {
                        if (args.ResponseId == ResponseType.Ok)
                        {
                            msg.Destroy();
                        }
                    };
                    msg.Show();
                }
            }
            else
            {
                MessageDialog msg = new MessageDialog(null, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "Updating Resource Assignment Failed");
                msg.Response += (o, args) => {
                    if (args.ResponseId == ResponseType.Ok)
                    {
                        msg.Destroy();
                    }
                };
                msg.Show();
            }
        }
Ejemplo n.º 19
0
		IEnumerable<TreeIter> WalkStore (TreeModel model)
		{
			TreeIter iter;
			bool valid = model.GetIterFirst (out iter);
			while (valid) {
				yield return iter;
				valid = model.IterNext (ref iter);
			}
		}
Ejemplo n.º 20
0
        //generally useful function... why not in model already?
        private bool IterPrev(TreeModel model, ref TreeIter iter)
        {
            TreeIter prev, next;

            if (!model.GetIterFirst (out prev))
                return false;

            do {
                next = prev.Copy ();

                if (!itemStore.IterNext (ref next))
                    return false;

                //if next one on from prev is our iter
                //then 'prev' is correct previous iter
                if (next.Equals (iter)) {
                    iter = prev;
                    return true;
                }

            } while (itemStore.IterNext (ref prev));

            return false;
        }
Ejemplo n.º 21
0
        private void FocusHelper(bool move_next)
        {
            if (focused_path == null)
            {
                return;
            }

            TreeIter focused_iter;

            if (!model.GetIter(out focused_iter, focused_path))
            {
                return;
            }

            int focus_x, focus_y;

            GetPlotPoint(focused_iter, out focus_x, out focus_y);

            // we can't just do focused_path.Prev () since there is
            // a disconnect between the order in the model and
            // where the axis has us place points.  besides, we
            // need to clamp the focus region to the zoom rect.
            TreeIter iter;

            if (!model.GetIterFirst(out iter))
            {
                return;
            }

            int total_height = (Allocation.Y + Allocation.Height);

            TreePath min_path    = null;
            int      min_x_delta = Int32.MaxValue;
            int      min_y_delta = Int32.MaxValue;

            do
            {
                TreePath path = model.GetPath(iter);

                // don't try to focus the same point again
                if (path.Compare(focused_path) == 0)
                {
                    continue;
                }

                int x, y;
                GetPlotPoint(iter, out x, out y);

                // if its out of bounds, throw it out
                if (IsBarOutOfBounds(x, y))
                {
                    continue;
                }

                int x_delta = 0, y_delta = 0;
                if (move_next)
                {
                    // find the bar with the smallest positive x
                    // delta, and smallest y, or if there
                    // is a tie, the one that's larger on the y
                    // axis
                    x_delta = x - focus_x;
                    y_delta = (focus_x != x) ? total_height - y : focus_y - y;
                }
                else
                {
                    // find the bar with the smallest positive x
                    // delta, and largest y, or if there
                    // is a tie, the one that's larger on the y
                    // axis
                    x_delta = focus_x - x;
                    y_delta = (focus_x != x) ? y : y - focus_y;
                }

                // don't go backward, and don't pick a bigger
                // delta than we already have
                if (x_delta < 0 ||
                    x_delta > min_x_delta)
                {
                    continue;
                }

                if (x_delta == min_x_delta &&
                    y_delta >= min_y_delta)
                {
                    continue;
                }

                // if we're at the same X value, make sure
                // we're moving forward in the y direction so
                // we don't get stuck in loops
                if (x_delta == 0 &&
                    y_delta < 0)
                {
                    continue;
                }

                min_x_delta = x_delta;
                min_y_delta = y_delta;
                min_path    = path;
            } while (model.IterNext(ref iter));

            if (min_path != null)
            {
                focused_path = min_path;
            }
            else
            {
                if (move_next)
                {
                    focused_path = TreePath.NewFirst();
                }
                else
                {
                    focused_path = new TreePath(new int[] {
                        model.IterNChildren() - 1
                    });
                }
            }

            if (Changed != null)
            {
                Changed(this, new EventArgs());
            }
        }