| View previous topic :: View next topic |
| Author |
Message |
Bhikkhu Pesala Super User


Joined: 23 Aug 2005 Posts: 2324 Location: Seven Kings, London, UK
|
Posted: Sun May 07, 2006 1:52 am Post subject: Go To Page Number |
|
|
I know how to go to a page number in the navigator, though it goes to the wrong page number because I have some front matter with roman numerals but is there any command to go to a specified page number using the keyboard or by recording a macro? What about via the find dialogue box? This seems like a basic function for a word-processor, but I haven't found it yet.
Please vote for this issue to fix the navigator go to page number problem. _________________ Fonts * Opera * Oo Tips * FAQ * New Forum
Oo 2.3.1 * Win XP |
|
| Back to top |
|
 |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 7664 Location: Kentucky, USA
|
Posted: Sun May 07, 2006 2:57 pm Post subject: |
|
|
Here is a macro. Run the macro and tap the space bar. | Code: | Sub JumpToPage 'Goes to home position on page X. Tap Space Bar
'to get the view there.
oVC = thisComponent.CurrentController.getViewCursor
Do
sAns = InputBox("Enter the page below.","JUMP TO PAGE")
If sAns = "" then End
Loop Until isNumeric(sAns)
oVC.jumpToPage(Cint(sAns)) 'If beyond end, you get the last page.
End Sub |
|
|
| Back to top |
|
 |
Bhikkhu Pesala Super User


Joined: 23 Aug 2005 Posts: 2324 Location: Seven Kings, London, UK
|
Posted: Sun May 07, 2006 9:17 pm Post subject: |
|
|
Thanks. That helps a bit though the front matter stops it from working properly.
I have a front cover, then 13 pages of front matter starting on the right-hand page, so I have to mentally add 15 to go to the page number that I want. I have assigned the macro to F2 since I never use formulae.
I don't need to tap the spacebar. The page shows up immediately after clicking OK on the dialogue box or pressing Enter to dismiss it. _________________ Fonts * Opera * Oo Tips * FAQ * New Forum
Oo 2.3.1 * Win XP |
|
| Back to top |
|
 |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 7664 Location: Kentucky, USA
|
Posted: Mon May 08, 2006 12:33 pm Post subject: |
|
|
| Quote: | | I don't need to tap the spacebar. The page shows up immediately after clicking OK on the dialogue box or pressing Enter to dismiss it. | I'm glad to know this as I was running the macro directly from the Basic IDE thus I got no screen update. | Quote: | | I have a front cover, then 13 pages of front matter starting on the right-hand page, so I have to mentally add 15 to go to the page number that I want. | The new version below allows you to provide an "offset".
I have also added the following:
1) a way to jump from the current page plus or minus X pages.
2) current page information in the dialog.
3) a user specified default value in the dialog, and
4) several other user settings to specify how things work.
All of this has made error trapping more complex. I think I have everything
trapped but attempting to go beyond the last page. Here I think the default
behavior of going to the last page is OK. It has the benefit of allowing you to
insert some high number if you choose to turn off the last page information
and want to go to the last one.
Any other features you can think of before I put this in Code Snippets. I would also be interested to know if you or others find the instructions in the >>>User Variables<<< area less than clear.
Please PM me if you run into a error. I have not heavily tested this. | Code: | Global PriorPjcv as String
Sub JumpToPage 'Cursor to home position on page X.
'>>>>>>>>>>>>>>>>>>USER VARIABLES<<<<<<<<<<<<<<<<<
REM Get last page info? Causes brief screen flicker
'but it's probably worth the info.
GetLastP = true 'Should be either "true" or "false".
REM Show a default value in dialog?
ShowDef = true 'Should be either "true" or "false".
REM If "ShowDef = true" then the default value to
'show is defined below.
Def = PriorPjcv 'Can be a specific page, e.g, "1" with
'quotes, "LastP" with quotes for last page if
'"GetLastP = true" or "PriorPjcv" WITHOUT quotes (this is a
'Global variable so I have made its name distinctive).
'>>>>>>>>>>>>>>>>END USER VARIABLES<<<<<<<<<<<<<<<
Def = Lcase(Def)
If Not GetLastP And Def = "lastp" then
a$ = "You can not set the variable 'Def' to 'LastP' "
a$ = a$ & "when the variable 'GetLastP' is 'false'."
MsgBox(a$ & " Quitting.",,"VARIABLE ERROR!") : End
EndIf
oVC = thisComponent.CurrentController.getViewCursor
CurrentP = oVC.getPage
If GetLastP then
oVC.gotoEnd(false) : LastP = Str(oVC.getPage)
'LastP will carry a + sign which is not considered as numeric.
If Def = "lastp" then Def = Mid(LastP,2)
oVC.jumpToPage(CurrentP)
EndIf
If Not ShowDef then Def = ""
Info = "Current Page = " & CurrentP
If PriorPjcv <> "" then Info = Info & " Prior Page = " & PriorPjcv
If GetLastP then Info = Info & " Last Page = " & LastP
a$ = "Enter the page below. To adjust the page number "
a$ = a$ & "enter a space and the adjustment, e.g., '100"
a$ = a$ & " 15' for physical page 115. "
a$ = a$ & "If the first entry starts with '+' or '-' you will"
a$ = a$ & " go to the current page plus or minus your entries."
sAns = InputBox(a$,"JUMP TO PAGE - " & Info,Def)
If sAns = "" then End
b = split(sAns) : c = b(0) : d = 0
I = Instr("+-",Left(c,1))
If I > 0 then
PlusMinus = true
If I = 1 then c = Mid(c,2) 'Another + sign we need to get rid of.
EndIf
If ubound(b) > 0 then d = b(1)
If Not isNumeric(c) Or Not isNumeric(d) then JumpToPage()
c = Cint(c) : d = Cint(d)
If PlusMinus then
p = CurrentP + c + d
Else p = c + d
EndIf
If p < 1 then
MsgBox("There is no page less than 1.",,"ENTRY RESULT = " & p)
JumpToPage()
EndIf
oVC.jumpToPage(p) 'If beyond end, you get the last page.
PriorPjcv = CurrentP
End Sub |
|
|
| Back to top |
|
 |
