Преглед изворни кода

Redesigning Generate URL/Code dialog using page control

Source commit: 0f8ef858aa6ecf6e413f4d17f59108e7ebd93169
Martin Prikryl пре 10 година
родитељ
комит
74aa959d9c
3 измењених фајлова са 162 додато и 229 уклоњено
  1. 19 39
      source/forms/GenerateUrl.cpp
  2. 134 178
      source/forms/GenerateUrl.dfm
  3. 9 12
      source/forms/GenerateUrl.h

+ 19 - 39
source/forms/GenerateUrl.cpp

@@ -31,14 +31,6 @@ __fastcall TGenerateUrlDialog::TGenerateUrlDialog(
   FPaths = Paths;
   FChanging = false;
   ReadOnlyControl(ResultMemo);
-  FGroupBoxPadding = ResultGroup->Top - (AssemblyOptionsGroup->Top + AssemblyOptionsGroup->Height);
-  ScriptOptionsGroup->Top = OptionsGroup->Top;
-  AssemblyOptionsGroup->Top = OptionsGroup->Top;
-  int DesiredHeight = ScaleByTextHeight(this, 360);
-  int HeightChange = Height - DesiredHeight;
-  // Need to enlarge the results box before it would get out of form
-  ResultGroup->SetBounds(ResultGroup->Left, ResultGroup->Top - HeightChange, ResultGroup->Width, ResultGroup->Height + HeightChange);
-  Height = Height - HeightChange;
 }
 //---------------------------------------------------------------------------
 bool __fastcall TGenerateUrlDialog::IsFileUrl()
@@ -80,36 +72,24 @@ void __fastcall TGenerateUrlDialog::UpdateControls()
   {
     Caption = LoadStr(IsFileUrl() ? GENERATE_URL_FILE_TITLE : GENERATE_URL_SESSION_TITLE);
 
-    EnableControl(ScriptButton, !IsFileUrl());
-    EnableControl(AssemblyButton, !IsFileUrl());
+    EnableControl(ScriptSheet, !IsFileUrl());
+    EnableControl(AssemblySheet, !IsFileUrl());
 
-    OptionsGroup->Visible = UrlButton->Checked;
-    ScriptOptionsGroup->Visible = ScriptButton->Checked;
-    AssemblyOptionsGroup->Visible = AssemblyButton->Checked;
-
-    TControl * ResultGroupBelow = NULL;
     UnicodeString ResultGroupCaption;
-
-    if (UrlButton->Checked)
+    if (OptionsPageControl->ActivePage == UrlSheet)
     {
-      ResultGroupBelow = OptionsGroup;
       ResultGroupCaption = LoadStr(GENERATE_URL_URL);
     }
-    else if (ScriptButton->Checked)
+    else if (OptionsPageControl->ActivePage == ScriptSheet)
     {
-      ResultGroupBelow = ScriptOptionsGroup;
       ResultGroupCaption = ScriptFormatCombo->Items->Strings[ScriptFormatCombo->ItemIndex];
     }
-    else if (DebugAlwaysTrue(AssemblyButton->Checked))
+    else if (DebugAlwaysTrue(OptionsPageControl->ActivePage == AssemblySheet))
     {
-      ResultGroupBelow = AssemblyOptionsGroup;
       ResultGroupCaption = LoadStr(GENERATE_URL_CODE);
     }
     ResultGroup->Caption = ResultGroupCaption;
 
-    int ResultGroupTop = ResultGroupBelow->Top + ResultGroupBelow->Height + FGroupBoxPadding;
-    ResultGroup->SetBounds(ResultGroup->Left, ResultGroupTop, ResultGroup->Width, (ResultGroup->Top + ResultGroup->Height) - ResultGroupTop);
-
     EnableControl(UserNameCheck, !FData->UserNameExpanded.IsEmpty());
     bool UserNameIncluded = UserNameCheck->Enabled && UserNameCheck->Checked;
     EnableControl(PasswordCheck, UserNameIncluded && FData->HasPassword());
@@ -121,7 +101,7 @@ void __fastcall TGenerateUrlDialog::UpdateControls()
 
     bool WordWrap = false;
     bool FixedWidth = false;
-    if (UrlButton->Checked)
+    if (OptionsPageControl->ActivePage == UrlSheet)
     {
       if (!IsFileUrl())
       {
@@ -141,7 +121,7 @@ void __fastcall TGenerateUrlDialog::UpdateControls()
       }
       WordWrap = true;
     }
-    else if (ScriptButton->Checked)
+    else if (OptionsPageControl->ActivePage == ScriptSheet)
     {
       UnicodeString ExeName = Application->ExeName;
       UnicodeString BaseExeName = ExtractFileBaseName(ExeName);
@@ -199,7 +179,7 @@ void __fastcall TGenerateUrlDialog::UpdateControls()
         FixedWidth = false;
       }
     }
