Page 1 of 1

How distinguish OK from Cancel when saving?

Posted: Thu May 28, 2015 7:56 am
by Dr.Sol
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):

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
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?

Re: How distinguish OK from Cancel when saving?

Posted: Sat Jun 13, 2015 3:06 pm
by crap_inhuman
I think this is a bug.

"A function from ScriptFile that is called when edited tracks(s) are to be saved (closed by OK button)"

Savesheet sub should not be called when cancel

Posted: Mon Jun 15, 2015 5:18 am
by Dr.Sol
I thought it was my lack of knowledge making this happening, but got a answer that it might be a bug. And maybe it is? (I use an old stable version, build 1703)

Re: Savesheet sub should not be called when cancel

Posted: Wed Jun 24, 2015 12:52 pm
by crap_inhuman
Dr.Sol wrote:I thought it was my lack of knowledge making this happening, but got a answer that it might be a bug. And maybe it is? (I use an old stable version, build 1703)
I just tested it with a small script, both buttons (ok and cancel) start the savesheet procedure. I have build 1736.
You should post it on the bug-page or open a support ticket, but do not expect too much. I'm a bit disappointed with the speed of ticket processing or removing bugs which i have reported...

Re: How distinguish OK from Cancel when saving?

Posted: Wed Jun 24, 2015 1:11 pm
by Lowlander