summaryrefslogtreecommitdiff
path: root/UMain.pas
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@users.sourceforge.net>2008-06-18 22:30:08 +0200
committerTomas Bzatek <tbzatek@users.sourceforge.net>2008-06-18 22:30:08 +0200
commite7a55631dfa3e4011e420dbd22891d4adf98aa7d (patch)
treef87f517df24b0267dcda78e8cade9e574b8f03f3 /UMain.pas
parentfd60abd18e718c2134b350308c8d4dbf0d95dcc0 (diff)
downloadtuxcmd-e7a55631dfa3e4011e420dbd22891d4adf98aa7d.tar.xz
Handle multiple file extensions
Resolves #1120769
Diffstat (limited to 'UMain.pas')
-rw-r--r--UMain.pas145
1 files changed, 45 insertions, 100 deletions
diff --git a/UMain.pas b/UMain.pas
index caf3e5a..99cbfbc 100644
--- a/UMain.pas
+++ b/UMain.pas
@@ -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;