Skip to content

Commit

Permalink
ahk reworkings #266
Browse files Browse the repository at this point in the history
  • Loading branch information
ewerybody committed Apr 14, 2024
1 parent f55e5b0 commit 10c5107
Show file tree
Hide file tree
Showing 5 changed files with 362 additions and 350 deletions.
6 changes: 3 additions & 3 deletions lib/_source/a2_starter.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ a2.cfg := a2_get_user_config(a2data)

if (A_Args.Length) {
args := _gather_args()
Run "%a2_ahk%" "%lib_path%\a2.ahk" %args%, %root_path%
Run '"' a2_ahk '" "' lib_path '\a2.ahk" ' args, root_path
}
else
Run "%a2_ahk%" "%lib_path%\a2.ahk", %root_path%
Run '"' a2_ahk '" "' lib_path '\a2.ahk"', root_path

check_load_time_errors(lib_path)
; check_load_time_errors(lib_path)

If !FileExist(path_join(root_path, "_ user_data_include")) {
; Start the ui by default if there is no include file written yet.
Expand Down
93 changes: 50 additions & 43 deletions lib/a2.ahk
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
; a2 - modular Autohotkey script envirionment
; main file! This gathers all the runtime resources
#SingleInstance force
#Persistent
Persistent
#NoTrayIcon

#include <ahk_functions>
#include <SQLiteDB>

#include lib\a2_core.ahk
#include lib\a2_config.ahk
#include lib\a2_globals.ahk
#include lib\a2_urls.ahk
#include lib\a2_exceptions.ahk
#include lib\a2_user_data.ahk
#include <Class_SQLiteDB>
#include <path>
#include <string>
#include <msgbox>
#include <cursor>
#include <a2tip>
#include <a2log>
#include <explorer>

#include a2_core.ahk
#include a2_config.ahk
#include a2_globals.ahk
#include a2_urls.ahk
#include a2_exceptions.ahk
#include a2_user_data.ahk

; build essential paths and objects
root_dir := path_dirname(A_ScriptDir) "\"
data_dir := a2_get_user_data_path(root_dir)
global a2 := new A2Core_Class(data_dir)
global a2 := A2Core_Class(data_dir)
a2.cfg := a2_get_user_config(data_dir)
SetWorkingDir % a2.paths.a2
SetWorkingDir a2.paths.a2

_a2_check_arguments()
_a2_build_tray_menu(a2_title)
Expand All @@ -28,7 +34,7 @@ if !a2.cfg.no_startup_tooltip
a2tip(a2_title)

if a2.cfg.auto_reload
SetTimer, _a2_check_changes, 1000
SetTimer _a2_check_changes, 1000

OnExit("a2ui_exit")
OnError("a2_on_runtime_exception")
Expand All @@ -43,15 +49,15 @@ a2ui() {
a2tip(tt_text)
a2_win_id := WinExist("a2 ahk_class Qt623QWindowIcon ahk_exe pythonw.exe")
if (a2_win_id)
WinActivate, ahk_id %a2_win_id%
WinActivate "ahk_id " a2_win_id
else {
ui_starter := path_join(a2.paths.a2, "a2ui.exe")
Run, "%ui_starter%"
Run ui_starter
}
}

a2ui_help() {
Run, %a2_help%
Run a2_help
}

a2ui_reload() {
Expand All @@ -60,7 +66,7 @@ a2ui_reload() {

a2ui_exit() {
exit_func := "a2_exit_calls"
if IsFunc(exit_func)
if IsObject(exit_func)
%exit_func%()
ExitApp
}
Expand All @@ -78,19 +84,18 @@ _a2_check_changes() {
; Removes the attribute from all files and returns true if any was found
do_reload := false
for _, libdir in [a2.paths.lib, a2.paths.ahklib] {
pattern := string_suffix(libdir, "\") "*.ahk"
Loop, Files, %pattern%
Loop Files, string_suffix(libdir, "\") "*.ahk"
{
num_files++
If InStr(A_LoopFileAttrib, "A") {
do_reload := true
FileSetAttrib, -A, %A_LoopFileFullpath%
FileSetAttrib "-A", A_LoopFileFullpath
a2log_debug("Changed lib file: " A_LoopFileFullPath)
}
}
}

Loop, read, % a2.paths.includes
Loop read a2.paths.includes
{
if !string_startswith(A_LoopReadLine, "#include ")
Continue
Expand All @@ -99,7 +104,7 @@ _a2_check_changes() {
if InStr(FileGetAttrib(path), "A") {
do_reload := true
a2log_debug("Changed include file: " path)
FileSetAttrib, -A, %path%
FileSetAttrib "-A", path
}
}

Expand All @@ -114,30 +119,32 @@ _a2_check_arguments() {
if (arg == "--shutdown")
ExitApp
else
MsgBox, a2, Arguments handling is WIP!`nWhat's "%arg%"?
MsgBox("Arguments handling is WIP!`nWhat's '" arg "'?", "a2")
}
}

_a2_build_tray_menu(a2_title) {
; Build the tray icon menu.
a2ui_res := a2.paths.resources
Menu, Tray, Icon, %a2ui_res%a2.ico, , 1
Menu, Tray, Icon
Gui, 1:Destroy

Menu, Tray, NoStandard
Menu, Tray, DeleteAll
Menu, Tray, Tip, %a2_title%
Menu, Tray, Click, 1
Menu, Tray, add, Open a2 User Interface, a2ui
Menu, Tray, icon, Open a2 User Interface, %a2ui_res%a2.ico
Menu, Tray, default, Open a2 User Interface
Menu, Tray, add, Open a2 Directory, a2_explore
Menu, Tray, icon, Open a2 Directory, %a2ui_res%a2.ico
Menu, Tray, add, Reload a2 Runtime, a2ui_reload
Menu, Tray, icon, Reload a2 Runtime, %a2ui_res%a2reload.ico
Menu, Tray, add, Help on a2, a2ui_help
Menu, Tray, icon, Help on a2, %a2ui_res%a2help.ico
Menu, Tray, add, Quit a2 Runtime, _a2ui_exit
Menu, Tray, icon, Quit a2 Runtime, %a2ui_res%a2x.ico
; a2ui_res := a2.paths.resources
TraySetIcon(path_join(a2.paths.resources, "a2.ico"))
; A_TrayMenu.Add
; Menu Tray, Icon, %a2ui_res%a2.ico, , 1
; Menu Tray, Icon
; Gui 1:Destroy

; Menu Tray, NoStandard
; Menu Tray, DeleteAll
; Menu Tray, Tip, %a2_title%
; Menu Tray, Click, 1
; Menu Tray, add, Open a2 User Interface, a2ui
; Menu Tray, icon, Open a2 User Interface, %a2ui_res%a2.ico
; Menu Tray, default, Open a2 User Interface
; Menu Tray, add, Open a2 Directory, a2_explore
; Menu Tray, icon, Open a2 Directory, %a2ui_res%a2.ico
; Menu Tray, add, Reload a2 Runtime, a2ui_reload
; Menu Tray, icon, Reload a2 Runtime, %a2ui_res%a2reload.ico
; Menu Tray, add, Help on a2, a2ui_help
; Menu Tray, icon, Help on a2, %a2ui_res%a2help.ico
; Menu Tray, add, Quit a2 Runtime, _a2ui_exit
; Menu Tray, icon, Quit a2 Runtime, %a2ui_res%a2x.ico
}
2 changes: 1 addition & 1 deletion lib/a2_config.ahk
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
SetTitleMatchMode, 2
SetTitleMatchMode 2
a2_title := "a2 - dev_version 0.5.4"
Loading

0 comments on commit 10c5107

Please sign in to comment.