mercurial/HGCommitDialog.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 07 Dec 2012 16:36:27 -0800
changeset 146 1015b8f6dc1c
parent 143 70e4bf961dec
child 151 527a1e85aef8
permissions -rw-r--r--
Added check for author signature before commit. If author is not specified when commiting, an HGCommitError is raise. Commit dialog checks in advance and shows warning.

"{ Package: 'stx:libscm/mercurial' }"

SCMAbstractCommitDialog subclass:#HGCommitDialog
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'SCM-Mercurial-StX-Interface'
!


!HGCommitDialog class methodsFor:'image specs'!

dialogIcon
    ^ HGIconLibrary hgLogo2

    "Created: / 14-11-2012 / 00:14:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 16-11-2012 / 11:01:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!HGCommitDialog class methodsFor:'interface specs'!

fileListColumnSpec
    "This resource specification was automatically generated
     by the DataSetBuilder of ST/X."

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

    "
     DataSetBuilder new openOnClass:SVN::CommitDialog2 andSelector:#fileListColumnSpec
    "

    <resource: #tableColumns>

    ^#(
      (DataSetColumnSpec
         label: ''
         activeHelpKey: ''
         activeHelpKeyForLabel: ''
         labelButtonType: None
         width: 22
         minWidth: 22
         editorType: CheckToggle
         rendererType: CheckToggle
         model: include
         menuFromApplication: false
         printSelector: include
         showRowSeparator: false
         showColSeparator: false
       )
      (DataSetColumnSpec
         label: ''
         activeHelpKey: ''
         activeHelpKeyForLabel: ''
         labelButtonType: Button
         width: 22
         minWidth: 22
         menuFromApplication: false
         printSelector: statusIcon
         canSelect: false
         showRowSeparator: false
         showColSeparator: false
       )
      (DataSetColumnSpec
         label: 'Container'
         labelAlignment: left
         activeHelpKey: ''
         activeHelpKeyForLabel: ''
         labelButtonType: Button
         menuFromApplication: false
         printSelector: pathText
         canSelect: false
         showRowSeparator: false
         showColSeparator: false
       )
    "
      (DataSetColumnSpec
         label: 'Rev'
         activeHelpKey: ''
         activeHelpKeyForLabel: ''
         labelButtonType: Button
         usePreferredWidth: true
         menuFromApplication: false
         printSelector: revision
         canSelect: false
         showRowSeparator: false
         showColSeparator: false
       )
      (DataSetColumnSpec
         label: 'Author'
         labelAlignment: left
         activeHelpKey: ''
         activeHelpKeyForLabel: ''
         labelButtonType: Button
         usePreferredWidth: true
         menuFromApplication: false
         printSelector: author
         canSelect: false
         showRowSeparator: false
         showColSeparator: false
       )
      (DataSetColumnSpec
         label: 'Date'
         activeHelpKey: ''
         activeHelpKeyForLabel: ''
         labelButtonType: Button
         usePreferredWidth: true
         menuFromApplication: false
         printSelector: date
         canSelect: false
         showRowSeparator: false
         showColSeparator: false
       )
        "
      )

    "Created: / 15-11-2012 / 09:28:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!HGCommitDialog methodsFor:'actions'!

doEditUserConfig
    | hgrc |

    hgrc := HGConfig userConfigFiles first.
    hgrc exists ifFalse:[hgrc writingFileDo:[:s|s cr]].
    WorkspaceApplication openOnFile: hgrc.
    self doCancel.

    "Created: / 07-12-2012 / 16:08:02 / jv"
!

doShowDiffsForEntry

    self fileSelectionHolder value do:[:each|
        self doShowDiffsForEntry: each entry against: each entry changeset
    ].

    "Created: / 09-02-2012 / 14:51:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 06-12-2012 / 17:00:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

