OSDN Git Service

カラムソートのカラム位置に対する依存性を改善(不完全)。
[gikonavigoeson/gikonavi.git] / Sort.pas
index 41160a6..a695b5d 100644 (file)
--- a/Sort.pas
+++ b/Sort.pas
@@ -3,7 +3,8 @@ unit Sort;
 interface
 uses
        Windows, Messages, SysUtils, Classes, Controls, Forms,
-       BoardGroup,DateUtils;
+       BoardGroup,DateUtils,
+       Setting;
 
        function CategorySortProc(Item1, Item2: Pointer): integer;
        function BoardSortProc(List: TStringList; Item1, Item2: Integer): integer;
@@ -28,10 +29,13 @@ begin
        CategoryItem1 := TCategory(Item1);
        CategoryItem2 := TCategory(Item2);
 
-       if SortNoFlag then
-               Result := CompareInt(CategoryItem1.No, CategoryItem2.No)
-       else
-               Result := AnsiCompareText(CategoryItem1.Title, CategoryItem2.Title);
+       case TGikoBBSColumnID( SortIndex ) of
+       gbbscTitle:
+               if SortNoFlag then
+                       Result := CompareInt(CategoryItem1.No, CategoryItem2.No)
+               else
+                       Result := AnsiCompareText(CategoryItem1.Title, CategoryItem2.Title);
+       end;
 
        if not SortOrder then
                Result := Result * -1;
@@ -44,15 +48,19 @@ var
 begin
        BoardItem1 := TBoard(List.Objects[Item1]);
        BoardItem2 := TBoard(List.Objects[Item2]);
-       if SortIndex = 0 then
+       case TGikoCategoryColumnID( SortIndex ) of
+       gccTitle:
                if SortNoFlag then
                        Result := CompareInt(BoardItem1.No, BoardItem2.No)
                else
-                       Result := AnsiCompareText(BoardItem1.Title, BoardItem2.Title)
-       else if SortIndex = 1 then
-               Result := CompareInt(BoardItem1.Count, BoardItem2.Count)
-    else
+                       Result := AnsiCompareText(BoardItem1.Title, BoardItem2.Title);
+
+       gccRoundName:
+               Result := CompareInt(BoardItem1.Count, BoardItem2.Count);
+
+       gccLastModified:
                Result := CompareDate(BoardItem1.RoundDate, BoardItem2.RoundDate);
+       end;
 
        if not SortOrder then
                Result := Result * -1;
@@ -65,34 +73,34 @@ var
 begin
        ThreadItem1 := TThreadItem(List.Objects[ Item1 ]);
        ThreadItem2 := TThreadItem(List.Objects[ Item2 ]);
-       case SortIndex of
-               0:
+       case TGikoBoardColumnID( SortIndex ) of
+               gbcTitle:
                        begin
                                if SortNoFlag then
                                        Result := CompareInt(ThreadItem1.No, ThreadItem2.No)
                                else
                                        Result := AnsiCompareText(ThreadItem1.Title, ThreadItem2.Title)
                        end;
-               1: Result := CompareInt(ThreadItem1.AllResCount, ThreadItem2.AllResCount);
-               2:
+
+               gbcAllCount:                    Result := CompareInt(ThreadItem1.AllResCount, ThreadItem2.AllResCount);
+               gbcLocalCount:          Result := CompareInt(ThreadItem1.Count, ThreadItem2.Count);
+               gbcNonAcqCount:
                        begin
-                               if SortNonAcquiredCountFlag then
-                                       if ThreadItem1.IsLogFile and ThreadItem2.IsLogFile then
-                                               Result := CompareInt(ThreadItem1.AllResCount - ThreadItem1.Count, ThreadItem2.AllResCount - ThreadItem2.Count)
-                                       else if ThreadItem1.IsLogFile then
-                                               Result := 1
-                                       else if ThreadItem2.IsLogFile then
-                                               Result := -1
-                                       else
-                                               Result := 0
+                               if ThreadItem1.IsLogFile and ThreadItem2.IsLogFile then
+                                       Result := CompareInt(ThreadItem1.AllResCount - ThreadItem1.Count, ThreadItem2.AllResCount - ThreadItem2.Count)
+                               else if ThreadItem1.IsLogFile then
+                                       Result := 1
+                               else if ThreadItem2.IsLogFile then
+                                       Result := -1
                                else
-                                       Result := CompareInt(ThreadItem1.Count, ThreadItem2.Count);
+                                       Result := 0;
                        end;
-               3: Result := CompareInt(ThreadItem1.NewResCount, ThreadItem2.NewResCount);
-               4: Result := 0;
-               5: Result := AnsiCompareText(ThreadItem1.RoundName, ThreadItem2.RoundName);
-               6: Result := CompareDateTime(ThreadItem1.RoundDate, ThreadItem2.RoundDate);
-               7: Result := CompareDateTime(ThreadItem1.CreateDate, ThreadItem2.CreateDate);
+
+               gbcNewCount:                    Result := CompareInt(ThreadItem1.NewResCount, ThreadItem2.NewResCount);
+               gbcUnReadCount:         Result := 0;
+               gbcRoundName:           Result := AnsiCompareText(ThreadItem1.RoundName, ThreadItem2.RoundName);
+               gbcLastModified:        Result := CompareDateTime(ThreadItem1.RoundDate, ThreadItem2.RoundDate);
+               gbcCreated:                             Result := CompareDateTime(ThreadItem1.CreateDate, ThreadItem2.CreateDate);
        else
                Result := 0;
        end;