This post demonstrates how to create a button on the top panel of the GNOME 3.2 Shell which displays a different menu depending on whether the left or right mouse button is clicked.
|
|
||
|
In this post I delve deeper into the technologies behind the new GNOME Shell and provide sample code for a number of simple extensions which demonstrate how to customize and extend various components of the GNOME Shell user interface. This post shows you how to build the Mozilla TraceMonkey JavaScript shell on Fedora 14. A number of examples are also provided to show you how to load and execute JavaScript scripts using this JavaScript shell. This post shows you how to build and smoketest a JavaScript shell for Microsoft Windows Vista SUA using the SpiderMonkey 1.8 sources As you are probably aware JavaScript engines such as SpiderMonkey typically do not allow access to the local filesystem for reasons of security. To enable developers to test the scripts from a command line, js includes the load() function which enables you to load one or more JavaScript scripts into the SpiderMonkey engine. However this is not sufficient for our purposes as no means is provided to write to the filesystem. Looking more closely at the source code, I noticed support for File objects. This support is not enabled by default however. It is not sufficient to simply recompile SpiderMonkey with this option enabled; you must also download and build the Netscape Portable Runtime (NSPR) library. This library provides a platform-neutral API for system level and libc-like functions, and is used by a number of Mozilla projects and other third party software developers. The current release is 4.7.3 and you can download it here. There are some gotchas to building Spidermonkey with NSPR. First of all, you need to successfully build NSPR. The source code tarball for NSPR comes with the standard GNU autoconfigure tools. If you are on a 64-bit system, you need to execute configure with the -enable-64bit option; otherwise the build will quickly fail. You should then test the build by going to the test subdirectory, building the testsuite and executing it. You also need to modify SpiderMonkey’s Makefile.ref (I am assuming you are building SpiderMonkey 1.7 and not an earlier release) to include libnspr and the NSPR headers. Two compile time defines are needed. You can either define JS_HAS_FILE_OBJECT and JS_THREADSAFE in Makefile.ref or as command line arguments to make. After than you, should be able to successfully build SpiderMonkey with native File object support. Now that we have js build with support for File objects, what can we do with it. Well, I guess we should start with the expected Hello World script. js> File.output.writeln(“Hello World”); Hello World true js> File.output.writeln(“Hello, world”); “OK” Hello, world OK js> File.output.writeln(“Hello, world”); “” Hello, world js> Notice that true is outputted unless you append something else as shown above. Here is another short example which demonstrates how to list the properties of the instance File object for the current directory. js> dir = new File(‘.’); /home/fpm/js/. js> for ( i in dir ) print(i); length parent path name isDirectory isFile exists canRead canWrite canAppend canReplace isOpen type |
||
|
Copyright © 2005-2012 Finnbarr P. Murphy. All Rights Reserved. |
||