doShowDiffsForEntry: wcentry against: rev
    |wc wcChangeSet repoentry repoChangeSet diffset |

    wc := self task workingCopy.
    repoentry := [ rev / wcentry pathNameRelativeSlashed ] on: HGError do: [
        Dialog warn: 'File does not exists in changeset ' , rev id printString.
    ].
    wcentry suffix = SmalltalkLanguage instance sourceFileSuffix ifTrue:[
        wcChangeSet := ChangeSet fromFile: wcentry .
        wcChangeSet name: wcChangeSet name, (resources string: ' (working copy - to be commited)').
        repoChangeSet := ChangeSet fromStream: repoentry contents asString readStream.
        repoChangeSet name: wcentry baseName,  ' (' , rev id printString , ')'.
        diffset := ChangeSetDiff versionA:wcChangeSet versionB:repoChangeSet.
        (Tools::ChangeSetDiffTool new)
            beSingleColumn;
            diffset:diffset;
            title:('%1: Diffbetween working copy and rev. %2 ' bindWith: wcentry pathNameRelative with: rev printString);
            showVersionMethodDiffs: false;
            open
    ] ifFalse:[
        | text1 text2 |
        text1 := wcentry contents asString.
        text2 := repoentry contents asString.
        "/Argh...backward compatibility..."
        (Tools::TextDiff2Tool ? Tools::TextDiffTool) new
            labelA: 'Working copy';
            labelB: ('r %1' bindWith: rev printString);
            textA: text1; textB: text2;
            title:('%1: Diffbetween working copy and rev. %2 ' bindWith: wcentry pathNameRelative with: rev printString);
            open
    ]

    "Created: / 09-02-2012 / 14:53:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 06-12-2012 / 17:26:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

doShowDiffsForEntryAgainstHEAD

    self fileSelectionHolder value do:[:each|
        self doShowDiffsForEntry: each entry against: self workingCopy heads anElement
    ].

    "Created: / 10-02-2012 / 10:00:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 06-12-2012 / 17:04:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!HGCommitDialog methodsFor:'change & update'!

updateFileList
    | wcroot statuses entries showOnlyModified wcrootPathNameRelative wcrootPathNameRelativeLen |

    showOnlyModified := fileListShowOnlyModifiedHolder value.
    "HACK..."

    wcroot := self model package temporaryWorkingCopyRoot.
    wcrootPathNameRelative := wcroot pathNameRelative.
    wcrootPathNameRelativeLen := wcrootPathNameRelative size.

    statuses := HGCommand status
                    workingDirectory: wcroot pathName;
                    execute.
    entries := OrderedCollection new: statuses size.
    statuses do:[:statusAndPath|
        (fileListShowOnlyModifiedHolder value not
            or:[statusAndPath first isCleanOrIgnored not]) ifTrue:[
            | nm entry |

            (statusAndPath second startsWith: wcrootPathNameRelative) ifTrue:[
                nm := statusAndPath second.
                wcrootPathNameRelativeLen ~~ 0 ifTrue:[
                    nm := nm copyFrom:wcrootPathNameRelativeLen + 2.
                ].
                entry := SCMAbstractCommitDialog::FileEntry application: self entry: wcroot / nm name: nm.
                entries add: entry
            ].
        ].
    ].
    self fileListHolder value: entries

    "Created: / 08-02-2012 / 18:05:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 01-12-2012 / 00:48:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!HGCommitDialog methodsFor:'private'!

doCheckAuthor
    "Checks whether commit author is defined"

    self task author isNil ifTrue:[
        self infoPanel 
            reset;
            beWarning;
            message: 'Commit author signature not configured';
            addButtonWithLabel: (self resources string:'Edit')
                action: [self doEditUserConfig];
            addButtonWithLabel: (self resources string:'Cancel')
                action: [self doCancel].
        self acceptEnabled:false. 
        ^self.
    ].
    self doCheckHead.

    "Created: / 07-12-2012 / 15:56:36 / jv"
!

doCheckHead
    "Checks whether commit would create a new head"

    | heads changeset |

    heads := self task package temporaryWorkingCopy heads.
    changeset := self task package temporaryWorkingCopy changeset.
    (heads includes: changeset) ifFalse:[
        self infoPanel 
            reset;
            beInformation;
            message: (self resources string:'Comitting a new head.');
            addButtonWithLabel: (self resources string:'Proceed') action: [self infoPanel hide];
            "/addButtonWithLabel: (self resources string:'Cancel') action:[self doCancel];
            show.
    ]

    "Created: / 07-12-2012 / 15:52:18 / jv"
!

doUpdateWorkingCopy
    super doUpdateWorkingCopy.
    self doCheckAuthor.

    "Created: / 27-11-2012 / 23:36:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 01-12-2012 / 00:49:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (format): / 07-12-2012 / 15:53:43 / jv"
! !

!HGCommitDialog class methodsFor:'documentation'!

version_HG

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

version_SVN
    ^ '§Id::                                                                                                                        §'
! !