Browse Source

GUI improve import RAW on Operations Explorer

PascalCoin 5 years ago
parent
commit
2aecb48d4c

+ 1 - 7
src/gui-classic/UFRMMemoText.dfm

@@ -24,8 +24,6 @@ object FRMMemoText: TFRMMemoText
     Align = alBottom
     BevelOuter = bvNone
     TabOrder = 0
-    ExplicitTop = 245
-    ExplicitWidth = 619
     DesignSize = (
       745
       55)
@@ -35,11 +33,9 @@ object FRMMemoText: TFRMMemoText
       Width = 116
       Height = 31
       Anchors = [akTop, akRight]
-      DoubleBuffered = True
       Kind = bkCancel
-      ParentDoubleBuffered = False
+      NumGlyphs = 2
       TabOrder = 0
-      ExplicitLeft = 494
     end
   end
   object Memo: TMemo
@@ -60,7 +56,5 @@ object FRMMemoText: TFRMMemoText
     ScrollBars = ssBoth
     TabOrder = 1
     WordWrap = False
-    ExplicitWidth = 619
-    ExplicitHeight = 245
   end
 end

+ 64 - 0
src/gui-classic/UFRMMemoText.pas

@@ -18,12 +18,22 @@ type
     bbCancel: TBitBtn;
     procedure FormCreate(Sender: TObject);
   private
+    FAllowInput: Boolean;
+    FbbOk : TBitBtn;
+    procedure SetAllowInput(const Value: Boolean);
+    procedure SetDataText(const Value: String);
+    function GetDataText: String;
     { Private declarations }
   public
     { Public declarations }
     Procedure InitData(const Title : String; const text : String);
+    property AllowInput : Boolean read FAllowInput write SetAllowInput;
+    property DataText : String read GetDataText write SetDataText;
   end;
 
+
+function InputMemoQuery(const ATitle : String; AAllowMultiline : Boolean; var AText : String) : Boolean;
+
 implementation
 
 {$IFnDEF FPC}
@@ -32,9 +42,37 @@ implementation
   {$R *.lfm}
 {$ENDIF}
 
+function InputMemoQuery(const ATitle : String; AAllowMultiline : Boolean; var AText : String) : Boolean;
+Var LFRM : TFRMMemoText;
+begin
+  LFRM := TFRMMemoText.Create(Nil);
+  try
+    LFRM.InitData(ATitle,AText);
+    LFRM.AllowInput := True;
+    if AAllowMultiline then begin
+      LFRM.Memo.ScrollBars := ssBoth;
+    end else begin
+      LFRM.Memo.ScrollBars := ssNone;
+      LFRM.Memo.WordWrap := True;
+    end;
+    if LFRM.ShowModal=MrOk then begin
+      AText := LFRM.DataText;
+      Result := True;
+    end else Result := False;
+  finally
+    LFRM.Free;
+  end;
+end;
+
 procedure TFRMMemoText.FormCreate(Sender: TObject);
 begin
   Memo.Clear;
+  FbbOk := Nil;
+end;
+
+function TFRMMemoText.GetDataText: String;
+begin
+  Result := Memo.Lines.Text;
 end;
 
 procedure TFRMMemoText.InitData(const Title, text: String);
@@ -43,4 +81,30 @@ begin
   Memo.Lines.Text := text;
 end;
 
+procedure TFRMMemoText.SetAllowInput(const Value: Boolean);
+begin
+  FAllowInput := Value;
+  Memo.ReadOnly := Not FAllowInput;
+  if FAllowInput then begin
+    if Not Assigned(FbbOk) then begin
+      FbbOk := TBitBtn.Create(Self);
+      FbbOk.Parent := bbCancel.Parent;
+      FbbOk.Anchors := bbCancel.Anchors;
+      FbbOk.Left := bbCancel.Left - bbCancel.Width - 10;
+      FbbOk.Top := bbCancel.Top;
+      FbbOk.Width := bbCancel.Width;
+      FbbOk.Height := bbCancel.Height;
+      FbbOk.Kind := bkOK;
+      FbbOk.ModalResult := MrOk;
+      FbbOk.Caption := 'Ok';
+    end;
+  end else FreeAndNil(FbbOk);
+
+end;
+
+procedure TFRMMemoText.SetDataText(const Value: String);
+begin
+  Memo.Lines.Text := Value;
+end;
+
 end.

+ 6 - 7
src/gui-classic/UFRMOperationsExplorer.pas

@@ -132,7 +132,7 @@ Uses
 {$IFDEF TESTNET}
    UFRMRandomOperations,
 {$ENDIF}
-   UFRMRPCCalls;
+   UFRMRPCCalls, UFRMMemoText;
 
 
 { TFRMOperationsExplorer }
@@ -530,17 +530,16 @@ end;
 procedure TFRMOperationsExplorer.MiImportOperationsFromTxtClick(Sender: TObject);
 Var i : Integer;
   raw : TRawBytes;
-  aux : AnsiString;
   auxS : String;
   errors : String;
   opht : TOperationsHashTree;
   ms : TMemoryStream;
 begin
-  aux := '';
-  If Not InputQuery(Caption,'Paste a RAW hexadecimal operations:',auxS) then exit;
-  aux := auxS;
-  If Not TCrypto.IsHexString(aux) then Raise Exception.Create('Invalid hexadecimal RAW');
-  raw := TCrypto.HexaToRaw(aux);
+  auxS := '';
+  if Not InputMemoQuery('Paste a RAW hexadecimal operations:',False,auxS) then Exit;
+
+  if Not TCrypto.HexaToRaw(auxS, raw) then Raise Exception.Create('Invalid hexadecimal RAW');
+
   If Length(raw)=0 then Exit;
   ms := TMemoryStream.Create;
   opht := TOperationsHashTree.Create;