VDBSettingsApplication.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 21 Jun 2019 22:54:50 +0100
changeset 175 a304c250e889
parent 174 3f6f51330641
child 202 8064029822c5
permissions -rw-r--r--
UI: add "Scratch Pad" tool which can be used by user to keep notes during debug session, to edit (configuration) files and so on.

"
jv:vdb - Visual / VM Debugger
Copyright (C) 2015-now Jan Vrany

This software is licensed under 'Creative Commons Attribution-NonCommercial 4.0 International License'

You may find a full license text in LICENSE.txt or at http://creativecommons.org/licenses/by-nc/4.0/
"
"{ Package: 'jv:vdb' }"

"{ NameSpace: Smalltalk }"

AbstractSettingsApplication subclass:#VDBSettingsApplication
	instanceVariableNames:'infoPanel gdbCommand'
	classVariableNames:''
	poolDictionaries:''
	category:'VDB-UI-Others'
!

!VDBSettingsApplication class methodsFor:'documentation'!

copyright
"
jv:vdb - Visual / VM Debugger
Copyright (C) 2015-now Jan Vrany

This software is licensed under 'Creative Commons Attribution-NonCommercial 4.0 International License'

You may find a full license text in LICENSE.txt or at http://creativecommons.org/licenses/by-nc/4.0/
"
! !

!VDBSettingsApplication class methodsFor:'initialization'!

initialize

    self installInSettings

    "Created: / 23-06-2005 / 09:27:10 / masca"
!

installInSettings
    
    Smalltalk addStartBlock:[
        AbstractLauncherApplication 
            addSettingsApplicationByClass:self name withName:'Tools/Visual VM Debugger' icon:self defaultIcon
    ]

    "Created: / 23-06-2005 / 09:27:10 / masca"
    "Modified: / 10-04-2018 / 16:56:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!VDBSettingsApplication class methodsFor:'help specs'!

helpSpec
    "This resource specification was automatically generated
     by the UIHelpTool of ST/X."

    "Do not manually edit this!! If it is corrupted,
     the UIHelpTool may not be able to read the specification."

    "
     UIHelpTool openOnClass:VDBSettingsApplication
    "

    <resource: #help>

    ^ super helpSpec addPairsFrom:#(

#ExecutableLabel
'Path to GDB executable. If left empty, system GDB is used.'

)
! !

!VDBSettingsApplication class methodsFor:'interface specs'!

