Ejemplo n.º 1
0
        public void OnDropDownItemClick(ToolStripItem item, MouseButtons mouseButton)
        {
            // user clicked the dropdown menu item of this plugin button dropdown.

            if (item.Text == "´ò¿ªÎļþ¼Ð")
            {
                if (mouseButton == MouseButtons.Left)
                {
                    string mydocument = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                    pluginServer.CreateTab(new Address(mydocument), -1, false, true);
                }
                else if (mouseButton == MouseButtons.Right)
                {
                    SystemSounds.Asterisk.Play();
                }
            }
            else if (item.Text == "²âÊÔÑ¡ÖÐ")
            {
                if (lstSelectedItems.Count > 0)
                {
                    pluginServer.TrySetSelection(lstSelectedItems.ToArray(), false);
                }
            }
            else if (item.Text == "²âÊÔ±êÇ©Ëø¶¨×´Ì¬")
            {
                MessageBox.Show("²âÊÔ±êÇ©Ëø¶¨×´Ì¬");
                ITab[] tabs = pluginServer.GetTabs();
                foreach (ITab iTab in tabs)
                {
                    MessageBox.Show("" + iTab.Address.Path + "->" + iTab.Locked);
                }
            }
        }
Ejemplo n.º 2
0
        public void OnDropDownItemClick(ToolStripItem item, MouseButtons mouseButton)
        {
            // user clicked the dropdown menu item of this plugin button dropdown.

            if (item.Text == "Open folder")
            {
                if (mouseButton == MouseButtons.Left)
                {
                    string mydocument = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                    pluginServer.CreateTab(new Address(mydocument), -1, false, true);
                }
                else if (mouseButton == MouseButtons.Right)
                {
                    SystemSounds.Asterisk.Play();
                }
            }
            else if (item.Text == "Test selection")
            {
                if (lstSelectedItems.Count > 0)
                {
                    pluginServer.TrySetSelection(lstSelectedItems.ToArray(), false);
                }
            }
        }
