#!/usr/bin/env kjscmd
// Populates the sidebar listview
function setup_sidebar( builtins, special, qt, kde, all )
{
var qobjects = Factory.constructors().sort();
for ( var i=0; i < qobjects.length ; i++ ) {
all.insertItem( qobjects[i] );
if ( /^Q/.test(qobjects[i]) )
qt.insertItem( qobjects[i] );
else if ( /^K/.test(qobjects[i]) )
kde.insertItem( qobjects[i] );
else
special.insertItem( qobjects[i] );
}
qt.insertItem( 'Qt' );
builtins.insertItem( 'System' );
builtins.insertItem( 'StdIcons' );
builtins.insertItem( 'Factory' );
builtins.insertItem( 'StdDirs' );
builtins.insertItem( 'StdAction' );
}
//
// Main
//
// Create the UI
var mw = new KMainWindow(this);
var ac = mw.actionCollection();
var split = new QSplitter( mw );
mw.setCentralWidget( split );
side = new QToolBox( split, 'sidebar' );
view = new QTabWidget( split, 'mainview' );
// Load the view
jsview = Factory.createROPart( "text/html", view, "js" );
cppview = Factory.createROPart( "text/html", view, "cpp" );
js = view.child(4);
cpp = view.child(6);
view.addTab( js, '&Javascript' );
view.addTab( cpp, '&C++' );
view.set_class = function( clazz )
{
var nm;
clazz = clazz.replace( '^[^QK]*', '' );
if ( /^Q/.test(clazz) )
nm = 'http://doc.trolltech.com/3.2/' + clazz.toLowerCase() + '.html';
else if ( /^K/.test(clazz) )
nm = 'http://developer.kde.org/documentation/library/cvs-api/kdeui/html/class' + clazz + '.html';
cppview.openURL( nm );
// JS docs
jsview.openStream( 'text/html', 'file:///index.html' );
jsview.writeStream( '' );
jsview.writeStream( '
' );
jsview.writeStream( '' );
jsview.writeStream( '' );
jsview.writeStream( '' );
jsview.writeStream( '' + clazz + '
' );
try {
var obj = eval('new '+clazz+'(this)');
jsview.writeStream( dump(obj) );
}
catch ( err ) {
try {
var obj = eval(clazz);
jsview.writeStream( dump(obj) );
}
catch ( err2 ) {
jsview.writeStream( 'Error dumping object: ' + err + '
' + err2 + '' );
}
}
jsview.writeStream( '' );
jsview.writeStream( '' );
jsview.closeStream();
}
view.setup = function()
{
// JS docs
jsview.openStream( 'text/html', 'file:///index.html' );
jsview.writeStream( '' );
jsview.writeStream( '' );
jsview.writeStream( '' );
jsview.writeStream( '' );
jsview.writeStream( '' );
jsview.writeStream( 'Script Reference
' );
jsview.writeStream( '' );
jsview.writeStream( '' );
jsview.closeStream();
// C++ docs
cppview.openStream( 'text/html', 'file:///index.html' );
cppview.writeStream( '' );
cppview.writeStream( '' );
cppview.writeStream( '' );
cppview.writeStream( '' );
cppview.writeStream( '' );
cppview.writeStream( 'C++ Reference
' );
cppview.writeStream( '' );
cppview.writeStream( '' );
cppview.closeStream();
jsview.connect( jsview.child(0), 'openURLRequest(const KURL&,const KParts::URLArgs&)', 'openURL(const KURL&)' );
cppview.connect( cppview.child(0), 'openURLRequest(const KURL&,const KParts::URLArgs&)', 'openURL(const KURL&)' );
}
// Setup the sidebar
builtinside = new KListView( side, 'builtinside' );
builtinside.addColumn( 'Class' );
builtinside.resizeMode = 2; // LastColumn
builtinside.changed = function()
{
var item = this.selectedItem();
view.set_class( item.text(0) );
}
specialside = new KListView( side, 'specialsidebar' );
specialside.addColumn( 'Class' );
specialside.resizeMode = 2; // LastColumn
specialside.changed = function()
{
var item = this.selectedItem();
view.set_class( item.text(0) );
}
qtside = new KListView( side, 'qtsidebar' );
qtside.addColumn( 'Class' );
qtside.resizeMode = 2; // LastColumn
qtside.changed = function()
{
var item = this.selectedItem();
view.set_class( item.text(0) );
}
kdeside = new KListView( side, 'kdesidebar' );
kdeside.addColumn( 'Class' );
kdeside.resizeMode = 2; // LastColumn
kdeside.changed = function()
{
var item = this.selectedItem();
view.set_class( item.text(0) );
}
allside = new KListView( side, 'allsidebar' );
allside.addColumn( 'Class' );
allside.resizeMode = 2; // LastColumn
allside.changed = function()
{
var item = this.selectedItem();
view.set_class( item.text(0) );
}
side.addItem( builtinside, '&Builtins' );
side.addItem( specialside, 'K&JSEmbed' );
side.addItem( kdeside, '&KDE' );
side.addItem( qtside, '&Qt' );
side.addItem( allside, '&All' );
setup_sidebar( builtinside, specialside, qtside, kdeside, allside );
kdeside.connect( kdeside, 'selectionChanged()', kdeside, 'changed' );
qtside.connect( qtside, 'selectionChanged()', qtside, 'changed' );
specialside.connect( specialside, 'selectionChanged()', specialside, 'changed' );
builtinside.connect( builtinside, 'selectionChanged()', builtinside, 'changed' );
allside.connect( allside, 'selectionChanged()', allside, 'changed' );
//
// Activate XMLGUI and show the window
//
var quitAction = StdAction.quit( 0, 0, mw.actionCollection() );
mw.connect( quitAction, 'activated()', this, 'exit');
mw.createGUI( 'stdactionsui.rc' );
side.maximumWidth = 250;
mw.resize( 800, 550 );
mw.show();
//
// Connect together
//
view.setup();
application.exec();