Jelajahi Sumber

GUI: added popup menus

Herman Schoenfeld 7 tahun lalu
induk
melakukan
7b66cfa22c

+ 0 - 1
src/core/USettings.pas

@@ -118,7 +118,6 @@ implementation
 uses
   Classes, SysUtils, UConst, UFolderHelper;
 
-
 { TSettings }
 
 class procedure TSettings.Load;

+ 38 - 1
src/gui/UCTRLWallet.lfm

@@ -10,7 +10,6 @@ object CTRLWallet: TCTRLWallet
   ClientWidth = 1151
   OnCreate = FormCreate
   OnResize = FormResize
-  LCLVersion = '1.8.0.6'
   Visible = False
   object PairSplitter1: TPairSplitter
     Left = 0
@@ -158,4 +157,42 @@ object CTRLWallet: TCTRLWallet
       end
     end
   end
+  object mnuAccountsPopup: TPopupMenu
+    left = 768
+    top = 64
+    object miSendPASC: TMenuItem
+      Caption = 'Send PASC'
+      OnClick = miSendPASCClick
+    end
+    object miTransferAccounts: TMenuItem
+      Caption = 'Transfer Account(s)'
+      OnClick = miTransferAccountsClick
+    end
+    object miSep1: TMenuItem
+      Caption = '-'
+    end
+    object miAccountInfo: TMenuItem
+      Caption = 'Account Info'
+      OnClick = miAccountInfoClick
+    end
+  end
+  object mnuOperationsPopup: TPopupMenu
+    left = 896
+    top = 64
+    object miCopyOphash: TMenuItem
+      Caption = 'Copy OPHASH'
+      OnClick = miCopyOphashClick
+    end
+    object MenuItem1: TMenuItem
+      Caption = '-'
+    end
+    object miOperationInfo: TMenuItem
+      Caption = 'Operation Info'
+      OnClick = miOperationInfoClick
+    end
+  end
+  object mnuFirstAccountPopup: TPopupMenu
+    left = 1024
+    top = 64
+  end
 end

+ 60 - 11
src/gui/UCTRLWallet.pas

@@ -7,7 +7,7 @@ unit UCTRLWallet;
 interface
 
 uses
-  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
+  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, Menus,
   ExtCtrls, PairSplitter, Buttons, UVisualGrid, UCommon.UI,
   UAccounts, UDataSources, UNode;
 
@@ -16,7 +16,7 @@ type
   { TCTRLWallet }
 
   TCTRLWalletAccountsMode = (wamMyAccounts, wamFirstAccount);
-  TCTRLWalletOperationsMode = (womUnknown, womSelectedAccounts, womAllAccounts);
+  TCTRLWalletOperationsMode = (womSelectedAccounts, womAllAccounts);
   TCTRLWalletOperationsHistory = (woh30Days, wohFullHistory);
 
   TCTRLWallet = class(TApplicationForm)
@@ -28,15 +28,30 @@ type
     Label2: TLabel;
     lblTotalPASA: TLabel;
     lblTotalPASC: TLabel;
+    MenuItem1: TMenuItem;
+    miCopyOphash: TMenuItem;
+    miOperationInfo: TMenuItem;
+    miSendPASC: TMenuItem;
+    miTransferAccounts: TMenuItem;
+    miAccountInfo: TMenuItem;
+    miSep1: TMenuItem;
     PairSplitter1: TPairSplitter;
     PairSplitterSide1: TPairSplitterSide;
     PairSplitterSide2: TPairSplitterSide;
     paAccounts: TPanel;
     paOperations: TPanel;
+    mnuAccountsPopup: TPopupMenu;
+    mnuOperationsPopup: TPopupMenu;
+    mnuFirstAccountPopup: TPopupMenu;
     procedure cbAccountsChange(Sender: TObject);
     procedure cmbDurationChange(Sender: TObject);
     procedure FormCreate(Sender: TObject);
     procedure FormResize(Sender: TObject);
+    procedure miAccountInfoClick(Sender: TObject);
+    procedure miCopyOphashClick(Sender: TObject);
+    procedure miOperationInfoClick(Sender: TObject);
+    procedure miSendPASCClick(Sender: TObject);
+    procedure miTransferAccountsClick(Sender: TObject);
   private
     FNodeNotifyEvents : TNodeNotifyEvents;
     FAccountsMode : TCTRLWalletAccountsMode;
@@ -58,6 +73,7 @@ type
     procedure OnOperationSelected(Sender: TObject; constref ASelection: TVisualGridSelection);
     procedure OnAccountsGridColumnInitialize(Sender: TObject; AColIndex:Integer; AColumn: TVisualColumn);
     procedure OnOperationsGridColumnInitialize(Sender: TObject; AColIndex:Integer; AColumn: TVisualColumn);
+    procedure OnPrepareAccountPopupMenu(Sender: TObject; constref ASelection: TVisualGridSelection; out APopupMenu: TPopupMenu);
   public
     property AccountsMode : TCTRLWalletAccountsMode read FAccountsMode write SetAccountsMode;
     property OperationsMode : TCTRLWalletOperationsMode read FOperationsMode write SetOperationsMode;