Ejemplo n.º 3
0
        public void OnDropDownItemClick(ToolStripItem item, MouseButtons mouseButton)
        {
            // user clicked the dropdown menu item of this plugin button dropdown.

            int    idx  = menu.Items.IndexOf(item);
            string path = null;

            if (mouseButton == MouseButtons.Left)
            {
                switch (idx)
                {
                case 0: {
                    // 0. 我的文档
                    path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                    break;
                }

                case 1: {
                    // 1. 系统
                    if (IsWin7)
                    {
                        path = "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{BB06C0E4-D293-4F75-8A90-CB05B6477EEE}";
                        string spa_exe = Environment.GetEnvironmentVariable("systemroot") + "\\System32\\SystemPropertiesAdvanced.exe";
                        Process.Start(spa_exe);
                        return;
                    }
                    else if (IsXP)
                    {
                    }
                    //path = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}";
                    break;
                }

                case 2: {
                    // 2. 显示
                    if (IsWin7)
                    {
                        path = "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{ED834ED6-4B5A-4BFE-8F11-A626DCB6A921}";
                    }
                    else if (IsXP)
                    {
                        path = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}";
                    }
                    break;
                }

                case 3:
                {
                    // 3. 网络连接
                    if (IsWin7)
                    {
                        path = "::{7007ACC7-3202-11D1-AAD2-00805FC1270E}";
                    }
                    else if (IsXP)
                    {
                        path = "::{7007ACC7-3202-11D1-AAD2-00805FC1270E}";
                    }
                    break;
                }

                case 444: {
                    string selectedPath = pluginServer.SelectedTab.Address.Path;
                    string binPath      = Path.Combine(selectedPath, "bin");
                    string libPath      = Path.Combine(selectedPath, "lib");
                    string toolsJar     = Path.Combine(libPath, "tools.jar");
                    string dtJar        = Path.Combine(libPath, "dt.jar");


                    if (String.IsNullOrEmpty(selectedPath) || !Directory.Exists(selectedPath))
                    {
                        MessageBox.Show("当前目录已经删除");
                        QTUtility.SoundPlay();
                        return;
                    }


                    if (String.IsNullOrEmpty(binPath) || !Directory.Exists(binPath))
                    {
                        MessageBox.Show("bin目录不存在");
                        QTUtility.SoundPlay();
                        return;
                    }



                    if (String.IsNullOrEmpty(libPath) || !Directory.Exists(libPath))
                    {
                        MessageBox.Show("lib目录不存在");
                        QTUtility.SoundPlay();
                        return;
                    }

                    using (var envKey = Registry.LocalMachine.OpenSubKey(REG_ENV_PATH, true))
                    {
                        string oldPath = getOldPath(envKey);
                        envKey.SetValue("JAVA_HOME", selectedPath);
                        envKey.SetValue("PATH", joinDevPath(oldPath));
                        if (File.Exists(toolsJar) && File.Exists(dtJar))
                        {
                            envKey.SetValue("CLASSPATH", @".;%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\dt.jar;");
                        }
                        SendNotifyMessage((IntPtr)HWND_BROADCAST, WM_SETTINGCHANGE, (UIntPtr)0, "Environment");
                        MessageBox.Show("设置JAVA_HOME成功");
                    }
                    break;
                }

                case 44:
                {
                    // 3. 设置当前目录JAVA_HOME
                    string selectedPath = pluginServer.SelectedTab.Address.Path;
                    string binPath      = Path.Combine(selectedPath, "bin");
                    string libPath      = Path.Combine(selectedPath, "lib");
                    string toolsJar     = Path.Combine(libPath, "tools.jar");
                    string dtJar        = Path.Combine(libPath, "dt.jar");


                    if (String.IsNullOrEmpty(selectedPath) || !Directory.Exists(selectedPath))
                    {
                        MessageBox.Show("当前目录已经删除");
                        QTUtility.SoundPlay();
                        return;
                    }


                    if (String.IsNullOrEmpty(binPath) || !Directory.Exists(binPath))
                    {
                        MessageBox.Show("bin目录不存在");
                        QTUtility.SoundPlay();
                        return;
                    }



                    if (String.IsNullOrEmpty(libPath) || !Directory.Exists(libPath))
                    {
                        MessageBox.Show("lib目录不存在");
                        QTUtility.SoundPlay();
                        return;
                    }

                    /*
                     *
                     * if(String.IsNullOrEmpty(toolsJar) || !File.Exists(toolsJar)) {
                     *  MessageBox.Show("toolsJar不存在");
                     *  QTUtility.SoundPlay();
                     *  return;
                     * }
                     *
                     *
                     *
                     * if(String.IsNullOrEmpty(toolsJar) || !File.Exists(dtJar)) {
                     *  MessageBox.Show("dtJar不存在");
                     *  QTUtility.SoundPlay();
                     *  return;
                     * }
                     */


                    //  Environment.SetEnvironmentVariable("JAVA_HOME", selectedPath, EnvironmentVariableTarget.Machine);
                    // Environment.SetEnvironmentVariable("CLASSPATH", @".;%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\dt.jar;", EnvironmentVariableTarget.Machine);
                    // 去重, 判断是否有 java home 删掉
                    string oldpath = filterEmpty("java.exe");
                    // Environment.SetEnvironmentVariable("PATH", @"%JAVA_HOME%\bin;" + oldpath, EnvironmentVariableTarget.Machine);


                    PowerShell.Create().AddCommand("setx")
                    .AddParameter("JAVA_HOME", selectedPath)
                    .AddParameter("/M")
                    .Invoke();
                    Thread.Sleep(800);


                    if (File.Exists(toolsJar) && File.Exists(dtJar))
                    {
                        PowerShell.Create().AddCommand("setx")
                        .AddParameter("CLASSPATH", @".;%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\dt.jar;")
                        .AddParameter("/M")
                        .Invoke();
                        Thread.Sleep(800);
                    }



                    PowerShell.Create().AddCommand("setx")
                    .AddParameter("PATH", @"%JAVA_HOME%\bin;" + oldpath)
                    .AddParameter("/M")
                    .Invoke();
                    Thread.Sleep(800);

                    MessageBox.Show("设置JAVA_HOME成功");
                    break;
                }

                case 55:
                {
                    // 5. 设置当前目录M2_HOME
                    string selectedPath = pluginServer.SelectedTab.Address.Path;
                    string binPath      = Path.Combine(selectedPath, "bin");
                    string mvnCmd       = Path.Combine(binPath, "mvn.cmd");


                    if (String.IsNullOrEmpty(selectedPath) || !Directory.Exists(selectedPath))
                    {
                        MessageBox.Show("当前目录已经删除");
                        QTUtility.SoundPlay();
                        return;
                    }


                    if (String.IsNullOrEmpty(binPath) || !Directory.Exists(binPath))
                    {
                        MessageBox.Show("bin目录不存在");
                        QTUtility.SoundPlay();
                        return;
                    }



                    if (String.IsNullOrEmpty(mvnCmd) || !File.Exists(mvnCmd))
                    {
                        MessageBox.Show("mvnCmd不存在");
                        QTUtility.SoundPlay();
                        return;
                    }

                    // Environment.SetEnvironmentVariable("M2_HOME", selectedPath, EnvironmentVariableTarget.Machine);

                    /*
                     * PowerShell.Create().AddCommand("setx")
                     *              .AddParameter("M2_HOME", selectedPath )
                     *              .AddParameter("/M")
                     *              .Invoke();
                     * Thread.Sleep(800);
                     *
                     * string oldpath = filterEmpty("mvn.cmd");
                     * //  Environment.SetEnvironmentVariable("PATH", @"%M2_HOME%\bin;" + oldpath, EnvironmentVariableTarget.Machine);
                     *
                     * PowerShell.Create().AddCommand("setx")
                     *                .AddParameter("PATH", @"%M2_HOME%\bin;" + oldpath)
                     *                .AddParameter("/M")
                     *                .Invoke();
                     * Thread.Sleep(800);
                     */

                    using (var envKey = Registry.LocalMachine.OpenSubKey(REG_ENV_PATH, true))
                    {
                        string oldPath = getOldPath(envKey);
                        envKey.SetValue("PATH", joinDevPath(oldPath));

                        envKey.SetValue("M2_HOME", selectedPath);

                        SendNotifyMessage((IntPtr)HWND_BROADCAST, WM_SETTINGCHANGE, (UIntPtr)0, "Environment");
                        MessageBox.Show("设置M2_HOME成功");
                    }
                    break;
                }

                case 4:
                {
                    // 4. 查看系统信息
                    string msinfo32 = Environment.GetEnvironmentVariable("systemroot") + "\\System32\\msinfo32.exe";
                    Process.Start(msinfo32);
                    break;
                }

                case 5:
                {
                    // 5. 重启资源管理器

                    /*
                     * foreach (Process p in Process.GetProcesses())
                     * {
                     *  if (p.MainModule.ModuleName.Contains("explorer") == true)
                     *      p.Kill();
                     * }
                     * Process.Start("explorer.exe");
                     */
                    IntPtr handle = GetWin10ExplorerWnd();
                    CloseExplorer(handle, 1);
                    // PInvoke.PostMessage(hwndExplr, WM.CLOSE, IntPtr.Zero, (IntPtr)nCode)
                    Thread.Sleep(800);
                    Process.Start("explorer.exe");
                    break;
                }

                case 6:
                {
                    // 6. 关机
                    IntPtr handle = GetShellTrayWnd();
                    CloseExplorer(handle, 1);
                    // PInvoke.PostMessage(hwndExplr, WM.CLOSE, IntPtr.Zero, (IntPtr)nCode)
                    Thread.Sleep(800);
                    break;
                }

                case 9:
                {
                    // 9. 设置当前目录ANT_HOME
                    string selectedPath = pluginServer.SelectedTab.Address.Path;
                    string binPath      = Path.Combine(selectedPath, "bin");
                    string antCmd       = Path.Combine(binPath, "ant.cmd");

                    if (String.IsNullOrEmpty(selectedPath) || !Directory.Exists(selectedPath))
                    {
                        MessageBox.Show("当前目录已经删除");
                        QTUtility.SoundPlay();
                        return;
                    }


                    if (String.IsNullOrEmpty(binPath) || !Directory.Exists(binPath))
                    {
                        MessageBox.Show("bin目录不存在");
                        QTUtility.SoundPlay();
                        return;
                    }


                    if (String.IsNullOrEmpty(antCmd) || !File.Exists(antCmd))
                    {
                        MessageBox.Show("antCmd不存在");
                        QTUtility.SoundPlay();
                        return;
                    }


                    using (var envKey = Registry.LocalMachine.OpenSubKey(REG_ENV_PATH, true))
                    {
                        string oldPath = getOldPath(envKey);
                        envKey.SetValue("ANT_HOME", selectedPath);
                        envKey.SetValue("PATH", joinDevPath(oldPath));
                        SendNotifyMessage((IntPtr)HWND_BROADCAST, WM_SETTINGCHANGE, (UIntPtr)0, "Environment");
                        MessageBox.Show("设置ANT_HOME成功");
                    }
                    break;
                }

                case 10:
                {
                    // 10. 设置当前目录MVND_HOME
                    string selectedPath = pluginServer.SelectedTab.Address.Path;
                    string binPath      = Path.Combine(selectedPath, "bin");
                    string mvndexe      = Path.Combine(binPath, "mvnd.exe");

                    if (String.IsNullOrEmpty(selectedPath) || !Directory.Exists(selectedPath))
                    {
                        MessageBox.Show("当前目录已经删除");
                        QTUtility.SoundPlay();
                        return;
                    }


                    if (String.IsNullOrEmpty(binPath) || !Directory.Exists(binPath))
                    {
                        MessageBox.Show("bin目录不存在");
                        QTUtility.SoundPlay();
                        return;
                    }


                    if (String.IsNullOrEmpty(mvndexe) || !File.Exists(mvndexe))
                    {
                        MessageBox.Show("mvndexe不存在");
                        QTUtility.SoundPlay();
                        return;
                    }


                    using (var envKey = Registry.LocalMachine.OpenSubKey(REG_ENV_PATH, true))
                    {
                        string oldPath = getOldPath(envKey);
                        envKey.SetValue("MVND_HOME", selectedPath);
                        envKey.SetValue("PATH", joinDevPath(oldPath));
                        SendNotifyMessage((IntPtr)HWND_BROADCAST, WM_SETTINGCHANGE, (UIntPtr)0, "Environment");
                        MessageBox.Show("设置MVND_HOME成功");
                    }
                    break;
                }


                case 7:
                {
                    // 11. 管理员方式启动
                    string selectedPath = pluginServer.SelectedTab.Address.Path;
                    string binPath      = Path.Combine(selectedPath, "bin");
                    string mvndexe      = Path.Combine(binPath, "mvnd.exe");
                    // string exePath = Path.Combine(Environment.ExpandEnvironmentVariables("%PROGRAMDATA%"), @"\QTTabBar\SetHome.exe");
                    //  string exePath = @"%PROGRAMDATA%\QTTabBar\SetHome.exe";

                    string exePath = @"C:\ProgramData\QTTabBar\SetHome.exe";
                    if (!File.Exists(exePath))
                    {
                        exePath = @"D:\ProgramData\QTTabBar\SetHome.exe";
                    }
                    if (!File.Exists(exePath))
                    {
                        exePath = @"E:\ProgramData\QTTabBar\SetHome.exe";
                    }
                    if (!File.Exists(exePath))
                    {
                        exePath = @"F:\ProgramData\QTTabBar\SetHome.exe";
                    }
                    if (!File.Exists(exePath))
                    {
                        exePath = @"G:\ProgramData\QTTabBar\SetHome.exe";
                    }
                    if (!File.Exists(exePath))
                    {
                        exePath = @"H:\ProgramData\QTTabBar\SetHome.exe";
                    }


                    if (File.Exists(exePath))
                    {
                        var process = new Process
                        {
                            StartInfo =
                            {
                                WorkingDirectory = selectedPath,
                                UseShellExecute  = true,
                                FileName         = exePath,
                                CreateNoWindow   = true,
                                Verb             = "runas"
                            }
                        };
                        process.Start();
                    }
                    else
                    {
                        MessageBox.Show("未找到可执行文件SetHome");
                    }
                    break;
                }
                }

                // pluginServer.CreateTab(new Address(mydocument), -1, false, true);
                if (null != path)
                {
                    pluginServer.CreateTab(new Address(path), -1, false, false);
                }
            }
            else if (mouseButton == MouseButtons.Right)
            {
                //QTUtility.AsteriskPlay();

                // MessageBox.Show("Hello World");


                switch (idx)
                {
                case 0:
                {
                    // 0. 我的文档
                    path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                    break;
                }

                case 1:
                {
                    // 1. 系统
                    if (IsWin7)
                    {
                        path = "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{BB06C0E4-D293-4F75-8A90-CB05B6477EEE}";
                    }
                    else if (IsXP)
                    {
                    }
                    //path = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}";
                    break;
                }

                case 2:
                {
                    // 2. 显示
                    if (IsWin7)
                    {
                        path = "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{ED834ED6-4B5A-4BFE-8F11-A626DCB6A921}";
                    }
                    else if (IsXP)
                    {
                        path = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}";
                    }
                    break;
                }
                }

                if (null != path)
                {
                    pluginServer.CreateTab(new Address(path), -1, false, false);
                }
            }

            /*  if(item.Text == "Open folder") {
             *    if(mouseButton == MouseButtons.Left) {
             *        string mydocument = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
             *        pluginServer.CreateTab(new Address(mydocument), -1, false, true);
             *    }
             *    else if(mouseButton == MouseButtons.Right) {
             *        QTUtility.AsteriskPlay();
             *    }
             * }
             * else if(item.Text == "Test selection") {
             *    if(lstSelectedItems.Count > 0)
             *        pluginServer.TrySetSelection(lstSelectedItems.ToArray(), false);
             * }*/
        }
