# toolkit.irc jircii script # adds menu 'Toolkit' to menubar # and some aliases # version: 2005/10/19 # author: ewulf # email: ewulf( - )ululatus.org # homepage: www.ululatus.org $TOOLKIT_VERSION = '2005/10/19'; # imports import javax.swing.*; import javax.swing.text.*; import java.awt.*; import java.awt.geom.*; import java.awt.event.*; import java.awt.image.*; import java.io.*; # aliases alias restart { if ( $1 == 1 ) { if ( !-istrue confirmDialog('Restart jIRCii','Do you really want to restart jIRCii?','YES_NO') ) { return; } } restartJIRCii(); } alias edit { if ( $1 == 1 ) { if ( -istrue confirmDialog('Start Editor','Start the editor?','YES_NO') ) { editScript("$2-"); } } else { editScript("$1-"); } } alias toolkit { if ( ($1 eq 'help') || ($1 eq '?') ) { showToolkitHelp(); } else if ( $1 eq 'about' ) { showAboutToolkit(); } else if ( $1 eq 'reload' ) { reinstallToolkit(); } else { echo('type /toolkit ? or /toolkit help for help'); } } alias loadScript { if ( "$1-" eq '' ) { openScript(); } else { call('/load ' . "$1-"); } } alias showDirectoryList { showScriptDirsList(); } # functions sub openScript { local('$scriptfile'); $scriptfile = showFileDialog('Open Scriptfile',[System getProperty:'user.dir'],'Load Script'); if ( -istrue $scriptfile ) { call("/load $scriptfile"); } } sub editScript { local('$editor $script'); $editor = tkGetProperty('script.editor'); if ( $editor eq '' ) { # echo('Script Editor not set. Edit in configuration sub menu'); # showMessage('Toolkit','No editor for scripts defined!'); if ( (-istrue $1) ) { $script = $1; call('/editor new ' . $script); } else { $script = showFileDialog('Edit Scriptfile',[System getProperty:'user.dir'],'Edit Script'); if ( -istrue $script ) { call('/editor new ' . $script); } } } else { if ( (-istrue $1) ) { $script = $1; call('/exec ' . $editor . ' ' . $script ); } else { $script = showFileDialog('Edit Scriptfile',[System getProperty:'user.dir'],'Edit Script'); if ( -istrue $script ) { call('/exec ' . $editor . ' ' . $script ); } } } } sub restartJIRCii { call('/exec ' . tkGetProperty('restart.command',$restart_buildin)); addTimer({call('/exit');},500,1); # call('/exit'); } # toolkit properties sub getJavaCommand { local('$result $os $tmp'); $os = '' . [System getProperty:'os.name']; $result = '' . [System getProperty:'java.home']; $tmp = $fs . '..'; if ( $tmp isin $result ) { $result = substr($result,0, int([[new String:$result] lastIndexOf: $fs . '..'])); } if ( charAt( $result, strlen($result) - 1 ) ne $fs ) { $result = $result . $fs; } $result = $result . 'bin' . $fs . 'java'; if ( 'Windows' isin $os ) { $result = $result . 'w'; # use javaw on Windows } # echo($result); return $result; } sub initToolkit { if ( !-istrue %GLOBAL['toolkit.config'] ) { $toolkitConfig = [new java.util.Properties]; %GLOBAL['toolkit.config'] = $toolkitConfig; } else { $toolkitConfig = %GLOBAL['toolkit.config']; } $fs = '' . [System getProperty:'file.separator']; $configfile = [System getProperty:'user.home'] . $fs . '.jIRC' . $fs . 'toolkit.config'; $restart_buildin = getDefaultRestartCommand(); loadToolkitConfig(); } sub loadToolkitConfig { if ( -exists $configfile ) { [$toolkitConfig load: [new java.io.FileInputStream:$configfile]]; echo( checkError() ); if ( tkGetProperty('toolkit.version') ne $TOOLKIT_VERSION ) { setProperToolkitVersion(); } } else { setProperToolkitVersion(); } } sub setProperToolkitVersion { tkSetProperty('toolkit.version',$TOOLKIT_VERSION); storeToolkitConfig(); } sub storeToolkitConfig { [$toolkitConfig store: [new java.io.FileOutputStream:[new java.io.File:[new String:$configfile]]], 'toolkit properties']; echo( checkError() ); } sub tkGetProperty { local('$result'); $result = iff((-istrue $2), $2,''); if ( -istrue [$toolkitConfig containsKey:$1] ) { $result = [$toolkitConfig getProperty:$1]; } return $result; } sub tkSetProperty { [$toolkitConfig setProperty:[new String:$1],[new String:$2]]; } sub tkRemoveProperty { [$toolkitConfig remove:[new String: $1]]; } sub getDefaultRestartCommand { return getJavaCommand() . ' -cp ' . [System getProperty:'java.class.path'] . ' rero.test.WindowTest'; } sub showMessage { local('$title $message'); $title = iff( -istrue $1, $1, 'Toolkit Message' ); $message = iff( -istrue $2, $2, '' ); if ( $message ne '') { [JOptionPane showMessageDialog: $null, [new String:$message], [new String: $title], 1]; } } sub inputDialog { local('$result'); $result = [JOptionPane showInputDialog: $null,[new String:$2], [new String:$1],[JOptionPane PLAIN_MESSAGE],$null,$null,[new String:$3]]; return $result; } sub confirmDialog { local('$result'); if ( $3 eq 'YES_NO' ) { $result = [JOptionPane showConfirmDialog: $null,[new String:$2], [new String:$1],[JOptionPane YES_NO_OPTION]]; if ( $result == [JOptionPane YES_OPTION] ) { $result = 1; } else { $result = 0; } } else { # OK_CANCEL $result = [JOptionPane showConfirmDialog: $null,[new String:$2], [new String:$1],[JOptionPane OK_CANCEL_OPTION]]; if ( $result == [JOptionPane OK_OPTION] ) { $result = 1; } else { $result = 0; } } return $result; } sub showToolkitHelp { if ( !%GLOBAL['toolkit.help.browser'] ) { createHelpBrowser(); } else { $helpBrowser = %GLOBAL['toolkit.help.browser']; } [$helpBrowser show]; } sub createHelpBrowser { if ( !$helpBrowser ) { local('$screen $sw $sh $fw $fh $page $display $linklistener'); import java.awt.*; import javax.swing.*; import java.net.*; $helpBrowser = [new JFrame:"Toolkit - Help"]; [$helpBrowser setDefaultCloseOperation: [JFrame HIDE_ON_CLOSE]]; [$helpBrowser setSize: 640, 480]; [$helpBrowser setIconImage: createEditorIcon()]; [[$helpBrowser getContentPane] setLayout:[new BorderLayout]]; [$helpBrowser setResizable: 0]; $display = [new JEditorPane:"text/html", ""]; $linklistener = lambda( { local('$ref $url') if ([$1 getEventType] eq "ACTIVATED") { $url = [$1 getURL]; $ref = [$url getRef]; if ( $ref ne '' ) { if ( $ref eq 'close' ) { [$helpBrowser setVisible: 0]; } else { [$display scrollToReference: $ref]; } } else { openCommand( $url ); } } }, $display => $display, $helpBrowser => $helpBrowser ); [$display addHyperlinkListener: $linklistener]; [[$helpBrowser getContentPane] add:[new JScrollPane:$display], [BorderLayout CENTER]]; $page = [new java.io.File: baseDirectory(), 'toolkit.help']; if ( [$page isFile] ) { $page = [$page toURL]; } else { $page = [new java.io.File: getScriptResource('toolkit.irc','toolkit.help')]; if ( [$page isFile] ) { $page = [$page toURL]; } else { $page = $null; } } if ( $page ) { [$display setPage: $page]; } else { [$display setText: '

