Skip to content

Commit

Permalink
Merge pull request #9477 from Vitalis95/dlgsplit
Browse files Browse the repository at this point in the history
Improving the Prepare > Column: Text > Split dialog
  • Loading branch information
N-thony authored Mar 6, 2025
2 parents 18f690e + 776ee80 commit 93eecae
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 47 deletions.
101 changes: 62 additions & 39 deletions instat/dlgPasteNewColumns.Designer.vb

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

33 changes: 30 additions & 3 deletions instat/dlgPasteNewColumns.vb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Imports instat.Translations
Public Class dlgPasteNewColumns
Private bFirstLoad As Boolean = True
Private bReset As Boolean = True
Private clsReadClipDataRFunction As New RFunction
Private clsReadClipDataRFunction, clsDummyFunction As New RFunction
Private clsImportColsToExistingDFRFunction As RFunction
'used to prevent TestOkEnabled from being called multiple times when loading the dialog.
Private bValidatePasteData As Boolean = False
Expand Down Expand Up @@ -52,6 +52,7 @@ Public Class dlgPasteNewColumns
ucrPnl.AddFunctionNamesCondition(rdoDataFrame, frmMain.clsRLink.strInstatDataObject & "$add_columns_to_data", bNewIsPositive:=False)
ucrPnl.AddFunctionNamesCondition(rdoColumns, frmMain.clsRLink.strInstatDataObject & "$add_columns_to_data", bNewIsPositive:=True)
ucrPnl.AddToLinkedControls({ucrDFSelected, ucrChkKeepExstingCols}, {rdoColumns}, bNewLinkedAddRemoveParameter:=False, bNewLinkedHideIfParameterMissing:=True)
ucrPnl.AddToLinkedControls(ucrChkSpaceSeperated, {rdoDataFrame}, bNewLinkedAddRemoveParameter:=False, bNewLinkedHideIfParameterMissing:=True)

ucrChkRowHeader.SetText("First row is header")
ucrChkRowHeader.SetParameter(New RParameter("header", 1))
Expand All @@ -78,18 +79,24 @@ Public Class dlgPasteNewColumns
ucrChkKeepExstingCols.SetParameter(New RParameter("use_col_name_as_prefix", 2))
ucrChkKeepExstingCols.SetValuesCheckedAndUnchecked("TRUE", "FALSE")
'----------------------------
ucrChkSpaceSeperated.SetText("Space Separated")
ucrChkSpaceSeperated.AddParameterValuesCondition(True, "sep", "True")
ucrChkSpaceSeperated.AddParameterValuesCondition(False, "sep", "False")

ucrNudPreviewLines.Minimum = 10
End Sub

Private Sub SetDefaults()
clsImportColsToExistingDFRFunction = New RFunction
clsReadClipDataRFunction = New RFunction
clsDummyFunction = New RFunction

ucrNudPreviewLines.Value = 10
ucrSaveNewDFName.Reset()
ucrDFSelected.Reset()

clsDummyFunction.AddParameter("sep", "False", iPosition:=0)

'todo. some clip data values work well with read_delim R function.
'that's why readr references have been left here for future testing and reference.
'clsReadClipDataRFunction.SetPackageName("readr")
Expand All @@ -114,6 +121,7 @@ Public Class dlgPasteNewColumns

ucrDFSelected.SetRCode(clsImportColsToExistingDFRFunction, bReset)
ucrChkKeepExstingCols.SetRCode(clsImportColsToExistingDFRFunction, bReset)
ucrChkSpaceSeperated.SetRCode(clsDummyFunction, bReset)

ucrPnl.SetRCode(ucrBase.clsRsyntax.clsBaseFunction, bReset)
End Sub
Expand Down Expand Up @@ -158,6 +166,14 @@ Public Class dlgPasteNewColumns
Return False
End If

' Disable "Space Separated" only if user didn't check it manually
If dfTemp.ColumnCount > 1 AndAlso Not ucrChkSpaceSeperated.Checked Then
ucrChkSpaceSeperated.Checked = False ' Uncheck if more than one column
ucrChkSpaceSeperated.Enabled = False ' Disable it
Else
ucrChkSpaceSeperated.Enabled = True ' Allow user to enable it
End If

'preview data
frmMain.clsGrids.FillSheet(dfTemp, "temp", grdDataPreview, bIncludeDataTypes:=False, iColMax:=frmMain.clsGrids.iMaxCols, iRowMax:=ucrNudPreviewLines.Value)
lblConfirmText.Text = "Columns: " & dfTemp.ColumnCount & " | Rows: " & dfTemp.RowCount & Environment.NewLine & "Click Ok to paste data."
Expand Down Expand Up @@ -214,10 +230,10 @@ Public Class dlgPasteNewColumns
End If
End Sub

Private Sub ucrControls_ControlContentsChanged(ucrchangedControl As ucrCore) Handles ucrDFSelected.ControlContentsChanged, ucrSaveNewDFName.ControlContentsChanged, ucrChkKeepExstingCols.ControlContentsChanged
Private Sub ucrControls_ControlContentsChanged(ucrchangedControl As ucrCore) Handles ucrDFSelected.ControlContentsChanged, ucrSaveNewDFName.ControlContentsChanged, ucrChkKeepExstingCols.ControlContentsChanged, ucrChkSpaceSeperated.ControlContentsChanged
If bValidatePasteData Then
'disabled unnecessary validation of copied data because it may take long for large datasets
TestOkEnabled(bValidateCopiedData:=ucrchangedControl IsNot ucrSaveNewDFName AndAlso ucrchangedControl IsNot ucrDFSelected AndAlso ucrchangedControl IsNot ucrChkKeepExstingCols)
TestOkEnabled(bValidateCopiedData:=ucrchangedControl IsNot ucrSaveNewDFName AndAlso ucrchangedControl IsNot ucrDFSelected AndAlso ucrchangedControl IsNot ucrChkKeepExstingCols AndAlso ucrchangedControl IsNot ucrChkSpaceSeperated)
End If
End Sub

Expand All @@ -230,4 +246,15 @@ Public Class dlgPasteNewColumns
TestOkEnabled()
End Sub

Private Sub ucrChkSpaceSeperated_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkSpaceSeperated.ControlValueChanged
If ucrChkSpaceSeperated.Checked Then
clsReadClipDataRFunction.AddParameter("sep", Chr(34) & "" & Chr(34), iPosition:=2)
clsDummyFunction.AddParameter("sep", "True", iPosition:=1)
Else
clsReadClipDataRFunction.RemoveParameterByName("sep")
clsDummyFunction.AddParameter("sep", "False", iPosition:=0)
End If
TestOkEnabled(True)
End Sub

End Class
Loading

0 comments on commit 93eecae

Please sign in to comment.