-    else if (DebugAlwaysTrue(AssemblyButton->Checked))
+    else if (DebugAlwaysTrue(OptionsPageControl->ActivePage == AssemblySheet))
     {
       Result = FData->GenerateAssemblyCode(static_cast<TAssemblyLanguage>(AssemblyLanguageCombo->ItemIndex));
       WordWrap = false;
@@ -235,22 +215,22 @@ void __fastcall TGenerateUrlDialog::Execute()
 
     if (IsFileUrl())
     {
-      UrlButton->Checked = true;
+      OptionsPageControl->ActivePage = UrlSheet;
     }
     else
     {
       switch (Target)
       {
         case guctUrl:
-          UrlButton->Checked = true;
+          OptionsPageControl->ActivePage = UrlSheet;
           break;
 
         case guctScript:
-          ScriptButton->Checked = true;
+          OptionsPageControl->ActivePage = ScriptSheet;
           break;
 
         case guctAssembly:
-          AssemblyButton->Checked = true;
+          OptionsPageControl->ActivePage = AssemblySheet;
           break;
 
         default:
@@ -258,9 +238,9 @@ void __fastcall TGenerateUrlDialog::Execute()
       }
     }
 
-    for (int Index = 0; Index < OptionsGroup->ControlCount; Index++)
+    for (int Index = 0; Index < UrlSheet->ControlCount; Index++)
     {
-      TCheckBox * CheckBox = dynamic_cast<TCheckBox *>(OptionsGroup->Controls[Index]);
+      TCheckBox * CheckBox = dynamic_cast<TCheckBox *>(UrlSheet->Controls[Index]);
 
       if (DebugAlwaysTrue((CheckBox != NULL) && (CheckBox->Tag != 0)))
       {
@@ -280,15 +260,15 @@ void __fastcall TGenerateUrlDialog::Execute()
   // Do not save the selection for files as the "URL" was selected implicitly
   if (!IsFileUrl())
   {
-    if (UrlButton->Checked)
+    if (OptionsPageControl->ActivePage == UrlSheet)
     {
       Target = guctUrl;
     }
-    else if (ScriptButton->Checked)
+    else if (OptionsPageControl->ActivePage == ScriptSheet)
     {
       Target = guctScript;
     }
-    else if (AssemblyButton->Checked)
+    else if (OptionsPageControl->ActivePage == AssemblySheet)
     {
       Target = guctAssembly;
     }
@@ -302,9 +282,9 @@ void __fastcall TGenerateUrlDialog::Execute()
   if (Target == guctUrl)
   {
     Components = 0;
-    for (int Index = 0; Index < OptionsGroup->ControlCount; Index++)
+    for (int Index = 0; Index < UrlSheet->ControlCount; Index++)
     {
-      TCheckBox * CheckBox = dynamic_cast<TCheckBox *>(OptionsGroup->Controls[Index]);
+      TCheckBox * CheckBox = dynamic_cast<TCheckBox *>(UrlSheet->Controls[Index]);
 
       if (DebugAlwaysTrue((CheckBox != NULL) && (CheckBox->Tag != 0)) &&
           CheckBox->Checked)

+ 134 - 178
source/forms/GenerateUrl.dfm

@@ -6,103 +6,159 @@ object GenerateUrlDialog: TGenerateUrlDialog
   BorderIcons = [biSystemMenu, biMinimize, biMaximize, biHelp]
   BorderStyle = bsDialog
   Caption = 'Generate URL X'
-  ClientHeight = 362
+  ClientHeight = 338
   ClientWidth = 484
   Color = clBtnFace
+  Constraints.MinHeight = 300
+  Constraints.MinWidth = 484
   ParentFont = True
   OldCreateOrder = True
   Position = poOwnerFormCenter
   DesignSize = (
     484
-    362)
+    338)
   PixelsPerInch = 96
   TextHeight = 13
-  object OptionsGroup: TGroupBox
-    Left = 8
-    Top = 61
-    Width = 468
-    Height = 95
+  object OptionsPageControl: TPageControl
+    Left = 5
+    Top = 5
+    Width = 475
+    Height = 111
+    ActivePage = UrlSheet
     Anchors = [akLeft, akTop, akRight]
-    Caption = 'URL options'
-    TabOrder = 1
-    object UserNameCheck: TCheckBox
-      Tag = 1
-      Left = 11
-      Top = 20
-      Width = 216
-      Height = 17
-      Caption = '&User name'
-      TabOrder = 0
-      OnClick = ControlChange
-    end
-    object PasswordCheck: TCheckBox
-      Tag = 2
-      Left = 235
-      Top = 20
-      Width = 216
-      Height = 17
-      HelpType = htKeyword
-      Caption = '&Password'
-      TabOrder = 1
-      OnClick = ControlChange
-    end
-    object HostKeyCheck: TCheckBox
-      Tag = 4
-      Left = 11
-      Top = 43
-      Width = 216
-      Height = 17
-      Caption = 'SSH &host Key'
-      TabOrder = 2
-      OnClick = ControlChange
-    end
-    object RemoteDirectoryCheck: TCheckBox
-      Tag = 8
-      Left = 235
-      Top = 43
-      Width = 216
-      Height = 17
-      Caption = 'Initial &directory'
-      TabOrder = 3
-      OnClick = ControlChange
+    TabOrder = 0
+    OnChange = ControlChange
+    object UrlSheet: TTabSheet
+      Caption = 'URL'
+      object UserNameCheck: TCheckBox
+        Tag = 1
+        Left = 11
+        Top = 8
+        Width = 216
+        Height = 17
+        Caption = '&User name'
+        TabOrder = 0
+        OnClick = ControlChange
+      end
+      object HostKeyCheck: TCheckBox
+        Tag = 4
+        Left = 11
+        Top = 31
+        Width = 216
+        Height = 17
+        Caption = 'SSH &host Key'
+        TabOrder = 1
+        OnClick = ControlChange
+      end
+      object WinSCPSpecificCheck: TCheckBox
+        Tag = 16
+        Left = 11
+        Top = 54
+        Width = 216
+        Height = 17
+        Caption = '&WinSCP-specific'
+        TabOrder = 2
+        OnClick = ControlChange
+      end
+      object SaveExtensionCheck: TCheckBox
+        Tag = 32
+        Left = 235
+        Top = 54
+        Width = 216
+        Height = 17
+        Caption = '&Save extension'
+        TabOrder = 3
+        OnClick = ControlChange
+      end
+      object RemoteDirectoryCheck: TCheckBox
+        Tag = 8
+        Left = 235
+        Top = 31
+        Width = 216
+        Height = 17
+        Caption = 'Initial &directory'
+        TabOrder = 4
+        OnClick = ControlChange
+      end
+      object PasswordCheck: TCheckBox
+        Tag = 2
+        Left = 235
+        Top = 8
+        Width = 216
+        Height = 17
+        HelpType = htKeyword
+        Caption = '&Password'
+        TabOrder = 5
+        OnClick = ControlChange
+      end
     end
-    object WinSCPSpecificCheck: TCheckBox
-      Tag = 16
-      Left = 11
-      Top = 66
-      Width = 216
-      Height = 17
-      Caption = '&WinSCP-specific'
-      TabOrder = 4
-      OnClick = ControlChange
+    object ScriptSheet: TTabSheet
+      Caption = 'Script'
+      ImageIndex = 1
+      object Label2: TLabel
+        Left = 11
+        Top = 8
+        Width = 38
+        Height = 13
+        Caption = '&Format:'
+        FocusControl = ScriptFormatCombo
+      end
+      object ScriptFormatCombo: TComboBox
+        Left = 112
+        Top = 5
+        Width = 103
+        Height = 21
+        Style = csDropDownList
+        TabOrder = 0
+        OnChange = ControlChange
+        Items.Strings = (
+          'Script file'
+          'Batch file'
+          'Command-line')
+      end
     end
-    object SaveExtensionCheck: TCheckBox
-      Tag = 32
-      Left = 235
-      Top = 66
-      Width = 216
-      Height = 17
-      Caption = '&Save extension'
-      TabOrder = 5
-      OnClick = ControlChange
+    object AssemblySheet: TTabSheet
+      Caption = '.NET assembly code'
+      ImageIndex = 2
+      object Label1: TLabel
+        Left = 11
+        Top = 8
+        Width = 51
+        Height = 13
+        Caption = '&Language:'
+        FocusControl = AssemblyLanguageCombo
+      end
+      object AssemblyLanguageCombo: TComboBox
+        Left = 112
+        Top = 5
+        Width = 103
+        Height = 21
+        Style = csDropDownList
+        TabOrder = 0
+        OnChange = ControlChange
+        Items.Strings = (
+          'C#'
+          'VB.NET'
+          'PowerShell')
+      end
     end
   end
   object ResultGroup: TGroupBox
     Left = 8
-    Top = 272
+    Top = 122
     Width = 468
-    Height = 51
+    Height = 176
     Anchors = [akLeft, akTop, akRight, akBottom]
     Caption = 'ResultX'
-    TabOrder = 4
+    TabOrder = 1
     DesignSize = (
       468
-      51)
+      176)
     object ResultMemo: TMemo
       Left = 7
       Top = 15
       Width = 454
-      Height = 27
+      Height = 152
       TabStop = False
       Anchors = [akLeft, akTop, akRight, akBottom]
       BevelInner = bvNone
@@ -116,133 +172,33 @@ object GenerateUrlDialog: TGenerateUrlDialog
   end
   object CancelBtn: TButton
     Left = 318
-    Top = 329
+    Top = 305
     Width = 75
     Height = 25
     Anchors = [akRight, akBottom]
     Cancel = True
     Caption = 'Close'
     ModalResult = 2
-    TabOrder = 6
+    TabOrder = 3
   end
   object HelpButton: TButton
     Left = 401
-    Top = 329
+    Top = 305
     Width = 75
     Height = 25
     Anchors = [akRight, akBottom]
     Caption = '&Help'
-    TabOrder = 7
+    TabOrder = 4
     OnClick = HelpButtonClick
   end
   object ClipboardButton: TButton
     Left = 8
-    Top = 329
+    Top = 305
     Width = 145
     Height = 25
     Anchors = [akLeft, akBottom]
     Caption = '&Copy to Clipboard'
-    TabOrder = 5
-    OnClick = ClipboardButtonClick
-  end
-  object GenerateGroup: TGroupBox
-    Left = 8
-    Top = 6
-    Width = 468
-    Height = 49
-    Anchors = [akLeft, akTop, akRight]
-    Caption = 'Generate'
-    TabOrder = 0
-    object UrlButton: TRadioButton
-      Tag = 1
-      Left = 11
-      Top = 20
-      Width = 102
-      Height = 17
-      Caption = '&URL'
-      TabOrder = 0
-      OnClick = ControlChange
-    end
-    object ScriptButton: TRadioButton
-      Tag = 2
-      Left = 124
-      Top = 20
-      Width = 102
-      Height = 17
-      HelpType = htKeyword
-      Caption = '&Script'
-      TabOrder = 1
-      OnClick = ControlChange
-    end
-    object AssemblyButton: TRadioButton
-      Tag = 4
-      Left = 235
-      Top = 20
-      Width = 216
-      Height = 17
-      Caption = '.NET &assembly code'
-      TabOrder = 2
-      OnClick = ControlChange
-    end
-  end
-  object AssemblyOptionsGroup: TGroupBox
-    Left = 8
-    Top = 217
-    Width = 468
-    Height = 49
-    Anchors = [akLeft, akTop, akRight]
-    Caption = 'Code options'
-    TabOrder = 3
-    object Label1: TLabel
-      Left = 11
-      Top = 21
-      Width = 51
-      Height = 13
-      Caption = '&Language:'
-      FocusControl = AssemblyLanguageCombo
-    end
-    object AssemblyLanguageCombo: TComboBox
-      Left = 124
-      Top = 17
-      Width = 103
-      Height = 21
-      Style = csDropDownList
-      TabOrder = 0
-      OnChange = ControlChange
-      Items.Strings = (
-        'C#'
-        'VB.NET'
-        'PowerShell')
-    end
-  end
-  object ScriptOptionsGroup: TGroupBox
-    Left = 8
-    Top = 162
-    Width = 468
-    Height = 49
-    Anchors = [akLeft, akTop, akRight]
-    Caption = 'Script options'
     TabOrder = 2
-    object Label2: TLabel
-      Left = 11
-      Top = 21
-      Width = 38
-      Height = 13
-      Caption = '&Format:'
-      FocusControl = ScriptFormatCombo
-    end
-    object ScriptFormatCombo: TComboBox
-      Left = 124
-      Top = 17
-      Width = 103
-      Height = 21
-      Style = csDropDownList
-      TabOrder = 0
-      OnChange = ControlChange
-      Items.Strings = (
-        'Script file'
-        'Batch file'
-        'Command-line')
-    end
+    OnClick = ClipboardButtonClick
   end
 end

+ 9 - 12
source/forms/GenerateUrl.h

@@ -8,32 +8,30 @@
 #include <Vcl.Forms.hpp>
 
 #include "SessionData.h"
+#include <Vcl.ComCtrls.hpp>
 //---------------------------------------------------------------------------
 class TGenerateUrlDialog : public TForm
 {
 __published:
-  TGroupBox *OptionsGroup;
   TGroupBox *ResultGroup;
   TMemo *ResultMemo;
   TButton *CancelBtn;
   TButton *HelpButton;
   TButton *ClipboardButton;
+  TPageControl *OptionsPageControl;
+  TTabSheet *UrlSheet;
+  TTabSheet *ScriptSheet;
+  TTabSheet *AssemblySheet;
   TCheckBox *UserNameCheck;
-  TCheckBox *PasswordCheck;
   TCheckBox *HostKeyCheck;
-  TCheckBox *RemoteDirectoryCheck;
   TCheckBox *WinSCPSpecificCheck;
   TCheckBox *SaveExtensionCheck;
-  TGroupBox *GenerateGroup;
-  TRadioButton *UrlButton;
-  TRadioButton *ScriptButton;
-  TRadioButton *AssemblyButton;
-  TGroupBox *AssemblyOptionsGroup;
-  TLabel *Label1;
-  TComboBox *AssemblyLanguageCombo;
-  TGroupBox *ScriptOptionsGroup;
+  TCheckBox *RemoteDirectoryCheck;
+  TCheckBox *PasswordCheck;
   TLabel *Label2;
   TComboBox *ScriptFormatCombo;
+  TLabel *Label1;
+  TComboBox *AssemblyLanguageCombo;
   void __fastcall ControlChange(TObject *Sender);
   void __fastcall ClipboardButtonClick(TObject *Sender);
   void __fastcall HelpButtonClick(TObject *Sender);
@@ -42,7 +40,6 @@ private:
   TSessionData * FData;
   TStrings * FPaths;
   bool FChanging;
-  int FGroupBoxPadding;
 
 protected:
   void __fastcall UpdateControls();