OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012, the Dart project authors. | 2 * Copyright (c) 2012, the Dart project authors. |
3 * | 3 * |
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
6 * | 6 * |
7 * http://www.eclipse.org/legal/epl-v10.html | 7 * http://www.eclipse.org/legal/epl-v10.html |
8 * | 8 * |
9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
(...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 @Override | 744 @Override |
745 protected IStatus run(IProgressMonitor monitor) { | 745 protected IStatus run(IProgressMonitor monitor) { |
746 | 746 |
747 MessageConsole console = DartCore.getConsole(); | 747 MessageConsole console = DartCore.getConsole(); |
748 | 748 |
749 if (PRINT_TO_CONSOLE) { | 749 if (PRINT_TO_CONSOLE) { |
750 console.clear(); | 750 console.clear(); |
751 console.println("Formatting " + file.getName() + " ..."); | 751 console.println("Formatting " + file.getName() + " ..."); |
752 } | 752 } |
753 | 753 |
754 final IDocument document = getSourceViewer().getDocument(); | 754 final ISourceViewer sourceViewer = getSourceViewer(); |
| 755 final IDocument document = sourceViewer.getDocument(); |
755 | 756 |
756 try { | 757 try { |
757 | 758 |
758 final Point[] selection = new Point[1]; | 759 final Point initialSelection = new Point(-1, 0); |
759 Display.getDefault().syncExec(new Runnable() { | 760 Display.getDefault().syncExec(new Runnable() { |
760 @Override | 761 @Override |
761 public void run() { | 762 public void run() { |
762 selection[0] = getSourceViewer().getSelectedRange(); | 763 Point selection = sourceViewer.getSelectedRange(); |
| 764 initialSelection.x = selection.x; |
| 765 initialSelection.y = selection.y; |
763 } | 766 } |
764 }); | 767 }); |
765 | 768 |
766 if (DartFormatter.isDartStyleEnabled()) { | 769 if (DartFormatter.isDartStyleEnabled()) { |
767 DartFormatter.DartStyleRunner.formatFile(file, selection[0], monitor
); | 770 final Point newSelection = DartFormatter.DartStyleRunner.formatFile( |
| 771 file, |
| 772 initialSelection, |
| 773 monitor); |
| 774 Display.getDefault().syncExec(new Runnable() { |
| 775 @Override |
| 776 public void run() { |
| 777 sourceViewer.setSelectedRange(newSelection.x, newSelection.y); |
| 778 } |
| 779 }); |
768 return Status.OK_STATUS; | 780 return Status.OK_STATUS; |
769 } | 781 } |
770 | 782 |
771 final String unformattedSource = document.get(); | 783 final String unformattedSource = document.get(); |
772 | 784 |
773 final FormattedSource formatResult = DartFormatter.format( | 785 final FormattedSource formatResult = DartFormatter.format( |
774 unformattedSource, | 786 unformattedSource, |
775 selection[0], | 787 initialSelection, |
776 monitor); | 788 monitor); |
777 | 789 |
778 Display.getDefault().syncExec(new Runnable() { | 790 Display.getDefault().syncExec(new Runnable() { |
779 @Override | 791 @Override |
780 public void run() { | 792 public void run() { |
781 if (!formatResult.source.equals(unformattedSource)) { | 793 if (!formatResult.source.equals(unformattedSource)) { |
782 try { | 794 try { |
783 document.replace( | 795 document.replace( |
784 formatResult.changeOffset, | 796 formatResult.changeOffset, |
785 formatResult.changeLength, | 797 formatResult.changeLength, |
786 formatResult.changeReplacement); | 798 formatResult.changeReplacement); |
787 getSourceViewer().revealRange( | 799 sourceViewer.revealRange( |
788 formatResult.selectionOffset, | 800 formatResult.selectionOffset, |
789 formatResult.selectionLength); | 801 formatResult.selectionLength); |
790 getSourceViewer().setSelectedRange( | 802 sourceViewer.setSelectedRange( |
791 formatResult.selectionOffset, | 803 formatResult.selectionOffset, |
792 formatResult.selectionLength); | 804 formatResult.selectionLength); |
793 } catch (BadLocationException e) { | 805 } catch (BadLocationException e) { |
794 DartToolsPlugin.log(e); | 806 DartToolsPlugin.log(e); |
795 } | 807 } |
796 } | 808 } |
797 } | 809 } |
798 }); | 810 }); |
799 } catch (Exception e) { | 811 } catch (Exception e) { |
800 | 812 |
(...skipping 3403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4204 } | 4216 } |
4205 } | 4217 } |
4206 | 4218 |
4207 private void updateOutlinePageNew(Outline outline) { | 4219 private void updateOutlinePageNew(Outline outline) { |
4208 if (fOutlinePage_NEW != null && outline != null) { | 4220 if (fOutlinePage_NEW != null && outline != null) { |
4209 int offset = getSourceViewer().getSelectedRange().x; | 4221 int offset = getSourceViewer().getSelectedRange().x; |
4210 fOutlinePage_NEW.setInput(outline, offset); | 4222 fOutlinePage_NEW.setInput(outline, offset); |
4211 } | 4223 } |
4212 } | 4224 } |
4213 } | 4225 } |
OLD | NEW |