Bhikkhu Pesala Super User


Joined: 23 Aug 2005 Posts: 2324 Location: Seven Kings, London, UK
|
Posted: Tue May 09, 2006 1:41 am Post subject: |
|
|
After some testing I modified the dialogue text to make it easier for me to understand.
I don't understand the User Variables section. The last page variable doesn't seem very important to me. If I wish to go to the last page I will just use Control End to go to the end, and anyway the total number of pages is shown in the status line. The macro doesn't need to duplicate that. If this code can be removed, I think the macro will be easier to understand.
I found one error. The macro fails when trying to go to a blank page inserted before the first page of a chapter. As my Chapter Title page style is set to right page only, if I use the macro to go to the blank even page preceding the first page of a chapter, the cursor stays where it is. This bug is not a problem if one knows about it.
The jump n pages feature may also be useful. I renamed the macro as "GoToPage" rather than "JumpToPage" as ovc.jumpToPage is a function name.
| Code: | Global PriorPjcv as String
Sub GoToPage
Def = PriorPjcv
Def = Lcase(Def)
oVC = thisComponent.CurrentController.getViewCursor
CurrentP = oVC.getPage
If Not ShowDef then Def = ""
Info = "Current Page = " & CurrentP
If PriorPjcv <> "" then Info = Info & " Prior Page = " & PriorPjcv
a$ = "Enter Page Number Below. "
a$ = a$ & "However, if Front Matter exists, add a space and an offset. "
a$ = a$ & "For example, 7 14 will go to Page 7 after Roman Page XIV. "
a$ = a$ & "To jump by n pages enter +n or -n where n is any number."
sAns = InputBox(a$,"GO TO PAGE " & Info,Def)
If sAns = "" then End
b = split(sAns) : c = b(0) : d = 0
I = Instr("+-",Left(c,1))
If I > 0 then
PlusMinus = true
If I = 1 then c = Mid(c,2) 'Another + sign we need to get rid of.
EndIf
If ubound(b) > 0 then d = b(1)
If Not isNumeric(c) Or Not isNumeric(d) then GoToPage()
c = Cint(c) : d = Cint(d)
If PlusMinus then
p = CurrentP + c + d
Else p = c + d
EndIf
If p < 1 then
MsgBox("There is no page less than 1.",,"Entry Result = " & p)
GoToPage()
EndIf
oVC.jumpToPage(p) 'If beyond end, you get the last page.
PriorPjcv = CurrentP
End Sub |
_________________ Fonts * Opera * Oo Tips * FAQ * New Forum
Oo 2.3.1 * Win XP |
|
| Back to top |
|
 |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 7664 Location: Kentucky, USA
|
Posted: Tue May 09, 2006 10:35 am Post subject: |
|
|
| Quote: | | I found one error. The macro fails when trying to go to a blank page inserted before the first page of a chapter. As my Chapter Title page style is set to right page only, if I use the macro to go to the blank even page preceding the first page of a chapter, the cursor stays where it is. |
Let me make sure I understand this. Say I have a Chapter paragraph style that is set the start any new chapter on a right page. On page one I create a title page and the next thing I do is start a chapter using my Chapter style so that OOo insert a blank page and my chapter is on page 3.
Is this the blank page that the macro fails on? |
|
| Back to top |
|
 |
Bhikkhu Pesala Super User


Joined: 23 Aug 2005 Posts: 2324 Location: Seven Kings, London, UK
|
Posted: Tue May 09, 2006 12:07 pm Post subject: |
|
|
Right. The macro fails if you type in "2" to go to page two, because that left page doesn't actually exist in the document, because the Front Matter starts on page 3 as Roman Page i. Likewise, if page 76 is blank, because a chapter starts on page 77, GoToPage "76 16" won't work. There are 14 pages of front matter, a cover, and a blank page. However, GoToPage "77 16" will work as expected. By not working, I mean the cursor just stays on the current page. _________________ Fonts * Opera * Oo Tips * FAQ * New Forum
Oo 2.3.1 * Win XP |
|
| Back to top |
|
 |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 7664 Location: Kentucky, USA
|
Posted: Wed May 10, 2006 10:35 am Post subject: |
|
|
| I find it disturbing that you would use the terms "error", "fails" and "bug" when the cursor stays where it is when you attempt to go to one of these phantom pages. If you can't get there manually and you can't get there from the Navigator where would you expect the cursor to go? |
|
| Back to top |
|
 |
Bhikkhu Pesala Super User


Joined: 23 Aug 2005 Posts: 2324 Location: Seven Kings, London, UK
|
Posted: Wed May 10, 2006 12:51 pm Post subject: |
|
|
If you click the page down scroll button on the cover page, and page 2 doesn't exist, where would you expect the cursor to go?
It goes to the top of page 3 or page i of the front matter.
I'm happy witth the results as they are. As I said, the fact that it doesn't work if the page doesn't exist is not a problem, as once one is aware of that, one just tries again after adding 1 to the page number.
The navigator scroll buttons also don't respond until a valid number is reached, though the next and previous page buttons on the Navigator work as expected. _________________ Fonts * Opera * Oo Tips * FAQ * New Forum
Oo 2.3.1 * Win XP |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|