Ejemplo n.º 1
0
        public static void GetVSMultiInstanceInfo(out VSMultiInstanceInfo vs_instance_info, string our_dte_version, Solution solution)
        {
            vs_instance_info.multiple_instances = false;
            vs_instance_info.multiple_instances_same_version = false;
            vs_instance_info.nb_instances_same_solution      = 0;
            try {
                if (VSConstants.S_OK != GetRunningObjectTable(0, out IRunningObjectTable running_object_table))
                {
                    return;
                }
                running_object_table.EnumRunning(out IEnumMoniker moniker_enumerator);
                moniker_enumerator.Reset();

                var monikers              = new IMoniker[1];
                var num_fetched           = IntPtr.Zero;
                int dte_count             = 0;
                int dte_count_our_version = 0;
                //Will only return if same privilege as per http://stackoverflow.com/questions/11835617/understanding-the-running-object-table
                while (VSConstants.S_OK == moniker_enumerator.Next(1, monikers, num_fetched))
                {
                    if (VSConstants.S_OK != CreateBindCtx(0, out IBindCtx ctx))
                    {
                        continue;
                    }

                    monikers[0].GetDisplayName(ctx, null, out string name);
                    if (!name.StartsWith("!VisualStudio.DTE."))
                    {
                        continue;
                    }

                    if (VSConstants.S_OK != running_object_table.GetObject(monikers[0], out object com_object))
                    {
                        continue;
                    }

                    var dte = com_object as DTE2;
                    if (dte != null)
                    {
                        var s = dte.Solution;
                        if (s != null)
                        {
                            var sn = Path.GetFileNameWithoutExtension(s.FullName);
                            if (!string.IsNullOrEmpty(sn) && solution != null && sn == Path.GetFileNameWithoutExtension(solution.FullName))
                            {
                                vs_instance_info.nb_instances_same_solution++;
                            }
                        }
                        ++dte_count;
                        var m = m_DTEComObjectNameRegex.Match(name);
                        if (m.Success)
                        {
                            var g = m.Groups["dte_version"];
                            if (g.Success && g.Value == our_dte_version)
                            {
                                ++dte_count_our_version;
                            }
                        }
                    }
                }
                vs_instance_info.multiple_instances = dte_count > 1;
                vs_instance_info.multiple_instances_same_version = dte_count_our_version > 1;
            }
            catch {
                vs_instance_info.multiple_instances = false;
                vs_instance_info.multiple_instances_same_version = false;
            }
        }
        void SetVariableValuesFromIDEState(IVariableValueSetter var_value_setter, VSMultiInstanceInfo multi_instance_info)
        {
            VarValues var_values = new VarValues();
            try
            {
                GetVariableValues(var_values);
            }
            catch (System.Exception ex)
            {
                var_values.exceptions.Add(ex);
            }

            if (var_values.exceptions.Count > 0 && m_Package.IsDebugEnabled())
            {
                DebugOutput.WriteLine("----- Exceptions: GetVariableValues:");
                foreach (Exception ex in var_values.exceptions)
                    DebugOutput.WriteLine("EX: " + ex.ToString());
            }

            AddFilePathVars(var_value_setter, ref var_values.sln_path, SlashPathSeparator, "sln_");
            var_value_setter.SetVariable("sln_open", var_values.sln_path.Length > 0);
            var_value_setter.SetVariable("sln_dirty", var_values.sln_dirty ? "*" : "");

            AddFilePathVars(var_value_setter, ref var_values.doc_path, SlashPathSeparator, "doc_");
            var_value_setter.SetVariable("doc_open", var_values.doc_path.Length > 0);
            var_value_setter.SetVariable("doc_dirty", var_values.doc_dirty ? "*" : "");
            var_value_setter.SetVariable("any_doc_dirty", var_values.any_doc_dirty ? "*" : "");

            AddFilePathVars(var_value_setter, ref var_values.startup_proj_path, SlashPathSeparator, "startup_proj_");
            var_value_setter.SetVariable("startup_proj", var_values.startup_proj);
            var_value_setter.SetVariable("startup_proj_dirty", var_values.startup_proj_dirty ? "*" : "");

            var_value_setter.SetVariable("any_proj_dirty", var_values.any_proj_dirty ? "*" : "");
            var_value_setter.SetVariable("anything_dirty", (var_values.sln_dirty || var_values.any_proj_dirty || var_values.any_doc_dirty) ? "*" : "");

            var_value_setter.SetVariable("wnd_minimized", var_values.wnd_minimized);
            var_value_setter.SetVariable("wnd_foreground", var_values.wnd_foreground);
            var_value_setter.SetVariable("app_active", var_values.app_active);

            bool debugging = false;
            string debug_mode = "";
            switch (var_values.dbgmode)
            {
                case DBGMODE.DBGMODE_Run:
                    debugging = true;
                    debug_mode = "running";
                    break;
                case DBGMODE.DBGMODE_Break:
                    debugging = true;
                    debug_mode = "debugging";
                    break;
            }

            var_value_setter.SetVariable("debugging", debugging);
            var_value_setter.SetVariable("debug_mode", debug_mode);

            var_value_setter.SetVariable("configuration", var_values.configuration);
            var_value_setter.SetVariable("platform", var_values.platform);

            var_value_setter.SetVariable("orig_title", var_values.orig_title);

            var_value_setter.SetVariable("multi_instances", multi_instance_info.multiple_instances);
            var_value_setter.SetVariable("multi_instances_same_ver", multi_instance_info.multiple_instances_same_version);

            var_value_setter.SetVariable("active_wnd_title", var_values.active_wnd_title);
            var_value_setter.SetVariable("active_wnd_class", var_values.active_wnd_class);

            var_value_setter.SetVariable("cmdline", var_values.cmdline);
        }
