431 lines
13 KiB
Smalltalk
431 lines
13 KiB
Smalltalk
|
"
|
||
|
An UbakyeExplorer is a graphical interface for showing trees and outlines.
|
||
|
|
||
|
Instance Variables
|
||
|
browser: <Object>
|
||
|
|
||
|
browser
|
||
|
- xxxxx
|
||
|
|
||
|
"
|
||
|
Class {
|
||
|
#name : #GrafoscopioBrowser,
|
||
|
#superclass : #Object,
|
||
|
#instVars : [
|
||
|
'browser',
|
||
|
'explorer',
|
||
|
'mainTree',
|
||
|
'workingFile'
|
||
|
],
|
||
|
#classVars : [
|
||
|
'DefaultUbakyeBrowser'
|
||
|
],
|
||
|
#category : #'Grafoscopio-UI'
|
||
|
}
|
||
|
|
||
|
{ #category : #'as yet unclassified' }
|
||
|
GrafoscopioBrowser class >> open [
|
||
|
^ self new open
|
||
|
]
|
||
|
|
||
|
{ #category : #'as yet unclassified' }
|
||
|
GrafoscopioBrowser class >> openLandscape [
|
||
|
^ self new openLandscape
|
||
|
]
|
||
|
|
||
|
{ #category : #'graphical interface' }
|
||
|
GrafoscopioBrowser >> bodyOn: constructor [
|
||
|
"Shows the body of a selected node"
|
||
|
|
||
|
(constructor text)
|
||
|
title: 'Cuerpo | Body ';
|
||
|
format:[:eachNode |
|
||
|
(eachNode body) isNil
|
||
|
ifTrue: [ '' ]
|
||
|
ifFalse: [ eachNode body]].
|
||
|
]
|
||
|
|
||
|
{ #category : #'graphical interface' }
|
||
|
GrafoscopioBrowser >> buildBrowser [
|
||
|
"Main method for building the interface for trees. Is getting long. Needs refactoring"
|
||
|
|
||
|
browser := GLMTabulator new
|
||
|
title: 'Grafoscopio'.
|
||
|
|
||
|
browser
|
||
|
column: #tree span: 2;
|
||
|
column: [ :c |
|
||
|
c row: #nodeBody span: 2;
|
||
|
row: #nodeHeader ] span: 4.
|
||
|
browser
|
||
|
updateOn: GLMItemAdded from: #yourself;
|
||
|
updateOn: GLMItemRemoved from: #yourself.
|
||
|
|
||
|
(browser transmit)
|
||
|
to: #tree;
|
||
|
andShow: [:a | self treeOn: a].
|
||
|
"Creating a self updatable body pane"
|
||
|
(browser transmit)
|
||
|
to: #nodeBody;
|
||
|
from: #tree;
|
||
|
andShow: [ :a | self bodyOn: a].
|
||
|
(browser transmit )
|
||
|
from: #tree port: #selection;
|
||
|
from: #nodeBody port: #text;
|
||
|
when: [:node :text | text notNil];
|
||
|
to: #nodeBody port: #neverland;
|
||
|
transformed: [:node :text | node body: text asString].
|
||
|
(browser transmit)
|
||
|
from: #tree;
|
||
|
to: #nodeHeader;
|
||
|
andShow: [ :h | self headerOn: h ].
|
||
|
(browser transmit )
|
||
|
from: #tree port: #selection;
|
||
|
from: #nodeHeader port: #text;
|
||
|
when: [:node :text | text notNil];
|
||
|
to: #nodeHeader port: #neverland1;
|
||
|
transformed: [:node :text | node header: text asString]
|
||
|
]
|
||
|
|
||
|
{ #category : #'graphical interface' }
|
||
|
GrafoscopioBrowser >> buildBrowserLandscape [
|
||
|
|
||
|
browser := GLMTabulator new
|
||
|
title: 'Grafoscopio'.
|
||
|
browser
|
||
|
column: #tree span: 3;
|
||
|
column: #body span: 3;
|
||
|
column: #code span: 3.
|
||
|
browser
|
||
|
updateOn: GLMItemAdded from: #yourself;
|
||
|
updateOn: GLMItemRemoved from: #yourself.
|
||
|
|
||
|
(browser transmit)
|
||
|
to: #tree;
|
||
|
andShow: [ :a |
|
||
|
(a tree) "Layout"
|
||
|
title: mainTree header;
|
||
|
children: [ :eachNode |
|
||
|
(eachNode children) isNil
|
||
|
ifTrue: [ #() ]
|
||
|
ifFalse:[ eachNode children ] ];
|
||
|
format:[:eachNode |
|
||
|
(eachNode header) isNil
|
||
|
ifTrue: [ '' ]
|
||
|
ifFalse: [ eachNode header ]];
|
||
|
"Adding nodes"
|
||
|
act: [:treePresentation |
|
||
|
(treePresentation selection) isNotNil
|
||
|
ifTrue: [treePresentation selection addNodeAfter].
|
||
|
treePresentation update]
|
||
|
icon: GLMUIThemeExtraIcons glamorousZoomIn
|
||
|
entitled: 'Add node';
|
||
|
"Removing nodes"
|
||
|
act: [:treePresentation |
|
||
|
(treePresentation selection isNotNil)
|
||
|
ifTrue: [(treePresentation selection parent)
|
||
|
removeNode: treePresentation selection]
|
||
|
ifFalse: [treePresentation entity removeLast].
|
||
|
treePresentation update]
|
||
|
icon: GLMUIThemeExtraIcons glamorousZoomOut
|
||
|
entitled: 'Remove node';
|
||
|
"Inspecting nodes, for debugging purposes, DISABLE THIS ON PRODUCTION"
|
||
|
act: [:treePresentation | treePresentation selection inspect ]
|
||
|
icon: GLMUIThemeExtraIcons glamorousInspect
|
||
|
entitled: 'Inspect selection';
|
||
|
"Move nodes in the same hierarchy"
|
||
|
act: [:treePresentation |
|
||
|
(treePresentation selection isNotNil)
|
||
|
ifTrue: [treePresentation selection moveBefore].
|
||
|
treePresentation update]
|
||
|
icon: GLMUIThemeExtraIcons glamorousUp
|
||
|
entitled: 'Move node up';
|
||
|
act: [:treePresentation |
|
||
|
(treePresentation selection isNotNil)
|
||
|
ifTrue: [treePresentation selection moveAfter].
|
||
|
treePresentation update]
|
||
|
icon: GLMUIThemeExtraIcons glamorousDown
|
||
|
entitled: 'Move node down';
|
||
|
act: [:treePresentation |
|
||
|
(treePresentation selection isNotNil)
|
||
|
ifTrue: [treePresentation selection promote].
|
||
|
treePresentation update]
|
||
|
icon: GLMUIThemeExtraIcons glamorousLeft
|
||
|
entitled: 'Move node left';
|
||
|
act: [:treePresentation |
|
||
|
(treePresentation selection isNotNil)
|
||
|
ifTrue: [treePresentation selection demote].
|
||
|
treePresentation update]
|
||
|
icon: GLMUIThemeExtraIcons glamorousRight
|
||
|
entitled: 'Move node left'.
|
||
|
].
|
||
|
(browser transmit)
|
||
|
to: #body;
|
||
|
from: #tree;
|
||
|
andShow: [ :a |
|
||
|
(a text)
|
||
|
title: 'Original';
|
||
|
format:[:eachNode |
|
||
|
(eachNode body) isNil
|
||
|
ifTrue: [ '' ]
|
||
|
ifFalse: [ eachNode body ]]].
|
||
|
(browser transmit)
|
||
|
to: #code;
|
||
|
andShow: [ :a |
|
||
|
a smalltalkCode
|
||
|
title: 'Transmediado';
|
||
|
populate: #acceptedCode
|
||
|
icon: GLMUIThemeExtraIcons glamorousAccept
|
||
|
on: $s entitled: 'Accept' with: [:text | text text ]].
|
||
|
]
|
||
|
|
||
|
{ #category : #bibliography }
|
||
|
GrafoscopioBrowser >> customKeys [
|
||
|
"Replaces the default key in a BibTeX file for a custom key taken from the 'shorttitle' field.
|
||
|
Useful when autogenerated BibTeX has cryptic or non easy to memorize keys (for example in some
|
||
|
Zotero exports)"
|
||
|
| bibFile bibliography |
|
||
|
bibFile := ((workingFile parent) children
|
||
|
detect: [:each | each basename endsWith: 'bib' ] ifNone: [ ]).
|
||
|
bibFile ifNotNil:
|
||
|
[ bibliography := CZBibParser parse: (bibFile contents).
|
||
|
1 to: (bibliography size) do: [:index |
|
||
|
(((bibliography entries at: index) fields at: 2) key = 'shorttitle')
|
||
|
ifTrue: [
|
||
|
(bibliography entries at: index)
|
||
|
key: ((bibliography entries at: index) fields at: 2) value ]]].
|
||
|
]
|
||
|
|
||
|
{ #category : #persistence }
|
||
|
GrafoscopioBrowser >> exportAsMarkdown: aTree on: locator [
|
||
|
|
||
|
locator writeStreamDo: [:stream | stream nextPutAll: aTree asMarkdown]
|
||
|
|
||
|
]
|
||
|
|
||
|
{ #category : #persistence }
|
||
|
GrafoscopioBrowser >> exportAsSton: aTree on: locator [
|
||
|
|
||
|
locator nextPutAll: (STON toStringPretty: aTree children)
|
||
|
]
|
||
|
|
||
|
{ #category : #'graphical interface' }
|
||
|
GrafoscopioBrowser >> headerOn: constructor [
|
||
|
"Shows the body of a selected node"
|
||
|
|
||
|
(constructor text)
|
||
|
title: 'Cabecera | Header ';
|
||
|
format:[:eachNode |
|
||
|
(eachNode header) isNil
|
||
|
ifTrue: [ '' ]
|
||
|
ifFalse: [ eachNode header]].
|
||
|
]
|
||
|
|
||
|
{ #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"
|
||
|
| draftsLocation |
|
||
|
self buildBrowser.
|
||
|
mainTree := GrafoscopioNode new.
|
||
|
mainTree becomeDefaultTree.
|
||
|
draftsLocation := FileSystem disk workingDirectory / 'Grafoscopio/Drafts'.
|
||
|
draftsLocation ensureCreateDirectory.
|
||
|
workingFile := draftsLocation / 'draft.ston'.
|
||
|
browser openOn: mainTree children.
|
||
|
|
||
|
]
|
||
|
|
||
|
{ #category : #persistence }
|
||
|
GrafoscopioBrowser >> openDefault [
|
||
|
"Opens a new browser with a default tree"
|
||
|
self buildBrowser.
|
||
|
mainTree := GrafoscopioNode new.
|
||
|
mainTree becomeDefaultTree.
|
||
|
browser openOn: mainTree children.
|
||
|
|
||
|
]
|
||
|
|
||
|
{ #category : #persistence }
|
||
|
GrafoscopioBrowser >> openFromFile [
|
||
|
"Opens a tree from a file. Maybe this should be integrated with the 'open' method"
|
||
|
|
||
|
| fileStream currentChildren |
|
||
|
|
||
|
self buildBrowser.
|
||
|
fileStream := UITheme builder
|
||
|
fileOpen: 'Elija un archivo .ston'
|
||
|
extensions: #('ston').
|
||
|
|
||
|
fileStream isNil ifTrue: [ ^nil ].
|
||
|
workingFile := fileStream name asFileReference.
|
||
|
currentChildren := (STON fromStream: fileStream).
|
||
|
mainTree := GrafoscopioNode new
|
||
|
header: 'Bootstrapping the research object';
|
||
|
level: 0.
|
||
|
mainTree children: currentChildren.
|
||
|
browser openOn: mainTree children.
|
||
|
]
|
||
|
|
||
|
{ #category : #'as yet unclassified' }
|
||
|
GrafoscopioBrowser >> openLandscape [
|
||
|
"Opens a new browser with a default tree in landscape mode"
|
||
|
self buildBrowserLandscape.
|
||
|
mainTree := GrafoscopioNode new.
|
||
|
mainTree becomeDefaultTree.
|
||
|
browser openOn: mainTree children.
|
||
|
|
||
|
]
|
||
|
|
||
|
{ #category : #persistence }
|
||
|
GrafoscopioBrowser >> openLast [
|
||
|
"Opens a new browser with a fixed 'last' working tree. May be this should be changed"
|
||
|
| workingFile currentChildren| "workingChildren would sound too cruel!"
|
||
|
self buildBrowser.
|
||
|
workingFile := '/home/offray/Documentos/U/Libertadores/Grafoscopio/bootstrapping-objeto-investigacion.ston' asFileReference readStream.
|
||
|
currentChildren := (STON fromStream: workingFile).
|
||
|
mainTree := GrafoscopioNode new
|
||
|
header: 'Bootstrapping the research object';
|
||
|
level: 0.
|
||
|
mainTree children: currentChildren.
|
||
|
browser openOn: mainTree children.
|
||
|
|
||
|
]
|
||
|
|
||
|
{ #category : #persistence }
|
||
|
GrafoscopioBrowser >> openWorking [
|
||
|
"Opens a new browser with the last working tree"
|
||
|
self buildBrowser.
|
||
|
mainTree := '/home/offray/Documentos/U/Libertadores/Grafoscopio/bootstrapping-objeto-investigacion.ston' asFileReference readStream.
|
||
|
browser openOn: mainTree children.
|
||
|
|
||
|
]
|
||
|
|
||
|
{ #category : #persistence }
|
||
|
GrafoscopioBrowser >> saveToFile [
|
||
|
"Saves the current tree to a file"
|
||
|
|
||
|
| file writeStream |
|
||
|
|
||
|
file := UITheme builder
|
||
|
fileSave: 'Guardar archivo como...'
|
||
|
extensions: #('ston')
|
||
|
path: nil.
|
||
|
|
||
|
file ifNil: [ self inform: 'Exportación cancelada'. ^ self ].
|
||
|
|
||
|
writeStream := file writeStream.
|
||
|
workingFile := writeStream name asFileReference.
|
||
|
[ self exportAsSton: mainTree on: writeStream ]
|
||
|
ensure: [ writeStream ifNotNil: #close ]
|
||
|
]
|
||
|
|
||
|
{ #category : #persistence }
|
||
|
GrafoscopioBrowser >> saveWorkingTree [
|
||
|
"Saves the current tree to the user predefined file location used when he/she opened it."
|
||
|
|
||
|
| fileStream markdownFile |
|
||
|
|
||
|
|
||
|
fileStream := workingFile writeStream.
|
||
|
markdownFile := (workingFile parent) / (workingFile basenameWithoutExtension, '.markdown').
|
||
|
[ self exportAsSton: mainTree on: fileStream.
|
||
|
self exportAsMarkdown: mainTree on: markdownFile ]
|
||
|
ensure: [ fileStream ifNotNil: #close.].
|
||
|
self customKeys.
|
||
|
self inform: 'Archivo Guardado'.
|
||
|
]
|
||
|
|
||
|
{ #category : #'graphical interface' }
|
||
|
GrafoscopioBrowser >> treeOn: constructor [
|
||
|
"Shows the correspondent tree of a node"
|
||
|
|
||
|
(constructor tree) "Layout"
|
||
|
title: mainTree header;
|
||
|
children: [ :eachNode |
|
||
|
(eachNode children) isNil
|
||
|
ifTrue: [ #() ]
|
||
|
ifFalse:[ eachNode children ] ];
|
||
|
format:[:eachNode |
|
||
|
(eachNode header) isNil
|
||
|
ifTrue: [ '' ]
|
||
|
ifFalse: [ eachNode header ]];
|
||
|
"Adding nodes"
|
||
|
act: [:treePresentation |
|
||
|
(treePresentation selection) isNotNil
|
||
|
ifTrue: [treePresentation selection addNodeAfter].
|
||
|
treePresentation update]
|
||
|
icon: GLMUIThemeExtraIcons glamorousZoomIn
|
||
|
entitled: 'Add node';
|
||
|
"Removing nodes"
|
||
|
act: [:treePresentation |
|
||
|
(treePresentation selection isNotNil)
|
||
|
ifTrue: [(treePresentation selection parent)
|
||
|
removeNode: treePresentation selection]
|
||
|
ifFalse: [treePresentation entity removeLast].
|
||
|
treePresentation update]
|
||
|
icon: GLMUIThemeExtraIcons glamorousZoomOut
|
||
|
entitled: 'Remove node';
|
||
|
|
||
|
"Move nodes in the same hierarchy"
|
||
|
|
||
|
act: [:treePresentation |
|
||
|
(treePresentation selection isNotNil)
|
||
|
ifTrue: [treePresentation selection moveBefore].
|
||
|
treePresentation update]
|
||
|
icon: GLMUIThemeExtraIcons glamorousUp
|
||
|
entitled: 'Move node up';
|
||
|
|
||
|
act: [:treePresentation |
|
||
|
(treePresentation selection isNotNil)
|
||
|
ifTrue: [treePresentation selection moveAfter].
|
||
|
treePresentation update]
|
||
|
icon: GLMUIThemeExtraIcons glamorousDown
|
||
|
entitled: 'Move node down';
|
||
|
|
||
|
act: [:treePresentation |
|
||
|
(treePresentation selection isNotNil)
|
||
|
ifTrue: [treePresentation selection promote].
|
||
|
treePresentation update]
|
||
|
icon: GLMUIThemeExtraIcons glamorousLeft
|
||
|
entitled: 'Move node left';
|
||
|
|
||
|
act: [:treePresentation |
|
||
|
(treePresentation selection isNotNil)
|
||
|
ifTrue: [treePresentation selection demote].
|
||
|
treePresentation update]
|
||
|
icon: GLMUIThemeExtraIcons glamorousRight
|
||
|
entitled: 'Move node rigt';
|
||
|
|
||
|
act: [self saveWorkingTree]
|
||
|
icon: GLMUIThemeExtraIcons glamorousSave
|
||
|
entitled: 'Save current tree';
|
||
|
|
||
|
"Menu options"
|
||
|
act: [ GrafoscopioBrowser new openFromFile] entitled: 'Abrir/Cargar ...';
|
||
|
act: [self saveToFile] entitled: 'Guardar como ...';
|
||
|
act: [self updateSystem] entitled: 'Actualizar Grafoscopio';
|
||
|
act: [:x | x printString inspect] entitled: 'Acerca de...'.
|
||
|
|
||
|
]
|
||
|
|
||
|
{ #category : #'as yet unclassified' }
|
||
|
GrafoscopioBrowser >> updateSystem [
|
||
|
"Updates the system with new versions of itself take from the source code repository"
|
||
|
Gofer new
|
||
|
smalltalkhubUser: 'SvenVanCaekenberghe' project: 'STON';
|
||
|
package: 'STON-Core';
|
||
|
load.
|
||
|
|
||
|
Gofer new squeaksource: 'Citezen';
|
||
|
package: 'ConfigurationOfCitezen';
|
||
|
load.
|
||
|
(ConfigurationOfCitezen project latestVersion: #development) load.
|
||
|
|
||
|
Gofer new
|
||
|
smalltalkhubUser: 'Offray' project: 'Ubakye';
|
||
|
package: 'Ubakye';
|
||
|
load.
|
||
|
|
||
|
]
|