#include <wobject/xstring.hpp>
|
#include <wobject/xwin.hpp>
|
#include <wobject/xaserver.hpp>
|
#include <wobject/xaserverarg.hpp>
|
#include <xcontrol/xtreeview.hpp>
|
#include <xcontrol/xlayersheet.hpp>
|
#include <xcontrol/xdwgrid.hpp>
|
#include <xcontrol/xsedit.hpp>
|
#include <xcontrol/xcombobox.hpp>
|
#include "XDevEditPage.hpp"
|
|
using xml = KXMLDOMDocument;
|
class export XDevEditXML : public XDevEditPage
|
{
|
public:
|
XDevEditXML(void* implPtr, HWND hWnd) :XDevEditPage(implPtr, hWnd) {}
|
public:
|
static XDevEditXML* CreateInstance(void* implPtr, void* hWnd)
|
{
|
XDevEditXML* pWin = new XDevEditXML(implPtr, (HWND)hWnd);
|
return pWin;
|
}
|
private:
|
xnode m_agentNode; //Agent Condition
|
xstring m_agentCond; //Agent Node
|
public:
|
int SetAgent()
|
{
|
/*xstring xfNodeAgentArea = L"agentarea";
|
xnode anode = GetAgentNode(xfNodeAgentArea);
|
auto xframeElement = GetElement();
|
auto agent = xframeElement.selectSingleNode(L"agent/"+xfNodeAgentArea+L"[1]/*");
|
if(agent)
|
{
|
xstring s = agent.xml;
|
m_agentNode = SetAgentNodeContent (anode,s);
|
}*/
|
return 1;
|
}
|
|
//½¹µã¼¤»î´¦Àíº¯Êý
|
int OnSetFocus(TEvent* evt,LPARAM param)
|
{
|
SetAgent();
|
|
//ÖØÖù¤¾ßÌõ
|
return 1;
|
}
|
|
int LoadData()
|
{
|
if (!GetWinParam()) return 1;
|
xstring content = GetData();
|
//trace(content);
|
xsedit xs = GetControl(L"content");
|
if (content != L"")
|
{
|
xs.LoadContent(content,L".xml");
|
}
|
else
|
xs.LoadContent(L"",L".xml");
|
return 1;
|
}
|
|
xstring OnGetType()
|
{
|
xwin w = GetFrameWindow();
|
xtreeview tv_folder = w.GetControl(L"DevExplorer");
|
HTREEITEM hItem = (HTREEITEM)GetWinParam();
|
KXMLDOMElement e = tv_folder.GetItemData(hItem);
|
xstring str = e.getAttribute(L"type");
|
return str;
|
}
|
|
//ÃüÁî·¢²¼º¯Êý
|
int OnCmdDispatch(xstring comdid)
|
{
|
xstring content;
|
xsedit xs = GetControl(L"content");
|
xs.GetContent(content);
|
|
HCURSOR hCursor = xutil::SetCursorWait();
|
if (comdid == L"xmFileSave")
|
{
|
//save xml content
|
SaveContent(content);
|
}
|
else if (comdid == L"xmRun")
|
{
|
xml x = new xml;
|
x.loadXML(content);
|
KXMLDOMElement e = x.documentElement();
|
if (e.selectSingleNode(L"test[1]/@xpage"))
|
{
|
xstring xpage = e.selectSingleNode(L"test/@xpage").text();
|
xaserverarg arg;
|
arg.AddArg(L"configxml", content);
|
//arg.AddArg(L"config", L"");
|
if (e.selectSingleNode(L"test/@EntityID"))
|
arg.AddArg(L"EntityID", e.selectSingleNode(L"test/@EntityID").text());
|
OpenWindow(xpage + L"native=true", arg);
|
}
|
}
|
else if (comdid == L"xmValid")
|
{
|
xml x;
|
if (!x.loadXML(content))
|
{
|
KXMLDOMParseError pError = x.parseError();
|
if (pError)
|
{
|
xstring str = pError.srcText();
|
xstring sError = L"\r\nXML´íÎó: " + str.trim() + L"\r\n";
|
int s = pError.errorCode();
|
sError += L" ´úÂë: " + xstring(s) + L"\r\n";
|
s = pError.line();
|
sError += L" λÖÃ: µÚ" + xstring(s) + L"ÐÐ,L";
|
s = pError.linepos();
|
sError += L"µÚ" + xstring(s) + L"ÁÐ" + L"\r\n";
|
str = pError.reason();
|
sError += L" ÔÒò: " + str;
|
trace(sError);
|
}
|
else
|
{
|
trace(L"XML ´íÎó");
|
}
|
xutil::RestoreCursor(hCursor);
|
return -1;
|
}
|
xstring sType = OnGetType();
|
if (sType == L"xml.xsd")
|
{
|
BSTR sError;
|
x.ValidSchema(content.c_str(), sError);
|
trace(sError);
|
}
|
}
|
else if (comdid == L"xmEditFind")
|
{
|
xutil::RestoreCursor(hCursor);
|
xsedit xs = GetControl(L"content");
|
xs.OnFindDlg();
|
return 1;
|
}
|
else if (comdid == L"xmEditReplace")
|
{
|
xutil::RestoreCursor(hCursor);
|
xsedit xs = GetControl(L"content");
|
xs.OnReplaceDlg();
|
return 1;
|
}
|
xutil::RestoreCursor(hCursor);
|
return 0;
|
}
|
|
//ÃüÁî´¦Àíʼþ
|
int OnXCommand(TEvent* evt,LPARAM param)
|
{
|
return OnCmdDispatch(evt->xcommand.pStrID);
|
}
|
|
int OnLButtonDown(TEvent* evt,LPARAM p)
|
{
|
xsedit edit_1 = GetControl(L"content");
|
int sPos = edit_1.GetSelectionStart();
|
int ePos = edit_1.GetSelectionEnd();
|
xstring content = edit_1.GetText();
|
content = content.mid(sPos, ePos - sPos);
|
//trace(content);
|
if (content == L"") return -1;
|
xwin w = GetFrameWindow();
|
xtreeview tv_folder = w.GetControl(L"DevExplorer");
|
HTREEITEM hItem = (HTREEITEM)GetWinParam();
|
KXMLDOMElement e = tv_folder.GetItemData(hItem);
|
//trace(e.xml);
|
xstring str = e.getAttribute(L"type");
|
xstring uri = e.getAttribute(L"uri");
|
//trace(str);
|
xml xl = new xml;
|
xstring xtype = L"";
|
if (str == L"iface")
|
//xaserver::LoadUrl(GetServerUrl(),L"dev:xml[sale.data.url.xml]",L"",xl);
|
xtype = L"data";
|
else if (str == L"vface")
|
//xaserver::LoadUrl(GetServerUrl(),L"dev:xml[sale.view.url.xml]",L"",xl);
|
xtype = L"view";
|
else
|
return 0;
|
xaserver::LoadUrl(GetServerUrl(),L"dev:xml[sale." + xtype + L".url.xml]",L"",xl);
|
//trace(xl.xml());
|
auto doc = xl;
|
auto n = doc.selectSingleNode(L"//item[@src='dev:" + str + L"[" + uri + L"]']/@url");
|
//trace(n.xml);
|
xstring aurl = L"";
|
if (n)
|
{
|
xstring tmp = n.text();
|
aurl = L"/sale/" + xtype + L"/" + tmp + L"/" + content;
|
}
|
else
|
return -1;
|
trace(aurl);
|
xml x = new xml;
|
xaserverarg arg;
|
arg.AddArg(L"url",aurl + L"?node");
|
if (xaserver::ExecXQuery(GetServerUrl(),L"[service.url.xq]",arg.GetString(),x) != 1)
|
{
|
trace((xstring)L"error:" + x.xml());
|
return 0;
|
}
|
trace(x.xml());
|
xaserver::FetchXml(GetServerUrl(),L"dev:xpage[XDevEdit.xml]",L"",xl);
|
//trace(xl.xml());
|
auto n1 = xl.selectSingleNode(L"//editor[@filetype='" + str + L"']/@xpage");
|
if (n1)
|
{
|
xstring xpage = n1.text();
|
trace(xpage);
|
OpenWindow(L"dev:xpage[" + xpage + L"]", 0);
|
}
|
|
return 1;
|
}
|
int OnAttachEvent()
|
{
|
//°ó¶¨¹¤¾ßÌõµã»÷ʼþ
|
AttachEvent(L"WM_XCOMMAND",(FEvent)&XDevEditXML::OnXCommand);
|
//»ñÈ¡½¹µãʼþ£¬ÓÃÓÚÖØÖù¤¾ßÌõ
|
AttachEvent(L"WM_SETFOCUS", (FEvent)&XDevEditXML::OnSetFocus);
|
//AttachEvent(L"content",L"WM_LBUTTONDOWN", ,(FEvent)&XDevEditXML::OnLButtonDown);
|
|
return 1;
|
}
|
|
int OnInitial()
|
{
|
SetAgent();
|
|
OnAttachEvent();
|
|
return 1;
|
}
|
|
int onload()
|
{
|
OnInitial();
|
LoadData();
|
|
return 1;
|
}
|
};
|