Skip to content

Commit

Permalink
Add: Auto-renumber settings for BASIC
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgRottensteiner committed Apr 16, 2023
1 parent 583f690 commit db32919
Show file tree
Hide file tree
Showing 10 changed files with 609 additions and 33 deletions.
15 changes: 9 additions & 6 deletions C64Models/Parser/BasicFileParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2651,7 +2651,8 @@ public string EncodeToLabels()
lineLengthOffset = lineInfo.Value.Tokens[1].StartIndex;
}

if ( lineNumberReference.ContainsKey( lineInfo.Value.LineNumber ) )
if ( ( lineNumberReference.ContainsKey( lineInfo.Value.LineNumber ) )
&& ( lineInfo.Value.Tokens[0].TokenType != Token.Type.HARD_COMMENT ) )
{
// something is referencing this line
sb.AppendLine();
Expand Down Expand Up @@ -2817,12 +2818,14 @@ private int FindNextToken( List<Token> Tokens, int StartIndex )



public string DecodeFromLabels()
public string DecodeFromLabels( int StartLineNumber = 10, int LineStep = 10 )
{
StringBuilder sb = new StringBuilder();
GR.Collections.Map<string,int> labelToNumber = new GR.Collections.Map<string, int>();

int lineNumber = 10;
int startLineNumber = StartLineNumber;
int lineNumberStep = LineStep;
int lineNumber = startLineNumber;

// collect labels
foreach ( KeyValuePair<int,LineInfo> lineInfo in m_LineInfos )
Expand Down Expand Up @@ -2852,9 +2855,9 @@ public string DecodeFromLabels()
}
continue;
}
lineNumber += 10;
lineNumber += lineNumberStep;
}
lineNumber = 10;
lineNumber = startLineNumber;
foreach ( KeyValuePair<int, LineInfo> lineInfo in m_LineInfos )
{
if ( ( lineInfo.Value.Tokens.Count == 1 )
Expand Down Expand Up @@ -2993,7 +2996,7 @@ public string DecodeFromLabels()
}
}
sb.Append( "\r\n" );
lineNumber += 10;
lineNumber += lineNumberStep;
}
return sb.ToString();
}
Expand Down
3 changes: 3 additions & 0 deletions C64Studio/C64Studio.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@
<Compile Update="Dialogs\FormRenameSolution.cs">
<SubType>Form</SubType>
</Compile>
<Compile Update="Dialogs\FormRenumberBASICLabelMode.cs">
<SubType>Form</SubType>
</Compile>
<Compile Update="Dialogs\Preferences\PrefAssembler.cs">
<SubType>UserControl</SubType>
</Compile>
Expand Down
73 changes: 67 additions & 6 deletions C64Studio/Controls/MenuButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace RetroDevStudio.Controls
{
Expand All @@ -18,22 +19,64 @@ public ContextMenuStrip Menu



[DefaultValue( true )]
public bool ShowDropDownArrow { get; set; }

[DefaultValue( false )]
public bool ShowSplitBar { get; set; }

[DefaultValue( false )]
public bool Checked { get; set; }



public event EventHandler CheckedChanged;



protected override void OnMouseDown( MouseEventArgs mevent )
{
base.OnMouseDown( mevent );

bool hitMenu = false;
int lineX = ClientRectangle.Width - 18;
int menuShowX = 0;

if ( ShowSplitBar )
{
if ( mevent.X >= lineX )
{
hitMenu = true;
menuShowX = lineX;
}
}
else
{
hitMenu = true;
}



if ( ( Menu != null )
&& ( hitMenu )
&& ( mevent.Button == MouseButtons.Left ) )
{
System.Drawing.Point ptMenu = new Point( 0, Height );

System.Drawing.Point ptMenu = new Point( menuShowX, Height );

if ( ptMenu.Y + Menu.Height >= Screen.FromControl( this ).WorkingArea.Height )
{
ptMenu = PointToScreen( new Point( 0, -Menu.Height ) );
ptMenu = PointToScreen( new Point( menuShowX, -Menu.Height ) );
}
Menu.Show( this, ptMenu );
}
else
{
if ( CheckedChanged != null )
{
CheckedChanged( this, new EventArgs() );
}
OnClick( new EventArgs() );
}
}


Expand All @@ -45,9 +88,27 @@ protected override void OnPaint( PaintEventArgs pevent )
int arrowX = ClientRectangle.Width - 14;
int arrowY = ClientRectangle.Height / 2 - 1;

Brush brush = Enabled ? SystemBrushes.ControlText : SystemBrushes.ButtonShadow;
Point[] arrows = new Point[] { new Point( arrowX, arrowY ), new Point( arrowX + 7, arrowY ), new Point( arrowX + 3, arrowY + 4 ) };
pevent.Graphics.FillPolygon( brush, arrows );
if ( ShowDropDownArrow )
{
Brush brush = Enabled ? SystemBrushes.ControlText : SystemBrushes.ButtonShadow;
Point[] arrows = new Point[] { new Point( arrowX, arrowY ), new Point( arrowX + 7, arrowY ), new Point( arrowX + 3, arrowY + 4 ) };
pevent.Graphics.FillPolygon( brush, arrows );
}

if ( ShowSplitBar )
{
// Draw a dashed separator on the left of the arrow
int lineX = ClientRectangle.Width - 18;
int lineYFrom = 4;
int lineYTo = ClientRectangle.Height - 5;
using ( var separatorPen = new Pen( Brushes.DarkGray ) )
{
pevent.Graphics.DrawLine( separatorPen, lineX, lineYFrom, lineX, lineYTo );
}
}
}



}
}
154 changes: 154 additions & 0 deletions C64Studio/Dialogs/FormRenumberBASICLabelMode.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit db32919

Please sign in to comment.