/* * Copyright (C) 2005 Tamara Roberson * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ using System; namespace Muine { public class AddWindowList : HandleView { // Constructor /// /// Creates a new HandleView. /// /// /// This widget is intended for use with /// and should not be used by /// other classes. /// public AddWindowList () : base () { base.Selection.Mode = Gtk.SelectionMode.Multiple; } // Properties // Properties :: HasSelection (get;) /// /// Whether any rows are currently selected. /// /// /// True if at least one row is selected, otherwise false. /// public bool HasSelection { get { return (base.Selection.CountSelectedRows () > 0); } } // Properties :: DragSource (set;) /// /// Set the Drag-and-Drop types for the list. /// public Gtk.TargetEntry [] DragSource { set { Gdk.DragAction act = ( Gdk.DragAction.Copy | Gdk.DragAction.Link | Gdk.DragAction.Ask); base.EnableModelDragSource (Gdk.ModifierType.Button1Mask, value, act); } } // Properties :: Selected (get;) // TODO: Does it *have* to be a GLib.List? /// /// A of selected items. /// public GLib.List Selected { get { return base.SelectedHandles; } } // Methods // Methods :: Public // Methods :: Public :: HandleAdded /// /// Append the item given by if it /// . /// /// /// This is used when an has been added /// to the database. /// /// /// handle to add. /// /// /// Whether the item fits or not, as returned by /// . /// public void HandleAdded (IntPtr ptr, bool fits) { if (fits) base.Model.Append (ptr); } // Methods :: Public :: HandleChanged /// /// Modify the item given by if it /// . /// /// /// This is used when an has been changed. /// /// /// handle. /// /// /// Whether the item fits or not, as returned by /// . /// public void HandleChanged (IntPtr ptr, bool fits) { if (fits) { if (base.Model.Contains (ptr)) base.Model.Changed (ptr); else base.Model.Append (ptr); } else { base.Model.Remove (ptr); } SelectFirstIfNeeded (); } // Methods :: Public :: HandleRemoved /// /// Remove the given by /// . /// /// /// This is used when an has been removed. /// /// /// handle to remove. /// public void HandleRemoved (IntPtr ptr) { base.Model.Remove (ptr); SelectFirstIfNeeded (); } // Methods :: Private // Methods :: Private :: SelectFirstIfNeeded /// /// Select the first item in the list if an item is not /// currently selected and there are items in the list. /// private void SelectFirstIfNeeded () { if (!this.HasSelection && this.Model.Length > 0) SelectFirst (); } } }