Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Closed] Mimic Phrase Express
Hi Gintaras,

i'd like to know before taking the plunge in a no ending hell coding if mimic
this is possible using QM (the drag and drop from menu part)?

This does not create floating windows from submenus, but you can drag-drop menu items directly.

Function ShowDragDropTextMenu
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
;;;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.

;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)
,mac "drag_drop_text_menu_manager"
,wait 5 V g_hwndDragDropTextMenuManager; err ret

lpstr s=q_strdup(menuCSV)
PostMessage g_hwndDragDropTextMenuManager WM_APP flags s
Also need these functions for ShowDragDropTextMenu.
Function drag_drop_text_menu_manager
Copy      Help
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

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

sel message
,int+ g_hwndDragDropTextMenuManager=hDlg
,case WM_APP goto gMenu
,case WM_MENUDRAG goto gDrag
,case WM_MENURBUTTONUP goto gRight
,case WM_COMMAND goto messages2
sel wParam
ret 1

ICsv-- t_csv._create

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

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)
SetMenuInfo(m &mi)

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

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

__Drag x.Init(hDlg 1)
,if(!x.Next) break
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_LBUTTONUP 0 xy

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)

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

err+ end _error 4
Function DDTM_GetItem
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
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
Copy      Help
str s=
;one, text for one
;two, "multiline
;run macro, this text is the first argument, Macro1503
ShowDragDropTextMenu s
Macro Macro1503
Copy      Help
function $s
OnScreenDisplay s
Absolutely wonderful, Gintaras, so amazed...
I don't need (yet) the menu creation...

Three addons if possible:

1. possibility to use this to paste a picture (loaded from resource in QM or a file from anywhere in disks)

2. Possibility to add dynamicaly from clipboard some items in menu

3. possibility to load items from a cvs file. I think I can do it by using csv from file in ShowDragDropTextMenu example routine, right?

ICsv x._create; x.FromString(_s)
1. Where would you paste these pictures?

2. In this version it is difficult because menu text is controlled by the caller. Maybe if using file...

3. ShowDragDropTextMenu _s.getfile("...."). But I'll add a flag for it.
1. in RTF files, or in folders in explorer, in PDF for signing as stamp....

2. OK

3. Ok

Updated. Added flags to use file or macro, and to open the file/macro to edit from the menu.
Oops, forgot one important use of a picture file : copy it to clipboard.
Ok, opens so much possibilities, my brain is boiling lol.

1. I want to be able to launch macros from an item too, not paste it. I modified the code, and it works so far. maybe you can check it to tell me if it is
possible to improve/correct it.

Function drag_drop_text_menu_manager
Copy      Help
ifk(C) key- C; key HSE ;;select line. Note: sometimes this may trigger QTranslate because creates double-Ctrl.
lpstr s=iif(t_csv.ColumnCount>1 t_csv.Cell(i 1) 0)
if(empty(s)) s=t_csv.Cell(i 0); rep() if(s[0]=9) s+1; else break
if(_s.beg("mac ")) goto lancemac
paste s; err
if(onSelect) goto gBack
_s.remove(0 4)
mac _s
if(onSelect) goto gBack

2. I noticed that function drag_drop_text_menu_manager stays in use after doing a paste operation, in running item window. Shouldn't it close after drag and drop operation and menu has disappeared?
Updated. Use third CSV column for macro.
drag_drop_text_menu_manager thread normally does not end, it waits for next menu request.

Correct me if I'm wrong, but file stored as resource in a macro can't be used by edit function in this example, right? I must
use an external one that i must load/modify/save each time I want to add or remove items?
In this example can't. Macro resources generally can be updated, but there is no editor to edit macro resource data directly. You can store text in a macro instead.
Brilliant, did not think about that.

Any hint to store and paste an image using this?
Your macro can do it, when it runs from the menu. Look in str.setsel help. It supports resources too.

Macro Macro2239
Copy      Help
function $text
;out text ;;must be .bmp file path or .bmp resource like "resource:<Macro2239>test.bmp"

Macro ShowDragDropTextMenu example
Trigger F7     Help - how to add the trigger to the macro
Copy      Help
str s=
;run macro that pastes image, resource:<Macro2239>test.bmp, Macro2239
ShowDragDropTextMenu s
ok, wasn't aware of the new setsel feature.
Last one for today:

say i link an external resource text file for switching menus upon needs and dynamically, and I manage to modify by code that file.
How to be sure new version will be loaded the next call after modification?
Hope it's clear ...
The function always loads the specified file, does not use caching.
Ok, I guess it's the same if the items are stored in a macro then...
In the video, there is the way to add clips in a little window to use them (33'), from a menu item (like the edit item you provide)

Any way to include it too or to much hassle?
Much work. Then need a window, cannot add to menu, because it disappears. Also many windows don't use OLE drag-drop, then difficult to capture text. To capture clipboard also much work.
Ok, what you have done is fantastic so far, will use it a lot
Thanks so much

Forum Jump:

Users browsing this thread: 1 Guest(s)