アラートダイアログ上にTabViewとPopup Buttonを表示して、Popup Menuの選択状況に合わせてTabViewの表示ビューを切り替え、Popup Menuの選択アイテムを1はじまりの番号で返すAppleScriptです。
最終的には各TabViewItem内にCustomViewを生成して、各種データ(TableとかWebとかImageとか)を一覧から選択するようなUI部品として使い回すつもりです。
このバージョンではTabViewのタブが表示状態になっていますが、最終的にはタブレスのTabViewとして表示することになります。
AppleScript名:アラートダイアログ上にTab View+Popup Buttonを表示して切り替え |
— – Created by: Takaaki Naganoya – Created on: 2019/09/16 — – Copyright © 2019 Piyomaru Software, All Rights Reserved — use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AppKit" property NSView : a reference to current application’s NSView property NSAlert : a reference to current application’s NSAlert property NSMenu : a reference to current application’s NSMenu property NSTabView : a reference to current application’s NSTabView property NSMenuItem : a reference to current application’s NSMenuItem property NSTabViewItem : a reference to current application’s NSTabViewItem property NSPopUpButton : a reference to current application’s NSPopUpButton property NSRunningApplication : a reference to current application’s NSRunningApplication property TabPosition : 0 —0=Top, 1=Left, 2=Bottom, 3=Right, 4=None property returnCode : 0 property aTabV : missing value property selectedNum : 1 set paramObj to {myMessage:"Main Message", mySubMessage:"Sub information", viewWidth:500, viewHeight:300} –my dispTextViewWithAlertdialog:paramObj –for debug my performSelectorOnMainThread:"dispTabViewWithAlertdialog:" withObject:paramObj waitUntilDone:true return selectedNum on dispTabViewWithAlertdialog:paramObj –Receive Parameters set aMainMes to (myMessage of paramObj) as string –Main Message set aSubMes to (mySubMessage of paramObj) as string –Sub Message set aWidth to (viewWidth of paramObj) as integer –TextView width set aHeight to (viewHeight of paramObj) as integer –TextView height set selectedNum to 0 set aView to NSView’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 0, aWidth, aHeight)) –Ppopup Buttonをつくる set a1Button to NSPopUpButton’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, aHeight – 20, 400, 20)) pullsDown:false a1Button’s removeAllItems() set a1Menu to NSMenu’s alloc()’s init() repeat with i from 1 to 8 set aTitle to "Selection #" & (i as string) set aMenuItem to (NSMenuItem’s alloc()’s initWithTitle:aTitle action:"actionHandler:" keyEquivalent:"") (aMenuItem’s setEnabled:true) (aMenuItem’s setTarget:me) (aMenuItem’s setTag:(i as string)) (a1Menu’s addItem:aMenuItem) end repeat a1Button’s setMenu:a1Menu –Make Tab View set aTabV to NSTabView’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 0, aWidth, aHeight – 30)) aTabV’s setTabViewType:(TabPosition) aTabV’s setTabViewType:(TabPosition) repeat with i from 1 to 8 set aTVItem to (NSTabViewItem’s alloc()’s initWithIdentifier:(i as string)) (aTVItem’s setLabel:(i as string)) –make custom view within a tab view item here (aTabV’s addTabViewItem:aTVItem) end repeat aView’s setSubviews:{a1Button, aTabV} aView’s setNeedsDisplay:true — set up alert set theAlert to NSAlert’s alloc()’s init() tell theAlert –for Messages its setMessageText:(aMainMes) its setInformativeText:(aSubMes) –for Buttons its addButtonWithTitle:"OK" its addButtonWithTitle:"Cancel" –Add Accessory View its setAccessoryView:(aView) –for Help Button its setShowsHelp:(true) its setDelegate:(me) end tell — show alert in modal loop NSRunningApplication’s currentApplication()’s activateWithOptions:0 my performSelectorOnMainThread:"doModal:" withObject:(theAlert) waitUntilDone:true if (my returnCode as number) = 1001 then error number -128 set selectedNum to (a1Button’s indexOfSelectedItem()) + 1 end dispTabViewWithAlertdialog: on doModal:aParam set (my returnCode) to aParam’s runModal() end doModal: on alertShowHelp:aNotification display dialog "Help Me!" buttons {"OK"} default button 1 with icon 1 return false –trueを返すと親ウィンドウ(アラートダイアログ)がクローズする end alertShowHelp: –Popup Action Handler on actionHandler:sender set aTag to tag of sender as integer aTabV’s selectTabViewItemAtIndex:(aTag – 1) end actionHandler: |