' ' MediaMonkey Script ' ' NAME: Incremental Search 1.0 [MM3] ' AUTHOR: Kawauso ' DATE: Feb, 20, 2008 ' ' INSTALL: Copy this code and save to 'Scripts/Auto' directory. ' ' NOTE: All checkboxes are checked by default. ' You can change it by setting following three const variables. ' '10/04/25 補助検索用スクリプトに改変 'タイトルをSub Searchに変更 '検索範囲条件のチェックボックスを追加(アルバムアーティスト、ファイルパス) 'AND検索のチェックボックスを追加 'インクリメンタルではなく、検索開始のトリガをボタン押下に変更 '空白で区切った場合は各単語をAND,もしくはOR条件として検索するよう変更 ' ' ' ' Const ARTIST_DEFAULT_CHECK = True Const ALBUM_DEFAULT_CHECK = True Const TITLE_DEFAULT_CHECK = True Const ALBUM_ARTIST_DEFAULT_CHECK = False Const FILENAME_DEFAULT_CHECK = True Const ANDSERACH_DEFAULT_CHECK = True Dim Tree, Node, Mnu, Pnl, Edt, ChkArtist, ChkAlbum, ChkSongTitle, ChkAlbumArtist, Btn, ChkFilename, ChkAndOr Sub OnStartup Set UI = SDB.UI Set Tree = SDB.MainTree Set Node = Tree.CreateNode Node.Caption = "Sub Search" Node.IconIndex = 24 Node.SortGroup = 1 Tree.AddNode Tree.Node_Library, Node, 0 Script.RegisterEvent Node, "OnNodeFocused", "QuerySearch" Set Pnl = UI.NewDockablePersistentPanel("SubSearch") Pnl.DockedTo = 1 Pnl.Common.Width = 200 Pnl.Common.Height = 45 Pnl.Caption = "Sub Search" Script.RegisterEvent Pnl, "OnClose", "PnlClose" '--- Add menu item that shows panel after it is closed --- Set Sep = SDB.UI.AddMenuItemSep(SDB.UI.Menu_View,0,0) Set Mnu = SDB.UI.AddMenuItem(SDB.UI.Menu_View,0,0) Mnu.Caption = "Sub Search" Mnu.Checked = Pnl.Common.Visible Script.RegisterEvent Mnu, "OnClick", "ShowPanel" '--- Add edit and checkbox to panel --- Set Edt = UI.NewEdit(Pnl) Edt.Common.SetRect 2, 2, Pnl.Common.ClientWidth-4, 10 Edt.Common.Anchors = 7 'Script.RegisterEvent Edt, "OnChange", "OnEditBoxChange" Set Btn = UI.NewButton(Pnl) Btn.UseScript = Script.ScriptPath Btn.OnClickFunc = "OnEditBoxChange" With Btn .Common.SetRect Pnl.Common.ClientWidth-37,2 , 37, 20 .Caption = "検索" .Common.Anchors = 6 End WIth Set ChkArtist = UI.NewCheckBox(Pnl) Script.RegisterEvent ChkArtist.Common, "OnClick", "OnEditBoxChange" With ChkArtist .Caption = "Artist" .Checked = ARTIST_DEFAULT_CHECK .Common.SetRect 6, 24, Pnl.Common.ClientWidth-4, 20 .Common.Anchors = 7 End With Set ChkAlbum = UI.NewCheckBox(Pnl) Script.RegisterEvent ChkAlbum.Common, "OnClick", "OnEditBoxChange" With ChkAlbum .Caption = "Album" .Checked = ALBUM_DEFAULT_CHECK .Common.SetRect 60, 24, Pnl.Common.ClientWidth-4, 20 .Common.Anchors = 7 End With Set ChkSongTitle = UI.NewCheckBox(Pnl) Script.RegisterEvent ChkSongTitle.Common, "OnClick", "OnEditBoxChange" With ChkSongTitle .Caption = "Title" .Checked = TITLE_DEFAULT_CHECK .Common.SetRect 118, 24, Pnl.Common.ClientWidth-4, 20 .Common.Anchors = 7 End With Set ChkFilename = UI.NewCheckBox(Pnl) Script.RegisterEvent ChkFilename.Common, "OnClick", "OnEditBoxChange" With ChkFilename .Caption = "FilePath" .Checked = FILENAME_DEFAULT_CHECK .Common.SetRect 166, 24, Pnl.Common.ClientWidth-4, 20 .Common.Anchors = 7 End With Set ChkAlbumArtist = UI.NewCheckBox(Pnl) Script.RegisterEvent ChkAlbumArtist.Common, "OnClick", "OnEditBoxChange" With ChkAlbumArtist .Caption = "Album Artist" .Checked = ALBUM_ARTIST_DEFAULT_CHECK .Common.SetRect 238, 24, Pnl.Common.ClientWidth-4, 20 .Common.Anchors = 7 End With Set ChkAndOr = UI.NewCheckBox(Pnl) Script.RegisterEvent ChkAndOr.Common, "OnClick", "OnEditBoxChange" With ChkAndOr .Caption = "AND検索" .Checked = ANDSERACH_DEFAULT_CHECK .Common.SetRect 6, 48, Pnl.Common.ClientWidth-4, 20 .Common.Anchors = 7 End With End Sub Sub QuerySearch( Item) Pnl.Common.Visible = True Mnu.Checked = True Dim Tw : Set Tw = SDB.MainTracksWindow Dim StrSQL : StrSQL = "" Dim StrKey : StrKey = Replace(Edt.Text, "'", "''") StrKey = Replace(StrKey," "," ") Dim StrOrder : StrOrder = "ORDER BY Artist" If StrKey <> "" Then Dim StrKeys : StrKeys = split(StrKey," ") Dim StrAndOr If ChkAndOr.Checked Then StrAndOr = "AND" Else StrAndOr = "OR" End If 'StrKey = Left(StrKey, Len(StrKey)-1) 'If ChkArtist.Checked Then StrSQL = StrSQL & GetLikeSQL("Artist",StrKeys,StrAndOr) 'If ChkAlbum.Checked Then StrSQL = StrSQL & GetLikeSQL("Album",StrKeys,StrAndOr) 'If ChkSongTitle.Checked Then StrSQL = StrSQL & GetLikeSQL("SongTitle",StrKeys,StrAndOr) 'If ChkAlbumArtist.Checked Then StrSQL = StrSQL & GetLikeSQL("AlbumArtist",StrKeys,StrAndOr) 'If ChkFilename.Checked Then StrSQL = StrSQL & GetLikeSQL("SongPath",StrKeys,StrAndOr) StrSQL = GetSQL(StrKeys,StrAndOr) If Len(StrSQL) <> 0 Then StrSQL = "WHERE " & StrSQL 'Left(StrSQL, Len(StrSQL)-3) Else StrSQL = "WHERE ID = -1 " End If Tw.AddTracksFromQuery(StrSQL & StrOrder) Tw.FinishAdding Else Tw.AddTracksFromQuery(StrOrder) Tw.FinishAdding End If End Sub Sub ShowPanel( Item) Pnl.Common.Visible = not Pnl.Common.Visible Mnu.Checked = Pnl.Common.Visible End Sub Sub PnlClose( Item) Mnu.Checked = false End Sub Sub OnEditBoxChange( Item) If Tree.CurrentNode.Caption = Node.Caption And Edt.Text <> "" Then 'And Right(Edt.Text, 1) = "\" Then SDB.MainTracksWindow.Refresh Else Tree.CurrentNode = Node End If End Sub Function GetLikeSQL(SearchType,StrKeys,StrAnd) Dim strSQL : strSQL = "" For Each Key In StrKeys If (key <> "" ) Then If (Len(strSQL) > 0) Then strSQL = strSQL & " " & StrAnd & " " strSQL = strSQL & SearchType & " LIKE '%" & key & "%' " End If Next If strSQL <> "" Then GetLikeSQL = "(" & strSQL & ") OR " Else GetLikeSQL = "" End If End Function Function GetSQL(strKeys,strAnd) Dim MainSQL : MainSQL = "" Dim PartSQL For Each Key In strKeys PartSQL = "" If (key <> "" ) Then If ChkArtist.Checked Then PartSQL = PartSQL & "Artist LIKE '%" & key & "%' OR " If ChkAlbum.Checked Then PartSQL = PartSQL & "Album LIKE '%" & key & "%' OR " If ChkSongTitle.Checked Then PartSQL = PartSQL & "SongTitle LIKE '%" & key & "%' OR " If ChkAlbumArtist.Checked Then PartSQL = PartSQL & "AlbumArtist LIKE '%" & key & "%' OR " If ChkFilename.Checked Then PartSQL = PartSQL & "SongPath LIKE '%" & key & "%' OR " If Len(PartSQL) > 0 Then If (Len(MainSQL) > 0) Then MainSQL = MainSQL & " " & strAnd & " " PartSQL = Left(PartSQL, Len(PartSQL) - 3) MainSQL = MainSQL & "(" & PartSQL & ") " End If End If Next GetSQL = MainSQL End Function