0 Star 2 Fork 1

Cadaqs/XStudio

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
XWndClass.xcsm 24.93 KB
一键复制 编辑 原始数据 按行查看 历史
Cadaqs 提交于 2020-11-28 21:28 . 9233
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
class XWndClass : QDockWidget
{
QTreeWidget _treeview;
public XWorkspace workspace;
JsonArray sources;
QLineEdit editSearch;
ContextMenu _contextMenu = new ContextMenu();
public static class ItemLoader
{
public long loaditem;
public JsonArray object;
public bool isStatic;
public ItemLoader(long i, JsonArray o, bool bs)
{
loaditem = i;
object = o;
isStatic = bs;
}
};
public static class Position : ClassViewInfo
{
public Position(int s,int l,int r, bool b, JsonObject _node)
{
source = s;
line = l;
row = r;
lib = b;
node = _node;
}
public int source = -1, line, row;
public bool lib = false;
public JsonObject node;
public int getLine(){
return line;
}
int getColumn(){
return row;
}
JsonObject getObject(){
return node;
}
bool isExternal(){
return lib;
}
};
Map<long, ItemLoader> expand_data = new Map<long, ItemLoader>();
Map<long, Position> position_info = new Map<long, Position>();
public static XWndClass wndClass;
String searchkey = nilptr;
public void onAttach()
{
editSearch = (QLineEdit)attachByName(new QLineEdit(), "classSearch");
_treeview = (QTreeWidget)attachByName(new QTreeWidget(), "tree_class");
wndClass = this;
/*
改成layout之后就不需要resize了
setOnLayoutEventListener(new onLayoutEventListener(){
void onResize(QObject obj, int w, int h, int oldw, int oldh)override {
if (_treeview != nilptr){
_treeview.resize(w, h - 25);
}
}
});*/
_treeview.setOnTreeViewItemEvent(new onTreeViewItemEvent() {
void onItemExpanded(QTreeWidget,long item)override {
XWndClass.this.expandLoad(item);
}
void onItemDoubleClicked(QTreeWidget,long item, int column) {
String text = _treeview.getItemText(item,0);
if (text.equals("外部库")) {
workspace.showProperites("项目设置");
}
}
void onItemClicked(QTreeWidget,long item, int column)override {
XWndClass.this.clickItem(item);
}
void onItemPressed(QTreeWidget, long item, int column)override {
Position pos = nilptr;
String source = nilptr;
try {
pos = position_info.get(item);
source = sources.getString(pos.source);
} catch(Exception e) {
}
PluginsController.updateClassViewActionState(workspace.getCurrentProject(), source, pos);
}
});
editSearch.setOnKeyEventListener(new onKeyEventListener() {
bool onKeyPress(QObject obj,int key,bool repeat,int count,String text,int scanCode,int virtualKey,int modifier)override {
if (key == Constant.Key_Escape) {
editSearch.setText("");
} else if (key == Constant.Key_Return) {
synchronized(searchLock) {
searchLock.notify();
}
}
return true;
}
});
editSearch.setOnEditEventListener(new onEditEventListener() {
void onTextChanged(QObject, String text)override {
if (ignoreSearch || workspace.getCurrentProject() == nilptr) {
return;
}
searchkey = text;
if (searchkey.length() == 0) {
searchkey = nilptr;
refresh();
} else {
onSearch();
}
}
});
}
public void createContextMenu()
{
ActionIdent [] ais = PluginsController.getClassViewContextActions();
__nilptr_safe(_treeview);
String [] acts = { "复制到剪贴板" };
_contextMenu.create(_treeview, acts, new onEventListener (){
public void onTrigger(QObject obj) {
long item = _treeview.getSelItem();
if (item != 0){
String str = _treeview.getItemText(item,0);
if (str != nilptr){
setClipboardText(str);
}
}
}
}, ais);
_contextMenu.setEnable(0, true);
}
Thread searchThread = nilptr;
bool ignoreSearch = false;
Object searchLock = new Object();
public void onSearch()
{
synchronized(searchLock) {
if (searchThread == nilptr) {
searchThread = new Thread() {
void run()override {
String currentKey = nilptr;
synchronized(searchLock) {
bool bw = false;
String _thekey = searchkey;
while (currentKey == nilptr || (_thekey != nilptr && currentKey.equals(_thekey) == false)) {
currentKey = _thekey;
if (bw == false) {
bw = searchLock.wait(800);
}
_thekey = searchkey;
}
}
ignoreSearch = true;
runOnUi(new Runnable() {
void run()override {
editSearch.setText("搜索中...");
editSearch.setEnabled(false);
}
});
if (currentKey != nilptr) {
search(workspace.getCurrentProject(), currentKey.upper());
}
synchronized(searchLock) {
if (currentKey != nilptr) {
refresh();
}
searchThread = nilptr;
}
runOnUi(new Runnable() {
void run()override {
if (currentKey != nilptr) {
editSearch.setText(currentKey);
} else {
editSearch.setText("");
}
editSearch.setEnabled(true);
editSearch.setFocus();
ignoreSearch = false;
}
});
}
};
searchThread.start();
}
}
}
public static void prepare(@NotNilptr Project project)
{
wndClass._treeview.addItem("res/toolbar/project.png", project.getName() + "(正在生成类视图...)");
}
public static void refresh()
{
XWndClass.postNotify(XWorkspace.AUTODOMPEVENTID);
}
public void clickItem(long item)
{
Position pos = nilptr;
try {
pos = position_info.get(item);
} catch(Exception e) {
}
if (pos != nilptr) {
//_system_.consoleWrite("" + pos.source + ": " + pos.line + "." + pos.row + "\n");
if (pos.source == -1) {
//QMessageBox.Information("注意", "对象不在源代码中定义.", QMessageBox.Ok, QMessageBox.Ok);
return ;
}
String source = sources.getString(pos.source);
if (source == nilptr || source.length() == 0) {
//QMessageBox.Information("注意", "对象不在源代码中定义.", QMessageBox.Ok, QMessageBox.Ok);
return ;
}
Project pjct = workspace.getCurrentProject();
if (pjct != nilptr) {
source = pjct.getFullPath(source);
}
if (XPlatform.existsSystemFile(source) == false) {
if (pos.lib == false) {
QMessageBox.Critical("文件不存在", "找不到文件:" + sources.getString(pos.source) + "该位置的文件已不存在.", QMessageBox.Ok, QMessageBox.Ok);
}
} else {
workspace.openTextFileInfo(source, pos.line + 1, pos.row + 1);
}
}
}
public void expandLoad(long item)
{
ItemLoader loader = nilptr;
try {
loader = expand_data.get(item);
} catch(Exception e) {
}
if (loader != nilptr) {
int count = loader.object.length();
if (count > 0) {
_treeview.setItemText(loader.loaditem, 0, String.format("%d个", count));
} else {
_treeview.setItemText(loader.loaditem, 0, "无");
}
expand_data.remove(item);
loadObject(item, nilptr, loader.object, 0, loader.isStatic);
}
}
public static void postNotify(int id)
{
wndClass.Notify(id);
}
public void clear()
{
_treeview.clear();
expand_data.clear();
position_info.clear();
sources = nilptr;
}
public void onNotification(long eventid)
{
if (workspace.getCurrentProject() != nilptr) {
Project pj = workspace.getCurrentProject();
if (pj != nilptr){
loadProject(pj);
}
}
}
/*static void load(Project project){
wndClass.loadProject(project);
}*/
public long [][] loadLibs(@NotNilptr Project project, Configure configure)
{
long [] hlibs;
long [] hlinks;
if (configure != nilptr) {
long libroot = 0;
JsonArray libs = project.getExternLibs(configure);
if (libs != nilptr) {
hlibs = new long[libs.length()];
if (libs.length() > 0) {
libroot = _treeview.addItem("res/toolbar/extern.png", "外部库");
}
for (int i = 0, c = libs.length(); i < c; i++) {
String var = libs.getString(i);
if (var != nilptr) {
hlibs[i] = _treeview.insertItem(libroot, "res/toolbar/library.png", var.findFilenameAndExtension());
}
}
}
JsonArray links = (JsonArray)configure.root.get("links");
if (links != nilptr) {
hlinks = new long[links.length()];
if (links.length() > 0 && libroot == 0) {
libroot = _treeview.addItem("res/toolbar/extern.png", "外部库");
}
for (int i = 0, c = links.length(); i < c; i++) {
String var = links.getString(i);
if (var != nilptr) {
hlinks[i] = _treeview.insertItem(libroot, "res/toolbar/library.png", var.findFilenameAndExtension());
}
}
}
}
long [][] hret = {hlibs, hlinks};
return hret;
}
public void search(Project project, String key)
{
if (project != nilptr) {
JsonObject json = project.xintelliSenseMap;
bool showBuildin = Setting.isShowBuildin();
if (json != nilptr) {
JsonArray template_class = (JsonArray)json.get("template_class");
JsonArray template_instance = (JsonArray)json.get("template_instance");
JsonArray heap = (JsonArray)json.get("heap");
if (template_class != nilptr)
searchObject(template_class, key, showBuildin);
if (template_instance != nilptr)
searchObject(template_instance, key, showBuildin);
if (heap != nilptr)
searchObject(heap, key, showBuildin);
}
}
}
public int searchObject(JsonArray objs, String key, bool showBuildin)
{
int hasVisible = 0;
if (objs == nilptr ) {
return 0;
}
for (int i =0, c = objs.length(); i < c; i++) {
JsonObject obj = (JsonObject)objs.get(i);
if (obj == nilptr){
continue;
}
int type = obj.getInt("type");
String objname = obj.getString("name");
if (objname != nilptr){
objname = objname.upper();
}
if (obj.has("buildin")) {
if (showBuildin == false) {
continue;
}
}
int bVisible = 0;
obj.remove("mathced");
try{
if (Pattern.test(objname, key, 0, false)) {
bVisible ++;
}
if (type == 31) {
bVisible += searchObject((JsonArray)obj.get("properites"), key, showBuildin);
bVisible += searchObject((JsonArray)obj.get("static_properites"), key, showBuildin);
bVisible += searchObject((JsonArray)obj.get("method"), key, showBuildin);
bVisible += searchObject((JsonArray)obj.get("static_method"), key, showBuildin);
} else if (type == 23) {
JsonArray param = (JsonArray)obj.get("params");
if (param != nilptr){
for (int x = 0, y = param.length(); x < y; x++) {
JsonObject jo = (JsonObject)param.get(x);
if (jo != nilptr){
String fname = jo.getString("name");
if (fname != nilptr){
fname = fname.upper();
}
jo.remove("mathced");
if (Pattern.test(fname, key, 0, false)) {
jo.put("mathced",1);
bVisible ++;
}
}
}
}
}
}catch(Exception e){
}
if (bVisible > 0) {
hasVisible++;
obj.put("mathced", 1);
}
}
return hasVisible;
}
public void loadProject(@NotNilptr Project project)
{
clear();
long root = _treeview.addItem("res/toolbar/project.png", project.getName());
long hbuildin = 0;
if (Setting.isShowBuildin()) {
hbuildin = _treeview.addItem("res/toolbar/sources.png", "内置对象");
}
long [][]libs = loadLibs(project, project.getCurrentConfig());
if (project.xintelliSenseMap != nilptr) {
sources = (JsonArray)project.xintelliSenseMap.get("sources");
JsonArray template_class = (JsonArray)project.xintelliSenseMap.get("template_class");
JsonArray template_instance = (JsonArray)project.xintelliSenseMap.get("template_instance");
JsonArray heap = (JsonArray)project.xintelliSenseMap.get("heap");
loadObject(root, libs, template_class, hbuildin, false);
loadObject(root, libs, template_instance, hbuildin, false);
loadObject(root, libs, heap, hbuildin, false);
_treeview.setExpand(root, true);
}
}
public long insertLoad(long item)
{
return _treeview.insertItem(item, nilptr, "加载中...");
}
public void loadObject(long hroot, long [][]libs, JsonArray objs, long hbuildin, bool isStatic)
{
if (objs == nilptr) {
return ;
}
bool searched = searchkey!= nilptr;
bool showBuildin = Setting.isShowBuildin();
for (int i =0, c = objs.length(); i < c; i++) {
long root = hroot;
JsonObject obj = (JsonObject)objs.get(i);
if (obj == nilptr){
continue;
}
if (searched && !obj.has("mathced")) {
continue;
}
if (obj.has("buildin")) {
if (showBuildin == false) {
continue;
} else {
if (hbuildin != 0) {
root = hbuildin;
}
}
}
int type = obj.getInt("type");
int visibility = obj.getInt("visibility");
bool blib = obj.has("lib");
if (blib && libs != nilptr && libs[0] != nilptr) {
int libid = obj.getInt("lib");
if (libid < libs[0].length) {
root = libs[0][libid];
} else {
continue;
}
}
bool blink = obj.has("link");
if (blink && libs != nilptr && libs[1] != nilptr) {
int linkid = obj.getInt("link");
if (linkid < libs[1].length) {
root = libs[1][linkid];
} else {
continue;
}
}
String prototype = obj.getString("prototype");
long item = 0;
if (type == 34) {
item = _treeview.insertItem(root, "res/toolbar/template.png", obj.getString("name"));
if (prototype != nilptr){
_treeview.insertItem(item, "res/toolbar/prototype.png", prototype);
}
} else if (type == 31) {
bool bpackage = false;
bool binterface = false;
if (obj.has("template")) {
item = _treeview.insertItem(root, "res/toolbar/tempinst.png", obj.getString("name"));
long temp = _treeview.insertItem(item, "res/toolbar/template.png", "模板");
_treeview.insertItem(temp, "res/toolbar/template.png", obj.getString("template"));
} else if (obj.has("interface")) {
item = _treeview.insertItem(root, "res/toolbar/interface.png", obj.getString("name"));
binterface = true;
} else if (obj.has("package")) {
item = _treeview.insertItem(root, "res/toolbar/package_icon.png", obj.getString("name"));
bpackage = true;
} else {
item = _treeview.insertItem(root, "res/toolbar/class.png", obj.getString("name"));
}
if (prototype != nilptr){
_treeview.insertItem(item, "res/toolbar/prototype.png", prototype);
}
if (obj.has("base")) {
long temp = _treeview.insertItem(item, "res/toolbar/class.png", "基类");
_treeview.insertItem(temp, "res/toolbar/class.png", obj.getString("base"));
}
if (bpackage){
long static_prop = _treeview.insertItem(item, "res/toolbar/static.png", "成员");
expand_data.put(static_prop,new ItemLoader(insertLoad(static_prop), (JsonArray)obj.get("static_properites"), false));
}else
if (binterface){
long method = _treeview.insertItem(item, "res/toolbar/function.png", "抽象方法");
long static_method = _treeview.insertItem(item, "res/toolbar/staticfunction.png", "静态接口方法");
expand_data.put(method, new ItemLoader(insertLoad(method), (JsonArray)obj.get("method"), false));
expand_data.put(static_method,new ItemLoader( insertLoad(static_method), (JsonArray)obj.get("static_method"), true));
}else{
JsonArray properites = (JsonArray)obj.get("properites");
if (properites != nilptr && properites.length() > 0){
long prop = _treeview.insertItem(item, "res/toolbar/member.png", "成员");
expand_data.put(prop,new ItemLoader(insertLoad(prop), properites, false));
}
JsonArray static_properites = (JsonArray)obj.get("static_properites");
if (static_properites != nilptr && static_properites.length() > 0){
long static_prop = _treeview.insertItem(item, "res/toolbar/static.png", "静态成员");
expand_data.put(static_prop,new ItemLoader(insertLoad(static_prop), static_properites, true));
}
JsonArray methods = (JsonArray)obj.get("method");
if (methods != nilptr && methods.length() > 0){
long method = _treeview.insertItem(item, "res/toolbar/function.png", "方法");
expand_data.put(method, new ItemLoader(insertLoad(method), methods, false));
}
JsonArray static_methods = (JsonArray)obj.get("static_method");
if (static_methods != nilptr && static_methods.length() > 0){
long static_method = _treeview.insertItem(item, "res/toolbar/staticfunction.png", "静态方法");
expand_data.put(static_method,new ItemLoader( insertLoad(static_method), static_methods, true));
}
}
/*loadObject(prop, (JsonArray)obj.get("properites"));
loadObject(static_prop, (JsonArray)obj.get("static_properites"));
loadObject(method, (JsonArray)obj.get("method"));
loadObject(static_method, (JsonArray)obj.get("static_method"));*/
} else if (type == 23) {
if (obj.has("interface")) {
item = _treeview.insertItem(root, "res/toolbar/interfacefun.png", obj.getString("name"));
} else {
if (isStatic){
if (visibility >= 0x40){
item = _treeview.insertItem(root, "res/toolbar/methodstatic.png", obj.getString("name"));
}else{
item = _treeview.insertItem(root, "res/toolbar/methodstaticprivate.png", obj.getString("name"));
}
}else
if (visibility >= 0x40){
item = _treeview.insertItem(root, "res/toolbar/method.png", obj.getString("name"));
}else{
item = _treeview.insertItem(root, "res/toolbar/methodprivate.png", obj.getString("name"));
}
if (prototype != nilptr){
_treeview.insertItem(item, "res/toolbar/prototype.png", prototype);
}
}
if (obj.has("typeobj")) {
long temp = _treeview.insertItem(item, "res/toolbar/class.png", "类型");
_treeview.insertItem(temp, nilptr, obj.getString("typeobj"));
}
long params = 0;
JsonArray param = (JsonArray)obj.get("params");
if (param != nilptr){
if (param.length() > 0){
params = _treeview.insertItem(item, "res/toolbar/params.png", "参数列表");
}
for (int x = 0, y = param.length(); x < y; x++) {
JsonObject jo = (JsonObject)param.get(x);
if (jo == nilptr){
continue;
}
if (searched && !jo.has("mathced")) {
continue;
}
long pitem = _treeview.insertItem(params, "res/toolbar/param.png", jo.getString("name"));
long temp = _treeview.insertItem(pitem, "res/toolbar/class.png", "类型");
_treeview.insertItem(temp, nilptr, jo.getString("type"));
}
}
} else if (type == 18) {
item = _treeview.insertItem(root, "res/toolbar/object.png", obj.getString("name"));
if (obj.has("typeobj")) {
long temp = _treeview.insertItem(item, "res/toolbar/class.png", "类型");
_treeview.insertItem(temp, nilptr, obj.getString("typeobj"));
}
}
if (item != 0) {
int sourceid = -1;
if (obj.has("source")) {
sourceid = obj.getInt("source");
}
position_info.put(item, new Position(sourceid, obj.getInt("line"), obj.getInt("column"), blib, obj));
}
}
}
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/ixlang/XStudio.git
git@gitee.com:ixlang/XStudio.git
ixlang
XStudio
XStudio
master

搜索帮助