Skip to content

Commit

Permalink
Merge pull request #73 from africanmathsinitiative/master
Browse files Browse the repository at this point in the history
updating branch
  • Loading branch information
shadrackkibet authored May 31, 2017
2 parents 5db55e1 + 2af4cd6 commit 587bea7
Show file tree
Hide file tree
Showing 8 changed files with 637 additions and 283 deletions.
379 changes: 194 additions & 185 deletions instat/dlgTransformText.Designer.vb

Large diffs are not rendered by default.

137 changes: 89 additions & 48 deletions instat/dlgTransformText.vb
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ Imports instat.Translations
Public Class dlgTransformText
Public bFirstLoad As Boolean = True
Private bReset As Boolean = True
Private clsConvertFunction, clsLengthFunction, clsPadFunction, clsTrimFunction, clsWordsFunction, clsSubStringFunction As New RFunction
Private clsConvertFunction, clsLengthFunction, clsPadFunction, clsTrimFunction, clsWordsFunction, clsSubstringFunction As New RFunction

Private Sub dlgTransformText_Load(sender As Object, e As EventArgs) Handles MyBase.Load
autoTranslate(Me)
If bFirstLoad Then
InitialiseDialog()
bFirstLoad = False
End If

If bReset Then
SetDefaults()
End If
Expand Down Expand Up @@ -71,6 +70,7 @@ Public Class dlgTransformText
ucrInputTo.AddFunctionNamesCondition("Upper", "str_to_upper")
ucrInputTo.AddFunctionNamesCondition("Title", "str_to_title")
ucrInputTo.SetLinkedDisplayControl(lblTo)
ucrInputTo.SetDropDownStyleAsNonEditable()

'rdoPad
ucrPnlOperation.AddToLinkedControls(ucrInputPad, {rdoPad}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True)
Expand Down Expand Up @@ -164,6 +164,7 @@ Public Class dlgTransformText
ucrNewColName.SetSaveTypeAsColumn()
ucrNewColName.SetDataFrameSelector(ucrSelectorForTransformText.ucrAvailableDataFrames)
ucrNewColName.SetLabelText("Column Name:")
DialogSize()
End Sub

Private Sub SetDefaults()
Expand All @@ -172,70 +173,44 @@ Public Class dlgTransformText
clsPadFunction = New RFunction
clsTrimFunction = New RFunction
clsWordsFunction = New RFunction
clsSubStringFunction = New RFunction
clsSubstringFunction = New RFunction

ucrNewColName.Reset()
ucrSelectorForTransformText.Reset()

NewDefaultName()
clsConvertFunction.SetPackageName("stringr")
clsConvertFunction.SetRCommand("str_to_lower")
clsConvertFunction.SetAssignTo(ucrNewColName.GetText(), strTempDataframe:=ucrSelectorForTransformText.ucrAvailableDataFrames.cboAvailableDataFrames.Text, strTempColumn:=ucrNewColName.GetText)

clsLengthFunction.SetPackageName("stringr")
clsLengthFunction.SetRCommand("str_length")

clsPadFunction.SetPackageName("stringr")
clsPadFunction.SetRCommand("str_pad")
clsPadFunction.AddParameter("pad", Chr(34) & " " & Chr(34))
clsPadFunction.AddParameter("side", Chr(34) & "left" & Chr(34))
clsPadFunction.AddParameter("width", 1)

clsTrimFunction.SetPackageName("stringr")
clsTrimFunction.SetRCommand("str_trim")
clsTrimFunction.AddParameter("side", Chr(34) & "left" & Chr(34))

clsWordsFunction.SetPackageName("stringr")
clsWordsFunction.SetRCommand("word")
clsWordsFunction.AddParameter("start", 1)
clsWordsFunction.AddParameter("end", 2)
clsWordsFunction.AddParameter("sep", "fixed(" & Chr(34) & " " & Chr(34) & ")")

clsSubStringFunction.SetRCommand("str_sub")
clsSubStringFunction.AddParameter("start", 1)
clsSubStringFunction.AddParameter("end", 2)
clsSubstringFunction.SetPackageName("stringr")
clsSubstringFunction.SetRCommand("str_sub")
clsSubstringFunction.AddParameter("start", 1)
clsSubstringFunction.AddParameter("end", 2)

ucrBase.clsRsyntax.SetBaseRFunction(clsConvertFunction)
End Sub

