BookmarkBar.st
author Claus Gittinger <cg@exept.de>
Fri, 01 Jul 2011 15:30:32 +0200
changeset 9998 dc88261b0fc2
parent 9974 fb1249834463
child 10080 4aeae0bc937d
permissions -rw-r--r--
initial checkin

"
 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' }"

ApplicationModel subclass:#BookmarkBar
	instanceVariableNames:'bookmarkHolder bookmarksHolder menuHolder
		bookmarkButtonIconHolder hasBookmarkHolder'
	classVariableNames:''
	poolDictionaries:''
	category:'Interface-Bookmarks'
!

!BookmarkBar 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.
"
! !

!BookmarkBar class methodsFor:'interface specs'!

windowSpec
    "This resource specification was automatically generated
     by the UIPainter of ST/X."

    "Do not manually edit this!! If it is corrupted,
     the UIPainter may not be able to read the specification."

    "
     UIPainter new openOnClass:BookmarkBar andSelector:#windowSpec
     BookmarkBar new openInterface:#windowSpec
     BookmarkBar open
    "

    <resource: #canvas>

    ^ 
     #(FullSpec
        name: windowSpec
        window: 
       (WindowSpec
          label: 'Bookmark bar'
          name: 'Bookmark bar'
          min: (Point 10 10)
          bounds: (Rectangle 0 0 600 25)
        )
        component: 
       (SpecCollection
          collection: (
           (MenuPanelSpec
              name: 'Bookmarks'
              layout: (LayoutFrame 0 0 0 0 -40 1 0 1)
              level: 0
              menu: menuHolder
              textDefault: true
            )
           (ActionButtonSpec
              name: 'BookmarkButton'
              layout: (LayoutFrame -25 1 0 0 0 1 25 0)
              level: 0
              hasCharacterOrientedLabel: false
              labelChannel: bookmarkButtonIconHolder
              model: bookmarkMenu
            )
           (ActionButtonSpec
              label: 'OK'
              name: 'menu'
              layout: (LayoutFrame -13 1 0 0 -3 1 0 1)
              initiallyInvisible: true
              hasCharacterOrientedLabel: false
              translateLabel: true
              labelChannel: menuButtonIcon
              model: bookmarkMenu
            )
           )
         
        )
      )
! !

!BookmarkBar class methodsFor:'menu specs'!

bookmarkMenu
    "This resource specification was automatically generated
     by the MenuEditor of ST/X."

    "Do not manually edit this!! If it is corrupted,
     the MenuEditor may not be able to read the specification."

    "
     MenuEditor new openOnClass:BookmarkBar andSelector:#bookmarkMenu
     (Menu new fromLiteralArrayEncoding:(BookmarkBar bookmarkMenu)) startUp
    "

    <resource: #menu>

    ^ 
     #(Menu
        (
         (MenuItem
            label: 'Add'
            translateLabel: true
            submenuChannel: bookmarkMenuAddSlice
            isMenuSlice: true
          )
         (MenuItem
            label: '-'
          )
         (MenuItem
            label: 'Bookmark Editor'
            itemValue: menuOpenBookmarkEditor
            translateLabel: true
          )
         )
        nil
        nil
      )
! !

!BookmarkBar class methodsFor:'plugIn spec'!

aspectSelectors
    "This resource specification was automatically generated
     by the UIPainter of ST/X."

    "Do not manually edit this. If it is corrupted,
     the UIPainter may not be able to read the specification."

    "Return a description of exported aspects;
     these can be connected to aspects of an embedding application
     (if this app is embedded in a subCanvas)."

    ^ #(
        #bookmarksHolder
        #bookmarkHolder
      ).

    "Modified: / 02-06-2011 / 22:46:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!BookmarkBar methodsFor:'actions'!

bookmark
    <resource: #uiCallback>

    self menuAddBookmark

    "Modified: / 02-06-2011 / 21:39:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

bookmarkMenu
    <resource: #uiCallback>
    |menu|

    menu := self class bookmarkMenu decodeAsLiteralArray.
    menu findGuiResourcesIn:self.
    menu startUp

    "Modified: / 02-06-2011 / 20:05:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!BookmarkBar methodsFor:'aspects'!

bookmarkButtonIconHolder
    <resource: #uiAspect>

    "automatically generated by UIPainter ..."

    "*** the code below creates a default model when invoked."
    "*** (which may not be the one you wanted)"
    "*** Please change as required and accept it in the browser."
    "*** (and replace this comment by something more useful ;-)"

    bookmarkButtonIconHolder isNil ifTrue:[
        bookmarkButtonIconHolder := ToolbarIconLibrary bookmarks22x22 asValue.
"/ if your app needs to be notified of changes, uncomment one of the lines below:
"/       bookmarkButtonIconHolder addDependent:self.
"/       bookmarkButtonIconHolder onChangeSend:#bookmarkButtonIconHolderChanged to:self.
    ].
    ^ bookmarkButtonIconHolder.

    "Modified: / 18-05-2011 / 18:22:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

