瀏覽代碼

Feature: Restore focus to last focused editor widget after the window its docked on re-gains focus

BearishSun 6 年之前
父節點
當前提交
7467dcca05

+ 28 - 2
Source/EditorCore/EditorWindow/BsEditorWidgetManager.cpp

@@ -40,7 +40,7 @@ namespace bs
 		mOnFocusLostConn.disconnect();
 		mOnFocusGainedConn.disconnect();
 
-		Map<String, EditorWidgetBase*> widgetsCopy = mActiveWidgets;
+		UnorderedMap<String, EditorWidgetBase*> widgetsCopy = mActiveWidgets;
 
 		for (auto& widget : widgetsCopy)
 			widget.second->close();
@@ -134,6 +134,14 @@ namespace bs
 		if(findIter != mActiveWidgets.end())
 			mActiveWidgets.erase(findIter);
 
+		for(auto iter = mSavedFocusedWidgets.begin(); iter != mSavedFocusedWidgets.end();)
+		{
+			if (iter->second == widget)
+				iter = mSavedFocusedWidgets.erase(iter);
+			else
+				++iter;
+		}
+
 		if(widget->mParent != nullptr)
 			widget->mParent->_notifyWidgetDestroyed(widget);
 
@@ -295,7 +303,22 @@ namespace bs
 
 	void EditorWidgetManager::onFocusGained(const RenderWindow& window)
 	{
-		// Do nothing, possibly regain focus on last focused widget?
+		auto iterFind = mSavedFocusedWidgets.find(&window);
+		if(iterFind != mSavedFocusedWidgets.end())
+		{
+			EditorWidgetBase* widget = iterFind->second;
+			EditorWidgetContainer* parentContainer = widget->_getParent();
+			if (parentContainer != nullptr)
+			{
+				EditorWindowBase* parentWindow = parentContainer->getParentWindow();
+				SPtr<RenderWindow> parentRenderWindow = parentWindow->getRenderWindow();
+
+				if (parentRenderWindow.get() == &window)
+					widget->_setHasFocus(true);
+			}
+			
+			mSavedFocusedWidgets.erase(iterFind);;
+		}
 	}
 
 	void EditorWidgetManager::onFocusLost(const RenderWindow& window)
@@ -313,6 +336,9 @@ namespace bs
 			if (parentRenderWindow.get() != &window)
 				continue;
 
+			if (widget->hasFocus())
+				mSavedFocusedWidgets[&window] = widget;
+
 			widget->_setHasFocus(false);
 		}
 	}

+ 3 - 2
Source/EditorCore/EditorWindow/BsEditorWidgetManager.h

@@ -84,8 +84,9 @@ namespace bs
 		/**	Triggered whenever a window loses focus. */
 		void onFocusLost(const RenderWindow& window);
 
-		Map<String, EditorWidgetBase*> mActiveWidgets;
-		Map<String, std::function<EditorWidgetBase*(EditorWidgetContainer&)>> mCreateCallbacks;
+		UnorderedMap<String, EditorWidgetBase*> mActiveWidgets;
+		UnorderedMap<const RenderWindow*, EditorWidgetBase*> mSavedFocusedWidgets;
+		UnorderedMap<String, std::function<EditorWidgetBase*(EditorWidgetContainer&)>> mCreateCallbacks;
 
 		HEvent mOnFocusLostConn;
 		HEvent mOnFocusGainedConn;

+ 1 - 1
Source/bsf

@@ -1 +1 @@
-Subproject commit 3fd3f6de6b5fd0fd019964a1c3c0e4e91f31610b
+Subproject commit c1fc166d7b91b2ed5c4296f090f163479d1b1927