オレブラウザを作る 14

2013年6月27日木曜日

AppleScript

t f B! P L
今回はコンテクストメニューについて。

オレブラウザの仕様はシングルウインドウアプリケーション。あとコンテンツのダウンロード機能はなしという形。

WebViewのコンテクストメニューはデフォルトで新しいウインドウを開く、リンク先を保存するというメニューが用意されている。



用意されているとその機能が実装されていると考えてしまうので不要なメニューを無くす事にする。

コンテクストメニューの構築はUIDelegateの webView_contextMenuItemsForElement_defaultMenuItems_ ハンドラで実現する。

on webView_contextMenuItemsForElement_defaultMenuItems_(sender,element,defaultMenuItems)
    set modifiedMenuItems to {}
    repeat with mItem in mutableCopy() of defaultMenuItems
        if tag() of mItem = 1 then -- new window
            --skip
        else if tag() of mItem = 2 then -- download link
            --skip
        else
            set the end of modifiedMenuItems to mItem
        end if
    end repeat
    return modifiedMenuItems
end


defaultMenuItemsを利用してコンテクストメニューを再構築していく。具体的にはdefaultMenuItemsのメニューアイテムのタグが1と2のメニュー以外で再構築する。

これで不要なメニューは表示されなくなった。もちろんここで独自メニューを追加していく事も可能。



今回はここまで。

このブログを検索

人気の投稿

ラベル

QooQ