Lines 51-56
Link Here
|
51 |
import org.netbeans.api.project.SourceGroup; |
51 |
import org.netbeans.api.project.SourceGroup; |
52 |
import org.netbeans.api.project.Sources; |
52 |
import org.netbeans.api.project.Sources; |
53 |
import org.netbeans.editor.BaseDocument; |
53 |
import org.netbeans.editor.BaseDocument; |
|
|
54 |
import org.netbeans.modules.editor.indent.api.Reformat; |
54 |
import org.openide.LifecycleManager; |
55 |
import org.openide.LifecycleManager; |
55 |
import org.openide.awt.StatusDisplayer; |
56 |
import org.openide.awt.StatusDisplayer; |
56 |
import org.openide.cookies.EditorCookie; |
57 |
import org.openide.cookies.EditorCookie; |
Lines 182-208
Link Here
|
182 |
StyledDocument document = ec.openDocument(); |
183 |
StyledDocument document = ec.openDocument(); |
183 |
if (document instanceof BaseDocument) { |
184 |
if (document instanceof BaseDocument) { |
184 |
final BaseDocument doc = (BaseDocument) document; |
185 |
final BaseDocument doc = (BaseDocument) document; |
185 |
final org.netbeans.editor.Formatter f = doc.getFormatter(); |
186 |
final Reformat f = Reformat.get(doc); |
186 |
doc.runAtomic(new Runnable() { |
187 |
f.lock(); |
|
|
188 |
try { |
189 |
doc.runAtomic(new Runnable() { |
190 |
public void run() { |
191 |
try { |
192 |
f.reformat(0, doc.getLength()); |
193 |
count++; |
194 |
} catch (BadLocationException ex) { |
195 |
Exceptions.attachMessage(ex, "Failure while formatting " + FileUtil.getFileDisplayName(fo)); |
196 |
Exceptions.printStackTrace(ex); |
197 |
} |
187 |
|
198 |
|
188 |
public void run() { |
|
|
189 |
boolean locked = false; |
190 |
try { |
191 |
f.reformatLock(); |
192 |
locked = true; |
193 |
f.reformat(doc, 0, doc.getLength()); |
194 |
count++; |
195 |
} catch (BadLocationException ex) { |
196 |
Exceptions.attachMessage(ex, "Failure while formatting " + FileUtil.getFileDisplayName(fo)); |
197 |
Exceptions.printStackTrace(ex); |
198 |
} finally { |
199 |
if (locked) { |
200 |
f.reformatUnlock(); |
201 |
} |
202 |
} |
199 |
} |
203 |
|
200 |
}); |
204 |
} |
201 |
} finally { |
205 |
}); |
202 |
f.unlock(); |
|
|
203 |
} |
206 |
} |
204 |
} |
207 |
} catch (DataObjectNotFoundException ex) { |
205 |
} catch (DataObjectNotFoundException ex) { |
208 |
Exceptions.attachMessage(ex, "Failure while formatting " + FileUtil.getFileDisplayName(fo)); |
206 |
Exceptions.attachMessage(ex, "Failure while formatting " + FileUtil.getFileDisplayName(fo)); |