-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDocumentView.x
More file actions
409 lines (344 loc) · 11.9 KB
/
Copy pathDocumentView.x
File metadata and controls
409 lines (344 loc) · 11.9 KB
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
//xlang Source, Name:DocumentView.x
//Date: Sat Oct 13:32:50 2020
class DocumentView : QMdiSubWindow{
private String szTitle = "未标题";
private String filePath = "#" + Math.random() + "" + _system_.currentTimeMillis();
public static Map<String, DocumentView> editorMgr = new Map<String, DocumentView>();
static Map<String, String> charsetCache = new Map<String, String>();
bool bModified = false;
XWorkspace __mdiarea = nilptr;
private void setMdiArea(XWorkspace qm){
__mdiarea = qm;
}
public static DocumentView findFileWindow(@NotNilptr String file) {
try {
file = String.formatPath(file, _system_.getPlatformId() == _system_.PLATFORM_WINDOWS);
return editorMgr.get(file);
} catch(Exception e) {
}
return nilptr;
}
public static String getDocumentExtension(){
String filter = nilptr;
ProjectPropInterface prop = XWorkspace.workspace.getCurrentProjectProp();
if (prop != nilptr){
filter = prop.getFileExtensionFilter();
}
if (filter != nilptr){
filter = filter.trim(true);
}
if (filter == nilptr){
filter = "";
}else
if (filter.length() > 0){
if (filter.endsWith(";;") == false){
filter = filter + ";;";
}
}
return filter + "All Files(*.* *)";
}
public static void addToCharset(String file, String asCharset){
if (file != nilptr){
charsetCache.put(String.formatPath(file,false),asCharset);
}
}
public static DocumentView findDocumentWindow(XWorkspace parent,@NotNilptr String source, bool open) {
DocumentView wnd = nilptr;
source = source.replace("\\", "/");
Project project = XWorkspace.workspace.getCurrentProject();
if (XPlatform.existsSystemFile(source) == false){
if (project != nilptr){
source = String.formatPath(project.getProjectDir().appendPath(source), false);
if (XPlatform.existsSystemFile(source) == false){
return nilptr;
}
}else{
return nilptr;
}
}
wnd = findFileWindow(source);
if (wnd == nilptr){
if (open && parent != nilptr) {
if (XPlatform.existsSystemFile(source)){
wnd = DocumentView.createView(parent, source);
if (wnd.create(parent)) {
if (wnd.loadFile(source, nilptr)) {
wnd.show();
} else {
wnd.close();
wnd = nilptr;
}
}
}else{
wnd = nilptr;
}
}
}
return wnd;
}
public static bool closeForFile(@NotNilptr String source) {
DocumentView wnd = findDocumentWindow(nilptr, source, false);
if (wnd != nilptr) {
wnd.close();
return true;
}
return false;
}
public static void toggleBreakPointOnFile(XWorkspace parent,@NotNilptr String source,int line, bool set) {
DocumentView wnd = findDocumentWindow(parent, source, true);
if (wnd != nilptr) {
wnd.toggleBreakPoint(line, set);
}
}
public void insertNewLine(){}
public void appendNewLine(){}
public void convertCharset() {}
public void UpdateCodepage(){}
public void Copy(){}
public void Paste(){}
public void Cut(){}
public void Delete(){}
public void DeleteCurLine(){}
public void UnDo() {}
public void ReDo() {}
public void toggleBreakpoint() {}
public void gotoCursordef() {}
public void findAgain() {}
public void saveFileAs(){}
public String getSelectedText(){return "";}
public String getText(int ,int ){return "";}
public int getSelectStart(){return -1;}
public int getSelectEnd(){return -1;}
public void matchBrace(){}
public void overrideObject() {}
public void setUpper(){}
public void setLower(){}
public void setIntellisense(XIntelliSense.XIntelliResult [] names) {}
public void showHoverInformation(String texts, int pos) {}
public void setFileSymbols(XIntelliSense.XIntelliResult [] names) {}
public void CursorUp() {}
public void CursorLeft() {}
public void CursorRight() {}
public void CursorDown() {}
public void CursorLineBegin() {}
public void CursorLineEnd() {}
public void CursorPrevPage() {}
public void CursorNextPage() {}
public int getContentLength (){return 0;}
public void CursortoTop() {}
public void CursortoBottom() {}
public void clearFoundMark(){}
public void markFound(int pos, int length){}
public void clearSelectedMark(){}
public void markSelected(int pos, int length){}
public QPoint getSelectMarkRange(){return nilptr;}
public void doPrint(){}
public static String getCharsetCache(String file){
if (file != nilptr){
try{
return charsetCache.get(String.formatPath(file,false));
}catch(Exception e){
}
}
return nilptr;
}
public static bool findSaveFile(@NotNilptr String file) {
DocumentView wnd = findDocumentWindow(nilptr, file, false);
if (wnd != nilptr) {
wnd.resetInformationPoint();
if (wnd.isModified()) {
return wnd.saveFile();
}
return false;
}
return false;
}
public void resetInformationPoint(){
}
public String getFilePath(){
return filePath;
}
public String getTitle() {
return szTitle;
}
public void setModified(bool bM){
if (bModified != bM){
bModified = bM;
updateTitle();
}
}
public bool isModified(){
return bModified;
}
public void setModified(){
if (bModified == false){
bModified = true;
updateTitle();
}
}
public void updateTitle() {
if (filePath.startsWith("#") == false) {
szTitle = filePath.findFilenameAndExtension();
}
if (bModified) {
setWindowTitle(szTitle + " *");
} else {
setWindowTitle(szTitle);
}
}
public void setFilePath(@NotNilptr String file) {
if (filePath != nilptr){
removeFromMap(getFilePath());
}
filePath = String.formatPath(file,false).replace("\\","/");
szTitle = filePath.findFilenameAndExtension();
addToMap(filePath);
updateTitle();
}
public void removeFromMap(@NotNilptr String file) {
file = String.formatPath(file, _system_.getPlatformId() == _system_.PLATFORM_WINDOWS);
if (file.startsWith("#") == false) {
__mdiarea.qfsw.removePath(file);
}
editorMgr.remove(file);
}
public void addToMap(@NotNilptr String file) {
file = String.formatPath(file, _system_.getPlatformId() == _system_.PLATFORM_WINDOWS);
if (file.startsWith("#") == false) {
__mdiarea.qfsw.addPath(file);
}
editorMgr.put(filePath, this);
}
public void pauseWatch() {
__mdiarea.qfsw.removePath(filePath);
}
public void continueWatch() {
__mdiarea.qfsw.addPath(filePath);
}
public static void notifyFileChange(XWorkspace workspace, @NotNilptr String path, bool autoLoad) {
DocumentView editor = findDocumentWindow(nilptr, path, false);
if (editor != nilptr) {
workspace.setActiveSubWindow(editor);
editor.notifyFileChange(autoLoad);
}
}
public static bool notifyDiagnosis(String file){
DocumentView wnd = findDocumentWindow(nilptr, file, true);
if (wnd != nilptr) {
wnd.updateInformationPoint();
return true;
}
return false;
}
public static bool locateForPosition(@NotNilptr XWorkspace parent,@NotNilptr String source,int position, int len) {
DocumentView wnd = findDocumentWindow(parent, source, true);
if (wnd != nilptr) {
parent.setActiveSubWindow(wnd);
wnd.setSelection(position, len);
return true;
}
return false;
}
public static bool locateForLineRow(@NotNilptr XWorkspace parent,@NotNilptr String source,int line, int column, int len) {
DocumentView wnd = findDocumentWindow(parent, source, true);
if (wnd != nilptr) {
parent.setActiveSubWindow(wnd);
wnd.gotoAndSelect(line,column);
return true;
}
return false;
}
public void notifyFileChange(bool autoLoad) {
if (Setting.getBoolean("changeautoload")){
reload();
}else
if (autoLoad == true || QMessageBox.Yes == QMessageBox.Question("注意", "检测到文件:" + getFilePath() + "已被外部程序改变,是否重新加载?", QMessageBox.Yes, QMessageBox.No)) {
reload();
}
}
public bool create(@NotNilptr QWidget parent) {
if (super.create(parent)) {
addToMap(getFilePath());
return true;
}
return false;
}
public void onDestroy()override {
__mdiarea.updateDocumentStatus();
}
public void reload(){}
public bool requestClose(){
return true;
}
public static void updateDocumentTo(@NotNilptr String path,String newname) {
DocumentView wnd = findDocumentWindow(nilptr, path, false);
if (wnd != nilptr) {
wnd.removeFromMap(path);
wnd.setFilePath(newname);
wnd.addToMap(newname);
}
}
private bool onClose()override {
if (onCloseDocument()){
removeFromMap(getFilePath());
__mdiarea.updateDocumentStatus();
return true;
}
return false;
}
public bool onCloseDocument(){
return true;
}
public String contentToString(){return nilptr;}
public @NotNilptr static DocumentView createView(XWorkspace parent, @NotNilptr String file){
String ext = "";
if (file != nilptr ){
ext = file.findExtension();
}
DocumentView dv = nilptr;
if (ext.equalsIgnoreCase(".version")){
try{
dv = new XVersionEditor(parent);
}catch(Exception e){
}
}
if (ext.equalsIgnoreCase(".xts")){
try{
dv = new XStringMapView(parent);
}catch(Exception e){
}
}
if (dv == nilptr){
dv = new XSourceEditor(parent);
}
dv.setMdiArea(parent);
return dv;
}
public bool loadFile(@NotNilptr String file, String asCharset){
return false;
}
public void goto(int pos) {
}
public void goto(int line, int column) {
}
public void showTips(int line, int column, String title, String content) {
}
public void showTips(int position, String title, String content){
}
public void setSelection(int pos, int len) {
}
public void updateInformationPoint(){
}
public void gotoAndSelect(int line, int column) {
}
public bool saveFile() {
return false;
}
public void toggleBreakPoint(int line, bool set) {
}
public void updateConfig() {
}
public void clearBreakOn() {}
public void breakOn(int line, int column, bool set, bool active, bool onlyActive) {}
public void replaceText(int start, int len,@NotNilptr String text) {}
};