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 
22 private import gtk.MainWindow;
23 private import gtk.Main;
24 private import gtk.ScrolledWindow;
25 private import gtk.Widget;
26 
27 private import glib.Str;
28 
29 private import gsv.SourceView;
30 private import gsv.SourceBuffer;
31 private import gsv.SourceLanguage;
32 private import gsv.SourceLanguageManager;
33 private import gsv.SourceBuffer;
34 
35 private import std.stdio;
36 private import std.file;
37 
38 /**
39  * Demos for SourceView.
40  * TODO on gsv: override methods from TextView, TextBuffer, etc
41  */
42 
43 class HelloWorld : MainWindow
44 {
45 
46 	SourceView sourceView;
47 	
48 	this()
49 	{
50 		super("GtkD SourceView");
51 		setBorderWidth(10);
52 		add(getSourceView());
53 		setDefaultSize(640,400);
54 		showAll();
55 	}
56 	
57 	private string getDemoText()
58 	{
59 		string text;
60 
61 		try
62 		{
63 			text = cast(string)std.file.read("SVTest.d");
64 		}
65 		catch ( FileException fe ) { }
66 		
67 		return text;
68 	}
69 	
70 	private Widget getSourceView()
71 	{
72 		sourceView = new SourceView();
73 		sourceView.setShowLineNumbers(true);
74 		
75 		sourceView.setInsertSpacesInsteadOfTabs(false);
76 		sourceView.setTabWidth(4);
77 		sourceView.setHighlightCurrentLine(true);
78 		
79 		SourceBuffer sb = sourceView.getBuffer();
80 		sb.setText(getDemoText());
81 		
82 		ScrolledWindow scWindow = new ScrolledWindow();
83 		scWindow.add(sourceView);
84 
85 		
86 		SourceLanguageManager slm = new SourceLanguageManager();
87 		SourceLanguage dLang = slm.getLanguage("d");
88 		
89 		if ( dLang !is null )
90 		{
91 			writefln("Setting language to D");
92 			sb.setLanguage(dLang);
93 			sb.setHighlightSyntax(true);
94 		}
95 		
96 		//sourceView.modifyFont("Courier", 9);
97 		sourceView.setRightMarginPosition(72);
98 		sourceView.setShowRightMargin(true);
99 		sourceView.setAutoIndent(true);
100 		
101 		
102 		return scWindow;
103 	}
104 }
105 
106 void main(string[] args)
107 {
108 	Main.init(args);
109 	new HelloWorld();
110 	Main.run();
111 }