Bläddra i källkod

Hiding irrelevant controls on Properties dialog

(also removing some small refactoring in LoadInfo)

Source commit: 34c70ad80b2dc77448ed447e6458d0957a52afb6
Martin Prikryl 4 år sedan
förälder
incheckning
ef9d22f377
4 ändrade filer med 79 tillägg och 48 borttagningar
  1. 9 6
      source/core/RemoteFiles.cpp
  2. 52 25
      source/forms/Properties.cpp
  3. 12 12
      source/forms/Properties.dfm
  4. 6 5
      source/forms/Properties.h

+ 9 - 6
source/core/RemoteFiles.cpp

@@ -2635,12 +2635,15 @@ TRemoteProperties __fastcall TRemoteProperties::CommonProperties(TStrings * File
     DebugAssert(File);
     if (!Index)
     {
-      CommonProperties.Rights = *(File->Rights);
-      // previously we allowed undef implicitly for directories,
-      // now we do it explicitly in properties dialog and only in combination
-      // with "recursive" option
-      CommonProperties.Rights.AllowUndef = File->Rights->IsUndef;
-      CommonProperties.Valid << vpRights;
+      if (!File->Rights->Unknown)
+      {
+        CommonProperties.Rights = *(File->Rights);
+        // previously we allowed undef implicitly for directories,
+        // now we do it explicitly in properties dialog and only in combination
+        // with "recursive" option
+        CommonProperties.Rights.AllowUndef = File->Rights->IsUndef;
+        CommonProperties.Valid << vpRights;
+      }
       if (File->Owner.IsSet)
       {
         CommonProperties.Owner = File->Owner;

+ 52 - 25
source/forms/Properties.cpp

@@ -86,12 +86,22 @@ bool __fastcall TPropertiesDialog::Execute(TRemoteProperties & Properties)
   SetFileProperties(Properties);
 
   PageControl->ActivePage = CommonSheet;
-  if (FAllowedChanges & cpGroup) ActiveControl = GroupComboBox;
-    else
-  if (FAllowedChanges & cpOwner) ActiveControl = OwnerComboBox;
-    else
-  if (FAllowedChanges & cpMode) ActiveControl = RightsFrame;
-    else ActiveControl = CancelButton;
+  if (OwnerComboBox->Visible && OwnerComboBox->Enabled)
+  {
+    ActiveControl = OwnerComboBox;
+  }
+  else if (GroupComboBox->Visible && GroupComboBox->Enabled)
+  {
+    ActiveControl = GroupComboBox;
+  }
+  else if (RightsFrame->Visible && RightsFrame->Enabled)
+  {
+    ActiveControl = RightsFrame;
+  }
+  else if (DebugAlwaysTrue(CancelButton->Visible && CancelButton->Enabled))
+  {
+    ActiveControl = CancelButton;
+  }
 
   if (DebugAlwaysTrue(FChecksumAlgs != NULL))
   {
@@ -228,6 +238,12 @@ void __fastcall TPropertiesDialog::LoadInfo()
     FilesSize += File->Size;
   }
 
+  LoadRemoteTokens(GroupComboBox, FGroupList);
+  LoadRemoteTokens(OwnerComboBox, FUserList);
+
+  FAnyDirectories = (Stats.Directories > 0);
+  RightsFrame->AllowAddXToDirectories = FAnyDirectories;
+
   if (!FMultiple)
   {
     // Show only file name, if we have only single file/directory.
@@ -235,13 +251,6 @@ void __fastcall TPropertiesDialog::LoadInfo()
     Stats = TCalculateSizeStats();
   }
 
-  LoadRemoteTokens(GroupComboBox, FGroupList);
-  LoadRemoteTokens(OwnerComboBox, FUserList);
-
-  RightsFrame->AllowAddXToDirectories = (Stats.Directories > 0);
-  RecursiveCheck->Visible = (Stats.Directories > 0);
-  RecursiveBevel->Visible = (Stats.Directories > 0);
-
   LoadStats(FilesSize, Stats);
 
   RightsFrame->AllowUndef = FMultiple;
@@ -260,10 +269,7 @@ void __fastcall TPropertiesDialog::LoadInfo()
       LinksToLabel->Caption = File->LinkTo;
     }
 
-    RightsFrame->AllowAddXToDirectories = File->IsDirectory;
     Caption = FMTLOAD(PROPERTIES_FILE_CAPTION, (File->FileName));
-    RecursiveCheck->Visible = File->IsDirectory;
-    RecursiveBevel->Visible = File->IsDirectory;
   }
   else
   {
@@ -375,7 +381,10 @@ void __fastcall TPropertiesDialog::SetFileProperties(const TRemoteProperties & v
   FOrigProperties.Valid = Valid;
   FOrigProperties.Recursive = false;
 
-  if (value.Valid.Contains(vpRights))
+  bool HasRights = value.Valid.Contains(vpRights);
+  RightsFrame->Visible = HasRights;
+  RightsLabel->Visible = RightsFrame->Visible;
+  if (HasRights)
   {
     RightsFrame->Rights = value.Rights;
     RightsFrame->AddXToDirectories = value.AddXToDirectories;
@@ -385,9 +394,27 @@ void __fastcall TPropertiesDialog::SetFileProperties(const TRemoteProperties & v
     RightsFrame->Rights = TRights();
     RightsFrame->AddXToDirectories = false;
   }
-  LoadRemoteToken(GroupComboBox, value.Valid.Contains(vpGroup), value.Group);
-  LoadRemoteToken(OwnerComboBox, value.Valid.Contains(vpOwner), value.Owner);
-  RecursiveCheck->Checked = value.Recursive;
+
+  bool HasGroup = value.Valid.Contains(vpGroup);
+  LoadRemoteToken(GroupComboBox, HasGroup, value.Group);
+  bool HasOwner = value.Valid.Contains(vpOwner);
+  LoadRemoteToken(OwnerComboBox, HasOwner, value.Owner);
+
+  bool HasGroupOrOwner = HasGroup || HasOwner;
+  bool HasAnything = HasGroupOrOwner || HasRights;
+  // Not necesarily true, let's find the scenario when it is not and then decide how to render that (shift rights up?)
+  DebugAssert(HasGroupOrOwner || !HasRights);
+  bool ShowGroupAndOwner = HasAnything;
+  OwnerComboBox->Visible = HasGroupOrOwner;
+  OwnerLabel->Visible = OwnerComboBox->Visible;
+  GroupComboBox->Visible = HasGroupOrOwner;
+  GroupLabel->Visible = GroupComboBox->Visible;
+  GroupOwnerRightsBevel->Visible = ShowGroupAndOwner;
+
+  RecursiveCheck2->Checked = value.Recursive;
+  RecursiveCheck2->Visible = HasAnything && FAnyDirectories;
+  RecursiveBevel->Visible = RecursiveCheck2->Visible || HasRights;
+
   UpdateControls();
 }
 //---------------------------------------------------------------------------
@@ -498,7 +525,7 @@ TRemoteProperties __fastcall TPropertiesDialog::GetFileProperties()
   StoreRemoteToken(OwnerComboBox, cpOwner, vpOwner, FOrigProperties.Owner,
     Result.Owner, PROPERTIES_INVALID_OWNER, FUserList, Result);
 
-  Result.Recursive = RecursiveCheck->Checked;
+  Result.Recursive = RecursiveCheck2->Checked;
 
   return Result;
 }
@@ -515,14 +542,14 @@ void __fastcall TPropertiesDialog::UpdateControls()
 {
   // No point enabling recursive check if there's no change allowed (supported),
   // i.e. with WebDAV.
-  EnableControl(RecursiveCheck, ((FAllowedChanges & (cpGroup | cpOwner | cpMode)) != 0));
+  EnableControl(RecursiveCheck2, ((FAllowedChanges & (cpGroup | cpOwner | cpMode)) != 0));
 
   bool Allow;
   try
   {
     Allow =
       !TRemoteProperties::ChangedProperties(FOrigProperties, GetFileProperties()).Valid.Empty() ||
-      (RecursiveCheck->Enabled && RecursiveCheck->Checked);
+      (RecursiveCheck2->Enabled && RecursiveCheck2->Checked);
   }
   catch(...)
   {
@@ -547,7 +574,7 @@ void __fastcall TPropertiesDialog::UpdateControls()
     bool AllowUndef =
       (FOrigProperties.Valid.Contains(vpRights) &&
        FOrigProperties.Rights.AllowUndef) ||
-      (RecursiveCheck->Checked);
+      (RecursiveCheck2->Checked);
     if (!AllowUndef)
     {
       // when disallowing undef state, make sure, all undef are turned into unset
@@ -781,7 +808,7 @@ void __fastcall TPropertiesDialog::CMDpiChanged(TMessage & Message)
   SizeLabel->Width = CalculateSizeButton->Left - ScaleByTextHeight(this, 8) - SizeLabel->Left;
   Bevel1->Width = CommonSheet->ClientWidth - (Bevel1->Left * 2);
   Bevel2->Width = Bevel1->Width;
-  Bevel3->Width = Bevel1->Width;
+  GroupOwnerRightsBevel->Width = Bevel1->Width;
   RecursiveBevel->Width = Bevel1->Width;
 }
 //---------------------------------------------------------------------------

+ 12 - 12
source/forms/Properties.dfm

@@ -138,7 +138,7 @@ object PropertiesDialog: TPropertiesDialog
         Anchors = [akLeft, akTop, akRight]
         Shape = bsTopLine
       end
-      object Label3: TLabel
+      object RightsLabel: TLabel
         Left = 8
         Top = 203
         Width = 59
@@ -146,7 +146,7 @@ object PropertiesDialog: TPropertiesDialog
         Caption = 'Permissions:'
         FocusControl = RightsFrame
       end
-      object Bevel3: TBevel
+      object GroupOwnerRightsBevel: TBevel
         Left = 8
         Top = 193
         Width = 320
@@ -154,17 +154,17 @@ object PropertiesDialog: TPropertiesDialog
         Anchors = [akLeft, akTop, akRight]
         Shape = bsTopLine
       end
-      object Label4: TLabel
+      object GroupLabel: TLabel
         Left = 8
-        Top = 138
+        Top = 166
         Width = 33
         Height = 13
         Caption = 'Group:'
         FocusControl = GroupComboBox
       end
-      object Label5: TLabel
+      object OwnerLabel: TLabel
         Left = 8
-        Top = 166
+        Top = 138
         Width = 36
         Height = 13
         Caption = 'Owner:'
@@ -194,35 +194,35 @@ object PropertiesDialog: TPropertiesDialog
       end
       object GroupComboBox: TComboBox
         Left = 85
-        Top = 135
+        Top = 163
         Width = 161
         Height = 21
         DropDownCount = 16
         MaxLength = 50
-        TabOrder = 1
+        TabOrder = 2
         Text = 'GroupComboBox'
         OnChange = ControlChange
         OnExit = GroupComboBoxExit
       end
       object OwnerComboBox: TComboBox
         Left = 85
-        Top = 163
+        Top = 135
         Width = 161
         Height = 21
         DropDownCount = 16
         MaxLength = 50
-        TabOrder = 2
+        TabOrder = 1
         Text = 'OwnerComboBox'
         OnChange = ControlChange
         OnExit = OwnerComboBoxExit
       end
-      object RecursiveCheck: TCheckBox
+      object RecursiveCheck2: TCheckBox
         Left = 12
         Top = 322
         Width = 317
         Height = 17
         Anchors = [akLeft, akTop, akRight]
-        Caption = 'Set group, owner and permissions &recursively'
+        Caption = 'Set owner, group and permissions &recursively'
         TabOrder = 4
         OnClick = ControlChange
       end

+ 6 - 5
source/forms/Properties.h

@@ -34,15 +34,15 @@ __published:
   TLabel *LinksToLabelLabel;
   TPathLabel *LinksToLabel;
   TBevel *Bevel2;
-  TLabel *Label3;
-  TBevel *Bevel3;
-  TLabel *Label4;
+  TLabel *RightsLabel;
+  TBevel *GroupOwnerRightsBevel;
+  TLabel *GroupLabel;
   TComboBox *GroupComboBox;
-  TLabel *Label5;
+  TLabel *OwnerLabel;
   TComboBox *OwnerComboBox;
   TImage *FileIconImage;
   TBevel *RecursiveBevel;
-  TCheckBox *RecursiveCheck;
+  TCheckBox *RecursiveCheck2;
   TButton *CalculateSizeButton;
   TRightsFrame *RightsFrame;
   TButton *HelpButton;
@@ -79,6 +79,7 @@ private:
   TStrings * FChecksumAlgs;
   TRemoteProperties FOrigProperties;
   bool FMultiple;
+  bool FAnyDirectories;
   bool FAllowCalculateStats;
   bool FStatsNotCalculated;
   TCalculateSizeEvent FOnCalculateSize;