1.1 --- a/formatmany/nbproject/project.xml Mon Aug 02 18:26:51 2010 -0400
1.2 +++ b/formatmany/nbproject/project.xml Wed Aug 04 15:57:41 2010 +0200
1.3 @@ -15,6 +15,15 @@
1.4 </run-dependency>
1.5 </dependency>
1.6 <dependency>
1.7 + <code-name-base>org.netbeans.modules.editor.indent</code-name-base>
1.8 + <build-prerequisite/>
1.9 + <compile-dependency/>
1.10 + <run-dependency>
1.11 + <release-version>2</release-version>
1.12 + <specification-version>1.20.0</specification-version>
1.13 + </run-dependency>
1.14 + </dependency>
1.15 + <dependency>
1.16 <code-name-base>org.netbeans.modules.editor.lib</code-name-base>
1.17 <build-prerequisite/>
1.18 <compile-dependency/>
2.1 --- a/formatmany/src/org/netbeans/modules/formatmany/FormatManyAction.java Mon Aug 02 18:26:51 2010 -0400
2.2 +++ b/formatmany/src/org/netbeans/modules/formatmany/FormatManyAction.java Wed Aug 04 15:57:41 2010 +0200
2.3 @@ -51,6 +51,7 @@
2.4 import org.netbeans.api.project.SourceGroup;
2.5 import org.netbeans.api.project.Sources;
2.6 import org.netbeans.editor.BaseDocument;
2.7 +import org.netbeans.modules.editor.indent.api.Reformat;
2.8 import org.openide.LifecycleManager;
2.9 import org.openide.awt.StatusDisplayer;
2.10 import org.openide.cookies.EditorCookie;
2.11 @@ -182,27 +183,24 @@
2.12 StyledDocument document = ec.openDocument();
2.13 if (document instanceof BaseDocument) {
2.14 final BaseDocument doc = (BaseDocument) document;
2.15 - final org.netbeans.editor.Formatter f = doc.getFormatter();
2.16 - doc.runAtomic(new Runnable() {
2.17 + final Reformat f = Reformat.get(doc);
2.18 + f.lock();
2.19 + try {
2.20 + doc.runAtomic(new Runnable() {
2.21 + public void run() {
2.22 + try {
2.23 + f.reformat(0, doc.getLength());
2.24 + count++;
2.25 + } catch (BadLocationException ex) {
2.26 + Exceptions.attachMessage(ex, "Failure while formatting " + FileUtil.getFileDisplayName(fo));
2.27 + Exceptions.printStackTrace(ex);
2.28 + }
2.29
2.30 - public void run() {
2.31 - boolean locked = false;
2.32 - try {
2.33 - f.reformatLock();
2.34 - locked = true;
2.35 - f.reformat(doc, 0, doc.getLength());
2.36 - count++;
2.37 - } catch (BadLocationException ex) {
2.38 - Exceptions.attachMessage(ex, "Failure while formatting " + FileUtil.getFileDisplayName(fo));
2.39 - Exceptions.printStackTrace(ex);
2.40 - } finally {
2.41 - if (locked) {
2.42 - f.reformatUnlock();
2.43 - }
2.44 }
2.45 -
2.46 - }
2.47 - });
2.48 + });
2.49 + } finally {
2.50 + f.unlock();
2.51 + }
2.52 }
2.53 } catch (DataObjectNotFoundException ex) {
2.54 Exceptions.attachMessage(ex, "Failure while formatting " + FileUtil.getFileDisplayName(fo));