How distinguish OK from Cancel when saving?
Posted: Thu May 28, 2015 7:56 am
Is it possible to distinguish OK button from Cancel button for a script using the file property dialogue when closing?
This example code illustrates the problem (coming from the MM wiki at http://www.mediamonkey.com/wiki/index.p ... rtiesSheet):
The problem is that SaveSheet is executed both when Cancel and OK buttons are pressed. I don't want to save when cancel is pressed but I don't know how to differ them.
Any suggestions on how making a difference between them?
This example code illustrates the problem (coming from the MM wiki at http://www.mediamonkey.com/wiki/index.p ... rtiesSheet):
Code: Select all
Option Explicit
Sub OnStartUp
Dim i : i = SDB.UI.AddPropertiesSheet("Sample sheet", Script.ScriptPath, "InitSheet", "TrackChange", "SaveSheet", 2)
End Sub
Sub InitSheet(Sheet)
Dim UI : Set UI = SDB.UI
Dim ini : Set ini = SDB.IniFile
Dim a : Set a = UI.NewGroupBox(Sheet) : a.Caption = "Settings" : a.Common.SetRect 10, 10, 230, 210
Dim ch
Set ch = UI.NewCheckbox(a)
ch.Common.SetRect 15, 20, 250, 20
ch.Common.ControlName = "CheckBox1"
ch.Caption = "Update to ini file"
ch.Checked = true
Dim e
Set e = UI.NewEdit(a)
e.Common.SetRect 15, 50, 250, 50
e.Common.ControlName = "EditBox1"
e.Text = "Song Title"
e.Common.Enabled = True
SDB.Objects("EditBox1") = e
End Sub
Sub TrackChange( Object, ObjectType)
Dim e: Set e = SDB.Objects("EditBox1")
If ObjectType = 0 then ' it is just Song
e.Text = Object.Title
End If
If ObjectType = 1 then ' it is SongList
e.Text = Object.Count & " songs selected"
End If
End Sub
Sub SaveSheet(Sheet, Object, ObjectType)
Dim ini : Set ini = SDB.IniFile
If ObjectType = 0 then ' it is just Song
If Sheet.Common.ChildControl("CheckBox1").Checked then
ini.StringValue("SampleScript", "Updated Song") = Object.Title
End If
End If
If ObjectType = 1 then ' it is SongList
If Sheet.Common.ChildControl("CheckBox1").Checked then
Dim i
For i = 0 to Object.Count-1
ini.StringValue("SampleScript", "Updated Songs - Song " & i ) = Object.Item(i).Title
Next
End If
End If
End Sub
Any suggestions on how making a difference between them?