-
Notifications
You must be signed in to change notification settings - Fork 0
/
goatee.go
168 lines (142 loc) · 3.11 KB
/
goatee.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package main
import (
"fmt"
"math"
"net/url"
"os"
"os/user"
"strings"
"github.com/mattn/go-gtk/gdk"
"github.com/mattn/go-gtk/gio"
"github.com/mattn/go-gtk/gtk"
gsv "github.com/mattn/go-gtk/gtksourceview"
)
var (
ui *UI
conf *Conf
gvfsPath = "/run/user/%s/gvfs/"
newtabiter int
langManager = gsv.SourceLanguageManagerGetDefault()
languages = langManager.GetLanguageIds()
charsets = []string{
CHARSET_UTF8,
"utf-16",
"",
"ISO-8859-2",
"ISO-8859-7",
"ISO-8859-9",
"ISO-8859-15",
"ShiftJIS",
"EUC-KR",
"gb18030",
"Big5",
"TIS-620",
"KOI8-R",
"",
"windows-874",
"windows-1250",
"windows-1251",
"windows-1252",
"windows-1253",
"windows-1254",
"windows-1255",
"windows-1256",
"windows-1257",
"windows-1258",
"",
CHARSET_BINARY}
)
func init() {
// log.SetFlags(log.Lshortfile)
user, _ := user.Current()
gvfsPath = fmt.Sprintf(gvfsPath, user.Uid)
conf = NewConf()
}
func main() {
gtk.Init(nil)
ui = CreateUI()
switch {
case len(os.Args) == 1:
ui.NewTab("")
case os.Args[1] == "--help" || os.Args[1] == "-h":
fmt.Println("Usage:\n\tgoatee [files...]")
os.Exit(0)
default:
for i := 1; i < len(os.Args); i++ {
ui.NewTab(os.Args[i])
}
}
gtk.Main()
}
func issetLanguage(lang string) bool {
for _, langID := range languages {
if langID == lang {
return true
}
}
return false
}
func xmlLanguages() string {
//construct sections
structure := structureLanguages()
var xmldata []string
for section, langs := range structure {
xmldata = append(xmldata, "<menu action='"+section+"'>")
for _, l := range langs {
xmldata = append(xmldata, "<menuitem action='"+l.name+"' />")
}
xmldata = append(xmldata, "</menu>")
}
return strings.Join(xmldata, "\n")
}
type language struct {
n int
name string
}
func structureLanguages() map[string][]language {
var structure = make(map[string][]language)
for n, langname := range languages {
lang := langManager.GetLanguage(langname)
section := lang.GetSection()
if _, ok := structure[section]; !ok {
structure[section] = []language{}
}
structure[section] = append(structure[section], language{n, langname})
}
return structure
}
func xmlEncodings() string {
var xmldata []string
for _, c := range charsets {
if len(c) == 0 {
xmldata = append(xmldata, "<separator />")
} else {
xmldata = append(xmldata, "<menuitem action='"+c+"' />")
}
}
return strings.Join(xmldata, "\n")
}
func errorMessage(err error) {
m := gtk.NewMessageDialogWithMarkup(nil, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, err.Error())
m.Run()
m.Destroy()
}
func convertColor(col []int) *gdk.Color {
r := uint16(math.Pow(float64(col[0]), 2))
g := uint16(math.Pow(float64(col[1]), 2))
b := uint16(math.Pow(float64(col[2]), 2))
return gdk.NewColorRGB(r, g, b)
}
func resolveFilename(filename string) string {
u, err := url.Parse(filename)
if err != nil {
return filename
}
//if scheme exist, ex: 'sftp://' then parse path with how URI
if u.Scheme != "" {
filename = gio.NewGFileForURI(filename).GetPath()
} else {
filename = gio.NewGFileForPath(filename).GetPath()
}
return filename
}