image ResEx Logo
ResExcellence www : Powered by Google
Cell Phone Themes Icons Mighty Mouse Cursors Software Reviews Widgets & Widgets

Articles
   3D
   Audio
   Custom Controls
   General RB
   Graphics
   Hacks
   Mac OS X
   Menus
   Novelty
   Printing
   REALbasic 2005
   REALbasic 2006
   Registration
   Resources
   Reviews
   Serial
   Speech
   Sockets
   XML
   Video
Resource Links
News
   Current News
   February 2006
   January 2006
   December 2005
   November 2005
   October 2005
   September 2005
   August 2005
   July 2005
   June 2005
   May 2005
   April 2005
   March 2005









REALbasic for Dummies
by Erick Tejkowski


Learning REALbasic through Applications
by Clayton E., Crooks II


REALbasic for Macintosh
by Michael Swaine


REALbasic Cross-Platform Application Development
by Mark S. Choate





Older files are in Stuffit 5 or greater format. Newer files are ".Zip". Download StuffIt Expander
Tell us about a bad link. Thank You!

Text Clippings Made Easy by Erick Tejkowsi
05-10-01

Printer Version




Of all the great technologies available to Mac users, perhaps the most overlooked is that of the Clipping file. Clipping files permit you to store data in a file that can be viewed from the Finder. Furthermore, they are especially nifty, thanks to drag-and-drop.

Text clippings are handy for quick storage of text data such as:

  • Internet bookmarks
  • Email addresses
  • Software registration codes
  • Code Snippets
  • Phone Numbers
  • ResEx hacks

Of course, clippings can hold other kinds of data, but for now we will limit the discussion to text.

Creating Text Clippings

To create a text clipping, open your favorite text editor (even Simple Text will work here). Type a few letters, select the text, and drag that text to the desktop. The text becomes its own miniature file. Double click the clipping file in the Finder and it opens to reveal the text in a Finder window. While the text clipping is open, you may also copy the text to the clipboard.

Resource Information

Text clippings usually consist of two or three resources. The important one here, though, is the 'TEXT' resource. As you probably guessed, this is where the text of the clipping resides.

So, what on Earth does this have to do with REALbasic? Armed with REALbasic and your knowledge of text clippings, you can create a miniature "database".

REALbasic makes it easy to work with resources. Text clippings are already very versatile, but sometimes it is a nuisance to constantly open the clipping to view its contents. This example shows you how to keep tabs on your text clippings and make them even more useful than ever.

Build the Interface

To create the interface for this project, fire up REALbasic and open the Window1 Window Editor. From the toolbar drag the following into the window:

  • Listbox
  • EditField
  • PushButton
The Listbox will display your library of text clippings, and the EditField will show the the contents of the Clipping currently selected in the Listbox. Finally, the PushButton will give you the chance to copy text to the clipboard from the EditField. Make certain that the MultiLine property of the EditField is checked. Your interface might look something like this:

interface.jpg (17k)

Add the Code

To make the interface do something, double click Window1 to open its Code Editor. In the Open Event of the window, add this code: dim n,i as integer
dim f as folderItem

// Get the FolderItem
// for the folder that contains
// the clippings.

f = GetFolderItem("clippings")
if f <> nil then
  //how many items are in this folder?
  n = f.count
  //now loop through the items in the
  //folder and look for text clippings with MacFileType = 'clpt'
  for i=1 to n
    //if this item a file (i.e. NOT a folder)
    if f.item(i).directory=FALSE then
    //if this item is a text clipping
       if f.item(i).MacType="clpt" then
        //then add it to listbox1
        listBox1.addrow f.item(i).name
       end if
    end if
  next
end if

This code first looks for a folder named "Clippings" in the same directory as your application. If you haven't yet, create this folder now. This folder will be your storage place for text clippings. Next, the code loops through the items in the "Clippings" folder, looking for clipping files. When it encounters one, the file's name is added to the Listbox.

Next, open the Code Editor to the Change Event of the Listbox and add this code:
//This code executes when you
// select an item in Listbox1

dim f as FolderItem
dim rf as ResourceFork

// Is there anything in the listbox yet?
if me.listindex>=0 then
  // Get the file with currently selected name
  f=GetFolderItem("clippings").Child(listBox1.text)
  if f<>nil then
    rf=f.OpenResourceFork
    //get the text from 'TEXT' resource #256
    //and put it in EditField1
    EditField1.text=rf.GetResource("TEXT",256)
    rf.close
  end if
else
  //nothing in the listbox, so display nothing in the EditField
  EditField1.text=""
end if

This code will fire each time a row is selected in the Listbox. When a row is selected, the code creates a FolderItem representing the particular Clipping file. This FolderItem's resource fork is then opened and the 'TEXT' resource is retrieved (resource # 256) and displayed in the Editfield. The code concludes by closing the resource fork.

Finally, add code to the PushButton's Action Event :
Dim c as Clipboard
//Make a new clipboard object
c=New Clipboard

//copy the text from editField1
//to the clipboard
c.text=EditField1.text
c.close

This code copies the text from the EditField to the Clipboard. Of course, you can also select the text manually and copy it using the traditional Edit->Copy menu. You gain this functionality for free with the EditField.

Test and Build

The last step is to test and build the project. Test it by selecting Debug->Run. When you are sure that everything works as expteced, select File->Build Application. Once you have finished building your application, add a bunch of text clippings to your "Clippings" folder and you gain instant access to the contents of each. The project is also compatible with Mac OS X, so you can create an Aqua version as well.

If you are having troubles getting the code to work, you can

Download the code and the finished product.




Cell Phone Themes Icons Mighty Mouse Cursors Software Reviews Widgets & Widgets

Maintained by the Staff of ResExcellence. This entire site ©1997-2006 ResExcellence
Privacy Statement? Sure we gotta Privacy Statement. [an error occurred while processing this directive]