Code Formatterby pitonyakSource Code fragments in C++, Java, or StarBasic can be color coded for a better appearance. StarBasic is formatted to like like the OOo IDE. Java colors mimic those in Eclipse. A block of code is assumed to be formatted based on the following paragraph styles: _OOoComputerCode, _OOoComputerCodeLastLine, _code, _code_first_line, _code_last_line, or _code_one_line. Numerous color code examples are shown in AndrewMacro.odt, along with a complete description of the add-in. License: opensource | Read license Source code: Browse source code Further product information: Product details
|
||
Comments
Adding configuration abilities
Rather than throw together a "dirty" solution for the style names, I have been working on a configuration system. I am trying to keep things simple for my first shot at this, with a schema to hold the configured values. So, you will be able to run a configuration dialog and then choose the paragraph style and the font. These values will be stored in a schema so that they will be remembered the next time that the macro is run.
oStyles(0).DisplayName
Please, use this to refer to the default style:
oStyles(0).DisplayNameCourier and Courier New fonts
There are two similar fonts used: Courier and Courier New. But OOo is slowing down when there is a font that is missing (especially on Linux). In my case "Courier" is missing in the list of fonts (Ubuntu), but I have Courier 10 Pitch and Courier New. When scrolling pages it is a bit slowing down as if there was a font that is missing and Writer trying to find a suitable replacement. Courier was automatically replaced by Courier 10 Pitch, however it was somehow "Italic" (with a smaller inclination than a true Italic) and at the same time it was just "Bold" according to all dialogs (?). Windows XP virtual machine shows the "Courier" font as if it were a Times New Roman. So I tried to change the "Courier" to "Courier 10 Pitch" or "Courier New" in the Styles module of this extension and then OOo scrolled the document fast and without small delays (and the font is not Italic anyhow). Please, take a look at this.
Version 2.1.0 is incomplete?
Version 2.1.0 is only 22 KB against 236 KB of the 2.0.0 version.
2.1.0 is complete
Bernard Marcelly's extension compiler is awesome, and I use it. To create the extension, you place your extension creation document in the directory with the files to be distributed. I accidentally included a few extra unused files in this build directory. If you have a copy of both, change the file extension to zip and then use your favorite zip program to take a look at the extra contained files.
When I realized my error, I decided to push 2.1.0 earlier than planned. Version 2.0.0 color codes entire paragraphs. Version 2.1.0 allows for color coding selected text, so you can select a statement embedded in regular text and color code it. I also added a few other minor items such as a "proper" add-on description in English, French, German, and Spanish; at least as well as my limited language abilities allow.
I am able and willing to provide the full creation documents and source to create the full extension, you need but ask! Also, if you find any problems or desire specific improvements, drop me a line...
Andrew Pitonyak
Locale.
Thank you. It works great, but supports only the English locale? To make it work I had to replace "Default" with the name of this style used in my locale. In French it is named "Standard", in Spanish "Predeterminado", in Russian it is called "Базовый" etc. All the instances of "Default" have to be replaced(?) Please, can you add something that automatically checks the locale and uses the correct style name for this locale?
I do not want it to recognize the default style
My usual usage is as follows:
[text paragraphs formatted with a text style]
[code formatted with a code paragraph style]
[code formatted with a code paragraph style]
[code formatted with a code paragraph style]
[code formatted with a code paragraph style]
[text paragraphs formatted with a text style]
Place the text cursor anywhere in the code paragraph style and tell the macro to format the code. The macro looks both before and after the cursor to find all of the code paragraph styles and then adds color to the text using character styles. For this to work, you must use specific paragraph styles. If the default paragraph style is set to be a "code" style, then the macro will attempt to colorize the regular text.
If you select the text and choose to only format the selected text, however, the paragraph style does not matter.
Does this make sense?
If you have locale specific names for code styles, however, I am more than happy to incorporate those names into the macro, but the default paragraph style is not a good choice I think.
Then what is this line?
This line:
oProps() = Array(CreateProperty("ParentStyle", "Default")
uses the style named "Default".
It can't create code styles because of this, because different languages use diferent names for default style. However, "Colorize Selected" works without the code styles, indeed.
Oops
OK, now this has long since been corrected. We also have the ability now to recognize XML as well as raw strings in the C++0x standard.