/*
* Copyright (C) 2006-2007 Eskil Bylund
*
* 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
using System;
using System.Collections.Generic;
using Gtk;
using Mono.Unix;
namespace DCSharp.GUI{
public abstract class ExtendedTreeView : MenuTreeView
{
public ExtendedTreeView() : this(null)
{
}
public ExtendedTreeView(TreeModel model) : base(model)
{
#if GTK_2_10
RubberBanding = true;
#endif
RulesHint = true;
Selection.Mode = SelectionMode.Multiple;
}
public bool CanActivateMultipleRows
{
get { return activateMultipleRows; }
set { activateMultipleRows = value; }
}
private bool activateMultipleRows;
#region Methods
public TreeViewColumn GetColumn(string title)
{
title = Catalog.GetString(title);
return Array.Find(Columns, delegate(TreeViewColumn column)
{
return column.Title == title;
});
}
public object[] GetSelectedObjects(int column)
{
TreeIter[] selectedIters = GetSelectedIters();
object[] objects = new object[selectedIters.Length];
for (int i = 0; i < selectedIters.Length; i++)
{
objects[i] = Model.GetValue(selectedIters[i], column);
}
return objects;
}
public TreeIter[] GetSelectedIters()
{
TreePath[] paths = Selection.GetSelectedRows();
List<TreeIter> iters = new List<TreeIter>();
foreach (TreePath path in paths)
{
TreeIter iter;
if (Model.GetIter(out iter, path))
{
iters.Add(iter);
}
}
return iters.ToArray();
}
// By default, only one row is activated when pressing Enter. Overriding.
protected override bool OnKeyPressEvent(Gdk.EventKey evnt)
{
if (activateMultipleRows && evnt.Key == Gdk.Key.Return)
{
TreePath[] paths = Selection.GetSelectedRows();
foreach (TreePath path in paths)
{
ActivateRow(path, Columns[0]);
}
return true;
}
return base.OnKeyPressEvent(evnt);
}
#endregion
}
}
|