[Monodevelop-patches-list] r2702 - in trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets: . Commands Tree
Lluis Sanchez <lluis@ximian.com>
lluis at mono-cvs.ximian.com
Wed Aug 3 05:34:06 EDT 2005
Author: lluis
Date: 2005-08-03 05:34:06 -0400 (Wed, 03 Aug 2005)
New Revision: 2702
Added:
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/LocalCommandEntry.cs
Removed:
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Tree/TreeNode.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Tree/TreeNodeCollection.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Tree/TreeView.cs
Modified:
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/ChangeLog
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/ActionCommand.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandArrayInfo.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandInfo.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandManager.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandMenuItem.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Makefile.am
Log:
2005-08-03 Lluis Sanchez Gual <lluis at novell.com>
* Tree/TreeNodeCollection.cs:
* Tree/TreeNode.cs:
* Tree/TreeView.cs: Removed.
* Commands/ActionCommand.cs: Added constructor overload.
* Commands/CommandManager.cs: Added some overloads and helper methods.
* Commands/CommandArrayInfo.cs:
* Commands/CommandInfo.cs:
* Commands/CommandMenuItem.cs: Allow separators in command arrays.
* Commands/LocalCommandEntry.cs: New kind of command entry, which
automatically registers a command if not previously registered.
Modified: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/ChangeLog
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/ChangeLog 2005-08-02 20:35:00 UTC (rev 2701)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/ChangeLog 2005-08-03 09:34:06 UTC (rev 2702)
@@ -1,3 +1,18 @@
+2005-08-03 Lluis Sanchez Gual <lluis at novell.com>
+
+ * Tree/TreeNodeCollection.cs:
+ * Tree/TreeNode.cs:
+ * Tree/TreeView.cs: Removed.
+
+ * Commands/ActionCommand.cs: Added constructor overload.
+ * Commands/CommandManager.cs: Added some overloads and helper methods.
+
+ * Commands/CommandArrayInfo.cs:
+ * Commands/CommandInfo.cs:
+ * Commands/CommandMenuItem.cs: Allow separators in command arrays.
+ * Commands/LocalCommandEntry.cs: New kind of command entry, which
+ automatically registers a command if not previously registered.
+
2005-07-27 Lluis Sanchez Gual <lluis at novell.com>
* Commands/CommandManager.cs: Improve error message when an exception is
Modified: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/ActionCommand.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/ActionCommand.cs 2005-08-02 20:35:00 UTC (rev 2701)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/ActionCommand.cs 2005-08-03 09:34:06 UTC (rev 2702)
@@ -42,6 +42,11 @@
{
}
+ public ActionCommand (object id, string text, string icon): base (id, text)
+ {
+ Icon = icon;
+ }
+
public ActionCommand (object id, string text, string icon, string accelKey, ActionType type): base (id, text)
{
Icon = icon;
Modified: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandArrayInfo.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandArrayInfo.cs 2005-08-02 20:35:00 UTC (rev 2701)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandArrayInfo.cs 2005-08-03 09:34:06 UTC (rev 2702)
@@ -49,6 +49,19 @@
list.Add (info);
}
+ public void Add (string text, object dataItem)
+ {
+ CommandInfo info = new CommandInfo (text);
+ Add (info, dataItem);
+ }
+
+ public void AddSeparator ()
+ {
+ CommandInfo info = new CommandInfo ("-");
+ info.IsArraySeparator = true;
+ Add (info, null);
+ }
+
public CommandInfo DefaultCommandInfo {
get { return defaultInfo; }
}
Modified: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandInfo.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandInfo.cs 2005-08-02 20:35:00 UTC (rev 2701)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandInfo.cs 2005-08-03 09:34:06 UTC (rev 2702)
@@ -42,6 +42,7 @@
bool useMarkup;
internal object DataItem;
internal CommandArrayInfo ArrayInfo;
+ internal bool IsArraySeparator;
internal CommandInfo (Command cmd)
{
Modified: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandManager.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandManager.cs 2005-08-02 20:35:00 UTC (rev 2701)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandManager.cs 2005-08-03 09:34:06 UTC (rev 2702)
@@ -32,7 +32,7 @@
namespace MonoDevelop.Commands
{
- public class CommandManager
+ public class CommandManager: IDisposable
{
public static CommandManager Main = new CommandManager ();
Gtk.Window rootWidget;
@@ -43,15 +43,21 @@
ArrayList globalHandlers = new ArrayList ();
ArrayList commandUpdateErrors = new ArrayList ();
Stack delegatorStack = new Stack ();
+ bool disposed;
+ bool toolbarUpdaterRunning;
Gtk.AccelGroup accelGroup;
- public CommandManager ()
+ public CommandManager (): this (null)
{
+ }
+
+ public CommandManager (Gtk.Window root)
+ {
+ rootWidget = root;
ActionCommand c = new ActionCommand (CommandSystemCommands.ToolbarList, "Toolbar List", null, null, ActionType.Check);
c.CommandArray = true;
RegisterCommand (c, "");
- GLib.Timeout.Add (500, new GLib.TimeoutHandler (UpdateStatus));
}
public void SetRootWindow (Gtk.Window root)
@@ -63,6 +69,16 @@
rootWidget.Realized += new EventHandler (RootRealized);
}
+ public void Dispose ()
+ {
+ disposed = true;
+ }
+
+ public void RegisterCommand (Command cmd)
+ {
+ RegisterCommand (cmd, "");
+ }
+
public void RegisterCommand (Command cmd, string category)
{
cmds [cmd.Id] = cmd;
@@ -87,6 +103,11 @@
return cmd;
}
+ internal Command FindCommand (object cmdId)
+ {
+ return cmds [cmdId] as Command;
+ }
+
public ActionCommand GetActionCommand (object cmdId)
{
ActionCommand cmd = cmds [cmdId] as ActionCommand;
@@ -116,6 +137,16 @@
return menu;
}
+ public void ShowContextMenu (CommandEntrySet entrySet)
+ {
+ ShowContextMenu (CreateMenu (entrySet));
+ }
+
+ public void ShowContextMenu (Gtk.Menu menu)
+ {
+ menu.Popup (null, null, null, IntPtr.Zero, 0, Gtk.Global.CurrentEventTime);
+ }
+
public Gtk.Toolbar CreateToolbar (string id, CommandEntrySet entrySet)
{
CommandToolbar toolbar = new CommandToolbar (this, id, entrySet.Name);
@@ -360,13 +391,22 @@
bool UpdateStatus ()
{
- UpdateToolbars ();
- return true;
+ if (!disposed) {
+ UpdateToolbars ();
+ return true;
+ } else {
+ toolbarUpdaterRunning = false;
+ return false;
+ }
}
internal void RegisterToolbar (CommandToolbar toolbar)
{
toolbars.Add (toolbar);
+ if (!toolbarUpdaterRunning) {
+ GLib.Timeout.Add (500, new GLib.TimeoutHandler (UpdateStatus));
+ toolbarUpdaterRunning = true;
+ }
}
void UpdateToolbars ()
Modified: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandMenuItem.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandMenuItem.cs 2005-08-02 20:35:00 UTC (rev 2701)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/CommandMenuItem.cs 2005-08-03 09:34:06 UTC (rev 2702)
@@ -105,9 +105,15 @@
if (cmdInfo.ArrayInfo != null) {
foreach (CommandInfo info in cmdInfo.ArrayInfo) {
- Gtk.MenuItem item = CommandEntry.CreateMenuItem (commandManager, commandId, false);
- ICommandMenuItem mi = (ICommandMenuItem) item;
- mi.SetUpdateInfo (info);
+ Gtk.MenuItem item;
+ if (info.IsArraySeparator) {
+ item = new Gtk.SeparatorMenuItem ();
+ item.Show ();
+ } else {
+ item = CommandEntry.CreateMenuItem (commandManager, commandId, false);
+ ICommandMenuItem mi = (ICommandMenuItem) item;
+ mi.SetUpdateInfo (info);
+ }
menu.Insert (item, ++i);
itemArray.Add (item);
}
Added: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/LocalCommandEntry.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/LocalCommandEntry.cs 2005-08-02 20:35:00 UTC (rev 2701)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Commands/LocalCommandEntry.cs 2005-08-03 09:34:06 UTC (rev 2702)
@@ -0,0 +1,66 @@
+//
+// LocalCommandEntry.cs
+//
+// Author:
+// Lluis Sanchez Gual
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+namespace MonoDevelop.Commands
+{
+ public class LocalCommandEntry: CommandEntry
+ {
+ Command cmd;
+
+ public LocalCommandEntry (Command cmd): base (cmd.Id)
+ {
+ this.cmd = cmd;
+ }
+
+ public LocalCommandEntry (object id, string text): base (id)
+ {
+ cmd = new ActionCommand ();
+ cmd.Id = id;
+ cmd.Text = text;
+ }
+
+ internal protected override Gtk.MenuItem CreateMenuItem (CommandManager manager)
+ {
+ if (manager.FindCommand (CommandId) == null)
+ manager.RegisterCommand (cmd, "");
+
+ return base.CreateMenuItem (manager);
+ }
+
+ internal protected override Gtk.ToolItem CreateToolItem (CommandManager manager)
+ {
+ if (manager.FindCommand (CommandId) == null)
+ manager.RegisterCommand (cmd, "");
+
+ return base.CreateToolItem (manager);
+ }
+ }
+}
+
Modified: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Makefile.am
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Makefile.am 2005-08-02 20:35:00 UTC (rev 2701)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Makefile.am 2005-08-03 09:34:06 UTC (rev 2702)
@@ -9,9 +9,6 @@
$(GNOME_SHARP_LIBS)
FILES = \
-Tree/TreeView.cs \
-Tree/TreeNodeCollection.cs \
-Tree/TreeNode.cs \
IconView/IconView.cs \
FileBrowser/FileBrowser.cs \
FileSelector/FileSelector.cs \
@@ -61,6 +58,7 @@
Commands/ICommandRouter.cs \
Commands/ICommandUserItem.cs \
Commands/LinkCommandEntry.cs \
+Commands/LocalCommandEntry.cs \
Commands/MenuToolButton.cs \
DockToolbars/ArrowWindow.cs \
DockToolbars/DockGrip.cs \
Deleted: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Tree/TreeNode.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Tree/TreeNode.cs 2005-08-02 20:35:00 UTC (rev 2701)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Tree/TreeNode.cs 2005-08-03 09:34:06 UTC (rev 2702)
@@ -1,215 +0,0 @@
-using System;
-using System.Collections;
-
-namespace MonoDevelop.Gui.Widgets {
- public class TreeNode {
- internal TreeView treeView = null;
- internal TreeNode parent = null;
- private TreeNodeCollection nodes;
- private string text;
- private string image, opened_image, closed_image;
- private object tag;
-
- internal Gtk.TreeRowReference row;
-
- public TreeNode ()
- {
- nodes = new TreeNodeCollection();
- nodes.TreeNodeCollectionChanged += new TreeNodeCollectionChangedHandler(OnNodesChanged);
- nodes.NodeInserted += new NodeInsertedHandler(OnNodeInserted);
- nodes.NodeRemoved += new NodeRemovedHandler(OnNodeRemoved);
- }
-
- public TreeNode(string text, string image) : this()
- {
- this.text = text;
- this.image = image;
- }
-
- public TreeNode (string text): this (text, null) {}
-
- public string Text {
- get {
- return text;
- }
- set {
- text = value;
- UpdateBacking ();
- }
- }
-
- public string Image {
- get {
- if (image == null)
- return closed_image;
- return image;
- }
- set {
- image = value;
- UpdateBacking ();
- }
- }
-
- public string OpenedImage {
- get {
- return opened_image;
- }
- set {
- opened_image = value;
- UpdateBacking ();
- }
- }
-
- public string ClosedImage {
- get {
- return closed_image;
- }
- set {
- closed_image = value;
- UpdateBacking ();
- }
- }
-
- public object Tag {
- get {
- return tag;
- }
- set {
- tag = value;
- }
- }
-
- public bool IsExpanded {
- get {
- return TreeView != null && TreeView.GetRowExpanded (TreePath);
- }
- set {
- if (TreeView != null)
- TreeView.ExpandRow (TreePath, value);
- }
- }
-
- public void UpdateBacking ()
- {
- if (TreeView == null)
- return;
-
- TreeView.Model.SetValue (TreeIter, 0, text);
- if (image != null) TreeView.Model.SetValue (TreeIter, 1, TreeView.RenderIcon (image));
- if (opened_image != null) TreeView.Model.SetValue (TreeIter, 3, TreeView.RenderIcon (opened_image));
- if (closed_image != null) TreeView.Model.SetValue (TreeIter, 4, TreeView.RenderIcon (closed_image));
- }
-
- public TreeNodeCollection Nodes {
- get {
- return nodes;
- }
- }
-
- public TreeNode Parent {
- get {
- return parent;
- }
- }
-
- public TreeView TreeView {
- get {
- if (treeView != null)
- return treeView;
-
- if (parent == null)
- return null;
-
- return parent.TreeView;
- }
- }
-
- public bool IsEditing {
- get {
- return false; // FIXME
- }
- }
-
- public void Expand ()
- {
- if (TreeView != null)
- TreeView.ExpandToPath (TreePath);
- }
-
- public void EnsureVisible ()
- {
- Expand (); // TODO
- }
-
- public void Remove ()
- {
- if (parent != null)
- parent.Nodes.Remove(this);
- }
-
- internal void SetTreeView (TreeView t)
- {
- this.treeView = t;
- }
-
- private void OnNodeInserted (TreeNode node)
- {
- node.parent = this;
- if (TreeView != null)
- TreeView.AddNode (this, node);
- }
-
- private void OnNodeRemoved(TreeNode node)
- {
- if (TreeView != null) {
- TreeView.RemoveNode(node);
- }
-
- node.parent = null;
- }
-
- private void OnNodesChanged ()
- {
- if (TreeView != null)
- TreeView.OnTreeChanged();
- }
-
- internal Gtk.TreeIter TreeIter {
- get {
- Gtk.TreeIter iter;
- if (! TreeView.Model.GetIter (out iter, TreePath))
- throw new Exception("Error calculating iter for " + this.Text);
-
- return iter;
- }
- }
-
- internal Gtk.TreePath TreePath {
- get {
- if (TreeView == null)
- return null;
-
- if (row == null || ! row.Valid ())
- throw new Exception ("RowReference not valid " + this.Text);
-
- return row.Path;
- }
- }
-
- public virtual void BeginEdit ()
- {
- TreeView.text_render.Editable = TreeView.canEdit;
- TreeView.SetCursor (TreePath, TreeView.complete_column, true);
- }
-
- public void Sort ()
- {
- Nodes.Sort ();
- }
-
- public void Sort (IComparer c)
- {
- Nodes.Sort (c);
- }
- }
-}
Deleted: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Tree/TreeNodeCollection.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Tree/TreeNodeCollection.cs 2005-08-02 20:35:00 UTC (rev 2701)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Tree/TreeNodeCollection.cs 2005-08-03 09:34:06 UTC (rev 2702)
@@ -1,229 +0,0 @@
-using System;
-using System.Collections;
-
-using MonoDevelop.Services;
-
-namespace MonoDevelop.Gui.Widgets {
- public class TreeNodeCollection: IList {
- private ArrayList list;
-
- public int Count {
- get { return list != null ? list.Count : 0; }
- }
-
- public bool IsReadOnly {
- get { return false; }
- }
-
- public virtual TreeNode this[int index] {
- get {
- if (list == null) throw new ArgumentOutOfRangeException( "index" );
- return (TreeNode) list[index];
- }
- set {
- if (list == null) list = new ArrayList ();
- list[index] = value; //TODO
- Changed();
- }
- }
-
- public void Sort ()
- {
- if (list == null) return;
- list.Sort ();
- Changed ();
- }
-
- public void Sort (IComparer c)
- {
- if (list == null) return;
- list.Sort (c);
- Changed ();
- }
-
- public virtual TreeNode Add(string text)
- {
- TreeNode node = new TreeNode (text, null);
- Add (node);
- return node;
- }
-
- public virtual int Add(TreeNode node)
- {
- if (node == null)
- throw new ArgumentNullException("value");
-
- if (list == null) list = new ArrayList ();
- Inserted(node);
- int index = list.Add(node);
- return index;
- }
-
- public virtual void AddRange(TreeNode[] nodes)
- {
- if (nodes == null)
- throw new ArgumentNullException("nodes");
-
- foreach (TreeNode node in nodes) {
- Add (node);
- }
- }
-
- public virtual void Clear()
- {
- if (list == null) return;
- ArrayList tmp = (ArrayList)list.Clone();
- foreach (TreeNode node in tmp) {
- Remove(node);
- }
- }
-
- public bool Contains(TreeNode node)
- {
- if (list == null) return false;
- return list.Contains(node);
- }
-
- public void CopyTo(Array dest, int index)
- {
- throw new NotImplementedException();
- }
-
- public IEnumerator GetEnumerator()
- {
- if (list == null) return Type.EmptyTypes.GetEnumerator ();
- return list.GetEnumerator();
- }
-
- public int IndexOf(TreeNode node)
- {
- if (list == null) return -1;
- return list.IndexOf(node);
- }
-
- public virtual void Insert(int index, TreeNode node)
- {
- if (list == null) list = new ArrayList ();
-
- if ( node == null )
- throw new ArgumentNullException ( "node" );
-
- if (index < 0 || index > Count )
- throw new ArgumentOutOfRangeException( "index" );
-
- list.Insert(index, node);
- Inserted(node);
- }
-
- public void Remove(TreeNode node)
- {
- if ( node == null )
- throw new ArgumentNullException( "node" );
- if (list == null) return;
- Removed(node);
- list.Remove(node);
- }
-
- public virtual void RemoveAt(int index)
- {
- if (list == null || index < 0 || index > Count )
- throw new ArgumentOutOfRangeException( "index" );
-
- TreeNode node = (TreeNode) list[ index ];
- Removed(node);
- list.RemoveAt(index);
- }
-
- bool IList.IsReadOnly{
- get{
- return false;
- }
- }
- bool IList.IsFixedSize{
- get{
- return false;
- }
- }
-
- object IList.this[int index]{
- get{
- if (list == null) throw new ArgumentOutOfRangeException( "index" );
- return list[index];
- }
- set{
- throw new NotImplementedException();
- }
- }
-
- void IList.Clear(){
- Clear();
- }
-
- int IList.Add(object value){
- return Add((TreeNode) value);
- }
-
- bool IList.Contains(object value){
- if (list == null) return false;
- return list.Contains(value);
- }
-
- int IList.IndexOf(object value){
- if (list == null) return -1;
- return list.IndexOf(value);
- }
-
- void IList.Insert(int index, object value){
- Insert(index, (TreeNode) value);
- }
-
- void IList.Remove(object value){
- if (value is TreeNode == false) {
- throw new Exception (GettextCatalog.GetString ("Attempt to remove a non node from the tree"));
- }
- Remove((TreeNode)value);
- }
-
- void IList.RemoveAt(int index){
- RemoveAt(index);
- }
-
- object ICollection.SyncRoot{
- get{
- throw new NotImplementedException ();
- }
- }
-
- bool ICollection.IsSynchronized{
- get {
- throw new NotImplementedException();
- }
- }
-
- private void Inserted(TreeNode node) {
- if (NodeInserted != null) {
- NodeInserted(node);
- }
- }
-
- private void Removed(TreeNode node) {
- if (NodeRemoved != null) {
- NodeRemoved(node);
- }
- }
-
- private void Changed() {
- if (TreeNodeCollectionChanged != null) {
- TreeNodeCollectionChanged();
- }
- }
-
- internal event TreeNodeCollectionChangedHandler TreeNodeCollectionChanged;
- internal event NodeInsertedHandler NodeInserted;
- internal event NodeRemovedHandler NodeRemoved;
- }
-
- internal delegate void TreeNodeCollectionChangedHandler();
- internal delegate void NodeInsertedHandler(TreeNode node);
- internal delegate void NodeRemovedHandler(TreeNode node);
-}
Deleted: trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Tree/TreeView.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Tree/TreeView.cs 2005-08-02 20:35:00 UTC (rev 2701)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Gui.Widgets/Tree/TreeView.cs 2005-08-03 09:34:06 UTC (rev 2702)
@@ -1,305 +0,0 @@
-using System;
-using System.Collections;
-
-namespace MonoDevelop.Gui.Widgets {
- public class TreeView: Gtk.TreeView {
- Gtk.TreeStore store;
- TreeNodeCollection nodes;
- bool updating = false;
-
- internal bool canEdit = false;
- internal Gtk.TreeViewColumn complete_column;
- internal Gtk.CellRendererText text_render;
-
- public TreeView () : this (false)
- {
- }
-
- public TreeView (bool canEdit)
- {
- /*
- 0 -- Text
- 1 -- Icon
- 2 -- Node
- 3 -- Expanded Icon
- 4 -- Unexpanded Icon
- */
- store = new Gtk.TreeStore (typeof (string), typeof (Gdk.Pixbuf), typeof (TreeNode), typeof (Gdk.Pixbuf), typeof (Gdk.Pixbuf));
- this.Model = store;
- this.canEdit = canEdit;
-
- HeadersVisible = false;
- SearchColumn = 0;
- EnableSearch = true;
- complete_column = new Gtk.TreeViewColumn ();
- complete_column.Title = "column";
-
- Gtk.CellRendererPixbuf pix_render = new Gtk.CellRendererPixbuf ();
- complete_column.PackStart (pix_render, false);
- complete_column.AddAttribute (pix_render, "pixbuf", 1);
- // Sadly, gtk+ does not have support for stock being here :-(
- complete_column.AddAttribute (pix_render, "pixbuf-expander-open", 3);
- complete_column.AddAttribute (pix_render, "pixbuf-expander-closed", 4);
-
- text_render = new Gtk.CellRendererText ();
- if (canEdit)
- text_render.Edited += new Gtk.EditedHandler (HandleOnEdit);
-
- complete_column.PackStart (text_render, true);
- complete_column.AddAttribute (text_render, "text", 0);
-
- AppendColumn (complete_column);
-
- nodes = new TreeNodeCollection ();
- nodes.TreeNodeCollectionChanged += new TreeNodeCollectionChangedHandler (OnTreeChanged);
- nodes.NodeInserted += new NodeInsertedHandler (OnNodeInserted);
- nodes.NodeRemoved += new NodeRemovedHandler (OnNodeRemoved);
-
- TestExpandRow += new Gtk.TestExpandRowHandler (OnTestExpandRow);
- RowActivated += new Gtk.RowActivatedHandler (OnRowClicked);
- }
-
- public TreeView (bool edit, Gtk.TreeIterCompareFunc cb_compare) : this (edit)
- {
- store.DefaultSortFunc = cb_compare;
- store.SetSortColumnId (/* GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID */ -1, Gtk.SortType.Ascending);
- }
-
- void HandleOnEdit (object o, Gtk.EditedArgs e)
- {
- text_render.Editable = false;
- Gtk.TreeIter iter;
- if (! Model.GetIterFromString (out iter, e.Path))
- throw new Exception("Error calculating iter for path " + e.Path);
-
- OnEdit ((TreeNode) store.GetValue (iter, 2), e.NewText);
- }
-
- protected virtual void OnEdit (TreeNode node, string new_text)
- {
- }
-
-
- public TreeNodeCollection Nodes {
- get {
- return nodes;
- }
- }
-
- public Gtk.TreeView View {
- get {
- return this;
- }
- }
-
- public TreeNode SelectedNode {
- get {
- Gtk.TreeModel foo;
- Gtk.TreeIter iter;
- if (! Selection.GetSelected (out foo, out iter))
- return null;
-
- return (TreeNode) store.GetValue (iter, 2);
- }
- set {
- Selection.SelectIter (value.TreeIter);
- this.ScrollToCell (store.GetPath (value.TreeIter), null, false, 0, 0);
- }
- }
-
- public bool LabelEdit {
- get {
- return canEdit;
- }
- set {
- canEdit = value;
- }
- }
-
- public void BeginUpdate()
- {
- //updating = true;
- }
-
- public void EndUpdate ()
- {
- //if (updating == true) {
- // UpdateStore(store);
- //}
- //updating = false;
-
- }
-
- internal void OnTreeChanged ()
- {
- if (updating == false)
- UpdateStore (store);
- }
-
- internal void UpdateStore (Gtk.TreeStore store)
- {
- store.Clear ();
- foreach (TreeNode node in nodes) {
- Gtk.TreeIter i = Append (node);
- AddNodesRecursively (store, i, node);
- }
- }
-
- Gtk.TreeIter Append (Gtk.TreeIter parent, TreeNode new_child)
- {
- if (new_child.row != null) {
- new_child.row.Free ();
- new_child.row = null;
- }
-
- Gtk.TreeIter it = store.AppendNode (parent);
-
- // It is *critical* that we set this first. We will
- // sort after this call, so we must give as much info
- // to the sort function as possible.
- store.SetValue (it, 2, new_child);
-
- if (new_child.Text != null) store.SetValue (it, 0, new_child.Text);
- if (new_child.Image != null) store.SetValue (it, 1, RenderIcon (new_child.Image));
- if (new_child.OpenedImage != null) store.SetValue (it, 3, RenderIcon (new_child.OpenedImage));
- if (new_child.ClosedImage != null) store.SetValue (it, 4, RenderIcon (new_child.ClosedImage));
-
- new_child.row = new Gtk.TreeRowReference (store, store.GetPath (it));
-
- return it;
- }
-
- Gtk.TreeIter Append (TreeNode new_child)
- {
- if (new_child.row != null) {
- new_child.row.Free ();
- new_child.row = null;
- }
-
- Gtk.TreeIter it = store.AppendNode ();
-
- // It is *critical* that we set this first. We will
- // sort after this call, so we must give as much info
- // to the sort function as possible.
- store.SetValue (it, 2, new_child);
-
- if (new_child.Text != null) store.SetValue (it, 0, new_child.Text);
- if (new_child.Image != null) store.SetValue (it, 1, RenderIcon (new_child.Image));
- if (new_child.OpenedImage != null) store.SetValue (it, 3, RenderIcon (new_child.OpenedImage));
- if (new_child.ClosedImage != null) store.SetValue (it, 4, RenderIcon (new_child.ClosedImage));
-
- new_child.row = new Gtk.TreeRowReference (store, store.GetPath (it));
-
- return it;
- }
-
- private void AddNodesRecursively (Gtk.TreeStore store, Gtk.TreeIter it, TreeNode node)
- {
- foreach (TreeNode nod in node.Nodes) {
- Gtk.TreeIter i = Append (it, nod);
- AddNodesRecursively (store, i, nod);
- }
- }
-
- internal void AddNode (TreeNode parent, TreeNode child)
- {
- if (parent.TreeView != this)
- throw new Exception ("Wrong tree");
-
- Gtk.TreeIter i = Append (parent.TreeIter, child);
-
- AddNodesRecursively (store, i, child);
- }
-
- internal void RemoveNode (TreeNode node)
- {
- if (node.TreeView != this)
- throw new Exception ("Wrong tree");
-
- Gtk.TreeIter iter = node.TreeIter;
- store.Remove (ref iter);
- }
-
- private void OnNodeInserted (TreeNode node)
- {
- node.treeView = this;
- node.parent = null;
-
-
- Gtk.TreeIter i = Append (node);
- AddNodesRecursively (store, i, node);
- }
-
- private void OnNodeRemoved (TreeNode node)
- {
- RemoveNode (node);
- node.parent = null;
- node.treeView = null;
- if (node.row != null) {
- node.row.Free ();
- node.row = null;
- }
- }
-
- private TreeNode GetNodeByIter (Gtk.TreeIter iter)
- {
- TreeNode ret = (TreeNode) store.GetValue(iter, 2);
- return ret;
- }
-
- private void OnTestExpandRow (object sender, Gtk.TestExpandRowArgs args)
- {
- TreeNode node = GetNodeByIter (args.Iter);
- TreeViewCancelEventArgs e = new TreeViewCancelEventArgs (node);
- OnBeforeExpand (e);
-
- args.RetVal = (e.Cancel == true || node.Nodes.Count == 0);
- }
-
- private void OnRowClicked (object sender, Gtk.RowActivatedArgs args)
- {
- Gtk.TreePath path = args.Path;
-
- if (!this.GetRowExpanded (path)) {
- this.ExpandRow (path, false);
- } else {
- this.CollapseRow (path);
- }
- }
-
- protected virtual void OnBeforeExpand (TreeViewCancelEventArgs e)
- {
- // Nothing
- }
-
- internal Gdk.Pixbuf RenderIcon (string stock_id)
- {
- return RenderIcon (stock_id, Gtk.IconSize.Menu, "");
- }
- }
-
- public class TreeViewCancelEventArgs {
- private TreeNode node;
- private bool cancel = false;
-
- public TreeViewCancelEventArgs (TreeNode node)
- {
- this.node = node;
- }
-
- public TreeNode Node {
- get {
- return node;
- }
- }
-
- public bool Cancel {
- get {
- return cancel;
- }
- set {
- cancel = value;
- }
- }
- }
-}
More information about the Monodevelop-patches-list
mailing list