1
0
mirror of https://github.com/fadden/6502bench.git synced 2025-09-16 21:24:54 +00:00

Minor changes to local variable tables

Split "edit local variable table" into "create" and "edit prior".
The motivation is to allow the user to make changes to the most
recently defined table without having to go search for it.  Having
table creation be an explicit action, rather than something that
just happens if you edit a table that isn't there, feels reasonable.

Show table offset in LV table edit dialog, so if you really want
to go find it there's a (clumsy) way to do so.

Increased the maximum width of a variable from 4 to 8.  (This is
entirely arbitrary.)
This commit is contained in:
Andy McFadden
2019-09-19 15:53:23 -07:00
parent 6bc491885a
commit 6df874c559
10 changed files with 89 additions and 21 deletions

View File

@@ -1641,19 +1641,52 @@ namespace SourceGen {
}
}
public bool CanCreateLocalVariableTable() {
int selIndex = mMainWin.CodeListView_GetFirstSelectedIndex();
// Only allow on code lines. This is somewhat arbitrary; data would work fine.
if (CodeLineList[selIndex].LineType != LineListGen.Line.Type.Code) {
return false;
}
int offset = CodeLineList[selIndex].FileOffset;
// Don't allow creation if a table already exists.
return !mProject.LvTables.ContainsKey(offset);
}
public void CreateLocalVariableTable() {
int selIndex = mMainWin.CodeListView_GetFirstSelectedIndex();
int offset = CodeLineList[selIndex].FileOffset;
Debug.Assert(!mProject.LvTables.ContainsKey(offset));
CreateOrEditLocalVariableTable(offset);
}
public bool CanEditLocalVariableTable() {
if (SelectionAnalysis.mNumItemsSelected != 1) {
return false;
}
EntityCounts counts = SelectionAnalysis.mEntityCounts;
// Single line of code, or a local variable table.
return SelectionAnalysis.mLineType == LineListGen.Line.Type.Code ||
SelectionAnalysis.mLineType == LineListGen.Line.Type.LocalVariableTable;
// Check to see if the offset of the first-defined table is less than or equal to
// the offset of the selected line. If so, we know there's a table, though we
// don't know which one.
int selIndex = mMainWin.CodeListView_GetFirstSelectedIndex();
int offset = CodeLineList[selIndex].FileOffset;
return mProject.LvTables.Count > 0 && mProject.LvTables.Keys[0] <= offset;
}
public void EditLocalVariableTable() {
int selIndex = mMainWin.CodeListView_GetFirstSelectedIndex();
int offset = CodeLineList[selIndex].FileOffset;
// Find the offset of the nearest table that's earlier in the file.
int bestOffset = -1;
foreach (KeyValuePair<int,LocalVariableTable> kvp in mProject.LvTables) {
if (kvp.Key > offset) {
break; // too far
}
bestOffset = kvp.Key;
}
Debug.Assert(bestOffset >= 0);
CreateOrEditLocalVariableTable(bestOffset);
}
private void CreateOrEditLocalVariableTable(int offset) {
// Get existing table, if any.
mProject.LvTables.TryGetValue(offset, out LocalVariableTable oldLvt);