Added include paths preferences

master
Marco Maccaferri 2019-01-01 08:46:45 +01:00
rodzic 18c15fbc3e
commit 8c950c335f
3 zmienionych plików z 151 dodań i 45 usunięć

Wyświetl plik

@ -1854,11 +1854,6 @@ public class Application {
console.clear();
final List<File> includePaths = new ArrayList<File>();
if (tab.getFile() != null) {
includePaths.add(tab.getFile().getParentFile());
}
final StringReader reader = new StringReader(tab.getEditor().getText());
final String name = tab.getText();
@ -1871,20 +1866,32 @@ public class Application {
IProgressMonitor monitor = statusLine.getProgressMonitor();
monitor.beginTask("Compile", IProgressMonitor.UNKNOWN);
compile(reader, name, file, includePaths);
compile(reader, name, file);
monitor.done();
}
}).start();
}
Source compile(Reader reader, String name, File file, List<File> includePaths) {
Source compile(Reader reader, String name, File file) {
PrintStream out = new PrintStream(console.getOutputStream());
PrintStream err = new PrintStream(console.getErrorStream());
out.print("Compiling " + name + "...");
try {
final List<File> includePaths = new ArrayList<File>();
if (file != null) {
includePaths.add(file.getParentFile());
}
String[] includes = preferences.getIncludes();
if (includes != null) {
for (int i = 0; i < includes.length; i++) {
includePaths.add(new File(includes[i]));
}
}
SourceBuilder builder = new SourceBuilder(includePaths) {
@Override
@ -2015,11 +2022,6 @@ public class Application {
console.clear();
final List<File> includePaths = new ArrayList<File>();
if (tab.getFile() != null) {
includePaths.add(tab.getFile().getParentFile());
}
final StringReader reader = new StringReader(tab.getEditor().getText());
final String name = tab.getText();
@ -2035,7 +2037,7 @@ public class Application {
monitor.beginTask("Compile", IProgressMonitor.UNKNOWN);
try {
Source source = compile(reader, name, file, includePaths);
Source source = compile(reader, name, file);
if (source == null) {
return;
}
@ -2106,11 +2108,6 @@ public class Application {
console.clear();
final List<File> includePaths = new ArrayList<File>();
if (tab.getFile() != null) {
includePaths.add(tab.getFile().getParentFile());
}
final StringReader reader = new StringReader(tab.getEditor().getText());
final String name = tab.getText();
@ -2135,7 +2132,7 @@ public class Application {
baseName = baseName.substring(0, baseName.lastIndexOf('.'));
}
Source source = compile(reader, name, file, includePaths);
Source source = compile(reader, name, file);
if (source == null) {
return;
}
@ -2177,11 +2174,6 @@ public class Application {
console.clear();
final List<File> includePaths = new ArrayList<File>();
if (tab.getFile() != null) {
includePaths.add(tab.getFile().getParentFile());
}
final StringReader reader = new StringReader(tab.getEditor().getText());
final String name = tab.getText();
@ -2206,7 +2198,7 @@ public class Application {
baseName = baseName.substring(0, baseName.lastIndexOf('.'));
}
Source source = compile(reader, name, file, includePaths);
Source source = compile(reader, name, file);
if (source == null) {
return;
}
@ -2248,11 +2240,6 @@ public class Application {
console.clear();
final List<File> includePaths = new ArrayList<File>();
if (tab.getFile() != null) {
includePaths.add(tab.getFile().getParentFile());
}
final StringReader reader = new StringReader(tab.getEditor().getText());
final String name = tab.getText();
@ -2271,7 +2258,7 @@ public class Application {
monitor.beginTask("Compile", IProgressMonitor.UNKNOWN);
try {
Source source = compile(reader, name, file, includePaths);
Source source = compile(reader, name, file);
if (source == null) {
return;
}
@ -2616,11 +2603,6 @@ public class Application {
console.clear();
final List<File> includePaths = new ArrayList<File>();
if (tab.getFile() != null) {
includePaths.add(tab.getFile().getParentFile());
}
final StringReader reader = new StringReader(tab.getEditor().getText());
final String name = tab.getText();
@ -2634,7 +2616,7 @@ public class Application {
monitor.beginTask("Compile", IProgressMonitor.UNKNOWN);
try {
Source source = compile(reader, name, file, includePaths);
Source source = compile(reader, name, file);
if (source == null) {
return;
}
@ -2676,11 +2658,6 @@ public class Application {
console.clear();
final List<File> includePaths = new ArrayList<File>();
if (tab.getFile() != null) {
includePaths.add(tab.getFile().getParentFile());
}
final StringReader reader = new StringReader(tab.getEditor().getText());
final String name = tab.getText();
@ -2699,7 +2676,7 @@ public class Application {
baseName = baseName.substring(0, baseName.lastIndexOf('.'));
}
Source source = compile(reader, name, file, includePaths);
Source source = compile(reader, name, file);
if (source == null) {
return;
}

Wyświetl plik

@ -75,6 +75,8 @@ public class Preferences {
boolean useTabstops;
int tabWidth;
String[] includes;
boolean generateBinary;
boolean generateHex;
boolean generateListing;
@ -242,6 +244,14 @@ public class Preferences {
changeSupport.firePropertyChange(PROP_TABWIDTH, this.tabWidth, this.tabWidth = tabWidth);
}
public String[] getIncludes() {
return includes;
}
public void setIncludes(String[] includes) {
this.includes = includes;
}
public boolean isGenerateBinary() {
return generateBinary;
}

Wyświetl plik

@ -60,6 +60,11 @@ public class PreferencesDialog extends Dialog {
Combo labelCase;
Combo mnemonicCase;
List includes;
Button includesAdd;
Button includesRemove;
Button includesMoveUp;
Button includesMoveDown;
Button generateBinary;
Button generateHex;
Button generateListing;
@ -294,10 +299,116 @@ public class PreferencesDialog extends Dialog {
pages.add("Assembler");
Label label = new Label(composite, SWT.NONE);
Composite group = new Composite(composite, SWT.NONE);
layout = new GridLayout(2, false);
layout.marginWidth = layout.marginHeight = 0;
group.setLayout(layout);
group.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
Label label = new Label(group, SWT.NONE);
label.setText("Include paths");
label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
includes = new List(group, SWT.SINGLE | SWT.BORDER);
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
gridData.widthHint = convertWidthInCharsToPixels(60);
gridData.heightHint = includes.getItemHeight() * 5 + includes.getBorderWidth() * 2;
includes.setLayoutData(gridData);
includes.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
updateIncludesButtons();
}
});
Composite container = new Composite(group, SWT.NONE);
layout = new GridLayout(1, true);
layout.marginWidth = layout.marginHeight = 0;
container.setLayout(layout);
includesAdd = new Button(container, SWT.PUSH);
includesAdd.setImage(ImageRegistry.getImageFromResources("add.png"));
includesAdd.setToolTipText("Add");
includesAdd.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
DirectoryDialog dlg = new DirectoryDialog(getShell());
String s = dlg.open();
if (s != null) {
includes.add(s);
updateIncludesButtons();
}
}
});
includesRemove = new Button(container, SWT.PUSH);
includesRemove.setImage(ImageRegistry.getImageFromResources("delete.png"));
includesRemove.setToolTipText("Remove");
includesRemove.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
includes.remove(includes.getSelectionIndex());
updateIncludesButtons();
}
});
includesRemove.setEnabled(false);
includesMoveUp = new Button(container, SWT.PUSH);
includesMoveUp.setImage(ImageRegistry.getImageFromResources("arrow_up.png"));
includesMoveUp.setToolTipText("Up");
includesMoveUp.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int index = includes.getSelectionIndex();
ArrayList<String> items = new ArrayList<String>(Arrays.asList(includes.getItems()));
String s = items.get(index);
items.remove(index);
items.add(index - 1, s);
includes.setItems(items.toArray(new String[items.size()]));
includes.setSelection(index - 1);
includes.setFocus();
updateIncludesButtons();
}
});
includesMoveUp.setEnabled(false);
includesMoveDown = new Button(container, SWT.PUSH);
includesMoveDown.setImage(ImageRegistry.getImageFromResources("arrow_down.png"));
includesMoveDown.setToolTipText("Down");
includesMoveDown.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int index = includes.getSelectionIndex();
ArrayList<String> items = new ArrayList<String>(Arrays.asList(includes.getItems()));
String s = items.get(index);
items.add(index + 2, s);
items.remove(index);
includes.setItems(items.toArray(new String[items.size()]));
includes.setSelection(index + 1);
includes.setFocus();
updateIncludesButtons();
}
});
includesMoveDown.setEnabled(false);
String[] items = preferences.getIncludes();
if (items != null) {
includes.setItems(items);
}
label = new Label(composite, SWT.NONE);
label.setText("Output");
Composite group = new Composite(composite, SWT.NONE);
group = new Composite(composite, SWT.NONE);
layout = new GridLayout(3, false);
layout.marginWidth = layout.marginHeight = 0;
group.setLayout(layout);
@ -316,6 +427,13 @@ public class PreferencesDialog extends Dialog {
generateListing.setSelection(preferences.isGenerateListing());
}
void updateIncludesButtons() {
int index = includes.getSelectionIndex();
includesRemove.setEnabled(index != -1);
includesMoveUp.setEnabled(index != -1 && index > 0);
includesMoveDown.setEnabled(index != -1 && index < (includes.getItemCount() - 1));
}
void createEditorPage(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(2, false);
@ -449,6 +567,7 @@ public class PreferencesDialog extends Dialog {
preferences.setLabelCase(labelCase.getSelectionIndex());
preferences.setMnemonicCase(mnemonicCase.getSelectionIndex());
preferences.setIncludes(includes.getItems());
preferences.setGenerateBinary(generateBinary.getSelection());
preferences.setGenerateHex(generateHex.getSelection());
preferences.setGenerateListing(generateListing.getSelection());