HOW TO: Write a code example

Request For Enhancement, User feedback candidates for wiki

HOW TO: Write a code example

Postby servoguy » Tue Feb 23, 2016 2:46 am

Hi open source people. Actually bothered to register and comment. Don't often do it. Here's some feed back. Its a good thing. I'm a bit oldschool (and old) I prefer a simple text editor to a word processor, unless I really need things to look fancy, then I cut and paste it into something else (writer these days), change the font and print it out. But lately I have been using writer more than I would have credited, and am - for the most part - enjoying it. Criticizms.. a bit top heavy, takes far too long to load, (although perhaps that's the portable apps thing ) too much automatic formatting, its just a pain... if I want bullet points I can press the button OK? How many bullet pointed lists does a person write in a week?... but every single time in the last 20 years that I use any wordprocessor, Im continuously wasting my time getting rid of unwanted formatting.... maybe there's an option somewhere.. There should be a three inch square glowing button smack in the middle of the GUI labeled "Turn if ALL off". You would get rave reviews .... really. Still, easier to keep a handle on than the MS program so good. PDF output is very high quality, and the output with regards to formatting is ALWAYS 100% WYSIWYG (same with printing), and the fonts look amazing. Massive points for that. :bravo: :super:

So last night I found myself putting cross-reference links from the table of contents to the relevent body text on a document I was converting, and I thought: "I know, I'll make a MACRO to speed things up". It is worth mentioning at this point that I have been a programmer for over 30 years, I'm semi-retired now, and have never had a lot to do with Javascript, but have no shortage of experience with C and ASM, so writing a WP macro to simulate half a dozen mouse clicks should be easy.

The MACRO I wanted seemed pretty straight forward, I was selecting the chapter and section numbering then pulling down Insert->Cross-Reference->Set Reference, copy and paste the numbering as the ref name and click insert. So I thought I should be able to highlight a number, say "3.1.4" then push a hotkey and have it set a reference at the current caret position that is named according to the highlighted text. Simple. As a little hello world task I set myself I chose rather poorly it would seem.

This was highlighted when I found this 510 page doc of examples from Andrew Pitonyak. They entirity of the text on page 259 reads " 7.29.4. Adding references I have no idea how to reference a heading, for example...". N.B. this is not a criticism of Mr. Pitonyak he has clearly done huge and vital works for the cause, nobody can do it all, and I heartily applaud his acknowlegment of the topic by including a heading and a short note on an otherwise blank page. It saved me a lot of time, and the other 509 pages speak for themselves. His excellent OOME has a fair bit of stuff on refs, however most of it appears to be with regards to spreadsheet cells. Certainly I can so far find no simple "here's how to set a reference point and give it a name" example.

I did find a couple of small code examples dotted around the web, nothing I could get to work straight out of the box. This one stood out: its the wiki page for reference marks last updated in May 2009 an is IMO the poster child for the worst concievable code exaple ever, albiet that it does contain some broadly descriptive comments. If the unnamed author was an elementary school swimming coach he would undoubtably line up the students and have them watch while he performed a quadrople backward sommersault with a triple twist off the high diving board and then announce that they all now knew how to swim.

Instead of a simple example of how to set a reference mark and another on how to link a reference to it. There is one example showing how to traverse a document, create paragraphs, create cursors, create tables, create text, store multiple reference points in an array and compare them to bookmarks, adjust the properties of reference text and insert it into tables, it is all mashed in together and there is no real explaination of how it all fits together, or - more importantly - how it comes apart. Although not my wheelhouse, I already have a decent understanding of OOP, dot notation and inheritance, but if anything the code seemed to be actively ofuscated. Why on earth would anyone use a wad of variables, functions and objects named: XTable, XTables, XText, XTableText, XTextTable, getTextTable, XTextCursor, XTableCursor, createTextCursor, XTableSupplier, XTextTableSupplier... and more besides, all packed together in one almost featureless chunk of example code? What about "MyRef = ...." I know its boring, but boring isnt confusing.

In all I spent about 6 hours trying to work out the convoluted HLL syntax to automate 5 or 6 mouse clicks, and gave up. I would quite honestly back myself to reverse engineer writer and patch the exe to do what I wanted in less time than that. The whole thing was off-putting, and I really wanted to like it. I know the project is almost entirely done by unpaid volunteers. That's why I've taken the time to write this. The suite is a fantastic achievement, which is only outdone by the feat of co-ordinating all the people involved to work towards a common goal. Despite having used writer and calc for occasional brief tasks for years, this was my first go at actually commiting some time towards exploring the whole thing and this was my User Experience. Im a fan, from what I can see they standard of work in the individual components is first rate, however the product as a whole feels as if it could stand having perhaps a couple less gadjets bolted onto it an a bit more self awareness. I think it would be happier and more effective that way. I hope somebody somewhere finds this helpful, thanks to all involved for all your hard work. Cheers :)
Posts: 1
Joined: Mon Feb 22, 2016 8:41 pm

Re: HOW TO: Write a code example

Postby RoryOF » Tue Feb 23, 2016 3:26 am

Apache OpenOffice 4.1.6 on Xubuntu 18.04.2 (mostly 64 bit version) and infrequently on Win2K/XP
User avatar
Posts: 28166
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: HOW TO: Write a code example

Postby John_Ha » Tue Feb 23, 2016 2:38 pm

servoguy wrote:There should be a three inch square glowing button smack in the middle of the GUI labeled "Turn if ALL off". You would get rave reviews .... really.

In Writer

1 Edit > Select All
2 Edit > Copy (or Edit > Cut)
3 Edit > Paste special > Unformatted.

In any application

1 Install Puretext
2 Edit > Select All
3 Edit > Copy (or Edit > Cut)
4 Windows_key+V

Please send rave review.
AOO 4.1.6, Windows 7 Home 64 bit

See the Writer Manual, the Writer FAQ, the Writer Tutorials and the Writer guide.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
Posts: 6355
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Return to User Experience (UX)

Who is online

Users browsing this forum: No registered users and 1 guest