Skip to content

Commit

Permalink
v0.95 - Helper script F4TCIE, DocumentTemplates, New icon
Browse files Browse the repository at this point in the history
  • Loading branch information
hi5 committed Jul 15, 2017
1 parent 601d420 commit 881bddb
Show file tree
Hide file tree
Showing 12 changed files with 298 additions and 79 deletions.
Binary file added DocumentTemplates/DocumentTemplatesExamples.zip
Binary file not shown.
40 changes: 40 additions & 0 deletions DocumentTemplates/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Document Templates for F4TCIE.ahk

Note that this is an additional functionality, if you don't place any template.* files
in this folder F4TCIE will not use it.

## Introduction

By default you can use the keyboard shortcut <kbd>Shift</kbd>+<kbd>F4</kbd> or the
*cm_EditNewFile* command to create a new text file and open this in your defined text
editor.

By setting F4TCIE.ahk as editor:

TC, Configuration, Edit/View, Editor:
drive:\path-to\F4TCIE.ahk "%1"

you can extend this functionality to the programs you defined in F4MiniMenu.

Unlike text editors, many program simply don't accept or understand the new empty
file Total Commander creates. They may not start correctly or generate an error message.
Here is where F4TCIE comes in. It checks if there is a "template.ext" file for the new
file you just created, if so it copies that template to your current active panel and
start your preferred program which you defined in F4MiniMenu.

So instead of opening your text editor when you create a new "MyImageFile.PNG" it
can start your preferred Graphics program for PNG files.

If it can't find a template, it will simply launch your default editor.

When you add new templates to this folder you need to Update (scan) the
"Currently Available Document Templates" in the Settings window, or via
"Scan Document Templates" in the Tray or Foreground menu OR restart F4MiniMenu.

You can find two examples in DocumentTemplatesExamples.zip to illustrate how it
works (RTF, PNG) - you can of course replace these with your own Template files.

## Limitation(s)

* It won't work in/with ZIP files (but will copy file to Active panel)
* Shift+F4 doesn't work in FTP panels (default TC behaviour)
108 changes: 39 additions & 69 deletions F4MiniMenu.ahk
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
Script : F4MiniMenu.ahk for Total Commander - AutoHotkey 1.1+ (Ansi and Unicode)
Version : 0.94c
Version : 0.95
Author : hi5
Last update : 7 June 2017
Last update : 10 July 2017
Purpose : Minimalistic clone of the F4 Menu program for Total Commander (open selected files in editor(s))
Source : https://github.com/hi5/F4MiniMenu
Expand Down Expand Up @@ -32,25 +32,10 @@ If (TmpFileList = "")

TmpFileList .= "\$$f4mtmplist$$.m3u"

F4Version:="v0.94c"
F4Version:="v0.95"

SplitPath, A_ScriptName, , , , OutNameNoExt
If (SubStr(OutNameNoExt,0) <> "i")
{
F4ConfigFile:="F4MiniMenu.xml"
F4Load:="XA_Load"
F4Save:="XA_Save"
}
else
{
F4ConfigFile:="F4MiniMenu.ini"
F4Load:="iob"
F4Save:="iob_save"
}

Error:=0
; http://en.wikipedia.org/wiki/List_of_archive_formats
ArchiveExtentions:="\.(a|ar|cpio|shar|iso|lbr|mar|tar|bz2|F|gz|lz|lzma|lzo|rz|sfark|xz|z|infl|7z|s7z|ace|afa|alz|apk|arc|arj|ba|bh|cab|cfs|cpt|dar|dd|dgc|dmg|gca|ha|hki|ice|j|kgb|lzh|lha|lzx|pak|partimg|paq6|paq7|paq8|pea|pim|pit|qda|rar|rk|sda|sea|sen|sfx|sit|sitx|sqx|tar\.gz|tgz|tar\.Z|tar\.bz2|tbz2|tar\.lzma|tlz|uc|uc0|uc2|ucn|ur2|ue2|uca|uha|wim|xar|xp3|yz1|zip|zipx|zoo|zz)\\"
; shared with F4TCIE
#Include %A_ScriptDir%\inc\LoadSettings1.ahk