404 TOOLKIT HELP FILE NOT FOUND

']; } [$display setEditable:0]; $screen = [[Toolkit getDefaultToolkit] getScreenSize]; $sw = [Math rint: ([$screen width] / 2) ]; $sh =[Math rint: ([$screen height] / 2) ]; $fw = [Math rint: ([[$helpBrowser getSize] width] / 2)]; $fh = [Math rint: ([[$helpBrowser getSize] height] / 2)]; [$helpBrowser setLocation: ($sw - $fw),($sh - $fh)]; %GLOBAL['toolkit.help.browser'] = $helpBrowser; } } sub showAboutToolkit { if ( !$aboutToolkit ) { local('$about'); $about = [new JOptionPane]; [$about setMessage: [new String: 'Toolkit Script ' . tkGetProperty('toolkit.version') . "\nAuthor: ewulf\nEmail: ewulf@ululatus.org\nHomepage: www.ululatus.org"]]; [$about setMessageType: [JOptionPane INFORMATION_MESSAGE]]; [$about setIcon: { if ( $0 eq 'getIconWidth' ) { return 64; } else if ( $0 eq 'getIconHeight' ) { return 64; } else if ( $0 eq 'paintIcon' ) { local('$path'); # [$2 setColor: [Color white]]; [$2 setColor: [$1 getBackground]]; [$2 fillRect: $3, $4, 64, 64]; $path = [new GeneralPath]; [$path moveTo: 4, 20]; [$path lineTo: 4, 60]; [$path lineTo: 46, 60]; [$path lineTo: 46, 20]; [$path lineTo: 4, 20]; [$path lineTo: 20, 4]; [$path lineTo: 62, 4]; [$path lineTo: 62, 44]; [$path lineTo: 46, 60]; [$path moveTo: 46, 20]; [$path lineTo: 62, 4]; [$2 setColor: [Color yellow]]; [$2 fillRect: 4,20,42,40]; [$2 fill: $path]; [$2 setColor: [Color black]]; [$2 draw: $path]; [$2 setFont: [new Font: [[$2 getFont] getName],0,12]]; [$2 drawString: [new String: 'Toolkit'], 6, 58]; } }]; # [[$about createDialog: $null, 'About Toolkit'] show]; createHelpBrowser(); $aboutToolkit = [$about createDialog: $helpBrowser, 'About Toolkit']; [$aboutToolkit setModal: 1]; } [$aboutToolkit show]; } initToolkit(); sub reinstallToolkit { call('/reload toolkit.irc'); } sub installToolkitMenu { menubar "&Toolkit" { # load a into jircii item "&Load script" { openScript(); } item "&Edit script" { editScript(); } addSeparator(); # menu scripts start # menu "&Script Directories" { menu "Loadable &Scripts" { local('@scriptdirs $scriptdir $i @files'); @scriptdirs = getScriptDirs(); for ( $i = 0; $i < 10; $i++ ) { if ( $i < size(@scriptdirs) ) { @files = getScriptFilesFromDir(@scriptdirs[$i], 1); if ( size(@files) > 0 ) { %GLOBAL['toolkit.script.dir.' . $i] = @scriptdirs[$i]; %GLOBAL['toolkit.script.dir.files.' . $i] = @files; } else { %GLOBAL['toolkit.script.dir.' . $i] = $null; %GLOBAL['toolkit.script.dir.files.' . $i] = $null; } } else { %GLOBAL['toolkit.script.dir.' . $i] = $null; %GLOBAL['toolkit.script.dir.files.' . $i] = $null; } } if ( -istrue %GLOBAL['toolkit.script.dir.0'] ) { $scriptdir = %GLOBAL['toolkit.script.dir.0']; menu "$scriptdir" { local('@scripts $script $name'); @scripts = %GLOBAL['toolkit.script.dir.files.0']; foreach $script (@scripts) { $name = getScriptName("$script"); addItem("$name",'/load ' . "$script"); } } } if ( -istrue %GLOBAL['toolkit.script.dir.1'] ) { $scriptdir = %GLOBAL['toolkit.script.dir.1']; menu "$scriptdir" { local('@scripts $script $name'); @scripts = %GLOBAL['toolkit.script.dir.files.1']; foreach $script (@scripts) { $name = getScriptName("$script"); addItem("$name",'/load ' . "$script"); } } } if ( -istrue %GLOBAL['toolkit.script.dir.2'] ) { $scriptdir = %GLOBAL['toolkit.script.dir.2']; menu "$scriptdir" { local('@scripts $script $name'); @scripts = %GLOBAL['toolkit.script.dir.files.2']; foreach $script (@scripts) { $name = getScriptName("$script"); addItem("$name",'/load ' . "$script"); } } } if ( -istrue %GLOBAL['toolkit.script.dir.3'] ) { $scriptdir = %GLOBAL['toolkit.script.dir.3']; menu "$scriptdir" { local('@scripts $script $name'); @scripts = %GLOBAL['toolkit.script.dir.files.3']; foreach $script (@scripts) { $name = getScriptName("$script"); addItem("$name",'/load ' . "$script"); } } } if ( -istrue %GLOBAL['toolkit.script.dir.4'] ) { $scriptdir = %GLOBAL['toolkit.script.dir.4']; menu "$scriptdir" { local('@scripts $script $name'); @scripts = %GLOBAL['toolkit.script.dir.files.4']; foreach $script (@scripts) { $name = getScriptName("$script"); addItem("$name",'/load ' . "$script"); } } } if ( -istrue %GLOBAL['toolkit.script.dir.5'] ) { $scriptdir = %GLOBAL['toolkit.script.dir.5']; menu "$scriptdir" { local('@scripts $script $name'); @scripts = %GLOBAL['toolkit.script.dir.files.5']; foreach $script (@scripts) { $name = getScriptName("$script"); addItem("$name",'/load ' . "$script"); } } } if ( -istrue %GLOBAL['toolkit.script.dir.6'] ) { $scriptdir = %GLOBAL['toolkit.script.dir.6']; menu "$scriptdir" { local('@scripts $script $name'); @scripts = %GLOBAL['toolkit.script.dir.files.6']; foreach $script (@scripts) { $name = getScriptName("$script"); addItem("$name",'/load ' . "$script"); } } } if ( -istrue %GLOBAL['toolkit.script.dir.7'] ) { $scriptdir = %GLOBAL['toolkit.script.dir.7']; menu "$scriptdir" { local('@scripts $script $name'); @scripts = %GLOBAL['toolkit.script.dir.files.7']; foreach $script (@scripts) { $name = getScriptName("$script"); addItem("$name",'/load ' . "$script"); } } } if ( -istrue %GLOBAL['toolkit.script.dir.8'] ) { $scriptdir = %GLOBAL['toolkit.script.dir.8']; menu "$scriptdir" { local('@scripts $script $name'); @scripts = %GLOBAL['toolkit.script.dir.files.8']; foreach $script (@scripts) { $name = getScriptName("$script"); addItem("$name",'/load ' . "$script"); } } } if ( -istrue %GLOBAL['toolkit.script.dir.9'] ) { $scriptdir = %GLOBAL['toolkit.script.dir.9']; menu "$scriptdir" { local('@scripts $script $name'); @scripts = %GLOBAL['toolkit.script.dir.files.9']; foreach $script (@scripts) { $name = getScriptName("$script"); addItem("$name",'/load ' . "$script"); } } } } # menu scripts end addSeparator(); menu "&Reload Script" { local('@scripts $prop $item $script'); $prop = getProperty('script.files'); @scripts = split('::', $prop); foreach $item (@scripts) { $script = [[new java.io.File: $item] getName]; addItem("$item" , "/reload $script"); } } menu "&Unload Script" { local('@scripts $prop $item $script'); $prop = getProperty('script.files'); @scripts = split('::', $prop); foreach $item (@scripts) { $script = [[new java.io.File: $item] getName]; addItem("$item" , "/unload $script"); } } menu "Edit &loaded script" { local('@scripts $prop $item $script $editor'); $prop = getProperty('script.files'); @scripts = split('::', $prop); $editor = tkGetProperty('script.editor'); foreach $item (@scripts) { addItem("$item" , "/edit $item"); } } addSeparator(); menu "&Configuration" { menu "Script Editor" { local('$editor'); $editor = tkGetProperty('script.editor',''); if ( $editor ne '' ) { addItem("$editor",'edit 1'); } else { addItem("$editor",'/editor new'); } item "Search program" { local('$editor'); $editor = showFileDialog('Select Program for editing script files', [new java.io.File: tkGetProperty('script.editor')] ); if ( (-istrue $editor) && (-exists $editor) ) { tkSetProperty('script.editor',$editor); storeToolkitConfig(); } } item "Edit &command" { local('$editor'); $editor = inputDialog('Script Editor','Edit command for editing script files', [new java.io.File: tkGetProperty('script.editor')],'OK'); if ( (-istrue $editor) ) { tkSetProperty('script.editor',$editor); storeToolkitConfig(); } } item "Use built-in" { local('$editor'); $editor = tkGetProperty('script.editor'); if ( $editor ne '' ) { tkRemoveProperty('script.editor'); storeToolkitConfig(); } } } menu "Restart Command" { local('$restartcmd'); $restartcmd = tkGetProperty('restart.command',""); addItem("$restartcmd",'/restart 1'); item "Search program" { local('$restart'); $restart = showFileDialog('Select executable that restarts jIRCii', '','OK'); if ( (-istrue $restart) && (-exists $restart) ) { tkSetProperty('restart.command',$restart); storeToolkitConfig(); } } item "Edit &command" { local('$restart'); $restart = inputDialog('Enter command to restart jIRCii','Current command: ' . tkGetProperty('restart.command',"$restart_buildin"), tkGetProperty('restart.command',"$restart_buildin") ); if ( -istrue $restart ) { tkSetProperty('restart.command',$restart); storeToolkitConfig(); } } item "Reset to &default" { tkRemoveProperty('restart.command'); storeToolkitConfig(); } } menu "Script Directories" { addItem('Edit directory list','/showDirectoryList'); } addSeparator(); # reload toolkit item "Reload &Toolkit" { reinstallToolkit(); } } addSeparator(); # restart jircii item "&Restart jIRCii" { # restartJIRCii(); call('/restart 1'); } } menubar "&Help" { addSeparator(); item "Toolkit Help" {showToolkitHelp();} item "About Toolkit" {showAboutToolkit();} } menubar "&Window" { local('@editor_titles $editor_title $editor_index'); if ( tkGetProperty('script.editor','') ne '' ) { return; } addSeparator(); addItem( 'New Toolkit Editor', '/editor new' ); @editor_titles = [%GLOBAL['toolkit.editor.manager'] titles]; if ( size(@editor_titles) > 0 ) { addSeparator(); $editor_index = 0; foreach $editor_title (@editor_titles) { # local('$temp'); # $temp = copy($editor_title); addItem( "$editor_index $editor_title", "/editor show $editor_index" ); $editor_index++; } } } } installToolkitMenu(); on session { refreshMenubar(); } ################################## # Built-in Script Editor # ################################## alias editor { if ( !-istrue isEditorManagerInstalled() ) { installEditorManager(); # echo('toolkit.editor.manager installed'); echo('toolkit menu installed'); } if ( -istrue $1 ) { callEditorManager($1,$2,$3,$4); } } sub isEditorManagerInstalled { if ( -istrue %GLOBAL['toolkit.editor.manager'] ) { return 1; } return 0; } sub installEditorManager { if ( !%GLOBAL['toolkit.editor.manager.editors'] ) { %GLOBAL['toolkit.editor.manager.editors'] = array(); } %GLOBAL['toolkit.editor.manager'] = lambda({ this('@EDITORS'); @EDITORS = %GLOBAL['toolkit.editor.manager.editors']; if ( $0 eq 'new' ) { local('$editWin'); $editWin = createEditorFrame($1); add(@EDITORS,$editWin,size(@EDITORS)); [$editWin setVisible: 1]; } else if ( $0 eq 'remove' ) { if ( -istrue $1 ) { remove(@EDITORS,$1); } else { echo('no editor: ' . $1); } } else if ( $0 eq 'count' ) { return size(@EDITORS); } else if ( $0 eq 'titles' ) { local('@titles $title $editor @parts'); @titles = array(); foreach $editor (@EDITORS) { $title = [$editor getTitle]; @parts = split(' - ', $title); if ( (-isnumber @parts[2]) || (@parts[2] eq 'New') ) { add(@titles,'' . $title,size(@titles)); } else { add(@titles,@parts[2],size(@titles)); } } return @titles; } else if ( $0 eq 'show' ) { if ( -isnumber $1 ) { [@EDITORS[$1] setVisible: 1]; } else { echo('NaN: ' . $1); } } else if ( $0 eq 'list' ) { # echo('editors: ' . @EDITORS); local('$editor $index'); $index = 0; if ( size(@EDITORS) > 0 ) { foreach $editor (@EDITORS) { echo('editor ' . $index . ': ' . [$editor getTitle]); $index++; } } else { echo('no editor available'); } } else { echo('editor: no message: ' . $0); } }); # , @EDITORS => %GLOBAL['toolkit.editor.manager.editors'] ); } sub callEditorManager { if ( !-istrue $1 ) { showMessage('Toolkit - Editor', 'InvalidArgumentException: $1 == null'); } if ( $1 eq 'list' ) { [%GLOBAL['toolkit.editor.manager'] list]; } else if ( $1 eq 'new' ) { [%GLOBAL['toolkit.editor.manager'] new: $2]; } else if ( $1 eq 'remove' ) { [%GLOBAL['toolkit.editor.manager'] remove: $2]; } else if ( $1 eq 'count' ) { return [%GLOBAL['toolkit.editor.manager'] count]; } else if ( $1 eq 'titles' ) { return [%GLOBAL['toolkit.editor.manager'] titles]; } else if ( $1 eq 'show' ) { local('$cnt'); $cnt = [%GLOBAL['toolkit.editor.manager'] count]; if ( ($cnt > 0) && (($2 >= 0) && ($2 < $cnt)) ) { [%GLOBAL['toolkit.editor.manager'] show: $2]; } else { echo('/editor show -> no editor available at: ' . $2) } } else { echo('Toolkit -> unknown message: ' . $1); } } sub createEditorIcon { local('$g $polygon1 $polygon2'); if ( !-istrue $icon ) { $icon = [new BufferedImage: 16, 16, [BufferedImage TYPE_INT_ARGB]]; $g = [$icon getGraphics]; [$g setColor: [new Color: 0,0,0,0]]; [$g fillRect: 0, 0, 16, 16]; $polygon1 = [new Polygon]; [$polygon1 addPoint: 1, 6]; [$polygon1 addPoint: 6, 1]; [$polygon1 addPoint: 14, 1]; [$polygon1 addPoint: 9, 6]; [$polygon1 addPoint: 1, 6]; $polygon2 = [new Polygon]; [$polygon2 addPoint: 9, 6]; [$polygon2 addPoint: 14, 1]; [$polygon2 addPoint: 14, 9]; [$polygon2 addPoint: 9,14]; [$polygon2 addPoint: 9, 6]; [$g setColor: [Color yellow]]; [$g fillRect: 1, 6, 8, 8]; [$g fillPolygon: $polygon1]; [$g fillPolygon: $polygon2]; [$g setColor: [Color black]]; [$g drawRect: 1, 6, 8, 8]; [$g drawPolygon: $polygon1]; [$g drawPolygon: $polygon2]; } return $icon; } sub createEditorFrame { local('$editorFrame $list $text $keylistener'); $editorFrame = [new JFrame:'Toolkit - Editor - ' . callEditorManager('count')]; [[$editorFrame getContentPane] setLayout: [new BorderLayout: 10, 10]]; [$editorFrame setDefaultCloseOperation: [JFrame HIDE_ON_CLOSE]]; [$editorFrame setIconImage: createEditorIcon()]; $text = [new JTextArea]; [$text setLineWrap: 0]; [$text setTabSize: 4]; [$text setFocusTraversalKeysEnabled: 0]; # [[new Boolean: 'false'] booleanValue]]; $keylistener = lambda( { this('$keycode $modifier'); # $keycode = [$1 getKeyCode]; # $modifier = [$1 getModifiersEx]; # echo('keyEvent: ' . $0 . ' code: ' . $keycode . ' mods: ' . $modifier . ' char: ' . [$1 getKeyChar]); if ( $0 eq 'keyReleased') { $keycode = [$1 getKeyCode]; if ( $keycode == [KeyEvent VK_TAB] ) { [$text insert: "\t", [$text getCaretPosition]]; } } }, $text => $text); [$text addKeyListener: $keylistener]; [$editorFrame setJMenuBar: createEditorMenubar( $text, $editorFrame )]; [$text setText:"# jircii script\n"]; [[$editorFrame getContentPane] add: [new JScrollPane: $text],[BorderLayout CENTER]]; [$editorFrame setSize: 640, 480]; [$editorFrame validate]; centerEditorFrame($editorFrame); if ( (-istrue $1) && (-exists $1) ) { [$text setText: readFile($1)]; [$editorFrame setTitle: 'Toolkit - Editor - ' . $1]; [$text setCaretPosition: 0]; } return $editorFrame; } sub createEditorMenubar { local('$menubar $filemenu $editmenu $item $menuitem @fileitems @edititems $actionlistener %editactions'); %editactions = getEditActions([$1 getActions]); # echo('editactions: ' . %editactions); @fileitems = array( 'New', 'Open', 'Save', 'Save as', '-', 'Hide', 'Dispose' ); @edititems = array( 'Cut', 'Copy', 'Paste', '-', 'Select all' ); $menubar = [new JMenuBar]; $filemenu = [new JMenu: "File"]; $editmenu = [new JMenu: "Edit"]; $actionlistener = lambda({ # closure for ActionListener interface this('$actioncommand'); # local('$content $filename'); $actioncommand = '' . [$1 getActionCommand]; if ($actioncommand eq 'New') { [$text setText: "# jircii script\n"]; [$editor setTitle: 'Toolkit - Editor - New']; } else if ( $actioncommand eq 'Open' ) { local('$filename'); $filename = showFileDialog('Open Scriptfile',[System getProperty:'user.dir'],'Load Script'); if ( (-istrue $filename) && (-exists $filename) ) { [$text setText: readFile($filename)]; [$editor setTitle: 'Toolkit - Editor - ' . $filename]; [$text setCaretPosition: 0]; } else if ( -istrue $filename ) { showMessage('Toolkit - Editor','File does not exist: ' . $filename ); } } else if ( $actioncommand eq 'Save' ) { local('$filename @parts'); @parts = split(' - ','' . [$editor getTitle]); if ( -isnumber @parts[2] ) { $filename = showFileDialog('Save Scriptfile',[System getProperty:'user.dir'],'Save Script'); } else { $filename = @parts[2]; } # if ( (-istrue $filename) && (-exists $filename) ) { # if ( confirmDialog('Toolkit - Editor','File exists: ' . $filename . ' Overwrite?') == [JOptionPane OK_OPTION] ) { # $content = [$text getText]; # writeFile( $filename, $content ); # [$editor setTitle: 'Toolkit - Editor - ' . $filename]; # } # } # else if ( -istrue $filename ) { if ( -istrue $filename ) { $content = [$text getText]; writeFile( $filename, $content ); [$editor setTitle: 'Toolkit - Editor - ' . $filename]; } } else if ( $actioncommand eq 'Save as' ) { local('$filename'); $filename = showFileDialog('Save Scriptfile as',[System getProperty:'user.dir'],'Save Script'); if ( (-istrue $filename) && (-exists $filename) ) { if ( confirmDialog('Toolkit - Editor','File exists: ' . $filename . ' Overwrite?') == [JOptionPane OK_OPTION] ) { $content = [$text getText]; writeFile( $filename, $content ); [$editor setTitle: 'Toolkit - Editor - ' . $filename]; } } else if ( -istrue $filename ) { $content = [$text getText]; writeFile( $filename, $content ); [$editor setTitle: 'Toolkit - Editor - ' . $filename]; } } else if ( $actioncommand eq 'Hide' ) { [$editor setVisible: 0]; } else if ( $actioncommand eq 'Dispose' ) { [$editor dispose]; callEditorManager('remove',$editor); } # echo('actioncommand: ' . $actioncommand); [$text requestFocus]; }, $text => $1, $editor => $2 ); foreach $item (@fileitems) { if ( $item ne '-' ) { $menuitem = [new JMenuItem: $item]; [$menuitem setActionCommand: $item]; [$menuitem addActionListener: $actionlistener]; [$filemenu add: $menuitem]; } else { [$filemenu addSeparator]; } } foreach $item (@edititems) { if ( $item ne '-' ) { $menuitem = [new JMenuItem: $item]; [$menuitem setActionCommand: $item]; [$menuitem addActionListener: %editactions[$item]]; [$editmenu add: $menuitem]; } else { [$editmenu addSeparator]; } } [$menubar add: $filemenu]; [$menubar add: $editmenu]; return $menubar; } sub centerEditorFrame { local('$screen $sw $sh $fw $fh'); $screen = [[Toolkit getDefaultToolkit] getScreenSize]; $sw = [Math rint: ([$screen width] / 2) ]; $sh =[Math rint: ([$screen height] / 2) ]; $fw = [Math rint: ([[$1 getSize] width] / 2)]; $fh = [Math rint: ([[$1 getSize] height] / 2)]; [$1 setLocation: ($sw - $fw),($sh - $fh)]; } sub getEditActions { local('%actions @array $action $string'); if ( -isarray $1 ) { @array = $1; %actions = hash( "Paste=$null", "Copy=$null", "Cut=$null", "Select all=$null" ); foreach $action (@array) { $string = '' . [$action toString]; # echo('action: ' . $string); if ( 'CutAction' isin $string ) { %actions['Cut'] = $action; } else if ( 'CopyAction' isin $string ) { %actions['Copy'] = $action; } else if ( 'PasteAction' isin $string ) { %actions['Paste'] = $action; } else if ( 'SelectAllAction' isin $string ) { %actions['Select all'] = $action; } else { # echo('no match: ' . $string ); } } } else { %actions = hash( null => $null ); } return %actions; } sub readFile { local('$handle $text') $handle = openf( "$1" ); @data = readAll($handle); closef($handle); $text = join("\n", @data); return $text; } sub writeFile { local('$handle') $handle = openf('>' . "$1"); print($handle, $2); closef($handle); } call('/editor'); on unload { local('@editors $editor $i'); remove(%GLOBAL,'toolkit.config'); remove(%GLOBAL,'toolkit.editor.manager'); remove(%GLOBAL,'toolkit.help.checked'); @editors = %GLOBAL['toolkit.editor.manager.editors']; if ( (-istrue @editors) && ( size(@editors) > 0 ) ) { foreach $editor (@editors) { [$editor dispose]; } } remove(%GLOBAL,'toolkit.editor.manager.editors'); remove(%GLOBAL,'toolkit.help.browser'); if ( $helpBrowser ) { [$helpBrowser dispose]; $helpBrowser = $null; } if ( $aboutToolkit ) { [$aboutToolkit dispose]; $aboutToolkit = $null; } for ( $i = 0; $i < 10; $i++ ) { remove(%GLOBAL,'toolkit.script.dir.' . $i); remove(%GLOBAL,'toolkit.script.dir.files.' . $i); } } # SCRIPT DIRECTORIES sub applyExtensionFilter { local('$filter $file @files @filtered'); $filter = lambda ( { if ( $0 eq 'accept' ) { local('$ext'); foreach $ext (@filter) { if ( -istrue [[new String: lc($1)] endsWith: $ext] ) { return 1; } } } return 0; }, @filter => split('\|',$2) ); @files = $1; @filtered = array(); foreach $file (@files) { if ( [$filter accept: $file] ) { add(@filtered,$file,size(@filtered)); } } return @filtered; } sub listFilesByExt { local('$root @files $file'); $root = $1; @files = array(); if ( -isDir $root ) { @files = applyExtensionFilter(ls($root),$2); } return @files; } sub getScriptDirs { local('@dirs $dirlist $jIRCiiDir'); $dirlist = [%GLOBAL['toolkit.config'] getProperty: 'toolkit.script.dirs', '']; @dirs = array(); if ( ($dirlist ne '') && ($dirlist ne '') ) { @dirs = split('::',$dirlist); @dirs = removeNotExistingDirs(@dirs); @dirs = removeDoubleEntries(@dirs); if ( size(@dirs) > 10 ) { @dirs = subarray(@dirs,0,10); } } if ( size(@dirs) == 0 ) { $jIRCiiDir = getjIRCiiDirectory( 1 ); # $jIRCiiDir = removeLastFileSeparator($jIRCiiDir); if ( $jIRCiiDir ) { [%GLOBAL['toolkit.config'] setProperty: 'toolkit.script.dirs', $jIRCiiDir]; push(@dirs, "$jIRCiiDir"); } else { push(@dirs, [[[new File: '.'] getAbsoluteFile] getParent]); } } return @dirs; } sub getjIRCiiDirectory { local('$cp $ps @paths $p $path'); $cp = [System getProperty: 'java.class.path']; $ps = [System getProperty: 'path.separator']; $path = ''; if ( $ps isin $cp ) { @paths = split($ps,$cp); foreach $p (@paths) { # echo('path: ' . $cp) if ( lc($p) hasmatch '.+(jerk.jar)$' ) { if ( strlen($cp) > 8 ) { $path = left($p, strlen($p) - 8); } break; } } } else { # echo('classpath: ' . $cp) if ( lc($cp) hasmatch '.+(jerk.jar)$' ) { if ( strlen($cp) > 8 ) { $path = left($cp, strlen($cp) - 8); } } } # echo('getjIRCiiDirectory: ' . $path); if ( $1 ) { $path = removeLastFileSeparator($path); } return $path; } sub removeLastFileSeparator { local('$len $result'); $result = '' . $1; $len = strlen($result); if ( ($len > 1) && (charAt($result,($len - 1)) eq ('' . [System getProperty: 'file.separator'])) ) { $result = '' . substr($1,0,$len - 1); } # echo('removeLastFileSeparator: ' . $result); return $result; } sub removeDoubleEntries { local('@entries @ $entry @result'); @entries = $1; @result = array(); foreach $entry (@entries) { if ( $entry !isin '' . @result ) { push(@result,$entry); } } return @result; } sub removeNotExistingDirs { local('@entries @ $entry @result'); @entries = $1; @result = array(); foreach $entry (@entries) { if ( -isDir $entry ) { push(@result,$entry); } } return @result; } sub getScriptFilesFromDir { local('@files $file'); @files = listFilesByExt($1,'.irc'); if ( $2 ) { @files = sorta(@files); removeLoadedScripts(@files); } return @files; } sub removeLoadedScripts { local('@scripts $script $loaded @removeScripts'); @scripts = $1; $loadedScripts = getProperty('script.files'); @removeScripts = array(); foreach $script (@scripts) { if ( $script isin "$loadedScripts" ){ push(@removeScripts,$script); } } foreach $script (@removeScripts) { remove(@scripts,$script); } } sub getScriptName { local('$name @parts'); if ( [System getProperty: 'file.separator'] eq '\\' ) { @parts = split( '\\\\', $1 ); } else { @parts = split( '/', $1 ); } $name = @parts[(size(@parts) - 1)]; return $name; } # sortable list sub createSortableList { local('@result $panel $btnPanel $list $model $btnAdd $btnRemove $btnUp $btnDown @data $item $actionlistener $optionPane $dirsdlg $dlgResult $status'); $panel = [new JPanel: [new BorderLayout: 5, 5]]; $model = [new DefaultListModel]; @data = $1; foreach $item (@data) { [$model addElement: $item]; } $list = [new JList: $model]; [[$list getSelectionModel] setSelectionMode: [ListSelectionModel SINGLE_SELECTION]]; [$list setVisibleRowCount: 10]; [$list setPreferredSize: [new Dimension: 280, 100]]; [$list setSelectedIndex: 0]; $btnPanel = [new JPanel: [new GridLayout: 6, 1, 5, 5]]; $btnUp = [new JButton: 'Up']; [$btnUp setActionCommand: 'Up']; $btnDown = [new JButton: 'Down']; [$btnDown setActionCommand: 'Down']; $btnAdd = [new JButton: 'Add']; [$btnAdd setActionCommand: 'Add']; $btnRemove = [new JButton: 'Remove']; [$btnRemove setActionCommand: 'Remove']; $status = [new JLabel: 'At most 10 directories, no double entries']; $actionlistener = lambda( { this('$cmd $idx $item'); if ( $0 eq 'actionPerformed' ) { $cmd = [$1 getActionCommand]; if ( $cmd eq 'Up' ) { $idx = [$list getSelectedIndex]; if ( $idx > 0 ) { $item = [$model remove: $idx]; if ( $item ) { [$model add: ($idx - 1), $item]; [$list setSelectedIndex: ($idx - 1)]; } else { [$list setSelectedIndex: $idx]; } } } else if ( $cmd eq 'Down' ) { $idx = [$list getSelectedIndex]; if ( ($idx >= 0) && ($idx < ([$model size] - 1)) ) { $item = [$model remove: $idx]; if ( $item ) { [$model add: ($idx + 1), $item]; [$list setSelectedIndex: ($idx + 1)]; } else { [$list setSelectedIndex: $idx]; } } } else if ( $cmd eq 'Add' ) { $item = showDirectoryDialog('Add Directory',getjIRCiiDirectory(),'Add'); if ( $item ) { if ( -isDir $item ) { $item = [[new File: $item] getCanonicalPath]; if ( [$model size] < 10 ) { if ( ![$model contains: $item] ) { local('@scripts'); @scripts = getScriptFilesFromDir( $item ); if ( size(@scripts) > 0 ) { [$model add: [$model size], $item]; [$list setSelectedIndex: ([$model size] - 1)]; [$status setText: 'Directory added: ' . $item]; } else { [$status setText: 'No scripts found in: ' . $item]; } } else { [$status setText: 'Directory is already in list: ' . $item]; [$list setSelectedValue: $item, 1]; } } else { [$status setText: 'Maximum of 10 directories already reached']; } } else { [$status setText: 'Not a directory: ' . $item]; } } } else if ( $cmd eq 'Remove' ) { $item = [$list getSelectedIndex]; if ( $item >= 0 ) { [$model remove: $item]; [$list setSelectedIndex: iff($item > 0,($item - 1),$item)]; [$status setText: 'Directory removed: ' . $item]; } } # echo($cmd); echo($model); echo($list); } }, $list => $list, $model => $model, $status => $status); [$btnUp addActionListener: $actionlistener]; [$btnDown addActionListener: $actionlistener]; [$btnAdd addActionListener: $actionlistener]; [$btnRemove addActionListener: $actionlistener]; [$btnPanel add: $btnAdd]; [$btnPanel add: $btnRemove]; [$btnPanel add: [new JLabel: ' ']]; [$btnPanel add: [new JLabel: ' ']]; [$btnPanel add: $btnUp]; [$btnPanel add: $btnDown]; [$panel add: [new JScrollPane: $list], [BorderLayout CENTER]]; [$panel add: $btnPanel, [BorderLayout EAST]]; [$panel add: $status, [BorderLayout SOUTH]]; $optionPane = [new JOptionPane: $panel, [JOptionPane PLAIN_MESSAGE], 0, $null, array('Done','Cancel'), 'Cancel']; $dirsdlg = [$optionPane createDialog: $null, 'Script Directories']; [$dirsdlg setModal: 1]; $dlgResult = [$dirsdlg show]; $dlgResult = [$optionPane getValue]; # echo('result: ' . $dlgResult); if ( $dlgResult eq 'Done' ) { @result = [$model toArray]; return @result; } return $null; } sub showScriptDirsList { local('@dirs $result $default_dir'); @dirs = getScriptDirs(); $result = createSortableList(@dirs); if ( -istrue $result ) { echo( 'result: ' . $result ); if ( size($result) == 0 ) { $default_dir = getjIRCiiDirectory( 1 ); # $default_dir = removeLastFileSeparator($default_dir); push($result,"$default_dir"); } # [%GLOBAL['toolkit.config'] put: 'toolkit.script.dirs', join('::',$result)]; if ( size($result) > 0 ) { tkSetProperty('toolkit.script.dirs', join('::',$result)); storeToolkitConfig(); } else { tkRemoveProperty('toolkit.script.dirs'); storeToolkitConfig(); } } } sub checkToolkitHelpFile { if ( !existsToolkitHelpFile() ) { createToolkitHelpFile(); } } sub existsToolkitHelpFile { local('$helpfile'); $helpfile = [new java.io.File: baseDirectory(), 'toolkit.help']; if ( -istrue [$helpfile isFile] ) { return 1; } return $null; } sub createToolkitHelpFile { local('@helptext $func $line'); $func = { # for extra security run this function twice ;-) this('$x $buffer $temp $a $z $A $Z'); if ( !-istrue $buffer ) { $buffer = [new StringBuffer]; } else { [$buffer delete: 0, [$buffer length]]; } $a = asc('a'); $A = asc('A'); $z = asc('z'); $Z = asc('Z'); for ( $x = 0; $x < strlen($1); $x++ ) { if ( (asc(charAt($1,$x)) >= $A) && (asc(charAt($1,$x)) <= $Z) ) { $temp = asc(charAt($1,$x)) - $A; $temp = ($temp + 13) % 26; [$buffer append: chr($temp + $A)]; } else if ( (asc(charAt($1,$x)) >= $a) && (asc(charAt($1,$x)) <= $z) ) { $temp = asc(charAt($1,$x)) - $a; $temp = ($temp + 13) % 26; [$buffer append: chr($temp + $a)]; } else { [$buffer append: charAt($1,$x)]; } } return [$buffer toString]; }; @helptext = getToolkitHelpText( $func ); if ( size(@helptext) > 0 ) { for ( $line = 0; $line < size(@helptext); $line++ ) { @helptext[$line] = substr([$func get: @helptext[$line]], 2); } writeFile( [[new java.io.File: baseDirectory(), 'toolkit.help'] toString], join("\n", @helptext) ); # echo('toolkit help created: ' . [[new java.io.File: baseDirectory(), 'toolkit.help'] toString]); } else { echo('could not create toolkit help: ' . [[new java.io.File: baseDirectory(), 'toolkit.help'] toString]); } } sub getToolkitHelpText { local('$handle @lines $line $start $end @help $i $s $sc $e $ec'); $sc = '# GBBYXVG.URYC FGNEG'; $s = [$1 get: $sc]; $ec = '# GBBYXVG.URYC RAQ'; $e = [$1 get: $ec]; $handle = openf( getScriptResource('toolkit.irc','toolkit.irc') ); @lines = readAll($handle); closef($handle); $start = 0; $end = 0; $i = 0; foreach $line (@lines) { if ( ($line eq $s) || ($line eq $sc) ) { $start = $i + 1; } else if ( ($line eq $e) || ($line eq $ec) ) { $end = $i; } $i++; } if ( ($start > 0) && ( $end > $start ) ) { @help = subarray(@lines, $start, $end); } else { @help = array(); } return @help; } if ( !-istrue %GLOBAL['toolkit.help.checked'] ) { %GLOBAL['toolkit.help.checked'] = 1; checkToolkitHelpFile(); } # GBBYXVG.URYC FGNEG # # # # # Gbbyxvg Fpevcg Uryc&aofc;&aofc;&aofc;&aofc;Pybfr # # Pbagrag # # Nyvnfrf # Gbbyxvg Zrah # Pbasvthengvba # Nobhg # # # # # # # # # # # # # # # # # # # # # # Nyvnfrf&aofc;&aofc;&aofc;&aofc;Pbagrag&aofc;&aofc;&aofc;&aofc;Pybfr # # # # # Nyvnf # Qrfpevcgvba # # # /erfgneg # Erfgnegf wVEPvv hfvat gur fcrpvsvrq pbzznaq va pbasvthengvba be hfvat gur ohvyqva pbzznaq # # # /rqvg [fpevcgsvyr] # Bcraf&aofc;[fpevcgsvyr] va fpevcg rqvgbe be fgnegf rqvgbe vs ab fpevcgsvyr vf tvira # # # /gbbyxvg [?|uryc] # Fubjf Gbbyxvg Uryc # # # /gbbyxvg nobhg # Fubjf Nobhg Gbbyxvg # # # /gbbyxvg erybnq # Erybnqf Gbbyxvg # # # /rqvgbe arj [&yg;fpevcgsvyr&tg;] # Perngrf n arj ohvyg-va rqvgbe. # # # /rqvgbe yvfg # Yvfgf ninvynoyr ohvyg-va rqvgbef # # # /rqvgbe fubj &yg;ahz&tg; # Fubjf ohvyg-va rqvgbe ng &yg;ahz&tg;. &yg;ahz&tg; nf fubja va /rqvgbe yvfg # # # # # # # # # # # # # # # # Gbbyxvg Zrah&aofc;&aofc;&aofc;&aofc;Pbagrag&aofc;&aofc;&aofc;&aofc;Pybfr # # # # # Zrah Vgrz # Qrfpevcgvba # # # Ybnq Fpevcg # Fubjf svyr qvnybt naq ybnqf fpevcg vs bar. # # # Rqvg Fpevcgsvyr # Fubjf svyr qvnybt naq rqvgf fpevcg vs bar. # # # Ybnqnoyr Fpevcgf # Fubjf fhozrah jvgu qverpgbevrf gung pbagnva fpevcsvyrf. Frr Pbasvthengvba # # # Erybnq Fpevcg # Qvfcynlf fhozrah jvgu ybnqrq fpevcg anzrf naq erybnqf fpevcg vs bar vf pyvpxrq # # # Haybnq Fpevcg # Qvfcynlf fhozrah jvgu ybnqrq fpevcg anzrf naq haybnqf fpevcg vs bar vf pyvpxrq # # # Rqvg ybnqrq fpevcg # Qvfcynlf fhozrah jvgu ybnqrq fpevcg anzrf naq rqvgf fpevcg vs bar vf pyvpxrq # # # Pbasvthengvba # Frr Pbasvthengvba # # # Erfgneg wVEPvv # Erfgnegf wVEPvv. Frr nyfb Pbasvthengvba # # # # # # # # # # # # Pbasvthengvba&aofc;&aofc;&aofc;&aofc;Pbagrag&aofc;&aofc;&aofc;&aofc;Pybfr # # # # # Zrah Vgrz # Qrfpevcgvba # # # Fpevcg Rqvgbe # # Gur svefg vgrz fubjf cngu gb gur rqvgbe be &yg;ohvyg-va&tg; vs gur ohvyg-va rqvgbe vf hfrq. # Gur frpbaq vgrz yrgf lbh pubbfr n qvssrerag rqvgbe va n svyr qvnybt. # Gur guveq vgrz yrgf lbh rqvg gur pbzznaq ol unaq. # Gur sbhegu vgrz erfrgf gur rqvgbe onpx gb gur ohvyg-va rqvgbe. # # # # Erfgneg pbzznaq # # Gur svefg vgrz fubjf gu erfgneg pbzznaq be &yg;qrsnhyg&tg; vs gur qrsnhyg pbzznaq vf hfrq. # Gur frpbaq vgrz yrgf lbh pubbfr n cebtenz (fubhyq or wvepvv.rkr ba Jvaqbjf) va n svyr qvnybt. # Gur guveq vgrz yrgf lbh rqvg gur pbzznaq ol unaq. # Gur sbhegu vgrz erfrgf vg onpx gb gur qrsnhyg pbzznaq. # # # # Fpevcg Qverpgbevrf # Fubjf n qvnybt sbe rqvgvat naq fbegvat gur qverpgbevrf. Gurl ner hfrq va gur Ybnqnoyr Fpevcgf fhozrah. # # # Erybnq Gbbyxvg # Erybnqf Gbbyxvg fpevcg (Znvayl urer sbe qrohttvat) # # # # # # # # # # # # # # # Nobhg&aofc;&aofc;&aofc;&aofc;Pbagrag&aofc;&aofc;&aofc;&aofc;Pybfr # # # # # # Gbbyxvg Fpevcg 2005/10/19 # Nhgube: rjhys # Rznvy: rjhys@hyhynghf.bet # Ubzrcntr: jjj.hyhynghf.bet # # # # # # # # # # # # # # # # # # # GBBYXVG.URYC RAQ