diff --git a/exec/menuedit.js b/exec/menuedit.js index 766b09dc8547a04888b54ce57e920a4c10bc0124..3077a7e10d16338db2f6b9c91d5cfc4a99b5ac22 100644 --- a/exec/menuedit.js +++ b/exec/menuedit.js @@ -9,12 +9,12 @@ load("uifcdefs.js"); load("menu-commands.js"); var help = { - 'main' : [ + main: [ "Main menu", "Select a menu to edit, and hit <enter>.", "Hit <enter> on a blank line to create a new menu." ], - 'editMenu' : [ + editMenu: [ "Edit a menu", " Title: String shown at top if header graphic unspecified.", " Header: File to be displayed at the top of the menu.", @@ -25,13 +25,13 @@ var help = { "", "CTRL-A and @-codes are supported in Title and Prompt." ], - 'editCommands' : [ + editCommands: [ "Menu commands", "A list of menu commands/items.", "Format is:", "Hotkey, Text, Area->Command" ], - 'editCommand' : [ + editCommand: [ "Edit a command", " Hotkey: The hotkey for this menu item.", " Text: The text displayed for this item. CTRL-A and @ codes supported.", @@ -41,7 +41,7 @@ var help = { " Command: If 'Area' is not 'Menus', the command to be executed.", " Menu: If 'Area' is 'Menus', the menu to be loaded." ], - 'chooseCommandArea' : [ + chooseCommandArea: [ "Choose a command area", " User: User information and configuration commands.", " System: System areas & commands that don't fit elsewhere.", @@ -50,7 +50,7 @@ var help = { "Externals: External programs.", " Menus: Other menus." ], - 'editLightbarOptions' : [ + editLightbarOptions: [ "Lightbar Options", "Position: Centered, Left, Right, or Fixed", "x: X-coordinate of top left corner of menu box (fixed only)", @@ -66,17 +66,17 @@ var help = { "BorderColor: CTRL-A code, menu box border color", "Hotkeys: Whether or not to use hotkeys" ], - 'commands' : [] + commands: [] }; -var log = function(msg) { +var flog = function(msg) { var f = new File(system.mods_dir + "uifc.log"); f.open("a"); f.writeln(system.timestr() + ": " + msg); f.close(); } -var saveMenus = function() { +function saveMenus() { file_backup(menuFile); var f = new File(menuFile); f.open("w"); @@ -84,33 +84,31 @@ var saveMenus = function() { f.close(); } -var init = function() { +function init() { uifc.init("Synchronet Menu Editor"); js.on_exit("uifc.bail()"); } -var uifcYesNo = function(question) { - while(1) { +function uifcYesNo(question) { + while (1) { var ret = uifc.list(WIN_MID, question + "?", ["Yes", "No"]); - if(ret >= 0) - break; + if (ret >= 0) break; } return (ret == 0); } -var uifcHelp = function(section) { +function uifcHelp(section) { uifc.help_text = word_wrap(help[section].join("\r\n\r\n")); } -var fileBrowser = function(dir) { - if(!file_isdir(dir)) - return; - while(1) { +function fileBrowser(dir) { + if (!file_isdir(dir)) return; + while (1) { var file; var files = directory(dir + "*", GLOB_MARK); var displayFiles = []; - for(var f = 0; f < files.length; f++) { - if(file_isdir(files[f])) { + for (var f = 0; f < files.length; f++) { + if (file_isdir(files[f])) { var fn = (files[f][files[f].length - 1] == "/") ? files[f].split("/") : files[f].split("\\"); displayFiles.push(fn[fn.length - 2] + "/"); } else { @@ -118,77 +116,76 @@ var fileBrowser = function(dir) { } } var selection = uifc.list(WIN_ORG|WIN_MID, "Browsing " + dir, displayFiles); - if(selection < 0) + if (selection < 0) { break; - else if(file_isdir(files[selection])) + } else if (file_isdir(files[selection])) { var file = fileBrowser(files[selection]); - else + } else { var file = files[selection]; - if(typeof file != "undefined") - break; + } + if (file !== undefined) break; } return file; } -var main = function() { +function main() { var last = 0; - while(1) { + while (1) { getMenus(); uifcHelp("main"); var menus = Object.keys(Commands.Menus); var menuTitles = []; - for(var m in Commands.Menus) + for (var m in Commands.Menus) { menuTitles.push(Commands.Menus[m].Title); + } var selection = uifc.list( WIN_ORG|WIN_MID|WIN_XTR|WIN_DEL|WIN_ACT|WIN_ESC, - 0, 0, 0, last, last, - "Menus", - menuTitles + 0, 0, 0, last, last, "Menus", menuTitles ); - if(selection < 0) { + if (selection < 0) { break; - } else if(selection&MSK_DEL) { + } else if (selection&MSK_DEL) { selection ^= MSK_DEL; delete Commands.Menus[menus[selection]]; selection--; - } else if(selection >= menus.length) { + } else if (selection >= menus.length) { editMenu(); } else { editMenu(selection); } last = Math.max(selection, 0); - if(uifcYesNo("Save changes")) - saveMenus(); + if (uifcYesNo("Save changes")) saveMenus(); } } -var editMenu = function(menu) { +function editMenu(menu) { - if(typeof menu == "undefined") { - while(typeof ID == "undefined" || typeof Commands.Menus[ID] != "undefined") - var ID = time(); + if (menu === undefined) { + while (ID === undefined || Commands.Menus[ID] !== undefined) { + var ID = time(); // whafuck? + } Commands.Menus[ID] = { - 'Title' : "Title", - 'Header' : "head.asc", - 'List' : true, - 'Prompt' : "Your choice:", - 'Commands' : [], - 'Lightbar' : { - 'Position' : "Centered", - 'x' : 1, - 'y' : 1, - 'Width' : 1, - 'Height' : 1, - 'Background' : "", - 'ActiveForeground' : "\\1h\\1w", - 'ActiveBackground' : "\\16", - 'InactiveForeground' : "\\1n\\1w", - 'InactiveBackground' : "\\10", - 'HotkeyColor' : "\\1h\\1c", - 'BorderColor' : "\\1h\\1w", - 'Hotkeys' : true + Title: "Title", + Header: "head.asc", + List: true, + Prompt: "Your choice:", + Commands: [], + Lightbar: { + Position: "Centered", + x: 1, + y: 1, + Width: 1, + Height: 1, + Background: "", + ActiveForeground: "\\1h\\1w", + ActiveBackground: "\\16", + InactiveForeground: "\\1n\\1w", + InactiveBackground: "\\10", + HotkeyColor: "\\1h\\1c", + BorderColor: "\\1h\\1w", + Hotkeys: true } }; var keys = Object.keys(Commands.Menus); @@ -198,42 +195,36 @@ var editMenu = function(menu) { var menu = Object.keys(Commands.Menus)[menu]; } var last = 0; - while(1) { + while (1) { uifcHelp("editMenu"); var selections = Object.keys(Commands.Menus[menu]); var items = []; - for(var item in Commands.Menus[menu]) { - items.push( - format( - "%8s %s", - item, - (typeof Commands.Menus[menu][item] != "object") ? Commands.Menus[menu][item] : "..." - ) - ); + for (var item in Commands.Menus[menu]) { + items.push(format( + "%8s %s", item, + (typeof Commands.Menus[menu][item] != "object") ? Commands.Menus[menu][item] : "..." + )); } var selection = uifc.list( WIN_ORG|WIN_MID|WIN_ACT|WIN_ESC, - 0, 0, 0, last, last, - Commands.Menus[menu].Title + ": Items", - items + 0, 0, 0, last, last, Commands.Menus[menu].Title + ": Items", items ); - if(selection < 0) - break; - switch(selections[selection]) { + if (selection < 0) break; + switch (selections[selection]) { case "Header": var selection2 = uifc.list( WIN_ORG|WIN_MID, "Header file:", ["Enter a path", "Browse"] ); - if(selection2 == 0) { + if (selection2 == 0) { var header = uifc.input( WIN_MID, Commands.Menus[menu].Header, 0, K_EDIT ); - } else if(selection2 == 1) { + } else if (selection2 == 1) { var header = fileBrowser(system.text_dir + "menu/"); } if(typeof header == "string") @@ -241,8 +232,7 @@ var editMenu = function(menu) { break; case "List": var yes = uifcYesNo("List menu items"); - if(yes == -1) - break; + if (yes == -1) break; Commands.Menus[menu].List = yes; break; case "Commands": @@ -254,11 +244,9 @@ var editMenu = function(menu) { case "Default": var yes = uifcYesNo("Default menu"); Commands.Menus[menu].Default = (yes); - if(!yes) - break; - for(var m in Commands.Menus) { - if(m == menu) - continue; + if (!yes) break; + for (var m in Commands.Menus) { + if (m == menu) continue; Commands.Menus[m].Default = false; } break; @@ -271,38 +259,33 @@ var editMenu = function(menu) { } -var editItem = function(menu, item) { +function editItem(menu, item) { var text = uifc.input(WIN_MID, item, Commands.Menus[menu][item], 0, K_EDIT); - if(typeof text != "undefined") - Commands.Menus[menu][item] = text; + if (typeof text != "undefined") Commands.Menus[menu][item] = text; } -var editCommands = function(menu) { +function editCommands(menu) { var last = 0; - while(1) { + while (1) { uifcHelp("editCommands"); var menuCommands = []; - for(var c in Commands.Menus[menu].Commands) { - if(Commands.Menus[menu].Commands[c].command.split(".")[1] == "Menus") { - menuCommands.push( - format( - "%s %-30s Menus->%s", - Commands.Menus[menu].Commands[c].hotkey, - Commands.Menus[menu].Commands[c].text.substr(0, 30), - Commands.Menus[Commands.Menus[menu].Commands[c].menu].Title.substr(0, uifc.screen_width - 35) - ) - ); + for (var c in Commands.Menus[menu].Commands) { + if (Commands.Menus[menu].Commands[c].command.split(".")[1] == "Menus") { + menuCommands.push(format( + "%s %-30s Menus->%s", + Commands.Menus[menu].Commands[c].hotkey, + Commands.Menus[menu].Commands[c].text.substr(0, 30), + Commands.Menus[Commands.Menus[menu].Commands[c].menu].Title.substr(0, uifc.screen_width - 35) + )); } else { var path = Commands.Menus[menu].Commands[c].command.split("."); - menuCommands.push( - format( - "%s %-30s %s->%s", - Commands.Menus[menu].Commands[c].hotkey, - Commands.Menus[menu].Commands[c].text.substr(0, 30), - path[1], - path[2] - ) - ); + menuCommands.push(format( + "%s %-30s %s->%s", + Commands.Menus[menu].Commands[c].hotkey, + Commands.Menus[menu].Commands[c].text.substr(0, 30), + path[1], + path[2] + )); } } var selection = uifc.list( @@ -311,12 +294,12 @@ var editCommands = function(menu) { Commands.Menus[menu].Title + ": Commands", menuCommands ); - if(selection < 0) { + if (selection < 0) { break; - } else if(selection&MSK_DEL) { + } else if (selection&MSK_DEL) { Commands.Menus[menu].Commands.splice((selection^MSK_DEL), 1); last = Math.max((selection^MSK_DEL) - 1, 0); - } else if(selection < Commands.Menus[menu].Commands.length) { + } else if (selection < Commands.Menus[menu].Commands.length) { last = editCommand(menu, selection); } else { last = editCommand(menu); @@ -324,20 +307,19 @@ var editCommands = function(menu) { } } -var editCommand = function(menu, selection) { +function editCommand(menu, selection) { - if(typeof selection == "undefined") { - Commands.Menus[menu].Commands.push( - { 'hotkey' : '', - 'text' : '', - 'ARS' : '', - 'command' : 'Commands.Messages.Find' - } - ); + if (selection === undefined) { + Commands.Menus[menu].Commands.push({ + hotkey: '', + text: '', + ARS: '', + command: 'Commands.Messages.Find' + }); selection = Commands.Menus[menu].Commands.length - 1; } - while(1) { + while (1) { uifcHelp("editCommand"); var path = Commands.Menus[menu].Commands[selection].command.split("."); var options = [ @@ -347,14 +329,14 @@ var editCommand = function(menu, selection) { "Position: " + selection, " Area: " + path[1] ]; - if(path.length > 2) + if (path.length > 2) { options.push(" Command: " + path[2]); - else + } else { options.push(" Menu: " + Commands.Menus[Commands.Menus[menu].Commands[selection].menu].Title); + } var selection2 = uifc.list(WIN_ORG|WIN_MID, "Edit command", options); - if(selection2 < 0) - break; - if(selection2 == 0) { + if (selection2 < 0) break; + if (selection2 == 0) { Commands.Menus[menu].Commands[selection].hotkey = uifc.input( WIN_MID, "Hotkey", @@ -362,7 +344,7 @@ var editCommand = function(menu, selection) { 1, K_EDIT|K_UPPER ); - } else if(selection2 == 1) { + } else if (selection2 == 1) { var text = uifc.input( WIN_MID, "Text", @@ -370,11 +352,9 @@ var editCommand = function(menu, selection) { 0, K_EDIT ); - if(typeof text != "undefined") - Commands.Menus[menu].Commands[selection].text = text; - } else if(selection2 == 2) { - if(Commands.Menus[menu].Commands[selection].command.split(".")[1] == "Externals") - continue; + if (text !== undefined) Commands.Menus[menu].Commands[selection].text = text; + } else if (selection2 == 2) { + if (Commands.Menus[menu].Commands[selection].command.split(".")[1] == "Externals") continue; var ars = uifc.input( WIN_MID, "Access Requirements", @@ -382,9 +362,8 @@ var editCommand = function(menu, selection) { 0, K_EDIT ); - if(typeof ars != "undefined") - Commands.Menus[menu].Commands[selection].ARS = ars; - } else if(selection2 == 3) { + if (ars !== undefined) Commands.Menus[menu].Commands[selection].ARS = ars; + } else if (selection2 == 3) { var position = uifc.input( WIN_MID, "Position", @@ -392,24 +371,21 @@ var editCommand = function(menu, selection) { 0, K_NUMBER|K_EDIT ); - if(typeof position == "undefined" || parseInt(position) >= Commands.Menus[menu].Commands.length) - continue; + if (position === undefined || parseInt(position) >= Commands.Menus[menu].Commands.length) continue; var cut = Commands.Menus[menu].Commands.splice(selection, 1)[0]; Commands.Menus[menu].Commands.splice(position, 0, cut); selection = parseInt(position); } else { var area = chooseCommandArea(); - if(typeof area == "undefined") - break; + if (area === undefined) break; var command = chooseCommand(area); - if(typeof command == "undefined") - break; + if (command === undefined) break; var areas = Object.keys(Commands); - if(areas[area] == "Menus") { + if (areas[area] == "Menus") { var menus = Object.keys(Commands.Menus); Commands.Menus[menu].Commands[selection].command = "Commands.Menus"; Commands.Menus[menu].Commands[selection].menu = menus[command]; - } else if(areas[area] == "Externals") { + } else if (areas[area] == "Externals") { Commands.Menus[menu].Commands[selection].command = "Commands.Externals." + command; Commands.Menus[menu].Commands[selection].ARS = xtrn_area.prog[command].ars; } else { @@ -421,76 +397,68 @@ var editCommand = function(menu, selection) { return selection; } -var chooseCommandArea = function() { +function chooseCommandArea() { uifcHelp("chooseCommandArea"); var areas = Object.keys(Commands); var selection = uifc.list(WIN_MID, "Command Areas", areas); - if(selection >= 0) - return selection; + if (selection >= 0) return selection; } -var chooseCommand = function(area) { +function chooseCommand(area) { var areas = Object.keys(Commands); - if(areas[area] == "Menus") { + if (areas[area] == "Menus") { var commands = []; - for(var m in Commands.Menus) + for (var m in Commands.Menus) { commands.push(Commands.Menus[m].Title); - } else if(areas[area] == "Externals") { + } + } else if (areas[area] == "Externals") { var sec = chooseXtrnSec(); return chooseXtrn(sec); } else { var commands = Object.keys(Commands[areas[area]]); help.commands = [areas[area] + " commands"]; - for(var c = 0; c < commands.length; c++) + for (var c = 0; c < commands.length; c++) { help.commands.push(commands[c] + ": " + Commands[areas[area]][commands[c]].Description); + } } uifcHelp("commands"); - while(1) { + while (1) { var selection = uifc.list(WIN_MID, "Commands", commands); - if(selection < 0) - break; + if (selection < 0) break; return selection; } help.commands = []; } -var chooseXtrnSec = function() { +function chooseXtrnSec() { var sex = []; var codes = []; - for(var sec in xtrn_area.sec) { + for (var sec in xtrn_area.sec) { sex.push(xtrn_area.sec[sec].name); codes.push(sec); } var selection = uifc.list(WIN_MID, "External Program Areas", sex); - if(selection >= 0) - return codes[selection]; + if (selection >= 0) return codes[selection]; } -var chooseXtrn = function(area) { - if(typeof area == "undefined") - return; +function chooseXtrn(area) { + if (area === undefined) return; var xtrns = []; var codes = []; - for(var prog in xtrn_area.sec[area].prog_list) { + for (var prog in xtrn_area.sec[area].prog_list) { xtrns.push(xtrn_area.sec[area].prog_list[prog].name); codes.push(xtrn_area.sec[area].prog_list[prog].code); } var selection = uifc.list(WIN_MID, "External Programs", xtrns); - if(selection >=0 ) - return codes[selection]; + if (selection >= 0) return codes[selection]; } -var editLightbarOptions = function(menu) { +function editLightbarOptions(menu) { var last = 0; - while(1) { + while (1) { var options = []; - for(var property in Commands.Menus[menu].Lightbar) { - options.push( - format( - "%22s %s", - property, Commands.Menus[menu].Lightbar[property] - ) - ); + for (var property in Commands.Menus[menu].Lightbar) { + options.push(format("%22s %s", property, Commands.Menus[menu].Lightbar[property])); } var selection = uifc.list( WIN_ORG|WIN_MID|WIN_ACT, @@ -499,18 +467,15 @@ var editLightbarOptions = function(menu) { options ); last = selection; - if(selection < 0) - return; - switch(selection) { + if (selection < 0) return; + switch (selection) { case 0: var opts = ["Centered", "Left", "Right", "Fixed"]; var pos = uifc.list(WIN_MID, "Lightbar menu position", opts); - if(pos >= 0) - Commands.Menus[menu].Lightbar.Position = opts[pos]; + if (pos >= 0) Commands.Menus[menu].Lightbar.Position = opts[pos]; break; case 1: - if(Commands.Menus[menu].Lightbar.Position != "Fixed") - break; + if (Commands.Menus[menu].Lightbar.Position != "Fixed") break; var x = parseInt( uifc.input( WIN_MID, @@ -520,12 +485,10 @@ var editLightbarOptions = function(menu) { K_EDIT ) ); - if(!isNaN(x) && x > 0) - Commands.Menus[menu].Lightbar.x = x; + if (!isNaN(x) && x > 0) Commands.Menus[menu].Lightbar.x = x; break; case 2: - if(Commands.Menus[menu].Lightbar.Position != "Fixed") - break; + if (Commands.Menus[menu].Lightbar.Position != "Fixed") break; var y = parseInt( uifc.input( WIN_MID, @@ -535,12 +498,10 @@ var editLightbarOptions = function(menu) { K_EDIT ) ); - if(!isNaN(y) && y > 0) - Commands.Menus[menu].Lightbar.y = y; + if (!isNaN(y) && y > 0) Commands.Menus[menu].Lightbar.y = y; break; case 3: - if(Commands.Menus[menu].Lightbar.Position != "Fixed") - break; + if (Commands.Menus[menu].Lightbar.Position != "Fixed") break; var w = parseInt( uifc.input( WIN_MID, @@ -550,12 +511,10 @@ var editLightbarOptions = function(menu) { K_EDIT ) ); - if(!isNaN(w) && w > 0) - Commands.Menus[menu].Lightbar.Width = w; + if (!isNaN(w) && w > 0) Commands.Menus[menu].Lightbar.Width = w; break; case 4: - if(Commands.Menus[menu].Lightbar.Position != "Fixed") - break; + if (Commands.Menus[menu].Lightbar.Position != "Fixed") break; var h = parseInt( uifc.input( WIN_MID, @@ -565,8 +524,7 @@ var editLightbarOptions = function(menu) { K_EDIT ) ); - if(!isNaN(h) && h > 0) - Commands.Menus[menu].Lightbar.Height = h; + if (!isNaN(h) && h > 0) Commands.Menus[menu].Lightbar.Height = h; break; case 5: var b = uifc.list( @@ -574,18 +532,19 @@ var editLightbarOptions = function(menu) { "Background file:", ["Enter a path", "Browse"] ); - if(b == 0) { + if (b == 0) { var b = uifc.input( WIN_MID, Commands.Menus[menu].Lightbar.Background, 0, K_EDIT ); - } else if(b == 1) { + } else if (b == 1) { var bg = fileBrowser(system.text_dir + "menu/"); } - if(typeof bg == "string") + if (typeof bg == "string") { Commands.Menus[menu].Lightbar.Background = bg.replace(system.text_dir + "menu/", ""); + } break; case 6: var fg = uifc.input( @@ -595,8 +554,7 @@ var editLightbarOptions = function(menu) { 12, K_EDIT ); - if(typeof fg != "undefined" && fg != "") - Commands.Menus[menu].Lightbar.ActiveForeground = fg; + if (fg !== undefined && fg != "") Commands.Menus[menu].Lightbar.ActiveForeground = fg; break; case 7: var bg = uifc.input( @@ -606,8 +564,7 @@ var editLightbarOptions = function(menu) { 6, K_EDIT ); - if(typeof bg != "undefined" && bg != "") - Commands.Menus[menu].Lightbar.ActiveBackground = bg; + if (bg !== undefined && bg != "") Commands.Menus[menu].Lightbar.ActiveBackground = bg; break; case 8: var fg = uifc.input( @@ -617,8 +574,7 @@ var editLightbarOptions = function(menu) { 12, K_EDIT ); - if(typeof fg != "undefined" && fg != "") - Commands.Menus[menu].Lightbar.InactiveForeground = fg; + if (fg !== undefined && fg != "") Commands.Menus[menu].Lightbar.InactiveForeground = fg; break; case 9: var bg = uifc.input( @@ -628,8 +584,7 @@ var editLightbarOptions = function(menu) { 6, K_EDIT ); - if(typeof bg != "undefined" && bg != "") - Commands.Menus[menu].Lightbar.InactiveBackground = bg; + if (bg !== undefined && bg != "") Commands.Menus[menu].Lightbar.InactiveBackground = bg; break; case 10: var h = uifc.input( @@ -639,8 +594,7 @@ var editLightbarOptions = function(menu) { 12, K_EDIT ); - if(typeof h != "undefined" && h != "") - Commands.Menus[menu].Lightbar.InactiveForeground = h; + if (h !== undefined && h != "") Commands.Menus[menu].Lightbar.InactiveForeground = h; break; case 11: var b = uifc.input( @@ -650,8 +604,7 @@ var editLightbarOptions = function(menu) { 12, K_EDIT ); - if(typeof b != "undefined" && b != "") - Commands.Menus[menu].Lightbar.BorderColor = b; + if (b !== undefined && b != "") Commands.Menus[menu].Lightbar.BorderColor = b; break; case 12: Commands.Menus[menu].Lightbar.Hotkeys = uifcYesNo("Hotkeys"); @@ -666,5 +619,5 @@ try { init(); main(); } catch(err) { - log(err); + flog(err); }