Ejemplo n.º 4
0
 internal void OpenDirectory(string path)
 {
     pluginServer.CreateTab(new Address(path), -1, false, true);
 }
Ejemplo n.º 5
0
        public void OnDropDownItemClick(ToolStripItem item, MouseButtons mouseButton)
        {
            // user clicked the dropdown menu item of this plugin button dropdown.

            int    idx  = menu.Items.IndexOf(item);
            string path = null;

            if (mouseButton == MouseButtons.Left)
            {
                switch (idx)
                {
                case 0: {
                    // 0. 我的文档
                    path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                    break;
                }

                case 1: {
                    // 1. 系统
                    if (IsWin7)
                    {
                        path = "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{BB06C0E4-D293-4F75-8A90-CB05B6477EEE}";
                        string spa_exe = Environment.GetEnvironmentVariable("systemroot") + "\\System32\\SystemPropertiesAdvanced.exe";
                        Process.Start(spa_exe);
                        return;
                    }
                    else if (IsXP)
                    {
                    }
                    //path = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}";
                    break;
                }

                case 2: {
                    // 2. 显示
                    if (IsWin7)
                    {
                        path = "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{ED834ED6-4B5A-4BFE-8F11-A626DCB6A921}";
                    }
                    else if (IsXP)
                    {
                        path = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}";
                    }
                    break;
                }
                }

                // pluginServer.CreateTab(new Address(mydocument), -1, false, true);
                if (null != path)
                {
                    pluginServer.CreateTab(new Address(path), -1, false, false);
                }
            }
            else if (mouseButton == MouseButtons.Right)
            {
                //SystemSounds.Asterisk.Play();

                // MessageBox.Show("Hello World");


                switch (idx)
                {
                case 0:
                {
                    // 0. 我的文档
                    path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                    break;
                }

                case 1:
                {
                    // 1. 系统
                    if (IsWin7)
                    {
                        path = "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{BB06C0E4-D293-4F75-8A90-CB05B6477EEE}";
                    }
                    else if (IsXP)
                    {
                    }
                    //path = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}";
                    break;
                }

                case 2:
                {
                    // 2. 显示
                    if (IsWin7)
                    {
                        path = "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{ED834ED6-4B5A-4BFE-8F11-A626DCB6A921}";
                    }
                    else if (IsXP)
                    {
                        path = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}";
                    }
                    break;
                }
                }

                if (null != path)
                {
                    pluginServer.CreateTab(new Address(path), -1, false, false);
                }
            }

            /*  if(item.Text == "Open folder") {
             *    if(mouseButton == MouseButtons.Left) {
             *        string mydocument = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
             *        pluginServer.CreateTab(new Address(mydocument), -1, false, true);
             *    }
             *    else if(mouseButton == MouseButtons.Right) {
             *        SystemSounds.Asterisk.Play();
             *    }
             * }
             * else if(item.Text == "Test selection") {
             *    if(lstSelectedItems.Count > 0)
             *        pluginServer.TrySetSelection(lstSelectedItems.ToArray(), false);
             * }*/
        }
