New GUI: Preliminary presistence support.

This commit is contained in:
Offray Vladimir Luna Cárdenas 2016-05-26 17:01:26 +00:00
parent 4ee483c541
commit d756846b86
3 changed files with 97 additions and 12 deletions

View File

@ -818,7 +818,7 @@ GrafoscopioBrowser >> openFromFile: aFileName [
GrafoscopioBrowser >> openFromFileSelector [
"Opens a tree from a file by using the file selector GUI."
"REFACTORING NOTES: This sould call openFromFile, instead of having the code repeated here.
This creates errors on debugging and worse on proper behaviour"
This creates errors on debugging and worse on proper behavior"
| fileStream currentChildren |
"GrafoscopioBrowser configureSettings."
fileStream := UITheme builder

View File

@ -17,6 +17,12 @@ Class {
'headerRefreshProcess',
'selected'
],
#classVars : [
'dockingBar'
],
#classInstVars : [
'dockingBar'
],
#category : #'Grafoscopio-UI'
}
@ -46,6 +52,16 @@ GrafoscopioGUI class >> defaultSpec [
yourself
]
{ #category : #accessing }
GrafoscopioGUI class >> dockingBar [
^ dockingBar
]
{ #category : #accessing }
GrafoscopioGUI class >> dockingBar: anObject [
dockingBar := anObject
]
{ #category : #examples }
GrafoscopioGUI class >> exampleBootstrapDynamicUI1 [
"Starting from an example UI from the Spec-Glamour, to customize towards the grafoscopio
@ -238,7 +254,7 @@ GrafoscopioGUI class >> startDockingBar [
launchMenu := MenuMorph new.
launchMenu
add: 'New notebook' target: self selector: #open;
add: 'Notebook from file...' target: (self new) selector: #openFromFileSelector;
add: 'Notebook from file...' target: (GrafoscopioNotebook new) selector: #openFromFileSelector;
add: 'Notebook from Internet...' target: (self new) selector: #openFromUrlUI;
add: 'Recent notebooks...' target: self selector: #openFromRecentlyUsed;
add: 'Example notebooks...' target: self selector: #messageNotImplementedYet;
@ -274,6 +290,18 @@ GrafoscopioGUI class >> startDockingBar [
openInWorld.
]
{ #category : #'graphical interface' }
GrafoscopioGUI class >> updateUI [
"I update the User Interface (UI) with new versions of the docking bar or logos where available.
I'm helpful while testing new functionality that should be expossed to the user via the UI"
self dockingBar
ifNil: [^ self ]
ifNotNil: [
self dockingBar delete.
self startDockingBar]
]
{ #category : #initialization }
GrafoscopioGUI >> initializePresenter [
tree.

View File

@ -16,7 +16,8 @@ Class {
'header',
'body',
'windowMainMenu',
'workingFile'
'workingFile',
'notebook'
],
#category : #'Grafoscopio-UI'
}
@ -72,6 +73,19 @@ GrafoscopioNotebook >> changeBody: aNodeCollection [
]
{ #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
@ -136,7 +150,7 @@ GrafoscopioNotebook >> newWindowMainMenu [
name: nil;
description: 'Save notebook';
icon: Smalltalk ui icons smallSaveIcon;
action: [ self inform: 'To be implemented...' ] ].
action: [ self saveWorkingNotebook ] ].
group addItem: [ :item |
item
name: nil;
@ -213,6 +227,16 @@ GrafoscopioNotebook >> newWindowMainMenu [
action: [ self inform: 'To be implemented...' ] ]].
]
{ #category : #accessing }
GrafoscopioNotebook >> notebook [
^ notebook
]
{ #category : #accessing }
GrafoscopioNotebook >> notebook: anObject [
notebook := anObject
]
{ #category : #api }
GrafoscopioNotebook >> notebookContent: aTree [
@ -230,7 +254,7 @@ GrafoscopioNotebook >> notebookSubMenu [
name: 'Save';
icon: Smalltalk ui icons smallSaveIcon;
shortcut: $s command;
action: [ self inform: 'To be implemented...' ] ].
action: [ self saveWorkingNotebook ] ].
group addItem: [ :item |
item
name: 'Save as...';
@ -261,15 +285,27 @@ GrafoscopioNotebook >> notebookSubMenu [
{ #category : #persistence }
GrafoscopioNotebook >> openFromFile: aFileName [
"I open a notebook from a file named aFileName containing a grafoscopio tree"
| root nb |
workingFile := aFileName.
root := ((STON fromString: aFileName contents) at: 1) parent.
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 title: aFileName basenameWithIndicator, ' | Grafoscopio notebook'.
nb notebookContent: root.
^ nb openWithSpec.
nb openFromFile: self workingFile.
]
{ #category : #initialization }
@ -310,6 +346,17 @@ GrafoscopioNotebook >> projectSubMenu [
]
{ #category : #persistence }
GrafoscopioNotebook >> saveWorkingNotebook [
"Saves the current tree to the user predefined file location used when he/she opened it."
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 inform: ('File saved at: ', String cr, self workingFile fullName).
]
{ #category : #accessing }
GrafoscopioNotebook >> tree [
^ tree
@ -329,3 +376,13 @@ GrafoscopioNotebook >> windowMainMenu [
GrafoscopioNotebook >> windowMainMenu: anObject [
windowMainMenu := anObject
]
{ #category : #accessing }
GrafoscopioNotebook >> workingFile [
^ workingFile
]
{ #category : #accessing }
GrafoscopioNotebook >> workingFile: aFile [
workingFile := aFile.
]