bookmarkHolder
    "return/create the 'bookmarkHolder' value holder (automatically generated)"

    bookmarkHolder isNil ifTrue:[
        bookmarkHolder := ValueHolder new.
        bookmarkHolder addDependent:self.
    ].
    ^ bookmarkHolder
!

bookmarkHolder:something
    "set the 'bookmarkHolder' value holder (automatically generated)"

    |oldValue newValue|

    bookmarkHolder notNil ifTrue:[
        oldValue := bookmarkHolder value.
        bookmarkHolder removeDependent:self.
    ].
    bookmarkHolder := something.
    bookmarkHolder notNil ifTrue:[
        bookmarkHolder addDependent:self.
    ].
    newValue := bookmarkHolder value.
    oldValue ~~ newValue ifTrue:[
        self update:#value with:newValue from:bookmarkHolder.
    ].
!

bookmarksHolder
    "return/create the 'bookmarksHolder' value holder (automatically generated)"

    bookmarksHolder isNil ifTrue:[
        bookmarksHolder := ValueHolder new.
        bookmarksHolder addDependent:self.
    ].
    ^ bookmarksHolder
!

bookmarksHolder:something
    "set the 'bookmarksHolder' value holder (automatically generated)"

    |oldValue newValue|

    bookmarksHolder notNil ifTrue:[
        oldValue := bookmarksHolder value.
        bookmarksHolder removeDependent:self.
    ].
    bookmarksHolder := something.
    bookmarksHolder notNil ifTrue:[
        bookmarksHolder addDependent:self.
    ].
    newValue := bookmarksHolder value.
    oldValue ~~ newValue ifTrue:[
        self update:#value with:newValue from:bookmarksHolder.
    ].
!

hasBookmarkHolder
    "return/create the 'bookmarkHolder' value holder (automatically generated)"

    hasBookmarkHolder isNil ifTrue:[
        hasBookmarkHolder := (AspectAdaptor forAspect:#notNil)
                                subjectChannel: (self bookmarkHolder)
    ].
    ^ hasBookmarkHolder

    "Created: / 08-06-2011 / 12:39:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

menuButtonIcon
    <resource: #uiAspect>

    ^ToolbarIconLibrary sortIndicatorIcon

    "Created: / 02-06-2011 / 19:55:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

menuHolder
    "return/create the 'menuHolder' value holder (automatically generated)"

    menuHolder isNil ifTrue:[
        menuHolder := ValueHolder new.
    ].
    ^ menuHolder

    "Modified: / 18-05-2011 / 18:57:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!BookmarkBar methodsFor:'change & update'!

update:something with:aParameter from:changedObject
    "Invoked when an object that I depend upon sends a change notification."

    changedObject == bookmarksHolder ifTrue:[
        self updateMenu.
        ^ self.
    ].

    changedObject == bookmarkHolder ifTrue:[
        self updateBookmarkButton.
        ^ self.
    ].

    super update:something with:aParameter from:changedObject

    "Modified: / 02-06-2011 / 22:47:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

updateBookmarkButton

    "Created: / 02-06-2011 / 22:47:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

updateMenu

    | menu item |

    self window isVisible ifFalse:[^self].
    menu := self bookmarksHolder value asMenu.
    menu hasItems ifFalse:[
        item := MenuItem labeled: ('No bookmarks yet, click here or on star to add one' asText colorizeAllWith: Color gray).
        item value: #bookmarkMenu.
        item enabled: self hasBookmarkHolder.
        item isButton: true.
        menu addItem: item.
    ].
    

    menu findGuiResourcesIn:self.
    menuHolder value: menu.

    "Created: / 18-05-2011 / 18:00:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 08-06-2011 / 12:40:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!BookmarkBar methodsFor:'hooks'!

commonPostOpen

    super commonPostOpen.
    self bookmarksHolder value ifNil:
        [self bookmarksHolder value: BookmarkList forSystemBrowser].
    self updateMenu.

    "Created: / 18-05-2011 / 18:58:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 02-06-2011 / 19:51:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!BookmarkBar methodsFor:'menu'!

bookmarkMenuAddSlice
    ^ BookmarkAddMenuBuilder buildMenuFor:self bookmarksHolder value

    "Created: / 02-06-2011 / 21:54:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!BookmarkBar methodsFor:'menu actions'!

menuAddBookmark

    self menuAddBookmarkTo: self bookmarksHolder value root.

    "Created: / 02-06-2011 / 21:36:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

menuAddBookmarkTo: folder

    | bookmark |
    bookmark := self bookmarkHolder value.
    bookmark ifNil:[^self].
    folder add: bookmark.
    self bookmarksHolder value save.

    "Created: / 02-06-2011 / 22:17:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

menuOpenBookmarkEditor

    BookmarkListEditor new
        bookmarkList: self bookmarksHolder value;
        open.

    "Modified: / 02-06-2011 / 20:02:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!BookmarkBar class methodsFor:'documentation'!

version_CVS
    ^ '$Header: /cvs/stx/stx/libtool/BookmarkBar.st,v 1.1 2011-07-01 13:15:55 cg Exp $'
!

version_SVN
    ^ '§Id§'
! !