@@ -82,19 +82,20 @@ public Layouter(int x, int y, int w, int h) : base(x, y, w, h, Main.BackgroundCo
8282 valueInput . Visible = false ;
8383 AddChild ( valueInput ) ;
8484
85- valueInputTypeButton = new Button ( 15 , 14 , "D" , Main . DecColor , typeButtonClicked , valueInput ) ;
85+ valueInputTypeButton = new Button ( 15 , 14 , "D" , Main . DecColor , inputTypeSwitchClicked , valueInput ) ;
8686 valueInputTypeButton . Font = Main . FontS ;
8787 valueInputTypeButton . Transform . X = 57 ;
8888 valueInput . AddChild ( valueInputTypeButton ) ;
8989
9090 // search inputs
9191 searchInput = new TextInput ( 10 , 10 , 56 , 14 ) ;
9292 searchInput . TextColor = Main . HexColor ;
93+ searchInput . OnChangeCallback = searchChanged ;
9394 searchInput . OnSubmitCallback = searchCommitted ;
9495 searchInput . Visible = false ;
9596 AddChild ( searchInput ) ;
9697
97- searchInputTypeButton = new Button ( 15 , 14 , "H" , Main . HexColor , typeButtonClicked , searchInput ) ;
98+ searchInputTypeButton = new Button ( 15 , 14 , "H" , Main . HexColor , inputTypeSwitchClicked , searchInput ) ;
9899 searchInputTypeButton . Font = Main . FontS ;
99100 searchInputTypeButton . Transform . X = 57 ;
100101 searchInput . AddChild ( searchInputTypeButton ) ;
@@ -107,7 +108,7 @@ public Layouter(int x, int y, int w, int h) : base(x, y, w, h, Main.BackgroundCo
107108 gotoInput . Visible = false ;
108109 AddChild ( gotoInput ) ;
109110
110- gotoInputTypeButton = new Button ( 15 , 14 , "D" , Main . DecColor , typeButtonClicked , gotoInput ) ;
111+ gotoInputTypeButton = new Button ( 15 , 14 , "D" , Main . DecColor , inputTypeSwitchClicked , gotoInput ) ;
111112 gotoInputTypeButton . Font = Main . FontS ;
112113 gotoInputTypeButton . Transform . X = 57 ;
113114 gotoInput . AddChild ( gotoInputTypeButton ) ;
@@ -486,25 +487,6 @@ public override void Resize(int w, int h)
486487 }
487488
488489 #region button handlers
489- private void typeButtonClicked ( Button btn )
490- {
491- TextInput input = btn . Tag as TextInput ;
492-
493- if ( btn . Text == "H" )
494- {
495- btn . Text = "D" ;
496- btn . TextColor = Main . DecColor ;
497- if ( input . Text != "" ) input . Text = int . Parse ( input . Text , NumberStyles . HexNumber , null ) . ToString ( ) ;
498- }
499- else
500- {
501- btn . Text = "H" ;
502- btn . TextColor = Main . HexColor ;
503- if ( input . Text != "" ) input . Text = int . Parse ( input . Text ) . ToString ( "X2" ) ;
504- }
505-
506- input . TextColor = btn . TextColor ;
507- }
508490
509491 private int getIntValue ( Button btn )
510492 {
@@ -526,7 +508,7 @@ private int getIntValue(Button btn)
526508 private void gotoInputChanged ( IInput obj )
527509 {
528510 int i = getIntValue ( gotoInputTypeButton ) ;
529- gotoInput . FocusFrameColor = ( i >= 0 && i < list . Bins . Count ) ? Main . DecColor : Color . Red ;
511+ gotoInput . FocusFrameColor = ( i >= 0 && i < list . Bins . Count ) ? Main . TrackColor : Color . Red ;
530512 }
531513
532514 private void gotoCommitted ( IInput input )
@@ -535,11 +517,55 @@ private void gotoCommitted(IInput input)
535517 if ( i >= 0 && i < list . Bins . Count ) list . ScrollTo ( i ) ;
536518 }
537519
538- private void searchCommitted ( IInput input )
520+ private byte [ ] getSearchQuery ( )
539521 {
522+ string text = searchInput . Text . Trim ( ) ;
540523
524+ if ( text == string . Empty ) return null ;
525+
526+ bool hex = searchInputTypeButton . Text == "H" ;
527+ List < byte > bytes = new List < byte > ( ) ;
528+
529+ string [ ] parts = text . Split ( ' ' ) ;
530+ foreach ( string part in parts )
531+ {
532+ text = part . Trim ( ) ;
533+ if ( text . Length == 0 ) return null ;
534+
535+ int value = - 1 ;
536+ if ( hex )
537+ {
538+ if ( ! int . TryParse ( text , NumberStyles . HexNumber , null , out value ) || value > 255 ) return null ;
539+ else bytes . Add ( ( byte ) value ) ;
540+ }
541+ else
542+ {
543+ if ( ! int . TryParse ( text , out value ) || value > 255 ) return null ;
544+ else bytes . Add ( ( byte ) value ) ;
545+ }
546+ }
547+
548+ return bytes . ToArray ( ) ;
541549 }
542550
551+ private void searchChanged ( IInput input )
552+ {
553+ byte [ ] query = getSearchQuery ( ) ;
554+ if ( query == null ) searchInput . FocusFrameColor = Color . Red ;
555+ else searchInput . FocusFrameColor = Main . TrackColor ;
556+ }
557+
558+ private void searchCommitted ( IInput input )
559+ {
560+ byte [ ] query = getSearchQuery ( ) ;
561+ if ( query != null )
562+ {
563+ int i = list . Search ( query ) ;
564+ if ( i >= 0 ) list . ScrollTo ( i ) ;
565+ else showStatus ( "No match found for query '" + searchInput . Text + "'." , 2 ) ;
566+ }
567+ }
568+
543569 private void valueChanged ( IInput input )
544570 {
545571 TextInput textInput = input as TextInput ;
@@ -554,6 +580,49 @@ private void valueChanged(IInput input)
554580 else valueInput . FocusFrameColor = Color . Red ;
555581 }
556582
583+ private void inputTypeSwitchClicked ( Button btn )
584+ {
585+ TextInput input = btn . Tag as TextInput ;
586+
587+ NumberStyles oldStyle ;
588+ string format = "" ;
589+
590+ if ( btn . Text == "H" )
591+ {
592+ btn . TextColor = Main . DecColor ;
593+ oldStyle = NumberStyles . HexNumber ;
594+ }
595+ else
596+ {
597+ btn . TextColor = Main . HexColor ;
598+ oldStyle = NumberStyles . Integer ;
599+ format = "X2" ;
600+ }
601+
602+ if ( input . Text != "" )
603+ {
604+ if ( input == searchInput ) // special treatment for search input because it can have several values (space-separated)
605+ {
606+ byte [ ] query = getSearchQuery ( ) ;
607+ if ( query != null )
608+ {
609+ List < string > bytes = new List < string > ( ) ;
610+ foreach ( byte b in query ) bytes . Add ( b . ToString ( format ) ) ;
611+ input . Text = string . Join ( " " , bytes ) ;
612+ }
613+ }
614+ else
615+ {
616+ int i = - 1 ;
617+ if ( int . TryParse ( input . Text , oldStyle , null , out i ) )
618+ input . Text = i . ToString ( format ) ;
619+ }
620+ }
621+
622+ input . TextColor = btn . TextColor ;
623+ btn . Text = btn . Text == "H" ? "D" : "H" ; // do this here and not above because getSearchQuery relies on the text
624+ }
625+
557626 private void writeButtonClicked ( Button obj )
558627 {
559628 writeDataFileChanges ( ) ;
0 commit comments