Grafoscopio/repository/Grafoscopio/GrafoscopioNotebook.class.st

447 lines
11 KiB
Smalltalk

"
I am a Grafoscopio Notebook.
Example:
| testTree nb |
testTree := GrafoscopioNode new becomeDefaultTestTree.
nb := GrafoscopioNotebook new.
nb notebookContent: testTree.
nb openWithSpec
"
Class {
#name : #GrafoscopioNotebook,
#superclass : #ComposableModel,
#instVars : [
'tree',
'header',
'body',
'windowMainMenu',
'workingFile',
'notebook'
],
#category : #'Grafoscopio-UI'
}
{ #category : #utility }
GrafoscopioNotebook class >> SHA1For: aFile is: aSHA1String [
"I verify that a file has the same signature that the one in a given string,
returning true in that case or false otherwise"
^ (SHA1 new hashMessage: aFile asFileReference binaryReadStream contents) hex = aSHA1String
]
{ #category : #specs }
GrafoscopioNotebook class >> defaultSpec [
"comment stating purpose of message"
^ 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 ]]]
]
{ #category : #operation }
GrafoscopioNotebook >> addNode [
]
{ #category : #accessing }
GrafoscopioNotebook >> body [
^ body
]
{ #category : #accessing }
GrafoscopioNotebook >> body: anObject [
body := anObject
]
{ #category : #operation }
GrafoscopioNotebook >> changeBody: aNodeCollection [
| node |
node := aNodeCollection first.
self needRebuild: false.
tree needRebuild: false.
body := self instantiate: node specModelClass new.
body content: node content.
body needRebuild: true.
header text: node header.
self buildWithSpecLayout: self class defaultSpec.
]
{ #category : #persistence }
GrafoscopioNotebook >> exportAsSton: aNotebook on: aFileStream [
| stonPrettyString |
aNotebook flatten.
stonPrettyString := String streamContents: [ :stream |
(STON writer on: stream)
newLine: String crlf;
prettyPrint: true;
keepNewLines: true;
nextPut: aNotebook children].
aFileStream nextPutAll: stonPrettyString
]
{ #category : #accessing }
GrafoscopioNotebook >> extent [
^800@500
]
{ #category : #accessing }
GrafoscopioNotebook >> header [
^ header
]
{ #category : #accessing }
GrafoscopioNotebook >> header: anObject [
header := anObject
]
{ #category : #initialization }
GrafoscopioNotebook >> initializePresenter [
tree whenSelectedItemsChanged: [ :arg |
arg isEmpty ifFalse: [self changeBody: arg ]].
header whenTextChanged: [ :arg |
(tree selectedItem content header) = arg
ifFalse: [
(tree selectedItem) content header: header text.
tree roots: tree roots]].
body whenTextChanged: [ :arg |
(tree selectedItem) content body: body text
]
]
{ #category : #initialization }
GrafoscopioNotebook >> initializeWidgets [
windowMainMenu := self newWindowMainMenu.
tree := TreeModel new.
body := self newText.
header := self newTextInput.
body disable.
body text: '<-- Select a node in the left panel'.
tree childrenBlock: [:node | node children];
displayBlock: [:node | node title ].
]
{ #category : #initialization }
GrafoscopioNotebook >> newWindowMainMenu [
^MenuModel new
addGroup: [ :group |
group addItem: [ :item |
item
name: 'Notebook';
icon: Smalltalk ui icons smallObjectsIcon;
subMenu: self notebookSubMenu ].
group addItem: [ :item |
item
name: 'Project';
icon: Smalltalk ui icons catalogIcon;
subMenu: self projectSubMenu ] ];
addGroup: [ :group |
group addItem: [ :item |
item
name: nil;
description: 'Save notebook';
icon: Smalltalk ui icons smallSaveIcon;
action: [ self saveWorkingNotebook ] ].
group addItem: [ :item |
item
name: nil;
description: 'Undo';
icon: Smalltalk ui icons smallUndoIcon;
action: [ self inform: 'To be implemented...' ] ].
group addItem: [ :item |
item
name: nil;
description: 'Redo';
icon: Smalltalk ui icons smallRedoIcon;
action: [ self inform: 'To be implemented...' ] ]];
addGroup: [ :group |
group addItem: [ :item |
item
name: nil;
description: 'Add nodo';
icon: MendaIcons new plusIcon;
action: [ self addNode ] ].
group addItem: [ :item |
item
name: nil;
description: 'Delete node';
icon: MendaIcons new minusIcon;
action: [ self removeNode ] ].
group addItem: [ :item |
item
name: nil;
description: 'Move up node';
icon: MendaIcons new arrowUpIcon;
action: [ self moveNodeBefore ] ].
group addItem: [ :item |
item
name: nil;
description: 'Move down node';
icon: MendaIcons new arrowDownIcon;
action: [ self moveNodeAfter ] ].
group addItem: [ :item |
item
name: nil;
description: 'Move node left';
icon: MendaIcons new arrowLeftIcon;
action: [ self promoteNode ] ].
group addItem: [ :item |
item
name: nil;
description: 'Move node right';
icon: MendaIcons new arrowRightIcon;
action: [ self demoteNode ] ]];
addGroup: [ :group |
group addItem: [ :item |
item
name: nil;
description: 'Togle: code <--> text';
icon: MendaIcons new smalltalkCodeIcon;
action: [ self inform: 'To be implemented...' ] ].
group addItem: [ :item |
item
name: nil;
description: 'Tag as...';
icon: MendaIcons new tagAddIcon;
action: [ self inform: 'To be implemented...' ] ].
group addItem: [ :item |
item
name: nil;
description: 'Untag ....';
icon: MendaIcons new tagMinusIcon;
action: [ self inform: 'To be implemented...' ] ].
group addItem: [ :item |
item
name: nil;
description: 'Edit tags...';
icon: FontAwesomeIcons new tagsIcon;
action: [ self inform: 'To be implemented...' ] ]].
]
{ #category : #accessing }
GrafoscopioNotebook >> notebook [
^ notebook
]
{ #category : #accessing }
GrafoscopioNotebook >> notebook: anObject [
notebook := anObject
]
{ #category : #api }
GrafoscopioNotebook >> notebookContent: aTree [
tree roots: aTree children
]
{ #category : #initialization }
GrafoscopioNotebook >> notebookSubMenu [
^ MenuModel new
addGroup: [ :group |
group addItem: [ :item |
item
name: 'Save';
icon: Smalltalk ui icons smallSaveIcon;
shortcut: $s command;
action: [ self saveWorkingNotebook ] ].
group addItem: [ :item |
item
name: 'Save as...';
icon: Smalltalk ui icons smallSaveAsIcon;
action: [ self saveToFileUI ] ].
group addItem: [ :item |
item
name: 'Export as html';
icon: Smalltalk ui icons smallWindowIcon;
action: [ self inform: 'To be implemented...' ] ].
group addItem: [ :item |
item
name: 'Export as pdf';
icon: Smalltalk ui icons smallPrintIcon;
action: [ self inform: 'To be implemented...' ] ].
group addItem: [ :item |
item
name: 'See html';
icon: Smalltalk ui icons smallInspectItIcon;
action: [ self inform: 'To be implemented...' ] ].
group addItem: [ :item |
item
name: 'See pdf';
icon: Smalltalk ui icons smallInspectItIcon;
action: [ self inform: 'To be implemented...' ] ] ]
]
{ #category : #persistence }
GrafoscopioNotebook >> openDefault [
"I open a new default notebook"
| nb |
nb := self class new.
nb
notebook: (GrafoscopioNode new becomeDefaultTree);
title: ' New | Grafoscopio notebook';
notebookContent: nb notebook.
^ nb openWithSpec.
]
{ #category : #persistence }
GrafoscopioNotebook >> openFromFile: aFileName [
"I open a notebook from a file named aFileName containing a grafoscopio tree"
self workingFile: aFileName.
self notebook: ((STON fromString: self workingFile contents) at: 1) parent.
self title: self workingFile basenameWithIndicator, ' | Grafoscopio notebook'.
self notebookContent: self notebook.
^ self openWithSpec.
]
{ #category : #persistence }
GrafoscopioNotebook >> openFromFileSelector [
| fileStream nb |
fileStream := UITheme builder
fileOpen: 'Choose a file'
extensions: #('ston').
fileStream ifNil: [
self inform: 'No file selected'.
^ self ].
self workingFile: fileStream name asFileReference.
nb := self class new.
nb openFromFile: self workingFile.
]
{ #category : #persistence }
GrafoscopioNotebook >> openTutorial [
| tutorial |
tutorial := (FileLocator documents / 'Grafoscopio/Docs/Es/Turiales/tutorial.ston' ) asFileReference.
self class new openFromFile: tutorial.
]
{ #category : #initialization }
GrafoscopioNotebook >> projectSubMenu [
^ MenuModel new
addGroup: [ :group |
group addItem: [ :item |
item
name: 'Activate remote repository...';
icon: Smalltalk ui icons smallPushpinIcon;
action: [ self inform: 'To be implemented ...' ] ].
group addItem: [ :item |
item
name: 'Activate local repository...';
icon: Smalltalk ui icons homeIcon;
action: [ self inform: 'To be implemented ...' ] ].
group addItem: [ :item |
item
name: 'Add file...';
icon: Smalltalk ui icons newerPackagesAvailableIcon;
action: [ self inform: 'To be implemented ...' ] ].
group addItem: [ :item |
item
name: 'Delete file...';
icon: Smalltalk ui icons packageDeleteIcon;
action: [ self inform: 'To be implemented ...' ] ].
group addItem: [ :item |
item
name: 'Commit to repository';
icon: Smalltalk ui icons smallScreenshotIcon;
action: [ self inform: 'To be implemented ...' ] ].
group addItem: [ :item |
item
name: 'Credentials';
icon: Smalltalk ui icons userIcon;
action: [ self inform: 'To be implemented ...' ] ] ]
]
{ #category : #persistence }
GrafoscopioNotebook >> saveToFile: aFileReference [
"I save the current tree/document to a file"
aFileReference ifNil: [ self inform: 'No file selected for saving. Save NOT done'. ^ self ].
workingFile := aFileReference.
self workingFile exists ifTrue: [self workingFile delete].
self workingFile ensureCreateFile.
[ self exportAsSton: self notebook on: (self workingFile writeStream)]
ensure: [ (self workingFile writeStream) ifNotNil: #close ].
self title: self workingFile basenameWithIndicator, ' | Grafoscopio notebook'.
self inform: ('File saved at: ', String cr, self workingFile fullName).
GrafoscopioGUI updateRecentNotebooksWith: aFileReference.
]
{ #category : #persistence }
GrafoscopioNotebook >> saveToFileUI [
| file |
file := UITheme builder
fileSave: 'Export notebook to file as...'
extensions: #('ston')
path: nil.
file
ifNil: [ self inform: 'Export cancelled'. ^ self ]
ifNotNil:[self saveToFile: file].
]
{ #category : #persistence }
GrafoscopioNotebook >> saveWorkingNotebook [
"Saves the current tree to the user predefined file location used when he/she opened it."
self workingFile
ifNil: [ self saveToFileUI ]
ifNotNil: [ self saveToFile: workingFile ]
]
{ #category : #accessing }
GrafoscopioNotebook >> tree [
^ tree
]
{ #category : #accessing }
GrafoscopioNotebook >> tree: anObject [
tree := anObject
]
{ #category : #accessing }
GrafoscopioNotebook >> windowMainMenu [
^ windowMainMenu
]
{ #category : #accessing }
GrafoscopioNotebook >> windowMainMenu: anObject [
windowMainMenu := anObject
]
{ #category : #accessing }
GrafoscopioNotebook >> workingFile [
^ workingFile
]
{ #category : #accessing }
GrafoscopioNotebook >> workingFile: aFile [
workingFile := aFile.
]