GroupAdd, TCF4Windows, ahk_class TTOTAL_CMD
GroupAdd, TCF4Windows, ahk_class TLister
Expand All @@ -65,32 +50,23 @@ Menu, tray, NoStandard
Menu, tray, Add, F4MiniMenu - %F4Version%, DoubleTrayClick
Menu, tray, Default, F4MiniMenu - %F4Version%
Menu, tray, Add,
Menu, tray, Add, &Reload this script, MenuHandler
Menu, tray, Add, &Edit this script, MenuHandler
Menu, tray, Add, &Reload this script, MenuHandler
Menu, tray, Add, &Edit this script, MenuHandler
Menu, tray, Add,
Menu, tray, Add, &Suspend Hotkeys, MenuHandler
Menu, tray, Add, &Pause Script, MenuHandler
Menu, tray, Add, &Suspend Hotkeys, MenuHandler
Menu, tray, Add, &Pause Script, MenuHandler
Menu, tray, Add,
Menu, tray, Add, Settings, Settings
Menu, tray, Add, Configure editors, ConfigEditors
Menu, tray, Add, Settings, Settings
Menu, tray, Add, Configure editors, ConfigEditors
Menu, tray, Add, Scan Document Templates, DocumentTemplatesScan
Menu, tray, Add,
Menu, tray, Add, Exit, SaveSettings

If !FileExist(F4ConfigFile) and !FileExist(F4ConfigFile ".bak") ; most likely first run, no need to show error message
Gosub, CreateNewConfig

; Load settings on MatchList Object
Try
{
%F4Load%(F4ConfigFile)
}
Catch
{
Error:=1
}

If ((MatchList.MaxIndex() = 0) or (MatchList.MaxIndex() = ""))
Error:=1
; shared with F4TCIE
#Include %A_ScriptDir%\inc\LoadSettings2.ahk

If (Error = 1)
{
Expand All @@ -115,20 +91,10 @@ If (MatchList.settings.TCStart = 1) and !WinExist("ahk_class TTOTAL_CMD")
Run % MatchList.settings.TCPath ; %
}

; try to get Commander_Path, it will be empty if TC is not running (yet)
EnvGet, Commander_Path, Commander_Path
; shared with F4MM
#Include %A_ScriptDir%\inc\TotalCommanderPath.ahk

If (Commander_Path = "") ; try to read registry
RegRead Commander_Path, HKEY_CURRENT_USER, Software\Ghisler\Total Commander, InstallDir

; Inform user just in case
If (Commander_Path = "")
{
FileRead, check_for_path, %F4ConfigFile%
If InStr(check_for_path,"%Commander_Path%")
MsgBox, 16, F4MiniMenu: Not found, F4MiniMenu:`nThe Commander_Path environment variable can not be found.`nStarting applications may not work in some cases.`nStart TC first.
check_for_path:=""
}
Gosub, DocumentTemplatesScan

Gosub, BuildMenu

Expand Down Expand Up @@ -206,7 +172,7 @@ ProcessFiles(MatchList, SelectedEditor = "-1")
{
FileList%Index% .= open "`n"
Done.Insert(open)
}
}
}
Else If (SelectedEditor > 0) ; Use selected editor from the Menu (Foreground option)
{
Expand All @@ -228,7 +194,7 @@ ProcessFiles(MatchList, SelectedEditor = "-1")
Loop, parse, list, `n, `r
cmdfiles .= """" A_LoopField """" A_Space
OpenFile(v, cmdfiles)
cmdfiles:=""
cmdfiles:=""
}
else If (v.Method = "FileList")
{
Expand Down Expand Up @@ -474,14 +440,6 @@ CountFiles(Files)
Return ErrorLevel+1
}

GetTCCommander_Path(editor)
{
global MyComSpec
editor:=StrReplace(editor,"%Commander_Path%",Commander_Path)
editor:=StrReplace(editor,"%ComSpec%",MyComSpec)
Return editor
}

