View Issue Details

IDProjectCategoryView StatusLast Update
0000275Double CommanderGraphical user interfacepublic2011-12-03 06:48
Reporteroji Assigned ToAlexx2000  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
ProjectionnoneETAnone 
Product Version0.6.0 (trunk)Product Build4122M 
Fixed in Version0.5.5 
Summary0000275: Настройки цвета файлов / папок
DescriptionВ случае совпадения масок, приложение раскрашивает файлы / папки тем цветом, который находится в самом верху списка настроек. Поменять же порядок в этом списке можно только двумя способами — отредактировать файл конфигурации вручную или пересоздать его с нуля, с учётом нового порядка.

Также, фон списка всегда отображается системным фоном окна, — например, в моей конфигурации DC используется тёмно-синий фон и все цвета, соответственно, светлые, — их видно только при выделении курсором элемента.
TagsNo tags attached.
Attached Files
2011-11-30_20-51-00.png (22,746 bytes)   
2011-11-30_20-51-00.png (22,746 bytes)   
color_options.patch (11,868 bytes)   
Index: src/frames/foptionsfiletypescolors.lfm
===================================================================
--- src/frames/foptionsfiletypescolors.lfm	(revision 4122)
+++ src/frames/foptionsfiletypescolors.lfm	(working copy)
@@ -17,16 +17,16 @@
     BorderSpacing.Right = 8
     BorderSpacing.Bottom = 8
     Caption = 'File types colors'
-    ClientHeight = 320
+    ClientHeight = 324
     ClientWidth = 739
     TabOrder = 0
     object lblCategoryName: TLabel
       AnchorSideTop.Control = edtCategoryName
       AnchorSideTop.Side = asrCenter
       Left = 12
-      Height = 22
-      Top = 136
-      Width = 105
+      Height = 16
+      Top = 140
+      Width = 85
       Caption = 'Category name:'
       ParentColor = False
     end
@@ -34,9 +34,9 @@
       AnchorSideTop.Control = edtCategoryMask
       AnchorSideTop.Side = asrCenter
       Left = 12
-      Height = 22
-      Top = 173
-      Width = 103
+      Height = 16
+      Top = 171
+      Width = 83
       Caption = 'Category mask:'
       ParentColor = False
     end
@@ -44,9 +44,9 @@
       AnchorSideTop.Control = cbCategoryColor
       AnchorSideTop.Side = asrCenter
       Left = 12
-      Height = 22
-      Top = 244
-      Width = 99
+      Height = 16
+      Top = 233
+      Width = 82
       Caption = 'Category color:'
       ParentColor = False
     end
@@ -54,9 +54,9 @@
       AnchorSideTop.Control = edtCategoryAttr
       AnchorSideTop.Side = asrCenter
       Left = 12
-      Height = 22
-      Top = 210
-      Width = 132
+      Height = 16
+      Top = 202
+      Width = 105
       Caption = 'Category attributes:'
       ParentColor = False
     end
@@ -66,25 +66,25 @@
       AnchorSideRight.Control = lbCategories
       AnchorSideRight.Side = asrBottom
       Left = 174
-      Height = 29
-      Top = 133
+      Height = 23
+      Top = 137
       Width = 557
       Anchors = [akTop, akLeft, akRight]
       BorderSpacing.Top = 12
-      TabOrder = 0
+      TabOrder = 1
     end
     object edtCategoryMask: TEdit
       AnchorSideTop.Control = edtCategoryName
       AnchorSideTop.Side = asrBottom
       AnchorSideRight.Control = btnSearchTemplate
       Left = 174
-      Height = 29
-      Top = 170
+      Height = 23
+      Top = 168
       Width = 528
       Anchors = [akTop, akLeft, akRight]
       BorderSpacing.Top = 8
       BorderSpacing.Right = 6
-      TabOrder = 1
+      TabOrder = 2
     end
     object cbCategoryColor: TColorBox
       AnchorSideTop.Control = edtCategoryAttr
@@ -92,14 +92,14 @@
       AnchorSideRight.Control = btnCategoryColor
       Left = 174
       Height = 22
-      Top = 244
+      Top = 230
       Width = 523
       Style = [cbStandardColors, cbExtendedColors, cbSystemColors, cbPrettyNames]
       Anchors = [akTop, akLeft, akRight]
       BorderSpacing.Top = 8
       BorderSpacing.Right = 6
       ItemHeight = 16
-      TabOrder = 2
+      TabOrder = 5
     end
     object btnAddCategory: TBitBtn
       AnchorSideTop.Control = cbCategoryColor
@@ -107,7 +107,7 @@
       AnchorSideRight.Control = btnDeleteCategory
       Left = 389
       Height = 32
-      Top = 278
+      Top = 264
       Width = 110
       Anchors = [akTop, akRight]
       BorderSpacing.Left = 6
@@ -116,7 +116,7 @@
       Caption = 'Add'
       NumGlyphs = 0
       OnClick = btnAddCategoryClick
-      TabOrder = 3
+      TabOrder = 7
     end
     object btnDeleteCategory: TBitBtn
       AnchorSideTop.Control = cbCategoryColor
