-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathXVersionEditor.x
164 lines (145 loc) · 5.98 KB
/
XVersionEditor.x
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
//xlang Source, Name:XVersionEditor.x
//Date: Mon Oct 23:43:51 2020
class XVersionEditor : DocumentView{
QTableWidget _container;
XWorkspace _workspace;
JsonObject versionObj = nilptr;
bool updating = false;
static String [] HVComulns = {" 公司名称 ", " 版权描述 ", " 产品版本 "," 产品名称 ", " 文件名称 ", " 文件版本 ", " 文件描述 "};
static String [] HHComulns = {"值"};
//QTableWidget versionTable;
public XVersionEditor(XWorkspace _w){
_workspace = _w;
}
public bool create(@NotNilptr QWidget parent) {
if (super.create(parent)) {
_container = new QTableWidget();
_container.create();
setWidget(_container);
/*versionTable = new QTableWidget();
versionTable.create(_container);
_container.setOnLayoutEventListener(new onLayoutEventListener(){
void onResize(QObject obj,int w,int h,int oldw,int oldh)override{
versionTable.resize(w,h);
}
});*/
_container.setColumnCount(1);
_container.setRowCount(7);
_container.setVHColumns(HVComulns);
_container.setHHColumns(HHComulns);
_container.setOnTableWidgetEventListener(new TableWidgetEventListener(){
public void onCellChange(QTableWidget object, int row,int column) {
if (updating){
return;
}
String [] keys = {"CompanyName", "LegalCopyright", "ProductVersion", "ProductName", "InternalName", "FileVersion", "FileDescription" };
if (versionObj != nilptr && row >= 0 && row < keys.length){
while (versionObj.has(keys[row])){
versionObj.remove(keys[row]);
}
String text = object.getText(row,column);
versionObj.put(keys[row],text);
setModified(true);
}
}
});
_container.show();
return true;
}
return false;
}
public bool loadFile(@NotNilptr String file, String asCharset){
String content = XFinder.readFileContent(file);
try{
versionObj = new JsonObject(content);
loadVersion();
setFilePath(file);
}catch(Exception e){
QMessageBox.Critical("注意","无效的版本文件",QMessageBox.Ok,QMessageBox.Ok);
}
return true;
}
void setToTable(String key, int row){
String val = nilptr;
if (versionObj != nilptr){
val = versionObj.getString(key);
if (val == nilptr){
val = "";
}
}
_container.setItem(row,0, nilptr, val);
}
void loadVersion(){
updating = true;
String [] keys = {"CompanyName", "LegalCopyright", "ProductVersion", "ProductName", "InternalName", "FileVersion", "FileDescription" };
for (int i =0; i < keys.length; i++){
setToTable(keys[i], i);
}
updating = false;
}
public void saveFileAs() {
String file = QFileDialog.getSaveFileName("保存文件", getFilePath(), getDocumentExtension(), this);
if (file != nilptr && file.length() > 0) {
saveAs(file);
}
}
public bool saveAs(@NotNilptr String path) {
pauseWatch();
try {
FileOutputStream fis = new FileOutputStream(path);
try {
String content = "";
if (versionObj != nilptr){
content = versionObj.toString(false);
}
byte [] data = content.getBytes();
fis.write(data);
fis.close();//必须close 不然GC 关闭文件的时候在watch之后 , watch 会报告被更改
setFilePath(String.formatPath(path,false).replace("\\","/"));
setModified(false);
continueWatch();
return true;
} catch(Exception e) {
}
} catch(Exception e) {
Critical("注意", "文件无法在此位置保存,或者此文件正被其他程序使用,请重新选择路径", QMessageBox.Ok, QMessageBox.Ok);
}
continueWatch();
return false;
}
public bool saveFile() {
String savepath = getFilePath();
bool saved = false;
while (saved == false) {
if (savepath != nilptr && savepath.startsWith("#")) {
while (saved == false) {
String file = QFileDialog.getSaveFileName("保存文件", savepath, "Version Files(*.version)", this);
if (file != nilptr && file.length() > 0) {
saved = saveAs(file);
} else {
return false;
}
}
} else
if (savepath != nilptr){
pauseWatch();
try {
String content = "";
if (versionObj != nilptr){
content = versionObj.toString(false);
}
byte [] data = content.getBytes();
FileOutputStream fis = new FileOutputStream(savepath);
fis.write(data);
fis.close();//必须close 不然GC 关闭文件的时候在watch之后 , watch 会报告被更改
setModified(false);
saved = true;
} catch(Exception e) {
Critical("注意", "文件无法在此位置保存,或者此文件正被其他程序使用,请重新选择路径", QMessageBox.Ok, QMessageBox.Ok);
}
continueWatch();
}
}
return saved;
}
};