/*
* Copyright (C) 2006 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 Gtk;
using Glade;
using Mono.Unix;
namespace DCSharp.GUI{
public class VisibleColumnsWindow : GladeWindow
{
private TreeViewColumn[] inactiveColumns;
private ListStore store;
[Widget]
private TreeView treeView;
[Widget]
private Button closeButton;
#region Constructors
public VisibleColumnsWindow(TreeViewColumn[] columns, Window parent,
params TreeViewColumn[] inactiveColumns) : base("VisibleColumnsWindow.glade", parent)
{
this.inactiveColumns = inactiveColumns;
closeButton.Clicked += OnCloseButtonClicked;
// Columns
TreeViewColumn column;
CellRendererToggle toggleRenderer = new CellRendererToggle();
toggleRenderer.Toggled += OnColumnToggled;
column = treeView.AppendColumn(null, toggleRenderer);
column.SetCellDataFunc(toggleRenderer, SetToggleColumn);
CellRendererText textRenderer = new CellRendererText();
column = treeView.AppendColumn(Catalog.GetString("Name"),
textRenderer);
column.SetCellDataFunc(textRenderer, SetNameColumn);
// Model
store = new ListStore(typeof(TreeViewColumn));
treeView.Model = store;
foreach (TreeViewColumn c in columns)
{
store.AppendValues(c);
}
}
#endregion
#region Methods
private void SetToggleColumn(TreeViewColumn column,
CellRenderer renderer, TreeModel model, TreeIter iter)
{
TreeViewColumn c = (TreeViewColumn)model.GetValue(iter, 0);
CellRendererToggle toggleRenderer = (CellRendererToggle)renderer;
toggleRenderer.Active = c.Visible;
toggleRenderer.Activatable = Array.IndexOf(inactiveColumns, c) == -1;
}
private void SetNameColumn(TreeViewColumn column,
CellRenderer renderer, TreeModel model, TreeIter iter)
{
TreeViewColumn c = (TreeViewColumn)model.GetValue(iter, 0);
CellRendererText textRenderer = (CellRendererText)renderer;
textRenderer.Text = c.Title;
}
private void OnCloseButtonClicked(object obj, EventArgs args)
{
Destroy();
}
private void OnColumnToggled(object obj, ToggledArgs args)
{
TreeIter iter;
if (store.GetIterFromString(out iter, args.Path))
{
TreeViewColumn c = (TreeViewColumn)store.GetValue(iter, 0);
c.Visible = !c.Visible;
}
}
#endregion
}
}
|