📄 rcmainframe.java
字号:
* -symbol="name value"
* Note: Pathes (in fact any command line argument, which contains spaces) often need to be wrapped
* by quotes and since it does not harm if they are quoted even if unnecessary it is good
* practice to always quote them.
*/
private void parseCommandLine()
{
for (int i = 0; i < commandLine.length; i++)
{
String entry = commandLine[i].trim();
if (entry.startsWith("-include=") || entry.startsWith("-i="))
{
String[] parts = entry.split("=");
if (parts.length > 1)
includes.add(parts[1].trim());
}
else
if (entry.startsWith("-symbol=") || entry.startsWith("-s="))
{
String[] parts = entry.split("=");
if (parts.length > 1)
defines.add(parts[1].trim());
}
}
}
//------------------------------------------------------------------------------------------------
/**
* Creates a cursor for the given table and adds an inplace editor to allow editing the values.
*
* @param table The table for which the cursor is to be created.
* @return The new table cursor.
*/
private TableCursor setupTableCursor(final Table table)
{
final TableCursor cursor = new TableCursor(table, SWT.NONE);
final ControlEditor editor = new ControlEditor(cursor);
editor.grabHorizontal = true;
editor.grabVertical = true;
cursor.addSelectionListener(
new SelectionAdapter()
{
//------------------------------------------------------------------------------------------
/**
* When the user presses <enter> then show the inplace editor.
*/
public void widgetDefaultSelected(SelectionEvent e)
{
startInplaceEditing(editor, cursor);
}
//------------------------------------------------------------------------------------------
/**
* Select the according line in the table when the editor is over it.
*/
public void widgetSelected(SelectionEvent e)
{
table.setSelection(new TableItem[] {cursor.getRow()});
}
//------------------------------------------------------------------------------------------
}
);
cursor.addMouseListener(
new MouseListener()
{
long lastClick = 0;
//------------------------------------------------------------------------------------------
/**
* Start editing also for double clicks.
*/
public void mouseDoubleClick(MouseEvent e)
{
startInplaceEditing(editor, cursor);
}
//------------------------------------------------------------------------------------------
public void mouseDown(MouseEvent e)
{
long currentClick = System.currentTimeMillis();
if (currentClick - lastClick > 1000)
{
if (isEditing)
{
stopInplaceEditing(editor, cursor, true);
}
}
else
{
startInplaceEditing(editor, cursor);
}
lastClick = currentClick;
}
//------------------------------------------------------------------------------------------
public void mouseUp(MouseEvent e)
{
// Nothing to do.
}
//------------------------------------------------------------------------------------------
}
);
cursor.addKeyListener(
new KeyListener()
{
//------------------------------------------------------------------------------------------
public void keyPressed(KeyEvent e)
{
if (e.keyCode == SWT.F2)
{
startInplaceEditing(editor, cursor);
}
}
//------------------------------------------------------------------------------------------
public void keyReleased(KeyEvent e)
{
// Nothing to do.
}
//------------------------------------------------------------------------------------------
}
);
return cursor;
}
//------------------------------------------------------------------------------------------------
protected void addIncludePathButtonWidgetSelected(SelectionEvent evt)
{ DirectoryDialog folderPicker = new DirectoryDialog(shell, SWT.NULL);
String folder = folderPicker.open();
if (folder != null)
includePathList.add(folder);
}
//------------------------------------------------------------------------------------------------
protected void addSymbolButtonWidgetSelected(SelectionEvent evt)
{
TableItem item = new TableItem(symbolsTable, SWT.NULL);
item.setText(0, "New symbol"); item.setText(1, "New value");
symbolsTable.setFocus();
symbolsTable.setSelection(new TableItem[] {item});
cursor.setSelection(item, 0);
}
//------------------------------------------------------------------------------------------------
protected void includePathListWidgetSelected(SelectionEvent evt)
{
if (includePathList.getSelectionIndex() > -1)
removeIncludePathButton.setEnabled(true); }
//------------------------------------------------------------------------------------------------
protected void parseButtonWidgetSelected(SelectionEvent evt)
{
tokenCount = 0;
processedLines = 0;
preProcessedLines = 0;
log.removeAll();
processedIncludesList.removeAll();
errorCount = 0;
// Switch to second (parse result) page.
tabFolder1.setSelection(1);
tabFolder1.update();
logMessage("Parsing started.");
try
{
// Depending on the settings there is either only one file to parse or a list of them.
boolean createASTVisualization;
ArrayList fileList = new ArrayList();
if (singleFileRadioButton.getSelection())
{
fileList.add(rcFileNameEdit.getText());
createASTVisualization = true;
}
else
{
FileReader fileReader = new FileReader(txtFileNameEdit.getText());
BufferedReader reader = new BufferedReader(fileReader);
String line;
do
{
line = reader.readLine();
if (line == null)
break;
line = line.trim();
if (line.length() > 0)
fileList.add(line);
}
while (true);
createASTVisualization = false;
}
boolean breakOnError = true;
for (int i = 0; i < fileList.size(); i++)
if (!convertFile((String) fileList.get(i), true, createASTVisualization,
outputPathEdit.getText()) &&
breakOnError)
break;
}
catch(TokenStreamRecognitionException e)
{
log.add(e.toString());
e.recog.printStackTrace();
}
catch(Exception e)
{
log.add(e.toString());
if (e.getCause() != null)
e.getCause().printStackTrace();
else
e.printStackTrace();
}
logMessage("Parsing done.");
}
//------------------------------------------------------------------------------------------------
protected void removeIncludePathButtonWidgetSelected(SelectionEvent evt)
{
int index = includePathList.getSelectionIndex();
if (index > -1)
{
includePathList.remove(index);
if (includePathList.getItemCount() == 0)
removeIncludePathButton.setEnabled(false);
else
if (index < includePathList.getItemCount())
includePathList.setSelection(index);
else
includePathList.setSelection(index - 1);
} }
//------------------------------------------------------------------------------------------------
protected void removeSymbolButtonWidgetSelected(SelectionEvent evt)
{ int index = symbolsTable.getSelectionIndex();
if (index > -1)
{
symbolsTable.remove(index);
if (symbolsTable.getItemCount() == 0)
removeSymbolButton.setEnabled(false);
else
if (index < symbolsTable.getItemCount())
symbolsTable.setSelection(index);
else
symbolsTable.setSelection(index - 1);
}
}
//------------------------------------------------------------------------------------------------
protected void startInplaceEditing(final ControlEditor editor, final TableCursor cursor)
{
if (!isEditing)
{
isEditing = true;
TableItem row = cursor.getRow();
int column = cursor.getColumn();
final Text text = new Text(cursor, SWT.RIGHT);
text.setText(row.getText(column));
text.addKeyListener(
new KeyAdapter()
{
public void keyPressed(KeyEvent e)
{
// When the user presses <enter> the changes will be accepted.
switch (e.character)
{
case SWT.CR:
stopInplaceEditing(editor, cursor, true);
break;
case SWT.ESC:
stopInplaceEditing(editor, cursor, false);
break;
}
}
}
);
editor.setEditor(text);
text.selectAll();
text.setFocus();
}
}
//------------------------------------------------------------------------------------------------
protected void stopInplaceEditing(ControlEditor editor, TableCursor cursor, boolean accept)
{
if (isEditing)
{
isEditing = false;
Text text = (Text)editor.getEditor();
if (accept)
{
TableItem row = cursor.getRow();
row.setText(cursor.getColumn(), text.getText());
}
text.dispose();
}
}
//------------------------------------------------------------------------------------------------
protected void symbolsTableWidgetSelected(SelectionEvent evt)
{ if (symbolsTable.getSelectionIndex() > -1)
removeSymbolButton.setEnabled(true);
}
/** * Initializes the GUI. * Auto-generated code - any changes you make will disappear. */
public void initGUI(){ try { preInitGUI(); composite6 = new Composite(this,SWT.NULL); composite7 = new Composite(composite6,SWT.NULL); singleFileRadioButton = new Button(composite7,SWT.RADIO| SWT.LEFT); rcFileNameEdit = new Text(composite7,SWT.BORDER); browseRCFileButton = new Button(composite7,SWT.PUSH| SWT.CENTER); multipleFilesRadioButton = new Button(composite7,SWT.RADIO| SWT.LEFT); txtFileNameEdit = new Text(composite7,SWT.BORDER); browseIniFileButton = new Button(composite7,SWT.PUSH| SWT.CENTER); button1 = new Label(composite7,SWT.LEFT); outputPathEdit = new Text(composite7,SWT.BORDER); browseOutputFolderButton = new Button(composite7,SWT.PUSH| SWT.CENTER); parseButton = new Button(composite6,SWT.PUSH| SWT.CENTER); group1 = new Group(this,SWT.NULL); tabFolder1 = new TabFolder(group1,SWT.NULL); tabItem3 = new TabItem(tabFolder1,SWT.NULL); composite3 = new Composite(tabFolder1,SWT.NULL); label6 = new Label(composite3,SWT.NULL); includePathList = new List(composite3,SWT.H_SCROLL| SWT.V_SCROLL| SWT.BORDER); composite4 = new Composite(composite3,SWT.NULL); addIncludePathButton = new Button(composite4,SWT.PUSH| SWT.CENTER); removeIncludePathButton = new Button(composite4,SWT.PUSH| SWT.CENTER); label7 = new Label(composite3,SWT.NULL); symbolsTable = new Table(composite3,SWT.SINGLE| SWT.FULL_SELECTION| SWT.H_SCROLL| SWT.V_SCROLL| SWT.BORDER); tableColumn1 = new TableColumn(symbolsTable,SWT.NULL); tableColumn2 = new TableColumn(symbolsTable,SWT.NULL); composite5 = new Composite(composite3,SWT.NULL); addSymbolButton = new Button(composite5,SWT.PUSH| SWT.CENTER); removeSymbolButton = new Button(composite5,SWT.PUSH| SWT.CENTER); tabItem1 = new TabItem(tabFolder1,SWT.NULL); composite1 = new Composite(tabFolder1,SWT.NULL);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -