Xcodeでは、対応するヘッダ/ソースファイルを別ウィンドウで開かない
- 同じウィンドウで開かれてしまうので不便極まりない。
- ウィンドウの位置という概念がないのか?このファイルは小さくこの辺に表示したいなどといった欲求を踏みにじる機能となってしまっている。
- 設定で解消!
- Xcodeの環境設定の、全般の、対応する要素を同じエディタで開く、についているチェックを外すと、自作AppleScriptを使わなくてもヘッダーファイルを開いたときなどに新しいウィンドウを開いてくれるようになった。
- 以下は設定で解決できることを知らなかったときにとった対応策。
- 無駄に時間かけてしまったな... そもそも別エディタで開く設定になっていろよな、ったく。
tell application "Xcode"
activate
set targetWin to window 1 -- 1番フロントのウィンドウ以外は「敢えて」見ない
set fname to associated file name of targetWin -- エディタウィンドウかどうかの確認用
if fname ends with ".cpp" or fname ends with ".h" or fname ends with ".hpp" then
if visible of targetWin then
set wname to name of targetWin -- 具体的なファイル名
if wname ends with ".cpp" then
set fname to my replace(wname, ".cpp", ".h") -- ソース⇒ヘッダ
else if wname ends with ".h" then
set fname to my replace(wname, ".h", ".cpp") -- ヘッダ⇒ソース
else if wname ends with ".hpp" then
set fname to my replace(wname, ".hpp", ".cpp") -- ヘッダ?⇒ソース
end if
try
set oldClip to the clipboard -- 古いクリップボードを保存しておく
on error
set the clipboard to "" -- 空っぽのクリップボードを作成
set oldClip to the clipboard -- oldClipは後で使うので空っぽを保存
end try
set the clipboard to fname
tell application "System Events"
tell process "Xcode"
keystroke "d" using {command down} --コマンド+D「すばやく開く」
delay 0.1 -- Xcodeが「すばやく開く」を開くまでにかかる時間
keystroke "v" using {command down}
delay 0.1 -- Xcodeがファイルを検索するのにかかる時間
delay 0.1 -- ユーザがコマンドキーから指を離すまでの時間
keystroke return -- ユーザがコマンドキー押しっぱなしだとエラー
end tell
end tell
set the clipboard to oldClip
end if
end if
end tell
(*文字列置換の一般的なコード*)
on replace(src, tg, rp)
set oldDel to text item delimiters of AppleScript -- オリジナルの区切り文字をとっておく
set text item delimiters of AppleScript to tg
set myList to text items of src
set text item delimiters of AppleScript to rp
set myText to myList as string
set text item delimiters of AppleScript to oldDel
return myText
end replace