Ejemplo n.º 3
0
 public static void GetVSMultiInstanceInfo(out VSMultiInstanceInfo vs_instance_info)
 {
     GetVSMultiInstanceInfo(out vs_instance_info, DTE.Version, DTE.Solution);
 }
 public void GetVSMultiInstanceInfo(out VSMultiInstanceInfo vs_instance_info)
 {
     DTE2 dte = (DTE2)m_Package.GetInterface(typeof(DTE));
     GetVSMultiInstanceInfo(out vs_instance_info, dte.Version);
 }
        public static void GetVSMultiInstanceInfo(out VSMultiInstanceInfo vs_instance_info, string our_dte_version)
        {
            vs_instance_info.multiple_instances = false;
            vs_instance_info.multiple_instances_same_version = false;

            try
            {
                IRunningObjectTable running_object_table;
                if (VSConstants.S_OK != GetRunningObjectTable(0, out running_object_table))
                    return;
                IEnumMoniker moniker_enumerator;
                running_object_table.EnumRunning(out moniker_enumerator);
                moniker_enumerator.Reset();

                IMoniker[] monikers = new IMoniker[1];
                IntPtr num_fetched = IntPtr.Zero;
                int dte_count = 0;
                int dte_count_our_version = 0;
                while (VSConstants.S_OK == moniker_enumerator.Next(1, monikers, num_fetched))
                {
                    IBindCtx ctx;
                    if (VSConstants.S_OK != CreateBindCtx(0, out ctx))
                        continue;

                    string name;
                    monikers[0].GetDisplayName(ctx, null, out name);
                    if (!name.StartsWith("!VisualStudio.DTE."))
                        continue;

                    object com_object;
                    if (VSConstants.S_OK != running_object_table.GetObject(monikers[0], out com_object))
                        continue;

                    DTE2 dte = com_object as DTE2;
                    if (dte != null)
                    {
                        ++dte_count;
                        Match m = m_DTEComObjectNameRegex.Match(name);
                        if (m.Success)
                        {
                            Group g = m.Groups["dte_version"];
                            if (g.Success && g.Value == our_dte_version)
                                ++dte_count_our_version;
                        }
                    }
                }
                vs_instance_info.multiple_instances = dte_count > 1;
                vs_instance_info.multiple_instances_same_version = dte_count_our_version > 1;
            }
            catch
            {
                vs_instance_info.multiple_instances = false;
                vs_instance_info.multiple_instances_same_version = false;
            }
        }
        public static void GetVSMultiInstanceInfo(out VSMultiInstanceInfo vs_instance_info, string our_dte_version)
        {
            vs_instance_info.multiple_instances = false;
            vs_instance_info.multiple_instances_same_version = false;

            try
            {
                IRunningObjectTable running_object_table;
                if (VSConstants.S_OK != GetRunningObjectTable(0, out running_object_table))
                {
                    return;
                }
                IEnumMoniker moniker_enumerator;
                running_object_table.EnumRunning(out moniker_enumerator);
                moniker_enumerator.Reset();

                IMoniker[] monikers              = new IMoniker[1];
                IntPtr     num_fetched           = IntPtr.Zero;
                int        dte_count             = 0;
                int        dte_count_our_version = 0;
                while (VSConstants.S_OK == moniker_enumerator.Next(1, monikers, num_fetched))
                {
                    IBindCtx ctx;
                    if (VSConstants.S_OK != CreateBindCtx(0, out ctx))
                    {
                        continue;
                    }

                    string name;
                    monikers[0].GetDisplayName(ctx, null, out name);
                    if (!name.StartsWith("!VisualStudio.DTE."))
                    {
                        continue;
                    }

                    object com_object;
                    if (VSConstants.S_OK != running_object_table.GetObject(monikers[0], out com_object))
                    {
                        continue;
                    }

                    DTE2 dte = com_object as DTE2;
                    if (dte != null)
                    {
                        ++dte_count;
                        Match m = m_DTEComObjectNameRegex.Match(name);
                        if (m.Success)
                        {
                            Group g = m.Groups["dte_version"];
                            if (g.Success && g.Value == our_dte_version)
                            {
                                ++dte_count_our_version;
                            }
                        }
                    }
                }
                vs_instance_info.multiple_instances = dte_count > 1;
                vs_instance_info.multiple_instances_same_version = dte_count_our_version > 1;
            }
            catch
            {
                vs_instance_info.multiple_instances = false;
                vs_instance_info.multiple_instances_same_version = false;
            }
        }
        public void GetVSMultiInstanceInfo(out VSMultiInstanceInfo vs_instance_info)
        {
            DTE2 dte = (DTE2)m_Package.GetInterface(typeof(DTE));

            GetVSMultiInstanceInfo(out vs_instance_info, dte.Version);
        }
        void SetVariableValuesFromIDEState(IVariableValueSetter var_value_setter, VSMultiInstanceInfo multi_instance_info)
        {
            VarValues var_values = new VarValues();

            try
            {
                GetVariableValues(var_values);
            }
            catch (System.Exception ex)
            {
                var_values.exceptions.Add(ex);
            }

            if (var_values.exceptions.Count > 0 && m_Package.IsDebugEnabled())
            {
                DebugOutput.WriteLine("----- Exceptions: GetVariableValues:");
                foreach (Exception ex in var_values.exceptions)
                {
                    DebugOutput.WriteLine("EX: " + ex.ToString());
                }
            }

            AddFilePathVars(var_value_setter, ref var_values.sln_path, SlashPathSeparator, "sln_");
            var_value_setter.SetVariable("sln_open", var_values.sln_path.Length > 0);
            var_value_setter.SetVariable("sln_dirty", var_values.sln_dirty ? "*" : "");

            AddFilePathVars(var_value_setter, ref var_values.doc_path, SlashPathSeparator, "doc_");
            var_value_setter.SetVariable("doc_open", var_values.doc_path.Length > 0);
            var_value_setter.SetVariable("doc_dirty", var_values.doc_dirty ? "*" : "");
            var_value_setter.SetVariable("any_doc_dirty", var_values.any_doc_dirty ? "*" : "");

            AddFilePathVars(var_value_setter, ref var_values.startup_proj_path, SlashPathSeparator, "startup_proj_");
            var_value_setter.SetVariable("startup_proj", var_values.startup_proj);
            var_value_setter.SetVariable("startup_proj_dirty", var_values.startup_proj_dirty ? "*" : "");

            var_value_setter.SetVariable("any_proj_dirty", var_values.any_proj_dirty ? "*" : "");
            var_value_setter.SetVariable("anything_dirty", (var_values.sln_dirty || var_values.any_proj_dirty || var_values.any_doc_dirty) ? "*" : "");

            var_value_setter.SetVariable("wnd_minimized", var_values.wnd_minimized);
            var_value_setter.SetVariable("wnd_foreground", var_values.wnd_foreground);
            var_value_setter.SetVariable("app_active", var_values.app_active);

            bool   debugging  = false;
            string debug_mode = "";

            switch (var_values.dbgmode)
            {
            case DBGMODE.DBGMODE_Run:
                debugging  = true;
                debug_mode = "running";
                break;

            case DBGMODE.DBGMODE_Break:
                debugging  = true;
                debug_mode = "debugging";
                break;
            }

            var_value_setter.SetVariable("debugging", debugging);
            var_value_setter.SetVariable("debug_mode", debug_mode);

            var_value_setter.SetVariable("configuration", var_values.configuration);
            var_value_setter.SetVariable("platform", var_values.platform);

            var_value_setter.SetVariable("orig_title", var_values.orig_title);

            var_value_setter.SetVariable("multi_instances", multi_instance_info.multiple_instances);
            var_value_setter.SetVariable("multi_instances_same_ver", multi_instance_info.multiple_instances_same_version);

            var_value_setter.SetVariable("active_wnd_title", var_values.active_wnd_title);
            var_value_setter.SetVariable("active_wnd_class", var_values.active_wnd_class);

            var_value_setter.SetVariable("cmdline", var_values.cmdline);
        }