asmpgmr:
One more revision and I think everyone is happy.
BrowserView.cpp:
[See notes 1 & 2]
-------------------------
void CBrowserView::OnNewUrlEnteredInUrlBar()
{
nsCOMPtr<nsIWebBrowserFocus> focus(do_GetInterface(mWebBrowser));
if(!focus) return;
focus->Activate();
mpBrowserFrame->m_wndUrlBar.EditChanged(FALSE);
// Get the currently entered URL
CString strUrl;
mpBrowserFrame->m_wndUrlBar.GetEnteredURL(strUrl);
// Add what was just entered into the UrlBar
mpBrowserFrame->m_wndUrlBar.AddURLToList(strUrl);
if(IsViewSourceUrl(strUrl)) {
OpenViewSourceWindow(strUrl.GetBuffer(0));
return;
}
else {
strUrl = NicknameLookup((char*)strUrl.GetBuffer(0));
// Navigate to that URL
OpenURL(strUrl.GetBuffer(0));
}
}
// ...
char* CBrowserView::NicknameLookup(char* pUrl)
{
char *p, *q, *r;
char nickUrl[INTERNET_MAX_URL_LENGTH];
char custUrl[INTERNET_MAX_URL_LENGTH];
CString strUrl;
strUrl = pUrl;
// Check for a nickname
*nickUrl = 0;
p = strUrl.GetBuffer(0); // get entered URL
p = SkipWhiteSpace(p); // skip any leading spaces
q = strchr(p, ' '); // look for a space
if (q) // if more than one word
*q = 0; // terminate first word
theApp.plugins.SendMessage("bookmarks", "* FindNick", "FindNick", (long)p, (long)&nickUrl);
if (q) // if more than one word
*q = ' '; // restore space
if (*nickUrl != 0) {
r = strstr(nickUrl, "%s"); // look for %s
if (r) { // if found
*r = 0; // terminate string up to %s
strcpy(custUrl, nickUrl); // copy string before %s
if (q) // if more than one word
strcat(custUrl, q+1); // copy second word
strcat(custUrl, r+2); // copy string after %s
strUrl = custUrl;
}
else
strUrl = nickUrl;
}
else {
theApp.plugins.SendMessage("hotlist", "* FindNick", "FindNick", (long)p, (long)&nickUrl);
if (*nickUrl != 0)
strUrl = nickUrl;
}
return (char*)strUrl.GetBuffer(0);
}
// ...
void CBrowserView::OnFileOpen()
{
char *lpszFilter =
"HTML Files Only (*.htm;*.html)|*.htm;*.html|"
"All Files (*.*)|*.*||";
CFileDialog cf(TRUE, NULL, NULL, OFN_NOVALIDATE | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, lpszFilter, this);
cf.m_ofn.lpstrTitle = "Select a file or type in a URL";
if(cf.DoModal() == IDOK) {
CString strFullPath = cf.GetPathName(); // Will be like: c:\tmp\junk.htm
FILE *test = fopen(strFullPath, "r");
if (!test) {
// if the file doesn't exist, they probably typed a url...
// so chop off the path (for some reason GetFileName doesn't work for us...
strFullPath = strFullPath.Mid(strFullPath.ReverseFind('\\')+1);
strFullPath = NicknameLookup((char*)strFullPath.GetBuffer(0));
}
else
fclose(test);
OpenURL(strFullPath);
}
}
BrowserView.h:
[See note 3]
---------------------
char* CBrowserView::NicknameLookup(char* pUrl);
Plugins.cpp:
-----------------
char* EvalURL(char* pURLNick)
{
CBrowserFrame *mainFrame;
mainFrame = theApp.m_pMostRecentBrowserFrame;
pURLNick = mainFrame->m_wndBrowserView.NicknameLookup(pURLNick);
// Return that URL
return pURLNick;
}
Notes:
---------
1. In OnNewUrlEnteredInUrlBar, we have to add what was entered first, beause of setting strUrl in:
strUrl = NicknameLookup((char*)strUrl.GetBuffer(0));
Otherwise we'll add the return of NicknameLookup, not what was entered.
2. Made NicknameLookup return only once at the end of the function. If ther was no nick / quicksearch found then it returns what was passed to it (e.g., a regular url).
3. Declare it with full scope (CBrowserView:
, to allow for access from kmeleonFunctions (Plugins.cpp, EvalURL).
Only one instance of the lookup code, accessable from Ctrl-O, Url bar & via macro. Seems like everyone gets to have their cake and eat it too unless I'm missing something.
Shelumi`El
Jordan
S.D.G