@@ -67,7 +83,8 @@ type
 implementation
 
 uses
-  UUserInterface, UBlockChain, UCommon, UAutoScope, Generics.Collections, UCommon.Collections;
+  UUserInterface, UBlockChain, UWallet,
+  UCommon, UAutoScope, Generics.Collections, UCommon.Collections;
 
 {$R *.lfm}
 
@@ -100,6 +117,7 @@ begin
   FAccountsGrid.OnColumnInitialize:= OnAccountsGridColumnInitialize;
   FAccountsGrid.OnSelection := OnAccountsSelected;
   FAccountsGrid.OnFinishedUpdating := OnAccountsUpdated;
+  FAccountsGrid.OnPreparePopupMenu:= OnPrepareAccountPopupMenu;
 
   FOperationsGrid := TVisualGrid.Create(Self);
   FOperationsGrid.SortMode := smMultiColumn;
@@ -121,9 +139,11 @@ begin
   );
   FOperationsGrid.OnColumnInitialize:= OnOperationsGridColumnInitialize;
   FOperationsGrid.OnSelection := OnOperationSelected;
+  FOperationsGrid.PopupMenu := mnuOperationsPopup;
   FOperationsGrid.Caption.Alignment:= taCenter;
   FOperationsGrid.Caption.Text := 'All Account Operations';
   FOperationsGrid.Caption.Visible := true;
+
   cmbDuration := TComboBox.Create(FOperationsGrid);
   FOperationsGrid.WidgetControl := cmbDuration;
   cmbDuration.Items.BeginUpdate;
@@ -141,7 +161,7 @@ begin
 
   // Configure grid states
   AccountsMode := wamMyAccounts;
-  OperationsMode:= womUnknown;
+  OperationsMode:= womAllAccounts;
   OperationsHistory := woh30Days;
 end;
 
@@ -151,6 +171,7 @@ begin
 
 end;
 
+
 procedure TCTRLWallet.ActivateFirstTime;
 begin
 
@@ -200,10 +221,6 @@ procedure TCTRLWallet.SetOperationsMode(AMode: TCTRLWalletOperationsMode);
 
 begin
   case AMode of
-     womUnknown: begin
-       FOperationsGrid.Caption.Text := '';
-       FOperationsDataSource.Accounts := TArrayTool<Cardinal>.Empty;
-     end;
      womAllAccounts: begin
        FOperationsGrid.Caption.Text := 'All Accounts';
        FOperationsDataSource.Accounts := TListTool<TAccount, Cardinal>.Transform( FAccountsDataSource.LastKnownUserAccounts, GetAccNo );
@@ -261,11 +278,10 @@ begin
         selectedAccounts.Add(acc);
     end;
     FOperationsDataSource.Accounts := selectedAccounts.ToArray;
+    FOperationsGrid.RefreshGrid;
   end else begin
-
-    TUserInterface.ShowInfo(Self, 'Deselect', 'Deselect');
+    OperationsMode:= womAllAccounts;
   end;
-  FOperationsGrid.RefreshGrid;
 end;
 
 procedure TCTRLWallet.OnOperationSelected(Sender: TObject; constref ASelection: TVisualGridSelection);
@@ -302,5 +318,38 @@ begin
   end;
 end;
 
+procedure TCTRLWallet.OnPrepareAccountPopupMenu(Sender: TObject; constref ASelection: TVisualGridSelection; out APopupMenu: TPopupMenu);
+begin
+  miSep1.Visible := ASelection.RowCount = 1;
+  miAccountInfo.Visible := ASelection.RowCount = 1;
+  miTransferAccounts.Caption := IIF( ASelection.RowCount = 1, 'Transfer Account', 'Transfer Accounts');
+  APopupMenu := mnuAccountsPopup;
+end;
+
+procedure TCTRLWallet.miAccountInfoClick(Sender: TObject);
+begin
+  raise ENotImplemented.Create('Not Implemented');
+end;
+
+procedure TCTRLWallet.miSendPASCClick(Sender: TObject);
+begin
+  raise ENotImplemented.Create('Not Implemented');
+end;
+
+procedure TCTRLWallet.miTransferAccountsClick(Sender: TObject);
+begin
+  raise ENotImplemented.Create('Not Implemented');
+end;
+
+procedure TCTRLWallet.miCopyOphashClick(Sender: TObject);
+begin
+  raise ENotImplemented.Create('Not Implemented');
+end;
+
+procedure TCTRLWallet.miOperationInfoClick(Sender: TObject);
+begin
+  raise ENotImplemented.Create('Not Implemented');
+end;
+
 end.
 

+ 2 - 90
src/libraries/sphere10/UVisualGrid.pas

@@ -23,7 +23,7 @@ interface
 
 uses
   Classes, SysUtils, StdCtrls, ExtCtrls, Controls, Grids, Types, Graphics,
