|
|
|
06-17-2014, 04:15 PM
|
#1
|
Human being with feelings
Join Date: Sep 2009
Location: Virginia
Posts: 2,067
|
Menu Noob Question
Hi,
Thanks to Xenakios, I have created a plugin extension, and I'm able to put my action on a menu. Nothing fancy, just a google site search for the Reaper forums. In windows, I'm putting it as the last one in the help menu. It compiles and runs fine. When I put in the help menu for Mac, and click it, nothing happens. On Mac, if I put it on another menu like file, edit, etc. it works (also works in the actions). Here's the code I'm using to add that (taken from the ninjamloop example in the sdk).
Code:
g_parent = GetMainHwnd();
HMENU hMenu = GetSubMenu(GetMenu(GetMainHwnd()),
#ifdef _WIN32
8
#else // OS X has one extra menu
9
#endif
);
MENUITEMINFO mi={sizeof(MENUITEMINFO),};
mi.fMask = MIIM_TYPE | MIIM_ID;
mi.fType = MFT_STRING;
mi.dwTypeData = ("Search Reaper Forums");
mi.wID = g_registered_command01;
InsertMenuItem(hMenu, 12, TRUE, &mi);
Any ideals why this won't work for Mac?
Many Thanks, Wyatt
Last edited by WyattRice; 06-17-2014 at 04:25 PM.
|
|
|
06-19-2014, 12:06 PM
|
#2
|
Administrator
Join Date: Jan 2005
Location: NYC
Posts: 15,721
|
Hmm, this ought to work on OSX too, but just in case try adding after the InsertMenuItem() call:
Code:
#ifdef __APPLE__
SWELL_SetMenuDestination(hMenu,g_parent);
#endif
|
|
|
06-19-2014, 01:42 PM
|
#3
|
Human being with feelings
Join Date: Sep 2009
Location: Virginia
Posts: 2,067
|
Many Thanks. Seems to be working. One more quick question. The code I have for the google search thingy works great for Windows using ShellExecute, but on OSX I have it working by adding the swell-modstubb.mm to the xcode project. It works, but it doesn't see space as %20 if I type two words in the input box. My way around it for now is:
Code:
void sreplace(std::string &str)
{
int i = -1;
i = str.find_first_of(" ") ;
if(str.empty() || i == -1)
return;
str.erase(i,1);
str.insert(i, "%20", 3);
sreplace(str);
}
Here's my action code:
Code:
void doAction1()
{
const char* dialog_name = "Reaper Google Search";
int howmanyfields = 1;
const char* field_names = "Search Reaper Forums";
int maxreturnlength = 50;
std::vector<char> resultvec(maxreturnlength);
bool proceed=GetUserInputs(dialog_name, howmanyfields, field_names, resultvec.data(), maxreturnlength);
if (proceed == true)
{
std::string url_to_launch = "http://www.google.com/search?hl=en&biw=1280&bih=844&as_q=";
url_to_launch += resultvec.data();
url_to_launch +="&as_epq=&as_oq=&as_eq=&tbs=&lr=&as_filetype=&ft=i&as_sitesearch=forum.cockos.com&as_qdr=all&as_rights=&as_occt=any&cr=&as_nlo=&as_nhi=&safe=images";
sreplace(url_to_launch);
ShellExecute(NULL, ("open"), url_to_launch.c_str(), NULL, NULL, SW_SHOWNORMAL);
}
// resultvec doesn't need to be explicitly freed to avoid a memory leak,
// std::vector cleans up automatically at the end of this function
//resultvec.clear();
}
Is there a better way? Or I did have this working instead of ShellExecute.
Code:
//NSString* myURL = [NSString stringWithUTF8String:url_to_launch.c_str()];
//NSString* escapedUrlString =[myURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:escapedUrlString]];
Anyway, thanks for helping a noob.
|
|
|
06-19-2014, 04:19 PM
|
#4
|
Administrator
Join Date: Jan 2005
Location: NYC
Posts: 15,721
|
Yeah that looks about right, you need to encode spaces (and probably some other characters too).
|
|
|
06-19-2014, 05:44 PM
|
#5
|
Human being with feelings
Join Date: Sep 2009
Location: Virginia
Posts: 2,067
|
Thanks for the reply. I will study the encoding thing.
Would it be possible to add it in the swell-wnd.mm using NSWorkspace so that it would encode automatically?
Code:
BOOL ShellExecute(HWND hwndDlg, const char *action, const char *content1, const char *content2, const char *content3, int blah)
{
if (content1 && !strnicmp(content1,"http://",7))
{
NSWorkspace *wk = [NSWorkspace sharedWorkspace];
if (!wk) return FALSE;
NSString *fnstr=(NSString *)SWELL_CStringToCFString(content1);
BOOL ret=[wk openURL:[NSURL URLWithString:fnstr]];
[fnstr release];
return ret;
}
Thanks for your time (especially for a complete noob).
Edit: I'll try and figure it out.
Many Thanks.
Last edited by WyattRice; 06-19-2014 at 07:24 PM.
|
|
|
12-08-2014, 04:39 PM
|
#6
|
Human being with feelings
Join Date: Dec 2014
Posts: 14
|
Hi guys, first post and it will be a development post!
I'm ressurecting this thread a bit since it's in the same topic...
I'm trying to figure out why I can't append a new major menu to the menu bar. When I run reaper there is absolutely no change at all in the menu bar. My code is as following:
Code:
// In extern "C" REAPER_PLUGIN_DLL_EXPORT int REAPER_PLUGIN_ENTRYPOINT...
HMENU hMenu = GetMenu(GetMainHwnd());
HMENU hSubMenu = CreateMenu();
AppendMenu(hMenu, MF_STRING, (UINT_PTR)hSubMenu, "Foo");
DrawMenuBar(GetMainHwnd());
If I instead change DrawMenuBar() to SetMenu() I completely empty the menu bar (figures) but no "Foo" option is shown, just a blank bar.
Code:
SetMenu(GetMainHwnd(), hMenu);
Is it even possible to add another major drop down menu, or am I trying the impossible here...?
|
|
|
12-09-2014, 04:04 PM
|
#8
|
Human being with feelings
Join Date: Dec 2014
Posts: 14
|
Quote:
Originally Posted by WyattRice
|
Awesome, it works great now!
Thanks a ton WyattRice!
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 02:18 AM.
|