1 /* -*- Mode: C#; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is Manticore.
18 * The Initial Developer of the Original Code is
19 * Silverstone Interactive.
20 * Portions created by the Initial Developer are Copyright (C) 2001
21 * the Initial Developer. All Rights Reserved.
24 * Ben Goodger <ben@netscape.com> (Original Author)
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 namespace Silverstone
.Manticore
.Bookmarks
44 using System
.Windows
.Forms
;
45 using System
.Collections
;
47 using Silverstone
.Manticore
.Core
;
48 using Silverstone
.Manticore
.Toolkit
;
51 /// A Bookmarks Tree widget
53 public class BookmarksTreeView
: ManticoreTreeView
55 protected BaseTreeBuilder mBuilder
;
56 protected Queue mFilterAttributes
;
58 public BookmarksTreeView(String aRoot
)
60 mBuilder
= new BaseTreeBuilder(this, null);
61 mBuilder
.Root
= aRoot
;
62 mBuilder
.DataStore
= DataStoreRegistry
.GetDataStore("Bookmarks");
63 mBuilder
.DataStore
.AddObserver(mBuilder
);
65 // Use bright green as transparent colour
66 mIconTransparentColor
= ColorTranslator
.FromOle(0x00FF00);
68 ImageList
= new ImageList();
69 // Built in Bookmark icons
70 ImageList
.Images
.Add(Image
.FromFile(@"resources\bookmark-folder-closed.png"), mIconTransparentColor
);
71 ImageList
.Images
.Add(Image
.FromFile(@"resources\bookmark-folder-open.png"), mIconTransparentColor
);
72 ImageList
.Images
.Add(Image
.FromFile(@"resources\bookmark.png"), mIconTransparentColor
);
74 // Don't draw lines to root
75 ShowRootLines
= false;
78 AfterLabelEdit
+= new NodeLabelEditEventHandler(OnAfterLabelEdit
);
79 AfterExpand
+= new TreeViewEventHandler(OnAfterExpand
);
80 AfterCollapse
+= new TreeViewEventHandler(OnAfterCollapse
);
96 if (mBuilder
.Root
!= value)
97 mBuilder
.Root
= value;
101 public void AddCriteria(String
[] aAttrValuePair
)
103 if (mFilterAttributes
== null)
104 mFilterAttributes
= new Queue();
105 mFilterAttributes
.Enqueue(aAttrValuePair
);
108 public override bool ShouldBuild(CommandTarget aTarget
)
110 Bookmarks bmks
= ServiceManager
.Bookmarks
;
112 if (mFilterAttributes
!= null)
114 IEnumerator criteria
= mFilterAttributes
.GetEnumerator();
115 while (criteria
.MoveNext())
117 String
[] singleCriteria
= criteria
.Current
as String
[];
118 if (bmks
.GetBookmarkAttribute(aTarget
.Data
as String
, singleCriteria
[0]) != singleCriteria
[1])
125 public override int GetIconIndex(CommandTarget aTarget
)
128 if (aTarget
.IsContainer
)
135 int fileIndex
= GetIconIndex(aTarget
.IconURL
);
142 /// Retrieves the single root |ManticoreTreeNode| in the TreeView.
144 /// <returns></returns>
145 protected ManticoreTreeNode
GetRootItem()
147 if (Nodes
.Count
== 0)
149 return Nodes
[0] as ManticoreTreeNode
;
152 public void NewFolder()
154 ManticoreTreeNode root
= GetRootItem();
157 ManticoreTreeNode temp
= new ManticoreTreeNode("New Folder", null);
158 root
.Nodes
.Add(temp
);
164 protected void OnAfterLabelEdit(Object sender
, NodeLabelEditEventArgs e
)
166 ManticoreTreeNode root
= GetRootItem();
167 if (root
!= null && e
.Label
!= "")
169 ManticoreTreeNode temp
= e
.Node
as ManticoreTreeNode
;
170 String parentID
= root
.Data
as String
;
171 Bookmarks bmks
= ServiceManager
.Bookmarks
;
172 String bookmarkID
= bmks
.CreateBookmark(e
.Label
, parentID
, -1);
173 bmks
.SetBookmarkAttribute(bookmarkID
, "container", "true");
174 bmks
.SetBookmarkAttribute(bookmarkID
, "open", "true");
175 e
.Node
.Text
= "FruitLoop";
176 e
.Node
.EndEdit(false);
177 root
.Nodes
.Remove(temp
);
181 e
.Node
.EndEdit(true);
184 protected void OnAfterExpand(Object sender
, TreeViewEventArgs e
)
186 ManticoreTreeNode node
= e
.Node
as ManticoreTreeNode
;
187 String nodeID
= node
.Data
as String
;
188 Bookmarks bmks
= ServiceManager
.Bookmarks
;
189 bmks
.SetBookmarkAttribute(nodeID
, "open", "true");
193 protected void OnAfterCollapse(Object sender
, TreeViewEventArgs e
)
195 ManticoreTreeNode node
= e
.Node
as ManticoreTreeNode
;
196 String nodeID
= node
.Data
as String
;
197 Bookmarks bmks
= ServiceManager
.Bookmarks
;
198 bmks
.SetBookmarkAttribute(nodeID
, "open", "false");