Example #1
0
        private void _mainWidget_Destroyed(object sender, EventArgs e)
        {
            textEditor.Document.LineChanged   -= OnTextHasChanged;
            textEditor.TextArea.FocusInEvent  -= OnTextBoxEnter;
            textEditor.TextArea.FocusOutEvent -= OnTextBoxLeave;
            _mainWidget.Destroyed             -= _mainWidget_Destroyed;
            textEditor.TextArea.KeyPressEvent -= OnKeyPress;
            CompletionForm.FocusOutEvent      -= OnLeaveCompletion;
            CompletionView.ButtonPressEvent   -= OnContextListMouseDoubleClick;
            CompletionView.KeyReleaseEvent    -= CompletionView_KeyReleaseEvent;
            if (CompletionForm.IsRealized)
            {
                CompletionForm.Destroy();
            }
            // It's good practice to disconnect all event handlers, as it makes memory leaks
            // less likely. However, we may not "own" the event handlers, so how do we
            // know what to disconnect?
            // We can do this via reflection. Here's how it currently can be done in Gtk#.
            // Windows.Forms would do it differently.
            // This may break if Gtk# changes the way they implement event handlers.
            foreach (Widget w in Popup)
            {
                if (w is MenuItem)
                {
                    PropertyInfo pi = w.GetType().GetProperty("AfterSignals", BindingFlags.NonPublic | BindingFlags.Instance);
                    if (pi != null)
                    {
                        System.Collections.Hashtable handlers = (System.Collections.Hashtable)pi.GetValue(w);
                        if (handlers != null && handlers.ContainsKey("activate"))
                        {
                            EventHandler handler = (EventHandler)handlers["activate"];
                            (w as MenuItem).Activated -= handler;
                        }
                    }
                }
            }

            Popup.Destroy();
            accel.Dispose();
            completionModel.Dispose();
            functionPixbuf.Dispose();
            propertyPixbuf.Dispose();
            CompletionView.Dispose();
            CompletionForm.Destroy();
            CompletionForm = null;
            textEditor.Destroy();
            textEditor = null;
            _findForm.Destroy();
            _owner = null;
        }
Example #2
0
        private void _mainWidget_Destroyed(object sender, EventArgs e)
        {
            textEditor.Document.LineChanged   -= OnTextHasChanged;
            textEditor.TextArea.FocusInEvent  -= OnTextBoxEnter;
            textEditor.TextArea.FocusOutEvent -= OnTextBoxLeave;
            _mainWidget.Destroyed             -= _mainWidget_Destroyed;
            textEditor.TextArea.KeyPressEvent -= OnKeyPress;

            intellisense.ContextItemsNeeded -= ContextItemsNeeded;
            intellisense.ItemSelected       -= InsertCompletionItemIntoTextBox;
            intellisense.LoseFocus          -= HideCompletionWindow;
            intellisense.Cleanup();

            // It's good practice to disconnect all event handlers, as it makes memory leaks
            // less likely. However, we may not "own" the event handlers, so how do we
            // know what to disconnect?
            // We can do this via reflection. Here's how it currently can be done in Gtk#.
            // Windows.Forms would do it differently.
            // This may break if Gtk# changes the way they implement event handlers.
            foreach (Widget w in Popup)
            {
                if (w is MenuItem)
                {
                    PropertyInfo pi = w.GetType().GetProperty("AfterSignals", BindingFlags.NonPublic | BindingFlags.Instance);
                    if (pi != null)
                    {
                        System.Collections.Hashtable handlers = (System.Collections.Hashtable)pi.GetValue(w);
                        if (handlers != null && handlers.ContainsKey("activate"))
                        {
                            EventHandler handler = (EventHandler)handlers["activate"];
                            (w as MenuItem).Activated -= handler;
                        }
                    }
                }
            }

            Popup.Destroy();
            accel.Dispose();
            textEditor.Destroy();
            textEditor = null;
            _findForm.Destroy();
            _owner = null;
        }