MCPcopy Create free account
hub / github.com/DISTRHO/Cardinal / appendContextMenu

Method appendContextMenu

plugins/Cardinal/src/MPV.cpp:143–199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

141 }
142
143 void appendContextMenu(ui::Menu* const menu) override
144 {
145 // embed player gets in the way, hide it
146 if (isEmbed)
147 embedWidget->hide();
148
149 menu->addChild(new ui::MenuSeparator);
150
151 struct LoadVideoFileItem : MenuItem {
152 CardinalEmbedWidget* const self;
153
154 LoadVideoFileItem(CardinalEmbedWidget* const s)
155 : self(s)
156 {
157 text = "Load video file...";
158 }
159
160 ~LoadVideoFileItem() override
161 {
162 d_stdout("submenu closed");
163 if (self->isEmbed)
164 self->embedWidget->show();
165 }
166
167 void onAction(const event::Action&) override
168 {
169 // terminate old one
170 self->videoIsLoaded = false;
171 self->terminateAndWaitForExternalProcess();
172
173 WeakPtr<CardinalEmbedWidget> const self = this->self;
174 async_dialog_filebrowser(false, nullptr, nullptr, text.c_str(), [self](char* path)
175 {
176 if (path == nullptr)
177 return;
178
179 if (self != nullptr)
180 {
181 char winIdStr[64];
182 std::snprintf(winIdStr, sizeof(winIdStr), "--wid=%lu",
183 static_cast<ulong>(self->embedWidget->getNativeWindowId()));
184 const char* args[] = {
185 "mpv", "--no-audio", winIdStr, path, nullptr
186 };
187
188 self->videoIsLoaded = true;
189 self->embedWidget->show();
190 self->startExternalProcess(args);
191 }
192
193 std::free(path);
194 });
195 }
196 };
197
198 menu->addChild(new LoadVideoFileItem(this));
199 }
200};

Callers

nothing calls this directly

Calls 2

addChildMethod · 0.80
hideMethod · 0.45

Tested by

no test coverage detected