Chapter 6. Code Gallery

Code reuse is an important part of many programmers’ lives. Most people understand the benefits of code reuse, but anyone who has had to search through hundreds of files for that “snippet that does exactly what you are trying to do” understands the need for some kind of organization or directory feature for code. Besides you just being able to find the code that you are looking for, unless the code is trivial, there is probably some code in a reused snippet that has to be modified every time you use it.

Zend Studio for Eclipse comes with a full-featured code gallery. It has two major types of galleries that should make development significantly easier and faster as the code gallery grows. The first type of gallery is the user (or local) gallery. This gallery is limited to use only by a single user on his or her installation of Zend Studio for Eclipse. The second type of gallery is the gallery maintained by Zend for Zend Studio for Eclipse code snippets. Zend Studio users may already be familiar with this.

User Code Gallery

The user galleries and Zend galleries are accessed in similar ways. There are just a few extra steps to connect to the nonlocal ones. Let’s start by looking at the simplest case first. To start with, you have to find the Code Gallery view. You can open it by selecting Window, Show View, Code Gallery or by using the fast view selector at the bottom left of your screen. Figure 6.1 shows the Code Gallery tree view as well as the icons used to interact with your galleries.

The Code Gallery view.

Figure 6.1. The Code Gallery view.

The Code Gallery view allows you to synchronize your gallery with a nonlocal repository; configure your gallery options (connections); and add, edit, or delete snippets. We look at the synchronization and configuration in the following sections. Right now, let’s start by creating a code snippet.

Click on the New Entry button in the Code Gallery view. This opens a new window that will hold information about the code snippet that you are adding. You must name the snippet, include the author information, and, of course, add the code snippet. You may also include a short description about what the code snippet does. Figure 6.2 shows the code snippet creation window.

Creating a simple code snippet.

Figure 6.2. Creating a simple code snippet.

After you have added a snippet to your gallery, you can search through the available snippets by expanding the tree on the left column of the Code Gallery view, or you can narrow down the results by typing the first few letters of the snippet name. Add the snippet to your code by clicking on the Insert button. This adds the selected snippet at the position of your cursor in a file. If you have no files open, the snippet is not added anywhere.

Snippets in the user gallery can be edited or deleted. Use the icons at the top of the gallery window, or right-click on a snippet and select Edit or Delete.

We mentioned earlier that you could suggest that your code snippets should be added to the Zend gallery. You can do this by choosing the Suggest option on a particular snippet. All you need is a free Zend.com user account. You are asked which gallery you want to suggest the snippet to and what category it should be added to.

Zend Gallery

The Zend gallery is an online code gallery that is maintained by Zend. Code snippets in this gallery come from several sources. Some are added by programmers at Zend, but many are added by Zend Studio for Eclipse users. These snippets are added to the main Zend gallery by “suggestions.” You can suggest code by right-clicking on a code snippet and choosing the Suggest option.

You can connect to the Zend code gallery in the Code Gallery view. A Zend.com user account is all you need to connect to the gallery and browse useful code snippets. Besides the user Zend galleries, you can connect to other remote galleries by adding a new gallery by URL in the Preferences window. See Figure 6.3 for a better look at adding a new code gallery.

Adding a code gallery by URL.

Figure 6.3. Adding a code gallery by URL.

Summary

The code gallery in Zend Studio for Eclipse can be used in two main ways. Individual programmers can maintain a local repository of snippets for personal use. They can also connect and contribute to the Zend repository online, which can be accessed via Zend Studio for Eclipse.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.100.219