| From | Sent On | Attachments |
|---|---|---|
| Duncan Foster | May 19, 2003 2:34 am |
| Subject: | [scripting-dev] Disable autocorrect/autoformat features | |
|---|---|---|
| From: | Duncan Foster (Dunc...@Sun.COM) | |
| Date: | May 19, 2003 2:34:23 am | |
| List: | org.openoffice.scripting.dev | |
Hi everyone,
I've had this script sitting on my computer for a while, and i thought it was about time I shared it with the rest of you! Rewriting it in StarBasic is left as an exercise for the reader :-)
Duncan
1. Application: OpenOffice.org 2. Author: Duncan Foster 3. Author's email: Dunc...@Sun.COM 4. Purpose of macro: Uses the Configuration API to change the entris in the OpenOffice.org registry to disable some of the autocorrect/autoformat features. 5. Language: BeanShell (needs the scripting framework). 6. Keywords: autocorrect, autoformat, configuration
/************************************************************************* * * $Revision: 1.1 $ * * last change: $Author: dfoster $ $Date: 2003/05/19 10:09:00 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses * * - GNU Lesser General Public License Version 2.1 * - Sun Industry Standards Source License Version 1.1 * * Sun Microsystems Inc., October, 2000 * * GNU Lesser General Public License Version 2.1 * ============================================= * Copyright 2000 by Sun Microsystems, Inc. * 901 San Antonio Road, Palo Alto, CA 94303, USA * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * * * Sun Industry Standards Source License Version 1.1 * ================================================= * The contents of this file are subject to the Sun Industry Standards * Source License Version 1.1 (the "License"); You may not use this file * except in compliance with the License. You may obtain a copy of the * License at http://www.openoffice.org/license.html. * * Software provided under this License is provided on an "AS IS" basis, * WITHOUT WARRUNTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, * WITHOUT LIMITATION, WARRUNTIES THAT THE SOFTWARE IS FREE OF DEFECTS, * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. * See the License for the specific provisions governing your rights and * obligations concerning the Software. * * The Initial Developer of the Original Code is: Sun Microsystems, Inc.. * * Copyright: 2000 by Sun Microsystems, Inc. * * All Rights Reserved. * * Contributor(s): _______________________________________ * * ************************************************************************/
import com.sun.star.uno.UnoRuntime; import com.sun.star.frame.XModel; import com.sun.star.beans.PropertyValue; import com.sun.star.beans.XPropertySet; import com.sun.star.container.XNameReplace; import com.sun.star.util.XChangesBatch; import com.sun.star.lang.XMultiComponentFactory; import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.uno.XComponentContext; import drafts.com.sun.star.script.framework.runtime.XScriptContext;
disable(nodePath, props) {
aPathArg = new PropertyValue();
aPathArg.Name = "nodepath";
aPathArg.Value = nodePath;
aModeArg = new PropertyValue();
aModeArg.Name = "lazywrite";
aModeArg.Value = new Boolean(false);
args = new Object[2];
args[0]=aPathArg;
args[1]=aModeArg;
oConfigUpdateAccess =
xConfigurationProviderMSF.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess",
args);
xNameReplace = (XNameReplace)
UnoRuntime.queryInterface(XNameReplace.class, oConfigUpdateAccess);
xChangesBatch = (XChangesBatch)
UnoRuntime.queryInterface(XChangesBatch.class, oConfigUpdateAccess);
xPropertySet = (XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class, oConfigUpdateAccess);
for(i=0;i<props.length;i++) {
currentVal = xPropertySet.getPropertyValue(props[i]);
System.out.println("Current val="+currentVal);
// to toggle: xNameReplace.replaceByName("Enabled",new
Boolean(!currentVal.booleanValue()));
xNameReplace.replaceByName(props[i],new Boolean(false));
xChangesBatch.commitChanges();
currentVal = xPropertySet.getPropertyValue(props[i]);
System.out.println("Current val="+currentVal);
}
}
// The context variable is of type XScriptContext and is available to
// all BeanShell scripts executed by the Script Framework
xComponentContext = (XComponentContext)
UnoRuntime.queryInterface(XComponentContext.class,
context.getComponentContext());
xMultiServiceFactory = (XMultiServiceFactory)
UnoRuntime.queryInterface(XMultiServiceFactory.class,
xComponentContext.getServiceManager());
xConfigurationProviderMSF = (XMultiServiceFactory)
UnoRuntime.queryInterface(XMultiServiceFactory.class,
xMultiServiceFactory.createInstance("com.sun.star.configuration.ConfigurationProvider"));
disable("org.openoffice.Office.Common/AutoCorrect", new String[]
{"UseReplacementTable", "TwoCapitalsAtStart", "CapitalAtStartSentence"} );
disable("org.openoffice.Office.Writer/AutoFunction/Format/Option", new String[]
{"UseReplacementTable", "TwoCapitalsAtStart", "CapitalAtStartSentence"} );
disable("org.openoffice.Office.Writer/AutoFunction/Completion", new String[]
{"Enable"} );
return 0;





