Browse Source

Add method to reload ElementDocument's stylesheet

Lucien Catonnet 5 năm trước cách đây
mục cha
commit
698df0ae7a
2 tập tin đã thay đổi với 18 bổ sung0 xóa
  1. 2 0
      Include/RmlUi/Core/ElementDocument.h
  2. 16 0
      Source/Core/ElementDocument.cpp

+ 2 - 0
Include/RmlUi/Core/ElementDocument.h

@@ -87,6 +87,8 @@ public:
 	void SetStyleSheet(SharedPtr<StyleSheet> style_sheet);
 	/// Returns the document's style sheet.
 	const SharedPtr<StyleSheet>& GetStyleSheet() const override;
+	/// Reload the document's style sheet from source files.
+	void ReloadStyleSheet();
 
 	/// Brings the document to the front of the document stack.
 	void PullToFront();

+ 16 - 0
Source/Core/ElementDocument.cpp

@@ -210,6 +210,22 @@ const SharedPtr<StyleSheet>& ElementDocument::GetStyleSheet() const
 	return style_sheet;
 }
 
+// Reload the document's style sheet from source files.
+void ElementDocument::ReloadStyleSheet()
+{
+	auto stream = MakeUnique<StreamFile>();
+	if(!stream->Open(source_url))
+		return;
+
+	Factory::ClearStyleSheetCache();
+	ElementPtr temp_doc = Factory::InstanceDocumentStream(context, stream.get());
+	if(!temp_doc)
+		return;
+
+	SetStyleSheet(temp_doc->GetStyleSheet());
+	context->UnloadDocument(static_cast<ElementDocument*>(temp_doc.get()));
+}
+
 // Brings the document to the front of the document stack.
 void ElementDocument::PullToFront()
 {