Posts: 795
Threads: 136
Joined: Feb 2009
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)?
http://www.phraseexpress.com/video/pex7_..._float.htm
Thanks
Posts: 12,066
Threads: 140
Joined: Dec 2002
This does not create floating windows from submenus, but you can drag-drop menu items directly.
Function ShowDragDropTextMenu
;/
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
;\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
;/
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
;/
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
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
function $s
OnScreenDisplay s
Posts: 795
Threads: 136
Joined: Feb 2009
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?
_s.getfile("....")
ICsv x._create; x.FromString(_s)
Posts: 12,066
Threads: 140
Joined: Dec 2002
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.
Posts: 795
Threads: 136
Joined: Feb 2009
1. in RTF files, or in folders in explorer, in PDF for signing as stamp....
2. OK
3. Ok
Ty
Posts: 12,066
Threads: 140
Joined: Dec 2002
Updated. Added flags to use file or macro, and to open the file/macro to edit from the menu.
Posts: 795
Threads: 136
Joined: Feb 2009
Oops, forgot one important use of a picture file : copy it to clipboard.
Posts: 795
Threads: 136
Joined: Feb 2009
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
gPaste
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)
_s=s
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
;
;lancemac
_s.trim
_s.remove(0 4)
mac _s
if(onSelect) goto gBack
end
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?
Posts: 12,066
Threads: 140
Joined: Dec 2002
Updated. Use third CSV column for macro.
drag_drop_text_menu_manager thread normally does not end, it waits for next menu request.
Posts: 795
Threads: 136
Joined: Feb 2009
Handsome.
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?
Posts: 12,066
Threads: 140
Joined: Dec 2002
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.
Posts: 795
Threads: 136
Joined: Feb 2009
Brilliant, did not think about that.
Any hint to store and paste an image using this?
Posts: 12,066
Threads: 140
Joined: Dec 2002
Your macro can do it, when it runs from the menu. Look in str.setsel help. It supports resources too.
Macro Macro2239
;\
function $text
;out text ;;must be .bmp file path or .bmp resource like "resource:<Macro2239>test.bmp"
_s=text
_s.setsel(CF_BITMAP)
Macro ShowDragDropTextMenu example
Trigger F7
str s=
;run macro that pastes image, resource:<Macro2239>test.bmp, Macro2239
;
ShowDragDropTextMenu s
Posts: 795
Threads: 136
Joined: Feb 2009
ok, wasn't aware of the new setsel feature.
TY
Posts: 795
Threads: 136
Joined: Feb 2009
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 ...
Posts: 12,066
Threads: 140
Joined: Dec 2002
The function always loads the specified file, does not use caching.
Posts: 795
Threads: 136
Joined: Feb 2009
Ok, I guess it's the same if the items are stored in a macro then...
Posts: 795
Threads: 136
Joined: Feb 2009
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?
Posts: 12,066
Threads: 140
Joined: Dec 2002
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.
Posts: 795
Threads: 136
Joined: Feb 2009
Ok, what you have done is fantastic so far, will use it a lot
Thanks so much
|