CudaText icon indicating copy to clipboard operation
CudaText copied to clipboard

macOS: ExtTools plugin, buttons are bugged

Open veksha opened this issue 3 years ago • 23 comments

On macOS ExtTools plugin is unusable, because all buttons are working only with first item, no matter what item you select. I have investigated Kvichansky code (!!) a bit and found that dlg_custom API acts differently on mac. it must return "focused=N with index of last focused control" (c) wiki

I think on mac it returns wrong index, therefore ExtTools addon is confused.

mac:

2022-08-14_05-13

linux:

2022-08-14_05-18

windows: Screenshot 2022-08-14 052427

veksha avatar Aug 14 '22 02:08 veksha

dlg_custom returns 2-tuple: (clicked_index, values_as_str) It gets clicked_index==10 for all 3 OSes. but it gets 'focused=3' on Mac. 'focused' is not important i guess. Ie I don't know how ExtTools reacts to 'focused' value,, maybe it ignores it, important is 'clicked_index' which is 10.

Alexey-T avatar Aug 14 '22 06:08 Alexey-T

On macOS ExtTools plugin is unusable, because all buttons are working only with first item, no matter what item you select.

this is important of course. can you make small repro plugin?

Alexey-T avatar Aug 14 '22 06:08 Alexey-T

if ExtTools 'works with 1st item' then we get 'value' of listview as 0.

* For "combo_ro", "listbox", "radiogroup", "listview": value is index (0-based) of selected item.

so your repro plugin must show that we get 0 value of listview on mac.

Alexey-T avatar Aug 14 '22 06:08 Alexey-T

my micro repro:

>>> dlg_custom('tst', 400, 300, 'type=label\1x=300\1y=10\1cap=text\ntype=button\1x=10\1y=10\1cap=ok\ntype=listview\1x=10\1y=40\1w=300\1h=200\1items=aa\tbb\tcc\tdd\tee\tff\1val=3')

enter it in Console.

Alexey-T avatar Aug 14 '22 07:08 Alexey-T

focused control for mac is correct, because it is just the way it works in mac. you can't set focus to button control with mouse click (focus will stay at listview)

Peek 2022-08-14 10-21.webm

But I tried to set focus with Tab key in ExtTools, and it is still bugged even when focused is now correctly 10. so I need to investigate a little more.

veksha avatar Aug 14 '22 07:08 veksha

~~hehe, 'focused=1' is OK, because 0-th control is 'label'.~~

Alexey-T avatar Aug 14 '22 07:08 Alexey-T

@veksha could you find missed keywords/ spec-words in Swift lexer? i see from your pic, that we miss highlight for 'final', 'override' modifiers (i usually give them spec category)

Alexey-T avatar Aug 14 '22 07:08 Alexey-T

@veksha could you find missed keywords/ spec-words in Swift lexer? i see from your pic, that we miss highlight for 'final', 'override' modifiers (i usually give them spec category)

trying Swift for the first time, can't even compile a simple file. i'm zero level in Swift.

veksha avatar Aug 14 '22 07:08 veksha

OK. i see on Linux returned dict contains values like selected item in listview. notice 2,1,0 - it is index of selected item:

dlg_custom returns: (10, '1\n0\n0\n2\n\n\n\n\n\n\n\n\n\n\n\n\nfocused=10\n')
dlg_custom returns: (10, '1\n0\n0\n1\n\n\n\n\n\n\n\n\n\n\n\n\nfocused=10\n')
dlg_custom returns: (10, '1\n0\n0\n0\n\n\n\n\n\n\n\n\n\n\n\n\nfocused=10\n')

on mac it is always 0!

veksha avatar Aug 14 '22 07:08 veksha

dlg_custom API problem or Lazarus issue?

veksha avatar Aug 14 '22 07:08 veksha

on small repro Console command it is always 3? (on mac)

veksha avatar Aug 14 '22 08:08 veksha

yes, it always returns initial listview index on mac. no matter what you select.

veksha avatar Aug 14 '22 08:08 veksha

so if initial 'val=' is N, it returns always N? Seems a Cocoa widgetset bug. I must prepare small Mac demo for you

Alexey-T avatar Aug 14 '22 08:08 Alexey-T

Here is demo - it shows the same as Cud 'value' on pressing the button. tst-listview-ItemFocused.zip

Alexey-T avatar Aug 14 '22 08:08 Alexey-T

(not sure is COCOA the default widgetset or old CARBON? you can change it in the Project Options dialog - presss 'set LCL widget type')

cccc

Alexey-T avatar Aug 14 '22 08:08 Alexey-T

it's here: image

veksha avatar Aug 14 '22 09:08 veksha

okay. The repro-demo shows the bug?

Alexey-T avatar Aug 14 '22 09:08 Alexey-T

yes. also there was no items visible until i added column

Peek 2022-08-14 12-21.webm

veksha avatar Aug 14 '22 09:08 veksha

and no item was focused at form show (visually)

veksha avatar Aug 14 '22 09:08 veksha

Lazarus 2.3.0 (rev main-2_3-1832-gc303bd45d2) FPC 3.2.2 x86_64-darwin-cocoa

veksha avatar Aug 14 '22 09:08 veksha

don't know if this issue is related: https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/34211 it is still open.

veksha avatar Aug 14 '22 09:08 veksha

Better you post the Lazarus bug report (in the GitLab) then me, because dev may ask something

Alexey-T avatar Aug 14 '22 09:08 Alexey-T

done https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/39856

veksha avatar Aug 14 '22 10:08 veksha

@veksha small idea. In proc_customdialog.pas, in function DoControl_GetState_Listview , replace

  Result:= ''; 
  if Assigned(C.ItemFocused) then
    Result:= IntToStr(C.ItemFocused.Index);  

with

  Result:= IntToStr(C.ItemIndex); 

is it a workaround? can you test on mac again?

Alexey-T avatar Dec 17 '22 13:12 Alexey-T

additional fix needed if you will test ExtTools. in procedure DoControl_SetState_Listview change

  if (N>=0) and (N<C.Items.Count) then
  begin
    C.ItemFocused:= C.Items[N];
    C.Selected:= C.ItemFocused;
    if Assigned(C.ItemFocused) then
      C.ItemFocused.MakeVisible(false);
  end;  

with

  if (N>=0) and (N<C.Items.Count) then
  begin
    C.ItemIndex:= N;
    if Assigned(C.Selected) then
      C.Selected.MakeVisible(false);
  end; 

Alexey-T avatar Dec 17 '22 13:12 Alexey-T

for simpler test in demo! change this block in my demo above, tst-listview-ItemFocused.zip -

procedure TForm1.Button1Click(Sender: TObject);
begin
  {
  with Listview1 do
    if Assigned(ItemFocused) then
      self.caption:= 'ItemFocused index: '+Inttostr(ItemFocused.Index)
    else
      self.caption:= 'ItemFocused nil';
      }
  self.caption:= 'ItemIndex: '+IntTostr(Listview1.ItemIndex);
end;

procedure TForm1.FormShow(Sender: TObject);
begin
  with ListView1 do
    ItemIndex:= 3;
end;

Alexey-T avatar Dec 17 '22 13:12 Alexey-T

@veksha I am changing it on Mac, dont worry

Alexey-T avatar Dec 17 '22 18:12 Alexey-T

partially solved by patch. but on Mac, ExtTools dialog cannot SET the selected item on show. but Edit button shows config-dlg for the OK item.

Alexey-T avatar Dec 17 '22 18:12 Alexey-T

@Alexey-T, maybe this issue was solved for macos (not tested), but it happens also for CudaText-QT. CudaText 1.206.5.2, linux-x86_64-qt5, fpc 3.2.0 Lazarus 2.2.0 (rev Unknown) FPC 3.2.0 x86_64-linux-gtk2

repro in CudaText console:

dlg_custom('tst', 400, 300, 'type=label\1x=300\1y=10\1cap=text\ntype=button\1x=10\1y=10\1cap=ok\ntype=listview\1x=10\1y=40\1w=300\1h=200\1items=aa\tbb\tcc\tdd\tee\tff\1val=3')

you will see on video that it returns "-1" as selected item for the first time, but if you manually change item selection to another item and back, it returns correct index "3":

dlg_custom.webm

(maybe you could do similar workaround as you did for macos.)

veksha avatar Jan 08 '24 03:01 veksha

Reproduced on qt5.

Alexey-T avatar Jan 08 '24 10:01 Alexey-T

made the fix. It works for me.

Alexey-T avatar Jan 08 '24 10:01 Alexey-T