From d129d6ee23995d0a5e89aa71e56d6ed6aa95761e Mon Sep 17 00:00:00 2001
From: Kelly Washington <kelly@lindenlab.com>
Date: Fri, 24 Sep 2010 15:57:17 -0700
Subject: [PATCH] VWR-21377 Script editor ctrl-f fix. let some LLViews handle
 shortcut keys if they want. reviewed with ambroff

---
 indra/llui/llfocusmgr.cpp        | 14 ++++++++++++++
 indra/llui/llfocusmgr.h          |  2 ++
 indra/llui/llview.h              |  5 +++++
 indra/newview/llpreviewscript.h  |  2 ++
 indra/newview/llviewerwindow.cpp | 11 ++++++++++-
 5 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/indra/llui/llfocusmgr.cpp b/indra/llui/llfocusmgr.cpp
index 1f16d12adda..7fbfd80d8da 100644
--- a/indra/llui/llfocusmgr.cpp
+++ b/indra/llui/llfocusmgr.cpp
@@ -315,6 +315,20 @@ void LLFocusMgr::removeKeyboardFocusWithoutCallback( const LLFocusableElement* f
 	}
 }
 
+bool LLFocusMgr::keyboardFocusHasMenus() const
+{
+	LLView* focus_view = dynamic_cast<LLView*>(mKeyboardFocus);
+	while( focus_view )
+	{
+		if(focus_view->hasMenus())
+		{
+			return true;
+		}
+
+		focus_view = focus_view->getParent();
+	}
+	return false;
+}
 
 void LLFocusMgr::setMouseCapture( LLMouseHandler* new_captor )
 {
diff --git a/indra/llui/llfocusmgr.h b/indra/llui/llfocusmgr.h
index eef82a3b5ab..e09bad0187d 100644
--- a/indra/llui/llfocusmgr.h
+++ b/indra/llui/llfocusmgr.h
@@ -118,6 +118,8 @@ class LLFocusMgr
 	void			unlockFocus();
 	BOOL			focusLocked() const { return mLockedView != NULL; }
 
+	bool			keyboardFocusHasMenus() const;
+
 private:
 	LLUICtrl*			mLockedView;
 
diff --git a/indra/llui/llview.h b/indra/llui/llview.h
index f7175112bff..62683491efb 100644
--- a/indra/llui/llview.h
+++ b/indra/llui/llview.h
@@ -277,6 +277,11 @@ class LLView : public LLMouseHandler, public LLMortician, public LLFocusableElem
 	BOOL focusNextRoot();
 	BOOL focusPrevRoot();
 
+	// Normally we want the app menus to get priority on modified keys
+	// However, if this item claims to have menus then we want to give
+	// it first chance at handling them. (eg. the script editor)
+	virtual bool	hasMenus() const { return false; };
+
 	// delete all children. Override this function if you need to
 	// perform any extra clean up such as cached pointers to selected
 	// children, etc.
diff --git a/indra/newview/llpreviewscript.h b/indra/newview/llpreviewscript.h
index ef4f0d9c204..3207da4e00f 100644
--- a/indra/newview/llpreviewscript.h
+++ b/indra/newview/llpreviewscript.h
@@ -87,6 +87,8 @@ class LLScriptEdCore : public LLPanel
 	static void		onBtnInsertSample(void*);
 	static void		onBtnInsertFunction(LLUICtrl*, void*);
 
+	virtual bool	hasMenus() const { return true; }
+
 private:
 	void		onBtnHelp();
 	void		onBtnDynamicHelp();
diff --git a/indra/newview/llviewerwindow.cpp b/indra/newview/llviewerwindow.cpp
index 0a3a8993eca..5a069547e4f 100644
--- a/indra/newview/llviewerwindow.cpp
+++ b/indra/newview/llviewerwindow.cpp
@@ -2134,10 +2134,20 @@ BOOL LLViewerWindow::handleKey(KEY key, MASK mask)
 		return TRUE;
 	}
 
+	LLFocusableElement* keyboard_focus = gFocusMgr.getKeyboardFocus();
+
 	// give menus a chance to handle modified (Ctrl, Alt) shortcut keys before current focus 
 	// as long as focus isn't locked
 	if (mask & (MASK_CONTROL | MASK_ALT) && !gFocusMgr.focusLocked())
 	{
+		// Check the current floater's menu first, if it has one.
+		if (gFocusMgr.keyboardFocusHasMenus()
+			&& keyboard_focus 
+			&& keyboard_focus->handleKey(key,mask,FALSE))
+		{
+			return TRUE;
+		}
+
 		if ((gMenuBarView && gMenuBarView->handleAcceleratorKey(key, mask))
 			||(gLoginMenuBarView && gLoginMenuBarView->handleAcceleratorKey(key, mask)))
 		{
@@ -2173,7 +2183,6 @@ BOOL LLViewerWindow::handleKey(KEY key, MASK mask)
 	}
 
 	// Traverses up the hierarchy
-	LLFocusableElement* keyboard_focus = gFocusMgr.getKeyboardFocus();
 	if( keyboard_focus )
 	{
 		LLLineEditor* chat_editor = LLBottomTray::instanceExists() ? LLBottomTray::getInstance()->getNearbyChatBar()->getChatBox() : NULL;
-- 
GitLab