Kaynağa Gözat

Shell: Reload style sheets with Ctrl+R

Michael Ragazzon 4 yıl önce
ebeveyn
işleme
f7fbce7c34

+ 13 - 0
Samples/shell/src/win32/InputWin32.cpp

@@ -31,6 +31,7 @@
 #include <RmlUi/Core/Input.h>
 #include <RmlUi/Core/Math.h>
 #include <RmlUi/Core/StringUtilities.h>
+#include <RmlUi/Core/ElementDocument.h>
 #include <RmlUi/Debugger.h>
 #include <Shell.h>
 #include <string.h>
@@ -121,6 +122,18 @@ void InputWin32::ProcessWindowsEvent(HWND window, UINT message, WPARAM w_param,
 				const float new_dp_ratio = Rml::Math::Min(context->GetDensityIndependentPixelRatio() * 1.2f, 2.5f);
 				context->SetDensityIndependentPixelRatio(new_dp_ratio);
 			}
+			else if (key_identifier == Rml::Input::KI_R && key_modifier_state & Rml::Input::KM_CTRL)
+			{
+				for (int i = 0; i < context->GetNumDocuments(); i++)
+				{
+					Rml::ElementDocument* document = context->GetDocument(i);
+					const Rml::String& src = document->GetSourceURL();
+					if (src.size() > 4 && src.substr(src.size() - 4) == ".rml")
+					{
+						document->ReloadStyleSheet();
+					}
+				}
+			}
 			else
 			{
 				context->ProcessKeyDown(key_identifier, key_modifier_state);

+ 24 - 9
Samples/shell/src/x11/InputX11.cpp

@@ -28,6 +28,7 @@
 
 #include <x11/InputX11.h>
 #include <RmlUi/Core/Context.h>
+#include <RmlUi/Core/ElementDocument.h>
 #include <RmlUi/Core/Input.h>
 #include <RmlUi/Debugger.h>
 #include <Shell.h>
@@ -156,21 +157,35 @@ void InputX11::ProcessXEvent(Display* display, const XEvent& event)
 				key_identifier = key_identifier_map[lower_sym & 0xFF];
 			}
 
-			int key_modifier_state = GetKeyModifierState(event.xkey.state);
+			const int key_modifier_state = GetKeyModifierState(event.xkey.state);
 
-			// Check for F8 to toggle the debugger.
+			// Check for special key combinations
 			if (key_identifier == Rml::Input::KI_F8)
 			{
 				Rml::Debugger::SetVisible(!Rml::Debugger::IsVisible());
-				break;
 			}
+			else if (key_identifier == Rml::Input::KI_R && key_modifier_state & Rml::Input::KM_CTRL)
+			{
+				for (int i = 0; i < context->GetNumDocuments(); i++)
+				{
+					Rml::ElementDocument* document = context->GetDocument(i);
+					const Rml::String& src = document->GetSourceURL();
+					if (src.size() > 4 && src.substr(src.size() - 4) == ".rml")
+					{
+						document->ReloadStyleSheet();
+					}
+				}
+			}
+			else
+			{
+				// No special shortcut, pass the key on to the context.
+				if (key_identifier != Rml::Input::KI_UNKNOWN)
+					context->ProcessKeyDown(key_identifier, key_modifier_state);
 
-			if (key_identifier != Rml::Input::KI_UNKNOWN)
-				context->ProcessKeyDown(key_identifier, key_modifier_state);
-
-			Rml::Character character = GetCharacterCode(key_identifier, key_modifier_state);
-			if (character != Rml::Character::Null)
-				context->ProcessTextInput(character);
+				Rml::Character character = GetCharacterCode(key_identifier, key_modifier_state);
+				if (character != Rml::Character::Null)
+					context->ProcessTextInput(character);
+			}
 		}
 		break;