gtk-sharp [00 24 00 00 04 80 00 00 94 00 00 00 06 02 00 00 00 24 00 00 52 53 41 31 00 04 00 00 01 00 01 00 71 EB 6C 55 75 52 9C BF 72 44 F7 A6 EA 05 62 84 F9 EA E0 3B CF F2 CC 13 2C 9C 49 0A B3 09 EA B0 B5 6B CE 44 9D F5 03 D9 C0 A8 1E 52 05 85 CD BE 70 E2 FB 90 43 4B AC 04 FA 62 22 A8 00 98 B7 A1 A7 B3 AF 99 1A 41 23 24 BB 43 25 F6 B8 65 BB 64 EB F6 D1 C2 06 D5 73 2D DF BC 70 A7 38 9E E5 3E 0C 24 6E 32 79 74 1A D0 05 03 E4 98 42 E1 9B F3 7B 19 8B 40 21 26 CB 36 89 C2 EA 64 96 A4 7C B4] 2.6.0.0 Gtk# is thread aware, but not thread safe; See the Gtk# Thread Programming for details. A widget which displays a list of icons in a grid provides an alternative view on a list model. It displays the model as a grid of icons with labels. Like , it allows to select one or multiple items (depending on the selection mode, see ). In addition to selection with the arrow keys, supports rubberband selection, which is controlled by dragging the pointer. using System; using System.IO; using Gtk; public class DemoIconView : Window { const int COL_PATH = 0; const int COL_DISPLAY_NAME = 1; const int COL_PIXBUF = 2; const int COL_IS_DIRECTORY = 3; DirectoryInfo parent = new DirectoryInfo ("/"); Gdk.Pixbuf dirIcon, fileIcon; ListStore store; ToolButton upButton; static void Main () { Application.Init (); new DemoIconView (); Application.Run (); } public DemoIconView () : base ("Gtk.IconView demo") { SetDefaultSize (650, 400); DeleteEvent += new DeleteEventHandler (OnWinDelete); VBox vbox = new VBox (false, 0); Add (vbox); Toolbar toolbar = new Toolbar (); vbox.PackStart (toolbar, false, false, 0); upButton = new ToolButton (Stock.GoUp); upButton.IsImportant = true; upButton.Sensitive = false; toolbar.Insert (upButton, -1); ToolButton homeButton = new ToolButton (Stock.Home); homeButton.IsImportant = true; toolbar.Insert (homeButton, -1); fileIcon = GetIcon ("gnome-fs-regular"); dirIcon = GetIcon ("gnome-fs-directory"); ScrolledWindow sw = new ScrolledWindow (); sw.ShadowType = ShadowType.EtchedIn; sw.SetPolicy (PolicyType.Automatic, PolicyType.Automatic); vbox.PackStart (sw, true, true, 0); // Create the store and fill it with the contents of '/' store = CreateStore (); FillStore (); IconView iconView = new IconView (store); iconView.SelectionMode = SelectionMode.Multiple; upButton.Clicked += OnUpClicked; homeButton.Clicked += OnHomeClicked; iconView.TextColumn = COL_DISPLAY_NAME; iconView.PixbufColumn = COL_PIXBUF; iconView.ItemActivated += new ItemActivatedHandler (OnItemActivated); sw.Add (iconView); iconView.GrabFocus (); ShowAll (); } Gdk.Pixbuf GetIcon (string name) { return Gtk.IconTheme.Default.LoadIcon (name, 48, (IconLookupFlags) 0); } ListStore CreateStore () { // path, name, pixbuf, is_dir ListStore store = new ListStore (typeof (string), typeof (string), typeof (Gdk.Pixbuf), typeof (bool)); // Set sort column and function store.DefaultSortFunc = SortFunc; store.SetSortColumnId (COL_DISPLAY_NAME, SortType.Ascending); return store; } void FillStore () { // first clear the store store.Clear (); // Now go through the directory and extract all the file information if (!parent.Exists) return; foreach (DirectoryInfo di in parent.GetDirectories ()) { if (!di.Name.StartsWith (".")) store.AppendValues (di.FullName, di.Name, dirIcon, true); } foreach (FileInfo file in parent.GetFiles ()) { if (!file.Name.StartsWith (".")) store.AppendValues (file.FullName, file.Name, fileIcon, false); } } int SortFunc (TreeModel model, TreeIter a, TreeIter b) { // sorts folders before files bool a_is_dir = (bool) model.GetValue (a, COL_IS_DIRECTORY); bool b_is_dir = (bool) model.GetValue (b, COL_IS_DIRECTORY); string a_name = (string) model.GetValue (a, COL_DISPLAY_NAME); string b_name = (string) model.GetValue (b, COL_DISPLAY_NAME); if (!a_is_dir && b_is_dir) return 1; else if (a_is_dir && !b_is_dir) return -1; else return String.Compare (a_name, b_name); } void OnHomeClicked (object sender, EventArgs a) { parent = new DirectoryInfo (Environment.GetFolderPath (Environment.SpecialFolder.Personal)); FillStore (); upButton.Sensitive = true; } void OnItemActivated (object sender, ItemActivatedArgs a) { TreeIter iter; store.GetIter (out iter, a.Path); string path = (string) store.GetValue (iter, COL_PATH); bool isDir = (bool) store.GetValue (iter, COL_IS_DIRECTORY); if (!isDir) return; // Replace parent with path and re-fill the model parent = new DirectoryInfo (path); FillStore (); // Sensitize the up button upButton.Sensitive = true; } void OnUpClicked (object sender, EventArgs a) { parent = parent.Parent; FillStore (); upButton.Sensitive = (parent.FullName == "/" ? false : true); } void OnWinDelete (object sender, DeleteEventArgs a) { Application.Quit (); a.RetVal = true; } } Gtk.Container Method System.Void Default handler for the event. Override this method in a subclass to provide a default handler for the event. Method System.Void Default handler for the event. Override this method in a subclass to provide a default handler for the event. Method System.Void Default handler for the event. a Override this method in a subclass to provide a default handler for the event. Method System.Void Default handler for the event. Override this method in a subclass to provide a default handler for the event. Method System.Void Default handler for the event. Override this method in a subclass to provide a default handler for the event. Method System.Boolean Default handler for the event. a a a Override this method in a subclass to provide a default handler for the event. Method System.Boolean Default handler for the event. a Override this method in a subclass to provide a default handler for the event. Method System.Void Default handler for the event. Override this method in a subclass to provide a default handler for the event. Method System.Void Unselects all the icons. Method System.Void Calls a function for each selected icon. a Note that the model or selection cannot be modified from within this function. Method System.Void Unselects the row at . a Method System.Void Selects all the icons. The IconView must has its selection mode set to . Method System.Boolean Returns if the icon pointed to by is currently selected. a a If does not point to a valid location, is returned. Method Gtk.TreePath To be added a a a To be added Method System.Void Activates the item determined by . a Method System.Void Selects the row at . a Constructor Protected Constructor. a Chain to this constructor if you have manually registered a native value for your subclass. System.Obsolete(Message=null, IsError=False) Constructor Internal constructor a This is not typically used by C# code. Constructor Default constructor Constructor Create a new IconView with a model. a Property GLib.GType GType Property. a Returns the native value for . Property Gtk.SelectionMode Specifies the selection mode of icon view. a If the mode is , rubberband selection is enabled, for the other modes, only keyboard selection is possible. GLib.Property(Name="selection_mode") Property System.Int32 The columns property contains the number of the columns in which the items should be displayed. a If it is -1, the number of columns will be chosen automatically to fill the available area. GLib.Property(Name="columns") Property System.Int32 Space which is inserted at the edges of the icon view. a Default value is 6. GLib.Property(Name="margin") Property Gtk.Orientation How the text and icon of each item are positioned relative to each other. a Default value is GLib.Property(Name="orientation") Property System.Int32 The width used for each item. a GLib.Property(Name="item_width") Property System.Int32 Contains the number of the model column containing the texts which are displayed. a The text column must be of type . If this property and the MarkupColumn property are both set to -1, no text is displayed. GLib.Property(Name="text_column") Property System.Int32 Space which is inserted between cells of an item. a To be added GLib.Property(Name="spacing") Property System.Int32 Contains the number of the model column containing the pixbufs which are displayed a The pixbuf column must be of type . Setting this property to -1 turns off the display of pixbufs. GLib.Property(Name="pixbuf_column") Property System.Int32 Space which is inserted between grid rows. a Default value is 6. GLib.Property(Name="row_spacing") Property System.Int32 Space which is inserted between grid column. a Default value is 6. GLib.Property(Name="column_spacing") Property System.Int32 Contains the number of the model column containing markup information to be displayed. a The markup column must be of type . If this property and the TextColumn property are both set to column numbers, it overrides the text column. If both are set to -1, no texts are displayed. GLib.Property(Name="markup_column") Property Gtk.TreeModel The model for the icon view. a GLib.Property(Name="model") Property Gtk.TreePath[] Creates a list of paths of all selected items. a Event System.EventHandler Emitted when the current selection changes. To be added GLib.Signal(CName="selection_changed") Event System.EventHandler Emitted when UnselectAll () is called. GLib.Signal(CName="unselect_all") Event Gtk.ItemActivatedHandler Emitted when an item is activated. GLib.Signal(CName="item_activated") Event System.EventHandler Emitted when SelectAll () is called. GLib.Signal(CName="select_all") Event System.EventHandler To be added GLib.Signal(CName="toggle_cursor_item") Event Gtk.MoveCursorHandler To be added GLib.Signal(CName="move_cursor") Event Gtk.ActivateCursorItemHandler To be added To be added GLib.Signal(CName="activate_cursor_item") Event System.EventHandler To be added GLib.Signal(CName="select_cursor_item")