ADD: Patch [ 1883955 ] uColorExt from Dmitry Kolomiets

This commit is contained in:
Alexander Koblov 2008-02-01 07:09:16 +00:00
commit a2a51dc24a
3 changed files with 245 additions and 149 deletions

View file

@ -48,6 +48,14 @@ ColorFilter1Name=Pascal sources
ColorFilter2=*.ppu;*.o;*.dcu
ColorFilter2Color=16711680
ColorFilter2Name=Pascal binaries
ColorFilter3=*
ColorFilter3Color=55758
ColorFilter3Attributes=-rwxrwxr*x
ColorFilter3Name=SpecifiedExecutables
ColorFilter4=*
ColorFilter4Color=32768
ColorFilter4Attributes=-*x*
ColorFilter4Name=Executables
[PackerPlugins]
zip=87,/home/alexx/doublecmd/plugins/zip/libZip.so

View file

@ -507,7 +507,7 @@ begin
end;
Canvas.FillRect(Rect);
//Canvas.Font.Style:=[];
newColor:=gColorExt.ColorByExt(sExt);
newColor:=gColorExt.GetColorBy(sExt, sModeStr);
if bSelected then
Canvas.Font.Color:= gMarkColor
else

View file

@ -1,148 +1,236 @@
{
Double Commander
-------------------------------------------------------------------------
Load colors of files in file panels
Copyright (C) 2003-2004 Radek Cervinka (radek.cervinka@centrum.cz)
Copyright (C) 2006-2007 Koblov Alexander (Alexx2000@mail.ru)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
}
unit uColorExt;
interface
uses
Classes, Graphics;
type
TColorExt=Class
protected
lsExts:TStringList;
public
constructor Create;
destructor Destroy; override;
function ColorByExt(const sExt:String):TColor;
procedure Load;
procedure Save;
end;
implementation
uses
SysUtils, uGlobs;
constructor TColorExt.Create;
begin
inherited;
lsExts:=TStringList.Create;
end;
destructor TColorExt.Destroy;
begin
if assigned(lsExts) then
FreeAndNil(lsExts);
end;
function TColorExt.ColorByExt(const sExt:String):TColor;
var
iIndex:Integer;
begin
Result:= gForeColor; //$0000ff00;
if sExt='' then Exit;
if sExt[1]='.' then
iIndex:= lsExts.IndexOf(UpperCase(Copy(sExt,2, Length(sExt)-1)))
else
iIndex:= lsExts.IndexOf(UpperCase(sExt));
if iIndex=-1 then Exit;
Result:=TColor(lsExts.Objects[iIndex]);
end;
(* Load colors of files from doublecmd.ini *)
{ format of colors storage as in Total Commander:
doublecmd.ini
[Colors]
ColorFilter1=*.o;*.ppu;*.rst;*.bak;*.dcu
ColorFilter1Color=16711680
ColorFilter2=*.pas
ColorFilter2Color=16711000
etc...
}
procedure TColorExt.Load;
var
sExt,
sExtMask : String;
iColor,
iPos,
iBegin,
iCharCount,
I : Integer;
begin
I := 1;
lsExts.Clear;
while gIni.ReadString('Colors', 'ColorFilter' + IntToStr(I), '') <> '' do
begin
iBegin := 1;
sExtMask := gIni.ReadString('Colors', 'ColorFilter' + IntToStr(I), '');
iColor := gIni.ReadInteger('Colors', 'ColorFilter' + IntToStr(I) + 'Color', clText);
if pos(';', sExtMask) <> 0 then // if some extensions
begin
if sExtMask[Length(sExtMask)] <> ';' then
sExtMask := sExtMask + ';';
repeat
begin
iPos := pos(';', sExtMask);
//WriteLN('sExtMask=='+sExtMask+ ' iBegin==' + IntToStr(iBegin)+' Index=='+IntToStr(iPos));
Delete(sExtMask, iPos, 1);
Insert(' ', sExtMask, iPos); // change ';' to space
iCharCount := Length(sExtMask) - ((Length(sExtMask) - iPos )) - iBegin;
sExt := Copy(sExtMask, iBegin, iCharCount);
sExt := ExtractFileExt(sExt);
//WriteLN('sExt==' + sExt);
if (sExt <> '') and (sExt[1] = '.') then
Delete(sExt,1,1);
lsExts.AddObject(sExt,TObject(iColor));
iBegin := iPos + 1;
end
until pos(';', sExtMask) = 0;
end
else // if one extension
begin
sExt := ExtractFileExt(sExtMask);
if (sExt <> '') and (sExt[1] = '.') then
Delete(sExt,1,1);
lsExts.AddObject(sExt,TObject(iColor));
end;
Inc(I);
end; // while gIni.ReadString();
end;
procedure TColorExt.Save;
begin
end;
end.
{
Double Commander
-------------------------------------------------------------------------
Load colors of files in file panels
Copyright (C) 2003-2004 Radek Cervinka (radek.cervinka@centrum.cz)
Copyright (C) 2006-2007 Koblov Alexander (Alexx2000@mail.ru)
Copyright (C) 2008 Dmitry Kolomiets (B4rr4cuda@rambler.ru)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
}
unit uColorExt;
interface
uses
Classes, Graphics;
type
TMaskItem=class
sExt:string;
sModeStr:string;
cColor:TColor;
sName:string;
end;
{ TColorExt }
TColorExt=Class
private
protected
lslist:TList;
public
constructor Create;
destructor Destroy; override;
function ColorByExt(const sExt:String):TColor;
function GetColorByExt(const sExt:String):TColor;
function GetColorByAttr(const sModeStr:String):TColor;
function GetColorBy(const sExt,sModeStr: String): TColor;
procedure Load;
procedure Save;
end;
implementation
uses
SysUtils, uGlobs, Masks;
constructor TColorExt.Create;
begin
inherited;
lslist:=TList.Create;
end;
destructor TColorExt.Destroy;
begin
if assigned(lsList) then
begin
while lslist.Count>0 do
begin
TMaskItem(lslist[0]).Free;
lslist.Delete(0);
end;
FreeAndNil(lsList);
end;
end;
function TColorExt.ColorByExt(const sExt:String):TColor;
begin
Result:=GetColorByExt(sExt);
end;
function TColorExt.GetColorByExt(const sExt: String): TColor;
var I:integer;
begin
Result:= gForeColor; //$0000ff00;
for I:=0 to lslist.Count-1 do
begin
if MatchesMaskList(sExt,TMAskItem(lslist[I]).sExt,';') then
begin
Result:=TMAskItem(lslist[I]).cColor;
exit;
end;
end;
end;
function TColorExt.GetColorByAttr(const sModeStr: String): TColor;
var I:Integer;
begin
Result:= gForeColor; //$0000ff00;
for I:=0 to lslist.Count-1 do
begin
if MatchesMaskList(sModeStr,TMAskItem(lslist[I]).sModeStr,';') then
begin
Result:=TMAskItem(lslist[I]).cColor;
exit;
end;
end;
end;
function TColorExt.GetColorBy(const sExt, sModeStr: String): TColor;
var I:Integer;
begin
Result:= gForeColor; //$0000ff00;
for I:=0 to lslist.Count-1 do
begin
if ( MatchesMaskList(sExt,TMAskItem(lslist[I]).sExt,';') ) and
(MatchesMaskList(sModeStr,TMAskItem(lslist[I]).sModeStr,';') or (TMAskItem(lslist[I]).sModeStr='')) then
begin
Result:=TMAskItem(lslist[I]).cColor;
exit;
end;
end;
end;
(* Load colors of files from doublecmd.ini *)
{ format of colors storage as in Total Commander:
doublecmd.ini
[Colors]
ColorFilter1=*.o;*.ppu;*.rst;*.bak;*.dcu
ColorFilter1Color=16711680
ColorFilter2=*.pas
ColorFilter2Color=16711000
etc...
Added Attributes:
ColorFilter1Attributes=-r*xr*xr*x //all read/executable file
ColorFilter2Attributes=-*x* //all executable
ColorFilter3Attributes=d* //all directories
ColorFilter4Attributes=l* //all links
Be careful with * expression. Functions return just first found value.
This is right demo of [Colors] section:
ColorFilter3=*
ColorFilter3Color=55758
ColorFilter3Attributes=-rwxrwxr*x
ColorFilter3Name=SomeName3
ColorFilter4=*
ColorFilter4Color=32768
ColorFilter4Attributes=-*x*
ColorFilter4Name=SomeName4
This IS WRONG because ColorFilter3Attributes=-*x* will be
found and ColorFilter3Color=32768 will be returned first:
ColorFilter3=*
ColorFilter3Color=32768
ColorFilter3Attributes=-*x*
ColorFilter3Name=SomeName3
ColorFilter4=*
ColorFilter4Color=55758
ColorFilter4Attributes=-rwxrwxr*x
ColorFilter4Name=SomeName4
!!! The "?" and other regular expressions DOES NOT SUPPORTED
}
procedure TColorExt.Load;
var
sExtMask,
sAttr,
sName: String;
iColor,
I : Integer;
begin
I := 1;
if assigned(lsList) then
begin
while lslist.Count>0 do
begin
TMaskItem(lslist[0]).Free;
lslist.Delete(0);
end;
end;
while gIni.ReadString('Colors', 'ColorFilter' + IntToStr(I), '') <> '' do
begin
sExtMask := gIni.ReadString('Colors', 'ColorFilter' + IntToStr(I), '');
iColor := gIni.ReadInteger('Colors', 'ColorFilter' + IntToStr(I) + 'Color', clText);
sName:=gIni.ReadString('Colors', 'ColorFilter' + IntToStr(I)+'Name', '');
sAttr := gIni.ReadString('Colors', 'ColorFilter' + IntToStr(I) + 'Attributes', '');
lsList.Add(TMaskItem.Create);
TMaskItem(lsList[lsList.Count-1]).sName:=sName;
TMaskItem(lsList[lsList.Count-1]).cColor:=iColor;
TMaskItem(lsList[lsList.Count-1]).sExt:=sExtMask;
TMaskItem(lsList[lsList.Count-1]).sModeStr:=sAttr;
Inc(I);
end; // while gIni.ReadString();
end;
procedure TColorExt.Save;
var I:Integer;
begin
//if (lslist.Count=0) then
// TODO: list is empty. need to remove all "ColorFilter*" keys
if (lslist.Count=0) then exit;
if (not assigned(lslist)) then exit;
for I:=0 to lslist.Count - 1 do
begin
gIni.WriteString('Colors', 'ColorFilter' + IntToStr(I), TMaskItem(lsList[I]).sExt);
gIni.WriteInteger('Colors', 'ColorFilter' + IntToStr(I) + 'Color', TMaskItem(lsList[I]).cColor);
gIni.WriteString('Colors', 'ColorFilter' + IntToStr(I)+'Name', TMaskItem(lsList[I]).sName);
gIni.WriteString('Colors', 'ColorFilter' + IntToStr(I) + 'Attributes', TMaskItem(lsList[I]).sModeStr);
end;
end;
end.