Skip to content

Commit

Permalink
Merge pull request #9361 from N-thony/trigger_auto_save
Browse files Browse the repository at this point in the history
Auto-Saving Data: Triggering Saves Only on Data Changes
  • Loading branch information
Patowhiz authored Feb 3, 2025
2 parents a61c374 + d9fc04a commit 04a18e2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
1 change: 1 addition & 0 deletions instat/Model/DataFrame/clsDataFrame.vb
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ Public Class clsDataFrame
Else
bRefreshed = False
End If
_clsVisibleDataFramePage.HasDataChangedForAutoSave = True
End If
_clsColumnMetaData.RefreshData()
Return bRefreshed
Expand Down
15 changes: 15 additions & 0 deletions instat/Model/DataFrame/clsDataFramePage.vb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Public Class clsDataFramePage
Private _lstColumns As List(Of clsColumnHeaderDisplay)
Private _hasChanged As Boolean
Private _useColumnSelectionInDataView As Boolean
Private _HasDataChangedForAutoSave As Boolean

Private ReadOnly Property iColumnIncrements As Integer
Get
Expand Down Expand Up @@ -140,6 +141,19 @@ Public Class clsDataFramePage
End Set
End Property

''' <summary>
''' holds whether the dataframe is different from visual grid component and trigger auto save
''' </summary>
''' <returns></returns>
Public Property HasDataChangedForAutoSave() As Boolean
Get
Return _HasDataChangedForAutoSave
End Get
Set(ByVal value As Boolean)
_HasDataChangedForAutoSave = value
End Set
End Property

''' <summary>
''' Create a new instance of a dataframe page
''' </summary>
Expand All @@ -152,6 +166,7 @@ Public Class clsDataFramePage
_iColumnStart = 1
_iRowStart = 1
_hasChanged = True
_HasDataChangedForAutoSave = True
_useColumnSelectionInDataView = True
End Sub

Expand Down
5 changes: 3 additions & 2 deletions instat/frmMain.vb
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ Public Class frmMain
Dim strCurrentStatus As String

strCurrentStatus = tstatus.Text
If clsRLink.bInstatObjectExists Then
If clsRLink.bInstatObjectExists AndAlso ucrDataViewer.HasDataChanged Then
tstatus.Text = GetTranslation("Auto saving data...")
Cursor = Cursors.WaitCursor
If Not Directory.Exists(strAutoSaveDataFolderPath) Then
Expand All @@ -1196,7 +1196,7 @@ Public Class frmMain
strTempFile = "data_" & DateTime.Now.ToString("yyyyMMdd_HHmmss") & ".rds"
strCurrentAutoSaveDataFilePath = Path.Combine(strAutoSaveDataFolderPath, strTempFile)

Dim strBackupMessage As String = $"##########{vbCrLf}## Backing up data and log files on: {DateTime.Now}{vbCrLf}##########"
Dim strBackupMessage As String = $"##########{vbCrLf}## Backing up data and metadata on: {DateTime.Now}{vbCrLf}##########"
Me.ucrScriptWindow.LogText(strBackupMessage)
clsRLink.AppendToAutoSaveLog(strBackupMessage)

Expand All @@ -1208,6 +1208,7 @@ Public Class frmMain
tstatus.Text = strCurrentStatus
Cursor = Cursors.Default
bFirstBackupDone = True
ucrDataViewer.HasDataChanged = False
End If
End Sub

Expand Down
19 changes: 19 additions & 0 deletions instat/ucrDataView.vb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Public Class ucrDataView
Private _clsDataBook As clsDataBook
Private _grid As IDataViewGrid
Private bOnlyUpdateOneCell As Boolean = False
Private _hasChanged As Boolean

Public WriteOnly Property DataBook() As clsDataBook
Set(value As clsDataBook)
Expand Down Expand Up @@ -157,6 +158,7 @@ Public Class ucrDataView
RefreshDisplayInformation()
End If
End If
_hasChanged = True
EnableDisableUndoMenu()
_grid.Focus()
End Sub
Expand Down Expand Up @@ -185,6 +187,23 @@ Public Class ucrDataView
Return If(_grid.CurrentWorksheet Is Nothing, Nothing, _grid.CurrentWorksheet.Name)
End Function

Public Property HasDataChanged() As Boolean
Get
Dim currentDataFrame = GetCurrentDataFrameFocus()
If currentDataFrame IsNot Nothing AndAlso currentDataFrame.clsVisibleDataFramePage IsNot Nothing Then
Return currentDataFrame.clsVisibleDataFramePage.HasDataChangedForAutoSave
End If
Return False ' Or a default value
End Get
Set(ByVal value As Boolean)
Dim currentDataFrame = GetCurrentDataFrameFocus()
If currentDataFrame IsNot Nothing AndAlso currentDataFrame.clsVisibleDataFramePage IsNot Nothing Then
currentDataFrame.clsVisibleDataFramePage.HasDataChangedForAutoSave = value
End If
' Optionally handle the case where currentDataFrame is Nothing
End Set
End Property

Private Sub mnuDeleteCol_Click(sender As Object, e As EventArgs) Handles mnuDeleteCol.Click
If GetSelectedColumns.Count = GetCurrentDataFrameFocus()?.iTotalColumnCount Then
MsgBox("Cannot delete all visible columns." & Environment.NewLine & "Use Prepare > Data Object > Delete Data Frame if you wish to delete the data.", MsgBoxStyle.Information, "Cannot Delete All Columns")
Expand Down

0 comments on commit 04a18e2

Please sign in to comment.