diff options
| -rw-r--r-- | UConfig.pas | 6 | ||||
| -rw-r--r-- | UCore.pas | 2 | ||||
| -rw-r--r-- | UCoreUtils.pas | 42 | ||||
| -rw-r--r-- | UFileAssoc.pas | 157 | ||||
| -rw-r--r-- | UFileTypeSettings.pas | 55 | ||||
| -rw-r--r-- | UMain.pas | 145 | ||||
| -rw-r--r-- | vfs/UVFSCore.pas | 2 |
7 files changed, 213 insertions, 196 deletions
diff --git a/UConfig.pas b/UConfig.pas index 034fd11..9642930 100644 --- a/UConfig.pas +++ b/UConfig.pas @@ -607,8 +607,8 @@ begin Item := TFileAssoc.Create; with Item do begin if (Sections[i] = ConstFTAMetaDirectory) or (Sections[i] = ConstFTAMetaFile) - then Extensions := '' - else Extensions := Sections[i]; + then SetLength(Extensions, 0) + else ParseString(Sections[i], ';', Extensions); FileTypeName := IniFile.ReadString(Sections[i], 'FileTypeName', ''); DefaultAction := IniFile.ReadInteger(Sections[i], 'DefaultAction', 0); cnt := IniFile.ReadInteger(Sections[i], 'NumActions', 0); @@ -661,7 +661,7 @@ begin with TFileAssoc(AssocList[i]) do begin if (FileTypeName = ConstFTAMetaDirectory) or (FileTypeName = ConstFTAMetaFile) then SectionTitle := FileTypeName - else SectionTitle := Extensions; + else SectionTitle := MakeString(';', Extensions); IniFile.EraseSection(SectionTitle); IniFile.WriteString(SectionTitle, 'FileTypeName', FileTypeName); IniFile.WriteString(SectionTitle, 'FileTypeIcon', FileTypeIcon); @@ -367,7 +367,7 @@ begin end; ItemColor := nil; - AddFileTypeIcon(List[i]); + AssignFileType(List[i]); DataList.Add(List[i]); ListItem.Data := DataList[DataList.Count - 1]; if not Application.GTKVersion_2_0_5_Up then ListItem.SetValue(0, List[i]); diff --git a/UCoreUtils.pas b/UCoreUtils.pas index 93bbff0..8fa6fef 100644 --- a/UCoreUtils.pas +++ b/UCoreUtils.pas @@ -60,6 +60,8 @@ function FormatSize(Value: Int64; Base: integer; OverrideSizeFormat: integer = - function FormatDate(Value: time_t; const FormatTime, FormatDate: boolean; OverrideTimeFormat: integer = -1; OverrideDateFormat: integer = -1; OverrideDateTimeFormat: integer = -1; OverrideCustomDateFormat: string = ''; OverrideCustomTimeFormat: string = ''): string; function StripDate(Value: time_t): time_t; +function IncludeLeadingDot(s: string): string; + function AttrToStr(const Mode: Cardinal; IncludeFileType: boolean = True): string; function AttrToOctal(const Mode: Cardinal): integer; function OctalToAttr(Octal: Cardinal): Cardinal; @@ -83,6 +85,9 @@ function ReplaceStr(const S, Srch, Replace: string): string; function NumCountChars(const Char: char; const S: string): integer; procedure ParseString(const Str, Separator: string; var SubStrings: TOpenStringArray); +function MakeString(const Separator: string; var SubStrings: TOpenStringArray): string; +procedure CopyArray(var src: TOpenStringArray; var dst: TOpenStringArray); +procedure DeleteFromArray(Index: integer; var SubStrings: TOpenStringArray); function ProcessPattern(Engine: TPanelEngine; Pattern, APath, FileName: string; const Directory: boolean): string; @@ -421,6 +426,14 @@ begin end; (********************************************************************************************************************************) +function IncludeLeadingDot(s: string): string; +begin + s := Trim(s); + if s[1] <> '.' then Result := '.' + s + else Result := s; +end; + +(********************************************************************************************************************************) function GetHomePath: string; begin Result := PgcharToString(g_get_home_dir); @@ -962,6 +975,35 @@ begin end; end; +function MakeString(const Separator: string; var SubStrings: TOpenStringArray): string; +var i: integer; +begin + Result := ''; + if Length(SubStrings) > 0 then begin + for i := 0 to Length(SubStrings) - 2 do + Result := Result + SubStrings[i] + Separator; + Result := Result + SubStrings[Length(SubStrings) - 1]; + end; +end; + +procedure CopyArray(var src: TOpenStringArray; var dst: TOpenStringArray); +var i: integer; +begin + SetLength(dst, Length(src)); + for i := 0 to Length(src) - 1 do dst[i] := src[i]; +end; + +procedure DeleteFromArray(Index: integer; var SubStrings: TOpenStringArray); +var i: integer; +begin + if Length(SubStrings) > 0 then begin + if Index < Length(SubStrings) - 1 then + for i := Index to Length(SubStrings) - 2 do + SubStrings[i] := SubStrings[i + 1]; + SetLength(SubStrings, Length(SubStrings) - 1); + end; +end; + (********************************************************************************************************************************) function GetStrSize(s: string): Int64; var i: integer; diff --git a/UFileAssoc.pas b/UFileAssoc.pas index 2c1f708..10d0f73 100644 --- a/UFileAssoc.pas +++ b/UFileAssoc.pas @@ -21,7 +21,7 @@ unit UFileAssoc; interface -uses Classes, SysUtils, GTKPixbuf, GTKClasses, GTKUtils, UEngines; +uses Classes, SysUtils, GTKPixbuf, GTKClasses, GTKUtils, UEngines, UVFSCore, UCoreUtils; type TAssocAction = class ActionName, ActionCommand: string; @@ -30,7 +30,8 @@ type TAssocAction = class end; TFileAssoc = class - Extensions, FileTypeName, FileTypeIcon, ColorString: string; + Extensions: TOpenStringArray; + FileTypeName, FileTypeIcon, ColorString: string; DefaultAction: integer; ActionList: TList; Pixmap, LnkPixmap: TGDKPixbuf; @@ -66,14 +67,16 @@ var FolderIcon, FileIcon, UpDirIcon, SymLinkEmblem, FolderIconLnk, FileIconLnk, procedure LoadIcons; -procedure AddFileTypeIcon(Item: PDataItem); +function FindVFSPlugin(Filename: string): TVFSPlugin; +function FindAssoc(Filename: string): TFileAssoc; +procedure AssignFileType(Item: PDataItem); procedure RecreateIcons(List: TList; const FreePixmaps: boolean = True); procedure RemoveIconRefs(List: TList; FreeIt: boolean); procedure AddDefaultItems(List: TList); implementation -uses GTKForms, UConfig, UCore, UCoreUtils, UVFSCore; +uses GTKForms, UConfig, UCore; (********************************************************************************************************************************) @@ -84,7 +87,7 @@ begin ActionList := TList.Create; DefaultAction := 0; FileTypeIcon := ''; - Extensions := ''; + SetLength(Extensions, 0); FileTypeName := ''; ColorString := ''; Pixmap := TGDKPixbuf.Create(nil); @@ -158,14 +161,74 @@ begin end; (********************************************************************************************************************************) -procedure AddFileTypeIcon(Item: PDataItem); -var Ext: string; +function FindVFSPlugin(Filename: string): TVFSPlugin; +var Ext, s: string; b: boolean; - i, j, Last: integer; - AColor: TGDKColor; + i, j, Last, MaxFound: integer; +begin + b := False; + Result := nil; + MaxFound := 0; + if (Pos('.', Filename) > 1) and (LastDelimiter('.', Filename) < Length(Filename)) then begin + Ext := WideUpperCase(Trim(Copy(Filename, Pos('.', Filename), Length(Filename) - Pos('.', Filename) + 1))); + if PluginList.Count > 0 then + for i := 0 to PluginList.Count - 1 do + with TVFSPlugin(PluginList[i]) do + if Length(Extensions) > 0 then begin + b := False; + s := ''; + for j := 0 to Length(Extensions) - 1 do begin + s := ANSIUpperCase(IncludeLeadingDot(Extensions[j])); + if Length(Ext) = Length(s) + then b := (Ext = s) and (Length(s) > MaxFound) + else b := (Pos(s, Ext) > 0) and (Pos(s, Ext) = (Length(Ext) - Length(s) + 1)) and (Length(s) > MaxFound); + if b then Break; + end; + if b then begin + Result := PluginList[i]; + MaxFound := Length(s); + end; + end; + end; +end; + +function FindAssoc(Filename: string): TFileAssoc; +var Ext, s: string; + b: boolean; + i, j, Last, MaxFound: integer; +begin + b := False; + Result := nil; + MaxFound := 0; + if (Pos('.', Filename) > 1) and (LastDelimiter('.', Filename) < Length(Filename)) then begin + Ext := WideUpperCase(Trim(Copy(Filename, Pos('.', Filename), Length(Filename) - Pos('.', Filename) + 1))); + if AssocList.Count > 0 then + for i := 0 to AssocList.Count - 1 do + with TFileAssoc(AssocList[i]) do + if Length(Extensions) > 0 then begin + b := False; + s := ''; + for j := 0 to Length(Extensions) - 1 do begin + s := ANSIUpperCase(IncludeLeadingDot(Extensions[j])); + if Length(Ext) = Length(s) + then b := (Ext = s) and (Length(s) > MaxFound) + else b := (Pos(s, Ext) > 0) and (Pos(s, Ext) = (Length(Ext) - Length(s) + 1)) and (Length(s) > MaxFound); + if b then Break; + end; + if b then begin + Result := AssocList[i]; + MaxFound := Length(s); + end; + end; + end; +end; + +procedure AssignFileType(Item: PDataItem); +var AColor: TGDKColor; Plugin: TVFSPlugin; + Assoc: TFileAssoc; begin - with Item^ do begin + with PDataItem(Item)^ do begin ItemColor := nil; if IsLnk and (not ConfLinkItemDefaultColors) then ItemColor := LinkItemGDKColor else if IsDotFile and (not ConfDotFileItemDefaultColors) then ItemColor := DotFileItemGDKColor; @@ -177,58 +240,28 @@ begin if not IsLnk then Icon := FileIconCached.FPixbuf else Icon := FileIconLnkCached.FPixbuf; if (Pos('.', FName) > 1) and (LastDelimiter('.', FName) < Length(FName)) then begin - Ext := WideUpperCase(Trim(Copy(FDisplayName, LastDelimiter('.', FDisplayName) + 1, Length(FDisplayName) - LastDelimiter('.', FDisplayName)))); - - // Try to find a plugin which can handle this archive type - b := False; - Plugin := nil; - if PluginList.Count > 0 then - for i := 0 to PluginList.Count - 1 do begin - Plugin := TVFSPlugin(PluginList[i]); - if Length(Plugin.Extensions) > 0 then - for j := 0 to Length(Plugin.Extensions) - 1 do begin - if AnsiCompareText(Plugin.Extensions[j], Ext) = 0 then begin - b := True; - if IsLnk then Icon := ArchiveIconLnk.FPixbuf - else Icon := ArchiveIcon.FPixbuf; - Break; - end; - end; - if b then Break; + Plugin := FindVFSPlugin(FDisplayName); + Assoc := FindAssoc(FDisplayName); + + // Asssign icon and color + if Plugin <> nil then begin + if IsLnk then Icon := ArchiveIconLnk.FPixbuf + else Icon := ArchiveIcon.FPixbuf; + end else + if Assoc <> nil then begin + if Assigned(Assoc.Pixmap) then begin + if IsLnk and Assigned(Assoc.LnkPixmap) and Assigned(Assoc.LnkPixmap.FPixbuf) + then Icon := Assoc.LnkPixmap.FPixbuf + else Icon := Assoc.Pixmap.FPixbuf; end; - - // Try to find an association - if (not b) and (AssocList.Count > 0) then - for i := 0 to AssocList.Count - 1 do - with TFileAssoc(AssocList[i]) do - if Length(Trim(Extensions)) > 0 then begin - b := False; - if Pos(';', Extensions) = 0 then b := ANSIUpperCase(Trim(Extensions)) = Ext else begin - Last := 0; - for j := 1 to Length(Extensions) do - if Extensions[j] = ';' then begin - if ANSIUpperCase(Trim(Copy(Extensions, Last + 1, j - Last - 1))) = Ext then begin - b := True; - Break; - end; - Last := j; - end; - if not b then b := ANSIUpperCase(Trim(Copy(Extensions, LastDelimiter(';', Extensions) + 1, Length(Extensions) - LastDelimiter(';', Extensions)))) = Ext; - end; - if b then begin - if Assigned(Pixmap) then - if IsLnk and Assigned(LnkPixmap) and Assigned(LnkPixmap.FPixbuf) - then Icon := LnkPixmap.FPixbuf - else Icon := Pixmap.FPixbuf; - if ItemColor = nil then - if (ColorString = '') or (not StringToGDKColor(ColorString, AColor)) - then ItemColor := NormalItemGDKColor - else ItemColor := GDKColorToPGdkColor(AColor); - end; - end; - + if ItemColor = nil then begin + if (Assoc.ColorString = '') or (not StringToGDKColor(Assoc.ColorString, AColor)) + then ItemColor := NormalItemGDKColor + else ItemColor := GDKColorToPGdkColor(AColor); + end; + end; end; - end; + end; end; end; @@ -318,7 +351,7 @@ begin if not Found then begin Item := TFileAssoc.Create; Item.FileTypeName := ConstFTAMetaDirectory; - Item.Extensions := ''; + SetLength(Item.Extensions, 0); Item.FileTypeIcon := ''; Item.ColorString := ''; Item.DefaultAction := 0; @@ -341,7 +374,7 @@ begin if not Found then begin Item := TFileAssoc.Create; Item.FileTypeName := ConstFTAMetaFile; - Item.Extensions := ''; + SetLength(Item.Extensions, 0); Item.FileTypeIcon := ''; Item.ColorString := ''; Item.DefaultAction := 0; diff --git a/UFileTypeSettings.pas b/UFileTypeSettings.pas index d6d5eb1..03eda53 100644 --- a/UFileTypeSettings.pas +++ b/UFileTypeSettings.pas @@ -401,7 +401,7 @@ begin for i := 0 to List.Count - 1 do begin Item := TFileAssoc.Create; with Item do begin - Extensions := TFileAssoc(List[i]).Extensions; + CopyArray(TFileAssoc(List[i]).Extensions, Extensions); FileTypeName := TFileAssoc(List[i]).FileTypeName; DefaultAction := TFileAssoc(List[i]).DefaultAction; FileTypeIcon := TFileAssoc(List[i]).FileTypeIcon; @@ -433,7 +433,7 @@ procedure TFFileTypeSettings.FillList; ListItem := ListView.Items.Add; if FileTypeName = ConstFTAMetaDirectory then ListItem.SetValue(0, LANGFileTypeDirectory) else if FileTypeName = ConstFTAMetaFile then ListItem.SetValue(0, LANGFileTypeFile) else - ListItem.SetValue(0, Extensions); + ListItem.SetValue(0, MakeString(';', Extensions)); if (FileTypeName = ConstFTAMetaDirectory) or (FileTypeName = ConstFTAMetaFile) then ListItem.SetValue(1, LANGFileTypeMetafile) else ListItem.SetValue(1, FileTypeName); @@ -520,7 +520,6 @@ end; procedure TFFileTypeSettings.ListViewSelectionChanged(Sender: TObject); var b: boolean; Item: TFileAssoc; - s: string; i: integer; ListItem: TGTKListItem; Color: TGDKColor; @@ -555,14 +554,9 @@ begin end; Item := ListView.Selected.AsPointer(2); FNameExtListView.Items.Clear; - if Length(Item.Extensions) > 0 then begin - s := Item.Extensions; - while Pos(';', s) > 0 do begin - FNameExtListView.Items.Add.SetValue(0, Trim(Copy(s, 1, Pos(';', s) - 1))); - Delete(s, 1, Pos(';', s)); - end; - if Length(Trim(s)) > 0 then FNameExtListView.Items.Add.SetValue(0, Trim(s)); - end; + if Length(Item.Extensions) > 0 then + for i := 0 to Length(Item.Extensions) - 1 do + FNameExtListView.Items.Add.SetValue(0, Item.Extensions[i]); IconEntry.Text := Item.FileTypeIcon; IconEntryChanged(Self); if (TFileAssoc(ListView.Selected.AsPointer(2)).FileTypeName = ConstFTAMetaDirectory) or @@ -597,7 +591,8 @@ end; procedure TFFileTypeSettings.AddExtButtonClick(Sender: TObject); var i: integer; - s, sx: string; + sx: string; + Assoc: TFileAssoc; begin if Length(Trim(FNameExtEntry.Text)) = 0 then Exit; if FNameExtListView.Items.Count > 0 then @@ -606,32 +601,32 @@ begin sx := WideLowerCase(Trim(FNameExtEntry.Text)); if sx[1] = '.' then Delete(sx, 1, 1); FNameExtListView.Items.Add.SetValue(0, sx); - s := TFileAssoc(ListView.Selected.AsPointer(2)).Extensions; - if Length(s) > 0 then s := s + ';'; - s := s + sx; - ListView.Selected.SetValue(0, s); - TFileAssoc(ListView.Selected.AsPointer(2)).Extensions := s; + + Assoc := TFileAssoc(ListView.Selected.AsPointer(2)); + SetLength(Assoc.Extensions, Length(Assoc.Extensions) + 1); + Assoc.Extensions[Length(Assoc.Extensions) - 1] := sx; + ListView.Selected.SetValue(0, MakeString(';', Assoc.Extensions)); + FNameExtEntry.Text := ''; end; procedure TFFileTypeSettings.RemoveExtButtonClick(Sender: TObject); var s: string; i: integer; + Assoc: TFileAssoc; begin try - if (FNameExtListView.Items.Count = 0) or (not Assigned(FNameExtListView.Selected)) or - (not Assigned(ListView.Selected)) or (not Assigned(ListView.Selected.AsPointer(2))) then Exit; - s := TFileAssoc(ListView.Selected.AsPointer(2)).Extensions; - i := Pos(FNameExtListView.Selected.AsString(0), s); - if i = 0 then Exit; - Delete(s, i, Length(FNameExtListView.Selected.AsString(0))); - if s = ';' then s := '' else - if (Length(s) >= i) and (s[i] = ';') then Delete(s, i, 1) else - if (Length(s) >= i - 1) and (i > 1) and (s[i - 1] = ';') then Delete(s, i - 1, 1); - ListView.Selected.SetValue(0, s); - TFileAssoc(ListView.Selected.AsPointer(2)).Extensions := s; - FNameExtListView.Items.Delete(FNameExtListView.Selected.Index); - except end; + if (FNameExtListView.Items.Count = 0) or (not Assigned(FNameExtListView.Selected)) or + (not Assigned(ListView.Selected)) or (not Assigned(ListView.Selected.AsPointer(2))) then Exit; + Assoc := TFileAssoc(ListView.Selected.AsPointer(2)); + if Length(Assoc.Extensions) > 0 then + for i := Length(Assoc.Extensions) - 1 downto 0 do + if Assoc.Extensions[i] = FNameExtListView.Selected.AsString(0) then + DeleteFromArray(i, Assoc.Extensions); + ListView.Selected.SetValue(0, MakeString(';', Assoc.Extensions)); + FNameExtListView.Items.Delete(FNameExtListView.Selected.Index); + except + end; end; procedure TFFileTypeSettings.FNameExtEntryKeyDown(Sender: TObject; Key: Word; Shift: TShiftState; var Accept: boolean); @@ -222,7 +222,7 @@ type procedure SwitchTab(TabNo: integer; LeftPanel, SetFocus: boolean); procedure CloseTab(TabNo: integer; LeftPanel: boolean); procedure AddTabs(LeftPanel: boolean; TabList: TStringList; TabSortIDs, TabSortTypes: TList; SetTabActive: integer); - function HandleVFSArchive(const Ext, FullPath, HighlightItem, TargetPath: string): boolean; + function HandleVFSArchive(const FileName, FullPath, HighlightItem, TargetPath: string): boolean; procedure CloseVFS(LeftPanel, SurpressRefresh: boolean); procedure ShowBookmarkQuick(LeftPanel: boolean); procedure SetTabLabel(Notebook: TEphyNotebook; PageIndex: integer; ALabel, Tooltip: string); @@ -1629,7 +1629,7 @@ begin // Test for known internal functions if (Ext = 'SFV') or (Ext = 'MD5') then miVerifyChecksumsClick(Self) else if (Ext = 'CRC') or (Ext = '001') then miMergeFilesClick(Self) else - if not ((Engine is TLocalTreeEngine) and HandleVFSArchive(Ext, IncludeTrailingPathDelimiter(Engine.Path) + String(Data^.FName), String(Data^.FName), '/')) then + if not ((Engine is TLocalTreeEngine) and HandleVFSArchive(String(Data^.FName), IncludeTrailingPathDelimiter(Engine.Path) + String(Data^.FName), String(Data^.FName), '/')) then if (not ConfUseURI) or ((Engine is TVFSEngine) and TVFSEngine(Engine).ArchiveMode) then RunFile(IncludeTrailingPathDelimiter(Engine.Path) + String(Data^.FName), Engine, -1) else RunFile(ExcludeTrailingPathDelimiter(Engine.GetPrefix) + IncludeTrailingPathDelimiter(Engine.Path) + String(Data^.FName), Engine, -1); @@ -3366,7 +3366,7 @@ end; procedure TFMain.EditViewFile(LeftPanel: boolean; AListView: TGTKListView; View, NewFile: boolean); var ANewDir: TFNewDir; Engine: TPanelEngine; - AFile, s: string; + AFile: string; Stat: PDataItemSL; Error, x: integer; // AViewer: TViewerThread; @@ -3475,11 +3475,12 @@ begin end; procedure TFMain.RunFile(Path: string; Engine: TPanelEngine; CustomAction: integer); -var Command, Ext, FileTypeDesc: string; - i, j, Last, ac: integer; +var Command, FileTypeDesc: string; + i, ac: integer; b, AutodetectGUI, RunInTerminal: boolean; Stat: PDataItemSL; s: string; + Assoc: TFileAssoc; begin try InternalLock; @@ -3487,40 +3488,19 @@ begin FileTypeDesc := ''; AutodetectGUI := True; RunInTerminal := False; - if (Pos('.', ExtractFileName(Path)) > 0) and (LastDelimiter('.', ExtractFileName(Path)) < Length(ExtractFileName(Path))) then begin - Ext := WideUpperCase(Trim(Copy(ExtractFileName(Path), LastDelimiter('.', ExtractFileName(Path)) + 1, Length(ExtractFileName(Path)) - LastDelimiter('.', ExtractFileName(Path))))); - // Search in the association list - if AssocList.Count > 0 then - for i := 0 to AssocList.Count - 1 do - with TFileAssoc(AssocList[i]) do - if (ActionList.Count > 0) and (Length(Trim(Extensions)) > 0) then begin - b := False; - if Pos(';', Extensions) = 0 then b := WideUpperCase(Trim(Extensions)) = Ext else begin - Last := 0; - for j := 1 to Length(Extensions) do - if Extensions[j] = ';' then begin - if WideUpperCase(Trim(Copy(Extensions, Last + 1, j - Last - 1))) = Ext then begin - b := True; - Break; - end; - Last := j; - end; - if not b then b := WideUpperCase(Trim(Copy(Extensions, LastDelimiter(';', Extensions) + 1, Length(Extensions) - LastDelimiter(';', Extensions)))) = Ext; - end; - if b then begin - FileTypeDesc := FileTypeName; - if (CustomAction > ActionList.Count - 1) or (CustomAction = -1) - then ac := DefaultAction - else ac := CustomAction; - if ac > ActionList.Count - 1 then ac := 0; - if ActionList.Count >= ac then begin - Command := UTF8ToStr(Trim(TAssocAction(ActionList[ac]).ActionCommand)); - AutodetectGUI := TAssocAction(ActionList[ac]).AutodetectGUI; - RunInTerminal := TAssocAction(ActionList[ac]).RunInTerminal; - end; - if Command <> '' then Break; - end; - end; + + Assoc := FindAssoc(ExtractFileName(Path)); + if Assoc <> nil then begin + FileTypeDesc := Assoc.FileTypeName; + if (CustomAction > Assoc.ActionList.Count - 1) or (CustomAction = -1) + then ac := Assoc.DefaultAction + else ac := CustomAction; + if ac > Assoc.ActionList.Count - 1 then ac := 0; + if Assoc.ActionList.Count > ac then begin + Command := UTF8ToStr(Trim(TAssocAction(Assoc.ActionList[ac]).ActionCommand)); + AutodetectGUI := TAssocAction(Assoc.ActionList[ac]).AutodetectGUI; + RunInTerminal := TAssocAction(Assoc.ActionList[ac]).RunInTerminal; + end; end; // Association not found, try to execute file itself @@ -4147,9 +4127,10 @@ var Item: TGTKMenuItem; DataItem: PDataItemSL; Engine: TPanelEngine; AListView: TGTKListView; - FileName, ShortFName, Ext: string; - UpDir, b, Found: boolean; - i, j, Last: integer; + FileName, ShortFName: string; + UpDir, Found: boolean; + i, j: integer; + Assoc: TFileAssoc; begin ClearPopupMenu(FilePopupMenu); if LeftLastFocused then begin @@ -4209,39 +4190,20 @@ begin // Find and add actions for this file type Found := False; - if Pos('.', ShortFName) > 0 then begin - Ext := WideUpperCase(Trim(Copy(ShortFName, LastDelimiter('.', ShortFName) + 1, Length(ShortFName) - LastDelimiter('.', ShortFName)))); - if AssocList.Count > 0 then - for i := 0 to AssocList.Count - 1 do - with TFileAssoc(AssocList[i]) do - if (ActionList.Count > 0) and (Length(Trim(Extensions)) > 0) then begin - b := False; - if Pos(';', Extensions) = 0 then b := Trim(Extensions) = Ext else begin - Last := 0; - for j := 1 to Length(Extensions) do - if Extensions[j] = ';' then begin - if WideUpperCase(Trim(Copy(Extensions, Last + 1, j - Last - 1))) = Ext then begin - b := True; - Break; - end; - Last := j; - end; - if not b then b := WideUpperCase(Trim(Copy(Extensions, LastDelimiter(';', Extensions) + 1, Length(Extensions) - LastDelimiter(';', Extensions)))) = Ext; - end; - if b and (ActionList.Count > 0) then begin - Found := True; - for j := 0 to ActionList.Count - 1 do begin - Item := TGTKMenuItem.CreateTyped(Self, itImageText); - Item.Caption := Format(LANGPopupOpenWithS, [TAssocAction(ActionList[j]).ActionName]); - if ((j = 0) and (DefaultAction > ActionList.Count - 1)) or (j = DefaultAction) then - Item.Caption := Item.Caption + LANGPopupDefault; - Item.Data := ActionList[j]; - Item.OnClick := FilePopupMenuItemClick; - FilePopupMenu.Add(Item); - end; - end; - end; + Assoc := FindAssoc(ShortFName); + if (Assoc <> nil) and (Assoc.ActionList.Count > 0) then begin + Found := True; + for j := 0 to Assoc.ActionList.Count - 1 do begin + Item := TGTKMenuItem.CreateTyped(Self, itImageText); + Item.Caption := Format(LANGPopupOpenWithS, [TAssocAction(Assoc.ActionList[j]).ActionName]); + if ((j = 0) and (Assoc.DefaultAction > Assoc.ActionList.Count - 1)) or (j = Assoc.DefaultAction) + then Item.Caption := Item.Caption + LANGPopupDefault; + Item.Data := Assoc.ActionList[j]; + Item.OnClick := FilePopupMenuItemClick; + FilePopupMenu.Add(Item); + end; end; + if (not Found) and (not DataItem^.IsDir) then begin Item := TGTKMenuItem.CreateTyped(Self, itImageText); Item.Caption := LANGPopupOpenWith; @@ -5807,31 +5769,16 @@ end; (********************************************************************************************************************************) (********************************************************************************************************************************) -function TFMain.HandleVFSArchive(const Ext, FullPath, HighlightItem, TargetPath: string): boolean; -var i, j: integer; - Plugin: TVFSPlugin; +function TFMain.HandleVFSArchive(const FileName, FullPath, HighlightItem, TargetPath: string): boolean; +var Plugin: TVFSPlugin; begin - Result := False; - Plugin := nil; + Plugin := FindVFSPlugin(FileName); + Result := Plugin <> nil; - // Try to find a plugin which can handle open the archive type - if PluginList.Count > 0 then - for i := 0 to PluginList.Count - 1 do begin - Plugin := TVFSPlugin(PluginList[i]); - if Length(Plugin.Extensions) > 0 then - for j := 0 to Length(Plugin.Extensions) - 1 do begin -// DebugMsg(['Extension = "', Plugin.Extensions[j], '", Ext = "', Ext, '"']); - if WideCompareText(Plugin.Extensions[j], Ext) = 0 then begin - Result := True; - Break; - end; - end; - if Result then Break; - end; - if not Result then Exit; // we didn't find appropriate plugin - DebugMsg(['Found plugin ''', Plugin.VFSName, ''', trying to open the file ''', FullPath, '''']); - - ChangingDir(LeftLastFocused, TargetPath, FullPath, HighlightItem, False, False, Plugin); + if Result then begin + DebugMsg(['Found plugin ''', Plugin.VFSName, ''', trying to open the file ''', FullPath, '''']); + ChangingDir(LeftLastFocused, TargetPath, FullPath, HighlightItem, False, False, Plugin); + end; end; procedure TFMain.CloseVFS(LeftPanel, SurpressRefresh: boolean); @@ -5877,7 +5824,6 @@ procedure TFMain.miSearchClick(Sender: TObject); var Engine: TPanelEngine; DataList: TList; AListView: TGTKListView; - Ext: string; i: integer; begin if LeftLastFocused then Engine := LeftPanelEngine @@ -5894,8 +5840,7 @@ begin mbApply: begin DebugMsg(['TFMain.miSearchClick: FSearch.GoToFileArchive = "', FSearch.GoToFileArchive, '", FSearch.GoToFile = "', FSearch.GoToFile, '"']); if Length(FSearch.GoToFileArchive) > 0 then begin - Ext := WideUpperCase(Trim(Copy(FSearch.GoToFileArchive, LastDelimiter('.', FSearch.GoToFileArchive) + 1, Length(FSearch.GoToFileArchive) - LastDelimiter('.', FSearch.GoToFileArchive)))); - HandleVFSArchive(Ext, FSearch.GoToFileArchive, ExtractFileName(FSearch.GoToFileArchive), ExtractFilePath(FSearch.GoToFile)); + HandleVFSArchive(ExtractFileName(FSearch.GoToFileArchive), FSearch.GoToFileArchive, ExtractFileName(FSearch.GoToFileArchive), ExtractFilePath(FSearch.GoToFile)); if LeftLastFocused then begin Engine := LeftPanelEngine; diff --git a/vfs/UVFSCore.pas b/vfs/UVFSCore.pas index e93fa11..eafc2ef 100644 --- a/vfs/UVFSCore.pas +++ b/vfs/UVFSCore.pas @@ -234,6 +234,8 @@ end; destructor TVFSPlugin.Destroy; begin + SetLength(Extensions, 0); + SetLength(Services, 0); if ModuleHandle <> nil then dlclose(ModuleHandle); inherited Destroy; end; |
