-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdialis.ahk
152 lines (119 loc) · 2.54 KB
/
dialis.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
; dialis - version 0.0.2
prepare:
; config
SetWorkingDir %A_ScriptDir%
CoordMode Menu, Screen
CoordMode Mouse, Screen
CoordMode Caret, Screen
; Use utf-8 on file read
FileEncoding, CP65001
; consts
EMBED_COUNTER_DELIM := " | "
EMPTY_STRING_DISPLAY := "<Empty>"
SP = \
BASEDIR = %A_ScriptDir%
FILELIST_PATH := BASEDIR SP "filelist.txt"
; includes
#Include %A_ScriptDir%\libargument.ahk
; parsing_commandline_arguments
args := parse_arguments()
____main___:
main_preparation_for_menu:
list_fullpath := Object()
menuname_root := "menuname_root"
counter := new Counter()
; Because ahk is 1-origin.
counter.plus()
try {
Menu, %menuname_root%, DeleteAll
} catch e {
; absorb unavoidable failure because no menu at first time.
}
mein_construct_menu_with_loopreading:
; from filelist
Loop, Read, %FILELIST_PATH%
{
fullpath := A_LoopReadLine
itemname := fullpath
curcount := counter.get()
Menu, %menuname_root%, Add, %itemname% %EMBED_COUNTER_DELIM% %curcount%, label_do_after_select
list_fullpath.Push(fullpath)
counter.plus()
}
; system items
count_syscmd_edit := counter.get()
Menu, %menuname_root%, Add, <<Edit file list(&\)>> %EMBED_COUNTER_DELIM% %count_syscmd_edit%, label_do_after_select
list_fullpath.Push("__dummy__")
counter.plus()
main_display_menu:
posobj := determin_showpos()
showx := posobj.x
showy := posobj.y
Menu, %menuname_root%, Show, %showx%, %showy%
Return
____end_of_main____:
label_do_after_select:
selected_idx := get_menuitem_index_from_menuname(A_ThisMenuItem, EMBED_COUNTER_DELIM)
if(selected_idx==count_syscmd_edit){
open_with_association(FILELIST_PATH)
Return
}
selected_fullpath := list_fullpath[selected_idx]
copy_method(selected_fullpath)
paste_method()
; enter_method()
Return
funcs:
Return
enter_method(){
Send,{Enter}
}
paste_method(){
Send,^v
}
copy_method(fullpath){
clipboard := fullpath
}
open_with_association(fullpath){
Run, %fullpath%
}
determin_showpos(){
; Use the caret pos
; But if cannot get, use mouse cursor pos.
pos := get_mouse_pos()
pos.x := A_CaretX
pos.y := A_CaretY
Return pos
}
get_mouse_pos(){
MouseGetPos, mousex, mousey
mousepos := {}
mousepos.x := mousex
mousepos.y := mousey
Return mousepos
}
get_menuitem_index_from_menuname(menuname, delim){
ls := StrSplit(menuname, delim)
Return ls[2]
}
is_empty_argument(arg){
Return arg==""
}
is_not_empty_argument(arg){
Return arg!=""
}
classes:
Return
class Counter {
__New(){
this._v := 0
}
plus(){
curv := this._v
newv := curv + 1
this._v := newv
}
get(){
Return this._v
}
}