• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

7.7. Adding a New Button

In this example, you'll add a new button to the Terminal's interface that, when clicked, will clear the scrollback within the Terminal window. In order to make room for this new button, you'll compress the height of the scrollbar.

  1. Close the ContextMenu menu editor if it's open.

  2. Open the Terminal design window by double-clicking Term in the NIB window.

  3. Select the scrollbar on the right side of the Terminal design window. It appears to the right of the TermSubview. Small, light-blue resize handles appear around the scrollbar. The Info window's titlebar updates to NSScroller (Custom) Info.

  4. Hold down the Shift key and resize the scrollbar so that it shrinks vertically without changing horizontally. Resize the scrollbar to about half its former size.

  5. Click at the very top of the column (just below the titlebar) to select the split-view button.

  6. Choose Edit → Duplicate (-D) to create a new copy of this invisible button.

  7. Drag the invisible button copy down just below the original and watch until the guides (shown in Figure 7-23) appear. These guides ensure that the new button appears just below the original, aligned within the column.

    Figure 7-23. Watch for these guidebars to appear when you reposition the new button

  8. With the new button selected, open the Attributes pane in the Info window (-1).

  9. In the Attributes pane, check the Bordered box. An outline appears around the new button. Then change the button's behavior from Toggle to Momentary Light.

  10. Select the original button (click just above the new button). In the Attributes pane, check the Bordered box to match the style of the new button (Figure 7-24).

    Figure 7-24. Update both buttons to the Bordered style.

  11. In the Terminal design window, adjust the position of the two buttons and the height of the scrollbar until you're satisfied with the look of the window. You may wish to test the layout and functionality by saving your edits (-S) and opening new windows in the Terminal application.

  12. After making the edits in the Attributes pane, go back to Interface Builder and select the new button; you're about to add its functionality.

  13. Press and hold the Control key.

  14. With the Control key depressed, drag a connection line between the new button and the First Responder in the NIB window.

  15. When the box appears around the First Responder (Figure 7-25), release the mouse and then release the Control key. The Info window updates to show the list of connections made possible by the First Responder.

    Figure 7-25. Hold down the Control key to connect interface items to object instances.

  16. In the Info window's Connection pane, locate and double-click clearScrollback:. A gray dot appears next to the clearScrollback: action to indicate the button's connection.

  17. Open the Info window's Help pane (-6) and update the tool tip for the new button to "Click to clear the window's scrollback."

  18. Choose File → Save (-S) to save the changes.

  19. In the Terminal application, open a new window and confirm that the window both appears and works correctly, as seen in Figure 7-26. Clicking the split-view button should split the view. When you click on the clear button, the scrollback in the Terminal window will be erased, and the shell prompt will appear at the top of the window.



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint