Basic-IDE: Out-comment a block of code

Creating a macro - Writing a Script - Using the API

Basic-IDE: Out-comment a block of code

Postby hansz » Thu Jun 05, 2008 3:09 pm

I'm quite familiar with VBA programming but totally new to StarBasic. Before starting to convert a rather large project from (Word) VBA to (Writer) StarBasic, I want to add some functionality to the Basic-IDE, well, the editor. E.g. I want a function to out-comment a selected block of code (each of the lines in the selection), and vice versa. Plus a function to indent a block of code and vice versa. And possibly some other things to enhance IDE functionality.

I've found examples to change the position of the object browser window, but that doesn't seem to help. How do I get and work with the text (code) frame of the IDE?

Starting with

Code: Select all   Expand viewCollapse view
oBasicIDE = CreateUNOService("com.sun.star.script.BasicIDE")



I've tried to inspect the oBasicIDE object, but OOo simply crashes, when I click the object in the Inspector frame.

Code: Select all   Expand viewCollapse view
XRay oBasicIDE
crashes OOo, too.

I've also tried a different approach, using the executeDispatch method. I can copy and paste code from and to the currently open code frame by doing:

Code: Select all   Expand viewCollapse view
oIDE_Frame = StarDesktop.CurrentComponent
oDispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
oDispatcher.executeDispatch(oIDE_Frame.getCurrentController().getframe(), ".uno:Copy", "", 0, Array())
'copies selected block of code to clipboard, cursor will be collapsed at end of selection after running the code
oDispatcher.executeDispatch(oIDE_Frame.getCurrentController().getframe(), ".uno:Paste", "", 0, Array())
'inserts content of clipboard at position of cursor, cursor will be collapsed at end of inserted content after running the code


But then I'm stuck again. I've tried some other ".uno:XXX" commands, but either they don't work in the IDE, or some PropertyValue is needed in Array(), which I don't know (where do I find the property values anyway?).

I'm using Win XP and OOo 2.4.0.

Thanks a lot,
Hans
Last edited by hansz on Tue Jun 10, 2008 1:26 pm, edited 2 times in total.
OOo 3.2.1 Win XP, Vista, 7
hansz
 
Posts: 12
Joined: Thu Jun 05, 2008 2:01 pm
Location: Bielefeld, Germany

Re: Basic-IDE: Out-comment a block of code

Postby ms777 » Thu Jun 05, 2008 11:12 pm

Hi,

I am quite convinced that what you target at is impossible. Do a
Code: Select all   Expand viewCollapse view
Sub Main
oEnum = Stardesktop.Components.createEnumeration
while oEnum.hasMoreElements
  oComp = oEnum.nextElement
  xray oComp
wend
End Sub
and investigate the BasicIDE component. There is no way to access the text, and the CurrentSelection is always zero.

How to out comment a piece of code ? This is what I found from some other posting:

Code: Select all   Expand viewCollapse view
if false then
...
endif


Good luck,

ms777
ms777
Volunteer
 
Posts: 138
Joined: Mon Oct 08, 2007 1:33 am

Re: Basic-IDE: Out-comment a block of code

Postby hansz » Fri Jun 06, 2008 3:35 pm

ms777 wrote:I am quite convinced that what you target at is impossible.
ms777


Thank you for answering, ms777! I've already invested a lot of time in investigating the possibility of extending the IDE. Knowing myself, I don't think I'll be able to give up now and accept the "If false then ... EndIf" trick as the only way to do it. On the other hand, this is quite handy to out-comment larger parts of code. I never thought of that before.
Hans
OOo 3.2.1 Win XP, Vista, 7
hansz
 
Posts: 12
Joined: Thu Jun 05, 2008 2:01 pm
Location: Bielefeld, Germany

Re: Basic-IDE: Out-comment a block of code

Postby ms777 » Sat Jun 07, 2008 5:06 pm

Hi,

I got a little success using the Accessibility interface. The following ode comments the selected lines in the IDE

Good luck,

ms777

Code: Select all   Expand viewCollapse view
Sub Main

oBasicComp = getBasicWindow

oContWin = oBasicComp.CurrentController.Frame.ComponentWindow

oACScrollPane1 = oContWin.AccessibleContext.getAccessiblechild(0)
oACPanel1 = oACScrollPane1.AccessibleContext.getAccessiblechild(2)
oACPanel2 = oACPanel1.AccessibleContext.getAccessibleChild(4)
oACScrollPane2 = oACPanel2.AccessibleContext.getAccessibleChild(0)
oACTextFrame = oACScrollPane2.AccessibleContext.getAccessibleChild(1)
oACPara1 = oACTextFrame.AccessibleContext.getAccessibleChild(8)

iMaxPara = oACTextFrame.AccessibleContext.AccessibleChildCount-1
aiParaSelected = getSelectedParas(oACTextFrame)