-  UCommon, UCommon.Data, UAccounts, UWallet, UCommon.Collections, Generics.Collections, Generics.Defaults, Menus, ComboEx, Buttons, Math,
+  UCommon, UCommon.Data, UCommon.Collections, Generics.Collections, Generics.Defaults, Menus, ComboEx, Buttons, Math,
   LResources, syncobjs;
 
 const
@@ -254,7 +254,6 @@ type
     function GetSelectedRows : TArray<Variant>;
     procedure ControlsEnable(AEnable: boolean);
     function GetCanvas: TCanvas;
-    procedure PreparePopupMenu(Sender: TObject; constref ASelection: TVisualGridSelection; out APopupMenu: TPopupMenu);
     procedure SetCells(ACol, ARow: Integer; AValue: Variant);
     procedure SetFetchDataInThread(AValue: boolean);
     procedure SetSortMode(AValue: TSortMode);
@@ -391,7 +390,7 @@ procedure Register;
 
 implementation
 
-uses Variants, UAutoScope, Dialogs, UUserInterface;
+uses Variants, UAutoScope, Dialogs;
 
 resourcestring
   sTotal = 'Total: %d';
@@ -1562,90 +1561,6 @@ begin
   Result := FDrawGrid.Canvas;
 end;
 
-procedure TCustomVisualGrid.PreparePopupMenu(Sender: TObject;
-  constref ASelection: TVisualGridSelection; out APopupMenu: TPopupMenu);
-
-  function GetAccNo(constref ARow: Variant): Cardinal;
-  begin
-    if NOT TAccountComp.AccountTxtNumberToAccountNumber(ARow.Account, Result)
-    then
-      raise Exception.Create
-        ('Internal Error: Unable to parse account number from table row');
-  end;
-
-   function GetAccNoWithCheckSum(constref ARow: Variant): String;
-  begin
-    Result := ARow.Account;
-  end;
-
-  function GetAccounts(AccountNumbers: TArray<Cardinal>): TArray<TAccount>;
-  var
-    acc: TAccount;
-    safeBox: TPCSafeBox;
-    keys: TOrderedAccountKeysList;
-    LContainer: Generics.Collections.TList<TAccount>;
-    i: Integer;
-  begin
-    LContainer := Generics.Collections.TList<TAccount>.Create();
-    keys := TWallet.keys.AccountsKeyList;
-    safeBox := TUserInterface.Node.Bank.safeBox;
-    safeBox.StartThreadSafe;
-    try
-      LContainer.Clear;
-      try
-
-        // load selected user accounts
-        for i := 0 to High(AccountNumbers) do
-        begin
-          acc := safeBox.Account(AccountNumbers[i]);
-          if keys.IndexOfAccountKey(acc.accountInfo.accountKey) >= 0 then
-          begin
-            LContainer.Add(acc);
-          end;
-        end;
-      finally
-        safeBox.EndThreadSave;
-      end;
-      Result := LContainer.ToArray;
-    finally
-      LContainer.Free;
-    end;
-
-  end;
-
-var
-  Item: TMenuItem;
-  i: Integer;
-  AccountNumbers: TArray<Cardinal>;
-  AccountNumbersWithChecksum: TArray<String>;
-  accounts: TArray<TAccount>;
-begin
-
-  if Self.Parent.Caption = 'MY ACCOUNT PANEL' then
-  begin
-    AccountNumbers := TListTool<Variant, Cardinal>.Transform(Self.SelectedRows,
-      GetAccNo);
-    AccountNumbersWithChecksum := TListTool<Variant, String>.Transform(Self.SelectedRows,
-      GetAccNoWithCheckSum);
-    for i := 0 to High(AccountNumbers) do
-    begin
-     // ShowMessage(GetAccounts(AccountNumbers)[i].Account.ToString);
-      ShowMessage(AccountNumbersWithChecksum[i]);
-    end;
-
-    APopupMenu := TPopupMenu.Create(Self);
-    Item := TMenuItem.Create(APopupMenu);
-    Item.Caption := 'Send PASC';
-    // Item.OnClick := HandlePopupItem;
-    APopupMenu.Items.Add(Item);
-
-  end
-  else
-  begin
-    APopupMenu := Nil;
-  end;
-end;
-
 procedure TCustomVisualGrid.SetCells(ACol, ARow: Integer; AValue: Variant);
 begin
   TTableRowData(FDataTable.Rows[ARow]).vvalues[ACol] := AValue;
@@ -2258,7 +2173,6 @@ var
 begin
   if ColCount = 0 then
     Exit;
-   OnPreparePopupMenu := PreparePopupMenu;
   case Button of
     mbRight:
       if (SelectionType <> stNone) and Assigned(FOnPreparePopupMenu) and
@@ -2269,14 +2183,12 @@ begin
         Dec(LRow);
         LSelection := Selection;
         for i := 0 to High(LSelection.Selections) do
-        begin
           if not LContains then
           begin
             with LSelection.Selections[i] do
               LContains := (LCol >= Left) and (LRow >= Top) and (LCol <= Right) and (LRow <= Bottom);
             Break;
           end;
-        end;
 
         if not LContains then
           Exit;