Skip to content

Commit ad7b73f

Browse files
Chains: open files in read-only.
1 parent 76cd70d commit ad7b73f

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

source/phasereditor/phasereditor.chains.ui/src/phasereditor/chains/ui/views/ChainsView.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2222
package phasereditor.chains.ui.views;
2323

24+
import java.io.IOException;
25+
import java.nio.file.Files;
2426
import java.nio.file.Path;
2527
import java.util.List;
2628

27-
import org.eclipse.core.filesystem.EFS;
28-
import org.eclipse.core.filesystem.IFileStore;
2929
import org.eclipse.core.runtime.CoreException;
3030
import org.eclipse.core.runtime.IProgressMonitor;
3131
import org.eclipse.core.runtime.IStatus;
@@ -72,7 +72,6 @@
7272
import org.eclipse.swt.widgets.TableColumn;
7373
import org.eclipse.swt.widgets.Text;
7474
import org.eclipse.ui.IWorkbenchPage;
75-
import org.eclipse.ui.ide.FileStoreEditorInput;
7675
import org.eclipse.ui.part.ViewPart;
7776
import org.eclipse.wb.swt.SWTResourceManager;
7877
import org.eclipse.wst.jsdt.internal.ui.javaeditor.CompilationUnitEditor;
@@ -91,10 +90,10 @@
9190
import phasereditor.ui.EditorSharedImages;
9291
import phasereditor.ui.IEditorSharedImages;
9392
import phasereditor.ui.WebkitBrowser;
93+
import phasereditor.ui.editors.StringEditorInput;
9494

9595
@SuppressWarnings("restriction")
9696
public class ChainsView extends ViewPart {
97-
9897
protected Text _queryText;
9998
private TableViewer _chainsViewer;
10099
protected ChainsModel _chainsModel;
@@ -171,6 +170,7 @@ public void update(ViewerCell cell) {
171170
}
172171

173172
class ExamplesLineLabelProvider extends StyledCellLabelProvider {
173+
174174
private Font _font;
175175
private Font _italic;
176176

@@ -418,12 +418,17 @@ private void openJSEditor(int linenum, int offset, Path filePath) {
418418

419419
String editorId = "org.eclipse.wst.jsdt.ui.CompilationUnitEditor";
420420

421-
IFileStore store = EFS.getStore(filePath.toUri());
422-
FileStoreEditorInput input = new FileStoreEditorInput(store);
421+
byte[] bytes = Files.readAllBytes(filePath);
423422

424423
IWorkbenchPage activePage = getViewSite().getWorkbenchWindow().getActivePage();
425424

425+
StringEditorInput input = new StringEditorInput(filePath.getFileName().toString(), new String(bytes));
426426
CompilationUnitEditor editor = (CompilationUnitEditor) activePage.openEditor(input, editorId);
427+
try {
428+
editor.updatedTitleImage(EditorSharedImages.getImage(IEditorSharedImages.IMG_JCU_OBJ));
429+
} catch (Exception e) {
430+
// ignore it
431+
}
427432
ISourceViewer viewer = editor.getViewer();
428433
StyledText textWidget = viewer.getTextWidget();
429434
textWidget.setEditable(false);
@@ -440,7 +445,7 @@ private void openJSEditor(int linenum, int offset, Path filePath) {
440445
e.printStackTrace();
441446
}
442447

443-
} catch (CoreException e) {
448+
} catch (CoreException | IOException e) {
444449
throw new RuntimeException(e);
445450
}
446451
}

source/phasereditor/phasereditor.ui/src/phasereditor/ui/editors/StringEditorInput.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@
3131
import org.eclipse.ui.IPersistableElement;
3232
import org.eclipse.ui.IStorageEditorInput;
3333

34+
@SuppressWarnings("synthetic-access")
3435
public class StringEditorInput implements IStorageEditorInput {
3536

3637
private final String _inputString;
3738
private String _title;
3839
private String _tooltip;
40+
private ImageDescriptor _imageDescriptor;
3941

4042
public StringEditorInput(String title, String inputString) {
4143
_title = title;
@@ -57,8 +59,11 @@ public boolean exists() {
5759

5860
@Override
5961
public ImageDescriptor getImageDescriptor() {
60-
return null;
62+
return _imageDescriptor;
63+
}
6164

65+
public void setImageDescriptor(ImageDescriptor imageDescriptor) {
66+
_imageDescriptor = imageDescriptor;
6267
}
6368

6469
@Override
@@ -90,7 +95,6 @@ public IStorage getStorage() throws CoreException {
9095

9196
return new IStorage() {
9297

93-
@SuppressWarnings("synthetic-access")
9498
@Override
9599
public InputStream getContents() throws CoreException {
96100
return new ByteArrayInputStream(_inputString.getBytes());
@@ -108,7 +112,7 @@ public String getName() {
108112

109113
@Override
110114
public boolean isReadOnly() {
111-
return false;
115+
return true;
112116
}
113117

114118
@SuppressWarnings("unchecked")

0 commit comments

Comments
 (0)