GetTCFields(opt,file="")
{
; %P causes the source path to be inserted into the command line, including a backslash (\) at the end.
Expand Down Expand Up @@ -589,12 +547,6 @@ AllExtensions:=Trim(AllExtensions,",")
AllExtensions:=RegExExtensions(AllExtensions)
Return

RegExExtensions(in)
{
out:="iU)\b(" StrReplace(StrReplace(StrReplace(in,",","|"),"?",".?"),"*",".*") ")\b" ; v0.9 allow for wildcards
Return out
}

CreateNewConfig:
if InStr(F4ConfigFile,"xml")
{
Expand Down Expand Up @@ -642,13 +594,31 @@ windowmode=1
}
Return


; Check DocumentTemplates\ - this setting can be used in F4TCIE.ahk (not required)
DocumentTemplatesScan:
If (FileExist(A_ScriptDir "\DocumentTemplates\") = "D")
{
Loop, %A_ScriptDir%\DocumentTemplates\template.*
{
SplitPath, A_LoopFileName, , , TemplatesOutExtension
templatesExt .= TemplatesOutExtension ","
}
MatchList.Settings["templatesExt"]:=Trim(templatesExt,",")
TemplatesOutExtension:=""
templatesExt:=""
%F4Save%("MatchList", F4ConfigFile)
}
Return

; Includes

#include %A_ScriptDir%\inc\Menu.ahk
#include %A_ScriptDir%\inc\Settings.ahk
#include %A_ScriptDir%\inc\Editors.ahk
#include %A_ScriptDir%\lib\XA.ahk
#include %A_ScriptDir%\lib\iob.ahk
#include %A_ScriptDir%\inc\HelperFunctions.ahk ; shared with F4TCIE
#include %A_ScriptDir%\lib\XA.ahk ; shared with F4TCIE
#include %A_ScriptDir%\lib\iob.ahk ; shared with F4TCIE
#include %A_ScriptDir%\lib\class_lv_rows.ahk
#include %A_ScriptDir%\lib\DropFiles.ahk
#include %A_ScriptDir%\lib\GetPos.ahk
95 changes: 95 additions & 0 deletions F4TCIE.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
Script : F4TCIE.ahk for Total Commander - AutoHotkey 1.1+ (Ansi and Unicode)
Version : 0.4
Author : hi5
Last update : 10 July 2017
Purpose : Helper script for F4MiniMenu program to allow internal editor to function
now you can edit files from within Archives and FTP (and have TC update/upload them)
Notes : It will always use the "normal" method to open programs, so the "drag & drop", "filelist"
and "cmdline" methods will not be used (TC doesn't see file changes when using these methods)
If you are using INI make sure to rename "F4TCIE" to end with an "i" (same method as F4MiniMenu)
Source : https://github.com/hi5/F4MiniMenu
Setup : TC, Configuration, Edit/View, Editor:
drive:\path-to\F4TCIE.ahk "%1"
Templates : Create a DocumentTemplates\ folder and place files for each template you'd like to use for
the Shift-F4 'enter file name to edit' function of TC. File names are template.ext
This will copy the template.ext to the panel with the new name so you can work on it the
defined editor. Not all programs allow empty files at start up so this will resolve that
problem for say Office applications or Graphics programs.
For testing purposes the variable "templateExt" below needs to be modified, this will
be automatically done when integrating F4TCIE into the F4MM repo.
See DocumentTemplates\readme.md for more info.
*/

#NoTrayIcon
#NoEnv

SetWorkingDir, %A_ScriptDir%

File=%1% ; cmd line parameter "%1" it receives from TC
SplitPath, File, , , OutExtension
StringUpper, OutExtension, OutExtension

If !File ; if empty
ExitApp

; shared with F4MM
#Include %A_ScriptDir%\inc\LoadSettings1.ahk
#Include %A_ScriptDir%\inc\LoadSettings2.ahk

If Error
{
MsgBox, 16, F4MiniMenu/F4TCIE, Couldn't load configuration file, closing script and starting default Windows editor.`n`nMay not work if there is no "Edit" defined for this filetype:`n`n%OutExtension%
Try
Run edit %file% ; run Windows editor for this filetype
Catch
Run notepad %file% ; alas no type defined so run notepad as a last resort
ExitApp
}

templateExt:=MatchList.Settings.templatesExt

; shared with F4MM
#Include %A_ScriptDir%\inc\TotalCommanderPath.ahk

for k, v in MatchList
{
if (k = "settings")
continue
if (v.ext = "") ; reported by Ovg if EXT is empty it would not launch the default editor
continue
If RegExMatch(OutExtension,RegExExtensions(v.ext)) ; Open in defined program - v0.9 allow for wildcards
{
editor:=GetTCCommander_Path(v.exe)
If OutExtension in %templateExt%
{
IfExist, %file% ; file is already present, this could be that TC created it just now (0 bytes) or that is already existed.
{
FileGetSize, NewFileSize, %file%
If (NewFileSize = 0) ; TC created it, so overwrite with our template, otherwise don't. This to avoid overwriting existing documents.
FileCopy, %A_ScriptDir%\DocumentTemplates\template.%OutExtension%, %file%, 1
}
}
If editor
{
Sleep % v.delay
Run %editor% %file%
}
ExitApp ; we only have one file to proces so we're done
}
}

; We couldn't find a defined Editor so launch the default Editor [1]
Run % matchlist[1].exe A_Space file

; shared with F4MM
#include %A_ScriptDir%\inc\HelperFunctions.ahk

; just for loading the Matchlist object, we don't need all the rest
#include %A_ScriptDir%\lib\xa.ahk
#include %A_ScriptDir%\lib\iob.ahk

15 changes: 15 additions & 0 deletions inc/HelperFunctions.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
; used in F4MiniMenu and F4TCIE

GetTCCommander_Path(editor)
{
global MyComSpec
editor:=StrReplace(editor,"%Commander_Path%",Commander_Path)
editor:=StrReplace(editor,"%ComSpec%",MyComSpec)
Return editor
}

RegExExtensions(in)
{
out:="iU)\b(" StrReplace(StrReplace(StrReplace(in,",","|"),"?",".?"),"*",".*") ")\b" ; v0.9 allow for wildcards
Return out
}
20 changes: 20 additions & 0 deletions inc/LoadSettings1.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
; used in F4MiniMenu and F4TCIE

SplitPath, A_ScriptName, , , , OutNameNoExt
If (SubStr(OutNameNoExt,0) <> "i")
{
F4ConfigFile:="F4MiniMenu.xml"
F4Load:="XA_Load"
F4Save:="XA_Save"
}
else
{
F4ConfigFile:="F4MiniMenu.ini"
F4Load:="iob"
F4Save:="iob_save"
}

Error:=0
; http://en.wikipedia.org/wiki/List_of_archive_formats
ArchiveExtentions:="\.(a|ar|cpio|shar|iso|lbr|mar|tar|bz2|F|gz|lz|lzma|lzo|rz|sfark|xz|z|infl|7z|s7z|ace|afa|alz|apk|arc|arj|ba|bh|cab|cfs|cpt|dar|dd|dgc|dmg|gca|ha|hki|ice|j|kgb|lzh|lha|lzx|pak|partimg|paq6|paq7|paq8|pea|pim|pit|qda|rar|rk|sda|sea|sen|sfx|sit|sitx|sqx|tar\.gz|tgz|tar\.Z|tar\.bz2|tbz2|tar\.lzma|tlz|uc|uc0|uc2|ucn|ur2|ue2|uca|uha|wim|xar|xp3|yz1|zip|zipx|zoo|zz)\\"

14 changes: 14 additions & 0 deletions inc/LoadSettings2.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
; used in F4MiniMenu and F4TCIE

; Load settings on MatchList Object
Try
{
%F4Load%(F4ConfigFile)
}
Catch
{
Error:=1
}

If ((MatchList.MaxIndex() = 0) or (MatchList.MaxIndex() = ""))
Error:=1
3 changes: 3 additions & 0 deletions inc/Menu.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ Menu, MyMenu, Add, %MenuPadding%Settings, MenuHandler
Menu, MyMenu, Icon, %MenuPadding%Settings, shell32.dll, 170
Menu, MyMenu, Add, %MenuPadding%Configure Editors, ConfigEditors
Menu, MyMenu, Icon, %MenuPadding%Configure Editors, shell32.dll, 70
Menu, MyMenu, Add, %MenuPadding%Scan Document Templates, DocumentTemplatesScan
Menu, MyMenu, Icon, %MenuPadding%Scan Document Templates, shell32.dll, 172

Menu, MyMenu, Add, %MenuPadding%Exit, MenuHandler
Menu, MyMenu, Icon, %MenuPadding%Exit, shell32.dll, 132

Expand Down
Loading

0 comments on commit 881bddb

Please sign in to comment.