// UpdateValues updates values within the settings view func UpdateValues() { jq("#network-nickname").SetVal("") jq("#network-highlights").SetVal("") jq("#channel-notifications").SetVal("all") font := js.Global.Get("document").Get("body").Get("style").Get("fontFamily") if font == nil || font.Length() == 0 { jq("#mauirc-font").SetVal("Raleway") } else { jq("#mauirc-font").SetVal(font.String()) } if !data.NetworkExists(GetActiveNetwork()) { return } net := data.MustGetNetwork(GetActiveNetwork()) jq("#network-nickname").SetVal(net.Nick) jq("#network-highlights").SetVal(net.Highlights.String()) if !net.ChannelExists(GetActiveChannel()) { return } ch := net.MustGetChannel(GetActiveChannel()) jq("#channel-notifications").SetVal(ch.Notifications.String()) }
// RenameScript renames a script func RenameScript() { selected := jq("#script-list > .selected-script") name := selected.Attr("data-name") net := jq("#script-list").Attr("data-network") if net == Global { data.GlobalScripts.Rename(net, name, jq("#script-name").Val(), OpenScriptEditor) } else { data.MustGetNetwork(net).Scripts.Rename(net, name, jq("#script-name").Val(), OpenScriptEditor) } }
// GetHighlight gets the first highlight match func GetHighlight(network, message string) *data.HighlightMatch { netData := data.MustGetNetwork(network) for _, hl := range netData.Highlights { match := hl.Match(message) if match != nil { return match } } return nil }
// SaveScript saves the open script func SaveScript() { selected := jq("#script-list > .selected-script") name := selected.Attr("data-name") net := jq("#script-list").Attr("data-network") if len(net) == 0 || len(name) == 0 { return } if net == Global { data.GlobalScripts.Put(net, name, scripteditor.GetValue(), nil) } else { data.MustGetNetwork(net).Scripts.Put(net, name, scripteditor.GetValue(), nil) } }
// SwitchScript switches the open script func SwitchScript(name string) { net := jq("#script-list").Attr("data-network") var script string if net == Global { script = data.GlobalScripts.Get(name) } else { script = data.MustGetNetwork(net).Scripts.Get(name) } jq("#script-list > .selected-script").RemoveClass("selected-script") jq(fmt.Sprintf("#chscript-%s", name)).AddClass("selected-script") scripteditor.SetValuePos(script, 1) jq("#script-name").SetVal(name) }
// Receive messages func Receive(msg messages.Message, isNew bool) { net := GetNetwork(msg.Network) if net.Length == 0 { if msg.Command == irc.PART && msg.Sender == data.MustGetNetwork(msg.Network).Nick { return } OpenNetwork(msg.Network) net = GetNetwork(msg.Network) } ch := GetChannel(msg.Network, msg.Channel) if ch.Length == 0 { if msg.Command == irc.PART && msg.Sender == data.MustGetNetwork(msg.Network).Nick { return } OpenChannel(msg.Network, msg.Channel, false) ch = GetChannel(msg.Network, msg.Channel) } templateData := parseMessage(msg) oldMsgWrap := jq(fmt.Sprintf("#msgwrap-%d", msg.ID)) if oldMsgWrap.Length != 0 { loadedTempl := jq("<div></div>") templates.AppendObj("message", loadedTempl, templateData) oldMsgWrap.ReplaceWith(loadedTempl.Children(":first")) } else { templates.AppendObj("message", ch, templateData) } if isNew { NotifyMessage(msg.Network, msg.Channel, templateData.Sender, templateData.Clipboard, templateData.Highlight) } }
// FinishNewScript creates the script with the name in the adder box and closes the adder func FinishNewScript() { net := jq("#script-list").Attr("data-network") name := jq("#script-adder").Val() if net == Global { data.GlobalScripts.Put(net, name, defaultScript, func(net string) { addScriptToList(name) SwitchScript(name) }) } else { data.MustGetNetwork(net).Scripts.Put(net, name, defaultScript, func(net string) { addScriptToList(name) SwitchScript(name) }) } CancelNewScript() }
// OpenScriptEditor opens the script editor func OpenScriptEditor(net string) { var scripts data.ScriptStore if net == "global" { scripts = data.GlobalScripts } else { scripts = data.MustGetNetwork(net).Scripts } jq("#settings-main").AddClass("hidden") jq("#settings-networks").AddClass("hidden") jq("#settings-scripts").RemoveClass("hidden") scripteditor = ace.Edit("script-editor") scripteditor.SetOptions(map[string]interface{}{ "fontFamily": "Fira Code", "fontSize": "11pt", }) scripteditor.GetSession().SetMode("ace/mode/golang") scripteditor.GetSession().SetUseWorker(false) scripteditor.GetSession().SetUseWrapMode(true) scripteditor.GetSession().SetUseSoftTabs(false) scripteditor.Get("commands").Call("addCommand", map[string]interface{}{ "name": "save", "bindKey": map[string]interface{}{ "win": "Ctrl-S", "mac": "Command-S", }, "exec": SaveScript, "readOnly": false, }) jq("#script-list").Empty() for name := range scripts { addScriptToList(name) } SwitchClearScript() jq("#script-list").SetAttr("data-network", net) }
// OnChangeHighlights updates the highlights in the data store func OnChangeHighlights() { data.MustGetNetwork(GetActiveNetwork()).Highlights.Parse(jq("#network-highlights").Val()) }