UPD: Made cm_ReverseOrder work for any file view and multiple sortings.

DEL: Removed cm_SortByColumn since it is not really useful.
This commit is contained in:
cobines 2010-03-01 14:10:46 +00:00
commit de3bd6f2cb
7 changed files with 36 additions and 70 deletions

View file

@ -1685,11 +1685,6 @@ object frmMain: TfrmMain
Caption = 'Set splitter position'
OnExecute = actExecute
end
object actSortByColumn: TAction
Category = 'Show'
Caption = 'Sort by column'
OnExecute = actExecute
end
object actDriveContextMenu: TAction
Category = 'Commands'
Caption = 'Drive context menu'

View file

@ -127,7 +127,6 @@ TFRMMAIN.ACTCHANGEDIR.CAPTION=Change directory
TFRMMAIN.ACTADDFILENAMETOCMDLINE.CAPTION=Add file name to command line
TFRMMAIN.ACTADDPATHANDFILENAMETOCMDLINE.CAPTION=Add path and file name to command line
TFRMMAIN.ACTPANELSSPLITTERPERPOS.CAPTION=Set splitter position
TFRMMAIN.ACTSORTBYCOLUMN.CAPTION=Sort by column
TFRMMAIN.ACTDRIVECONTEXTMENU.CAPTION=Drive context menu
TFRMMAIN.ACTCOPYNOASK.CAPTION=Copy files without asking for confirmation
TFRMMAIN.ACTRENAMENOASK.CAPTION=Move/Rename files without asking for confirmation

View file

@ -91,7 +91,6 @@ type
actSetFileProperties: TAction;
actQuickFilter: TAction;
actRenameNoAsk: TAction;
actSortByColumn: TAction;
actPanelsSplitterPerPos: TAction;
actMinimize: TAction;
actRightEqualLeft: TAction;

View file

@ -188,8 +188,6 @@ type
FFileFilter: String;
FColumnsSorting: TColumnsSortings;
FSortColumn: Integer;
FSortDirection: TSortDirection;
pnlFooter: TPanel;
lblInfo: TLabel;
@ -291,7 +289,6 @@ type
Translates file sorting by functions to sorting by columns.
}
procedure SetColumnsSorting(ASortings: TFileSortings);
procedure SortByColumn(iColumn: Integer);
procedure ShowRenameFileEdit(const sFileName:String);
procedure ShowPathEdit;
@ -433,8 +430,6 @@ type
procedure cm_QuickSearch(param: string='');
procedure cm_QuickFilter(param: string='');
procedure cm_Open(param: string='');
procedure cm_ReverseOrder(param:string);
procedure cm_SortByColumn(param: string='');
procedure cm_CountDirContent(param: string='');
procedure cm_RenameOnly(param: string='');
procedure cm_ContextMenu(param: string='');
@ -1429,24 +1424,6 @@ begin
lblPath.Caption := MinimizeFilePath(CurrentPath, lblPath.Canvas, lblPath.Width);
end;
procedure TColumnsFileView.SortByColumn(iColumn: Integer);
var
ColumnsClass: TPanelColumnsClass;
begin
ColumnsClass := GetColumnsClass;
if (iColumn >= 0) and (iColumn < ColumnsClass.ColumnsCount) then
begin
FColumnsSorting.Clear;
FColumnsSorting.AddSorting(iColumn, FSortDirection);
FSortColumn := iColumn;
inherited SetSorting(PrepareSortings);
Sort(FFileSourceFiles, Sorting);
ReDisplayFileList;
end;
end;
function TColumnsFileView.PrepareSortings: TFileSortings;
var
ColumnsClass: TPanelColumnsClass;
@ -2617,9 +2594,6 @@ begin
FUpdatingGrid := False;
FColumnsSorting := nil;
// default to sorting by 0-th column
FSortColumn := 0;
FSortDirection := sdAscending;
// -- other components
@ -2836,8 +2810,6 @@ begin
end;
FColumnsSorting := Self.FColumnsSorting.Clone;
FSortColumn := Self.FSortColumn;
FSortDirection := Self.FSortDirection;
ActiveColm := Self.ActiveColm;
ActiveColmSlave := nil; // set to nil because only used in preview?
@ -3345,27 +3317,6 @@ begin
ChooseFile(GetActiveItem);
end;
procedure TColumnsFileView.cm_ReverseOrder(param:string);
begin
FSortDirection := ReverseSortDirection(FSortDirection);
SortByColumn(FSortColumn);
end;
procedure TColumnsFileView.cm_SortByColumn(param: string='');
var
ColumnNumber: Integer;
begin
if TryStrToInt(param, ColumnNumber) then
begin
if FSortColumn = ColumnNumber then
FSortDirection := ReverseSortDirection(FSortDirection)
else
FSortDirection := sdAscending;
SortByColumn(ColumnNumber);
end;
end;
procedure TColumnsFileView.cm_CountDirContent(param: string='');
begin
CalculateSpaceOfAllDirectories;
@ -4401,7 +4352,7 @@ begin
FFileFilter := AColumnsView.FileFilter;
FCurrentPath := AColumnsView.CurrentPath;
FThread := AColumnsView.FListFilesThread;
FSortings := AColumnsView.Sorting;
FSortings := CloneSortings(AColumnsView.Sorting);
end;
procedure TColumnsFileListBuilder.MakeFileSourceFileList(Params: Pointer);

