DI_PSWEDIT

Здесь обсуждается всё, что касается макросов.
Post Reply
User avatar
John Doe
Бюрократ
Posts: 13860
Joined: Wed 27 Apr, 2005 20:42
Has thanked: 74 times
Been thanked: 428 times
Contact:

DI_PSWEDIT

Post by John Doe »

Макросы для работы с паролями, скрытыми под звёздочками.

CtrlIns — копировать пароль в буфер обмена
F3 — показать пароль
F4 — редактировать пароль

Альтернативно можно использовать пункт в меню плагинов.
Его можно настроить на одно из трёх перечисленных действий, для этого необходимо в начале скрипта изменить значение переменной F11Mode.
  1. --http://forum.farmanager.com/viewtopic.php?f=15&t=9684
  2.  
  3. local F11Mode = "copy"--"copy"--"show"--"edit"
  4.  
  5.  
  6.  
  7. local F,C = far.Flags,far.Colors
  8.  
  9. local strCopy,strShow,strEdit,strInputTitle,strInputPrompt = "Copy pwd: ","Show pwd","Edit pwd","Edit password",""
  10.  
  11. local copykey = "R?CtrlIns"
  12.  
  13.  
  14.  
  15. local pwd,hDlg,CurPos
  16.  
  17.  
  18.  
  19. local function getDI_PSWEDIT()
  20.  
  21.   hDlg = far.AdvControl(F.ACTL_GETWINDOWINFO).Id
  22.  
  23.   CurPos = hDlg:send(F.DM_GETFOCUS)
  24.  
  25.   local item = hDlg:send(F.DM_GETDLGITEM,CurPos)
  26.  
  27.   if item and item[1]==F.DI_PSWEDIT then
  28.  
  29.     pwd = hDlg:send(F.DM_GETTEXT,CurPos); return true
  30.  
  31.   end
  32.  
  33. end
  34.  
  35. local InputId = win.Uuid"589D1EEA-1C8D-4B85-80A8-A2377993A154"
  36.  
  37. local delay = 300
  38.  
  39. local actions = {
  40.  
  41.   copy=function() --------------------------------
  42.  
  43.     far.CopyToClipboard(pwd)
  44.  
  45.   end;
  46.  
  47.   show=function() --------------------------------
  48.  
  49.     local item = hDlg:send(F.DM_GETDLGITEM,CurPos)
  50.  
  51.     local X,Y = item[2],item[3]
  52.  
  53.     local r = hDlg:send(F.DM_GETDLGRECT)
  54.  
  55.     far.Text(r.Left+X,r.Top+Y,far.AdvControl(F.ACTL_GETCOLOR,C.COL_DIALOGEDIT),pwd)
  56.  
  57.     far.Text()
  58.  
  59.     local res = far.MacroExecute("return mf.waitkey()")
  60.  
  61.     if res then
  62.  
  63.       local key = res[1]
  64.  
  65.       if key:match(copykey) then
  66.  
  67.         far.CopyToClipboard(pwd)
  68.  
  69.         far.Text(r.Left+X,r.Top+Y,far.AdvControl(F.ACTL_GETCOLOR,C.COL_DIALOGEDITSELECTED),pwd)
  70.  
  71.         far.Text()
  72.  
  73.         win.Sleep(delay)
  74.  
  75.       else
  76.  
  77.         far.MacroPost(("if mf.eval('%s',2)==-1 then Keys'%s' end"):format(key,key))
  78.  
  79.       end
  80.  
  81.     end
  82.  
  83.     far.AdvControl(F.ACTL_REDRAWALL)
  84.  
  85.   end;
  86.  
  87.   edit=function() --------------------------------
  88.  
  89.     pwd = far.InputBox(InputId,strInputTitle,strInputPrompt,nil,pwd)
  90.  
  91.     if pwd then hDlg:send(F.DM_SETTEXT,CurPos,pwd) end
  92.  
  93.   end;
  94.  
  95. }
  96.  
  97.  
  98.  
  99. MenuItem { description="password: show/edit/copy";
  100.  
  101.   menu="Plugins"; area="Dialog";
  102.  
  103.   guid="61279036-42E9-4063-8C5A-714022F9BE3F";
  104.  
  105.   text=function()
  106.  
  107.     return getDI_PSWEDIT() and (F11Mode=="copy" and strCopy..pwd or F11Mode=="show" and strShow or strEdit)
  108.  
  109.   end;
  110.  
  111.   action=function()
  112.  
  113.     actions[F11Mode]()
  114.  
  115.   end;
  116.  
  117. }
  118.  
  119.  
  120.  
  121. Macro { description="password: copy";
  122.  
  123.   area="Dialog"; key="CtrlIns";
  124.  
  125.   uid="AF590D4C-C513-41A4-A8C9-0DC3F272CAB9";
  126.  
  127.   condition=getDI_PSWEDIT;
  128.  
  129.   action=actions.copy;
  130.  
  131. }
  132.  
  133.  
  134.  
  135. Macro { description="password: show";
  136.  
  137.   area="Dialog"; key="F3";
  138.  
  139.   uid="70501E5E-C0EE-41FD-8F96-9BC942F06586";
  140.  
  141.   condition=getDI_PSWEDIT;
  142.  
  143.   action=actions.show;
  144.  
  145. }
  146.  
  147.  
  148.  
  149. Macro { description="password: edit";
  150.  
  151.   area="Dialog"; key="F4";
  152.  
  153.   uid="B01D3DBD-E79E-40D8-93EA-3BDF25E089CF";
  154.  
  155.   condition=getDI_PSWEDIT;
  156.  
  157.   action=actions.edit;
  158.  
  159. }
Post Reply

Return to “Обсуждение макросов”