How to call editor method from draggable component?

I have a single button that I want to be draggable.
I have it in another header file.
I instantiate it in MyAppAudioProcessorEditor.
So far so good.

But there is an MyAppAudioProcessorEditor method I need to include in the subcomponents onDrag method at the moment dragging occurs. I’m new to this… how do I do this?
I thought to let my draggable component accept a reference to MyAppAudioProcessorEditor and simply use the method that way, as shown:

class MyDraggableComp : public juce::TextButton, public juce::DragAndDropContainer
{
public: MyDraggableComp(MyAppAudioProcessorEditor& editor) myeditor{editor} 
{ void onDrag() { myeditor.method()}
MyAppAudioProcessorEditor& myeditor
}

But my IDE says
Unknown type name 'MyAppAudioProcessorEditor'; did you mean 'MyAppAudioProcessor'?

It says MyAppAudioProcessorEditor doesn’t exist even though it will suggest it in the dropdown as I begin typing “MyAppAudio…” and even though I include the processor header file.

First of all, is including a reference to my processor the best solution here?

In any case how do I handle this?
Thanks!

If your DraggableComp depends on your editor, and your editor depends on your draggable comp, you will have a circular dependency in your code. Such circular dependencies can become quite difficult to maintain, and so it’s normally best to avoid this sort of structure.

You can get around this by introducing a new type, e.g:

struct DraggableCompListener
{
    virtual ~DraggableCompListener() noexcept = default;
    virtual void compWasDragged() = 0;
};

struct DraggableComp : public juce::Component
{
    DraggableComp (DraggableCompListener& l)
        : listener (&l) {}

    void mouseDrag (const juce::MouseEvent&) override { listener->compWasDragged(); }

    DraggableCompListener* listener = nullptr;
};

class MyEditor : public juce::AudioProcessorEditor,
                 private DraggableCompListener
{
    void compWasDragged() override
    {
        ...
    }

    DraggableComp draggableComp { *this };
};

Perfect, thanks for the guidance!

You can use findParentComponentOfClass from inside the component class after addAndMakeVisible or addChildComponent has been called on it. You can replace AudioProcessorEditor with your editor class if it’s accessable from your component class.

if (auto *editor = findParentComponentOfClass<AudioProcessorEditor>())
{
   // use editor here
}