1 // Written in the D programming language.
2 
3 /**
4 This module contains implementation of source code editor widget.
5 
6 SourceEdit - base class for source code editors, with line numbering, syntax highlight, etc.
7 
8 Synopsis:
9 
10 ----
11 import dlangui.widgets.srcedit;
12 
13 ----
14 
15 Copyright: Vadim Lopatin, 2014
16 License:   Boost License 1.0
17 Authors:   Vadim Lopatin, coolreader.org@gmail.com
18 */
19 module dlangui.widgets.srcedit;
20 
21 import dlangui.graphics.fonts;
22 import dlangui.widgets.editors;
23 import dlangui.widgets.styles;
24 
25 enum DEFAULT_SOURCE_EDIT_FONT_FACES = "Menlo,Consolas,DejaVuSansMono,DejaVu Sans Mono,Liberation Mono,Lucida Sans Typewriter,Courier New,Lucida Console";
26 
27 class SourceEdit : EditBox {
28     this(string ID) {
29         super(ID);
30         fontFace = DEFAULT_SOURCE_EDIT_FONT_FACES;
31         //fontFace = "Consolas,Lucida Console,Courier New";
32         fontFamily = FontFamily.MonoSpace;
33         fontSize = makePointSize(10);
34         layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
35         minFontSize(9).maxFontSize(75); // allow font zoom with Ctrl + MouseWheel
36         showModificationMarks = true;
37 
38         _showLineNumbers = true;
39 
40     }
41     this() {
42         this("SRCEDIT");
43     }
44     protected string _filename;
45     @property string filename() {
46         return _filename;
47     }
48     /// load from file
49     bool load(string fn) {
50         if (content.load(fn)) {
51             _filename = fn;
52             requestLayout();
53             return true;
54         }
55         // failed
56         _filename = null;
57         return false;
58     }
59 
60     bool save(string fn) {
61         if (content.save(fn)) {
62             _filename = fn;
63             requestLayout();
64             window.update();
65             return true;
66         }
67         // failed
68         requestLayout();
69         window.update();
70         _filename = null;
71         return false;
72     }
73 
74 }