View file

@ -331,7 +331,7 @@ begin
AFileView.FFileSources.Assign(Self.FFileSources);
AFileView.FCurrentPaths.Assign(Self.FCurrentPaths);
AFileView.FSortings := Self.FSortings;
AFileView.FSortings := CloneSortings(Self.FSortings);
end;
end;
@ -382,7 +382,7 @@ end;
procedure TFileView.SetSorting(NewSortings: TFileSortings);
begin
FSortings := NewSortings;
FSortings := CloneSortings(NewSortings);
end;
procedure TFileView.StopBackgroundWork;
@ -514,7 +514,7 @@ var
FileListSorter: TListSorter;
ASortingsCopy: TFileSortings;
begin
ASortingsCopy := ASortings;
ASortingsCopy := CloneSortings(ASortings);
// Add automatic sorting by name and/or extension if there wasn't any.
AddSortingByNameIfNeeded(ASortingsCopy);

View file

@ -127,7 +127,7 @@ const cf_Null=0;
// 1. Global commands intended for the main application (cm_VisitHomePage,
// cm_About, cm_Exit, ...).
//
// 2. Commands intended for file views (cm_QuickSearch, cm_SortByColumn, ...).
// 2. Commands intended for file views (cm_QuickSearch, cm_EditPath, etc.).
// Those commands are simply redirected to the currently active file view by calling:
// frmMain.ActiveFrame.ExecuteCommand(CommandName, param);
// If they are supported by the given file view they are executed there.
@ -224,7 +224,6 @@ const cf_Null=0;
procedure cm_SortByExt(param: string='');
procedure cm_SortByName(param: string='');
procedure cm_SortBySize(param: string='');
procedure cm_SortByColumn(param: string='');
procedure cm_SymLink(param: string='');
procedure cm_CopySamePanel(param: string='');
procedure cm_DirHistory(param: string='');
@ -2123,7 +2122,8 @@ end;
// Uses to change sort direction when columns header is disabled
procedure TActs.cm_ReverseOrder(param:string);
begin
frmMain.ActiveFrame.ExecuteCommand('cm_ReverseOrder', param);
with frmMain.ActiveFrame do
Sorting := ReverseSortDirection(Sorting);
end;
procedure TActs.cm_SortByName(param:string);
@ -2167,13 +2167,6 @@ begin
DoSortByFunctions(frmMain.ActiveFrame, FileFunctions);
end;
// Parameters:
// Number of the column to sort by.
procedure TActs.cm_SortByColumn(param: string='');
begin
frmMain.ActiveFrame.ExecuteCommand('cm_SortByColumn', param);
end;
procedure TActs.cm_MultiRename(param:string);
var
aFiles: TFiles;

View file

@ -88,6 +88,11 @@ type
}
procedure AddSortingByNameIfNeeded(var FileSortings: TFileSortings);
{en
Creates a deep copy of sortings.
}
function CloneSortings(Sortings: TFileSortings): TFileSortings;
function ICompareByDirectory(item1, item2: TFile; bSortNegative: Boolean):Integer;
function ICompareByName(item1, item2: TFile; bSortNegative: Boolean):Integer;
function ICompareByNameNoExt(item1, item2: TFile; bSortNegative: Boolean):Integer;
@ -97,6 +102,7 @@ type
function ICompareByAttr(item1, item2: TFile; bSortNegative: Boolean):Integer;
function ReverseSortDirection(SortDirection: TSortDirection): TSortDirection;
function ReverseSortDirection(Sortings: TFileSortings): TFileSortings;
implementation
@ -213,6 +219,20 @@ begin
// There is already a sorting by filename and extension.
end;
function CloneSortings(Sortings: TFileSortings): TFileSortings;
var
i, j: Integer;
begin
SetLength(Result, Length(Sortings));
for i := 0 to Length(Sortings) - 1 do
begin
SetLength(Result[i].SortFunctions, Length(Sortings[i].SortFunctions));
for j := 0 to Length(Sortings[i].SortFunctions) - 1 do
Result[i].SortFunctions[j] := Sortings[i].SortFunctions[j];
Result[i].SortDirection := Sortings[i].SortDirection;
end;
end;
function ICompareByDirectory(item1, item2: TFile; bSortNegative: Boolean):Integer;
var
IsDir1, IsDir2: Boolean;
@ -369,6 +389,15 @@ begin
end;
end;
function ReverseSortDirection(Sortings: TFileSortings): TFileSortings;
var
i: Integer;
begin
Result := CloneSortings(Sortings);
for i := 0 to Length(Result) - 1 do
Result[i].SortDirection := ReverseSortDirection(Result[i].SortDirection);
end;
{ TListSorter }
constructor TListSorter.Create(Files: TFiles; Sortings: TFileSortings);