SmallSense__CriticsWindow.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 26 Aug 2013 10:33:23 +0100
changeset 67 020b7461b15e
parent 64 2257d7223898
child 72 7a71bbc338e2
permissions -rw-r--r--
Package structure reorganization. SmallSense is no longer Smalltalk-specific but it provides infrastructure to build support for other languages as well. Therefore classes and class categories were renamed to reflect whether it is a reusable *core* thing or Smalltalk-specific code.

"{ Package: 'jv:smallsense' }"

"{ NameSpace: SmallSense }"

ApplicationModel subclass:#CriticsWindow
	instanceVariableNames:'ruleHolder ruleRationaleAndFixesHTMLHolder rationalView fixer
		entered codeView'
	classVariableNames:''
	poolDictionaries:''
	category:'SmallSense-Core-Interface'
!


!CriticsWindow 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:SmallSenseCriticsWindow andSelector:#windowSpec
     SmallSenseCriticsWindow new openInterface:#windowSpec
     SmallSenseCriticsWindow open
    "

    <resource: #canvas>

    ^ 
     #(FullSpec
        name: windowSpec
        window: 
       (WindowSpec
          label: 'SmalllintRuleDetail'
          name: 'SmalllintRuleDetail'
          min: (Point 10 10)
          bounds: (Rectangle 0 0 418 219)
          backgroundColor: (Color 94.1176470588235 93.7254901960784 59.2156862745098)
          forceRecursiveBackgroundOfDefaultBackground: true
        )
        component: 
       (SpecCollection
          collection: (
           (LinkButtonSpec
              name: 'Button1'
              layout: (LayoutFrame -1 0 -1 0 1 1 30 0)
              activeHelpKey: ruleName
              level: 0
              backgroundColor: (Color 94.1176470588235 93.7254901960784 59.2156862745098)
              translateLabel: true
              labelChannel: ruleNameAspect
              adjust: left
              model: browseLintRule
            )
           (ActionButtonSpec
              label: 'X'
              name: 'Button2'
              layout: (LayoutFrame -30 1 0 0 0 1 30 0)
              level: 0
              backgroundColor: (Color 94.1176470588235 93.7254901960784 59.2156862745098)
              translateLabel: true
              model: closeRequest
            )
           (HTMLViewSpec
              name: 'Rationale'
              layout: (LayoutFrame 0 0 28 0 0 1 0 1)
              level: 0
              visibilityChannel: rationaleVisibleHolder
              hasHorizontalScrollBar: true
              hasVerticalScrollBar: true
              backgroundColor: (Color 94.1176470588235 93.7254901960784 59.2156862745098)
              htmlText: ruleRationaleAndFixesHTMLHolder
              postBuildCallback: setupHTMLView:
            )
           )
         
        )
      )
! !

!CriticsWindow class methodsFor:'plugIn spec'!

aspectSelectors
    "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."

    "Return a description of exported aspects;
     these can be connected to aspects of an embedding application
     (if this app is embedded in a subCanvas)."

    ^ #(
        #ruleHolder
      ).

! !

!CriticsWindow methodsFor:'accessing'!

codeView
    ^ codeView
!

codeView:aCodeView2
    codeView := aCodeView2.
!

rule

    ^self ruleHolder value.

    "Created: / 30-01-2012 / 21:45:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

rule: anRBLintRule

    ^self ruleHolder value: anRBLintRule

    "Created: / 30-01-2012 / 21:45:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!CriticsWindow methodsFor:'actions'!

browseLintRule
    |rule ruleClass sel|

    rule := self ruleHolder value.
    rule isNil ifTrue:[^ self].
    ruleClass := rule class.
    (ruleClass implements:#rationale) ifTrue:[
        sel := #rationale.
    ].
    self close.
    UserPreferences current systemBrowserClass
       openInClass:ruleClass selector:sel.

    "Created: / 07-09-2011 / 04:09:38 / cg"
    "Modified: / 31-01-2012 / 11:30:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