windowSpec
    "This resource specification was automatically generated
     by the UIPainter of ST/X."

    "Do not manually edit this!! If it is corrupted,
     the UIPainter may not be able to read the specification."

    "
     UIPainter new openOnClass:VDBSettingsApplication andSelector:#windowSpec
     VDBSettingsApplication new openInterface:#windowSpec
     VDBSettingsApplication open
    "

    <resource: #canvas>

    ^ 
    #(FullSpec
       name: windowSpec
       uuid: '44956520-937c-11e9-8e2a-606720e43e2c'
       window: 
      (WindowSpec
         label: 'Java Settings'
         name: 'Java Settings'
         uuid: '10c0dbf1-3cd7-11e8-882f-0021ccd5e3d3'
         min: (Point 10 10)
         bounds: (Rectangle 0 0 695 627)
       )
       component: 
      (SpecCollection
         collection: (
          (LabelSpec
             label: ' Visual/VM Debugger Settings'
             name: 'SettingsTitle'
             layout: (LayoutFrame 0 0 0 0 0 1 66 0)
             style: (FontDescription helvetica medium roman 18 #'iso10646-1' nil nil)
             uuid: '10c0dbf2-3cd7-11e8-882f-0021ccd5e3d3'
             backgroundColor: (Color 100.0 100.0 100.0)
             translateLabel: true
             adjust: left
           )
          (LabelSpec
             label: 'Icon'
             name: 'Icon'
             layout: (LayoutFrame -75 1 0 0 0 1 66 0)
             uuid: '10c10300-3cd7-11e8-882f-0021ccd5e3d3'
             hasCharacterOrientedLabel: false
             backgroundColor: (Color 100.0 100.0 100.0)
             translateLabel: true
             labelChannel: libjavaCupIcon
           )
          (SubCanvasSpec
             name: 'InfoPanel'
             layout: (LayoutFrame 0 0 67 0 0 1 107 0)
             uuid: '10c10301-3cd7-11e8-882f-0021ccd5e3d3'
             level: 0
             initiallyInvisible: true
             hasHorizontalScrollBar: false
             hasVerticalScrollBar: false
             clientKey: infoPanel
             createNewBuilder: false
           )
          (VerticalPanelViewSpec
             name: 'Controls'
             layout: (LayoutFrame 10 0 70 0 -10 1 0 1)
             uuid: '10c10302-3cd7-11e8-882f-0021ccd5e3d3'
             horizontalLayout: fit
             verticalLayout: top
             horizontalSpace: 3
             verticalSpace: 3
             component: 
            (SpecCollection
               collection: (
                (ViewSpec
                   name: 'Spacer1'
                   uuid: 'fed33671-91af-11e9-b25b-606720e43e2c'
                   extent: (Point 675 15)
                 )
                (ViewSpec
                   name: 'CommandPane'
                   uuid: '7628c0d0-c755-11e8-8f9c-0021ccd5e3d3'
                   component: 
                  (SpecCollection
                     collection: (
                      (LabelSpec
                         label: ''';gdb'' command:'
                         name: 'CommandLabel'
                         layout: (LayoutFrame 0 0 0 0 120 0 0 1)
                         uuid: 'fed33672-91af-11e9-b25b-606720e43e2c'
                         translateLabel: true
                         adjust: left
                       )
                      (FilenameInputFieldSpec
                         name: 'Command'
                         layout: (LayoutFrame 120 0 0 0 -100 1 0 1)
                         uuid: '7628c0d2-c755-11e8-8f9c-0021ccd5e3d3'
                         model: gdbCommand
                         immediateAccept: true
                         acceptOnPointerLeave: true
                         emptyFieldReplacementText: 'Autodetect'
                       )
                      (ActionButtonSpec
                         label: 'Browse'
                         name: 'BrowseButton'
                         layout: (LayoutFrame -100 1 0 0 -8 1 0 1)
                         uuid: '7628c0d3-c755-11e8-8f9c-0021ccd5e3d3'
                         translateLabel: true
                         model: doSelectExecutable
                       )
                      )
                    
                   )
                   extent: (Point 675 25)
                 )
                (ViewSpec
                   name: 'Spacer2'
                   uuid: '7628c0d4-c755-11e8-8f9c-0021ccd5e3d3'
                   extent: (Point 675 15)
                 )
                (ViewSpec
                   name: 'vdbinit'
                   uuid: '85b08540-936c-11e9-ac6c-606720e43e2c'
                   component: 
                  (SpecCollection
                     collection: (
                      (LabelSpec
                         label: 'VDB init script'
                         name: 'Label1'
                         layout: (LayoutFrame 0 0 -1 0 0 1 24 0)
                         uuid: '85b08541-936c-11e9-ac6c-606720e43e2c'
                         translateLabel: true
                         adjust: left
                       )
                      (LinkButtonSpec
                         label: 'LinkButton'
                         name: 'EditPreferences'
                         layout: (LayoutFrame 0 0 28 0 -100 1 58 0)
                         uuid: '85b08542-936c-11e9-ac6c-606720e43e2c'
                         foregroundColor: (Color 0.0 0.0 100.0)
                         translateLabel: true
                         labelChannel: vdbinitAspect
                         adjust: left
                         model: doEditVDBinit
                       )
                      (ActionButtonSpec
                         label: 'Edit'
                         name: 'Button1'
                         layout: (LayoutFrame -106 1 33 0 -6 1 58 0)
                         uuid: '85b08543-936c-11e9-ac6c-606720e43e2c'
                         translateLabel: true
                         model: doEditVDBinit
                       )
                      )
                    
                   )
                   extent: (Point 675 70)
                 )
                (ViewSpec
                   name: 'Spacer3'
                   uuid: '7628c0d4-c755-11e8-8f9c-0021ccd5e3d3'
                   extent: (Point 675 15)
                 )
                (ViewSpec
                   name: 'gdbinit'
                   uuid: '85b08544-936c-11e9-ac6c-606720e43e2c'
                   component: 
                  (SpecCollection
                     collection: (
                      (LabelSpec
                         label: 'GDB init script'
                         name: 'Label2'
                         layout: (LayoutFrame 0 0 -1 0 0 1 24 0)
                         uuid: '85b08545-936c-11e9-ac6c-606720e43e2c'
                         translateLabel: true
                         adjust: left
                       )
                      (LinkButtonSpec
                         label: 'LinkButton'
                         name: 'Button2'
                         layout: (LayoutFrame 0 0 28 0 -100 1 58 0)
                         uuid: '85b08546-936c-11e9-ac6c-606720e43e2c'
                         foregroundColor: (Color 0.0 0.0 100.0)
                         translateLabel: true
                         labelChannel: gdbinitAspect
                         adjust: left
                         model: doEditGDBinit
                       )
                      (ActionButtonSpec
                         label: 'Edit'
                         name: 'Button3'
                         layout: (LayoutFrame -106 1 33 0 -6 1 58 0)
                         uuid: '85b08547-936c-11e9-ac6c-606720e43e2c'
                         translateLabel: true
                         model: doEditGDBinit
                       )
                      )
                    
                   )
                   extent: (Point 675 70)
                 )
                )
              
             )
           )
          )
        
       )
     )
! !

!VDBSettingsApplication methodsFor:'actions'!

doEditGDBinit
    VDBScatchPadApplication openOnFile:VDBDebuggerApplication gdbUserInitFile

    "Modified: / 21-06-2019 / 10:10:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

doEditVDBinit
    | user  default  userEditor  defaultEditor  workspaceView  workspace |

    workspace := VDBScatchPadApplication new.
    user := VDBDebuggerApplication vdbUserInitFile.
    default := VDBDebuggerApplication vdbDefaultInitFile.
    user exists ifFalse:[
        default copyTo:user.
    ].
    userEditor := Tools::CodeView2 new.
    userEditor name:#Workspace.
    workspace 
        loadFile:user
        encoding:nil
        into:userEditor.
    defaultEditor := Tools::CodeView2 new.
    workspace 
        loadFile:default
        encoding:nil
        into:defaultEditor.
    defaultEditor readOnly:true.
    workspaceView := VariableHorizontalPanel new.
    workspaceView addComponent:userEditor.
    workspaceView addComponent:defaultEditor.
    workspace := VDBScatchPadApplication new.
    workspace workspaces add:workspaceView.
    workspace syntax:SmalltalkLanguage instance.
    workspace open.
    workspace window 
        label:(resources string:'.vdbinit.st - User : vdbinit.st - Default')
!

doSelectExecutable
    | guess executable |

    guess := self gdbCommand value asNilIfEmpty.
    guess isNil ifTrue:[
        guess := GDBProcess gdbCommand
    ].

    [ guess notNil and:[ (guess := guess asFilename) exists not ] ] whileTrue:[ 
        | p |

        p := guess directory.
        (p notNil and:[ p pathName = guess pathName ]) ifTrue:[ 
            p := nil.
        ].
        guess := p.
    ].
    guess isNil ifTrue:[ 
        guess := GDBProcess gdbCommand
    ].
    executable := Dialog requestFileName:(resources string:'Select GDB executable') default: guess ifFail:[ ^ self ].
    self infoPanel hide. 
    (executable includes: Character space) ifTrue:[ 
        executable := '"' , executable , '"'.
    ].
    self gdbCommand value: executable

    "Created: / 03-10-2018 / 22:46:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 18-06-2019 / 10:42:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!VDBSettingsApplication methodsFor:'aspects'!

aspects
    ^ #(gdbCommand)

    "Created: / 10-04-2018 / 16:53:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 17-06-2019 / 13:38:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

gdbCommand
    "return/create the 'gdbCommand' value holder (automatically generated)"

    gdbCommand isNil ifTrue:[
        gdbCommand := ValueHolder new.
        gdbCommand onChangeSend:#doCheckSettings to:self.
        gdbCommand onChangeSend:#updateModifiedChannel to:self.
    ].
    ^ gdbCommand
    "
    UserPreferences current gdbCommand
    "

    "Modified: / 18-06-2019 / 11:16:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

gdbinitAspect
    <resource: #uiAspect>

    ^ VDBDebuggerApplication gdbUserInitFile pathName

    "Modified: / 20-06-2019 / 16:24:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

infoPanel
    infoPanel isNil ifTrue:[
        infoPanel := Tools::InlineMessageDialog new.
    ].
    ^ infoPanel

    "Created: / 10-04-2018 / 16:52:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

vdbinitAspect
    <resource: #uiAspect>

    ^ VDBDebuggerApplication vdbUserInitFile pathName

    "Modified: / 20-06-2019 / 16:25:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!VDBSettingsApplication methodsFor:'checks'!

doCheckCommand
    "Check `hg` command. Return true if `hg` command exists
     and of supported version, false otherwise."

    | command |

    command := self gdbCommand value.
    command isEmptyOrNil ifTrue:[         
        command := GDBProcess gdbCommandDefault.
        command isNil ifTrue:[ 
            self infoPanel 
                reset;
                beWarning;
                message: (resources string:'Cannot find path to `gdb` command');
                addButtonWithLabel: (self resources string:'Browse') action: [ self doSelectExecutable ];
                show. 
            ^ false                
        ].
    ].
    [
        GDBProcess gdbCommandParseAndValidate:command 
    ] on: GDBError do:[:ex | 
        self infoPanel 
            reset;
            beWarning;
            message: (resources string:ex description);
            addButtonWithLabel: (self resources string:'Browse') action: [self infoPanel hide. self doSelectExecutable ];
            show.            
        ^ false                            
    ].
    ^ true.

    "Created: / 18-06-2019 / 10:47:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

doCheckSettings
    self doCheckCommand ifFalse:[ ^ self ].

    self infoPanel hide.

    "Created: / 18-06-2019 / 10:45:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!VDBSettingsApplication methodsFor:'hooks'!

commonPostOpen
    self doCheckSettings

    "Created: / 18-06-2019 / 10:44:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!VDBSettingsApplication methodsFor:'protocol'!

basicSaveSettings
    self gdbCommand value = '' ifTrue:[ 
        self gdbCommand setValue: nil
    ].
    super basicSaveSettings.

    "Created: / 04-10-2018 / 09:46:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 17-06-2019 / 13:40:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!VDBSettingsApplication class methodsFor:'documentation'!

version_HG

    ^ '$Changeset: <not expanded> $'
! !


VDBSettingsApplication initialize!