summaryrefslogtreecommitdiff
path: root/indra/newview/llpreviewscript.cpp
diff options
context:
space:
mode:
authorRichard Nelson <richard@lindenlab.com>2007-04-05 00:59:55 +0000
committerRichard Nelson <richard@lindenlab.com>2007-04-05 00:59:55 +0000
commit2ce0fc5f185f22be79b9be5406b76c97ed91ee01 (patch)
treed70ea9faf02e4e1e7aeb14aa524644c23c703d55 /indra/newview/llpreviewscript.cpp
parentfd5608a3e79397d4ebc8819dc9de75863f6fb9b3 (diff)
svn merge -r 59234:60086 svn+ssh://svn/svn/linden/branches/live_lsl_help2 -> release
Diffstat (limited to 'indra/newview/llpreviewscript.cpp')
-rw-r--r--indra/newview/llpreviewscript.cpp249
1 files changed, 246 insertions, 3 deletions
diff --git a/indra/newview/llpreviewscript.cpp b/indra/newview/llpreviewscript.cpp
index 97b4a982d2..6a9965dbfb 100644
--- a/indra/newview/llpreviewscript.cpp
+++ b/indra/newview/llpreviewscript.cpp
@@ -57,6 +57,7 @@
#include "llviewertexteditor.h"
#include "llviewerwindow.h"
#include "llvieweruictrlfactory.h"
+#include "llwebbrowserctrl.h"
#include "lluictrlfactory.h"
#include "viewer.h"
@@ -115,6 +116,9 @@ const S32 SCRIPT_SEARCH_HEIGHT = 120;
const S32 SCRIPT_SEARCH_LABEL_WIDTH = 50;
const S32 SCRIPT_SEARCH_BUTTON_WIDTH = 80;
const S32 TEXT_EDIT_COLUMN_HEIGHT = 16;
+const S32 MAX_HISTORY_COUNT = 10;
+const F32 LIVE_HELP_REFRESH_TIME = 1.f;
+
/// ---------------------------------------------------------------------------
/// LLFloaterScriptSearch
/// ---------------------------------------------------------------------------
@@ -254,6 +258,7 @@ void LLFloaterScriptSearch::open() /*Flawfinder: ignore*/
LLFloater::open(); /*Flawfinder: ignore*/
childSetFocus("search_text", TRUE);
}
+
/// ---------------------------------------------------------------------------
/// LLScriptEdCore
/// ---------------------------------------------------------------------------
@@ -276,7 +281,9 @@ LLScriptEdCore::LLScriptEdCore(
mLoadCallback( load_callback ),
mSaveCallback( save_callback ),
mUserdata( userdata ),
- mForceClose( FALSE )
+ mForceClose( FALSE ),
+ mLastHelpToken(NULL),
+ mLiveHelpHistorySize(0)
{
setFollowsAll();
setBorderVisible(FALSE);
@@ -336,14 +343,13 @@ LLScriptEdCore::LLScriptEdCore(
initMenu();
-
// Do the work that addTabPanel() normally does.
//LLRect tab_panel_rect( 0, mRect.getHeight(), mRect.getWidth(), 0 );
//tab_panel_rect.stretch( -LLPANEL_BORDER_WIDTH );
//mCodePanel->setFollowsAll();
//mCodePanel->translate( tab_panel_rect.mLeft - mCodePanel->getRect().mLeft, tab_panel_rect.mBottom - mCodePanel->getRect().mBottom);
//mCodePanel->reshape( tab_panel_rect.getWidth(), tab_panel_rect.getHeight(), TRUE );
-
+
}
LLScriptEdCore::~LLScriptEdCore()
@@ -402,6 +408,9 @@ void LLScriptEdCore::initMenu()
menuItem->setMenuCallback(onBtnHelp, this);
menuItem->setEnabledCallback(NULL);
+ menuItem = LLUICtrlFactory::getMenuItemCallByName(this, "LSL Wiki Help...");
+ menuItem->setMenuCallback(onBtnDynamicHelp, this);
+ menuItem->setEnabledCallback(NULL);
}
BOOL LLScriptEdCore::hasChanged(void* userdata)
@@ -431,9 +440,135 @@ void LLScriptEdCore::draw()
childSetText("line_col", "");
}
+ updateDynamicHelp();
+
LLPanel::draw();
}
+void LLScriptEdCore::updateDynamicHelp(BOOL immediate)
+{
+ LLFloater* help_floater = LLFloater::getFloaterByHandle(mLiveHelpHandle);
+ if (!help_floater) return;
+
+ // update back and forward buttons
+ LLButton* fwd_button = LLUICtrlFactory::getButtonByName(help_floater, "fwd_btn");
+ LLButton* back_button = LLUICtrlFactory::getButtonByName(help_floater, "back_btn");
+ LLWebBrowserCtrl* browser = LLUICtrlFactory::getWebBrowserCtrlByName(help_floater, "lsl_guide_html");
+ back_button->setEnabled(browser->canNavigateBack());
+ fwd_button->setEnabled(browser->canNavigateForward());
+
+ if (!immediate && !gSavedSettings.getBOOL("ScriptHelpFollowsCursor"))
+ {
+ return;
+ }
+
+ LLTextSegment* segment = NULL;
+ std::vector<LLTextSegment*> selected_segments;
+ mEditor->getSelectedSegments(selected_segments);
+
+ // try segments in selection range first
+ std::vector<LLTextSegment*>::iterator segment_iter;
+ for (segment_iter = selected_segments.begin(); segment_iter != selected_segments.end(); ++segment_iter)
+ {
+ if((*segment_iter)->getToken() && (*segment_iter)->getToken()->getType() == LLKeywordToken::WORD)
+ {
+ segment = *segment_iter;
+ break;
+ }
+ }
+
+ // then try previous segment in case we just typed it
+ if (!segment)
+ {
+ LLTextSegment* test_segment = mEditor->getPreviousSegment();
+ if(test_segment->getToken() && test_segment->getToken()->getType() == LLKeywordToken::WORD)
+ {
+ segment = test_segment;
+ }
+ }
+
+ if (segment)
+ {
+ if (segment->getToken() != mLastHelpToken)
+ {
+ mLastHelpToken = segment->getToken();
+ mLiveHelpTimer.start();
+ }
+ if (immediate || (mLiveHelpTimer.getStarted() && mLiveHelpTimer.getElapsedTimeF32() > LIVE_HELP_REFRESH_TIME))
+ {
+ LLString help_string = mEditor->getText().substr(segment->getStart(), segment->getEnd() - segment->getStart());
+ setHelpPage(help_string);
+ mLiveHelpTimer.stop();
+ }
+ }
+ else
+ {
+ setHelpPage("");
+ }
+}
+
+void LLScriptEdCore::setHelpPage(const LLString& help_string)
+{
+ LLFloater* help_floater = LLFloater::getFloaterByHandle(mLiveHelpHandle);
+ if (!help_floater) return;
+
+ LLWebBrowserCtrl* web_browser = gUICtrlFactory->getWebBrowserCtrlByName(help_floater, "lsl_guide_html");
+ if (!web_browser) return;
+
+ LLComboBox* history_combo = gUICtrlFactory->getComboBoxByName(help_floater, "history_combo");
+ if (!history_combo) return;
+
+ LLUIString url_string = gSavedSettings.getString("LSLHelpURL");
+ url_string.setArg("[APP_DIRECTORY]", gDirUtilp->getWorkingDir());
+ url_string.setArg("[LSL_STRING]", help_string);
+
+ addHelpItemToHistory(help_string);
+ web_browser->navigateTo(url_string);
+}
+
+void LLScriptEdCore::addHelpItemToHistory(const LLString& help_string)
+{
+ if (help_string.empty()) return;
+
+ LLFloater* help_floater = LLFloater::getFloaterByHandle(mLiveHelpHandle);
+ if (!help_floater) return;
+
+ LLComboBox* history_combo = gUICtrlFactory->getComboBoxByName(help_floater, "history_combo");
+ if (!history_combo) return;
+
+ // separate history items from full item list
+ if (mLiveHelpHistorySize == 0)
+ {
+ LLSD row;
+ row["columns"][0]["type"] = "separator";
+ history_combo->addElement(row, ADD_TOP);
+ }
+ // delete all history items over history limit
+ while(mLiveHelpHistorySize > MAX_HISTORY_COUNT - 1)
+ {
+ history_combo->remove(mLiveHelpHistorySize - 1);
+ mLiveHelpHistorySize--;
+ }
+
+ history_combo->setSimple(help_string);
+ S32 index = history_combo->getCurrentIndex();
+
+ // if help string exists in the combo box
+ if (index >= 0)
+ {
+ S32 cur_index = history_combo->getCurrentIndex();
+ if (cur_index < mLiveHelpHistorySize)
+ {
+ // item found in history, bubble up to top
+ history_combo->remove(history_combo->getCurrentIndex());
+ mLiveHelpHistorySize--;
+ }
+ }
+ history_combo->add(help_string, LLSD(help_string), ADD_TOP);
+ history_combo->selectFirstItem();
+ mLiveHelpHistorySize++;
+}
+
BOOL LLScriptEdCore::canClose()
{
if(mForceClose || mEditor->isPristine())
@@ -498,6 +633,92 @@ void LLScriptEdCore::onBtnHelp(void* userdata)
}
// static
+void LLScriptEdCore::onBtnDynamicHelp(void* userdata)
+{
+ LLScriptEdCore* corep = (LLScriptEdCore*)userdata;
+
+ LLFloater* live_help_floater = LLFloater::getFloaterByHandle(corep->mLiveHelpHandle);
+ if (live_help_floater)
+ {
+ live_help_floater->setFocus(TRUE);
+ corep->updateDynamicHelp(TRUE);
+
+ return;
+ }
+
+ live_help_floater = new LLFloater("lsl_help");
+ gUICtrlFactory->buildFloater(live_help_floater, "floater_lsl_guide.xml");
+ ((LLFloater*)corep->getParent())->addDependentFloater(live_help_floater, TRUE);
+ live_help_floater->childSetCommitCallback("lock_check", onCheckLock, userdata);
+ live_help_floater->childSetValue("lock_check", gSavedSettings.getBOOL("ScriptHelpFollowsCursor"));
+ live_help_floater->childSetCommitCallback("history_combo", onHelpComboCommit, userdata);
+ live_help_floater->childSetAction("back_btn", onClickBack, userdata);
+ live_help_floater->childSetAction("fwd_btn", onClickForward, userdata);
+
+ LLWebBrowserCtrl* browser = LLUICtrlFactory::getWebBrowserCtrlByName(live_help_floater, "lsl_guide_html");
+ browser->setAlwaysRefresh(TRUE);
+
+ LLComboBox* help_combo = LLUICtrlFactory::getComboBoxByName(live_help_floater, "history_combo");
+ LLKeywordToken *token;
+ LLKeywords::word_token_map_t::iterator token_it;
+ for (token_it = corep->mEditor->mKeywords.mWordTokenMap.begin();
+ token_it != corep->mEditor->mKeywords.mWordTokenMap.end();
+ ++token_it)
+ {
+ token = token_it->second;
+ help_combo->add(wstring_to_utf8str(token->mToken));
+ }
+ help_combo->sortByName();
+
+ // re-initialize help variables
+ corep->mLastHelpToken = NULL;
+ corep->mLiveHelpHandle = live_help_floater->getHandle();
+ corep->mLiveHelpHistorySize = 0;
+ corep->updateDynamicHelp(TRUE);
+}
+
+//static
+void LLScriptEdCore::onClickBack(void* userdata)
+{
+ LLScriptEdCore* corep = (LLScriptEdCore*)userdata;
+ LLFloater* live_help_floater = LLFloater::getFloaterByHandle(corep->mLiveHelpHandle);
+ if (live_help_floater)
+ {
+ LLWebBrowserCtrl* browserp = LLUICtrlFactory::getWebBrowserCtrlByName(live_help_floater, "lsl_guide_html");
+ if (browserp)
+ {
+ browserp->navigateBack();
+ }
+ }
+}
+
+//static
+void LLScriptEdCore::onClickForward(void* userdata)
+{
+ LLScriptEdCore* corep = (LLScriptEdCore*)userdata;
+ LLFloater* live_help_floater = LLFloater::getFloaterByHandle(corep->mLiveHelpHandle);
+ if (live_help_floater)
+ {
+ LLWebBrowserCtrl* browserp = LLUICtrlFactory::getWebBrowserCtrlByName(live_help_floater, "lsl_guide_html");
+ if (browserp)
+ {
+ browserp->navigateForward();
+ }
+ }
+}
+
+// static
+void LLScriptEdCore::onCheckLock(LLUICtrl* ctrl, void* userdata)
+{
+ LLScriptEdCore* corep = (LLScriptEdCore*)userdata;
+
+ // clear out token any time we lock the frame, so we will refresh web page immediately when unlocked
+ gSavedSettings.setBOOL("ScriptHelpFollowsCursor", ctrl->getValue().asBoolean());
+
+ corep->mLastHelpToken = NULL;
+}
+
+// static
void LLScriptEdCore::onBtnInsertSample(void* userdata)
{
LLScriptEdCore* self = (LLScriptEdCore*) userdata;
@@ -509,6 +730,27 @@ void LLScriptEdCore::onBtnInsertSample(void* userdata)
}
// static
+void LLScriptEdCore::onHelpComboCommit(LLUICtrl* ctrl, void* userdata)
+{
+ LLScriptEdCore* corep = (LLScriptEdCore*)userdata;
+
+ LLFloater* live_help_floater = LLFloater::getFloaterByHandle(corep->mLiveHelpHandle);
+ if (live_help_floater)
+ {
+ LLWebBrowserCtrl* web_browser = gUICtrlFactory->getWebBrowserCtrlByName(live_help_floater, "lsl_guide_html");
+
+ LLString help_string = ctrl->getValue().asString();
+
+ corep->addHelpItemToHistory(help_string);
+
+ LLUIString url_string = gSavedSettings.getString("LSLHelpURL");
+ url_string.setArg("[APP_DIRECTORY]", gDirUtilp->getWorkingDir());
+ url_string.setArg("[LSL_STRING]", help_string);
+ web_browser->navigateTo(url_string);
+ }
+}
+
+// static
void LLScriptEdCore::onBtnInsertFunction(LLUICtrl *ui, void* userdata)
{
LLScriptEdCore* self = (LLScriptEdCore*) userdata;
@@ -519,6 +761,7 @@ void LLScriptEdCore::onBtnInsertFunction(LLUICtrl *ui, void* userdata)
self->mEditor->insertText(self->mFunctions->getSimple());
}
self->mEditor->setFocus(TRUE);
+ self->setHelpPage(self->mFunctions->getSimple());
}
// static