Ejemplo n.º 6
0
        public void OnDropDownItemClick(ToolStripItem item, MouseButtons mouseButton)
        {
            // user clicked the dropdown menu item of this plugin button dropdown.

            int    idx  = menu.Items.IndexOf(item);
            string path = null;

            if (mouseButton == MouseButtons.Left)
            {
                switch (idx)
                {
                case 0: {
                    // 0. 我的文档
                    path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                    break;
                }

                case 1: {
                    // 1. 系统
                    if (IsWin7)
                    {
                        path = "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{BB06C0E4-D293-4F75-8A90-CB05B6477EEE}";
                        string spa_exe = Environment.GetEnvironmentVariable("systemroot") + "\\System32\\SystemPropertiesAdvanced.exe";
                        Process.Start(spa_exe);
                        return;
                    }
                    else if (IsXP)
                    {
                    }
                    //path = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}";
                    break;
                }

                case 2: {
                    // 2. 显示
                    if (IsWin7)
                    {
                        path = "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{ED834ED6-4B5A-4BFE-8F11-A626DCB6A921}";
                    }
                    else if (IsXP)
                    {
                        path = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}";
                    }
                    break;
                }

                case 3:
                {
                    // 3. 设置当前目录JAVA_HOME
                    string selectedPath = pluginServer.SelectedTab.Address.Path;
                    string binPath      = Path.Combine(selectedPath, "bin");
                    string libPath      = Path.Combine(selectedPath, "lib");
                    string toolsJar     = Path.Combine(libPath, "tools.jar");
                    string dtJar        = Path.Combine(libPath, "dt.jar");


                    if (String.IsNullOrEmpty(selectedPath) || !Directory.Exists(selectedPath))
                    {
                        MessageBox.Show("当前目录已经删除");
                        SystemSounds.Hand.Play();
                        return;
                    }


                    if (String.IsNullOrEmpty(binPath) || !Directory.Exists(binPath))
                    {
                        MessageBox.Show("bin目录不存在");
                        SystemSounds.Hand.Play();
                        return;
                    }



                    if (String.IsNullOrEmpty(libPath) || !Directory.Exists(libPath))
                    {
                        MessageBox.Show("lib目录不存在");
                        SystemSounds.Hand.Play();
                        return;
                    }



                    if (String.IsNullOrEmpty(toolsJar) || !File.Exists(toolsJar))
                    {
                        MessageBox.Show("toolsJar不存在");
                        SystemSounds.Hand.Play();
                        return;
                    }



                    if (String.IsNullOrEmpty(toolsJar) || !File.Exists(dtJar))
                    {
                        MessageBox.Show("dtJar不存在");
                        SystemSounds.Hand.Play();
                        return;
                    }
                    Environment.SetEnvironmentVariable("JAVA_HOME", selectedPath, EnvironmentVariableTarget.Machine);
                    Environment.SetEnvironmentVariable("CLASSPATH", @".;%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\dt.jar;", EnvironmentVariableTarget.Machine);
                    // 去重, 判断是否有 java home 删掉
                    string oldpath = filterEmpty("java.exe");
                    Environment.SetEnvironmentVariable("PATH", @"%JAVA_HOME%\bin;" + oldpath, EnvironmentVariableTarget.Machine);
                    MessageBox.Show("设置JAVA_HOME成功");

                    break;
                }

                case 4:
                {
                    // 4. 设置当前目录M2_HOME

                    // 3. 设置当前目录JAVA_HOME
                    string selectedPath = pluginServer.SelectedTab.Address.Path;
                    string binPath      = Path.Combine(selectedPath, "bin");
                    string mvnCmd       = Path.Combine(binPath, "mvn.cmd");



                    if (String.IsNullOrEmpty(selectedPath) || !Directory.Exists(selectedPath))
                    {
                        MessageBox.Show("当前目录已经删除");
                        SystemSounds.Hand.Play();
                        return;
                    }


                    if (String.IsNullOrEmpty(binPath) || !Directory.Exists(binPath))
                    {
                        MessageBox.Show("bin目录不存在");
                        SystemSounds.Hand.Play();
                        return;
                    }



                    if (String.IsNullOrEmpty(mvnCmd) || !File.Exists(mvnCmd))
                    {
                        MessageBox.Show("mvnCmd不存在");
                        SystemSounds.Hand.Play();
                        return;
                    }

                    Environment.SetEnvironmentVariable("M2_HOME", selectedPath, EnvironmentVariableTarget.Machine);
                    string oldpath = filterEmpty("mvn.cmd");
                    Environment.SetEnvironmentVariable("PATH", @"%M2_HOME%\bin;" + oldpath, EnvironmentVariableTarget.Machine);
                    MessageBox.Show("设置M2_HOME成功");

                    break;
                }

                case 5:
                {
                    // 5. 查看系统信息
                    string msinfo32 = Environment.GetEnvironmentVariable("systemroot") + "\\System32\\msinfo32.exe";
                    Process.Start(msinfo32);
                    break;
                }
                }

                // pluginServer.CreateTab(new Address(mydocument), -1, false, true);
                if (null != path)
                {
                    pluginServer.CreateTab(new Address(path), -1, false, false);
                }
            }
            else if (mouseButton == MouseButtons.Right)
            {
                //SystemSounds.Asterisk.Play();

                // MessageBox.Show("Hello World");


                switch (idx)
                {
                case 0:
                {
                    // 0. 我的文档
                    path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                    break;
                }

                case 1:
                {
                    // 1. 系统
                    if (IsWin7)
                    {
                        path = "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{BB06C0E4-D293-4F75-8A90-CB05B6477EEE}";
                    }
                    else if (IsXP)
                    {
                    }
                    //path = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}";
                    break;
                }

                case 2:
                {
                    // 2. 显示
                    if (IsWin7)
                    {
                        path = "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{ED834ED6-4B5A-4BFE-8F11-A626DCB6A921}";
                    }
                    else if (IsXP)
                    {
                        path = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}";
                    }
                    break;
                }
                }

                if (null != path)
                {
                    pluginServer.CreateTab(new Address(path), -1, false, false);
                }
            }

            /*  if(item.Text == "Open folder") {
             *    if(mouseButton == MouseButtons.Left) {
             *        string mydocument = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
             *        pluginServer.CreateTab(new Address(mydocument), -1, false, true);
             *    }
             *    else if(mouseButton == MouseButtons.Right) {
             *        SystemSounds.Asterisk.Play();
             *    }
             * }
             * else if(item.Text == "Test selection") {
             *    if(lstSelectedItems.Count > 0)
             *        pluginServer.TrySetSelection(lstSelectedItems.ToArray(), false);
             * }*/
        }
