Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Closed] Mimic Phrase Express
#2
This does not create floating windows from submenus, but you can drag-drop menu items directly.

Function ShowDragDropTextMenu
Code:
Copy      Help
;/
function $menuCSV [flags] ;;flags: 1 menuCSV is file, 2 menuCSV is macro, 4 add 'Edit menu'

;Shows menu. You can drag-drop menu items to text fields in any window to paste the text there.

;menuCSV - CSV containing menu items.
;;;Can be 1 or 2 or 3 columns.
;;;First column - menu item labels. Also you can create submenus and separators, like with <help>ShowMenu</help>.
;;;Second column - text to paste. If column or text is missing, pastes first column's text.
;;;Third column can be name of macro to run instead of pasting text. To get text in the macro: function $text
;flags:
;;;1, 2 - CSV is in file or macro. menuCSV is file path or macro name or \path.
;;;4 - add 'Edit menu' menu item that opens the file or macro in QM. This flag is used with flag 1 or 2.

;REMARKS
;To paste text, you can click or drag-drop a menu item.
;Use Ctrl to select existing text to replace. In multiline text it replaces single line.
;After you drop, the menu remains, and you can drag-drop more items or click somewhere to end menu.
;If the drop target window is inactive, on drop it is activated. It ends menu too.
;You can right-click a menu item to copy its text to the clipboard.
;You'll see drag_drop_text_menu_manager thread in the Threads list, unless function drag_drop_text_menu_manager is in a private folder.


opt noerrorshere 1

int+ g_hwndDragDropTextMenuManager
if !IsWindow(g_hwndDragDropTextMenuManager)
,g_hwndDragDropTextMenuManager=0
,mac "drag_drop_text_menu_manager"
,wait 5 V g_hwndDragDropTextMenuManager; err ret
,0.05

lpstr s=q_strdup(menuCSV)
PostMessage g_hwndDragDropTextMenuManager WM_APP flags s
Also need these functions for ShowDragDropTextMenu.
Function drag_drop_text_menu_manager
Code:
Copy      Help
;\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

if(getopt(nthreads)>1) ret

if(!ShowDialog("" &drag_drop_text_menu_manager 0 0 128)) ret

;BEGIN DIALOG
;0 "" 0x80C800C8 0x0 0 0 223 135 "Dialog"
;END DIALOG
;DIALOG EDITOR: "" 0x2040101 "*" "" "" ""

ret
;messages
sel message
,case WM_INITDIALOG
,int+ g_hwndDragDropTextMenuManager=hDlg
,
,case WM_DESTROY
,g_hwndDragDropTextMenuManager=0
,
,case WM_APP goto gMenu
,
,case WM_MENUDRAG goto gDrag
,
,case WM_MENURBUTTONUP goto gRight
,
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDCANCEL
ret 1
;________________

;gMenu
ICsv-- t_csv._create

if t_csv.RowCount ;;if already in menu, end it and show new
,t_csv.Clear
,EndMenu
,PostMessage hDlg WM_APP wParam lParam
,ret

int i flags(wParam) onSelect
lpstr menuCSV(+lParam) csvErr
str sm sf sFree.lpstr=+lParam

sel flags&3
,case 1 menuCSV=sf.getfile(menuCSV); err csvErr=_error.description
,case 2 menuCSV=sf.getmacro(menuCSV); err csvErr=_error.description

if(!csvErr) t_csv.FromString(menuCSV); err csvErr="invalid CSV"

if(csvErr) out "ShowDragDropTextMenu error: %s" csvErr; ret

for(i 0 t_csv.RowCount) sm.addline(t_csv.Cell(i 0))
MenuPopup m.AddItems(sm 1)
if flags&7>4
,m.AddItems("-[]30000 Edit menu")

MENUINFO mi.cbSize=sizeof(mi)
mi.fMask=MIM_STYLE|MIM_APPLYTOSUBMENUS
mi.dwStyle=MNS_DRAGDROP
SetMenuInfo(m &mi)

i=m.Show(hDlg)
if i>0
,sel i
,,case 30000
,,sel flags&3
,,,case 1 run "qmcl.exe" F"''{sFree.lpstr}''"
,,,case 2 mac+ sFree.lpstr
,,
,,case else i-1; onSelect=1; goto gPaste
;gBack
t_csv.Clear
ret
;________________

;gDrag
i=DDTM_GetItem(lParam wParam t_csv); if(i<0) ret

__Drag x.Init(hDlg 1)
rep
,if(!x.Next) break
,x.cursor=2
if(!x.dropped) ret

;lef ;;closes menu
int w=child(mouse 1)
act w; err
POINT p; xm p w 1
int xy=p.y<<16|p.x
SendMessage w WM_LBUTTONDOWN MK_LBUTTON xy
SendMessage w WM_LBUTTONUP 0 xy

;gPaste
ifk(C) key- C; key HSE ;;select line. Note: sometimes this may trigger QTranslate because creates double-Ctrl.
lpstr s=DDTM_GetItemText(t_csv i)

lpstr macro
if(t_csv.ColumnCount>2) macro=t_csv.Cell(i 2)
if(!empty(macro)) mac macro "" s
else paste s; err

if(onSelect) goto gBack

SetCursor LoadCursor(0 +IDC_ARROW)
;ret DT_Ret(hDlg MND_ENDMENU)
ret
;________________

;gRight
i=DDTM_GetItem(lParam wParam t_csv); if(i<0) ret
sel ShowMenu("1 Copy text" hDlg 0 0 TPM_RECURSE)
,case 1 _s=DDTM_GetItemText(t_csv i); _s.setclip
ret
;________________

err+ end _error 4
Function DDTM_GetItem
Code:
Copy      Help
;/
function# hMenu miIndex ICsv&c

int r=GetMenuItemID(hMenu miIndex)-1
if(r<0 or r>=c.RowCount) ret -1 ;;>submenu or a spec item
ret r
Function DDTM_GetItemText
Code:
Copy      Help
;/
function$ ICsv&c i

lpstr r=iif(c.ColumnCount>1 c.Cell(i 1) 0)
if(empty(r)) r=c.Cell(i 0); rep() if(r[0]=9) r+1; else break
ret r

Macro ShowDragDropTextMenu example
Trigger F7     Help - how to add the trigger to the macro
Code:
Copy      Help
str s=
;one, text for one
;two, "multiline
;text"
;three
;>submenu
,;four
,;<
;-
;five
;run macro, this text is the first argument, Macro1503
;
ShowDragDropTextMenu s
Macro Macro1503
Code:
Copy      Help
function $s
OnScreenDisplay s


Messages In This Thread

Forum Jump:


Users browsing this thread: 7 Guest(s)