" I am a Grafoscopio Notebook. Example: | testTree nb | testTree := GrafoscopioNode new becomeDefaultTestTree. nb := GrafoscopioNotebook new. nb notebookContent: testTree. nb openWithSpec " Class { #name : #GrafoscopioNotebook, #superclass : #ComposablePresenter, #instVars : [ 'tree', 'header', 'body', 'links', 'windowMainMenu', 'workingFile', 'notebook', 'debugMessage', 'imagesList' ], #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 [ ^ 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' } GrafoscopioNotebook class >> newDefault [ ^ self new. ] { #category : #'instance creation' } GrafoscopioNotebook class >> open: aFileReference [ self newDefault openFromFile: aFileReference ] { #category : #utilities } GrafoscopioNotebook >> addCommandFrom: dictionary into: stream [ dictionary keysAndValuesDo: [ :k :v | k = 'thisNotebook' ifTrue: [ stream nextPutAll: (GrafoscopioUtils perform: v on: self) ]] ] { #category : #'editing nodes' } GrafoscopioNotebook >> addNode [ self currentNodeContent addNodeAfterMe. self notebookContent: notebook. ] { #category : #persistence } GrafoscopioNotebook >> askToSaveBeforeClosing [ | saveChanges | saveChanges := UIManager default question: 'Do you want to save changes in the notebook before closing?' title: 'Save changes before closing?'. saveChanges ifNil: [ ^ self notebook unsavedNodes inspect ]. ^ saveChanges ] { #category : #operation } GrafoscopioNotebook >> autoSaveBodyOf: aNode [ | playground bodyContents | bodyContents := aNode body. self body class = GrafoscopioTextModel ifTrue: [ self body body whenTextChanged: [ :arg | aNode body: arg. "self body body whenTextIsAccepted: [:bodyText | self inform: bodyText. 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 body: (x pane port: #entity) value content. "aNode updateEditionTimestamp." "self inform: aNode edited" ] ] { #category : #accessing } GrafoscopioNotebook >> body [ ^ body ] { #category : #accessing } GrafoscopioNotebook >> body: anObject [ body := anObject ] { #category : #utilities } GrafoscopioNotebook >> checksumForRootSubtree [ "I return the checksum (crypto hash) of the workingFile where this notebook is being stored. I'm useful for data provenance and traceability of derivated files coming from this source notebook." self workingFile ifNil: [ ^ self ]. self workingFile contents = '' ifTrue: [ ^ self ]. ^ GrafoscopioUtils checksumFor: self workingFile ] { #category : #'editing nodes' } GrafoscopioNotebook >> copyNodeToClipboard [ tree highlightedItem content copyToClipboard. self notebookContent: notebook. ] { #category : #operation } GrafoscopioNotebook >> currentNode [ | currentNode | currentNode := tree highlightedItem. currentNode ifNil: [ ^ self ]. ^ currentNode ] { #category : #operation } GrafoscopioNotebook >> currentNodeContent [ ^ self currentNode content ] { #category : #'editing nodes' } GrafoscopioNotebook >> cutNodeToClipboard [ self copyNodeToClipboard; removeNode. ] { #category : #accessing } GrafoscopioNotebook >> debugMessage [ ^ debugMessage ifNil: [ self defineDebugMessageUI ] ] { #category : #accessing } GrafoscopioNotebook >> debugMessage: aGrafoscopioNodeSelector [ "I define a message that can be used for debugging purposes in the current notebook." debugMessage := aGrafoscopioNodeSelector ] { #category : #operation } GrafoscopioNotebook >> debugWithSelector: aSymbol [ "I invoke a message to debug in the current node. In the future the debugging scope can be changed to include different elements instead of the current node." | currentNode nodeContent | currentNode := tree highlightedItem. currentNode ifNil: [ ^ self ]. nodeContent := currentNode content. ^ (nodeContent perform: aSymbol asSymbol) inspect ] { #category : #utilities } GrafoscopioNotebook >> defineDebugMessageUI [ | answer | answer := UIManager default request: 'Define debug message to be send to a selected node in this notebook.' initialAnswer: 'messageNoDebugSelector'. self debugMessage: answer ] { #category : #'editing nodes' } GrafoscopioNotebook >> demoteNode [ | editedNode | editedNode := tree highlightedItem content. editedNode demote. self notebookContent: notebook. ] { #category : #'as yet unclassified' } GrafoscopioNotebook >> downloadImages [ "I download all images in a notebook into a local folder that respects relative paths. So if a image refers to http://mysite.com/uploads/chap1/myimage.png, it will be stored into: 'uploads/chap1/myimage.png' in the same folder where the notebook is stored. This is helpful for notebooks conversions that expect to have local images in particular 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 ]] ] { #category : #persistence } GrafoscopioNotebook >> exportAllSubtreesAsMarkup [ | toBeExported | toBeExported := self notebook selectMarkupSubtreesToExport. toBeExported ifEmpty: [ ^ self ]. toBeExported do: [ :each | self subtreeAsMarkdownFileFor: each ]. self inform: toBeExported size asString , ' exported markdown subtrees.' ] { #category : #persistence } GrafoscopioNotebook >> exportAsHTML [ "I export the current tree/document to a HTML file, using pandoc external app. I suppose pandoc is already installed and available in the system." | htmlFile | self markdownFile exists ifTrue: [ self markdownFile delete ]. self exportAsMarkdown. htmlFile := self markdownFile parent fullName,'/', self markdownFile basenameWithoutExtension, '.html'. htmlFile asFileReference exists ifTrue: [ htmlFile asFileReference delete ]. Smalltalk platformName = 'unix' ifTrue: [ OSSUnixSubprocess new command: 'pandoc'; arguments: {'--standalone'. self markdownFile fullName. '--output' . htmlFile}; redirectStdout; runAndWaitOnExitDo: [ :process :outString :errString | process isSuccess ifTrue: [ self inform: ('File exported as: ', String cr, htmlFile) ] ifFalse: [ self inform: 'Exportation unsuccesful. Please review that you have installed Pandoc and have used the exportation options properly.' ]]]. Smalltalk platformName = 'Win32' ifTrue: ["WinProcess createProcess: 'pandoc --standalone ', self markdownFile fullName, ' -o ', htmlFile"]. ] { #category : #persistence } GrafoscopioNotebook >> exportAsLaTeX [ "I export the current tree/document to a LaTeX file, using pandoc external app. I suppose pandoc is already installed and available in the system." | texFile | self markdownFile exists ifTrue: [ self markdownFile delete ]. "self exportAsMarkdown.""<- This violates the separation of concenrs. Markdown exportation should be explicit. There is still the issue of how to deal with desynchronization between a notebook which has unsaved changes as markdown.... TO BE REVIWED!" texFile := self markdownFile parent fullName,'/', self markdownFile basenameWithoutExtension, '.tex'. texFile asFileReference exists ifTrue: [ texFile asFileReference delete ]. OSProcess command: 'pandoc --standalone ', self markdownFile fullName, ' -o ', texFile. self inform: ('File exported as: ', String cr, texFile). ] { #category : #persistence } GrafoscopioNotebook >> exportAsMarkdown [ "I export the current working tree/document to a markdown file." workingFile ifNil: [ self inform: 'File NOT exported. Please save the notebook on hard drive first' ] ifNotNil: [ self exportNode: (self notebook) asMarkdownIn: (self markdownFile) ] ] { #category : #persistence } GrafoscopioNotebook >> exportAsPDF [ "I export the current tree/document to a PDF file, using pandoc and LaTeX external apps. The latex engine used is xelatex, to minimize errors and warnings related with UTF8 support. I suppose all them are already installed and defined in the system." | pandocCommonCommand | self markdownFile exists ifFalse: [ self exportAsMarkdown ]. self pdfFile ensureDelete. pandocCommonCommand := 'pandoc ', self pandocOptionsComputed, ' ', self markdownFile fullName, ' --output ', self pdfFile fullName. Smalltalk platformName = 'unix' ifTrue: [ ExternalOSProcess command: 'cd ', self markdownFile parent fullName,'; ', pandocCommonCommand ]. Smalltalk platformName = 'Win32' ifTrue: [ WinProcess createProcess: pandocCommonCommand ]. self inform: ('File exported as: ', String cr, self pdfFile fullName) ] { #category : #persistence } GrafoscopioNotebook >> exportAsSton: aNotebook on: aFileStream [ aNotebook flatten. self notebook root updateEditionTimestamp. (STON writer on: aFileStream) newLine: String crlf; prettyPrint: true; keepNewLines: true; nextPut: aNotebook children. ] { #category : #utility } GrafoscopioNotebook >> exportLinkContent [ Transcript show: (self currentNodeContent asMarkdown) ] { #category : #persistence } GrafoscopioNotebook >> exportNode: aGrafoscopioNode asMarkdownIn: aFile [ "I export the current tree/document to a markdown file" aFile ensureDelete. aFile ensureCreateFile; writeStreamDo: [:stream | stream nextPutAll: ('---', String cr, 'exportedFrom: ', self checksumForRootSubtree, String cr) withInternetLineEndings. aGrafoscopioNode metadataAsYamlIn: stream. stream nextPutAll: ('---', String cr, String cr) withInternetLineEndings, aGrafoscopioNode asMarkdown ]. self inform: 'Exported as: ', String cr, aFile fullName ] { #category : #api } GrafoscopioNotebook >> extent [ ^900@500 ] { #category : #'as yet unclassified' } GrafoscopioNotebook >> findAndReplace [ | currentNode replaceGUI findString replaceString | currentNode := tree highlightedItem content. replaceGUI := GrafoscopioReplace new. replaceGUI openWithSpec. replaceGUI ok on: [ ] do: [ findString := replaceGUI returnValues at: 'find'. replaceString := replaceGUI returnValues at: 'replace'. currentNode find: findString andReplaceWith: replaceString. ] ] { #category : #testing } GrafoscopioNotebook >> hasAWorkingFileDefined [ self workingFile ifNil: [ ^ false ] ifNotNil: [ ^ true ] ] { #category : #accessing } GrafoscopioNotebook >> header [ ^ header ] { #category : #accessing } GrafoscopioNotebook >> header: anObject [ header := anObject ] { #category : #operation } GrafoscopioNotebook >> htmlToMarkdown [ self currentNodeContent htmlToMarkdown. self updateBodyFor: self currentNode ] { #category : #operation } GrafoscopioNotebook >> htmlToMarkdownSubtree [ self currentNodeContent htmlToMarkdownSubtree. self updateBodyFor: self currentNode ] { #category : #accessing } GrafoscopioNotebook >> imagesList [ imagesList ifNil: [ ^ #('No images list for this notebook') ]. ^ imagesList ] { #category : #accessing } GrafoscopioNotebook >> imagesList: anObject [ imagesList := anObject ] { #category : #'as yet unclassified' } GrafoscopioNotebook >> importImages [ self imagesList: (Pandoc listImagesFrom: self markdownFile). self inform: 'All notebook images has been imported.', String cr, 'Now you can list and download them.' ] { #category : #operation } GrafoscopioNotebook >> 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 ifNil: [ ^ self ]. nodeContent := currentNode content. nodeContent importPlaygroundLink. nodeContent importHtmlLink. self updateBodyFor: currentNode ] { #category : #initialization } GrafoscopioNotebook >> initialize [ super initialize. self notebook: (GrafoscopioNode new becomeDefaultTree); title: ' New | Grafoscopio notebook'. self notebookContent: self notebook. ] { #category : #initialization } GrafoscopioNotebook >> initializeDefaultTest [ super initialize. self notebook: (GrafoscopioNode new becomeDefaultTestTree); title: ' New test | Grafoscopio notebook'. self notebookContent: self notebook. ] { #category : #initialization } GrafoscopioNotebook >> initializePresenter [ tree whenHighlightedItemChanged: [ :item | tree highlightedItem ifNotNil: [self updateBodyFor: item]]. tree whenTreeUpdated: [ :item | item ifNotNil: [self updateBodyFor: item]]. header whenTextChanged: [ :arg | (tree highlightedItem content header) = arg ifFalse: [ tree highlightedItem content header: arg. tree highlightedItem content updateEditionTimestamp. tree roots: tree roots]]. links whenTextChanged: [ :arg | tree highlightedItem content addLink: arg. tree highlightedItem content updateEditionTimestamp. ] ] { #category : #initialization } GrafoscopioNotebook >> initializeWidgets [ windowMainMenu := self topBar. header := self newTextInput. header autoAccept: true. body := self newText. body class logCr. 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 add: tree; add: header; add: body; add: links. self askOkToClose: true. ] { #category : #persistence } GrafoscopioNotebook >> isSaved [ "I tell if a notebook has been saved in a persistence storage, including last editions." ^ self hasAWorkingFileDefined and: [self isSavedAfterLastEdition ]. ] { #category : #testing } GrafoscopioNotebook >> isSavedAfterLastEdition [ ^ self notebook isSavedAfterLastEdition ] { #category : #accessing } GrafoscopioNotebook >> links [ ^ links ] { #category : #accessing } GrafoscopioNotebook >> links: anObject [ links := anObject ] { #category : #'as yet unclassified' } GrafoscopioNotebook >> linksList [ | currentNode | currentNode := tree highlightedItem content. GrafoscopioLinksList new content: currentNode; openWithSpec ] { #category : #utilities } GrafoscopioNotebook >> listImagesUI [ ListModel new title: 'Images files list'; items: self imagesList ; openWithSpec ] { #category : #persistence } GrafoscopioNotebook >> loadFromFile: aFileReference [ "I load the contents of aFileReference into a GrafoscopioNotebook, without opening it." (aFileReference basename endsWith: 'ston') ifFalse: [ ^ self ]. self workingFile: aFileReference. self notebook: ((STON fromString: self workingFile contents) at: 1) parent. self title: self workingFile basenameWithIndicator, ' | Grafoscopio notebook'. self notebookContent: self notebook. ] { #category : #persistence } GrafoscopioNotebook >> markdownFile [ "I define the location of the markdown file where the notebook will be exported" | markdownFile | markdownFile := (((workingFile parent) / workingFile basenameWithoutExtension) fullName, '.markdown') asFileReference. ^ markdownFile ] { #category : #utilities } GrafoscopioNotebook >> markdownFileChecksum [ self workingFile ifNil: [ ^ self ]. self workingFile contents = '' ifTrue: [ ^ self ]. ^ GrafoscopioUtils checksumFor: self markdownFile ] { #category : #utilities } GrafoscopioNotebook >> markdownFileChecksumUpto: anInteger [ "I cut the markdownFileCheckup upto a given integer. Type coersion is needed, because this message argument can be read from a string in %metadata nodes. Maybe the way used by playgrounds to import text as commands can be useful here." ^ self markdownFileChecksum copyFrom: 1 to: anInteger asInteger. ] { #category : #utilities } GrafoscopioNotebook >> metadata [ ^ self notebook metadata ] { #category : #'editing nodes' } GrafoscopioNotebook >> moveNodeAfter [ | editedNode | editedNode := tree selectedItem content. editedNode moveAfter. self notebookContent: notebook ] { #category : #'editing nodes' } GrafoscopioNotebook >> moveNodeBefore [ | editedNode | editedNode := tree highlightedItem content. editedNode moveBefore. self notebookContent: notebook ] { #category : #utilities } GrafoscopioNotebook >> navigateRelativePathFor: aFileString [ "Given a relative path according to location of the notebook's workingFile, I navigate to that file if exist and create it, including subdirectories if it does not exist. If the relative path is located in a subdirectory that shares the route with the notebooks working file, it must start with the folders name, without using './' to point the same shared root " | finalLocation pathSegments | aFileString ifEmpty: [ ^ self ]. aFileString asUrl host ifNotNil: [ ^self ]. finalLocation := workingFile parent. pathSegments := aFileString splitOn: '/'. pathSegments allButLastDo: [ :segment | (segment = '..') ifTrue: [ finalLocation := finalLocation parent ] ifFalse: [ finalLocation := finalLocation / segment. finalLocation exists ifFalse: [ finalLocation ensureCreateDirectory ]]]. finalLocation := finalLocation / (pathSegments last). finalLocation exists ifFalse: [ finalLocation ensureCreateFile ]. ^ finalLocation ] { #category : #accessing } GrafoscopioNotebook >> notebook [ ^ notebook ] { #category : #accessing } GrafoscopioNotebook >> notebook: anObject [ notebook := anObject ] { #category : #api } GrafoscopioNotebook >> notebookContent: aTree [ | nodeBlock | nodeBlock:= [:gfcNode | |node| node := TreeNodeModel new. node hasChildren: [ gfcNode children isNotEmpty ]; children: [ gfcNode children collect: [:subNode | nodeBlock value: subNode ]]; content: gfcNode]. tree roots: (aTree children collect:[ :gfcNode | nodeBlock value: gfcNode]) ] { #category : #initialization } GrafoscopioNotebook >> notebookSubMenu [ ^ MenuModel new addGroup: [ :group | group addItem: [ :item | item name: 'Save'; icon: (Smalltalk ui icons iconNamed: #smallSave); shortcut: $s command; action: [ self saveWorkingNotebook ] ]. group addItem: [ :item | item name: 'Save as...'; icon: (Smalltalk ui icons iconNamed: #smallSaveAs); action: [ self saveToFileUI ] ]. group addItem: [ :item | item name: 'Import images'; icon: (Smalltalk ui icons iconNamed: #processBrowser); action: [ self importImages ] ]. group addItem: [ :item | item name: 'See images list'; icon: (Smalltalk ui icons iconNamed: #processBrowser); action: [ self listImagesUI ] ]. group addItem: [ :item | item name: 'Download images'; icon: (Smalltalk ui icons iconNamed: #processBrowser); action: [ self downloadImages ] ]. group addItem: [ :item | item name: 'Export as markdown'; icon: (Smalltalk ui icons iconNamed: #smallSaveAs); action: [ self exportAsMarkdown ] ]. group addItem: [ :item | item name: 'Export as html'; icon: (Smalltalk ui icons iconNamed: #smallWindow); action: [ self exportAsHTML ] ]. group addItem: [ :item | item name: 'Export as LaTeX'; icon: (Smalltalk ui icons iconNamed: #smallPrint); action: [ self exportAsLaTeX ] ]. group addItem: [ :item | item name: 'Export as pdf'; icon: (Smalltalk ui icons iconNamed: #smallPrint); action: [ self exportAsPDF ] ]. group addItem: [ :item | item name: 'See html'; icon: (self iconNamed: #smallInspectIt); action: [ self inform: 'To be implemented...' ] ]. group addItem: [ :item | item name: 'See pdf'; icon: (Smalltalk ui icons iconNamed: #smallInspectIt); action: [ self inform: 'To be implemented...' ] ]. group addItem: [ :item | item name: 'Define debug message...'; icon: Smalltalk ui icons glamorousBug; action: [ self defineDebugMessageUI ] ] ] ] { #category : #'event handling' } GrafoscopioNotebook >> okToChange [ self isSaved ifTrue: [ ^ true ] ifFalse: [ ^ self askToSaveBeforeClosing ] ] { #category : #persistence } GrafoscopioNotebook >> openDefault [ "I open a new default notebook" ^ self class new openWithSpec. ] { #category : #persistence } GrafoscopioNotebook >> openFromFile: aFileReference [ self loadFromFile: aFileReference. ^ self openWithSpec. ] { #category : #persistence } GrafoscopioNotebook >> openFromFileSelector [ | file nb | file := UIManager default chooseExistingFileReference:'Choose a file' extensions: #('ston') path: FileLocator documents. file ifNil: [ self inform: 'No file selected'. ^ self ]. self workingFile: file. nb := self class new. nb openFromFile: self workingFile. GfUIHelpers updateRecentNotebooksWith: workingFile ] { #category : #persistence } GrafoscopioNotebook >> openFromUrl: url [ "Opens a tree from a file named aFileName" | fileName sanitized | sanitized := GrafoscopioUtils sanitize: url. fileName := sanitized segments last. GrafoscopioUtils downloadingFrom: sanitized withMessage: 'Downloading document...' into: FileLocator temp. self class new openFromFile: (FileLocator temp / fileName) ] { #category : #persistence } GrafoscopioNotebook >> openFromUrlUI [ "This method generates the UI for the openFromUrl: method, it asks for a URL from the user" | fileUrl | "GrafoscopioBrowser configureSettings." fileUrl := UIManager default textEntry: 'Enter the URL' title: 'Open notebook from URL'. fileUrl isNil ifTrue: [ ^nil ]. self class new openFromUrl: fileUrl ] { #category : #utilities } GrafoscopioNotebook >> pandocOptions [ ^ self notebook pandocOptions ] { #category : #utilities } GrafoscopioNotebook >> pandocOptionsComputed [ "I convert the pandoc options array into a single line that can be used with the pandoc command." | result | result := '' writeStream. self pandocOptions ifNil: [ ^ '' ]. self pandocOptions do: [ :option | option isDictionary ifTrue: [ self addCommandFrom: option into: result ] ifFalse: [ result nextPutAll: option] ]. ^ result contents ] { #category : #'editing nodes' } GrafoscopioNotebook >> pasteNodeFromClipboard [ tree highlightedItem content pasteFromClipboard. self notebookContent: notebook. ] { #category : #persistence } GrafoscopioNotebook >> pdfFile [ "I define the location of the markdown file where the notebook will be exported" | pdfFile | pdfFile := (self markdownFile parent fullName,'/', self markdownFile basenameWithoutExtension, '.pdf') asFileReference. ^ pdfFile. ] { #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: (self iconNamed: #userIcon); action: [ self inform: 'To be implemented ...' ] ] ] ] { #category : #'editing nodes' } GrafoscopioNotebook >> promoteNode [ | editedNote | editedNote := tree selectedItem content. editedNote promote. self notebookContent: notebook ] { #category : #'editing nodes' } GrafoscopioNotebook >> removeNode [ | contentToDelete parentContent newSelectedContent children | contentToDelete := tree selectedItem content. parentContent := contentToDelete parent. children := parentContent children. children size > 1 ifTrue: [ children last = contentToDelete ifTrue: [ newSelectedContent := children at: (children size - 1) ] ] ifFalse: [ newSelectedContent := parentContent ]. contentToDelete parent removeNode: contentToDelete. self notebookContent: notebook ] { #category : #persistence } GrafoscopioNotebook >> saveToFile: aFileReference [ "I save the current tree/document to a file and update storage timestamp." aFileReference ifNil: [ self inform: 'No file selected for saving. Save NOT done.'. ^ self ]. workingFile := aFileReference. self workingFile ensureDelete. self workingFile writeStreamDo: [:stream | self exportAsSton: self notebook on: stream ]. self title: self workingFile basenameWithIndicator, ' | Grafoscopio notebook'. self inform: ('File saved at: ', String cr, self workingFile fullName). GfUIHelpers updateRecentNotebooksWith: aFileReference. ] { #category : #persistence } GrafoscopioNotebook >> saveToFileUI [ | file | file := UIManager default chooseForSaveFileReference: 'Save notebook to file as...' extensions: #('ston') path: (workingFile ifNotNil: [ workingFile parent ] ifNil: [ FileLocator documents ] ). file ifNil: [ self inform: 'Saving to file 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 ]. self notebook root updateEditionTimestamp. GfUIHelpers updateRecentNotebooksWith: workingFile ] { #category : #persistence } GrafoscopioNotebook >> subtreeAsMarkdown [ | currentNode | currentNode := tree highlightedItem content. self inform: ('Exported as: ', String cr, (self subtreeAsMarkdownFileFor: currentNode) fullName ) ] { #category : #persistence } GrafoscopioNotebook >> subtreeAsMarkdownFileFor: aNode [ | exportedFile | aNode links ifEmpty: [ ^ self ]. exportedFile:= self navigateRelativePathFor: aNode links last. exportedFile class = self class ifTrue: [ ^ self ]. self exportNode: aNode asMarkdownIn: exportedFile. ^ exportedFile ] { #category : #'editing nodes' } GrafoscopioNotebook >> toggleCodeNode [ | currentNode | currentNode := tree highlightedItem. currentNode content toggleCodeText. self updateBodyFor: currentNode. ] { #category : #initialization } GrafoscopioNotebook >> topBar [ ^ MenuModel new addGroup: [ :group | group addItem: [ :item | item name: 'Notebook'; icon: (self iconNamed: #smallObjects); subMenu: self notebookSubMenu ]. group addItem: [ :item | item name: 'Project'; icon: (self iconNamed: #catalog); subMenu: self projectSubMenu ] ]; addGroup: [ :group | group addItem: [ :item | item name: nil; description: 'Save notebook'; icon: (self iconNamed: #glamorousSave); action: [ self saveWorkingNotebook ] ]. group addItem: [ :item | item name: nil; description: 'Export all Markdown subtrees'; icon: (self iconNamed: #glamorousMore); action: [ self exportAllSubtreesAsMarkup ] ]. group addItem: [ :item | item name: nil; description: 'Cut'; icon: (self iconNamed: #smallCut); action: [ self cutNodeToClipboard ] ]. group addItem: [ :item | item name: nil; description: 'Copy'; icon: (self iconNamed: #smallCopy); action: [ self copyNodeToClipboard ] ]. group addItem: [ :item | item name: nil; description: 'Paste'; icon: (self iconNamed: #smallPaste); action: [ self pasteNodeFromClipboard ] ]. group addItem: [ :item | item name: nil; description: 'Find & Replace'; icon: (self iconNamed: #smallFind); action: [ self findAndReplace ] ] ]; addGroup: [ :group | group addItem: [ :item | item name: nil; description: 'Add node'; 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 node up'; icon: MendaIcons new arrowUpIcon; action: [ self moveNodeBefore ] ]. group addItem: [ :item | item name: nil; description: 'Move node down'; 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: 'Toggle: code <--> text'; icon: MendaIcons new smalltalkCodeIcon; action: [ self toggleCodeNode ] ]. group addItem: [ :item | item name: nil; description: 'List node links'; icon: (self iconNamed: #tinyMenu); action: [ self linksList ] ]. group addItem: [ :item | item name: nil; description: 'Visit link'; icon: (self iconNamed: #glamorousRight); action: [ self visitNodeLink ] ]. group addItem: [ :item | item name: nil; description: 'Import link content'; icon: (self iconNamed: #glamorousOpenFromUrl); action: [ self importLinkContent ] ]. group addItem: [ :item | item name: nil; description: 'Export link content'; icon: (self iconNamed: #glamorousSaveToUrl); action: [ self exportLinkContent ] ]. group addItem: [ :item | item name: nil; description: 'HTML to Markdown'; icon: (self iconNamed: #smallProfile); action: [ self htmlToMarkdown ] ]. group addItem: [ :item | item name: nil; description: 'HTML to Markdown subtree'; icon: (self iconNamed: #hierarchy); action: [ self htmlToMarkdownSubtree ] ]. 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...' ] ] ]; addGroup: [ :debug | debug addItem: [ :item | item name: nil; description: 'Debug'; icon: (self iconNamed: #glamorousBug); action: [ self debugWithSelector: self debugMessage ] ] ] ] { #category : #accessing } GrafoscopioNotebook >> tree [ ^ tree ] { #category : #accessing } GrafoscopioNotebook >> tree: anObject [ tree := anObject ] { #category : #operation } GrafoscopioNotebook >> updateBodyFor: aNodeContainer [ | aNode | self needRebuild: false. tree needRebuild: false. body needRebuild: true. aNode := aNodeContainer content. aNode toggleSelected. header text: aNode header. body := self instantiate: aNode specModelClass new. body content: aNode body. links text: aNode lastLink. self autoSaveBodyOf: aNode. self buildWithSpecLayout: self class defaultSpec ] { #category : #operation } GrafoscopioNotebook >> visitNodeLink [ tree highlightedItem content visitLastLink. ] { #category : #accessing } GrafoscopioNotebook >> windowMainMenu [ ^ windowMainMenu ] { #category : #accessing } GrafoscopioNotebook >> windowMainMenu: anObject [ windowMainMenu := anObject ] { #category : #accessing } GrafoscopioNotebook >> workingFile [ ^ workingFile ] { #category : #accessing } GrafoscopioNotebook >> workingFile: aFileReference [ workingFile := aFileReference. ] { #category : #'as yet unclassified' } GrafoscopioNotebook >> wrapBodyLines [ self currentNodeContent wrapBodyLines. self updateBodyFor: self currentNode ]