CudaText
CudaText copied to clipboard
macOS: ExtTools plugin, buttons are bugged
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:

linux:

windows:

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.
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?
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.
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.
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)
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.
~~hehe, 'focused=1' is OK, because 0-th control is 'label'.~~
@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)
@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.
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!
dlg_custom API problem or Lazarus issue?
on small repro Console command it is always 3? (on mac)
yes, it always returns initial listview index on mac. no matter what you select.
so if initial 'val=' is N, it returns always N? Seems a Cocoa widgetset bug. I must prepare small Mac demo for you
Here is demo - it shows the same as Cud 'value' on pressing the button. tst-listview-ItemFocused.zip
(not sure is COCOA the default widgetset or old CARBON? you can change it in the Project Options dialog - presss 'set LCL widget type')

it's here:

okay. The repro-demo shows the bug?
and no item was focused at form show (visually)
Lazarus 2.3.0 (rev main-2_3-1832-gc303bd45d2) FPC 3.2.2 x86_64-darwin-cocoa
don't know if this issue is related: https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/34211 it is still open.
Better you post the Lazarus bug report (in the GitLab) then me, because dev may ask something
done https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/39856
@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?
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;
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;
@veksha I am changing it on Mac, dont worry
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, 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":
(maybe you could do similar workaround as you did for macos.)
Reproduced on qt5.
made the fix. It works for me.