@@ -124,7 +124,7 @@
       AnchorSideRight.Control = btnApplyCategory
       Left = 505
       Height = 32
-      Top = 278
+      Top = 264
       Width = 110
       Anchors = [akTop, akRight]
       BorderSpacing.Top = 12
@@ -132,7 +132,7 @@
       Caption = 'Delete'
       NumGlyphs = 0
       OnClick = btnDeleteCategoryClick
-      TabOrder = 4
+      TabOrder = 8
     end
     object btnCategoryColor: TButton
       AnchorSideLeft.Side = asrBottom
@@ -143,30 +143,33 @@
       AnchorSideBottom.Side = asrBottom
       Left = 703
       Height = 22
-      Top = 244
+      Top = 230
       Width = 28
       Anchors = [akTop, akRight, akBottom]
       BorderSpacing.InnerBorder = 4
       Caption = '>>'
       OnClick = btnCategoryColorClick
-      TabOrder = 5
+      TabOrder = 6
     end
     object lbCategories: TListBox
       AnchorSideTop.Control = gbFileTypesColors
       AnchorSideRight.Control = gbFileTypesColors
       AnchorSideRight.Side = asrBottom
       Left = 12
-      Height = 115
+      Height = 119
       Top = 6
       Width = 719
       Anchors = [akTop, akLeft, akRight, akBottom]
       BorderSpacing.Top = 6
       BorderSpacing.Right = 8
+      DragMode = dmAutomatic
       ItemHeight = 0
       OnClick = lbCategoriesClick
+      OnDragDrop = lbCategoriesDragDrop
+      OnDragOver = lbCategoriesDragOver
       OnDrawItem = lbCategoriesDrawItem
       Style = lbOwnerDrawFixed
-      TabOrder = 6
+      TabOrder = 0
     end
     object btnApplyCategory: TBitBtn
       AnchorSideTop.Control = cbCategoryColor
@@ -175,14 +178,14 @@
       AnchorSideRight.Side = asrBottom
       Left = 621
       Height = 32
-      Top = 278
+      Top = 264
       Width = 110
       Anchors = [akTop, akRight]
       BorderSpacing.Top = 12
       Caption = 'Apply'
       NumGlyphs = 0
       OnClick = btnApplyCategoryClick
-      TabOrder = 7
+      TabOrder = 9
     end
     object edtCategoryAttr: TEdit
       AnchorSideTop.Control = edtCategoryMask
@@ -190,12 +193,12 @@
       AnchorSideRight.Control = lbCategories
       AnchorSideRight.Side = asrBottom
       Left = 174
-      Height = 29
-      Top = 207
+      Height = 23
+      Top = 199
       Width = 557
       Anchors = [akTop, akLeft, akRight]
       BorderSpacing.Top = 8
-      TabOrder = 8
+      TabOrder = 4
     end
     object btnSearchTemplate: TBitBtn
       AnchorSideTop.Control = edtCategoryMask
@@ -204,9 +207,9 @@
       AnchorSideBottom.Control = edtCategoryMask
       AnchorSideBottom.Side = asrBottom
       Left = 708
-      Height = 29
+      Height = 23
       Hint = 'Template...'
