Beispiel #1
0
func init_lang() {
	lang_man := gtk.SourceLanguageManagerGetDefault()
	lang_map = make(map[string]*gtk.GtkSourceLanguage)
	lang_map["go"] = lang_man.GetLanguage("go")
	lang_map["c"] = lang_man.GetLanguage("c")
	lang_map["h"] = lang_man.GetLanguage("cpp")
	lang_map["sh"] = lang_man.GetLanguage("sh")
	lang_map["diff"] = lang_man.GetLanguage("diff")
	lang_map["patch"] = lang_man.GetLanguage("diff")
	lang_map["cpp"] = lang_man.GetLanguage("cpp")
	lang_map["hpp"] = lang_man.GetLanguage("cpp")
	lang_map["cc"] = lang_man.GetLanguage("cpp")
	lang_map["latex"] = lang_man.GetLanguage("latex")
	lang_map["tex"] = lang_man.GetLanguage("latex")
	lang_map["Makefile"] = lang_man.GetLanguage("makefile")
	lang_map["am"] = lang_man.GetLanguage("makefile")
	lang_map["in"] = lang_man.GetLanguage("makefile")
	lang_map["xml"] = lang_man.GetLanguage("xml")
	lang_map["py"] = lang_man.GetLanguage("python")
	lang_map["scons"] = lang_man.GetLanguage("python")
	lang_map["SConstruct"] = lang_man.GetLanguage("python")
	lang_map["java"] = lang_man.GetLanguage("java")

	lang_map["default"] = lang_man.GetLanguage("sh")

	source_buf.SetLanguage(lang_map["default"])
}
Beispiel #2
0
func main() {
	gtk.Init(&os.Args)
	window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
	window.SetTitle("SourceView")
	window.Connect("destroy", gtk.MainQuit)

	swin := gtk.ScrolledWindow(nil, nil)
	swin.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_AUTOMATIC)
	swin.SetShadowType(gtk.GTK_SHADOW_IN)
	sourcebuffer := gtk.SourceBufferWithLanguage(gtk.SourceLanguageManagerGetDefault().GetLanguage("cpp"))
	sourceview := gtk.SourceViewWithBuffer(sourcebuffer)

	var start gtk.GtkTextIter
	sourcebuffer.GetStartIter(&start)
	sourcebuffer.BeginNotUndoableAction()
	sourcebuffer.Insert(&start, `#include <iostream>
template<class T>
struct foo_base {
  T operator+(T const &rhs) const {
    T tmp(static_cast<T const &>(*this));
    tmp += rhs;
    return tmp;
  }
};

class foo : public foo_base<foo> {
private:
  int v;
public:
  foo(int v) : v(v) {}
  foo &operator+=(foo const &rhs){
    this->v += rhs.v;
    return *this;
  }
  operator int() { return v; }
};

int main(void) {
  foo a(1), b(2);
  a += b;
  std::cout << (int)a << std::endl;
}
`)
	sourcebuffer.EndNotUndoableAction()

	swin.Add(sourceview)

	window.Add(swin)
	window.SetSizeRequest(400, 300)
	window.ShowAll()

	gtk.Main()
}