Exemple #1
0
        private void UpdateFocusedControl()
        {
            //			TabControl tabControl = sender as TabControl;

            EventTrackInfo evt = tabEventView.SelectedTab.Tag as EventTrackInfo;

            if (evt == null)
            {
                propertyGrid1.SelectedObject = null;
                checkedListBox1.Items.Clear();
                return;
            }
            propertyGrid1.SelectedObject = evt.SelectedObject;

            checkedListBox1.DisplayMember = "EventName";
            checkedListBox1.Items.Clear();

            // Populate event list with details
            int item = 0;

            foreach (ControlEvent ce in evt.EventList)
            {
                checkedListBox1.Items.Add(ce, ce.TrackEnabled);
                item++;
            }
        }
Exemple #2
0
        private void bSetAll_Click(object sender, System.EventArgs e)
        {
            EventTrackInfo evt = tabEventView.SelectedTab.Tag as EventTrackInfo;

            if (evt == null)
            {
                return;
            }

            foreach (ControlEvent ce in evt.EventList)
            {
                ce.TrackEnabled = true;
            }

            UpdateFocusedControl();
        }
Exemple #3
0
        private EventTrackInfo AddTabPage(string name, object selectedObject)
        {
            TabPage newPage = new TabPage();

            newPage.Text             = name;
            newPage.ToolTipText      = selectedObject.GetType().FullName;
            newPage.CausesValidation = false;

            EventTrackInfo evtTrackInfo = new EventTrackInfo();

            evtTrackInfo.CausesValidation = false;
            evtTrackInfo.Dock             = System.Windows.Forms.DockStyle.Fill;
            evtTrackInfo.ContextMenu      = contextMenu;
            evtTrackInfo.SelectedObject   = selectedObject;
            newPage.Tag = evtTrackInfo;
            newPage.Controls.Add(evtTrackInfo);

            tabEventView.Controls.Add(newPage);

            return(evtTrackInfo);
        }
Exemple #4
0
        public void StopTracking(string eventName)
        {
            foreach (TabPage tp in tabEventView.Controls)
            {
                EventTrackInfo evt = tp.Tag as EventTrackInfo;

                if (evt == null)
                {
                    continue;
                }

                foreach (ControlEvent ce in evt.EventList)
                {
                    if (ce.EventName == eventName)
                    {
                        ce.TrackEnabled = false;
                    }
                }
            }

            UpdateFocusedControl();
        }
Exemple #5
0
        public void HookEvents(object o, string name)
        {
            if (recursion_counter_ >= recursion_depth_)
            {
                return;
            }

            recursion_counter_++;

            Type t = o.GetType();

            EventTrackInfo trackInfo        = AddTabPage(name, o);
            ArrayList      controlEventList = new ArrayList();

            foreach (EventInfo ei in t.GetEvents())
            {
                // Discover type of event handler
                Type eventHandlerType = ei.EventHandlerType;

                // eventHandlerType is the type of the delegate (eg System.EventHandler)
                // what we need, is to find the type of the second parameter of the
                // delegate, eg System.EventArgs

                MethodInfo      mi = eventHandlerType.GetMethod("Invoke");
                ParameterInfo[] pi = mi.GetParameters();

                if (pi == null || pi.Length < 2)
                {
                    continue;
                }

                // Get a class derived from ControlEvent which has a HandleEvent method
                // taking the appropriate parameters
                ControlEvent ce = GenerateEventAssembly.Instance.GetEventConsumerType(pi[1].ParameterType);

                // Hook onto this control event to get the details of all events fired
                ce.ControlName    = name;
                ce.EventName      = ei.Name;
                ce.EventTrackInfo = trackInfo;
                ce.EventFired    += new EventHandler(eventFired);

                controlEventList.Add(ce);

                // Wire up the event handler to our new consumer
                Delegate d = Delegate.CreateDelegate(eventHandlerType, ce, "HandleEvent");
                ei.AddEventHandler(o, d);
            }

            trackInfo.EventList = controlEventList;

            if (is_recursive_)
            {
                if (o is Control)
                {
                    Control c = (Control)o;

                    if (c.Controls != null)
                    {
                        foreach (Control subControl in c.Controls)
                        {
                            HookEvents(subControl, name + "/" + ControlName(subControl));
                        }
                    }

                    if (c is Form)
                    {
                        Form f = (Form)c;
                        if (f.Menu != null)
                        {
                            foreach (MenuItem m in f.Menu.MenuItems)
                            {
                                HookEvents(m, name + "/" + ControlName(m));
                            }
                        }
                    }

                    if (c.ContextMenu != null)
                    {
                        foreach (MenuItem m in c.ContextMenu.MenuItems)
                        {
                            HookEvents(m, name + "/" + ControlName(m));
                        }
                    }
                }

                if (o is MenuItem)
                {
                    MenuItem m = (MenuItem)o;
                    foreach (MenuItem mi in m.MenuItems)
                    {
                        HookEvents(mi, name + "/" + ControlName(mi));
                    }
                }
            }

            recursion_counter_--;
        }