mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-15 20:08:54 +03:00
Added stylesheet @import into live reload filewatch for a canvas
This commit is contained in:
@@ -50,6 +50,11 @@ namespace Nuake
|
||||
bool sourceHasChanged = false;
|
||||
for (auto& fileAssociated : ui->GetCanvas()->GetSourceFiles())
|
||||
{
|
||||
if (!fileAssociated)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Re-fetching the file object because the Scan might have invalided the pointer.
|
||||
if (FileSystem::GetFile(fileAssociated->GetRelativePath())->GetHasBeenModified())
|
||||
{
|
||||
|
||||
@@ -359,7 +359,7 @@ Ref<Canvas> CanvasParser::Parse(CanvasPtr canvas, const std::string& path)
|
||||
std::string relativePath = styleSheet->Value();
|
||||
if (FileSystem::FileExists(relativePath))
|
||||
{
|
||||
auto styleSheet = StyleSheetParser::Get().Parse(relativePath);
|
||||
auto styleSheet = StyleSheetParser::Get().Parse(canvas, relativePath);
|
||||
currentParsingCanvas->AddSourceFile(FileSystem::GetFile(relativePath));
|
||||
canvas->SetStyleSheet(styleSheet);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "StyleSheetParser.h"
|
||||
|
||||
#include "src/FileSystem/FileSystem.h"
|
||||
#include <src/UI/Nodes/Canvas.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
@@ -9,10 +10,11 @@
|
||||
|
||||
using namespace NuakeUI;
|
||||
|
||||
std::shared_ptr<StyleSheet> StyleSheetParser::Parse(const std::string& path)
|
||||
std::shared_ptr<StyleSheet> StyleSheetParser::Parse(Ref<NuakeUI::Canvas> canvas, const std::string& path)
|
||||
{
|
||||
assert(FileSystem::FileExists(path));
|
||||
|
||||
currentCanvas = canvas;
|
||||
_parsingPath = path;
|
||||
|
||||
std::string fileContent = FileSystem::ReadFile(path);
|
||||
@@ -31,6 +33,7 @@ std::shared_ptr<StyleSheet> StyleSheetParser::Parse(const std::string& path)
|
||||
std::cout << "ERROR at line " + std::to_string(error->first_line) +
|
||||
" : " + std::to_string(error->first_column) << std::endl;
|
||||
}
|
||||
|
||||
return styleSheet;
|
||||
}
|
||||
else
|
||||
@@ -95,6 +98,9 @@ void StyleSheetParser::ParseImportRule(KatanaImportRule* rule, StyleSheetPtr sty
|
||||
std::string fileContent = FileSystem::ReadFile(path);
|
||||
auto data = katana_parse(fileContent.c_str(), fileContent.length(), KatanaParserModeStylesheet);
|
||||
|
||||
// Add to source files anyway since the user might fix his errors, we want to reload.
|
||||
currentCanvas->AddSourceFile(FileSystem::GetFile(path));
|
||||
|
||||
if (data->errors.length > 0)
|
||||
{
|
||||
KatanaArray errors = data->errors;
|
||||
@@ -106,7 +112,7 @@ void StyleSheetParser::ParseImportRule(KatanaImportRule* rule, StyleSheetPtr sty
|
||||
std::cout << "ERROR at line " + std::to_string(error->first_line) +
|
||||
" : " + std::to_string(error->first_column) << std::endl;
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
#include "../Vendors/katana-parser/katana.h"
|
||||
|
||||
#include "src/UI/Nodes/Canvas.h"
|
||||
|
||||
namespace NuakeUI
|
||||
{
|
||||
class StyleSheetParser
|
||||
@@ -20,9 +22,10 @@ namespace NuakeUI
|
||||
StyleSheetParser() = default;
|
||||
~StyleSheetParser() = default;
|
||||
|
||||
std::shared_ptr<StyleSheet> Parse(const std::string& path);
|
||||
std::shared_ptr<StyleSheet> Parse(Ref<NuakeUI::Canvas> canvas, const std::string& path);
|
||||
|
||||
private:
|
||||
Ref<Canvas> currentCanvas;
|
||||
std::string _parsingPath;
|
||||
std::vector<std::string> _visitedFiles;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user