- Home /
 
 
               Question by 
               Aram-Azhari · Nov 04, 2013 at 08:50 PM · 
                editorwindowongui  
              
 
              Event.current not fired after BeginWindows() on an EditorWindow
Hi,
I'm trying to detect a context menu on a GUILayout.Window I created inside the OnGUI method of an Editor window:
 public class SlideShowWindow : EditorWindow
 {
 [MenuItem("Window/Slide Show")]
 static void Init()
 {
   // Get existing open window or if none, make a new one:
   SlideShowWindow window = (SlideShowWindow)EditorWindow.GetWindow(typeof(SlideShowWindow));
 
 }
 
 
 void OnGUI()
 {
 BeginWindows();
   if (Event.current.button == 1 && Event.current.isMouse)
 { // Debug.Log("Fired");
   foreach (var node in nodes)
   {
     var mousePos = ev.mousePosition;
     if (node.window.Contains(mousePos))
     {
       node.ShowContextMenu();
       ev.Use();
     }
   }
 }    
 foreach (var node in nodes)
 {
   node.OnGUI();
 }
 EndWindows();
 
               And the code for the node thing is:
 public class NodeWindow : ScriptableObject
 {
 public Rect window = new Rect(0, 0, 100, 100);
 public int id;
 public string title = "Title";
 public virtual void Initialize()
 {
 }
 public void OnGUI()
 {
   window = GUILayout.Window(id, window, show, title);
 }
 public virtual void show(int windowID)
 {
   if (windowID == id)
   {
     GUILayout.Button("Test Node for window " + id);
     GUI.DragWindow();
   }
 }
 public virtual void ShowContextMenu()
 {
   GenericMenu menu = new GenericMenu();
   menu.AddItem(new GUIContent("Copy"), false, ContextMenuCallback, "Copy");
   menu.AddItem(new GUIContent("Paste"), false, ContextMenuCallback, "Paste");
   menu.ShowAsContext();
 }
 
               The problem I have, is that the event is not raised while the mouse is over a sub window.
What should I do to catch that event?
Thanks,
               Comment
              
 
               
              Your answer