From 07828dce744213481e4111224bfc24c33cf6daef Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Mon, 30 Mar 2015 12:25:01 +0000 Subject: [PATCH] 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. --- .../Grafoscopio/GrafoscopioBrowser.class.st | 46 ++++++++++++------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/repository/Grafoscopio/GrafoscopioBrowser.class.st b/repository/Grafoscopio/GrafoscopioBrowser.class.st index e30a6a0..94413c0 100644 --- a/repository/Grafoscopio/GrafoscopioBrowser.class.st +++ b/repository/Grafoscopio/GrafoscopioBrowser.class.st @@ -400,7 +400,7 @@ GrafoscopioBrowser >> body2ForTransmediaIn: constructor for: aNode [ { #category : #'graphical interface' } 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" | innerBrowser | @@ -811,7 +811,7 @@ GrafoscopioBrowser >> messageNotImplementedYet [ title: 'No implementado aún'. ] -{ #category : #'graphical interface' } +{ #category : #persistence } GrafoscopioBrowser >> open [ "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" @@ -820,8 +820,7 @@ GrafoscopioBrowser >> open [ mainTree := GrafoscopioNode new. mainTree becomeDefaultTree. workingFile := draftsLocation / 'draft.ston'. - self buildBrowserNamed: workingFile basenameWithIndicator. - browser openOn: mainTree children. + self openFromFile: workingFile. ] @@ -832,7 +831,10 @@ GrafoscopioBrowser >> openDefault [ self buildBrowser. mainTree := GrafoscopioNode new. 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 | GrafoscopioBrowser configureSettings. - workingFile := aFileName name asFileReference. + workingFile := aFileName. currentChildren := (STON fromString: aFileName contents). self buildBrowserNamed: aFileName basenameWithIndicator. mainTree := GrafoscopioNode new @@ -1115,16 +1117,12 @@ GrafoscopioBrowser >> repositoryCredentials [ ] { #category : #persistence } -GrafoscopioBrowser >> saveToFile [ - "Saves the current tree to a file" +GrafoscopioBrowser >> saveToFile: aFileReference [ + "Saves the current tree/document to a file" | file writeStream markdownFile | - file := UITheme builder - fileSave: 'Guardar archivo como...' - extensions: #('ston') - path: nil. - + file := aFileReference. file ifNil: [ self inform: 'Exportación cancelada'. ^ self ]. writeStream := file writeStream. @@ -1133,11 +1131,25 @@ GrafoscopioBrowser >> saveToFile [ [ self exportAsSton: mainTree on: writeStream. self exportAsMarkdown: mainTree on: markdownFile ] ensure: [ writeStream ifNotNil: #close ]. - recentTrees isNil 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. ] @@ -1245,7 +1257,7 @@ GrafoscopioBrowser >> treeOn: constructor [ =============" "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; exportAsPdf] entitled: 'Exportar como PDF (requiere LaTeX)' categorized: 'Arbol'; act: [self messageNotImplementedYet] entitled: 'Ver HTML' categorized: 'Arbol';