Index: ide/Json.cpp
===================================================================
--- ide/Json.cpp	(wersja 7589)
+++ ide/Json.cpp	(kopia robocza)
@@ -1,22 +1,50 @@
 #include "ide.h"
 
-struct JsonView : TopWindow {
-	TreeCtrl  tree;
+class JsonView : public TopWindow {
+	typedef JsonView CLASSNAME;
+
+public:
+	TreeCtrl              tree;
+	LineEdit              view;
+	FrameTop<StaticRect>  errorbg;
+	Label                 error;
 	
+public:
+	JsonView();
+	
 	virtual bool Key(dword key, int count);
 	virtual void Close();
 
-	int  AddNode(int parent_id, const Value& id, const String& name, const Value& v);
-	void Load(const char *json);
+	void Load(const String& json);
 	void CopyPath();
 
 	void Serialize(Stream& s);
 
-	typedef JsonView CLASSNAME;
+private:
+	void   Reset();
+	String Load0(const String& json);
 	
-	JsonView();
+	int AddNode(int parent_id, const Value& id, const String& name, const Value& v);
 };
 
+JsonView::JsonView()
+{
+	Title("JSON view");
+	Sizeable().Zoomable();
+	Icon(IdeCommonImg::xml());
+	
+	Add(tree.SizePos()); 	
+	Add(view.SizePos());
+	
+	error.SetFont(Arial(20)).SetInk(Red);
+	errorbg.Height(25).Add(error.SizePos());
+	view.SetReadOnly();
+	view.SetColor(LineEdit::PAPER_READONLY, SColorPaper());
+	tree.SetDisplay(QTFDisplay());
+	tree.NoRoot();
+	tree.WhenLeftDouble = THISBACK(CopyPath);
+}
+
 bool JsonView::Key(dword key, int count)
 {
 	if(key == K_ESCAPE) {
@@ -26,10 +54,86 @@
 	return false;
 }
 
+void JsonView::Load(const String& json)
+{
+	Reset();
+	
+	String parsingError = Load0(json);
+	if(parsingError.GetCount() > 0) {
+		parsingError.Set(0, ToLower(parsingError[0]));
+		
+		error = "Json parsing error: \"" + parsingError + "\".";
+		AddFrame(errorbg);
+		view.Show();
+		view <<= json;
+		
+		return;
+	}
+	
+	tree.Show();
+	tree.SetFocus();
+}
+
+void JsonView::CopyPath()
+{
+	int id = tree.GetCursor();
+	String path;
+	while(id) {
+		Value k = tree.Get(id);
+		if(!IsNull(k)) {
+			if(IsNumber(k))
+				path = "[" + AsString(k) + "]" + path;
+			if(IsString(k))
+				path = "[" + AsCString(String(k)) + "]" + path;
+		}
+		id = tree.GetParent(id);
+	}
+	WriteClipboardText(path);
+}
+
+void JsonView::Serialize(Stream& s)
+{
+	int version = 0;
+	s / version;
+	SerializePlacement(s);
+}
+
+void JsonView::Close()
+{
+	StoreToGlobal(*this, "JSONview");
+	TopWindow::Close();
+}
+
+void JsonView::Reset()
+{
+	RemoveFrame(errorbg);
+	view.Clear();
+	view.Hide();
+	tree.Clear();
+	tree.Hide();
+}
+
+String JsonView::Load0(const String& json)
+{
+	String parsingError;
+	
+	try {
+		tree.Open(AddNode(0, Null, "JSON", ParseJSON(json)));
+	}
+	catch(const Exc& e) {
+		parsingError = e;
+	}
+	
+	return parsingError;
+}
+
 int JsonView::AddNode(int parent_id, const Value& id, const String& name, const Value& v)
 {
 	if(IsError(v)) {
-		parent_id = tree.Add(parent_id, IdeImg::Error(), "ERROR", "[@R [* " + GetErrorText(v));
+		// TODO: Replace with JsonExc or something that is more accurate in this situation.
+		String errorText = GetErrorText(v);
+		errorText.Remove(0, errorText.Find(" ") + 1);
+		throw Exc(errorText);
 	}
 	else
 	if(v.Is<ValueMap>()) {
@@ -67,50 +171,6 @@
 	return parent_id;
 }
 
-void JsonView::Load(const char *json)
-{
-	tree.Clear();
-	tree.Open(AddNode(0, Null, "JSON", ParseJSON(json)));
-}
-
-void JsonView::CopyPath()
-{
-	int id = tree.GetCursor();
-	String path;
-	while(id) {
-		Value k = tree.Get(id);
-		if(!IsNull(k)) {
-			if(IsNumber(k))
-				path = "[" + AsString(k) + "]" + path;
-			if(IsString(k))
-				path = "[" + AsCString(String(k)) + "]" + path;
-		}
-		id = tree.GetParent(id);
-	}
-	WriteClipboardText(path);
-}
-
-void JsonView::Serialize(Stream& s)
-{
-	int version = 0;
-	s / version;
-	SerializePlacement(s);
-}
-
-JsonView::JsonView()
-{
-	Title("JSON view");
-	Add(tree.SizePos()); tree.SetDisplay(QTFDisplay()); tree.NoRoot();	Sizeable().Zoomable();
-	Icon(IdeCommonImg::xml());
-	tree.WhenLeftDouble = THISBACK(CopyPath);
-}
-
-void JsonView::Close()
-{
-	StoreToGlobal(*this, "JSONview");
-	TopWindow::Close();
-}
-
 void Ide::Json()
 {
 	static JsonView dlg;
Index: ide/Xml.cpp
===================================================================
--- ide/Xml.cpp	(wersja 7589)
+++ ide/Xml.cpp	(kopia robocza)
@@ -1,24 +1,30 @@
 #include "ide.h"
 
-struct XmlView : public TopWindow {
+class XmlView : public TopWindow {
+	typedef XmlView CLASSNAME;
+
+public:
 	TreeCtrl              xml;
 	LineEdit              view;
 	FrameTop<StaticRect>  errorbg;
 	Label                 error;
 	ParentCtrl            data;
-
+	
+	XmlView();
+	
 	virtual bool Key(dword key, int count);
 	virtual void Close();
 
-	void Load(int parent, XmlParser& p);
 	void Load(const String& txt);
 	void CopyPath();
 
-	typedef XmlView CLASSNAME;
-
 	void Serialize(Stream& s);
 
-	XmlView();
+private:
+	String Load0(XmlParser& p);
+	void   Load0(int parent, XmlParser& p);
+	
+	void   Reset();
 };
 
 bool XmlView::Key(dword key, int count)
@@ -30,46 +36,36 @@
 	return false;
 }
 
-void XmlView::Load(int parent, XmlParser& p)
+XmlView::XmlView()
 {
-	if(p.IsTag()) {
-		String tag = p.ReadTag();
-		String txt = tag;
-		for(int i = 0; i < p.GetAttrCount(); i++)
-			txt << ' ' << p.GetAttr(i) << "=\"" << p[i] << "\"";
-		parent = xml.Add(parent, IdeImg::XmlTag(), tag, txt);
-		while(!p.End()) {
-			if(p.IsEof())
-				throw XmlError("Unexpected end of text.");
-			Load(parent, p);
-		}
-	}
-	else
-	if(p.IsText())
-		xml.Add(parent, IdeImg::XmlText(), Null, NormalizeSpaces(p.ReadText()));
-	else
-	if(p.IsPI())
-		xml.Add(parent, IdeImg::XmlPI(), Null, NormalizeSpaces(p.ReadPI()));
-	else
-	if(p.IsDecl())
-		xml.Add(parent, IdeImg::XmlDecl(), Null, NormalizeSpaces(p.ReadDecl()));
-	else
-	if(p.IsComment())
-		xml.Add(parent, IdeImg::XmlComment(), Null, NormalizeSpaces(p.ReadComment()));
-	else
-		throw XmlError("Unexpected input.");
+	Title("XML view");
+	Sizeable().Zoomable();
+	Icon(IdeCommonImg::xml());
+
+	xml.NoRoot();
+
+	error.SetFont(Arial(20)).SetInk(Red);
+	errorbg.Height(25).Add(error.SizePos());
+	view.SetReadOnly();
+	view.SetColor(LineEdit::PAPER_READONLY, SColorPaper());
+
+	Add(xml.SizePos());
+	Add(view.SizePos());
+
+	xml.WhenLeftDouble = THISBACK(CopyPath);
 }
 
 void XmlView::Load(const String& txt)
 {
+	Reset();
+	
 	XmlParser p(txt);
-	xml.Clear();
-	try {
-		while(!p.IsEof())
-			Load(0, p);
-	}
-	catch(XmlError e) {
-		error = "XML parsing error: " + e;
+	String parsingError = Load0(p);
+	if(parsingError.GetCount() > 0) {
+		parsingError.Set(0, ToLower(parsingError[0]));
+		
+		error = "XML parsing error: " + parsingError + ".";
+		AddFrame(errorbg);
 		view.Show();
 		view <<= txt;
 		view.SetCursor(view.GetPos(p.GetLine() - 1, p.GetColumn() - 1));
@@ -76,6 +72,7 @@
 		view.SetFocus();
 		return;
 	}
+	
 	xml.Show();
 	xml.SetFocus();
 }
@@ -106,29 +103,61 @@
 	TopWindow::Close();
 }
 
-XmlView::XmlView()
+String XmlView::Load0(XmlParser& p) {
+	String parsingError;
+	
+	try {
+		while(!p.IsEof())
+			Load0(0, p);
+	}
+	catch(const XmlError& e) {
+		parsingError = e;
+	}
+	
+	if(!parsingError.GetCount() && !xml.GetChildCount(0))
+	 	parsingError = "Not found any XML tags";
+	
+	return parsingError;
+}
+
+void XmlView::Load0(int parent, XmlParser& p)
 {
-	Title("XML view");
+	if(p.IsTag()) {
+		String tag = p.ReadTag();
+		String txt = tag;
+		for(int i = 0; i < p.GetAttrCount(); i++)
+			txt << ' ' << p.GetAttr(i) << "=\"" << p[i] << "\"";
+		parent = xml.Add(parent, IdeImg::XmlTag(), tag, txt);
+		while(!p.End()) {
+			if(p.IsEof())
+				throw XmlError("Unexpected end of text");
+			Load0(parent, p);
+		}
+	}
+	else
+	if(p.IsText())
+		xml.Add(parent, IdeImg::XmlText(), Null, NormalizeSpaces(p.ReadText()));
+	else
+	if(p.IsPI())
+		xml.Add(parent, IdeImg::XmlPI(), Null, NormalizeSpaces(p.ReadPI()));
+	else
+	if(p.IsDecl())
+		xml.Add(parent, IdeImg::XmlDecl(), Null, NormalizeSpaces(p.ReadDecl()));
+	else
+	if(p.IsComment())
+		xml.Add(parent, IdeImg::XmlComment(), Null, NormalizeSpaces(p.ReadComment()));
+	else
+		throw XmlError("Unexpected input");
+}
 
-	xml.NoRoot();
-
-	error.SetFont(Arial(20)).SetInk(Red);
-	errorbg.Height(25).Add(error.SizePos());
-	view.AddFrame(errorbg);
-	view.SetReadOnly();
-	view.SetColor(LineEdit::PAPER_READONLY, SColorPaper());
-
+void XmlView::Reset()
+{
+	RemoveFrame(errorbg);
+	
+	xml.Clear();
 	xml.Hide();
+	view.Clear();
 	view.Hide();
-
-	Add(xml.SizePos());
-	Add(view.SizePos());
-
-	Sizeable().Zoomable();
-
-	Icon(IdeCommonImg::xml());
-	
-	xml.WhenLeftDouble = THISBACK(CopyPath);
 }
 
 void Ide::Xml()