doQuickFix: quickFixNo

    self closeDownViews.
    [ fixer performFix: quickFixNo ] fork.

    "Created: / 16-02-2012 / 14:19:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!CriticsWindow methodsFor:'aspects'!

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

    ruleHolder isNil ifTrue:[
        ruleHolder := ValueHolder with: (RBDebuggingCodeLeftInMethodsRule new)
    ].
    ^ ruleHolder

    "Modified: / 30-01-2012 / 21:43:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

ruleHolder:something
    "set the 'ruleHolder' value holder (automatically generated)"

    |oldValue newValue|

    ruleHolder notNil ifTrue:[
	oldValue := ruleHolder value.
	ruleHolder removeDependent:self.
    ].
    ruleHolder := something.
    ruleHolder notNil ifTrue:[
	ruleHolder addDependent:self.
    ].
    newValue := ruleHolder value.
    oldValue ~~ newValue ifTrue:[
	self update:#value with:newValue from:ruleHolder.
    ].
!

ruleNameAspect
    <resource: #uiAspect>

    |holder|

    (holder := builder bindingAt:#ruleNameAspect) isNil ifTrue:[
        holder := BlockValue
                    with:[:h | 
                        "/ h displayString , ' ' , (('[browse]' actionForAll:[ self browseLintRule]) colorizeAllWith:Color blue) 
                        h displayString actionForAll:[ self browseLintRule] 
                    ]
                    argument: self ruleHolder.
        builder aspectAt:#ruleNameAspect put:holder.
    ].
    ^ holder.

    "Modified: / 05-02-2010 / 12:51:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 07-09-2011 / 04:54:24 / cg"
!

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

    ruleRationaleAndFixesHTMLHolder isNil ifTrue:[
        ruleRationaleAndFixesHTMLHolder := ValueHolder new.
    ].
    ^ ruleRationaleAndFixesHTMLHolder

    "Modified (format): / 01-02-2012 / 10:57:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!CriticsWindow methodsFor:'change & update'!

update:something with:aParameter from:changedObject
    "Invoked when an object that I depend upon sends a change notification."

    "stub code automatically generated - please change as required"

    changedObject == ruleHolder ifTrue:[
         self updateRationaleAndFixes.
         ^ self.
    ].
    super update:something with:aParameter from:changedObject

    "Modified: / 01-02-2012 / 10:56:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

updateRationaleAndFixes

    | rule html |
    rule := self ruleHolder value.
    rule isNil ifTrue:[
        fixer := nil.
        html :=  'No rule...'.
    ] ifFalse:[
        fixer := QuickFixer for: rule view: codeView.
        html := String streamContents:[:s|
                    s nextPutAll: rule rationale ; cr.
                    fixer printHtmlOn: s.
                ]
    ].

    self ruleRationaleAndFixesHTMLHolder value: html

    "Created: / 01-02-2012 / 10:56:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!CriticsWindow methodsFor:'event processing'!

processEvent: anEvent

"/    entered ifFalse:[
"/        anEvent isPointerLeaveEvent ifTrue:[
"/            anEvent view == self window ifTrue:[
"/                entered := true.
"/            ]
"/        ]
"/    ] ifTrue:[
        anEvent isPointerLeaveEvent ifTrue:[
            anEvent view == self window ifTrue:[
                self closeDownViews.
                ^true.
            ]
        ].
"/    ].

    ^false

    "Created: / 16-02-2012 / 14:09:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!CriticsWindow methodsFor:'hooks'!

postBuildWith: bldr

    entered := false.
    self updateRationaleAndFixes.
    bldr window 
        "windowGroup: codeView windowGroup;"
        bePopUpView; 
        beSlave.

    "Created: / 03-04-2011 / 10:45:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 16-02-2012 / 14:14:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

postOpenWith: bldr

    self windowGroup addPreEventHook: self.

    "Created: / 16-02-2012 / 14:09:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!CriticsWindow methodsFor:'initialization'!

setupHTMLView:aView
    rationalView := aView.
    aView painter
        leftMargin:20;
        topMargin:5.

    "Created: / 04-08-2011 / 18:00:36 / cg"
! !

!CriticsWindow class methodsFor:'documentation'!

version_HG

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

version_SVN
    ^ '$Id: SmallSenseCriticsWindow.st 7911 2012-02-22 09:55:48Z vranyj1 $'
! !