LoginSignup
8

More than 5 years have passed since last update.

Visual Studio for Macで簡単に複数ウインドウを開けるようにする

Posted at

はじめに

Visual Studio for Mac は複数のウインドウを開けなくて不便(´・ω・`)
という意見をチラホラと見かけます。
確かに不便なので、簡単に複数のウインドウを開けるようにしてみたいと思います。

できたもの

ファイル メニューの一番下に 新しいウインドウを開く メニューを追加しました。
(Open new window というものです)

Screen Shot 2017-12-23 at 0.04.00.png

このメニューの項目を押すと、新しいウインドウが開きます。

Screen Shot 2017-12-23 at 0.04.15.png

作成の流れ

今回やった流れは下記です。
VS for Macの拡張機能だけで実現できそうですが、
サクッとできなかったので、1と2をやりました。

  1. 新しいウインドウでVS for Macを開けるシェルスクリプトを書く
  2. 1のシェルスクリプトをアプリケーションバンドルにする
  3. VS for Macの拡張機能を作る
  4. 使う ∩(´∀`)∩

作る

1. 新しいウインドウでVS for Macを開けるシェルスクリプトを書く

ここでは、RunVS.sh として保存しました。

#!/bin/sh

open -n /Applications/Visual\ Studio.app/

2. 1のシェルスクリプトをアプリケーションバンドルにする

まず、アプリケーションバンドル化するディレクトリを作成します。
ここでは、RunVS.app という名前で作成しました。

次に、その中身を以下のディレクトリ構成にします。
Screen Shot 2017-12-24 at 22.20.34.png

Resourcesディレクトリの中身は空です。

Info.plistの中身は以下です。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>CFBundleExecutable</key>
    <string>RunVS.sh</string>
  </dict>
</plist>

RunVS.sh に実行属性を付与します。

chmod +x ./RunVS.app/Contents/MacOS/RunVS.sh

これで、通常のアプリケーションと同じように実行できるアプリケーションバンドルができます。
※これを実行すると、新しいウインドウでVS for Macが起動します。
Screen Shot 2017-12-24 at 22.26.23.png

3. VS for Macの拡張機能を作る

2で作成したものを VS for Mac から実行できるように拡張機能を作成します。
拡張の機能の作り方そのものは、こちらの投稿 などを参考にしてください。

Manifest.addin.xml
メニューのファイルに Open new window という名前で追加します。

<?xml version="1.0" encoding="UTF-8"?>
   <ExtensionModel>
       <Extension path = "/MonoDevelop/Ide/Commands/File">
           <Command id = "extention.RunVSCommands.RunVS"
               _label = "Open new window"
               defaultHandler = "extention.RunVSHandler" />
       </Extension>
       <Extension path = "/MonoDevelop/Ide/MainMenu/File">
           <CommandItem id="extention.RunVSCommands.RunVS" />
       </Extension>
   </ExtensionModel>

RunVSCommands.cs

namespace extention
{
    public enum RunVSCommands
    {
        RunVS,
    }
}

RunVSHandler.cs

2で作ったアプリケーションバンドルを実行させるだけの内容です。

using MonoDevelop.Components.Commands;
using AppKit;

namespace extention
{
   class RunVSHandler : CommandHandler
    {
        protected override void Run()
        {
            NSWorkspace.SharedWorkspace.LaunchApplication("/Applications/RunVS.app");
        }
    }
}

なお、アドインのパッケージ化はVS for Macの場合、以下のコマンドで行えます。

/Applications/Visual\ Studio.app/Contents/MacOS/vstool setup pack DLL名

4. 使う ∩(´∀`)∩

簡単にいっぱい開ける!
Screen Shot 2017-12-24 at 22.45.08.png

おわりに

2日ぐらい自分で使ってみましたが、メニューから新しいウインドウが開けると、
めっちゃ便利ですね(`・ω・´)

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8