Improved open and saving from files, for a more modular approach and consistent behaviour. This solves a bug with saving when the file was opened from the "recent documents" in the launch menu.

This commit is contained in:
Offray Vladimir Luna Cárdenas 2015-03-30 12:25:01 +00:00
parent 0817d2d484
commit 07828dce74

View File

@ -400,7 +400,7 @@ GrafoscopioBrowser >> body2ForTransmediaIn: constructor for: aNode [
{ #category : #'graphical interface' } { #category : #'graphical interface' }
GrafoscopioBrowser >> bodyForCodeIn: constructor for: aNode [ GrafoscopioBrowser >> bodyForCodeIn: constructor for: aNode [
"Shows the body of a node as an interactive playground. If node is not tagged it will return itself, "Shows the body of a node as an interactive playground. If node is not tagged it will return itself,
so it can be rendered properly for other messages" so it can be rendered properly for other messages"
| innerBrowser | | innerBrowser |
@ -811,7 +811,7 @@ GrafoscopioBrowser >> messageNotImplementedYet [
title: 'No implementado aún'. title: 'No implementado aún'.
] ]
{ #category : #'graphical interface' } { #category : #persistence }
GrafoscopioBrowser >> open [ GrafoscopioBrowser >> open [
"Opens a new browser with a default tree and assigns a default draft file for storing it. "Opens a new browser with a default tree and assigns a default draft file for storing it.
This is changed when the file is saved with the 'Save as' menu option" This is changed when the file is saved with the 'Save as' menu option"
@ -820,8 +820,7 @@ GrafoscopioBrowser >> open [
mainTree := GrafoscopioNode new. mainTree := GrafoscopioNode new.
mainTree becomeDefaultTree. mainTree becomeDefaultTree.
workingFile := draftsLocation / 'draft.ston'. workingFile := draftsLocation / 'draft.ston'.
self buildBrowserNamed: workingFile basenameWithIndicator. self openFromFile: workingFile.
browser openOn: mainTree children.
] ]
@ -832,7 +831,10 @@ GrafoscopioBrowser >> openDefault [
self buildBrowser. self buildBrowser.
mainTree := GrafoscopioNode new. mainTree := GrafoscopioNode new.
mainTree becomeDefaultTree. mainTree becomeDefaultTree.
browser openOn: mainTree children. workingFile := draftsLocation / 'draft.ston'.
self saveToFile: workingFile.
self openFromFile: workingFile.
" browser openOn: mainTree children."
] ]
@ -843,7 +845,7 @@ GrafoscopioBrowser >> openFromFile: aFileName [
| currentChildren | | currentChildren |
GrafoscopioBrowser configureSettings. GrafoscopioBrowser configureSettings.
workingFile := aFileName name asFileReference. workingFile := aFileName.
currentChildren := (STON fromString: aFileName contents). currentChildren := (STON fromString: aFileName contents).
self buildBrowserNamed: aFileName basenameWithIndicator. self buildBrowserNamed: aFileName basenameWithIndicator.
mainTree := GrafoscopioNode new mainTree := GrafoscopioNode new
@ -1115,16 +1117,12 @@ GrafoscopioBrowser >> repositoryCredentials [
] ]
{ #category : #persistence } { #category : #persistence }
GrafoscopioBrowser >> saveToFile [ GrafoscopioBrowser >> saveToFile: aFileReference [
"Saves the current tree to a file" "Saves the current tree/document to a file"
| file writeStream markdownFile | | file writeStream markdownFile |
file := UITheme builder file := aFileReference.
fileSave: 'Guardar archivo como...'
extensions: #('ston')
path: nil.
file ifNil: [ self inform: 'Exportación cancelada'. ^ self ]. file ifNil: [ self inform: 'Exportación cancelada'. ^ self ].
writeStream := file writeStream. writeStream := file writeStream.
@ -1133,11 +1131,25 @@ GrafoscopioBrowser >> saveToFile [
[ self exportAsSton: mainTree on: writeStream. [ self exportAsSton: mainTree on: writeStream.
self exportAsMarkdown: mainTree on: markdownFile ] self exportAsMarkdown: mainTree on: markdownFile ]
ensure: [ writeStream ifNotNil: #close ]. ensure: [ writeStream ifNotNil: #close ].
recentTrees isNil recentTrees isNil
ifTrue:[recentTrees := OrderedCollection new]. ifTrue:[recentTrees := OrderedCollection new].
recentTrees add: workingFile. recentTrees add: workingFile.
browser update.
]
{ #category : #persistence }
GrafoscopioBrowser >> saveToFileUI [
"Saves the current tree to a file"
| file |
file := UITheme builder
fileSave: 'Guardar archivo como...'
extensions: #('ston')
path: nil.
file
ifNil: [ self inform: 'Exportación cancelada'. ^ self ]
ifNotNilDo:[self saveToFile: file].
browser update. browser update.
] ]
@ -1245,7 +1257,7 @@ GrafoscopioBrowser >> treeOn: constructor [
=============" ============="
"For trees" "For trees"
act: [self saveToFile] entitled: 'Guardar como ...' categorized: 'Arbol'; act: [self saveToFileUI] entitled: 'Guardar como ...' categorized: 'Arbol';
act: [self saveWorkingTree; exportAsHtml] entitled: 'Exportar como HTML' categorized: 'Arbol'; act: [self saveWorkingTree; exportAsHtml] entitled: 'Exportar como HTML' categorized: 'Arbol';
act: [self saveWorkingTree; exportAsPdf] entitled: 'Exportar como PDF (requiere LaTeX)' categorized: 'Arbol'; act: [self saveWorkingTree; exportAsPdf] entitled: 'Exportar como PDF (requiere LaTeX)' categorized: 'Arbol';
act: [self messageNotImplementedYet] entitled: 'Ver HTML' categorized: 'Arbol'; act: [self messageNotImplementedYet] entitled: 'Ver HTML' categorized: 'Arbol';