diff options
Diffstat (limited to 'files/zh-cn/getting_started_with_xulrunner/index.html')
-rw-r--r-- | files/zh-cn/getting_started_with_xulrunner/index.html | 202 |
1 files changed, 0 insertions, 202 deletions
diff --git a/files/zh-cn/getting_started_with_xulrunner/index.html b/files/zh-cn/getting_started_with_xulrunner/index.html deleted file mode 100644 index 1686cb7422..0000000000 --- a/files/zh-cn/getting_started_with_xulrunner/index.html +++ /dev/null @@ -1,202 +0,0 @@ ---- -title: XULRunner入门 -slug: Getting_started_with_XULRunner -translation_of: Archive/Mozilla/XULRunner/Getting_started_with_XULRunner ---- -<p>{{ Next("Windows and menus in XULRunner") }}</p> -<p>这一节通过使用<a href="/en-US/docs/XULRunner" title="/en-US/docs/XULRunner">XULRunner</a>构建一个基本的桌面应用来探讨<a href="/en-US/docs/The_Mozilla_platform" title="/en-US/docs/The_Mozilla_platform">Mozilla平台</a>。已知的Firefox(“火狐”Web浏览器)、Thunderbird(“雷鸟”Email客户端)和其它多种类应用程序都是使用这个平台编写完成的,可以坚信一点Mozilla平台可以被用来构建基本的应用程序。另有一个名为<a href="/en-US/docs/Creating_XULRunner_Apps_with_the_Mozilla_Build_System" title="/en-US/docs/Creating_XULRunner_Apps_with_the_Mozilla_Build_System">Creating XULRunner Apps with the Mozilla Build System</a>的章节包含了更加完整的内容用于构建XULRunner应用程序。如果你需要修改XULRunner本身或是将XULRunner整合到外部二进制程序中,那么你需要阅读这个章节。</p> -<h2 id="Step_1:_Download_XULRunner" name="Step_1:_Download_XULRunner">步骤1:下载XULRunner</h2> -<p>你能够在MDC里的<a href="/en-US/docs/XULRunner" title="/en-US/docs/XULRunner">XULRunner</a>主页中找到下载连接。由于我们并不创建任何的二进制XPCOM组件,所以仅需要下载并安装XULRunner运行时包而不是<a href="/en-US/docs/Gecko_SDK" title="/en-US/docs/Gecko_SDK">SDK</a>。</p> -<p>针对WIndows版本下载得到的是一个ZIP文件而并不是真正的安装程序。作为一个开发者我更喜欢这种简单解压缩就可以完成安装的方式。我假设它不会挂接到我的Windows系统上而这是件好事。这同时也意味着XULRunner是“便携式”的,所以如果你将应用开发成一种“便携式”的形式,那么你将可以将程序放到闪存存储器中或在云端同步。</p> -<p>Mac版本的XULRunner被发布成tar.bz2格式的归档文件。你可以解压缩到任何你喜欢的位置,但在本文档中的多个位置都假设了你已经将解压缩得到的文件放置在了/Library/Frameworks目录中。</p> -<p>到从版本11.10开始在Ubuntu桌面系统及它的各种变体版本中(Xubuntu,Kubuntu),XULRunner已经不再被维护并且不存在于Ubuntu的软件仓库中了。因此不管你是想手动编译XULRunner或是从<a href="https://ftp.mozilla.org/pub/mozilla.org/xulrunner/releases/" title="https://ftp.mozilla.org/pub/mozilla.org/xulrunner/releases/">Mozilla's FT</a><a href="https://ftp.mozilla.org/pub/mozilla.org/xulrunner/releases/" title="https://ftp.mozilla.org/pub/mozilla.org/xulrunner/releases/">P</a><a href="https://ftp.mozilla.org/pub/mozilla.org/xulrunner/releases/" title="https://ftp.mozilla.org/pub/mozilla.org/xulrunner/releases/">服务器</a>上下载发布版本。一种方法就是在每次你想安装新版本时运行以下脚本:</p> -<div class="note"> - <code>FIREFOX_VERSION=`grep -Po "\d{2}\.\d+" /usr/lib/firefox/platform.ini`<br> - ARCH=`uname -p`<br> - XURL=https://ftp.mozilla.org/pub/mozilla.org/xulrunner/releases/$FIREFOX_VERSION/runtimes/xulrunner-$FIREFOX_VERSION.en-US.linux-$ARCH.tar.bz2<br> - cd /opt<br> - sudo sh -c "wget -O- $XURL | tar -xj"<br> - sudo ln -s /opt/xulrunner/xulrunner /usr/bin/xulrunner<br> - sudo ln -s /opt/xulrunner/xpcshell /usr/bin/xpcshell </code></div> -<p>你也应该保存此脚本以便使用。注意:如果你使用的Firefox是构建于Ubuntuzilla仓库的,请将<code>/usr/lib/firefox/platform.ini</code>替换<code>为</code><code>/opt/firefox/platform.ini。</code></p> -<h2 id="Step_2:__Install_XULRunner" name="Step_2:__Install_XULRunner">步骤2:安装XULRunner</h2> -<p>在Windows系统中将压缩文件解压缩到一个合理的位置。我将其解压缩到了一个新创建的目录中<code>C:\program files\xulrunner。</code></p> -<p>在Mac系统中将tar.bz2文件解压缩到名为<code>XUL.Framework</code>的目录中。将此目录拷贝到<code>/Library/Frameworks,或是其它你喜欢的位置。</code></p> -<p>在Linux系统中如果你使用的是预发布(Pre-release)的XULRunner的话,你仅需要解包归档文件即可。</p> -<div class="note"> - <p>Optionally, if you've downloaded the compressed archive of XULRunner and would like to install it on your system you can do so by running作为可选的步骤,如果你已经下载了XULRunner的压缩文档并想将其安装到你的系统中,你可以运行以下命令来做到这一点</p> - <p><code>xulrunner --register-global</code></p> - <p> 作为管理名以上命令会将XULRunner注册给本机上的所有用户。仅注册给当前用户可以运行以下命令</p> - <p><code>xulrunner --register-user</code></p> - <p>不管你是否执行了安装过程XULRunner都会正常工作。这纯粹是为了方便。</p> -</div> -<div class="note"> - <p><span style="color: rgb(93, 86, 54); line-height: 1.5em; font-size: 14px;">In all systems you should unzip the </span><a href="/en-US/docs/Mozilla/About_omni.ja_(formerly_omni.jar)" style="line-height: 1.5em; font-size: 14px;" title="/en-US/docs/Mozilla/About_omni.ja_(formerly_omni.jar)">omni.ja</a><span style="color: rgb(93, 86, 54); line-height: 1.5em; font-size: 14px;"> file into some example directory and take a look at all the awesome! First change the file extension to zip and then use your normal filesystem's decompression tool to open it up. The contents of omni.ja are available to XULRunner applications and are what make it possible to build amazing applications easily!</span></p> -</div> -<h2 id="Step_3:_Create_the_application_folder_structure" name="Step_3:_Create_the_application_folder_structure">步骤3:创建应用程序目录结构</h2> -<p>是时候了,我们做一个简单的没有什么功能的应用程序。如果你愿意你可以称它为“Hello World”。所有以下你看到的你都可以在MDC的<a href="/en-US/docs/XULRunner" title="/en-US/docs/XULRunner">XULRunner</a>文档中找到更细节的内容。</p> -<div class="note"> - <p><strong>Hint:</strong> Skip ahead and download the sample application, you can experiment with it while following this tutorial. You can download the sample application from <a href="https://github.com/matthewkastor/XULRunner-Examples" title="https://github.com/matthewkastor/XULRunner-Examples">https://github.com/matthewkastor/XULRunner-Examples</a>. Please continue reading to learn the "what", "why" and "how" parts of building a XULRunner application.</p> -</div> -<p>在Windows中我新创建了root目录在<code>c:\program files\myapp,但你可以</code>将其创建在任何你喜欢的地方,使用任意一种你喜欢的OS。Windows、Mac和Linux使用了相同的目录结构。这里列出了子目录的结构:</p> -<pre>+ myapp/ -| -+-+ chrome/ -| | -| +-+ content/ -| | | -| | +-- main.xul -| | | -| | +-- main.js -| | -| +-- chrome.manifest -| -+-+ defaults/ -| | -| +-+ preferences/ -| | -| +-- prefs.js -| -+-- application.ini -| -+-- chrome.manifest -</pre> -<p>注意在目录结构中有5个文件:<code>application.ini</code>、<code>chrome.manifest (2个)、</code> <code>prefs.js</code>和<code>main.xul。</code><code>/chrome/chrome.manifest文件是可选的,但可能对向下兼容是有用的。请看以下记述内容。</code></p> -<div class="note"> - <p>关于可安装bundle的目录结构的更详细内容请参考<a href="/zh-CN/docs/Structure_of_an_installable_bundle" title="/en-US/docs/Bundles">Structure of an installable bundle</a>。</p> -</div> -<div class="note"> - <strong>Note:</strong> In XULRunner 2.0, the chrome.manifest is now used to register XPCOM components in addition to its previous uses. Part of this change means the <code>/chrome/chrome.manifest</code> is no longer considered the "root" manifest. XULRunner will not check that folder location for a root-level <code>chrome.manifest</code>. You need to move your existing chrome.manifest to the application root folder, remembering to update the relative paths within the file. You could also just create a new application root-level manifest that includes the <code>/chrome/chrome.manifest</code>, which is what this tutorial will do.</div> -<h2 id="Step_4:_Set_up_application.ini" name="Step_4:_Set_up_application.ini">步骤4:设置<code> application.ini</code></h2> -<p><code><a href="/en-US/docs/XUL_Application_Packaging" title="/en-US/docs/XUL_Application_Packaging">application.ini</a> 文件为你的应用扮演着XULRunner入口点的角色。</code>它指定了你的应用打算如何使用XULRunner平台以及配置一些信息以告诉XULRunner如何运行你的程序。下面是我的文件内容:</p> -<pre>[App] -Vendor=XULTest -Name=myapp -Version=1.0 -BuildID=20100901 -ID=xulapp@xultest.org - -[Gecko] -MinVersion=1.8 -MaxVersion=200.* -</pre> -<div class="note"> - <strong>Note:</strong> <code>MinVersion</code> <code>和MaxVersion</code>字段指示了你的应用所兼容的Gecko版本的范围;确保你设置了它们而且你所使用的XULRunner的版本也是在这个范围之内,否则你的应用将不能工作。</div> -<div class="note"> - <strong>Note</strong>: 确保你的应用名称是小写的,并且长度大于3个字符。</div> -<h2 id="Step_5:_Set_up_the_chrome_manifest" name="Step_5:_Set_up_the_chrome_manifest">步骤5:设置chrome清单文件</h2> -<p>The <a href="/en-US/docs/Chrome_Registration" title="/en-US/docs/Chrome_Registration">chrome manifest</a> file is used by XULRunner to define specific URIs which in turn are used to locate application resources. This will become clearer when we see how the “chrome://” URI is used. Application chrome can be in a single or a few JAR files or uncompressed as folders and files. I am using the uncompressed method for now. Here is the <code>chrome/chrome.manifest</code>:</p> -<pre class="eval"> content myapp content/ -</pre> -<p>As mentioned in Step 3, the default location of the <code>chrome.manifest</code> has changed in XULRunner 2.0, so we also need a simple <code>chrome.manifest</code> in the <strong>application</strong> root which will include the the manifest in our <strong>chrome</strong> root. Here is the application root <code>chrome.manifest</code>:</p> -<pre>manifest chrome/chrome.manifest</pre> -<h2 id="Step_6:_Set_up_preferences" name="Step_6:_Set_up_preferences">步骤6:设置配置</h2> -<p>The <a href="/en-US/docs/Mozilla/Preferences/A_brief_guide_to_Mozilla_preferences" title="/en-US/docs/Mozilla/Preferences/A_brief_guide_to_Mozilla_preferences">prefs.js</a> file tells XULRunner the name of the XUL file to use as the main window. Here is mine:</p> -<pre class="eval">pref("toolkit.defaultChromeURI", "<span class="external">chrome://myapp/content/main.xul</span>"); - -/* debugging prefs, disable these before you deploy your application! */ -pref("browser.dom.window.dump.enabled", true); -pref("javascript.options.showInConsole", true); -pref("javascript.options.strict", true); -pref("nglayout.debug.disable_xul_cache", true); -pref("nglayout.debug.disable_xul_fastload", true); -</pre> -<p>XULRunner specific preferences include:</p> -<dl> - <dt> - <code><a href="/en-US/docs/toolkit.defaultChromeURI" title="/en-US/docs/toolkit.defaultChromeURI">toolkit.defaultChromeURI</a></code></dt> - <dd> - Specifies the default window to open when the application is launched.</dd> - <dt> - <code><a href="/en-US/docs/toolkit.defaultChromeFeatures" title="/en-US/docs/toolkit.defaultChromeFeatures">toolkit.defaultChromeFeatures</a></code></dt> - <dd> - Specifies the features passed to <code><a href="/en-US/docs/DOM:window.open" title="/en-US/docs/DOM:window.open">window.open()</a></code> when the main application window is opened.</dd> - <dt> - <code><a href="/en-US/docs/toolkit.singletonWindowType" title="/en-US/docs/toolkit.singletonWindowType">toolkit.singletonWindowType</a></code></dt> - <dd> - Allows configuring the application to allow only one instance at a time.</dd> -</dl> -<div class="note"> - <p>The toolkit preferences are described in further detail in <a href="/en-US/docs/XULRunner/Specifying_Startup_Chrome_Window" title="/en-US/docs/XULRunner/Specifying_Startup_Chrome_Window">XULRunner:Specifying Startup Chrome Window</a>.</p> - <p>The debugging preferences are discussed in <a href="/en-US/docs/Debugging_a_XULRunner_Application" title="/en-US/docs/Debugging_a_XULRunner_Application">Debugging a XULRunner Application</a></p> -</div> -<h2 id="Step_7:_Create_some_XUL" name="Step_7:_Create_some_XUL">步骤7:创建一些XUL</h2> -<p>Finally, we need to create a simple <a href="/en-US/docs/XUL/window" title="/en-US/docs/XUL/window">XUL window</a>, which is described in the file <code>main.xul</code>. Nothing fancy here, just the minimum we need to make a window. No menus or anything.</p> -<p>main.xul:</p> -<pre><?xml version="1.0"?> - -<?xml-stylesheet href="chrome://global/skin/" type="text/css"?> - -<window id="main" title="My App" width="300" height="300" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> - - <script type="application/javascript" src="chrome://myapp/content/main.js"/> - - <caption label="Hello World"/> - <separator/> - <button label="More >>" oncommand="showMore();"/> - <separator/> - <description id="more-text" hidden="true">This is a simple XULRunner application. XUL is simple to use and quite powerful and can even be used on mobile devices.</description> - -</window> -</pre> -<div class="note"> - <strong>Note:</strong> Make sure there is no extra whitespace at the beginning of the XML/XUL file</div> -<p>The application also has a JavaScript file. Most XUL applications will include some external JavaScript, so the sample application does too, just to show how to include it into the XUL file.</p> -<p>main.js:</p> -<pre>function showMore() { - document.getElementById("more-text").hidden = false; -} -</pre> -<div class="note"> - <p>For more information about XUL see: <a href="/en-US/docs/XUL" title="/en-US/docs/XUL">XUL</a>.</p> - <p>For information about mixing HTML elements into your XUL read <a href="/en-US/docs/XUL/Tutorial/Adding_HTML_Elements" title="/en-US/docs/XUL/Tutorial/Adding_HTML_Elements">Adding HTML Elements</a>.</p> -</div> -<h2 id="Step_8:_Run_the_application" name="Step_8:_Run_the_application">步骤8:运行应用程序</h2> -<p>The moment of truth. We need to get XULRunner to launch the bare-bones application.</p> -<h3 id="Windows">Windows</h3> -<p>From a Windows command prompt opened to the <code>myapp</code> folder, we should be able to execute this:</p> -<pre class="eval"> C:\path\to\xulrunner.exe application.ini -</pre> -<p>Of course, if you opted to install xulrunner then you could simply do</p> -<pre><span style="font-family: 'Courier New', 'Andale Mono', monospace; line-height: normal;">%ProgramFiles%\xulrunner.exe application.ini</span></pre> -<p><span style="font-size: 14px; line-height: 1.572;">or on 64 bit systems</span></p> -<pre><span style="font-family: 'Courier New', 'Andale Mono', monospace; line-height: normal;">%ProgramFiles(x86)%\xulrunner.exe application.ini</span></pre> -<div class="note"> - <p><span style="font-size: 14px; line-height: 1.572;"><strong>Note</strong>: you can also install your application when you're finished debugging it. See <a href="/en-US/docs/XUL_Application_Packaging" title="/en-US/docs/XUL_Application_Packaging">XUL Application Packaging</a> for details.</span></p> -</div> -<h3 id="Mac">Mac</h3> -<p>On the Mac, before you can run a XULRunner application with everything intact, you must install it using the <code>--install-app</code> xulrunner commandline flag. Installing the application creates an OS X application bundle:</p> -<pre class="eval"> /Library/Frameworks/XUL.framework/xulrunner-bin --install-app /<path>/<to>/myapp.zip -</pre> -<p>Once installed, you can run the application:</p> -<pre class="eval"> /Library/Frameworks/XUL.framework/xulrunner-bin "/Applications/Finkle/TestApp.app/Contents/Resources/application.ini" -</pre> -<p>You may run it without installing (but with the menu bar and dock icon missing) in OS X by typing:</p> -<pre>/Library/Frameworks/XUL.framework/xulrunner-bin "/<full path>/TestApp/application.ini" -</pre> -<div class="note"> - <p>Note: The full path is required or a "Error: couldn't parse application.ini."-message will be returned.</p> -</div> -<p>This might also be simplified using a very simple shell script (i call mine "run.sh"):</p> -<pre>#!/bin/sh -/Library/Frameworks/XUL.framework/xulrunner-bin `pwd`/application.ini -</pre> -<h3 id="Linux">Linux</h3> -<p>On Ubuntu, you can run the application from a terminal. First change into the <code>\myapp</code> folder, then start the application by:</p> -<pre class="eval"> xulrunner application.ini -</pre> -<p>You should now see a window that looks something like this. This particular screenshot is from Ubuntu 10.</p> -<p><img alt="myapp-screenshot.png" class="internal default" src="/@api/deki/files/4679/=myapp-screenshot.png"></p> -<h3 id="Alternative:_Use_Firefox3_-app_to_run_XUL_apps" name="Alternative:_Use_Firefox3_-app_to_run_XUL_apps">Alternative: 通过Firefox运行XUL应用</h3> -<p>With Firefox 3 and later, you can tell the Firefox executable to run a XUL application from the command line. The XUL application will run instead of the Firefox browser that normally starts. This is similar to starting a XUL app using XULRunner. See <a href="/en/XULRunner_tips#Using_Firefox_to_run_XULRunner_applications" title="en/XULRunner_tips#Using_Firefox_to_run_XULRunner_applications">Using Firefox to run XULRunner applications</a>. This does not work if Firefox itself was installed as a XUL app - you need to use the installed XULRunner directly.</p> -<h2 id="Further_Reading">Further Reading:</h2> -<p>There are many things you can do with XULRunner. Before you get too far into things you might want to read the <a href="/en-US/docs/XULRunner_tips" title="/en-US/docs/XULRunner_tips">XULRunner tips</a> article. Also, throughout this tutorial you've been introduced to various bits of the <a href="/en-US/docs/Toolkit_API" title="/en-US/docs/Toolkit_API">Toolkit API</a> and it may help you to get familiar with it. Once you've got an application that's ready for the world you'll love our article titled <a href="/en-US/docs/XULRunner/Deploying_XULRunner_1.8" title="/en-US/docs/XULRunner/Deploying_XULRunner_1.8">Deploying XULRunner</a>.</p> -<p>For now, click the "next" link to learn about windows and menus in XULRunner!</p> -<p>{{ Next("Windows and menus in XULRunner") }}</p> -<div class="originaldocinfo"> - <h2 id="Original_Document_Information" name="Original_Document_Information">Original Document Information</h2> - <ul> - <li>Author: Mark Finkle, October 2, 2006</li> - </ul> -</div> -<p>{{ languages( { "ja": "ja/Getting_started_with_XULRunner", "ko": "ko/Getting_started_with_XULRunner" } ) }}</p> |