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 _extendRightScrollBound = true; 31 fontFace = DEFAULT_SOURCE_EDIT_FONT_FACES; 32 //fontFace = "Consolas,Lucida Console,Courier New"; 33 fontFamily = FontFamily.MonoSpace; 34 fontSize = makePointSize(10); 35 layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT); 36 minFontSize(9).maxFontSize(75); // allow font zoom with Ctrl + MouseWheel 37 showModificationMarks = true; 38 39 _showLineNumbers = true; 40 41 } 42 this() { 43 this("SRCEDIT"); 44 } 45 protected string _filename; 46 @property string filename() { 47 return _filename; 48 } 49 /// load from file 50 bool load(string fn) { 51 if (content.load(fn)) { 52 _filename = fn; 53 requestLayout(); 54 return true; 55 } 56 // failed 57 _filename = null; 58 return false; 59 } 60 61 bool save(string fn) { 62 if (content.save(fn)) { 63 _filename = fn; 64 requestLayout(); 65 window.update(); 66 return true; 67 } 68 // failed 69 requestLayout(); 70 window.update(); 71 _filename = null; 72 return false; 73 } 74 75 }