Skip to content

Commit 9c07f7d

Browse files
authored
Merge pull request #834 from yc2lee/binary-readonly-files
Make *.ll files show up as readonly, binary files
2 parents 2d765bf + 57a4776 commit 9c07f7d

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/frontend/src/views/Project/Files/Display.tsx

+12-7
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,13 @@ class Display extends React.Component<DisplayProps & actionsInterface, DisplaySt
4949
cursorBlinking: "phase",
5050
cursorStyle: "line",
5151
parameterHints: true,
52-
readOnly: false,
5352
roundedSelection: true,
5453
scrollBeyondLastLine: false,
5554
scrollbar: {
5655
vertical: "visible",
5756
},
5857
selectOnLineNumbers: true,
59-
wrappingColumn: 0,
60-
fontFamily: this.props.settings.font + ", monospace",
61-
fontSize: this.props.settings.fontSize
58+
wrappingColumn: 0
6259
};
6360
this.setState(merge(this.state, {editorLastUpdated: this.props.settings.updated}));
6461
if (this.editor) {
@@ -150,23 +147,31 @@ class Display extends React.Component<DisplayProps & actionsInterface, DisplaySt
150147
return d.file === currentFile.name;
151148
});
152149
const lang = currentFile.extension() === "rkt" ? "racket" : "cpp";
150+
const isBinary = currentFile.extension() === "ll";
151+
const fontOptions = isBinary ?
152+
{ lineNumbers: "off", fontSize: 25, fontFamily: "Arial" } :
153+
{ lineNumbers: "on",
154+
fontSize: this.props.settings.fontSize,
155+
fontFamily: this.props.settings.font + ", monospace"};
156+
153157
return (<div className={styles.filePanel}>
154158
<div className = {styles.editorContainer + " " + this.props.className}
155159
ref = {(elem: HTMLElement | null) => { this.editorContainer = elem; }}>
156160
<MonacoEditor
157161
dirty = {!!currentFile.unwrittenContent}
158162
value = {(currentFile.contents === false ||
159163
currentFile.contents === undefined) ? "Unavailable in browser!" :
160-
currentFile.contents.contents}
164+
(isBinary ? "This is a binary file!" :
165+
currentFile.contents.contents)}
161166
theme = {this.props.settings.theme ? "vs" : "vs-dark"}
162167
language = {lang}
163168
diags = {currentQuestion.diags}
164169
onChange = {this.onChange.bind(this)}
165170
editorDidMount = {this.editorDidMount.bind(this)} requireConfig={loaderOptions}
166-
readOnly = {!currentFile.contents || currentFile.hasFlag(FlagMask.READONLY)}
171+
readOnly = {!currentFile.contents || isBinary || currentFile.hasFlag(FlagMask.READONLY)}
167172
options = {{lineNumbersMinChars: 2,
168173
minimap: {enabled: false},
169-
rulers: [0]}} />
174+
rulers: [0], ...fontOptions}} />
170175
<Draggable axis="x" handle="div" onDrag={this.handleDrag} onStop={this.stopDrag}>
171176
<div ref = {(elem: HTMLElement | null) => { this.resizeHandle = elem; }}
172177
className = {styles.resizeHandle} />

src/frontend/src/views/Project/Files/Editor.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ export default class MonacoEditor extends React.PureComponent<MonacoEditorProps,
5858
this.decorations = [];
5959
}
6060
public componentDidUpdate(previous: MonacoEditorProps) {
61+
if(this.editor) {
62+
this.editor.updateOptions({readOnly: this.props.readOnly, ...this.props.options});
63+
}
6164
// Update value if and only if it changed from previous prop OR
6265
// if dirty goes from true => false.
6366
if (this.props.value !== previous.value ||
@@ -204,12 +207,13 @@ export default class MonacoEditor extends React.PureComponent<MonacoEditorProps,
204207
monaco.languages.setMonarchTokensProvider("racket", Monarch.getRacketTokenizer());
205208

206209
const value = this.props.value !== null ? this.props.value : this.props.defaultValue;
207-
const { language, theme, options } = this.props;
210+
const { language, theme, options, readOnly } = this.props;
208211

209212
this.editor = monaco.editor.create(container, {
210213
value,
211214
language,
212215
theme,
216+
readOnly,
213217
...options,
214218
});
215219

0 commit comments

Comments
 (0)