-      Top = 170
+      Top = 168
       Width = 23
       Anchors = [akTop, akRight, akBottom]
       Glyph.Data = {
@@ -249,7 +252,7 @@
       OnClick = btnSearchTemplateClick
       ParentShowHint = False
       ShowHint = True
-      TabOrder = 9
+      TabOrder = 3
     end
   end
   object optColorDialog: TColorDialog[1]
Index: src/frames/foptionsfiletypescolors.pas
===================================================================
--- src/frames/foptionsfiletypescolors.pas	(revision 4122)
+++ src/frames/foptionsfiletypescolors.pas	(working copy)
@@ -57,6 +57,9 @@
     procedure btnApplyCategoryClick(Sender: TObject);
     procedure btnDeleteCategoryClick(Sender: TObject);
     procedure btnCategoryColorClick(Sender: TObject);
+    procedure lbCategoriesDragDrop(Sender, Source: TObject; X, Y: Integer);
+    procedure lbCategoriesDragOver(Sender, Source: TObject; X, Y: Integer;
+      State: TDragState; var Accept: Boolean);
     procedure lbCategoriesDrawItem(Control: TWinControl; Index: Integer;
       ARect: TRect; State: TOwnerDrawState);
   protected
@@ -136,12 +139,13 @@
       btnDeleteCategory.Enabled := True;
       btnApplyCategory.Enabled := True;
     end;
-  iIndex := lbCategories.Items.AddObject('', nil);
+  iIndex := lbCategories.Items.AddObject('New', nil);
   lbCategories.ItemIndex := iIndex;
-  edtCategoryName.Text := '';
+  edtCategoryName.Text := 'New';
   edtCategoryMask.Text := '*';
   edtCategoryAttr.Text := '';
   cbCategoryColor.ItemIndex := -1;
+  edtCategoryName.SetFocus;
 end;
 
 procedure TfrmOptionsFileTypesColors.btnApplyCategoryClick(Sender: TObject);
@@ -149,47 +153,26 @@
   MaskItem : TMaskItem;
   I, iCount : Integer;
 begin
-  if btnDeleteCategory.Tag = 0 then // if we add or change category
-    begin
-      lbCategories.Items[lbCategories.ItemIndex] := edtCategoryName.Text;
-      MaskItem := TMaskItem.Create;
-      MaskItem.sName := edtCategoryName.Text;
-      MaskItem.cColor := cbCategoryColor.Selected;
-      if edtCategoryMask.Text = '' then
-        edtCategoryMask.Text := '*'; // because we load colors from ini by mask
-      MaskItem.sExt := edtCategoryMask.Text;
-      MaskItem.sModeStr := edtCategoryAttr.Text;
-      lbCategories.Items.Objects[lbCategories.ItemIndex] := MaskItem;
-      if lbCategories.ItemIndex >= gColorExt.MaskItemList.Count then
-        gColorExt.MaskItemList.Add(MaskItem)
-      else
-        begin
-          TMaskItem(gColorExt.MaskItemList.Items[lbCategories.ItemIndex]).Free;
-          gColorExt.MaskItemList.Items[lbCategories.ItemIndex] := MaskItem;
-        end;
-
-    end
-  else  // if we delete category
-    begin
-      iCount := gColorExt.MaskItemList.Count - 1;
-      for I := iCount downto 0 do  // delete old categories
-        begin
-          gColorExt.MaskItemList.Delete(I);
-        end;
-      iCount := lbCategories.Count;
-      for I := 0 to iCount - 1 do  //write new categories
-        begin
-          gColorExt.MaskItemList.Add(lbCategories.Items.Objects[I]);
-        end;
-    end; // delete category
-
-    btnDeleteCategory.Tag := 0;
+  lbCategories.Items[lbCategories.ItemIndex] := edtCategoryName.Text;
+  MaskItem := TMaskItem.Create;
+  try
+    MaskItem.sName := edtCategoryName.Text;
+    MaskItem.cColor := cbCategoryColor.Selected;
+    if edtCategoryMask.Text = '' then
+      edtCategoryMask.Text := '*'; // because we load colors from ini by mask
+    MaskItem.sExt := edtCategoryMask.Text;
+    MaskItem.sModeStr := edtCategoryAttr.Text;
+    lbCategories.Items.Objects[lbCategories.ItemIndex] := MaskItem;
+  except
+    FreeAndNil(MaskItem);
+    raise;
+  end;
 end;
 
 procedure TfrmOptionsFileTypesColors.btnDeleteCategoryClick(Sender: TObject);
 begin
+  lbCategories.Items.Objects[lbCategories.ItemIndex].Free;
   lbCategories.Items.Delete(lbCategories.ItemIndex);
-  btnDeleteCategory.Tag := 1; // show that we delete category
   if lbCategories.Count > 0 then
     lbCategories.ItemIndex := 0;
   lbCategoriesClick(lbCategories);
@@ -202,6 +185,28 @@
     SetColorInColorBox(cbCategoryColor, optColorDialog.Color);
 end;
 
+procedure TfrmOptionsFileTypesColors.lbCategoriesDragDrop(Sender,
+  Source: TObject; X, Y: Integer);
+var
+  SrcIndex, DestIndex: Integer;
+begin
+  SrcIndex := lbCategories.ItemIndex;
+  if SrcIndex = -1 then
+    Exit;
+  DestIndex := lbCategories.GetIndexAtY(Y);
+  if (DestIndex < 0) or (DestIndex >= lbCategories.Count) then
+    DestIndex := lbCategories.Count - 1;
+
+  lbCategories.Items.Move(SrcIndex, DestIndex);
+  lbCategories.ItemIndex := DestIndex;
+end;
+
+procedure TfrmOptionsFileTypesColors.lbCategoriesDragOver(Sender,
+  Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean);
+begin
+  Accept := (Source = lbCategories) and (lbCategories.ItemIndex <> -1);
+end;
+
 procedure TfrmOptionsFileTypesColors.lbCategoriesDrawItem(Control: TWinControl;
   Index: Integer; ARect: TRect; State: TOwnerDrawState);
 begin
@@ -263,8 +268,16 @@
 end;
 
 function TfrmOptionsFileTypesColors.Save: TOptionsEditorSaveFlags;
+var
+  i: Integer;
 begin
   Result := [];
+  for I := gColorExt.MaskItemList.Count - 1 downto 0 do  // delete old categories
+    gColorExt.MaskItemList.Delete(I);
+
+  for I := 0 to lbCategories.Count - 1 do  //write new categories
+    if Assigned(lbCategories.Items.Objects[I]) then
+      gColorExt.MaskItemList.Add(lbCategories.Items.Objects[I]);
 end;
 
 end.
color_options.patch (11,868 bytes)   
color_options2.patch (17,631 bytes)   
Index: src/frames/foptionsfiletypescolors.lfm
===================================================================
--- src/frames/foptionsfiletypescolors.lfm	(revision 4122)
+++ src/frames/foptionsfiletypescolors.lfm	(working copy)
@@ -17,16 +17,16 @@
     BorderSpacing.Right = 8
     BorderSpacing.Bottom = 8
     Caption = 'File types colors'
-    ClientHeight = 320
+    ClientHeight = 324
     ClientWidth = 739
     TabOrder = 0
     object lblCategoryName: TLabel
       AnchorSideTop.Control = edtCategoryName
       AnchorSideTop.Side = asrCenter
       Left = 12
-      Height = 22
-      Top = 136
-      Width = 105
+      Height = 14
+      Top = 140
+      Width = 79
       Caption = 'Category name:'
       ParentColor = False
     end
@@ -34,9 +34,9 @@
       AnchorSideTop.Control = edtCategoryMask
       AnchorSideTop.Side = asrCenter
       Left = 12
-      Height = 22
-      Top = 173
-      Width = 103
+      Height = 14
+      Top = 169
+      Width = 77
       Caption = 'Category mask:'
       ParentColor = False
     end
@@ -44,9 +44,9 @@
       AnchorSideTop.Control = cbCategoryColor
       AnchorSideTop.Side = asrCenter
       Left = 12
-      Height = 22
-      Top = 244
-      Width = 99
+      Height = 14
+      Top = 228
+      Width = 76
       Caption = 'Category color:'
       ParentColor = False
     end
@@ -54,9 +54,9 @@
       AnchorSideTop.Control = edtCategoryAttr
       AnchorSideTop.Side = asrCenter
       Left = 12
-      Height = 22
-      Top = 210
-      Width = 132
+      Height = 14
+      Top = 198
+      Width = 100
       Caption = 'Category attributes:'
       ParentColor = False
     end
@@ -66,25 +66,25 @@
       AnchorSideRight.Control = lbCategories
       AnchorSideRight.Side = asrBottom
       Left = 174
-      Height = 29
-      Top = 133
+      Height = 21
+      Top = 137
       Width = 557
       Anchors = [akTop, akLeft, akRight]
       BorderSpacing.Top = 12
-      TabOrder = 0
+      TabOrder = 1
     end
     object edtCategoryMask: TEdit
       AnchorSideTop.Control = edtCategoryName
       AnchorSideTop.Side = asrBottom
       AnchorSideRight.Control = btnSearchTemplate
       Left = 174
-      Height = 29
-      Top = 170
+      Height = 21
+      Top = 166
       Width = 528
       Anchors = [akTop, akLeft, akRight]
       BorderSpacing.Top = 8
       BorderSpacing.Right = 6
-      TabOrder = 1
+      TabOrder = 2
     end
     object cbCategoryColor: TColorBox
       AnchorSideTop.Control = edtCategoryAttr
@@ -92,14 +92,14 @@
       AnchorSideRight.Control = btnCategoryColor
       Left = 174
       Height = 22
-      Top = 244
+      Top = 224
       Width = 523
       Style = [cbStandardColors, cbExtendedColors, cbSystemColors, cbPrettyNames]
       Anchors = [akTop, akLeft, akRight]
       BorderSpacing.Top = 8
       BorderSpacing.Right = 6
       ItemHeight = 16
-      TabOrder = 2
+      TabOrder = 5
     end
     object btnAddCategory: TBitBtn
       AnchorSideTop.Control = cbCategoryColor
@@ -107,7 +107,7 @@
       AnchorSideRight.Control = btnDeleteCategory
       Left = 389
       Height = 32
-      Top = 278
+      Top = 258
       Width = 110
       Anchors = [akTop, akRight]
       BorderSpacing.Left = 6
@@ -116,7 +116,7 @@
       Caption = 'Add'
       NumGlyphs = 0
       OnClick = btnAddCategoryClick
-      TabOrder = 3
+      TabOrder = 7
     end
     object btnDeleteCategory: TBitBtn
       AnchorSideTop.Control = cbCategoryColor
@@ -124,7 +124,7 @@
       AnchorSideRight.Control = btnApplyCategory
       Left = 505
       Height = 32
-      Top = 278
+      Top = 258
       Width = 110
       Anchors = [akTop, akRight]
       BorderSpacing.Top = 12
@@ -132,7 +132,7 @@
       Caption = 'Delete'
       NumGlyphs = 0
       OnClick = btnDeleteCategoryClick
-      TabOrder = 4
+      TabOrder = 8
     end
     object btnCategoryColor: TButton
       AnchorSideLeft.Side = asrBottom
@@ -143,30 +143,33 @@
       AnchorSideBottom.Side = asrBottom
       Left = 703
       Height = 22
-      Top = 244
+      Top = 224
       Width = 28
       Anchors = [akTop, akRight, akBottom]
       BorderSpacing.InnerBorder = 4
       Caption = '>>'
       OnClick = btnCategoryColorClick
-      TabOrder = 5
+      TabOrder = 6
     end
     object lbCategories: TListBox
       AnchorSideTop.Control = gbFileTypesColors
       AnchorSideRight.Control = gbFileTypesColors
       AnchorSideRight.Side = asrBottom
       Left = 12
-      Height = 115
+      Height = 119
       Top = 6
       Width = 719
       Anchors = [akTop, akLeft, akRight, akBottom]
       BorderSpacing.Top = 6
       BorderSpacing.Right = 8
+      DragMode = dmAutomatic
       ItemHeight = 0
       OnClick = lbCategoriesClick
+      OnDragDrop = lbCategoriesDragDrop
+      OnDragOver = lbCategoriesDragOver
       OnDrawItem = lbCategoriesDrawItem
       Style = lbOwnerDrawFixed
-      TabOrder = 6
+      TabOrder = 0
     end
     object btnApplyCategory: TBitBtn
       AnchorSideTop.Control = cbCategoryColor
@@ -175,14 +178,14 @@
       AnchorSideRight.Side = asrBottom
       Left = 621
       Height = 32
-      Top = 278
+      Top = 258
       Width = 110
       Anchors = [akTop, akRight]
       BorderSpacing.Top = 12
       Caption = 'Apply'
       NumGlyphs = 0
       OnClick = btnApplyCategoryClick
-      TabOrder = 7
+      TabOrder = 9
     end
     object edtCategoryAttr: TEdit
       AnchorSideTop.Control = edtCategoryMask
@@ -190,12 +193,12 @@
       AnchorSideRight.Control = lbCategories
       AnchorSideRight.Side = asrBottom
       Left = 174
-      Height = 29
-      Top = 207
+      Height = 21
+      Top = 195
       Width = 557
       Anchors = [akTop, akLeft, akRight]
       BorderSpacing.Top = 8
-      TabOrder = 8
+      TabOrder = 4
     end
     object btnSearchTemplate: TBitBtn
       AnchorSideTop.Control = edtCategoryMask
@@ -204,9 +207,9 @@
       AnchorSideBottom.Control = edtCategoryMask
       AnchorSideBottom.Side = asrBottom
       Left = 708
-      Height = 29
+      Height = 21
       Hint = 'Template...'
-      Top = 170
+      Top = 166
       Width = 23
       Anchors = [akTop, akRight, akBottom]
       Glyph.Data = {
@@ -249,7 +252,7 @@
       OnClick = btnSearchTemplateClick
       ParentShowHint = False
       ShowHint = True
-      TabOrder = 9
+      TabOrder = 3
     end
   end
   object optColorDialog: TColorDialog[1]
Index: src/frames/foptionsfiletypescolors.pas
===================================================================
--- src/frames/foptionsfiletypescolors.pas	(revision 4122)
+++ src/frames/foptionsfiletypescolors.pas	(working copy)
@@ -51,12 +51,16 @@
     lblCategoryColor: TLabel;
     lblCategoryMask: TLabel;
     lblCategoryName: TLabel;
+
     procedure lbCategoriesClick(Sender: TObject);
     procedure btnSearchTemplateClick(Sender: TObject);
     procedure btnAddCategoryClick(Sender: TObject);
     procedure btnApplyCategoryClick(Sender: TObject);
     procedure btnDeleteCategoryClick(Sender: TObject);
     procedure btnCategoryColorClick(Sender: TObject);
+    procedure lbCategoriesDragDrop(Sender, Source: TObject; X, Y: Integer);
+    procedure lbCategoriesDragOver(Sender, Source: TObject; X, Y: Integer;
+      State: TDragState; var Accept: Boolean);
     procedure lbCategoriesDrawItem(Control: TWinControl; Index: Integer;
       ARect: TRect; State: TOwnerDrawState);
   protected
@@ -82,28 +86,24 @@
   MaskItem : TMaskItem;
   bEnabled: Boolean;
 begin
-  if (lbCategories.Count > 0) and (Assigned(lbCategories.Items.Objects[lbCategories.ItemIndex])) then
+  if (lbCategories.ItemIndex <> -1) then
     begin
-      edtCategoryName.Text := lbCategories.Items[lbCategories.ItemIndex];
       MaskItem := TMaskItem(lbCategories.Items.Objects[lbCategories.ItemIndex]);
 
+      edtCategoryName.Text := MaskItem.sName;
       edtCategoryMask.Text := MaskItem.sExt;
       SetColorInColorBox(cbCategoryColor, MaskItem.cColor);
-      bEnabled:= Pos('>', MaskItem.sExt) <> 1;
+      bEnabled:= (MaskItem.sExt = '') or (MaskItem.sExt[1] <> '>');
       edtCategoryMask.Enabled:= bEnabled;
       edtCategoryAttr.Enabled:= bEnabled;
       edtCategoryAttr.Text := MaskItem.sModeStr;
     end
   else
     begin
-      if lbCategories.Count = 0 then
-        edtCategoryName.Text := ''
-      else
-        edtCategoryName.Text := lbCategories.Items[lbCategories.ItemIndex];
-      edtCategoryMask.Text := '*';
+      edtCategoryName.Text := '';
+      edtCategoryMask.Text := '';
       edtCategoryAttr.Text := '';
       cbCategoryColor.ItemIndex := -1;
-      cbCategoryColor.Selected := clWindow;
     end;
 end;
 
@@ -125,6 +125,7 @@
 procedure TfrmOptionsFileTypesColors.btnAddCategoryClick(Sender: TObject);
 var
   iIndex : Integer;
+  MaskItem: TMaskItem;
 begin
   if lbCategories.Count = 0 then
     begin
@@ -136,12 +137,25 @@
       btnDeleteCategory.Enabled := True;
       btnApplyCategory.Enabled := True;
     end;
-  iIndex := lbCategories.Items.AddObject('', nil);
-  lbCategories.ItemIndex := iIndex;
-  edtCategoryName.Text := '';
-  edtCategoryMask.Text := '*';
-  edtCategoryAttr.Text := '';
-  cbCategoryColor.ItemIndex := -1;
+
+  MaskItem := TMaskItem.Create;
+  try
+   edtCategoryName.Text := 'New';
+   edtCategoryMask.Text := '*';
+   edtCategoryAttr.Text := '';
+   cbCategoryColor.ItemIndex := -1;
+
+   MaskItem.sName:= edtCategoryName.Text;
+   MaskItem.sExt:= edtCategoryMask.Text;
+   MaskItem.sModeStr:= edtCategoryAttr.Text;
+   MaskItem.cColor:= clBlack;
+   iIndex := lbCategories.Items.AddObject(MaskItem.sName, MaskItem);
+  except
+    FreeAndNil(MaskItem);
+    raise;
+  end;
+  lbCategories.ItemIndex:= iIndex;
+  edtCategoryName.SetFocus;
 end;
 
 procedure TfrmOptionsFileTypesColors.btnApplyCategoryClick(Sender: TObject);
@@ -149,50 +163,30 @@
   MaskItem : TMaskItem;
   I, iCount : Integer;
 begin
-  if btnDeleteCategory.Tag = 0 then // if we add or change category
-    begin
-      lbCategories.Items[lbCategories.ItemIndex] := edtCategoryName.Text;
-      MaskItem := TMaskItem.Create;
-      MaskItem.sName := edtCategoryName.Text;
-      MaskItem.cColor := cbCategoryColor.Selected;
-      if edtCategoryMask.Text = '' then
-        edtCategoryMask.Text := '*'; // because we load colors from ini by mask
-      MaskItem.sExt := edtCategoryMask.Text;
-      MaskItem.sModeStr := edtCategoryAttr.Text;
-      lbCategories.Items.Objects[lbCategories.ItemIndex] := MaskItem;
-      if lbCategories.ItemIndex >= gColorExt.MaskItemList.Count then
-        gColorExt.MaskItemList.Add(MaskItem)
-      else
-        begin
-          TMaskItem(gColorExt.MaskItemList.Items[lbCategories.ItemIndex]).Free;
-          gColorExt.MaskItemList.Items[lbCategories.ItemIndex] := MaskItem;
-        end;
+  if (lbCategories.ItemIndex <> -1) then
+  begin
+    lbCategories.Items[lbCategories.ItemIndex] := edtCategoryName.Text;
+    if edtCategoryMask.Text = '' then
+      edtCategoryMask.Text := '*'; // because we load colors from ini by mask
+    MaskItem := TMaskItem(lbCategories.Items.Objects[lbCategories.ItemIndex]);
 
-    end
-  else  // if we delete category
-    begin
-      iCount := gColorExt.MaskItemList.Count - 1;
-      for I := iCount downto 0 do  // delete old categories
-        begin
-          gColorExt.MaskItemList.Delete(I);
-        end;
-      iCount := lbCategories.Count;
-      for I := 0 to iCount - 1 do  //write new categories
-        begin
-          gColorExt.MaskItemList.Add(lbCategories.Items.Objects[I]);
-        end;
-    end; // delete category
-
-    btnDeleteCategory.Tag := 0;
+    MaskItem.sName := edtCategoryName.Text;
+    MaskItem.cColor := cbCategoryColor.Selected;
+    MaskItem.sExt := edtCategoryMask.Text;
+    MaskItem.sModeStr := edtCategoryAttr.Text;
+  end;
 end;
 
 procedure TfrmOptionsFileTypesColors.btnDeleteCategoryClick(Sender: TObject);
 begin
-  lbCategories.Items.Delete(lbCategories.ItemIndex);
-  btnDeleteCategory.Tag := 1; // show that we delete category
-  if lbCategories.Count > 0 then
-    lbCategories.ItemIndex := 0;
-  lbCategoriesClick(lbCategories);
+  if (lbCategories.ItemIndex <> -1) then
+  begin
+    lbCategories.Items.Objects[lbCategories.ItemIndex].Free;
+    lbCategories.Items.Delete(lbCategories.ItemIndex);
+    if lbCategories.Count > 0 then
+      lbCategories.ItemIndex := 0;
+    lbCategoriesClick(lbCategories);
+  end;
 end;
 
 procedure TfrmOptionsFileTypesColors.btnCategoryColorClick(Sender: TObject);
@@ -202,6 +196,28 @@
     SetColorInColorBox(cbCategoryColor, optColorDialog.Color);
 end;
 
+procedure TfrmOptionsFileTypesColors.lbCategoriesDragDrop(Sender,
+  Source: TObject; X, Y: Integer);
+var
+  SrcIndex, DestIndex: Integer;
+begin
+  SrcIndex := lbCategories.ItemIndex;
+  if SrcIndex = -1 then
+    Exit;
+  DestIndex := lbCategories.GetIndexAtY(Y);
+  if (DestIndex < 0) or (DestIndex >= lbCategories.Count) then
+    DestIndex := lbCategories.Count - 1;
+
+  lbCategories.Items.Move(SrcIndex, DestIndex);
+  lbCategories.ItemIndex := DestIndex;
+end;
+
+procedure TfrmOptionsFileTypesColors.lbCategoriesDragOver(Sender,
+  Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean);
+begin
+  Accept := (Source = lbCategories) and (lbCategories.ItemIndex <> -1);
+end;
+
 procedure TfrmOptionsFileTypesColors.lbCategoriesDrawItem(Control: TWinControl;
   Index: Integer; ARect: TRect; State: TOwnerDrawState);
 begin
@@ -235,16 +251,22 @@
 
 procedure TfrmOptionsFileTypesColors.Load;
 var
-  sCategoryName : String;
   I : Integer;
+  MaskItem: TMaskItem;
 begin
   lbCategories.Clear;
 
   { File lbtypes category color }
-  for I := 0 to gColorExt.MaskItemList.Count - 1 do
+  for I := 0 to gColorExt.Count - 1 do
     begin
-      sCategoryName := TMaskItem(gColorExt.MaskItemList.Items[I]).sName;
-      lbCategories.Items.AddObject(sCategoryName,TMaskItem(gColorExt.MaskItemList.Items[I]));
+      MaskItem := TMaskItem.Create;
+      try
+       MaskItem.Assign(gColorExt[I]);
+       lbCategories.Items.AddObject(MaskItem.sName, MaskItem);
+      except
+        FreeAndNil(MaskItem);
+        raise;
+      end;
     end; // for
 
     if lbCategories.Count > 0 then
@@ -263,8 +285,25 @@
 end;
 
 function TfrmOptionsFileTypesColors.Save: TOptionsEditorSaveFlags;
+var
+  i: Integer;
+  MaskItem: TMaskItem;
 begin
   Result := [];
+  gColorExt.Clear;
+
+  for I := 0 to lbCategories.Count - 1 do  //write new categories
+    if Assigned(lbCategories.Items.Objects[I]) then
+    begin
+      MaskItem := TMaskItem.Create;
+      try
+       MaskItem.Assign(TMaskItem(lbCategories.Items.Objects[I]));
+       gColorExt.Add(MaskItem);
+      except
+        FreeAndNil(MaskItem);
+        raise;
+      end;
+    end;
 end;
 
 end.
Index: src/uColorExt.pas
===================================================================
--- src/uColorExt.pas	(revision 4122)
+++ src/uColorExt.pas	(working copy)
@@ -35,10 +35,13 @@
   { TMaskItem }
 
   TMaskItem = class
+  public
     sExt: String;
     sModeStr: String;
     cColor: TColor;
     sName: String;
+
+    procedure Assign(ASource: TMaskItem);
   end;
 
   { TColorExt }
@@ -46,12 +49,17 @@
   TColorExt = class
   private
     fOldCount: Integer;
-  protected
     lslist: TList;
+
+    function GetCount: Integer;
+    function GetItems(const Index: Integer): TMaskItem;
   public
     constructor Create;
     destructor Destroy; override;
+
     procedure Clear;
+    procedure Add(AItem: TMaskItem);
+
     function GetColorByExt(const sExt: String): TColor;
     function GetColorByAttr(const sModeStr: String): TColor;
     function GetColorBy(const AFile: TFile): TColor;
@@ -59,7 +67,9 @@
     procedure SaveIni;
     procedure Load(AConfig: TXmlConfig; ANode: TXmlNode);
     procedure Save(AConfig: TXmlConfig; ANode: TXmlNode);
-    property  MaskItemList: TList read lslist;
+
+    property Count: Integer read GetCount;
+    property Items[const Index: Integer]: TMaskItem read GetItems; default;
   end;
 
 implementation
@@ -67,6 +77,27 @@
 uses
   SysUtils, uDebug, uGlobs, uMasks, uFileProperty;
 
+{ TMaskItem }
+
+procedure TMaskItem.Assign(ASource: TMaskItem);
+begin
+  Assert(Assigned(ASource));
+  sExt := ASource.sExt;
+  sModeStr := ASource.sModeStr;
+  cColor := ASource.cColor;
+  sName := ASource.sName;
+end;
+
+function TColorExt.GetCount: Integer;
+begin
+  Result := lslist.Count;
+end;
+
+function TColorExt.GetItems(const Index: Integer): TMaskItem;
+begin
+  Result := TMaskItem(lslist[Index]);
+end;
+
 constructor TColorExt.Create;
 begin
   inherited;
@@ -75,11 +106,9 @@
 
 destructor TColorExt.Destroy;
 begin
-  if assigned(lsList) then
-    begin
-      Clear;
-      FreeAndNil(lsList);
-    end;
+  Clear;
+  FreeAndNil(lsList);
+  inherited;
 end;
 
 procedure TColorExt.Clear;
@@ -91,6 +120,11 @@
     end;
 end;
 
+procedure TColorExt.Add(AItem: TMaskItem);
+begin
+  lslist.Add(AItem);
+end;
+
 function TColorExt.GetColorByExt(const sExt: String): TColor;
 var I:integer;
 begin
@@ -316,4 +350,4 @@
     end;
 end;
 
-end.
+end.
color_options2.patch (17,631 bytes)   
color_options3.patch (1,430 bytes)   
Index: src/frames/foptionsfiletypescolors.pas
===================================================================
--- src/frames/foptionsfiletypescolors.pas	(revision 4125)
+++ src/frames/foptionsfiletypescolors.pas	(working copy)
@@ -63,11 +63,15 @@
       State: TDragState; var Accept: Boolean);
     procedure lbCategoriesDrawItem(Control: TWinControl; Index: Integer;
       ARect: TRect; State: TOwnerDrawState);
+
+    procedure Clear;
   protected
     procedure Init; override;
     procedure Load; override;
     function Save: TOptionsEditorSaveFlags; override;
   public
+    destructor Destroy; override;
+
     class function GetIconIndex: Integer; override;
     class function GetTitle: String; override;
   end;
@@ -233,6 +237,16 @@
    end;
 end;
 
+procedure TfrmOptionsFileTypesColors.Clear;
+var
+  i: Integer;
+begin
+  for i := lbCategories.Count - 1 downto 0 do
+    lbCategories.Items.Objects[i].Free;
+
+  lbCategories.Clear;
+end;
+
 procedure TfrmOptionsFileTypesColors.Init;
 begin
   lbCategories.Canvas.Font := lbCategories.Font;
@@ -254,7 +268,7 @@
   I : Integer;
   MaskItem: TMaskItem;
 begin
-  lbCategories.Clear;
+  Clear;
 
   { File lbtypes category color }
   for I := 0 to gColorExt.Count - 1 do
@@ -306,5 +320,11 @@
     end;
 end;
 
+destructor TfrmOptionsFileTypesColors.Destroy;
+begin
+  Clear;
+  inherited;
+end;
+
 end.
 
color_options3.patch (1,430 bytes)   
Fixed in Revision4129
Operating systemWindows
Widgetset
Architecture64-bit

Activities

vitaliyg

2011-11-30 18:50

developer   ~0000232

Сделал поддержку Drag & Drop

vitaliyg

2011-12-01 00:43

developer   ~0000234

Исправил некоторые недоделки в первом патче
Надо испольвовать токо второй патч

oji

2011-12-01 03:13

reporter   ~0000236

Ок, только, по-моему, это неочевидно. Может, подсказка какая? При наведении курсора или обычным лейблом?

Alexx2000

2011-12-01 10:46

administrator   ~0000242

Патч применил (revision: 4123)

vitaliyg

2011-12-01 14:09

developer   ~0000244

И еще один фикс надо залить поверх второго патча

Alexx2000

2011-12-01 15:09

administrator   ~0000246

>И еще один фикс надо залить поверх второго патча

Применил

>Также, фон списка всегда отображается системным фоном окна

Исправил, теперь используется тот же цвет, что и в панели (r4126)

Alexx2000

2011-12-02 21:49

administrator   ~0000255

>Может, подсказка какая? При наведении курсора или обычным лейблом?

Добавил подсказку в заголовок панели, пойдет?

oji

2011-12-03 06:47

reporter   ~0000256

> Добавил подсказку в заголовок панели, пойдет?
Да, отлично

vitaliyg, Alexx2000, спасибо за оперативное решение проблемы.

Issue History

Date Modified Username Field Change
2011-11-30 13:56 oji New Issue
2011-11-30 13:56 oji File Added: 2011-11-30_20-51-00.png
2011-11-30 18:49 vitaliyg File Added: color_options.patch
2011-11-30 18:50 vitaliyg Note Added: 0000232
2011-12-01 00:42 vitaliyg File Added: color_options2.patch
2011-12-01 00:43 vitaliyg Note Added: 0000234
2011-12-01 00:44 vitaliyg Status new => feedback
2011-12-01 03:13 oji Note Added: 0000236
2011-12-01 03:13 oji Status feedback => new
2011-12-01 10:46 Alexx2000 Note Added: 0000242
2011-12-01 14:08 vitaliyg File Added: color_options3.patch
2011-12-01 14:09 vitaliyg Note Added: 0000244
2011-12-01 15:09 Alexx2000 Note Added: 0000246
2011-12-02 21:48 Alexx2000 Assigned To => Alexx2000
2011-12-02 21:48 Alexx2000 Status new => assigned
2011-12-02 21:49 Alexx2000 Fixed in Revision => 4129
2011-12-02 21:49 Alexx2000 Note Added: 0000255
2011-12-02 21:49 Alexx2000 Status assigned => resolved
2011-12-02 21:49 Alexx2000 Fixed in Version => 0.5.5
2011-12-02 21:49 Alexx2000 Resolution open => fixed
2011-12-03 06:47 oji Note Added: 0000256
2011-12-03 06:48 oji Status resolved => closed