How distinguish OK from Cancel when saving?

This forum is for questions / discussions regarding development of addons / tweaks for MediaMonkey.

Moderator: Gurus

Dr.Sol
Posts: 12
Joined: Thu Mar 20, 2014 2:24 am
Location: Sweden

How distinguish OK from Cancel when saving?

Post by Dr.Sol » 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):

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?
MM-Gold user since 2005

crap_inhuman
Posts: 679
Joined: Sat Jan 26, 2013 6:00 am
Location: Friedberg / Hessen / Germany
Contact:

Re: How distinguish OK from Cancel when saving?

Post by crap_inhuman » Sat Jun 13, 2015 3:06 pm

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)"
Metal up your ass !
-----------------------------------------------
I added my first 2 videos on youtube. The language is german.

Discogs Autorisierung: https://www.youtube.com/watch?v=oryxKKtnEnc
Discogs Tagger Bedienung: https://www.youtube.com/watch?v=85Wk-5rd-W0

Dr.Sol
Posts: 12
Joined: Thu Mar 20, 2014 2:24 am
Location: Sweden

Savesheet sub should not be called when cancel

Post by Dr.Sol » Mon Jun 15, 2015 5:18 am

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)
MM-Gold user since 2005

crap_inhuman
Posts: 679
Joined: Sat Jan 26, 2013 6:00 am
Location: Friedberg / Hessen / Germany
Contact:

Re: Savesheet sub should not be called when cancel

Post by crap_inhuman » Wed Jun 24, 2015 12:52 pm

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...
Metal up your ass !
-----------------------------------------------
I added my first 2 videos on youtube. The language is german.

Discogs Autorisierung: https://www.youtube.com/watch?v=oryxKKtnEnc
Discogs Tagger Bedienung: https://www.youtube.com/watch?v=85Wk-5rd-W0

Lowlander
Posts: 45838
Joined: Sat Sep 06, 2003 5:53 pm
Location: MediaMonkey 5

Re: How distinguish OK from Cancel when saving?

Post by Lowlander » Wed Jun 24, 2015 1:11 pm

Lowlander (MediaMonkey user since 2003)

Post Reply