diff -r eb4bd1984ca0 -r ade46105bcc0 BookmarksEditDialog.st --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BookmarksEditDialog.st Wed Mar 12 17:38:30 2008 +0100 @@ -0,0 +1,489 @@ +"{ Package: 'stx:libtool' }" + +SimpleDialog subclass:#BookmarksEditDialog + instanceVariableNames:'selectedBookmarksHolder bookmarkListHolder defaultBookmark answer' + classVariableNames:'' + poolDictionaries:'' + category:'Interface-Tools-File' +! + + +!BookmarksEditDialog class methodsFor:'image specs'! + +fileIn22x22Icon + "This resource specification was automatically generated + by the ImageEditor of ST/X." + + "Do not manually edit this!! If it is corrupted, + the ImageEditor may not be able to read the specification." + + " + self fileIn22x22Icon inspect + ImageEditor openOnClass:self andSelector:#fileIn22x22Icon + Icon flushCachedIcons + " + + + + ^Icon + constantNamed:'BookmarksDialog class fileIn22x22Icon' + ifAbsentPut:[(Depth8Image new) width: 22; height: 22; photometric:(#palette); bitsPerSample:(#[8]); samplesPerPixel:(1); bits:(ByteArray fromPackedString:' +@@@@@@@@GQ4]GQ4]GQ4]GQ4]GQ4]GP@@@@@@@A4]GQ4]GQ4]GQ4]GQ4]GQ4@@@@@@@@]GQ4]GQ4]GQ4]GQ4]GQ4]@ATUEQTUEQTUEA4]GQ4]GQ4]GQ4]GP@U +GQ4]DPP''I!!TTGQ4]GQ4]GQ4]GQ4@EQ4]GP$K@"XUG!!P]GQ4]GQ4]GQ4]@AT]GQ4IDPX&EAPTEA4]GQ4]GQ4]GP@UGQ4]C1DEI!!<)HQP]@A4]GQ4]GQ4@EQ4] +GQLIFQ,)JQ\TGP@@GQ4]GQ4]@AT]GQ4]BRH)JR$)JR$)JR$)GQ4]GP@UGQ4SDPP)JR$)JR$)JR$)JQ4]GQ4@EQ4SC1 )JR$)JR$)JR$)JR$@@A4]@AT]GQDZ +F2$)JR$)JR$)JR$)GP@]GQ4UGP@@_?@@_? @_? @_? @_??@_??@_??@_??@_??@_? @_? @_? @_? @_? @@@@@@@@@@@@@') ; yourself); yourself] +! + +icon + + ^ ToolbarIconLibrary directoryBookmarksIcon +! ! + +!BookmarksEditDialog 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:BookmarksDialog andSelector:#windowSpec + BookmarksDialog new openInterface:#windowSpec + BookmarksDialog open + " + + + + ^ + #(FullSpec + name: windowSpec + window: + (WindowSpec + label: 'Edit Bookmarks' + name: 'Edit Bookmarks' + min: (Point 0 0) + bounds: (Rectangle 0 0 450 296) + ) + component: + (SpecCollection + collection: ( + (MenuPanelSpec + name: 'ToolBar' + layout: (LayoutFrame 0 0 0 0 0 1 30 0) + menu: toolBarMenu + textDefault: true + ) + (SequenceViewSpec + name: 'BookmarkList' + layout: (LayoutFrame 0 0 30 0 0 1 -30 1) + model: selectedBookmarksHolder + hasHorizontalScrollBar: true + hasVerticalScrollBar: true + isMultiSelect: true + useIndex: false + sequenceList: bookmarkListHolder + ) + (HorizontalPanelViewSpec + name: 'HorizontalPanel1' + layout: (LayoutFrame 0 0 -30 1 0 1 0 1) + horizontalLayout: center + verticalLayout: center + horizontalSpace: 3 + verticalSpace: 3 + component: + (SpecCollection + collection: ( + (ActionButtonSpec + label: 'OK' + name: 'Button1' + translateLabel: true + model: doAccept + extent: (Point 125 22) + ) + (ActionButtonSpec + label: 'Cancel' + name: 'Button2' + translateLabel: true + model: doCancel + extent: (Point 125 22) + ) + ) + + ) + ) + ) + + ) + ) +! ! + +!BookmarksEditDialog class methodsFor:'menu specs'! + +toolBarMenu + "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:BookmarksEditDialog andSelector:#toolBarMenu + (Menu new fromLiteralArrayEncoding:(BookmarksEditDialog toolBarMenu)) startUp + " + + + + ^ + #(Menu + ( + (MenuItem + label: 'New' + itemValue: new + translateLabel: true + labelImage: (ResourceRetriever XPToolbarIconLibrary newBookmark22x22Icon) + ) + (MenuItem + enabled: removeButtonEnabledHolder + label: 'Remove' + itemValue: remove + translateLabel: true + labelImage: (ResourceRetriever XPToolbarIconLibrary close22x22Icon) + ) + (MenuItem + label: '-' + ) + (MenuItem + enabled: upButtonEnabledHolder + label: 'Up' + itemValue: up + translateLabel: true + labelImage: (ResourceRetriever XPToolbarIconLibrary up22x22Icon) + ) + (MenuItem + enabled: downButtonEnabledHolder + label: 'Down' + itemValue: down + translateLabel: true + labelImage: (ResourceRetriever XPToolbarIconLibrary down22x22Icon) + ) + (MenuItem + label: '-' + ) + (MenuItem + label: 'Import' + itemValue: import + translateLabel: true + labelImage: (ResourceRetriever BookmarksEditDialog fileIn22x22Icon) + ) + (MenuItem + label: 'Export' + itemValue: export + translateLabel: true + labelImage: (ResourceRetriever XPToolbarIconLibrary fileIn22x22Icon) + ) + ) + nil + nil + ) +! ! + +!BookmarksEditDialog class methodsFor:'opening'! + +openWith: bookmarks + + ^ self openWith: bookmarks defaultBookmark: '' +! + +openWith: bookmarks defaultBookmark: aFilename + + | dialog bookmarkStrings | + + dialog := BookmarksEditDialog new. + + dialog allButOpenInterface:#windowSpec. + Dialog aboutToOpenBoxNotificationSignal raiseRequestWith:dialog. + + aFilename notNil ifTrue:[dialog defaultBookmark: aFilename asString.]. + bookmarkStrings := bookmarks collect:[:each | each asString]. + dialog bookmarkList: bookmarkStrings. + dialog openWindow. + ^ dialog answer +! ! + +!BookmarksEditDialog methodsFor:'accessing'! + +answer + ^ answer +! + +bookmarkList + + ^ self bookmarkListHolder. +! + +bookmarkList: bookmarkStrings + + self bookmarkList contents: bookmarkStrings. +! + +defaultBookmark + ^ defaultBookmark +! + +defaultBookmark:something + defaultBookmark := something. +! + +indexForNewBookmark + + | index | + index := self selectedBookmarkIndex. + index = 0 ifTrue:[^ self bookmarkList size]. + ^ index +! + +indexOfBookmark: aString + + ^ self bookmarkList indexOf: aString +! + +selectBookmark: bookmark + + self selectedBookmarks: (Array with: bookmark). +! + +selectedBookmarkIndex + + | someBookmarks | + + someBookmarks := self selectedBookmarks. + someBookmarks size = 1 ifTrue:[ + ^ self indexOfBookmark: someBookmarks first + ]. + ^ 0 +! + +selectedBookmarks + + ^ self selectedBookmarksHolder value +! + +selectedBookmarks: aCollection + + ^ self selectedBookmarksHolder value: aCollection +! ! + +!BookmarksEditDialog methodsFor:'aspects'! + +bookmarkListHolder + + + bookmarkListHolder isNil ifTrue:[ + bookmarkListHolder := List new. +"/ if your app needs to be notified of changes, uncomment one of the lines below: +"/ bookmarkListHolder addDependent:self. +"/ bookmarkListHolder onChangeSend:#bookmarkListChanged to:self. + ]. + ^ bookmarkListHolder. +! + +downButtonEnabledHolder + + ^ builder valueAspectFor:#'downButtonEnabledHolder' initialValue:false +! + +removeButtonEnabledHolder + + ^ builder valueAspectFor:#'removeButtonEnabledHolder' initialValue:false +! + +selectedBookmarksHolder + + + selectedBookmarksHolder isNil ifTrue:[ + selectedBookmarksHolder := #() asValue. +"/ if your app needs to be notified of changes, uncomment one of the lines below: +"/ selectedBookmarksHolder addDependent:self. + selectedBookmarksHolder onChangeSend:#selectedBookmarksChanged to:self. + ]. + ^ selectedBookmarksHolder. +! + +upButtonEnabledHolder + + ^ builder valueAspectFor:#'upButtonEnabledHolder' initialValue:false +! ! + +!BookmarksEditDialog methodsFor:'initialize'! + +initialize + + defaultBookmark := ''. + ^ super initialize. +! ! + +!BookmarksEditDialog methodsFor:'menu actions'! + +down + + | someBookmarks bookmarkToMove index | + + someBookmarks := self selectedBookmarks. + someBookmarks size = 1 ifFalse:[^ self]. + bookmarkToMove := someBookmarks first. + index := self indexOfBookmark: bookmarkToMove. + index = self bookmarkList size ifTrue:[^self]. + self bookmarkList remove: bookmarkToMove. + self bookmarkList add: bookmarkToMove afterIndex: index. + self selectBookmark: bookmarkToMove. +! + +export + + | filename bookmarks | + + filename := Dialog + requestFileName:'Select file to export bookmarks:' + default:'.fileBrowserBookmarks' + fromDirectory:Filename desktopDirectory. + filename isEmptyOrNil ifTrue:[^ self]. + + bookmarks := self bookmarkList. + AbstractFileBrowser saveBookmarks: bookmarks in:filename. +! + +import + + | answer filename bookmarksFromFile bookmarksToAdd bookmarks| + + answer := Dialog + requestFileName:'Select file to import bookmarks:' + default:'.fileBrowserBookmarks' + fromDirectory:Filename desktopDirectory. + + answer isEmptyOrNil ifTrue:[^ self]. + filename := answer asFilename. + (filename isDirectory or:[filename exists not]) ifTrue:[^ self]. + bookmarksFromFile := AbstractFileBrowser bookmarksFrom: filename. + + bookmarks := self bookmarkList. + bookmarksToAdd := bookmarksFromFile reject:[:each | bookmarks includes: each]. + bookmarks addAll: bookmarksToAdd. +! + +new + + | someBookmarks default index bookmark| + + someBookmarks := self selectedBookmarks. + + default := someBookmarks isEmpty + ifTrue:[defaultBookmark] + ifFalse:[someBookmarks first]. + + bookmark := Dialog request:'New Bookmark' title:'Enter a directory' initialAnswer:default. + bookmark isEmptyOrNil ifTrue:[^ self]. + (self bookmarkList includes: bookmark) ifTrue:[^ self]. + + index := self indexForNewBookmark. + self bookmarkList add: bookmark afterIndex: index. + self selectBookmark: bookmark. +! + +remove + + | someBookmarks message ans | + + someBookmarks := self selectedBookmarks. + someBookmarks isEmpty ifTrue:[^ self]. + + message := 'Really remove bookmarks: ', String lf. + someBookmarks do:[:each | message := message, String lf, (String new: 5) , each]. + ans := Dialog confirm: message. + ans ifFalse:[^ self]. + + self bookmarkList removeAll: someBookmarks. +! + +up + + | someBookmarks bookmarkToMove index | + + someBookmarks := self selectedBookmarks. + someBookmarks size = 1 ifFalse:[^ self]. + bookmarkToMove := someBookmarks first. + index := self indexOfBookmark: bookmarkToMove. + index = 1 ifTrue:[^self]. + self bookmarkList remove: bookmarkToMove. + self bookmarkList add: bookmarkToMove beforeIndex: index - 1. + self selectBookmark: bookmarkToMove. +! ! + +!BookmarksEditDialog methodsFor:'queries'! + +hasChanges + + |oldDirectoryBookmarks| + + oldDirectoryBookmarks := AbstractFileBrowser directoryBookmarks collect:[:each | each asString]. + ^ self bookmarkList ~= oldDirectoryBookmarks +! ! + +!BookmarksEditDialog methodsFor:'user actions'! + +doAccept + + | filenames | + + filenames := self bookmarkList collect:[:each | each asFilename]. + answer := filenames. + ^ super doAccept +! + +doCancel + + | ans | + + self hasChanges ifTrue:[ + ans := Dialog confirm: 'Really cancel all changes?'. + ans ifFalse:[^ self]. + ]. + ^ super doCancel +! + +selectedBookmarksChanged + + | someBookmarks selectedBookmarkIndex | + + someBookmarks := self selectedBookmarks. + + self upButtonEnabledHolder value: false. + self downButtonEnabledHolder value: false. + self removeButtonEnabledHolder value: false. + + someBookmarks isEmpty ifTrue:[^ self]. + + someBookmarks size = 1 ifTrue:[ + selectedBookmarkIndex := self selectedBookmarkIndex. + selectedBookmarkIndex = 1 ifFalse:[ + self upButtonEnabledHolder value: true. + ]. + selectedBookmarkIndex = self bookmarkList size ifFalse:[ + self downButtonEnabledHolder value: true. + ]. + ] ifFalse:[ + self upButtonEnabledHolder value: false. + self downButtonEnabledHolder value: false. + ]. + self removeButtonEnabledHolder value: true. +! ! + +!BookmarksEditDialog class methodsFor:'documentation'! + +version + ^ '$Header: /cvs/stx/stx/libtool/BookmarksEditDialog.st,v 1.1 2008-03-12 16:38:30 fm Exp $' +! !