revised main

This commit is contained in:
joten 2016-02-12 20:39:04 +01:00
parent 70d79b7987
commit c157df9c80
4 changed files with 57 additions and 81 deletions

View file

@ -201,13 +201,13 @@ Bar_cmdGuiEnter:
Bar_cmdGuiIsVisible := False
Gui, Cancel
WinActivate, ahk_id %Bar_aWndId%
Main_evalCommand(Bar_#0_#0)
Cmd_eval(Bar_#0_#0)
Bar_#0_#0 := ""
} Else If (A_GuiControl = "Bar_#0_#1") {
Gui, Submit, NoHide
Debug_logMessage("DEBUG[6] Bar_cmdGuiEnter; command: " . Bar_#0_#1, 6)
Loop, Parse, Bar_#0_#1, `n, `r
Main_evalCommand(A_LoopField)
Cmd_eval(A_LoopField)
}
Return

View file

@ -261,7 +261,7 @@ Config_redirectHotkey(key)
If (key = Config_hotkey_#%A_index%_key)
{
Debug_logMessage("DEBUG[1] Config_redirectHotkey: Found " Config_hotkey_#%A_index%_key " -> " Config_hotkey_#%A_index%_command, 1)
Main_evalCommand(Config_hotkey_#%A_index%_command)
Cmd_eval(Config_hotkey_#%A_index%_command)
Break
}
}

View file

@ -9,6 +9,50 @@ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
*/
Cmd_eval(s) {
Log_msg("**Command_eval**: '" . s . "'", 5)
c := SubStr(s, 1, 5)
If (s = "ExitApp")
ExitApp
Else If (s = "Reload")
Reload
Else If (c = "Send ")
Send % SubStr(s, 6)
Else If (c = "Run, ") {
parameters := SubStr(s, 6)
StringReplace, parameters, parameters, `,%A_Space%, `,, All
StringSplit, p, parameters, `,
If (p0 = 1)
Run, %p1%
Else If (p0 = 2)
Run, %p1%, %p2%
Else If (p0 = 3)
Run, %p1%, %p2%, %p3%
Else If (p0 = 4)
Run, %p1%, %p2%, %p3%, %p4%
} Else {
i := InStr(s, "(")
j := InStr(s, ")", False, i)
If i And j {
fun := SubStr(s, 1, i - 1)
arguments := SubStr(s, i + 1, j - (i + 1))
StringReplace, arguments, arguments, %A_Space%, , All
StringSplit, arg, arguments, `,
If (arg0 = 0)
%fun%()
Else If (arg0 = 1)
%fun%(arg1)
Else If (arg0 = 2)
%fun%(arg1, arg2)
Else If (arg0 = 3)
%fun%(arg1, arg2, arg3)
Else If (arg0 = 4)
%fun%(arg1, arg2, arg3, arg4)
}
}
Log_msg("Command evaluated '" . s . "'", 4)
}
Int_min(a, b) {
Return, a < b ? a : b
}

View file

@ -64,84 +64,21 @@ Main_cleanup:
Debug_logMessage("====== Exiting bug.n ======", 0)
ExitApp
Main_evalCommand(command)
{
type := SubStr(command, 1, 5)
If (type = "Run, ")
{
parameters := SubStr(command, 6)
If InStr(parameters, ", ")
{
StringSplit, parameter, parameters, `,
If (parameter0 = 2)
{
StringTrimLeft, parameter2, parameter2, 1
Run, %parameter1%, %parameter2%
}
Else If (parameter0 > 2)
{
StringTrimLeft, parameter2, parameter2, 1
StringTrimLeft, parameter3, parameter3, 1
Run, %parameter1%, %parameter2%, %parameter3%
}
}
Else
Run, %parameters%
}
Else If (type = "Send ")
Send % SubStr(command, 6)
Else If (command = "Reload")
Reload
Else If (command = "ExitApp")
ExitApp
Else
{
i := InStr(command, "(")
j := InStr(command, ")", False, i)
If i And j
{
functionName := SubStr(command, 1, i - 1)
functionArguments := SubStr(command, i + 1, j - (i + 1))
StringReplace, functionArguments, functionArguments, %A_SPACE%, , All
StringSplit, functionArgument, functionArguments, `,
Debug_logMessage("DEBUG[1] Main_evalCommand: " functionName "(" functionArguments ")", 1)
If (functionArgument0 = 0)
%functionName%()
Else If (functionArgument0 = 1)
%functionName%(functionArguments)
Else If (functionArgument0 = 2)
%functionName%(functionArgument1, functionArgument2)
Else If (functionArgument0 = 3)
%functionName%(functionArgument1, functionArgument2, functionArgument3)
Else If (functionArgument0 = 4)
%functionName%(functionArgument1, functionArgument2, functionArgument3, functionArgument4)
}
}
}
Main_help:
Run, explore %Main_docDir%
Return
;; Create bug.n-specific directories.
Main_makeDir(dirName) {
IfNotExist, %dirName%
{
FileCreateDir, %dirName%
If ErrorLevel
{
MsgBox, Error (%ErrorLevel%) when creating '%dirName%'. Aborting.
ExitApp
}
}
Else
{
FileGetAttrib, attrib, %dirName%
IfNotInString, attrib, D
{
MsgBox, The file path '%dirName%' already exists and is not a directory. Aborting.
Main_makeDir(name) {
q := FileExist(name)
If Not q {
FileCreateDir, %name%
If ErrorLevel {
MsgBox, Error (%ErrorLevel%) creating '%name%'. Aborting.
ExitApp
}
} Else If Not InStr(q, "D") {
MsgBox, The filepath '%name%' already exists and is not a directory. Aborting.
ExitApp
}
}
@ -157,15 +94,10 @@ Main_setup() {
Main_docDir .= "\.."
Main_docDir .= "\doc"
Main_logFile := ""
Main_dataDir := ""
Main_autoLayout := ""
Main_autoWindowState := ""
EnvGet, winAppDir, APPDATA
If (Main_appDir = "")
Main_appDir := winAppDir . "\bug.n"
Main_logFile := Main_appDir . "\log.txt"
Log_file := Main_appDir . "\log.md"
Main_dataDir := Main_appDir . "\data"