initial checkin
authorClaus Gittinger <cg@exept.de>
Fri, 01 Jul 2011 15:14:18 +0200
changeset 9968 07185068e8ec
parent 9967 88b490b5e9bd
child 9969 c02850f71ad2
initial checkin
BookmarkMenuBuilder.st
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BookmarkMenuBuilder.st	Fri Jul 01 15:14:18 2011 +0200
@@ -0,0 +1,168 @@
+"
+ COPYRIGHT (c) 2006 by eXept Software AG
+              All Rights Reserved
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice.   This software may not
+ be provided or otherwise made available to, or used by, any
+ other person.  No title to or ownership of the software is
+ hereby transferred.
+"
+"{ Package: 'stx:libtool' }"
+
+BookmarkVisitor subclass:#BookmarkMenuBuilder
+	instanceVariableNames:'menu stack toolbar'
+	classVariableNames:''
+	poolDictionaries:''
+	category:'Interface-Bookmarks'
+!
+
+!BookmarkMenuBuilder class methodsFor:'documentation'!
+
+copyright
+"
+ COPYRIGHT (c) 2006 by eXept Software AG
+              All Rights Reserved
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice.   This software may not
+ be provided or otherwise made available to, or used by, any
+ other person.  No title to or ownership of the software is
+ hereby transferred.
+"
+! !
+
+!BookmarkMenuBuilder class methodsFor:'instance creation'!
+
+buildMenuFor: anObject
+
+    ^self new
+        visit: anObject;
+        menu
+
+    "Created: / 02-06-2011 / 21:52:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+new
+    "return an initialized instance"
+
+    ^ self basicNew initialize.
+! !
+
+!BookmarkMenuBuilder methodsFor:'* uncategorized *'!
+
+menuItemFolder: folder
+
+    ^(MenuItem labeled:folder label)
+
+    "Created: / 21-06-2011 / 08:08:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!BookmarkMenuBuilder methodsFor:'accessing'!
+
+menu
+
+    ^ menu
+
+    "Created: / 23-05-2011 / 10:43:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!BookmarkMenuBuilder methodsFor:'initialization'!
+
+initialize
+
+    menu := Menu new.
+    stack := Stack with: menu
+
+    "/ super initialize.   -- commented since inherited method does nothing
+
+    "Modified: / 23-05-2011 / 10:34:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!BookmarkMenuBuilder methodsFor:'utilities'!
+
+menuItemAddBookmark:anObject 
+
+
+    ^self menuItemAddBookmark:anObject labeled:'Add Bookmark Here'.
+
+    "Modified: / 21-06-2011 / 08:00:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+menuItemAddBookmark:anObject labeled: label
+    |item|
+
+    item := MenuItem labeled: label.
+    item
+        value:#menuAddBookmarkTo:;
+        argument:anObject.
+    ^ item
+
+    "Created: / 21-06-2011 / 07:59:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+menuItemGotoBookmark:anObject 
+    |item icon label|
+
+    label := anObject label.
+    icon := anObject icon.
+    icon ifNotNil:[ label := LabelAndIcon label:label icon:icon ].
+    item := (MenuItem labeled:label)
+                value:#switchToBookmarkEntry:;
+                argument:anObject.
+    ^ item
+
+    "Created: / 21-06-2011 / 07:55:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!BookmarkMenuBuilder methodsFor:'visiting'!
+
+visitBookmark:anObject 
+    |item|
+
+    item := self menuItemGotoBookmark:anObject.
+    stack top addItem:item
+
+    "Created: / 23-05-2011 / 10:42:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 21-06-2011 / 07:55:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+visitFolder:anObject 
+    |item submenu|
+
+    anObject parent isNil 
+        ifTrue:[ anObject children ? #() do:[:child | self visit:child ] ]
+        ifFalse:
+            [ item := self menuItemFolder: anObject.
+            stack top addItem:item.
+            submenu := Menu new.
+            item submenu:submenu.
+            stack push:submenu.
+            anObject children ? #() do:[:child | self visit:child ].
+            stack top hasItems ifTrue:[ stack top addSeparator ].
+            item := self menuItemAddBookmark:anObject.
+            stack top addItem:item.
+            stack pop ].
+
+    "Created: / 23-05-2011 / 10:38:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 21-06-2011 / 08:08:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+visitSeparator:anObject
+
+    stack top addItem: MenuItem separator
+
+    "Created: / 03-06-2011 / 13:41:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!BookmarkMenuBuilder class methodsFor:'documentation'!
+
+version_CVS
+    ^ '$Header: /cvs/stx/stx/libtool/BookmarkMenuBuilder.st,v 1.1 2011-07-01 13:14:18 cg Exp $'
+!
+
+version_SVN
+    ^ '§Id§'
+! !