1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License as published by 6 * the Free Software Foundation; either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * gtkD is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public License 15 * along with gtkD; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 17 */ 18 19 module sourceView.SVTest; 20 21 private import gio.Application : GioApplication = Application; 22 private import gtk.Application; 23 private import gtk.ApplicationWindow; 24 25 private import gtk.ScrolledWindow; 26 private import gtk.Widget; 27 28 private import glib.Str; 29 30 private import gsv.SourceView; 31 private import gsv.SourceBuffer; 32 private import gsv.SourceLanguage; 33 private import gsv.SourceLanguageManager; 34 private import gsv.SourceBuffer; 35 36 private import std.stdio; 37 private import std.file; 38 39 /** 40 * Demos for SourceView. 41 * TODO on gsv: override methods from TextView, TextBuffer, etc 42 */ 43 44 class HelloWorld : ApplicationWindow 45 { 46 47 SourceView sourceView; 48 49 this(Application application) 50 { 51 super(application); 52 setTitle("GtkD SourceView"); 53 setBorderWidth(10); 54 add(getSourceView()); 55 setDefaultSize(640,400); 56 showAll(); 57 } 58 59 private string getDemoText() 60 { 61 string text; 62 63 try 64 { 65 text = cast(string)std.file.read("SVTest.d"); 66 } 67 catch ( FileException fe ) { } 68 69 return text; 70 } 71 72 private Widget getSourceView() 73 { 74 sourceView = new SourceView(); 75 sourceView.setShowLineNumbers(true); 76 77 sourceView.setInsertSpacesInsteadOfTabs(false); 78 sourceView.setTabWidth(4); 79 sourceView.setHighlightCurrentLine(true); 80 81 SourceBuffer sb = sourceView.getBuffer(); 82 sb.setText(getDemoText()); 83 84 ScrolledWindow scWindow = new ScrolledWindow(); 85 scWindow.add(sourceView); 86 87 88 SourceLanguageManager slm = new SourceLanguageManager(); 89 SourceLanguage dLang = slm.getLanguage("d"); 90 91 if ( dLang !is null ) 92 { 93 writefln("Setting language to D"); 94 sb.setLanguage(dLang); 95 sb.setHighlightSyntax(true); 96 } 97 98 //sourceView.modifyFont("Courier", 9); 99 sourceView.setRightMarginPosition(72); 100 sourceView.setShowRightMargin(true); 101 sourceView.setAutoIndent(true); 102 103 104 return scWindow; 105 } 106 } 107 108 int main(string[] args) 109 { 110 auto application = new Application("org.gtkd.demo.sourceview", GApplicationFlags.FLAGS_NONE); 111 application.addOnActivate(delegate (GioApplication app) { new HelloWorld(application); }); 112 return application.run(args); 113 }