File indexing completed on 2025-01-19 04:25:19
0001 Importer.loadQtBinding( "qt.core" ); 0002 Importer.loadQtBinding( "qt.gui" ); 0003 Importer.loadQtBinding( "qt.uitools" ); 0004 0005 function globalScopeEval( inputCode ) 0006 { 0007 try 0008 { 0009 result = eval( inputCode ) + " "; 0010 } 0011 catch( error ) 0012 { 0013 result = error + " "; 0014 } 0015 return result; 0016 } 0017 0018 function ScriptConsoleMainWindow() 0019 { 0020 QMainWindow.call( this, null ); 0021 0022 var mainWidget = new QWidget( this ); 0023 this.historyList = new QListWidget( mainWidget ); 0024 this.historyList.sizeHint = new QSize(900, 600); 0025 this.historyList.size = new QSize(900, 600); 0026 this.historyList.verticalScrollMode = QAbstractItemView.ScrollPerPixel; 0027 this.inputLine = new QTextEdit( mainWidget ); 0028 this.executeButton = new QPushButton( mainWidget ); 0029 this.commandArray = []; 0030 this.commandPos = -1; 0031 this.executeButton.clicked.connect( this, this.executeLine ); 0032 this.executeButton.text = "Execute Code"; 0033 this.windowTitle = "Amarok Script Console"; 0034 //the following line doesn't work for some reason: 0035 //executeButton.shortcut = new QKeySequence( "CTRL+Return" ); 0036 0037 var executeShortcut = new QShortcut( this ); 0038 executeShortcut.key = new QKeySequence( "CTRL+Return" ); 0039 executeShortcut.activated.connect( this, this.executeLine ); 0040 0041 var backHistoryShortcut = new QShortcut( this ); 0042 backHistoryShortcut.key = new QKeySequence( QKeySequence.StandardKey( QKeySequence.MoveToPreviousPage ) ); 0043 backHistoryShortcut.activated.connect( this, this.backHistory ); 0044 0045 var forwardHistoryShortcut = new QShortcut( this ); 0046 forwardHistoryShortcut.key = new QKeySequence( QKeySequence.StandardKey( QKeySequence.MoveToNextPage ) ); 0047 forwardHistoryShortcut.activated.connect( this, this.forwardHistory ); 0048 0049 var explanationItem = new QListWidgetItem("The Amarok Script Console allows you to easily execute JavaScript with access to all functions\nand methods you would have in an Amarok script.\nInformation on scripting for Amarok is available at:\nhttp://community.kde.org/Amarok/Development#Scripting\nExecute code: CTRL-Enter\nBack in code history: Page Up\nForward in code history: Page Down"); 0050 //explanationItem.setForeground( new QBrush( new QColor(Qt.darkGray) ) ); 0051 explanationItem.setFlags( !Qt.ItemIsSelectable ); 0052 this.historyList.addItem( explanationItem ); 0053 0054 var layout = new QGridLayout( mainWidget ); 0055 layout.addWidget( this.historyList, 0, 0, 1, 2 ); 0056 layout.addWidget( this.inputLine, 1, 0, 3, 2 ); 0057 layout.addWidget( this.executeButton, 4, 1 ); 0058 mainWidget.setLayout( layout ); 0059 this.setCentralWidget( mainWidget ); 0060 this.resize(750, 400); 0061 this.show(); 0062 } 0063 0064 ScriptConsoleMainWindow.prototype = new QMainWindow(); 0065 0066 ScriptConsoleMainWindow.prototype.executeLine = function() 0067 { 0068 command = new QListWidgetItem( this.inputLine.plainText ); 0069 this.commandArray.unshift( this.inputLine.plainText ); 0070 boldFont = new QFont(); 0071 boldFont.setBold( true ); 0072 command.setFont( boldFont ); 0073 result = globalScopeEval.call( null, this.inputLine.plainText ); 0074 resultsRow = new QListWidgetItem( result ); 0075 this.historyList.addItem( command ); 0076 this.historyList.addItem( resultsRow ); 0077 this.historyList.setCurrentItem( resultsRow ); 0078 this.inputLine.plainText = ""; 0079 this.commandPos = -1; 0080 } 0081 0082 ScriptConsoleMainWindow.prototype.backHistory = function() 0083 { 0084 if( this.commandArray.length > ( this.commandPos + 1 ) ) 0085 { 0086 this.commandPos++; 0087 } 0088 if( this.commandArray.length > 0 ) 0089 { 0090 this.inputLine.plainText = this.commandArray[ this.commandPos ]; 0091 } 0092 Amarok.debug( "back, " + this.commandArray[ this.commandPos ] ); 0093 } 0094 0095 ScriptConsoleMainWindow.prototype.forwardHistory = function() 0096 { 0097 if( this.commandArray.length > 0 ) 0098 { 0099 if( this.commandPos > 0 ) 0100 { 0101 this.commandPos--; 0102 } 0103 this.inputLine.plainText = this.commandArray[ this.commandPos ]; 0104 } 0105 Amarok.debug( "forward, " + this.commandPos + ": " + this.commandArray[ this.commandPos ] ); 0106 } 0107 0108 scriptConsoleMainWindow = new ScriptConsoleMainWindow();