Last active
April 7, 2017 14:42
-
-
Save bwinton/0ab969dbb72e86d8cb9c4326d051badc to your computer and use it in GitHub Desktop.
FooIRC Simple Keyboard Shortcuts.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This Action Group implements keyboard shortcuts for Foo IRC. | |
The following keyboard shortcuts are provided: | |
Switch to the previous server in the IRC View (default: Shift+S) | |
Switch to the next server in the IRC View (default: Shift+W) | |
Switch to previous channel or view on the current server (default: Shift+A) | |
Switch to next channel or view on the current server (default: Shift+D) | |
Clears the messages of the currently open private message, channel, or server console view (default: Shift+C) | |
These shortcuts can be enabled and changed in Custom Settings. | |
*/ | |
KeyCommands { | |
action Init() { | |
set group.enableKeyboardShortcuts = false; | |
set group.nextChannelKeys = "CONTROL+K"; | |
set group.prevChannelKeys = "CONTROL+SHIFT+K"; | |
/* A linked list of the channels with activity. */ | |
set group.nextChannel = ""; | |
if (!System.ClusterSectionExists("Shortcut Settings", "Keyboard")) { | |
if (!Utils.IsSet(global.keyboardShortcutSettings)) { | |
set global.keyboardShortcutSettings[]; | |
} | |
SetSettingIfNotSet("Enable Keyboard Shortcuts:", group.enableKeyboardShortcuts); | |
SetSettingIfNotSet("Switch to the Previous Channel or View on the Current Server:", group.nextChannelKeys); | |
SetSettingIfNotSet("Switch to the Next Channel or View on the Current Server:", group.prevChannelKeys); | |
System.CreateClusterSection("Shortcut Settings", "Keyboard", "keyboardShortcutSettings", "KeyCommands.UpdateLocalValues"); | |
System.SaveSettingsClusterChanges(); | |
} | |
UpdateLocalValues(); | |
} | |
action SetSettingIfNotSet(setting, value) { | |
if (!Utils.IsSet(global.keyboardShortcutSettings[setting])) { | |
global.keyboardShortcutSettings[setting] = value; | |
} | |
} | |
action Uninit() { | |
if (System.ClusterSectionExists("Shortcut Settings", "Keyboard")) { | |
System.RemoveClusterSection("Shortcut Settings", "Keyboard"); | |
} | |
} | |
action UpdateLocalValues() { | |
group.enableKeyboardShortcuts = global.keyboardShortcutSettings["Enable Keyboard Shortcuts:"]; | |
group.nextChannelKeys = global.keyboardShortcutSettings["Switch to the Previous Channel or View on the Current Server:"]; | |
group.prevChannelKeys = global.keyboardShortcutSettings["Switch to the Next Channel or View on the Current Server:"]; | |
if (group.enableKeyboardShortcuts) { | |
Actions.Register("KEY", group.prevChannelKeys, "NextChannel"); | |
Actions.Register("KEY", group.nextChannelKeys, "PrevChannel"); | |
Actions.Register("USER", "PRIVMSG", "ChannelMessage"); | |
} | |
else { | |
Actions.Unregister(); | |
} | |
} | |
action NextChannel() | |
{ | |
System.ConsoleMessage("Next Channel!!!"); | |
System.ConsoleMessage(group.nextChannel); | |
if (group.nextChannel == "") { | |
return null; | |
} | |
Server.SwitchToChannel(group.nextChannel["channel"], group.nextChannel["server"]); | |
group.nextChannel = group.nextChannel["next"]; | |
} | |
action PrevChannel() | |
{ | |
System.ConsoleMessage("Previous Channel!!!"); | |
System.ConsoleMessage(group.nextChannel); | |
if (group.nextChannel == "") { | |
return null; | |
} | |
/* Go to the end of the linked list. */ | |
set curr = group.nextChannel; | |
set prev = group.nextChannel; | |
while (curr["next"] != "") { | |
prev = curr; | |
curr = curr["next"]; | |
} | |
if (prev == curr) { | |
/* This can only happen if there was only one entry in the nextChannel linked list. */ | |
group.nextChannel = "" | |
} else { | |
prev["next"] = ""; | |
} | |
System.ConsoleMessage(prev); | |
System.ConsoleMessage(curr); | |
Server.SwitchToChannel(curr["channel"], curr["server"]); | |
} | |
action ChannelMessage() | |
{ | |
if (r_3 != server.r_nickname) { | |
System.ConsoleMessage("Channel Message!!!"); | |
/* Create the item to add to the end of the linked list. */ | |
set next[]; | |
next["channel"] = r_3; | |
next["server"] = server.r_guid; | |
next["next"] = ""; | |
if (Server.IsViewVisible(next["channel"], next["server"])) { | |
System.ConsoleMessage("Current Channel!"); | |
System.ConsoleMessage(group.nextChannel); | |
return null; | |
} | |
if (group.nextChannel == "") { | |
/* If the list was empty, set this as the first item. */ | |
group.nextChannel = next; | |
System.ConsoleMessage("Adding!"); | |
System.ConsoleMessage(group.nextChannel); | |
return null; | |
} | |
/* Otherwise, look for this channel in the list. */ | |
set curr = group.nextChannel; | |
set prev = group.nextChannel; | |
while (curr != "") { | |
if (curr["channel"] == next["channel"] & curr["server"] == next["server"]) { | |
/* We found it, so bail early! */ | |
System.ConsoleMessage("Already got it!"); | |
System.ConsoleMessage(group.nextChannel); | |
return null; | |
} | |
prev = curr; | |
curr = curr["next"]; | |
} | |
/* If we can’t find it, add it to the end. */ | |
System.ConsoleMessage("Adding!"); | |
prev["next"] = next; | |
System.ConsoleMessage(group.nextChannel); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment