@all
I'm developing small tools using texteditor.gadget that require copying text to the clipboard and pasting from it.
Instead of clipboard.device, I'm using textclip.library, which works well for both copying to and retrieving from the clipboard.
However, I'm facing issues with texteditor.gadget. Here are the details:
1. Unmarking Text and Setting Cursor After CopyAfter copying text to the clipboard, I want the selection to unmark and the cursor to move to the start of the previously marked text. My current approach, executed after ITextClip->WriteClipVector, is:
// Set cursor to selection start
IIntuition->SetGadgetAttrs((struct Gadget *)textEditor, window, NULL,
GA_TEXTEDITOR_CursorX, startx,
GA_TEXTEDITOR_CursorY, starty,
TAG_DONE);
// Activate the text editor
if (IIntuition->ActivateGadget((struct Gadget *)textEditor, window, NULL)) {
IDOS->Printf("Text editor activated successfully\n");
} else {
IDOS->Printf("Failed to activate text editor\n");
}
// Verify cursor position
ULONG newCursorX = 0, newCursorY = 0;
IIntuition->GetAttr(GA_TEXTEDITOR_CursorX, textEditor, &newCursorX);
IIntuition->GetAttr(GA_TEXTEDITOR_CursorY, textEditor, &newCursorY);
IDOS->Printf("Cursor set to position (%lu, %lu), selection should be cleared\n", newCursorX, newCursorY);
// Refresh to clear selection visually
IIntuition->RefreshGadgets((struct Gadget *)textEditor, window, NULL);
} else {
IDOS->Printf("Failed to write to clipboard\n");
}
This works, but is there a simpler way to instruct texteditor.gadget to unmark and reposition the cursor?
2. Pasting from ClipboardI'm stuck when pasting text from the clipboard into the texteditor window. I successfully read the clipboard buffer, but pasting fails. My code is:
IDOS->Printf("Pasting text: '%s', length: %lu\n", clipText, textLen);
// Ensure window and gadget are active
IIntuition->ActivateWindow(window);
if (!IIntuition->ActivateGadget((struct Gadget *)textEditor, window, NULL)) {
IDOS->Printf("Failed to activate text editor before paste\n");
ITextClip->DisposeClipVector(clipText);
return;
}
// Attempt to insert text at cursor
struct GP_TEXTEDITOR_InsertText insertMsg = {
.MethodID = GM_TEXTEDITOR_InsertText,
.GInfo = NULL, // GadgetInfo can be NULL
.text = clipText,
.pos = GV_TEXTEDITOR_InsertText_Cursor
};
if (IIntuition->IDoMethodA(textEditor, (Msg)&insertMsg)) {
IDOS->Printf("Successfully pasted %lu bytes into text editor\n", textLen);
// Activate and refresh
if (IIntuition->ActivateGadget((struct Gadget *)textEditor, window, NULL)) {
IDOS->Printf("Text editor activated successfully after paste\n");
} else {
IDOS->Printf("Failed to activate text editor after paste\n");
}
IIntuition->RefreshGadgets((struct Gadget *)textEditor, window, NULL);
IIntuition->RefreshWindowFrame(window);
} else {
IDOS->Printf("Failed to paste text into text editor: possible error in context or method\n");
}
ITextClip->DisposeClipVector(clipText);
I consistently get "Failed to paste text..." with IDoMethodA. Switching to DoGadgetMethodA yields the same error, though the text appears visually. Any suggestions?
3. Reading Selected Text for ClipboardReading selected text to copy to the clipboard works, but the process feels cumbersome. My current logic is:
Get selection coordinates via GM_TEXTEDITOR_BlockInfo (startx, starty, stopx, stopy).
Export full text with GM_TEXTEDITOR_ExportText.
Split text into lines by counting \n and replacing with \0.
Calculate indices, adjust order if needed.
Compute length, allocate a buffer, copy the selected portion, and add \n between lines.
Copy to clipboard.
Is there a more efficient method?
Any help would be greatly appreciated. Thanks!