UX: show user some usefull message when source code is not available
authorJan Vrany <jan.vrany@fit.cvut.cz>
Tue, 02 Oct 2018 12:32:08 +0100
changeset 122 c992f32875bf
parent 121 e825c8db2147
child 123 59344404471e
UX: show user some usefull message when source code is not available ...along with hints what might be wrong in order to help users to debug / fix the problem.
VDBSourceApplication.st
--- a/VDBSourceApplication.st	Sun Oct 07 09:14:26 2018 +0100
+++ b/VDBSourceApplication.st	Tue Oct 02 12:32:08 2018 +0100
@@ -197,65 +197,124 @@
 
 !VDBSourceApplication methodsFor:'change & update'!
 
-update:aspect with:param from:sender
+update:aspect with:param from:sender 
     "Invoked when an object that I depend upon sends a change notification."
-
-    sender == frameHolder ifTrue:[ 
-        self updateAfterFrameHolderChanged.
+    
+    sender == frameHolder ifTrue:[
+        self updateSourceFile.
         ^ self.
     ].
-
     sender == sourceFileHolder ifTrue:[
-        | file source |
-
-        source := nil.
-        file := sourceFileHolder value.
-        file notNil ifTrue:[ 
-            file := file asFilename.
-            file exists ifTrue:[ 
-                source := file contents asString.
-            ]
-        ].
-        self sourceStringHolder value: source.  
+        self updateSourceString.
         ^ self.
     ].
     super update:aspect with:param from:sender
 
-    "Modified: / 01-02-2018 / 15:15:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 02-10-2018 / 10:50:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-updateAfterFrameHolderChanged
+updateCurrentLine
+    | frame file |
+
+    frame := frameHolder value.
+    file := sourceFileHolder value.
+    (frame notNil and:[file notNil]) ifTrue:[
+        | line |
+        line := frame line.
+        line notNil ifTrue:[
+            sourceView selectLine:line.
+            sourceView makeSelectionVisible.
+            ^ self.
+        ]
+    ].
+    sourceView unselect
+
+    "Created: / 02-10-2018 / 11:03:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+updateSourceFile
     | frame |
 
     frame := frameHolder value.
-    frame notNil ifTrue:[ 
-        | line |
+    frame notNil ifTrue:[
+        | file |
 
-        self sourceFileHolder value: frame file.
-        line := frame line.
-        line notNil ifTrue:[  
-            sourceView selectLine: line.
-            sourceView makeSelectionVisible.
-        ]
+        file := frame file.
+        file notNil ifTrue:[ file := file asFilename ].
+        self sourceFileHolder value: file
     ].
 
     "Created: / 01-02-2018 / 15:16:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 02-10-2018 / 11:12:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+updateSourceString
+    | source file |
+
+    source := nil.
+    file := sourceFileHolder value.
+    (file notNil and:[file exists]) ifTrue:[
+        source := file contents asString.
+    ] ifFalse:[ 
+        "/ We have no source. As a courtesy to the user, display some info
+        "/ on what's the problem and
+        | frame |
+
+        frame := self frameHolder value.
+        source := Text streamContents:[ :info |
+            | frameFile frameFullname |
+            info emphasis: #color -> (UserPreferences current codeViewTheme ? UserPreferences current) commentColor.
+            info nextPutAll: '//' ; cr.
+            info nextPutAll: '// '; nextPutAll: (resources string: 'No source available :-('); cr.
+            info nextPutAll: '//' ; cr.
+            frameFile := frame propertyAt: #file.
+            frameFullname := frame propertyAt: #fullname.
+            (frameFile isNil and:[ frameFullname notNil ]) ifTrue:[ 
+                info nextPutAll: '// '; nextPutLine: (resources string: 'Source file reference missing (no debug info?)').
+            ] ifFalse:[ 
+                info nextPutAll: '// '; nextPutLine: (resources string: 'Source file cannot be resolved:').
+                info nextPutAll: '// '; cr.
+                frameFile notNil ifTrue:[
+                    info nextPutAll: '//   '; nextPutLine: frameFile.
+                ].
+                frameFullname notNil ifTrue:[
+                    info nextPutAll: '//   '; nextPutLine: frameFullname.
+                ].
+                info nextPutAll: '// '; cr.
+                info nextPutAll: '// '; nextPutLine: (resources string: 'Configured source directories:').
+                debugger directories do:[:each | 
+                    info nextPutAll: '//   '; nextPutLine: each.
+                ].
+                info nextPutAll: '// '; cr.
+                info nextPutAll: '// '; nextPutLine: (resources string: 'See also:').
+                info nextPutAll: '// [1]: https://sourceware.org/gdb/onlinedocs/gdb/Source-Path.html'.
+            ].
+
+        ]
+
+    ].
+    self sourceStringHolder value:source.
+    self updateCurrentLine.
+    ^ self.
+
+    "Modified: / 07-10-2018 / 20:47:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !VDBSourceApplication methodsFor:'change & update-delayed'!
 
-delayedUpdateAfterFrameChanged
-    self updateAfterFrameHolderChanged
+delayedUpdateCurrentLine
+    self updateCurrentLine
 
-    "Created: / 01-02-2018 / 15:28:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Created: / 02-10-2018 / 11:04:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !VDBSourceApplication methodsFor:'event handling'!
 
 onStoppedEvent: aGDBStoppedEvent
-    self enqueueDelayedUpdate: #delayedUpdateAfterFrameChanged
+    self enqueueDelayedUpdate: #delayedUpdateCurrentLine
 
     "Created: / 01-02-2018 / 15:23:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 02-10-2018 / 11:04:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !VDBSourceApplication methodsFor:'initialization & release'!