コード例 #1
0
        /// <summary>
        /// This returns the currently selected category.
        /// TODO: This should really be moved as a method Application or
        /// or something.
        /// </summary>
        /// <returns>
        /// A <see cref="ICategory"/>
        /// </returns>
        private ICategory GetSelectedCategory()
        {
            // TODO: Move this code into some function in the backend/somewhere
            // with the signature of GetCategoryForName (string catName):ICategory
            string selectedCategoryName =
                Application.Preferences.Get(Preferences.SelectedCategoryKey);

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

                // Iterate through (yeah, I know this is gross!) and find the
                // matching category
                if (model.GetIterFirst(out iter))
                {
                    do
                    {
                        ICategory cat = model.GetValue(iter, 0) as ICategory;
                        if (cat == null)
                        {
                            continue;                             // Needed for some reason to prevent crashes from some backends
                        }
                        if (cat.Name.CompareTo(selectedCategoryName) == 0)
                        {
                            return(cat);
                        }
                    } while (model.IterNext(ref iter));
                }
            }

            return(null);
        }
コード例 #2
0
        // Find the index within the tree
        public int GetIterIndex(Gtk.TreeIter iter)
        {
            Gtk.TreePath  path = treeView.Model.GetPath(iter);
            Gdk.Rectangle rect =
                treeView.GetBackgroundArea(path, treeView.GetColumn(0));

            int pos = 0;

            Gtk.TreeIter  tempIter;
            Gtk.TreeModel model = treeView.Model;
            ITask         task  = model.GetValue(iter, 0) as ITask;

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

            // This is ugly, but figure out what position the specified iter is
            // at so we can return a value accordingly.
            do
            {
                ITask tempTask = model.GetValue(tempIter, 0) as ITask;
                if (tempTask == task)
                {
                    break;
                }

                pos++;
            } while (model.IterNext(ref tempIter));

            return(pos);
        }
コード例 #3
0
        /// <summary>
        /// Convenience method to determine whether the specified task is
        /// currently shown in this TaskGroup.
        /// </summary>
        /// <param name="task">
        /// A <see cref="ITask"/>
        /// </param>
        /// <param name="iter">
        /// A <see cref="Gtk.TreeIter"/>
        /// </param>
        /// <returns>
        /// A <see cref="System.Boolean"/> True if the specified <see
        /// cref="ITask">task</see> is currently shown inside this TaskGroup.
        /// Additionally, if true, the <see cref="Gtk.TreeIter">iter</see> will
        /// point to the specified <see cref="ITask">task</see>.
        /// </returns>
        public bool ContainsTask(ITask task, out Gtk.TreeIter iter)
        {
            Gtk.TreeIter  tempIter;
            Gtk.TreeModel model = treeView.Model;

            iter = Gtk.TreeIter.Zero;

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

            // Loop through the model looking for a matching task
            do
            {
                ITask tempTask = model.GetValue(tempIter, 0) as ITask;
                if (tempTask == task)
                {
                    iter = tempIter;
                    return(true);
                }
            } while (model.IterNext(ref tempIter));

            return(false);
        }
コード例 #4
0
ファイル: TreeMap.cs プロジェクト: siaf/custom-gtk-widgets
            public TreeMapItem(Gtk.TreeModel m,
                               ref Gtk.TreeIter iter,
                               bool horiz,
                               int textColumn,
                               int weightColumn)
            {
                if (m == null)
                {
                    throw new ArgumentNullException("m");
                }

                if (iter.Equals(Gtk.TreeIter.Zero))
                {
                    throw new ArgumentException("iter");
                }

                if (textColumn < 0)
                {
                    throw new ArgumentException("textColumn");
                }

                if (weightColumn < 0)
                {
                    throw new ArgumentException("weightColumn");
                }

                Path     = m.GetPath(iter);
                Title    = (string)m.GetValue(iter, textColumn);
                Weight   = (double)m.GetValue(iter, weightColumn);
                X        = 0;
                Y        = 0;
                Width    = 0;
                Height   = 0;
                Children = null;
                Horiz    = horiz;

                Gtk.TreeIter citer;
                double       c_total = 0.0;

                if (m.IterChildren(out citer, iter))
                {
                    do
                    {
                        AddChild(new TreeMapItem(m, ref citer, !horiz, textColumn, weightColumn));
                    } while (m.IterNext(ref citer));

                    // Get total weight
                    Children.ForEach(delegate(TreeMapItem i) {
                        c_total += Math.Abs(i.Weight);
                    });

                    this.ChildrenWeight = c_total;
                }
            }
コード例 #5
0
 protected void BtnOk_Click(object sender, EventArgs e)
 {
     Gtk.TreeModel model = nodeView.Model;
     Gtk.TreeIter  iter;
     if (model.GetIterFirst(out iter))
     {
         do
         {
             if ((bool)nodeView.Model.GetValue(iter, 0))
             {
                 ResourceLocation rl = new ResourceLocation();
                 rl.URL = nodeView.Model.GetValue(iter, 1).ToString();
                 Downloader download = DownloadManager.Instance.Add(
                     rl,
                     new ResourceLocation[0],
                     System.IO.Path.Combine(MonoDM.Core.Settings.Default.DownloadFolder, PathHelper.GetFileNameFromUrl(rl.URL)),
                     MonoDM.Core.Settings.Default.MaxSegments,
                     cbStartNow.Active);
             }
         } while (model.IterNext(ref iter));
     }
     Destroy();
 }
コード例 #6
0
        // Find the height position within the tree
        public int GetIterPos(Gtk.TreeIter iter)
        {
            Gtk.TreePath  path = treeView.Model.GetPath(iter);
            Gdk.Rectangle rect =
                treeView.GetBackgroundArea(path, treeView.GetColumn(0));
            int height = rect.Height;

            int pos = 0;

            Gtk.TreeIter  tempIter;
            Gtk.TreeModel model = treeView.Model;
            ITask         task  = model.GetValue(iter, 0) as ITask;

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

            // This is ugly, but figure out what position the specified iter is
            // at so we can return a value accordingly.
            do
            {
                ITask tempTask = model.GetValue(tempIter, 0) as ITask;
                if (tempTask == task)
                {
                    break;
                }

                pos++;
            } while (model.IterNext(ref tempIter));

//Logger.Debug ("pos: {0}", pos);
//Logger.Debug ("height: {0}", height);
//Logger.Debug ("returning: {0}", pos * height + header.Requisition.Height + 10);
            // + 10 is for the spacing added on when packing the header
            return(pos * height + header.Requisition.Height);
        }