Ejemplo n.º 7
0
        public void OnDropDownItemClick(ToolStripItem item, MouseButtons mouseButton)
        {
            // user clicked the dropdown menu item of this plugin button dropdown.

            int    idx  = menu.Items.IndexOf(item);
            string path = null;

            if (mouseButton == MouseButtons.Left)
            {
                switch (idx)
                {
                case 0: {
                    // 0. 我的文档
                    path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                    break;
                }

                case 1: {
                    // 1. 系统
                    if (IsWin7)
                    {
                        path = "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{BB06C0E4-D293-4F75-8A90-CB05B6477EEE}";
                        string spa_exe = Environment.GetEnvironmentVariable("systemroot") + "\\System32\\SystemPropertiesAdvanced.exe";
                        Process.Start(spa_exe);
                        return;
                    }
                    else if (IsXP)
                    {
                    }
                    //path = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}";
                    break;
                }

                case 2: {
                    // 2. 显示
                    if (IsWin7)
                    {
                        path = "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{ED834ED6-4B5A-4BFE-8F11-A626DCB6A921}";
                    }
                    else if (IsXP)
                    {
                        path = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}";
                    }
                    break;
                }

                case 3:
                {
                    // 3. 网络连接
                    if (IsWin7)
                    {
                        path = "::{7007ACC7-3202-11D1-AAD2-00805FC1270E}";
                    }
                    else if (IsXP)
                    {
                        path = "::{7007ACC7-3202-11D1-AAD2-00805FC1270E}";
                    }
                    break;
                }

                case 4:
                {
                    // 3. 设置当前目录JAVA_HOME
                    string selectedPath = pluginServer.SelectedTab.Address.Path;
                    string binPath      = Path.Combine(selectedPath, "bin");
                    string libPath      = Path.Combine(selectedPath, "lib");
                    string toolsJar     = Path.Combine(libPath, "tools.jar");
                    string dtJar        = Path.Combine(libPath, "dt.jar");


                    if (String.IsNullOrEmpty(selectedPath) || !Directory.Exists(selectedPath))
                    {
                        MessageBox.Show("当前目录已经删除");
                        SystemSounds.Hand.Play();
                        return;
                    }


                    if (String.IsNullOrEmpty(binPath) || !Directory.Exists(binPath))
                    {
                        MessageBox.Show("bin目录不存在");
                        SystemSounds.Hand.Play();
                        return;
                    }



                    if (String.IsNullOrEmpty(libPath) || !Directory.Exists(libPath))
                    {
                        MessageBox.Show("lib目录不存在");
                        SystemSounds.Hand.Play();
                        return;
                    }

                    /*
                     *
                     * if(String.IsNullOrEmpty(toolsJar) || !File.Exists(toolsJar)) {
                     *  MessageBox.Show("toolsJar不存在");
                     *  SystemSounds.Hand.Play();
                     *  return;
                     * }
                     *
                     *
                     *
                     * if(String.IsNullOrEmpty(toolsJar) || !File.Exists(dtJar)) {
                     *  MessageBox.Show("dtJar不存在");
                     *  SystemSounds.Hand.Play();
                     *  return;
                     * }
                     */


                    //  Environment.SetEnvironmentVariable("JAVA_HOME", selectedPath, EnvironmentVariableTarget.Machine);
                    // Environment.SetEnvironmentVariable("CLASSPATH", @".;%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\dt.jar;", EnvironmentVariableTarget.Machine);
                    // 去重, 判断是否有 java home 删掉
                    string oldpath = filterEmpty("java.exe");
                    // Environment.SetEnvironmentVariable("PATH", @"%JAVA_HOME%\bin;" + oldpath, EnvironmentVariableTarget.Machine);


                    PowerShell.Create().AddCommand("setx")
                    .AddParameter("JAVA_HOME", selectedPath)
                    .AddParameter("/M")
                    .Invoke();
                    Thread.Sleep(800);


                    if (File.Exists(toolsJar) && File.Exists(dtJar))
                    {
                        PowerShell.Create().AddCommand("setx")
                        .AddParameter("CLASSPATH", @".;%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\dt.jar;")
                        .AddParameter("/M")
                        .Invoke();
                        Thread.Sleep(800);
                    }



                    PowerShell.Create().AddCommand("setx")
                    .AddParameter("PATH", @"%JAVA_HOME%\bin;" + oldpath)
                    .AddParameter("/M")
                    .Invoke();
                    Thread.Sleep(800);

                    MessageBox.Show("设置JAVA_HOME成功");
                    break;
                }

                case 5:
                {
                    // 5. 设置当前目录M2_HOME

                    // 6. 设置当前目录JAVA_HOME
                    string selectedPath = pluginServer.SelectedTab.Address.Path;
                    string binPath      = Path.Combine(selectedPath, "bin");
                    string mvnCmd       = Path.Combine(binPath, "mvn.cmd");



                    if (String.IsNullOrEmpty(selectedPath) || !Directory.Exists(selectedPath))
                    {
                        MessageBox.Show("当前目录已经删除");
                        SystemSounds.Hand.Play();
                        return;
                    }


                    if (String.IsNullOrEmpty(binPath) || !Directory.Exists(binPath))
                    {
                        MessageBox.Show("bin目录不存在");
                        SystemSounds.Hand.Play();
                        return;
                    }



                    if (String.IsNullOrEmpty(mvnCmd) || !File.Exists(mvnCmd))
                    {
                        MessageBox.Show("mvnCmd不存在");
                        SystemSounds.Hand.Play();
                        return;
                    }

                    // Environment.SetEnvironmentVariable("M2_HOME", selectedPath, EnvironmentVariableTarget.Machine);

                    PowerShell.Create().AddCommand("setx")
                    .AddParameter("M2_HOME", selectedPath)
                    .AddParameter("/M")
                    .Invoke();
                    Thread.Sleep(800);

                    string oldpath = filterEmpty("mvn.cmd");
                    //  Environment.SetEnvironmentVariable("PATH", @"%M2_HOME%\bin;" + oldpath, EnvironmentVariableTarget.Machine);

                    PowerShell.Create().AddCommand("setx")
                    .AddParameter("PATH", @"%M2_HOME%\bin;" + oldpath)
                    .AddParameter("/M")
                    .Invoke();
                    Thread.Sleep(800);

                    MessageBox.Show("设置M2_HOME成功");

                    break;
                }

                case 6:
                {
                    // 6. 查看系统信息
                    string msinfo32 = Environment.GetEnvironmentVariable("systemroot") + "\\System32\\msinfo32.exe";
                    Process.Start(msinfo32);
                    break;
                }

                case 7:
                {
                    // 7. 重启资源管理器

                    /*
                     * foreach (Process p in Process.GetProcesses())
                     * {
                     *  if (p.MainModule.ModuleName.Contains("explorer") == true)
                     *      p.Kill();
                     * }
                     * Process.Start("explorer.exe");
                     */
                    IntPtr handle = GetWin10ExplorerWnd();
                    CloseExplorer(handle, 1);
                    // PInvoke.PostMessage(hwndExplr, WM.CLOSE, IntPtr.Zero, (IntPtr)nCode)
                    Thread.Sleep(800);
                    Process.Start("explorer.exe");
                    break;
                }

                case 8:
                {
                    // 8. 关机
                    IntPtr handle = GetShellTrayWnd();
                    CloseExplorer(handle, 1);
                    // PInvoke.PostMessage(hwndExplr, WM.CLOSE, IntPtr.Zero, (IntPtr)nCode)
                    Thread.Sleep(800);
                    break;
                }
                }

                // pluginServer.CreateTab(new Address(mydocument), -1, false, true);
                if (null != path)
                {
                    pluginServer.CreateTab(new Address(path), -1, false, false);
                }
            }
            else if (mouseButton == MouseButtons.Right)
            {
                //SystemSounds.Asterisk.Play();

                // MessageBox.Show("Hello World");


                switch (idx)
                {
                case 0:
                {
                    // 0. 我的文档
                    path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                    break;
                }

                case 1:
                {
                    // 1. 系统
                    if (IsWin7)
                    {
                        path = "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{BB06C0E4-D293-4F75-8A90-CB05B6477EEE}";
                    }
                    else if (IsXP)
                    {
                    }
                    //path = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}";
                    break;
                }

                case 2:
                {
                    // 2. 显示
                    if (IsWin7)
                    {
                        path = "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{ED834ED6-4B5A-4BFE-8F11-A626DCB6A921}";
                    }
                    else if (IsXP)
                    {
                        path = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}";
                    }
                    break;
                }
                }

                if (null != path)
                {
                    pluginServer.CreateTab(new Address(path), -1, false, false);
                }
            }

            /*  if(item.Text == "Open folder") {
             *    if(mouseButton == MouseButtons.Left) {
             *        string mydocument = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
             *        pluginServer.CreateTab(new Address(mydocument), -1, false, true);
             *    }
             *    else if(mouseButton == MouseButtons.Right) {
             *        SystemSounds.Asterisk.Play();
             *    }
             * }
             * else if(item.Text == "Test selection") {
             *    if(lstSelectedItems.Count > 0)
             *        pluginServer.TrySetSelection(lstSelectedItems.ToArray(), false);
             * }*/
        }