1212using namespace iplug ;
1313using namespace igraphics ;
1414
15+ enum class NAMBrowserState
16+ {
17+ Empty, // when no file loaded, show "Get" button
18+ Loaded // when file loaded, show "Clear" button
19+ };
20+
1521// Where the corner button on the plugin (settings, close settings) goes
1622// :param rect: Rect for the whole plugin's UI
1723IRECT CornerButtonArea (const IRECT& rect)
@@ -209,12 +215,30 @@ class NAMFileNameControl : public IVButtonControl
209215 }
210216};
211217
218+ // URL control for the "Get" models/irs links
219+ class NAMGetButtonControl : public NAMSquareButtonControl
220+ {
221+ public:
222+ NAMGetButtonControl (const IRECT& bounds, const char * label, const char * url, const ISVG& globeSVG)
223+ : NAMSquareButtonControl(
224+ bounds,
225+ [url](IControl* pCaller) {
226+ WDL_String fullURL (url);
227+ pCaller->GetUI ()->OpenURL (fullURL.Get ());
228+ },
229+ globeSVG)
230+ {
231+ SetTooltip (label);
232+ }
233+ };
234+
212235class NAMFileBrowserControl : public IDirBrowseControlBase
213236{
214237public:
215238 NAMFileBrowserControl (const IRECT& bounds, int clearMsgTag, const char * labelStr, const char * fileExtension,
216239 IFileDialogCompletionHandlerFunc ch, const IVStyle& style, const ISVG& loadSVG,
217- const ISVG& clearSVG, const ISVG& leftSVG, const ISVG& rightSVG, const IBitmap& bitmap)
240+ const ISVG& clearSVG, const ISVG& leftSVG, const ISVG& rightSVG, const IBitmap& bitmap,
241+ const ISVG& globeSVG, const char * getButtonLabel, const char * getButtonURL)
218242 : IDirBrowseControlBase(bounds, fileExtension, false , false )
219243 , mClearMsgTag (clearMsgTag)
220244 , mDefaultLabelStr (labelStr)
@@ -225,6 +249,10 @@ class NAMFileBrowserControl : public IDirBrowseControlBase
225249 , mClearSVG (clearSVG)
226250 , mLeftSVG (leftSVG)
227251 , mRightSVG (rightSVG)
252+ , mGlobeSVG (globeSVG)
253+ , mGetButtonLabel (getButtonLabel)
254+ , mGetButtonURL (getButtonURL)
255+ , mBrowserState (NAMBrowserState::Empty)
228256 {
229257 mIgnoreMouse = true ;
230258 }
@@ -304,6 +332,7 @@ class NAMFileBrowserControl : public IDirBrowseControlBase
304332 auto clearFileFunc = [&](IControl* pCaller) {
305333 pCaller->GetDelegate ()->SendArbitraryMsgFromUI (mClearMsgTag );
306334 mFileNameControl ->SetLabelAndTooltip (mDefaultLabelStr .Get ());
335+ SetBrowserState (NAMBrowserState::Empty);
307336 // FIXME disabling output mode...
308337 // pCaller->GetUI()->GetControlWithTag(kCtrlTagOutputMode)->SetDisabled(false);
309338 };
@@ -328,7 +357,7 @@ class NAMFileBrowserControl : public IDirBrowseControlBase
328357 IRECT padded = mRECT .GetPadded (-6 .f ).GetHPadded (-2 .f );
329358 const auto buttonWidth = padded.H ();
330359 const auto loadFileButtonBounds = padded.ReduceFromLeft (buttonWidth);
331- const auto clearButtonBounds = padded.ReduceFromRight (buttonWidth);
360+ const auto clearAndGetButtonBounds = padded.ReduceFromRight (buttonWidth);
332361 const auto leftButtonBounds = padded.ReduceFromLeft (buttonWidth);
333362 const auto rightButtonBounds = padded.ReduceFromLeft (buttonWidth);
334363 const auto fileNameButtonBounds = padded;
@@ -341,10 +370,17 @@ class NAMFileBrowserControl : public IDirBrowseControlBase
341370 ->SetAnimationEndActionFunction (nextFileFunc);
342371 AddChildControl (mFileNameControl = new NAMFileNameControl (fileNameButtonBounds, mDefaultLabelStr .Get (), mStyle ))
343372 ->SetAnimationEndActionFunction (chooseFileFunc);
344- AddChildControl (new NAMSquareButtonControl (clearButtonBounds, DefaultClickActionFunc, mClearSVG ))
345- ->SetAnimationEndActionFunction (clearFileFunc);
346373
347- mFileNameControl ->SetLabelAndTooltip (mDefaultLabelStr .Get ());
374+ // creates both right-side controls but only show one based on state
375+ mClearButton = new NAMSquareButtonControl (clearAndGetButtonBounds, DefaultClickActionFunc, mClearSVG );
376+ mClearButton ->SetAnimationEndActionFunction (clearFileFunc);
377+ AddChildControl (mClearButton );
378+
379+ mGetButton = new NAMGetButtonControl (clearAndGetButtonBounds, mGetButtonLabel , mGetButtonURL , mGlobeSVG );
380+ AddChildControl (mGetButton );
381+
382+ // initialize control visibility
383+ SetBrowserState (NAMBrowserState::Empty);
348384 }
349385
350386 void LoadFileAtCurrentIndex ()
@@ -367,6 +403,7 @@ class NAMFileBrowserControl : public IDirBrowseControlBase
367403 {
368404 std::string label (std::string (" (FAILED) " ) + std::string (mFileNameControl ->GetLabelStr ()));
369405 mFileNameControl ->SetLabelAndTooltip (label.c_str ());
406+ SetBrowserState (NAMBrowserState::Empty);
370407 }
371408 break ;
372409 case kMsgTagLoadedModel :
@@ -382,8 +419,9 @@ class NAMFileBrowserControl : public IDirBrowseControlBase
382419 SetupMenu ();
383420 SetSelectedFile (fileName.Get ());
384421 mFileNameControl ->SetLabelAndTooltipEllipsizing (fileName);
385- break ;
422+ SetBrowserState (NAMBrowserState::Loaded) ;
386423 }
424+ break ;
387425 default : break ;
388426 }
389427 }
@@ -398,13 +436,38 @@ class NAMFileBrowserControl : public IDirBrowseControlBase
398436 return ;
399437 }
400438
439+ // set the state of the browser and the visibility of the "Get" vs. "Clear" buttons
440+ void SetBrowserState (NAMBrowserState newState)
441+ {
442+ mBrowserState = newState;
443+
444+ switch (mBrowserState )
445+ {
446+ case NAMBrowserState::Empty:
447+ mClearButton ->Hide (true );
448+ mGetButton ->Hide (false );
449+ break ;
450+ case NAMBrowserState::Loaded:
451+ mClearButton ->Hide (false );
452+ mGetButton ->Hide (true );
453+ break ;
454+ }
455+ }
456+
401457 WDL_String mDefaultLabelStr ;
402458 IFileDialogCompletionHandlerFunc mCompletionHandlerFunc ;
403459 NAMFileNameControl* mFileNameControl = nullptr ;
404460 IVStyle mStyle ;
405461 IBitmap mBitmap ;
406- ISVG mLoadSVG , mClearSVG , mLeftSVG , mRightSVG ;
462+ ISVG mLoadSVG , mClearSVG , mLeftSVG , mRightSVG , mGlobeSVG ;
407463 int mClearMsgTag ;
464+
465+ // new members for the "Get" button
466+ const char * mGetButtonLabel ;
467+ const char * mGetButtonURL ;
468+ NAMBrowserState mBrowserState ;
469+ NAMSquareButtonControl* mClearButton = nullptr ;
470+ NAMGetButtonControl* mGetButton = nullptr ;
408471};
409472
410473class NAMMeterControl : public IVPeakAvgMeterControl <>, public IBitmapBase
0 commit comments