call commentParas(oACTextFrame, aiParaSelected)

End Sub

function getBasicWindow() as Any
oEnum = Stardesktop.Components.createEnumeration
while oEnum.hasMoreElements
  oComp = oEnum.nextElement
  if HasUnoInterfaces(oComp, "com.sun.star.lang.XServiceInfo") then 'to cath the Help Window
    if oComp.supportsService("com.sun.star.script.BasicIDE") then
      oBasicComp = oComp
    endif
  endif
wend
getBasicWindow = oBasicComp
end function

sub commentParas(oACTextFrame as Any, aiPara as Any)
for k=0 to UBound(aiPara)
  oACP = oACTextFrame.AccessibleContext.getAccessibleChild(aiPara(k))
  bResult = oACP.insertText( "'", 0)
next k
end sub

function getSelectedParas(oACTextFrame as Any) as Any
iMaxPara = oACTextFrame.AccessibleContext.AccessibleChildCount-1
Dim aiParaSelected(iMaxPara) as integer
iCount = 0
for k=0 to iMaxPara
  oACP = oACTextFrame.AccessibleContext.getAccessibleChild(k)
  if (oACP.SelectedText = oACP.Text) and (oACP.Text <> "") then
    aiParaSelected(iCount) = k
    iCount = iCount + 1
  endif
next k
if iCount >= 1 then
  redim preserve aiParaSelected(iCount-1)
  getSelectedParas = aiParaSelected
else
  getSelectedParas = Array()
endif
end function
ms777
Volunteer
 
Posts: 138
Joined: Mon Oct 08, 2007 1:33 am

Re: Basic-IDE: Out-comment a block of code

Postby hansz » Mon Jun 09, 2008 6:46 pm

That's just great. I had planned to dive into the Accessibility service, but it would have been very hard for me without your work. Now it's fun. I've found a way to scroll the code window and will do some more experimentation. But in principle the problem is solved. Thanks again!
Hans
OOo 3.2.1 Win XP, Vista, 7
hansz
 
Posts: 12
Joined: Thu Jun 05, 2008 2:01 pm
Location: Bielefeld, Germany

Re: [Solved] Basic-IDE: Out-comment a block of code

Postby ms777 » Mon Jun 09, 2008 7:09 pm

If you need some tools to analyze the Accessibility interface have a look at sub AnalyzeCreateSxc and others in http://www.oooforum.org/forum/viewtopic.phtml?t=22845

Good luck,

ms777
ms777
Volunteer
 
Posts: 138
Joined: Mon Oct 08, 2007 1:33 am

Re: [Solved] Basic-IDE: Out-comment a block of code

Postby hanya » Mon Jun 09, 2008 8:09 pm

Hi,

I have tried to extend the Basic IDE with the extension using accessibility API. This is my limit to extend it. Accessibility API can not process non-displayed text. So, you need to care the selection or something is there out side of the text frame.
This extension is very developing version but I can't extend anymore.

I failed to attache the extension file because the size of the extension over 240 KB (below 128 KB is allowed here). Here is a link to the file placed on my site.
http://hermione.s41.xrea.com/pukiwiki/i ... bbs2%2F101

How to use the extension:
Needs Py-UNO and OOo 2.4 or later. Install the package using Extension Manager.
1. Choose Tools - Extension Manager... entry
2. Expand "My Extensions" item
3. Push "Add" button and select ia-devxx.oxt file to install
4. Select "Input Assistant for the Basic IDE" after the package installation
5. Push "Options..." button there is right side of the Extension Manager dialog
6. Check in the "Enabled" checkbox placed on the "General" settings
7. Push "OK" to store the setting
8. Restart OpenOffice.org

Open Basic IDE after the installation process and see its status bar and right click the new item neighboring the degital signature and choose Help entry to read the help file.
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
hanya
Volunteer
 
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: Basic-IDE: Out-comment a block of code

Postby hansz » Tue Jun 10, 2008 1:25 pm

hanya

thank you for your response. I've downloaded and tried your Input Assistant. I like the overall concept very much, but most of the functionality has no effect on my system (Windows XP, OOo 2.4 (German)). Nearly all of the shortcut keys are not working, except for Alt+L, Alt+R, Alt+C, and Shift+Alt+C, and even these shortcuts are not listed in the shortcuts list for the Basic IDE (Tools - Customize - Keyboard). The replace function doesn't work either. There's no toolbar or menu, just the entry in the status bar. And I can't see the python code modules anywhere in the python macros list, so I can't even try to assign shortcuts by hand.

This is quite unfortunate, because the functionality would fullfill all my needs if working as described. I'm not planning to learn python scripting, but your tool is interesting enough for me to try to make it work on my system. Could you give some more information please?

BTW: I have removed the [solved] tag from the thread.
Hans
OOo 3.2.1 Win XP, Vista, 7
hansz
 
