예제 #1
0
        private int RemoveDropDownBar()
        {
            var cpc = (IConnectionPointContainer)_window;

            if (cpc != null)
            {
                IConnectionPoint cp;
                cpc.FindConnectionPoint(typeof(IVsCodeWindowEvents).GUID, out cp);
                if (cp != null)
                {
                    try
                    {
                        cp.Unadvise(_cookieVsCodeWindowEvents);
                    }
                    catch (ArgumentException) // ArgException, invalid cookie. At this point, not much we can do.
                    { }
                }
            }

            if (_client != null)
            {
                IVsDropdownBarManager manager = (IVsDropdownBarManager)_window;

                _client.Unregister();
                // A buffer may have multiple DropDownBarClients, given one may open multiple CodeWindows
                // over a single buffer using Window/New Window
                List <DropDownBarClient> listDropDownBarClient;
                if (_textBuffer.Properties.TryGetProperty(typeof(DropDownBarClient), out listDropDownBarClient) && listDropDownBarClient != null)
                {
                    listDropDownBarClient.Remove(_client);
                    if (listDropDownBarClient.Count == 0)
                    {
                        _textBuffer.Properties.RemoveProperty(typeof(DropDownBarClient));
                    }

                    int instancesOpen = 0;
                    if (_textBuffer.Properties.TryGetProperty <int>("InstancesOpen", out instancesOpen))
                    {
                        instancesOpen--;
                        _textBuffer.Properties["InstancesOpen"] = instancesOpen;
                    }
                }

                _client = null;
                return(manager.RemoveDropdownBar());
            }
            return(VSConstants.S_OK);
        }
        private int RemoveDropDownBar()
        {
            var cpc = (IConnectionPointContainer)_window;

            if (cpc != null)
            {
                IConnectionPoint cp;
                cpc.FindConnectionPoint(typeof(IVsCodeWindowEvents).GUID, out cp);
                if (cp != null)
                {
                    cp.Unadvise(_cookieVsCodeWindowEvents);
                }
            }

            if (_client != null)
            {
                IVsDropdownBarManager manager = (IVsDropdownBarManager)_window;

                _client.Unregister();
                // A buffer may have multiple DropDownBarClients, given one may open multiple CodeWindows
                // over a single buffer using Window/New Window
                List <DropDownBarClient> listDropDownBarClient;
                if (_textBuffer.Properties.TryGetProperty(typeof(DropDownBarClient), out listDropDownBarClient) && listDropDownBarClient != null)
                {
                    listDropDownBarClient.Remove(_client);
                    if (listDropDownBarClient.Count == 0)
                    {
                        _textBuffer.Properties.RemoveProperty(typeof(DropDownBarClient));
                    }

                    int instancesOpen = 0;
                    if (_textBuffer.Properties.TryGetProperty <int>("InstancesOpen", out instancesOpen))
                    {
                        instancesOpen--;
                        _textBuffer.Properties["InstancesOpen"] = instancesOpen;
                    }

                    if (instancesOpen == 0)
                    {
                        string filePath = _textBuffer.GetFilePath();



                        //// remove the file parser manager from the buffer (hang onto it for unregistration)
                        //var delFpm = VSGeneroPackage.Instance.RemoveBufferFileParserManager(_textBuffer);
                        //if (delFpm.PrimarySibling == null)
                        //{
                        //    // remove the buffer from the global buffer dictionary
                        //    if (VSGeneroPackage.BufferDictionary.ContainsKey(filePath))
                        //    {
                        //        VSGeneroPackage.BufferDictionary.Remove(filePath);
                        //    }

                        //    VSGeneroPackage.Instance.ProgramContentsManager.Programs.Remove(_textBuffer.GetProgram());

                        //    IEnumerable<string> programFilenames = (VSGeneroPackage.Instance.CurrentProgram4GLFileProvider == null) ?
                        //                                    VSGenero.EditorExtensions.EditorExtensions.GetProgramFilenames(filePath) :
                        //                                    VSGeneroPackage.Instance.CurrentProgram4GLFileProvider.GetProgramFilenames(filePath);
                        //    var filenameList = programFilenames.ToList();
                        //    if(filenameList.Count > 0)
                        //    {
                        //        foreach(var filename in filenameList)
                        //        {
                        //            TextBufferOpenStatus bufferStatus;
                        //            if(VSGeneroPackage.BufferDictionary.TryGetValue(filename, out bufferStatus))
                        //            {
                        //                if (!bufferStatus.IsOpen)
                        //                {
                        //                    VSGeneroPackage.Instance.RemoveBufferFileParserManager(bufferStatus.Buffer);
                        //                    VSGeneroPackage.BufferDictionary.Remove(filename);
                        //                }
                        //            }
                        //        }
                        //    }
                        //}
                        //else
                        //{
                        //    if (!VSGeneroPackage.BufferDictionary.ContainsKey(delFpm.PrimarySibling))
                        //    {
                        //        VSGeneroPackage.BufferDictionary.Remove(filePath);
                        //    }
                        //    else if (VSGeneroPackage.BufferDictionary.ContainsKey(filePath))
                        //    {
                        //        VSGeneroPackage.BufferDictionary[filePath].IsOpen = false;
                        //    }
                        //}

                        //Genero4GLOutliner outliner;
                        //if (_textBuffer.Properties.TryGetProperty<Genero4GLOutliner>(typeof(Genero4GLOutliner), out outliner))
                        //{
                        //    outliner.Unregister(delFpm);
                        //    _textBuffer.Properties.RemoveProperty(typeof(Genero4GLOutliner));
                        //}

                        //GeneroClassifier classifier;
                        //if (_textBuffer.Properties.TryGetProperty<GeneroClassifier>(typeof(GeneroClassifier), out classifier))
                        //{
                        //    classifier.Unregister();
                        //    _textBuffer.Properties.RemoveProperty(typeof(GeneroClassifier));
                        //}

                        //GeneroLineEndingsListener lineEndingsListener;
                        //if (_textBuffer.Properties.TryGetProperty<GeneroLineEndingsListener>(typeof(GeneroLineEndingsListener), out lineEndingsListener))
                        //{
                        //    lineEndingsListener.Unregister();
                        //    _textBuffer.Properties.RemoveProperty(typeof(GeneroLineEndingsListener));
                        //}

                        //SignatureHelpSource sigHelpSource;
                        //if (_textBuffer.Properties.TryGetProperty<SignatureHelpSource>(typeof(SignatureHelpSource), out sigHelpSource))
                        //{
                        //    sigHelpSource.Unregister();
                        //    _textBuffer.Properties.RemoveProperty(typeof(SignatureHelpSource));
                        //}
                    }
                }

                _client = null;
                return(manager.RemoveDropdownBar());
            }
            return(VSConstants.S_OK);
        }
        private int AddDropDownBar()
        {
            var cpc = (IConnectionPointContainer)_window;

            if (cpc != null)
            {
                IConnectionPoint cp;
                cpc.FindConnectionPoint(typeof(IVsCodeWindowEvents).GUID, out cp);
                if (cp != null)
                {
                    cp.Advise(this, out _cookieVsCodeWindowEvents);
                }
            }

            var pythonProjectEntry = _textBuffer.GetAnalysis() as IGeneroProjectEntry;

            if (pythonProjectEntry == null)
            {
                return(VSConstants.E_FAIL);
            }

            IWpfTextView wpfTextView = null;
            IVsTextView  vsTextView;

            if (ErrorHandler.Succeeded(_window.GetLastActiveView(out vsTextView)) && vsTextView != null)
            {
                wpfTextView = VsEditorAdaptersFactoryService.GetWpfTextView(vsTextView);
            }
            if (wpfTextView == null)
            {
                return(VSConstants.E_FAIL);
            }

            // pass on the text view
            //GeneroFileParserManager fpm = VSGeneroPackage.Instance.UpdateBufferFileParserManager(_textBuffer);
            _client = new DropDownBarClient(wpfTextView, pythonProjectEntry);

            IVsDropdownBarManager manager = (IVsDropdownBarManager)_window;

            int instancesOpen = 0;

            if (!_textBuffer.Properties.TryGetProperty <int>("InstancesOpen", out instancesOpen))
            {
                _textBuffer.Properties.AddProperty("InstancesOpen", 1);
            }
            else
            {
                _textBuffer.Properties["InstancesOpen"] = instancesOpen + 1;
            }

            IVsDropdownBar dropDownBar;
            int            hr = manager.GetDropdownBar(out dropDownBar);

            if (ErrorHandler.Succeeded(hr) && dropDownBar != null)
            {
                hr = manager.RemoveDropdownBar();
                if (!ErrorHandler.Succeeded(hr))
                {
                    return(hr);
                }
            }

            int res = manager.AddDropdownBar(1, _client);

            if (ErrorHandler.Succeeded(res))
            {
                // A buffer may have multiple DropDownBarClients, given one may open multiple CodeWindows
                // over a single buffer using Window/New Window
                List <DropDownBarClient> listDropDownBarClient;
                if (!_textBuffer.Properties.TryGetProperty(typeof(DropDownBarClient), out listDropDownBarClient) || listDropDownBarClient == null)
                {
                    listDropDownBarClient = new List <DropDownBarClient>();
                    _textBuffer.Properties[typeof(DropDownBarClient)] = listDropDownBarClient;
                }
                listDropDownBarClient.Add(_client);
            }
            return(res);
        }