OpenOffice.org OpenOffice - 3.3 Guía de inicio rápido Pagina 332

  • Descarga
  • Añadir a mis manuales
  • Imprimir
  • Pagina
    / 379
  • Tabla de contenidos
  • MARCADORES
  • Valorado. / 5. Basado en revisión del cliente
Vista de pagina 331
The IDE has a Run Basic icon in the toolbar that runs the first macro in the IDE.
Unless you change the first macro, it is the empty macro named Main. Modify Main
so that it reads as shown in Listing 6.
Listing 6: Modify Main to call CopyNumToCol1.
Sub Main
CopyNumToCol1
End Sub
Now, you can run CopyNumToCol1 by repeatedly clicking the Run Basic icon in the
toolbar of the IDE. This is very fast and easy, especially for temporary macros that
will be used a few times and then discarded.
Sometimes the macro recorder fails
Understanding the OpenOffice.org internals helps to understand how and why the
macro recorder frequently fails. The primary offender is related to the dispatch
framework and its relationship to the macro recorder.
The dispatch framework
The purpose of the dispatch framework is to provide a uniform access to components
(documents) for commands that usually correspond to menu items. I can use File >
Save from the menu, the shortcut keys Ctrl+S, or click on the Save toolbar icon. All
of these commands are translated into the same “dispatch command”, which is sent
to the current document.
The dispatch framework can also be used to send “commands” back to the UI (User
Interface). For example, after saving the document, the File Save command is
disabled. As soon as the document has been changed, the File Save command is
enabled.
If we see a dispatch command, it is text such as .uno:InsertObject or
.uno:GoToStartOfLine. The command is sent to the document’s frame, and the frame
passes on the command until an object is found that can handle the command.
How the macro recorder uses the dispatch framework
The macro recorder records the generated dispatches. The recorder is relatively
simple to implement and the same commands that are issued are recorded for later
use. The problem is that not all dispatched commands are complete. For example,
inserting an object generates the following code:
dispatcher.executeDispatch(document, ".uno:InsertObject", "", 0, Array())
It is not possible to specify what kind of object to create or insert. If an object is
inserted from a file, you cannot specify which file to insert.
I recorded a macro and used Tools > Options to open and modify configuration
items. The generated macro does not record any configuration changes; in fact, the
generated code is commented so it will not even be run.
rem dispatcher.executeDispatch(document,
".uno:OptionsTreeDialog", "", 0, Array())
If a dialog is opened, the command to open the dialog is likely to be generated. Any
work done inside the dialog is not usually recorded. Examples include macro
332 Getting Started with OpenOffice.org 3.3
Vista de pagina 331
1 2 ... 327 328 329 330 331 332 333 334 335 336 337 ... 378 379

Comentarios a estos manuales

Sin comentarios