Pharo 8, spec 2 :)

This commit is contained in:
SantiagoBragagnolo 2020-02-23 00:05:41 +00:00
parent b9a9c99af1
commit 9c84f8bca2
8 changed files with 133 additions and 121 deletions

View File

@ -69,6 +69,7 @@ GfWorldMenu class >> launchCompatibilityMenuOn: aBuilder [
{ #category : #'world menu' }
GfWorldMenu class >> launchMenuOn: aBuilder [
<worldMenu>
(aBuilder item: #'New notebook')
label: 'New notebook';
order: 1;

View File

@ -37,7 +37,7 @@ GrafoscopioAbstractNode >> addTag: aTag [
{ #category : #exporting }
GrafoscopioAbstractNode >> asTreeNodePresenter [
| node |
node := TreeNodePresenter new.
node := SpTreeNodePresenter new.
node
hasChildren: [ false ];
children: [ {} ];

View File

@ -4,7 +4,7 @@ embedded interactive Playground.
"
Class {
#name : #GrafoscopioCodeModel,
#superclass : #ComposablePresenter,
#superclass : #SpPresenter,
#instVars : [
'body'
],
@ -13,8 +13,9 @@ Class {
{ #category : #specs }
GrafoscopioCodeModel class >> defaultSpec [
^ SpecLayout composed add: #body
^ SpBoxLayout newVertical
add: #body;
yourself
]
{ #category : #accessing }

View File

@ -14,7 +14,7 @@ Class {
{ #category : #specs }
GrafoscopioLinksList class >> defaultSpec [
^ SpecLayout composed
^ SpLayout composed
add: #links;
yourself
]

View File

@ -10,7 +10,7 @@ nb openWithSpec
"
Class {
#name : #GrafoscopioNewNotebook,
#superclass : #ComposablePresenter,
#superclass : #SpPresenter,
#instVars : [
'tree',
'header',
@ -39,22 +39,21 @@ GrafoscopioNewNotebook class >> SHA1For: aFile is: aSHA1String [
{ #category : #specs }
GrafoscopioNewNotebook class >> defaultSpec [
^ SpecLayout composed
newColumn: [:tcol|
tcol newRow: [ :wrow | wrow add: #windowMainMenu ] height: (self toolbarHeight);
newRow: [:row |
row newColumn: [ :tc |
tc add: #tree
] width: 300.
row newColumn: [ :bc |
bc newRow: [ :bcr | bcr add: #header ] height: self toolbarHeight.
bc add: #body; add: #links height: self toolbarHeight ]]]
]
{ #category : #'instance creation' }
GrafoscopioNewNotebook class >> initialize [
recents := Set new.
^ SpBoxLayout newVertical
add: #windowMainMenu
withConstraints: [ :constraints | constraints height: self toolbarHeight ];
add:
(SpPanedLayout newHorizontal
position: 250;
add: #tree;
add:
(SpBoxLayout newVertical
add: #header height: self toolbarHeight;
add: #body;
add: #links height: self toolbarHeight;
yourself);
yourself);
yourself
]
{ #category : #'instance creation' }
@ -74,7 +73,7 @@ GrafoscopioNewNotebook class >> open: aFileReference [
{ #category : #'instance creation' }
GrafoscopioNewNotebook class >> recents [
^ recents
^ recents ifNil: [ recents := Set new. ]
]
{ #category : #'instance creation' }
@ -117,25 +116,24 @@ GrafoscopioNewNotebook >> askToSaveBeforeClosing [
GrafoscopioNewNotebook >> autoSaveBodyOf: aNode [
| playground bodyContents |
bodyContents := aNode content.
self body class = GrafoscopioTextModel
ifTrue: [ self body body whenTextChanged: [ :arg |
aNode content: arg.
"self body body whenTextIsAccepted: [:bodyText |
self body class = GrafoscopioTextModel
ifTrue: [ self body body
whenTextChangedDo: [ :arg |
aNode content: arg.
"self body body whenTextIsAccepted: [:bodyText |
self inform: bodyText.
aNode updateEditionTimestamp ]."
bodyContents = arg ifFalse: [
"self inform: arg."
"aNode updateEditionTimestamp" ]]].
bodyContents = arg
ifFalse: [ "self inform: arg.""aNode updateEditionTimestamp" ] ] ].
self body body class = GlamourPresentationModel
ifFalse: [ ^ self ].
playground := self body body glmPres.
playground
onChangeOfPort: #text
act: [ :x |
aNode content: (x pane port: #entity) value content.
aNode content: (x pane port: #entity) value content
"aNode updateEditionTimestamp."
"self inform: aNode edited" ]
]
{ #category : #accessing }
@ -178,8 +176,8 @@ GrafoscopioNewNotebook >> content [
{ #category : #'editing nodes' }
GrafoscopioNewNotebook >> copyNodeToClipboard [
tree highlightedItem content copyToClipboard.
self notebookContent: notebook.
tree selectedItem copyToClipboard.
self notebookContent: notebook
]
{ #category : #persistence }
@ -200,11 +198,10 @@ GrafoscopioNewNotebook >> createNewExample [
{ #category : #operation }
GrafoscopioNewNotebook >> currentNode [
^ tree highlightedItem
^ tree selectedItem
ifNil: [ notebook children
ifEmpty: [ notebook root ]
ifNotEmpty: [ notebook children first ] ]
ifNotNil: [ :v | v content ]
]
{ #category : #operation }
@ -251,7 +248,7 @@ GrafoscopioNewNotebook >> defineDebugMessageUI [
{ #category : #'editing nodes' }
GrafoscopioNewNotebook >> demoteNode [
| editedNode |
editedNode := tree highlightedItem content.
editedNode := tree selectedItem.
editedNode demote.
self notebookContent: notebook.
]
@ -265,13 +262,22 @@ GrafoscopioNewNotebook >> downloadImages [
locations."
| parentFolder |
parentFolder := self workingFile parent.
self.
^ self imagesList do: [ :each | | relativePathString link |
link := each contents asUrl.
relativePathString := link directory.
relativePathString ifNotEmpty: [
GrafoscopioUtils ensureCreateDirectory: relativePathString into: parentFolder ]]
parentFolder := UIManager default
chooseDirectory: 'Please, choose a destination for the images'
from:
(self workingFile
ifNil: [ FileLocator home ]
ifNotNil: [ self workingFile parent ]).
parentFolder
ifNotNil: [ ^ self imagesList
do: [ :each |
| relativePathString link |
link := each contents asUrl.
relativePathString := link directory.
relativePathString
ifNotEmpty: [ GrafoscopioUtils
ensureCreateDirectory: relativePathString
into: parentFolder ] ] ]
]
{ #category : #persistence }
@ -432,7 +438,7 @@ GrafoscopioNewNotebook >> extent [
{ #category : #'as yet unclassified' }
GrafoscopioNewNotebook >> findAndReplace [
| currentNode replaceGUI findString replaceString |
currentNode := tree highlightedItem content.
currentNode := tree selectedItem.
replaceGUI := GrafoscopioReplace new.
replaceGUI openWithSpec.
replaceGUI ok
@ -500,12 +506,12 @@ GrafoscopioNewNotebook >> importImages [
GrafoscopioNewNotebook >> importLinkContent [
"I see if a node link is an url located at 'http://ws.stfx.eu', wich means that is a shared
workspace, and convert the node body to an interactive playground"
| currentNode nodeContent |
currentNode := tree highlightedItem.
| currentNode |
currentNode := tree selectedItem.
currentNode ifNil: [ ^ self ].
nodeContent := currentNode content.
nodeContent importPlaygroundLink.
nodeContent importHtmlLink.
currentNode importPlaygroundLink.
currentNode importHtmlLink.
self updateBodyFor: currentNode
]
@ -522,21 +528,19 @@ GrafoscopioNewNotebook >> initialize [
{ #category : #initialization }
GrafoscopioNewNotebook >> initializePresenter [
tree
whenHighlightedItemChanged:
[ :item | tree highlightedItem ifNotNil: [ self updateBodyFor: item content ] ].
tree
whenTreeUpdated: [ :item | item ifNotNil: [ self updateBodyFor: item ] ].
whenActivatedDo:
[ :selection | selection ifNotNil: [ self updateBodyFor: selection selectedItem ] ].
header
whenTextChanged: [ :arg |
tree highlightedItem content header = arg
ifFalse: [ tree highlightedItem content header: arg.
tree highlightedItem content updateEditionTimestamp.
whenTextChangedDo: [ :arg |
tree selectedItem header = arg
ifFalse: [ tree selectedItem header: arg.
tree selectedItem updateEditionTimestamp.
tree roots: tree roots ] ].
links
whenTextChanged: [ :arg |
(tree highlightedItem content respondsTo: #link:)
ifTrue: [ tree highlightedItem content link: arg.
tree highlightedItem content updateEditionTimestamp ] ]
whenTextChangedDo: [ :arg |
(tree respondsTo: #link:)
ifTrue: [ tree selectedItem link: arg.
tree selectedItem updateEditionTimestamp ] ]
]
{ #category : #initialization }
@ -545,21 +549,22 @@ GrafoscopioNewNotebook >> initializeWidgets [
header := self newTextInput.
header autoAccept: true.
body := self newText.
body class logCr.
body class traceCr.
body disable.
body text: '<- Select a node'.
body autoAccept: true.
links := self newTextInput.
tree := self newTree.
tree
childrenBlock: [:node | node children];
displayBlock: [:node | node title ].
self focusOrder
tree := self newTreeTable.
tree addColumn: (SpStringTableColumn evaluated: #title).
" tree
childrenBlock: [ :node | node children value ];
displayBlock: [ :node | node title value ]."
self focusOrder
add: tree;
add: header;
add: body;
add: links.
self askOkToClose: true.
self askOkToClose: true
]
{ #category : #persistence }
@ -596,7 +601,7 @@ GrafoscopioNewNotebook >> links: anObject [
{ #category : #'as yet unclassified' }
GrafoscopioNewNotebook >> linksList [
| currentNode |
currentNode := tree highlightedItem content.
currentNode := tree selectedItem.
GrafoscopioLinksList new
content: currentNode;
openWithSpec
@ -652,16 +657,16 @@ GrafoscopioNewNotebook >> metadata [
{ #category : #'editing nodes' }
GrafoscopioNewNotebook >> moveSelectedNodeDown [
| editedNode |
editedNode := tree selectedItem content.
editedNode := tree selectedItem.
editedNode moveDown.
self notebookContent: notebook.
tree needRebuild: true.
tree needRebuild: true
]
{ #category : #'editing nodes' }
GrafoscopioNewNotebook >> moveSelectedNodeUp [
| editedNode |
editedNode := tree highlightedItem content.
editedNode := tree selectedItem.
editedNode moveUp.
self notebookContent: notebook
]
@ -702,13 +707,12 @@ GrafoscopioNewNotebook >> notebook: anObject [
{ #category : #api }
GrafoscopioNewNotebook >> notebookContent: aTree [
tree
roots: (aTree children collect: [ :gfcNode | gfcNode asTreeNodePresenter ])
tree roots: aTree children
]
{ #category : #initialization }
GrafoscopioNewNotebook >> notebookSubMenu [
^ MenuPresenter new
^ SpMenuBarPresenter new
addGroup: [ :group |
group
addItem: [ :item |
@ -875,7 +879,7 @@ GrafoscopioNewNotebook >> pandocOptionsComputed [
{ #category : #'editing nodes' }
GrafoscopioNewNotebook >> pasteNodeFromClipboard [
tree highlightedItem content pasteFromClipboard.
tree selectedItem pasteFromClipboard.
self notebookContent: notebook.
]
@ -933,24 +937,26 @@ GrafoscopioNewNotebook >> projectSubMenu [
{ #category : #'editing nodes' }
GrafoscopioNewNotebook >> promoteNode [
| editedNote |
editedNote := tree selectedItem content.
editedNote := tree selectedItem.
editedNote promote.
self notebookContent: notebook
]
{ #category : #'editing nodes' }
GrafoscopioNewNotebook >> removeNode [
| contentToDelete parentContent newSelectedContent children |
| contentToDelete parentContent newSelectedContent children path |
tree selectedItem
ifNil: [ ^ self inform: 'No node available or properly selected ' ].
contentToDelete := tree selectedItem content.
path := tree selection selectedPath.
contentToDelete := tree selectedItem.
contentToDelete shouldAskBeforeRemove
ifTrue: [ (UIManager default
questionWithoutCancel:
'The selected node has children and / or content. This change so far cannot be undone. Are you sure you want to proceed? '
title: 'Remove node')
ifFalse: [ ^ self ] ].
parentContent := contentToDelete parent.
parentContent := tree selectedItem parent.
children := parentContent children.
children size > 1
ifTrue: [ children last = contentToDelete
@ -958,7 +964,7 @@ GrafoscopioNewNotebook >> removeNode [
ifFalse: [ newSelectedContent := parentContent ].
contentToDelete parent removeNode: contentToDelete.
self notebookContent: notebook.
self resetSelectedItem
self resetSelectedItemTo: path.
]
{ #category : #'editing nodes' }
@ -968,6 +974,12 @@ GrafoscopioNewNotebook >> resetSelectedItem [
tree updatePresenter.
]
{ #category : #'editing nodes' }
GrafoscopioNewNotebook >> resetSelectedItemTo: aPath [
tree selectPath: {(aPath first min: notebook children size)}.
tree updatePresenter
]
{ #category : #persistence }
GrafoscopioNewNotebook >> saveToFile: aFileReference [
"I save the current tree/document to a file and update storage timestamp."
@ -1022,14 +1034,13 @@ GrafoscopioNewNotebook >> seePdf [
{ #category : #'editing nodes' }
GrafoscopioNewNotebook >> selectedItem: anItem [
tree selectedItem: (tree roots detect: [ : p | p content = anItem ]).
tree highlightedItem: tree selectedItem.
tree selectItem: (tree roots detect: [ : p | p = anItem ]).
]
{ #category : #persistence }
GrafoscopioNewNotebook >> subtreeAsMarkdown [
| currentNode |
currentNode := tree highlightedItem content.
currentNode := tree selectedItem.
self inform: ('Exported as: ', String cr, (self subtreeAsMarkdownFileFor: currentNode) fullName )
]
@ -1046,14 +1057,14 @@ GrafoscopioNewNotebook >> subtreeAsMarkdownFileFor: aNode [
{ #category : #'editing nodes' }
GrafoscopioNewNotebook >> toggleCodeNode [
| currentNode |
currentNode := tree highlightedItem.
currentNode content toggleCodeText.
self updateBodyFor: currentNode.
currentNode := tree selectedItem.
currentNode toggleCodeText.
self updateBodyFor: currentNode
]
{ #category : #initialization }
GrafoscopioNewNotebook >> topBar [
^ MenuPresenter new
^ SpMenuBarPresenter new
addGroup: [ :group |
group
addItem: [ :item |
@ -1071,42 +1082,42 @@ GrafoscopioNewNotebook >> topBar [
group
addItem: [ :item |
item
name: nil;
name: '';
description: 'Save notebook';
icon: (self iconNamed: #glamorousSave);
action: [ self saveWorkingNotebook ] ].
group
addItem: [ :item |
item
name: nil;
name: '';
description: 'Export all Markdown subtrees';
icon: (self iconNamed: #glamorousMore);
action: [ self exportAllSubtreesAsMarkup ] ].
group
addItem: [ :item |
item
name: nil;
name: '';
description: 'Cut';
icon: (self iconNamed: #smallCut);
action: [ self cutNodeToClipboard ] ].
group
addItem: [ :item |
item
name: nil;
name: '';
description: 'Copy';
icon: (self iconNamed: #smallCopy);
action: [ self copyNodeToClipboard ] ].
group
addItem: [ :item |
item
name: nil;
name: '';
description: 'Paste';
icon: (self iconNamed: #smallPaste);
action: [ self pasteNodeFromClipboard ] ].
group
addItem: [ :item |
item
name: nil;
name: '';
description: 'Find & Replace';
icon: (self iconNamed: #smallFind);
action: [ self findAndReplace ] ] ];
@ -1114,42 +1125,42 @@ GrafoscopioNewNotebook >> topBar [
group
addItem: [ :item |
item
name: nil;
name: '';
description: 'Add node';
icon: MendaIcons new plusIcon;
action: [ self addNode ] ].
group
addItem: [ :item |
item
name: nil;
name: '';
description: 'Delete node';
icon: MendaIcons new minusIcon;
action: [ self removeNode ] ].
group
addItem: [ :item |
item
name: nil;
name: '';
description: 'Move node up';
icon: MendaIcons new arrowUpIcon;
action: [ self moveSelectedNodeUp ] ].
group
addItem: [ :item |
item
name: nil;
name: '';
description: 'Move node down';
icon: MendaIcons new arrowDownIcon;
action: [ self moveSelectedNodeDown ] ].
group
addItem: [ :item |
item
name: nil;
name: '';
description: 'Move node left';
icon: MendaIcons new arrowLeftIcon;
action: [ self promoteNode ] ].
group
addItem: [ :item |
item
name: nil;
name: '';
description: 'Move node right';
icon: MendaIcons new arrowRightIcon;
action: [ self demoteNode ] ] ];
@ -1157,70 +1168,70 @@ GrafoscopioNewNotebook >> topBar [
group
addItem: [ :item |
item
name: nil;
name: '';
description: 'Toggle: code <--> text';
icon: MendaIcons new smalltalkCodeIcon;
action: [ self toggleCodeNode ] ].
group
addItem: [ :item |
item
name: nil;
name: '';
description: 'List node links';
icon: (self iconNamed: #tinyMenu);
action: [ self linksList ] ].
group
addItem: [ :item |
item
name: nil;
name: '';
description: 'Visit link';
icon: (self iconNamed: #glamorousRight);
action: [ self visitNodeLink ] ].
group
addItem: [ :item |
item
name: nil;
name: '';
description: 'Import link content';
icon: (self iconNamed: #glamorousOpenFromUrl);
action: [ self importLinkContent ] ].
group
addItem: [ :item |
item
name: nil;
name: '';
description: 'Export link content';
icon: (self iconNamed: #glamorousSaveToUrl);
action: [ self exportLinkContent ] ].
group
addItem: [ :item |
item
name: nil;
name: '';
description: 'HTML to Markdown';
icon: (self iconNamed: #smallProfile);
action: [ self htmlToMarkdown ] ].
group
addItem: [ :item |
item
name: nil;
name: '';
description: 'HTML to Markdown subtree';
icon: (self iconNamed: #hierarchy);
action: [ self htmlToMarkdownSubtree ] ].
group
addItem: [ :item |
item
name: nil;
name: '';
description: 'Tag as...';
icon: MendaIcons new tagAddIcon;
action: [ self inform: 'To be implemented...' ] ].
group
addItem: [ :item |
item
name: nil;
name: '';
description: 'Untag ....';
icon: MendaIcons new tagMinusIcon;
action: [ self inform: 'To be implemented...' ] ].
group
addItem: [ :item |
item
name: nil;
name: '';
description: 'Edit tags...';
icon: FontAwesomeIcons new tagsIcon;
action: [ self inform: 'To be implemented...' ] ] ];
@ -1228,7 +1239,7 @@ GrafoscopioNewNotebook >> topBar [
debug
addItem: [ :item |
item
name: nil;
name: '';
description: 'Debug';
icon:
(self iconNamed: #glamorousBug);
@ -1251,13 +1262,12 @@ GrafoscopioNewNotebook >> updateBodyFor: aNode [
tree needRebuild: false.
body needRebuild: true.
aNode openIn: self.
self buildWithSpecLayout: self class defaultSpec
self buildWithSpec
]
{ #category : #operation }
GrafoscopioNewNotebook >> visitNodeLink [
tree highlightedItem content visitLastLink.
tree selectedItem visitLastLink
]
{ #category : #accessing }

View File

@ -4,7 +4,7 @@ Usually my content is markdown text.
"
Class {
#name : #GrafoscopioTextModel,
#superclass : #ComposablePresenter,
#superclass : #SpPresenter,
#instVars : [
'body'
],
@ -13,8 +13,9 @@ Class {
{ #category : #specs }
GrafoscopioTextModel class >> defaultSpec [
^ SpecLayout composed add: #body
^ SpBoxLayout newVertical
add: #body;
yourself
]
{ #category : #accessing }
@ -36,6 +37,5 @@ GrafoscopioTextModel >> content: aGrafoscopioNodeContent [
GrafoscopioTextModel >> initializeWidgets [
body := self newText.
body beForText.
body autoAccept: true.
]

View File

@ -182,7 +182,7 @@ GrafoscopioTextNode >> asStonFromRoot [
{ #category : #accessing }
GrafoscopioTextNode >> asTreeNodePresenter [
| node |
node := TreeNodePresenter new.
node := SpTreeNodePresenter new.
node
hasChildren: [ self children isNotEmpty ];
children: [ self children collect: [ :subNode | subNode asTreeNodePresenter ] ];

View File

@ -42,7 +42,7 @@ GrafoscopioUrlNode >> link: aZnUrl [
{ #category : #'as yet unclassified' }
GrafoscopioUrlNode >> openIn: aNotebook [
super openIn: aNotebook.
aNotebook links text: (link ifNil: 'Invalid url')
aNotebook links text: (link ifNil: 'Invalid url') asString
]
{ #category : #'as yet unclassified' }