Private Sub ucrBase_ClickReset(sender As Object, e As EventArgs) Handles ucrBase.ClickReset
SetDefaults()
SetRCodeForControls(True)
TestOkEnabled()
End Sub

Private Sub ucrPnl_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrPnlOperation.ControlValueChanged, ucrInputTo.ControlValueChanged
If rdoLength.Checked Then
ucrBase.clsRsyntax.SetBaseRFunction(clsLengthFunction)
ElseIf rdoPad.Checked Then
ucrBase.clsRsyntax.SetBaseRFunction(clsPadFunction)
ElseIf rdoTrim.Checked Then
ucrBase.clsRsyntax.SetBaseRFunction(clsTrimFunction)
ElseIf rdoWords.Checked Then
ucrBase.clsRsyntax.SetBaseRFunction(clsWordsFunction)
ElseIf rdoSubstring.Checked Then
ucrBase.clsRsyntax.SetBaseRFunction(clsSubStringFunction)
ElseIf rdoConvertCase.Checked Then
ucrBase.clsRsyntax.SetBaseRFunction(clsConvertFunction)
Select Case ucrInputTo.GetText
Case "Lower"
ucrBase.clsRsyntax.SetFunction("str_to_lower")
Case "Upper"
ucrBase.clsRsyntax.SetFunction("str_to_upper")
Case "Title"
ucrBase.clsRsyntax.SetFunction("str_to_title")
End Select
End If
TestOkEnabled()
SetRCodeForControls(False)
End Sub

Public Sub SetRCodeForControls(bReset As Boolean)
Private Sub SetRCodeForControls(bReset As Boolean)
ucrReceiverTransformText.SetRCode(ucrBase.clsRsyntax.clsBaseFunction, bReset)
ucrNewColName.SetRCode(ucrBase.clsRsyntax.clsBaseFunction, bReset)
ucrPnlOperation.SetRCode(ucrBase.clsRsyntax.clsBaseFunction, bReset)
Expand All @@ -252,8 +227,8 @@ Public Class dlgTransformText
ucrNudFirstWord.SetRCode(clsWordsFunction, bReset)
ucrNudLastWord.SetRCode(clsWordsFunction, bReset)
ucrInputSeparator.SetRCode(clsWordsFunction, bReset)
ucrNudFrom.SetRCode(clsSubStringFunction, bReset)
ucrNudTo.SetRCode(clsSubStringFunction, bReset)
ucrNudFrom.SetRCode(clsSubstringFunction, bReset)
ucrNudTo.SetRCode(clsSubstringFunction, bReset)
End Sub

Private Sub TestOkEnabled()
Expand Down Expand Up @@ -294,10 +269,77 @@ Public Class dlgTransformText
End If
End Sub

Private Sub ucrReceiverTransformText_ControlContentsChanged(ucrChangedControl As ucrCore) Handles ucrReceiverFirstWord.ControlContentsChanged, ucrNudWidth.ControlContentsChanged, ucrNudFirstWord.ControlContentsChanged, ucrNudLastWord.ControlContentsChanged, ucrNudFrom.ControlContentsChanged, ucrNudTo.ControlContentsChanged, ucrReceiverLastWord.ControlContentsChanged, ucrReceiverTransformText.ControlContentsChanged, ucrPnlOperation.ControlContentsChanged, ucrInputPad.ControlContentsChanged, ucrNewColName.ControlContentsChanged, ucrInputSeparator.ControlContentsChanged, ucrInputTo.ControlContentsChanged, ucrChkFirstOr.ControlContentsChanged, ucrChkLastOr.ControlContentsChanged
Private Sub ucrBase_ClickReset(sender As Object, e As EventArgs) Handles ucrBase.ClickReset
SetDefaults()
SetRCodeForControls(True)
TestOkEnabled()
End Sub

Private Sub NewDefaultName()
If (Not ucrNewColName.bUserTyped) AndAlso ucrSelectorForTransformText.ucrAvailableDataFrames.cboAvailableDataFrames.Text <> "" Then
ucrNewColName.SetName(ucrSelectorForTransformText.ucrAvailableDataFrames.cboAvailableDataFrames.Text & "_Transformed")
End If
End Sub