Posts: 12
Joined: Thu Jun 05, 2008 2:01 pm
Location: Bielefeld, Germany

Re: Basic-IDE: Out-comment a block of code

Postby hanya » Tue Jun 10, 2008 4:15 pm

hansz wrote:thank you for your response. I've downloaded and tried your Input Assistant. I like the overall concept very much, but most of the functionality has no effect on my system (Windows XP, OOo 2.4 (German)). Nearly all of the shortcut keys are not working, except for Alt+L, Alt+R, Alt+C, and Shift+Alt+C, and even these shortcuts are not listed in the shortcuts list for the Basic IDE (Tools - Customize - Keyboard).

"Ctrl + Keys" shortcut keys does not work on my Windows XP and OOo 2.4 too. But they work well on Linux environment (Momonga Linux and OOo 2.4). It is windows specific problem.
I'm sorry, I didn't know that customizable shotcut keys are not handled by the KeyHandler on the Windows environment.

Shortcut keys are catched by the XKeyHandler on the Basic IDE and they are processed through dispatch process by custom protocol handler and custom dispach service. So, shortcut keys are not shown in the key list of the Basic IDE. Most shortcut keys have their Command URL and they work well from the context menu of the Basic IDE (by the extension) and modified shortcut key settings.

The extension does not have any toolbar and menu but easy to make them by Commands.
Here is an example key settings "current.xml" in the attached file. And Command URLs are listed in the Commands.html file.
Open the Basic IDE and choose Tools - Customize menu entry. And then change tabl to Keyboard and push Load button to load current.xml file. (This current.xml file based on en-US version, so there are difference between your language one.)

The replace function doesn't work either.

Looks the same problem but it works on my WIndows environment. Input "th" and then push Ctrl + Space keys does not work ? Replacement and complation does not processed by the dispatch and they don't have any command url. I may change it.

P.S. Input assistant is a spaghetti extension !

Edited. Wrong file attached and I will attach correct one in the next post.
Last edited by hanya on Tue Jun 10, 2008 7:27 pm, edited 1 time in total.
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
hanya
Volunteer
 
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: Basic-IDE: Out-comment a block of code

Postby hansz » Tue Jun 10, 2008 6:52 pm

hanya wrote:Most shortcut keys have their Command URL and they work well from the context menu of the Basic IDE (by the extension) and modified shortcut key settings.


I'm sorry. I think I saw the command url's in one of the files, but didn't understand that there was a context menu in the first place. And I'm still struggling a bit with the whole OOo environment, which is rather new to me. I don't have time to test everything today, but the context menu is there (great!!) and the commands I tried worked well. So this is very promising already.

hanya wrote:Input "th" and then push Ctrl + Space keys does not work ?


Sorry again. Actually this works quite well, too, now that I know I have to hit Ctrl + Space. I didn't find this information in the help file. Maybe I missed it.

I'll try to make the best out of your other suggestions when I have more time. For now, I want to thank you very much for your patience. This is quite an encouragement for the start of my project.

I think you should publish your work in the extensions section here. A little more information in the help file on how it works may be welcome, though. Your tool seems well worth a careful testing by the community, a bit of re-design perhaps, and a small amount of additional work on usability. If I can help with something (e.g. german translation), I'll gladly do what I can.

And forget about "spaghetti code". A great tool is a great tool, even when the code doesn't look that great.

Thanks again,
Hans
OOo 3.2.1 Win XP, Vista, 7
hansz
 
Posts: 12
Joined: Thu Jun 05, 2008 2:01 pm
Location: Bielefeld, Germany

Re: Basic-IDE: Out-comment a block of code

Postby hanya » Tue Jun 10, 2008 8:23 pm

Here is the modified extension. Pushing Ctrl + Space processed through dispatch process.
http://hermione.s41.xrea.com/pukiwiki/i ... bbs2%2F101

Configuration file for shortcut keys. Do not unpack the zip file. Load it from Tools - Customize - Keyboard - "Load" button on the Basic IDE.
http://hermione.s41.xrea.com/pukiwiki/i ... bbs2%2F101

I changed a few shortcut keys because they can not assign to keys. But there are a few collision with Windows IME (maybe language specific problem, I use Japanese localized editon of Windows XP). And debug menu is removed.

I think you should publish your work in the extensions section here. A little more information in the help file on how it works may be welcome, though. Your tool seems well worth a careful testing by the community, a bit of re-design perhaps, and a small amount of additional work on usability. If I can help with something (e.g. german translation), I'll gladly do what I can.

The extension has some serious problem and they freezes or crashes OOo. And limitted functions based on the accessibility API may confuse users, you can treat only displayed text. (Cut, Copy and Paste on the context menu is processed by the IDE, so you don't need to take care about them to use.)
I think this extension can't see the light of day....
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
hanya
Volunteer
 
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 4 guests