Skip to content

Commit

Permalink
Fix: Project would sometimes not save all configs, re-add missing con…
Browse files Browse the repository at this point in the history
…figs from elements on load
  • Loading branch information
GeorgRottensteiner committed Mar 1, 2025
1 parent ccae55a commit 04c29cd
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 38 deletions.
39 changes: 22 additions & 17 deletions C64Studio/Dialogs/FormFindReplace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -943,27 +943,32 @@ private bool FindNextNew( string SearchString,
}
docInfoToSearch = activeDocument.DocumentInfo;
edit = EditFromDocumentEx( activeDocument.DocumentInfo );
if ( edit == null )
{
LastFound.Clear();
return false;
}
if ( DirectlyFromSourceFile != null )
{
lastPosition = CharacterPosFromPosition( edit, edit.Selection.Start );
}
else if ( lastPosition != -1 )
if ( edit != null )
{
// virtualize pos
lastPosition = edit.PositionToVirtualPosition( lastPosition );
}
if ( DirectlyFromSourceFile != null )
{
lastPosition = CharacterPosFromPosition( edit, edit.Selection.Start );
}
else if ( lastPosition != -1 )
{
// virtualize pos
lastPosition = edit.PositionToVirtualPosition( lastPosition );
}

textFromElement = edit.Text;
if ( activeDocument.DocumentInfo.Type == ProjectElement.ElementType.BASIC_SOURCE )
textFromElement = edit.Text;
}
else
{
if ( activeDocument.DocumentInfo.BaseDoc != null )
if ( activeDocument.DocumentInfo.Type == ProjectElement.ElementType.BASIC_SOURCE )
{
textFromElement = ( (SourceBasicEx)activeDocument.DocumentInfo.BaseDoc ).GetContentForSearch();
if ( activeDocument.DocumentInfo.BaseDoc != null )
{
textFromElement = ( (SourceBasicEx)activeDocument.DocumentInfo.BaseDoc ).GetContentForSearch();
}
}
else
{
textFromElement = activeDocument.GetContent();
}
}

Expand Down
38 changes: 27 additions & 11 deletions C64Studio/Documents/Disassembler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using RetroDevStudio.Formats;
using FastColoredTextBoxNS;
using RetroDevStudio.Formats;
using RetroDevStudio.Parser;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -28,16 +29,6 @@ public partial class Disassembler : CompilableDocument



public override FastColoredTextBoxNS.FastColoredTextBox SourceControl
{
get
{
return editDisassembly;
}
}



public Disassembler( StudioCore Core )
{
this.Core = Core;
Expand Down Expand Up @@ -69,6 +60,31 @@ public Disassembler( StudioCore Core )



public override FastColoredTextBox SourceControl
{
get
{
if ( tabContent.SelectedIndex == 0 )
{
return editDisassembly;
}
return null;
}
}



public override string GetContent()
{
if ( tabContent.SelectedIndex == 0 )
{
return editDisassembly.Text;
}
return hexView.AsHex( false );
}



void editDisassembly_TextChanged( object sender, FastColoredTextBoxNS.TextChangedEventArgs e )
{
//clear previous highlighting
Expand Down
1 change: 1 addition & 0 deletions C64Studio/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ public MainForm( string[] args )

//DumpPanes( panelMain, "" );

panelMain_ActiveDocumentChanged( this, new EventArgs() );
ApplicationEvent += new ApplicationEventHandler( MainForm_ApplicationEvent );

RaiseApplicationEvent( new ApplicationEvent( Types.ApplicationEvent.Type.DEFAULT_PALETTE_CHANGED ) );
Expand Down
16 changes: 16 additions & 0 deletions C64Studio/Project/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ public bool Load( byte[] ProjectData, bool AutoCreateGUIItems )
while ( chunk.ReadFromStream( memIn ) )
{
GR.IO.MemoryReader memChunk = chunk.MemoryReader();

switch ( chunk.Type )
{
case FileChunkConstants.PROJECT:
Expand Down Expand Up @@ -481,6 +482,8 @@ public bool Load( byte[] ProjectData, bool AutoCreateGUIItems )

config.Load( memChunk );

Debug.Log( $"Config {config.Name} found" );

if ( string.IsNullOrEmpty( config.DebugStartAddressLabel ) )
{
config.DebugStartAddressLabel = origDebugStartAddress.ToString();
Expand Down Expand Up @@ -537,6 +540,19 @@ public bool Load( byte[] ProjectData, bool AutoCreateGUIItems )
}
foreach ( ProjectElement element in Elements )
{
// sometimes configs get missing in the project?
foreach ( var elementSetting in element.Settings )
{
if ( Settings.GetConfigurationByName( elementSetting.Key ) == null )
{
Debug.Log( $"Readd missing config entry: {elementSetting.Key}" );
var config = new ProjectConfig()
{
Name = elementSetting.Key
};
Settings.Configuration( config.Name, config );
}
}
if ( element.Settings.Count == 0 )
{
foreach ( var configName in Settings.GetConfigurationNames() )
Expand Down
8 changes: 2 additions & 6 deletions C64Studio/Searching.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,12 @@ internal string GetDocumentInfoText( DocumentInfo DocInfo )
PreviousSearchedFileContent = ( (SourceASMEx)DocInfo.BaseDoc ).editSource.Text;
return PreviousSearchedFileContent;
}
else if ( DocInfo.BaseDoc is SourceBasicEx )
else if ( ( DocInfo.BaseDoc is SourceBasicEx )
|| ( DocInfo.BaseDoc is Disassembler ) )
{
PreviousSearchedFile = elementPath;
return DocInfo.BaseDoc.GetContent();
}
else if ( DocInfo.BaseDoc is Disassembler )
{
PreviousSearchedFile = elementPath;
return ( (Disassembler)DocInfo.BaseDoc ).editDisassembly.Text;
}
return "";
}

Expand Down
36 changes: 32 additions & 4 deletions HexBox/HexBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2316,10 +2316,38 @@ public void PasteHex()
Invalidate();
}

/// <summary>
/// Copies the current selection in the hex box to the Clipboard in hex format.
/// </summary>
public void CopyHex()


public string AsHex( bool selectionOnly )
{
long offset = 0;
long length = _byteProvider.Length;
if ( selectionOnly )
{
offset = _bytePos;
length = _selectionLength;
}

// put bytes into buffer
byte[] buffer = new byte[length];
int id = -1;
for ( long i = offset; i < offset + length; i++ )
{
id++;

buffer[id] = _byteProvider.ReadByte( i );
}

// set string buffer clipbard data
return ConvertBytesToHex( buffer );
}



/// <summary>
/// Copies the current selection in the hex box to the Clipboard in hex format.
/// </summary>
public void CopyHex()
{
if (!CanCopy()) return;

Expand Down
Binary file modified Sample Projects/MacroTest/MacroTest.c64
Binary file not shown.

0 comments on commit 04c29cd

Please sign in to comment.