Private Sub DialogSize()
If rdoConvertCase.Checked OrElse rdoTrim.Checked Then
grpParameters.Visible = True
grpParameters.Size = New Size(397, 57)
ucrNewColName.Location = New Point(10, 301)
ucrBase.Location = New Point(10, 326)
Me.Size = New Size(435, 422)
ElseIf rdoLength.Checked Then
grpParameters.Visible = False
ucrNewColName.Location = New Point(10, 237)
ucrBase.Location = New Point(10, 262)
Me.Size = New Size(435, 357)
ElseIf rdoSubstring.Checked Then
grpParameters.Visible = True
grpParameters.Size = New Size(397, 81)
ucrNewColName.Location = New Point(10, 327)
ucrBase.Location = New Point(10, 352)
Me.Size = New Size(435, 448)
ElseIf rdoPad.Checked Then
grpParameters.Visible = True
grpParameters.Size = New Size(397, 121)
ucrNewColName.Location = New Point(10, 365)
ucrBase.Location = New Point(10, 390)
Me.Size = New Size(435, 486)
Else
grpParameters.Visible = True
grpParameters.Size = New Size(397, 173)
ucrNewColName.Location = New Point(10, 417)
ucrBase.Location = New Point(10, 442)
Me.Size = New Size(435, 537)
End If
End Sub

Private Sub ucrPnl_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrPnlOperation.ControlValueChanged, ucrInputTo.ControlValueChanged
If rdoLength.Checked Then
ucrBase.clsRsyntax.SetBaseRFunction(clsLengthFunction)
ElseIf rdoPad.Checked Then
ucrBase.clsRsyntax.SetBaseRFunction(clsPadFunction)
ElseIf rdoTrim.Checked Then
ucrBase.clsRsyntax.SetBaseRFunction(clsTrimFunction)
ElseIf rdoWords.Checked Then
ucrBase.clsRsyntax.SetBaseRFunction(clsWordsFunction)
ElseIf rdoSubstring.Checked Then
ucrBase.clsRsyntax.SetBaseRFunction(clsSubstringFunction)
ElseIf rdoConvertCase.Checked Then
ucrBase.clsRsyntax.SetBaseRFunction(clsConvertFunction)
Select Case ucrInputTo.GetText
Case "Lower"
ucrBase.clsRsyntax.SetFunction("str_to_lower")
Case "Upper"
ucrBase.clsRsyntax.SetFunction("str_to_upper")
Case "Title"
ucrBase.clsRsyntax.SetFunction("str_to_title")
End Select
End If
TestOkEnabled()
SetRCodeForControls(False)
End Sub

Private Sub ucrWordsTab_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkFirstOr.ControlValueChanged, ucrChkLastOr.ControlValueChanged, ucrPnlOperation.ControlValueChanged
If rdoWords.Checked Then
ucrNudFirstWord.Visible = True
Expand Down Expand Up @@ -336,15 +378,14 @@ Public Class dlgTransformText
ucrBase.clsRsyntax.RemoveParameter("start")
ucrBase.clsRsyntax.RemoveParameter("end")
End If
End Sub

Private Sub NewDefaultName()
If (Not ucrNewColName.bUserTyped) AndAlso ucrSelectorForTransformText.ucrAvailableDataFrames.cboAvailableDataFrames.Text <> "" Then
ucrNewColName.SetName(ucrSelectorForTransformText.ucrAvailableDataFrames.cboAvailableDataFrames.Text & "_Transformed")
End If
DialogSize()
End Sub

Private Sub ucrSelector_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrSelectorForTransformText.ControlValueChanged
NewDefaultName()
End Sub

Private Sub ucrReceiverTransformText_ControlContentsChanged(ucrChangedControl As ucrCore) Handles ucrReceiverFirstWord.ControlContentsChanged, ucrNudWidth.ControlContentsChanged, ucrNudFirstWord.ControlContentsChanged, ucrNudLastWord.ControlContentsChanged, ucrNudFrom.ControlContentsChanged, ucrNudTo.ControlContentsChanged, ucrReceiverLastWord.ControlContentsChanged, ucrReceiverTransformText.ControlContentsChanged, ucrPnlOperation.ControlContentsChanged, ucrInputPad.ControlContentsChanged, ucrNewColName.ControlContentsChanged, ucrInputSeparator.ControlContentsChanged, ucrInputTo.ControlContentsChanged, ucrChkFirstOr.ControlContentsChanged, ucrChkLastOr.ControlContentsChanged
TestOkEnabled()
End Sub
End Class
68 changes: 54 additions & 14 deletions instat/dlgView.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 587bea7

Please sign in to comment.