This repository has been archived by the owner on May 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
editor.d
442 lines (343 loc) · 12.8 KB
/
editor.d
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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
module editor;
import std.stdio;
import std.file;
import std.conv;
import std.string;
import gtk.MainWindow, gtk.Main, gtk.Button, gtk.Label, gtk.VBox, gtk.HBox, gtk.Widget, gtk.ScrolledWindow, gtk.Notebook, gtk.Frame;
import gtk.Image, gtk.RcStyle, gtk.Box, gtk.ToolButton, gtk.MenuBar, gtk.Menu, gtk.MenuItem, gtk.FileChooserDialog, gtk.TextBuffer;
import gtk.AboutDialog, gtk.MessageDialog, gtk.TextIter, gtk.TextMark, gtk.FileFilter, gtk.Statusbar, gtk.TextView;
import gtk.SeparatorMenuItem, gtk.Action, gtk.AccelGroup;
import gsv.SourceView, gsv.SourceBuffer, gsv.SourceLanguage, gsv.SourceLanguageManager, gsv.SourceBuffer;
import gsv.SourceStyleSchemeManager, gsv.SourceStyleScheme, gsv.SourceGutter, gtk.CellRendererText;
import gdk.Keysyms;
import gtkc.gdktypes;
import sayfaBaslik;
enum statusBarId = 1;
version (Windows)
{
enum logoDosyaAdresi = "resim\\logo.png";
enum dilDosyaAdresi = "share\\gtksourceview-2.0\\language-specs";
enum stilDosyaAdresi = "share\\gtksourceview-2.0\\styles";
}
version (linux)
{
enum logoDosyaAdresi = "resim/logo.png";
enum dilDosyaAdresi = "share/gtksourceview-2.0/language-specs";
enum stilDosyaAdresi = "share/gtksourceview-2.0/styles";
}
class Editor : MainWindow
{
private Notebook defter;
private Statusbar durumCubugu;
public this()
{
super("Divid Metin Editörü (Geliştiriciler için) -- 0.5.3 (Begonya) [BETA]");
this.setIconFromFile(logoDosyaAdresi);
//this.setIcon(createPixbuf("resim\\logo.png"));
//this.resize(300, 300);
//this.move(20, 20);
EkraniHazirla();
setSizeRequest(640, 480);
showAll();
//setBorderWidth(10);
//setPosition(GtkWindowPosition.POS_CENTER_ALWAYS);
}
private void EkraniHazirla()
{
defter = new Notebook();
defter.addOnSwitchPage(&OnSekmeDegisti);
defter.setTabPos(PositionType.TOP);
//sekme.setBorderWidth(10);
durumCubugu = new Statusbar();
durumCubugu.push(statusBarId, "Divid Metin Editörü");
VBox vboxAnaTablo = new VBox(false, 0);
vboxAnaTablo.packStart(AnaMenuHazirla, false, false, 0);
vboxAnaTablo.packStart(defter, true, true, 0);
vboxAnaTablo.packStart(durumCubugu, false, false, 0);
add(vboxAnaTablo);
/*
Widget sayfa = MetinEditoruHazirla("editor.d");
defter.appendPage(sayfa, new SayfaBaslik("editor.d", defter, sayfa));
Widget sayfa1 = MetinEditoruHazirla("sekme.d");
defter.appendPage(sayfa1, new SayfaBaslik("sekme.d", defter, sayfa1));
Widget sayfa2 = MetinEditoruHazirla("sekme.d");
defter.appendPage(sayfa2, new SayfaBaslik("BaskaTest", defter, sayfa2));
*/
}
private bool keyPerssed(GdkEventKey* e, Widget w)
{
if (e.state & ModifierType.CONTROL_MASK && e.keyval == GdkKeysyms.GDK_s)
{
MenuDosyaKaydet();
return true;
}
return false;
/*
switch(event.keyval){
case(GdkKeysyms.GDK_Up): // up arrow
Stdout("up").nl;
break;
case(GdkKeysyms.GDK_Down): // down arrow
Stdout("down").nl;
break;
case(GdkKeysyms.GDK_Right): // right arrow
Stdout("right").nl;
break;
case(GdkKeysyms.GDK_Left): // left arrow
Stdout("left").nl;
break;
default:
Stdout("default").nl;
break;
}
return false;
*/
}
private Widget MetinEditoruHazirla(string dosyaAdi)
{
SourceView metinEditoru = new SourceView();
metinEditoru.addOnKeyPress(&keyPerssed);
metinEditoru.setShowLineNumbers(true);
metinEditoru.setInsertSpacesInsteadOfTabs(true);
metinEditoru.setTabWidth(4);
metinEditoru.setHighlightCurrentLine(true);
metinEditoru.modifyFont("Consolas", 10);
//metinEditoru.modifyFont("Monospace", 10);
metinEditoru.setLeftMargin(10);
metinEditoru.setSmartHomeEnd(GtkSourceSmartHomeEndType.ALWAYS);
SourceBuffer sb = metinEditoru.getBuffer();
sb.addOnChanged(&OnMetinDegisti);
sb.addOnMarkSet(&OnMarkSet);
if (dosyaAdi != "bos")
{
sb.setText(cast(string)std.file.read(dosyaAdi));
}
// Imleci satır başına taşı
TextIter iter = new TextIter();
sb.getStartIter(iter);
sb.placeCursor(iter);
ScrolledWindow scWindow = new ScrolledWindow();
scWindow.setPolicy(GtkPolicyType.AUTOMATIC, GtkPolicyType.AUTOMATIC);
scWindow.setShadowType(GtkShadowType.ETCHED_OUT);
scWindow.add(metinEditoru);
SourceLanguageManager slm = new SourceLanguageManager();
slm.setSearchPath([dilDosyaAdresi]);
SourceLanguage dLang = slm.getLanguage("d");
//writeln(slm.getSearchPath());
SourceStyleSchemeManager sssm = new SourceStyleSchemeManager();
string[] styleSearchPaths = [stilDosyaAdresi];
sssm.setSearchPath(styleSearchPaths);
SourceStyleScheme sema = sssm.getScheme("classic");
sb.setStyleScheme(sema);
//writeln("test");
//SourceGutter gutter = metinEditoru.getGutter(GtkTextWindowType.LEFT);
//SourceGutter gutter = metinEditoru.getGutter(GtkTextWindowType.LEFT);
//CellRendererText render = new CellRendererText();
//gutter.insert(render, 20);
if (dLang !is null)
{
writefln("Setting language to D");
sb.setLanguage(dLang);
sb.setHighlightSyntax(true);
}
//sourceView.modifyFont("Courier", 9);
//metinEditoru.setRightMarginPosition(72);
//metinEditoru.setShowRightMargin(true);
metinEditoru.setAutoIndent(true);
return scWindow;
}
private MenuBar AnaMenuHazirla()
{
MenuBar menuBar = new MenuBar();
AccelGroup accelGroup = new AccelGroup();
/*
Action action = new Action("dosya.ac", "_Aç", "tooltip", StockID.OPEN); //Should accept an StockID.
action.addOnActivate(&OnMenuKomutuCalistir);
action.setAccelGroup(accelGroup);
MenuItem menuItem = action.createMenuItem;
menuItem.addAccelerator("activate", accelGroup, 'o', GdkModifierType.CONTROL_MASK, GtkAccelFlags.VISIBLE);
*/
Menu menu = menuBar.append("_Dosya");;
menu.append(new MenuItem(&OnMenuKomutuCalistir, "Yeni", "dosya.yeni", true, accelGroup, 'N'));
menu.append(new MenuItem(&OnMenuKomutuCalistir, "Aç", "dosya.ac"));
menu.append(new MenuItem(&OnMenuKomutuCalistir, "Kaydet", "dosya.kaydet", true, accelGroup, 'S'));
menu.append(new MenuItem(&OnMenuKomutuCalistir, "Farklı Kaydet", "dosya.farkliKaydet"));
menu.append(new SeparatorMenuItem());
menu.append(new MenuItem(&OnMenuKomutuCalistir, "Çıkış", "dosya.cikis"));
menu = menuBar.append("_Düzen");
menu.append(new MenuItem(&OnMenuKomutuCalistir,"_Find","edit.find"));
menu.append(new MenuItem(&OnMenuKomutuCalistir,"_Search","edit.search"));
menu = menuBar.append("_Yardım");
menu.append(new MenuItem(&OnMenuKomutuCalistir,"Yardım","yardim.yardim"));
menu.append(new MenuItem(&OnMenuKomutuCalistir,"Divid Hakkında","yardim.hakkinda"));
return menuBar;
}
/*======================================================= MENU KOMUT METOTLARI BASI =============================*/
private void MenuDosyaYeni()
{
Widget sayfa = MetinEditoruHazirla("bos");
int gecerliSekmeNo = defter.appendPage(sayfa, new SayfaBaslik("Adsız", defter, sayfa));
defter.showAll();
defter.setCurrentPage(gecerliSekmeNo);
// İmleci editöre konumla
ScrolledWindow text = cast(ScrolledWindow)sayfa;
TextView editor = cast(TextView)text.getChild();
editor.grabFocus();
}
private void MenuDosyaAc()
{
string[] a = ["Aç", "İptal"];
ResponseType[] r = [ResponseType.GTK_RESPONSE_OK, ResponseType.GTK_RESPONSE_CANCEL];
FileChooserDialog fcd = new FileChooserDialog("Dosya Seç", this, FileChooserAction.OPEN, a, r);
FileFilter filtreTum = new FileFilter();
filtreTum.setName("Tüm Dosyalar (*.*)");
filtreTum.addPattern("*.*");
FileFilter filtreD = new FileFilter();
filtreD.setName("D (*.d, *.di)");
filtreD.addPattern("*.d");
filtreD.addPattern("*.di");
filtreD.addPattern("*.txt");
fcd.addFilter(filtreTum);
fcd.addFilter(filtreD);
fcd.move(50, 50);
if (fcd.run() == ResponseType.GTK_RESPONSE_OK)
{
string dosyaAdresi = fcd.getFilename();
Widget sayfa = MetinEditoruHazirla(dosyaAdresi);
int gecerliSekmeNo = defter.appendPage(sayfa, new SayfaBaslik(dosyaAdresi, defter, sayfa));
defter.showAll();
defter.setCurrentPage(gecerliSekmeNo);
// İmleci editöre konumla
ScrolledWindow text = cast(ScrolledWindow)sayfa;
TextView editor = cast(TextView)text.getChild();
editor.grabFocus();
}
fcd.hide();
}
private void MenuDosyaKaydet()
{
int sayfaNo = defter.getCurrentPage();
Widget sayfa = defter.getNthPage(sayfaNo);
SayfaBaslik baslik = cast(SayfaBaslik)defter.getTabLabel(sayfa);
ScrolledWindow disPencere = cast(ScrolledWindow)defter.getNthPage(sayfaNo);
SourceView editor = cast(SourceView)disPencere.getChild();
if (baslik.VerDosyaAdi != "Adsız")
{
File dosya = File(baslik.VerDosyaAdresi, "wb");
dosya.write(editor.getBuffer().getText());
durumCubugu.push(0, " Kaydedildi..." ~ baslik.VerDosyaAdresi);
}
else
{
MenuDosyaFarkliKaydet();
}
}
private void MenuDosyaFarkliKaydet()
{
string[] a = ["Kaydet", "İptal"];
ResponseType[] r = [ResponseType.GTK_RESPONSE_OK, ResponseType.GTK_RESPONSE_CANCEL];
FileChooserDialog fcd = new FileChooserDialog("Dosya Seç", this, FileChooserAction.SAVE, a, r);
if (fcd.run() == ResponseType.GTK_RESPONSE_OK)
{
int sayfaNo = defter.getCurrentPage();
Widget sayfa = defter.getNthPage(sayfaNo);
SayfaBaslik baslik = cast(SayfaBaslik)defter.getTabLabel(sayfa);
ScrolledWindow disPencere = cast(ScrolledWindow)defter.getNthPage(sayfaNo);
SourceView editor = cast(SourceView)disPencere.getChild();
File dosya = File(fcd.getFilename(), "wb");
dosya.write(editor.getBuffer().getText());
baslik.YapDosyaAdresi(fcd.getFilename());
}
fcd.hide();
}
private void MenuYardimHakkinda()
{
string mesaj = "Divid Metin Editörü\n\n"
"D dilinde gtkD kütüphanesi kullanarak geliştirilmektedir.\n"
"Daha fazla bilgi için lütfen http://www.ddili.org adresini ziyaret edin.\n\n"
"Zafer Çelenk (http://www.zafercelenk.net)\n";
MessageDialog d = new MessageDialog(this, GtkDialogFlags.MODAL, MessageType.INFO, ButtonsType.OK, mesaj);
d.run();
d.destroy();
}
private void MenuDosyaCikis()
{
Main.quit;
}
/*======================================================= MENU KOMUT METOTLARI SONU =============================*/
/*======================================================= OLAY METODLARI BASI =============================*/
void OnMenuKomutuCalistir(MenuItem menuItem)
{
string action = menuItem.getActionName();
switch( action )
{
case "dosya.yeni":
MenuDosyaYeni();
break;
case "dosya.ac":
MenuDosyaAc();
break;
case "dosya.kaydet":
MenuDosyaKaydet();
break;
case "dosya.farkliKaydet":
MenuDosyaFarkliKaydet();
break;
case "dosya.cikis":
MenuDosyaCikis();
break;
case "yardim.hakkinda":
MenuYardimHakkinda();
break;
default:
MessageDialog d = new MessageDialog(
this,
GtkDialogFlags.MODAL,
MessageType.INFO,
ButtonsType.OK,
"You pressed menu item "~action);
d.run();
d.destroy();
break;
}
}
void OnSekmeDegisti(void *sekme, uint sekmeNo, Notebook defter)
{
int sayfaNo = defter.getCurrentPage();
ScrolledWindow text = cast(ScrolledWindow)defter.getNthPage(sayfaNo);
SourceView kaynak = cast(SourceView)text.getChild();
SourceBuffer sb = kaynak.getBuffer();
//writefln("Notebook switch to page %s, %s", sekmeNo, sb.getModified());
// fullCollect helps finding objects that shouldn't have been collected\r
//std.gc.fullCollect();
//MessageDialog d = new MessageDialog(this, GtkDialogFlags.MODAL, MessageType.INFO, ButtonsType.OK, "You pressed menu item ");
//d.run();
//d.destroy();
}
void onWitgetActivate(Widget widget)
{
//
}
void OnMetinDegisti(TextBuffer textBuffer)
{
/*
TextIter iter = new TextIter();
textBuffer.getIterAtMark(iter, textBuffer.getInsert());
int lineNumber = iter.getLine();
TextIter iter = new TextIter();
textBuffer.getIterAtMark(iter, textBuffer.getInsert());
writefln("-> Satir : %s, Sutun : %s", iter.getLine(), iter.getLineIndex());
*/
}
void OnMarkSet(TextIter iter, TextMark mark, TextBuffer textBuffer)
{
if (mark.getVisible())
{
int row = iter.getLine();
int col = iter.getLineOffset();
string konumBilgi = format("Satir %s, Sütun %s", row + 1, col + 1);
durumCubugu.push(statusBarId, konumBilgi);
}
}
/*======================================================= OLAY METODLARI SONU =============================*/
}