STORM-1911: Go-to line function for the internal LSL script editor

master
MartinRJ Fayray 2012-09-19 00:49:34 +02:00
parent 46a8d67a90
commit 005cd40247
8 changed files with 301 additions and 0 deletions

View File

@ -740,6 +740,7 @@ Marine Kelley
STORM-281
MartinRJ Fayray
STORM-1845
STORM-1911
Matthew Anthony
Matthew Dowd
VWR-1344

View File

@ -202,6 +202,7 @@ set(viewer_SOURCE_FILES
llfloaterfonttest.cpp
llfloatergesture.cpp
llfloatergodtools.cpp
llfloatergotoline.cpp
llfloatergroupinvite.cpp
llfloatergroups.cpp
llfloaterhandler.cpp
@ -778,6 +779,7 @@ set(viewer_HEADER_FILES
llfloaterfonttest.h
llfloatergesture.h
llfloatergodtools.h
llfloatergotoline.h
llfloatergroupinvite.h
llfloatergroups.h
llfloaterhandler.h

View File

@ -0,0 +1,160 @@
/**
* @file llfloatergotoline.h
* @author MartinRJ
* @brief LLFloaterGotoLine class implementation
*
* $LicenseInfo:firstyear=2012&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2012, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include "llviewerprecompiledheaders.h"
#include "llfloatergotoline.h"
#include "llpreviewscript.h"
#include "llfloaterreg.h"
#include "lllineeditor.h"
#include "llviewertexteditor.h"
#include "llviewerwindow.h"
LLFloaterGotoLine* LLFloaterGotoLine::sInstance = NULL;
LLFloaterGotoLine::LLFloaterGotoLine(LLScriptEdCore* editor_core)
: LLFloater(LLSD()),
mGotoBox(NULL),
mEditorCore(editor_core)
{
buildFromFile("floater_goto_line.xml");
sInstance = this;
// find floater in which script panel is embedded
LLView* viewp = (LLView*)editor_core;
while(viewp)
{
LLFloater* floaterp = dynamic_cast<LLFloater*>(viewp);
if (floaterp)
{
floaterp->addDependentFloater(this);
break;
}
viewp = viewp->getParent();
}
}
BOOL LLFloaterGotoLine::postBuild()
{
mGotoBox = getChild<LLLineEditor>("goto_line");
mGotoBox->setCommitCallback(boost::bind(&LLFloaterGotoLine::onGotoBoxCommit, this));
mGotoBox->setCommitOnFocusLost(FALSE);
getChild<LLLineEditor>("goto_line")->setPrevalidate(LLTextValidate::validateNonNegativeS32);
childSetAction("goto_btn", onBtnGoto,this);
setDefaultBtn("goto_btn");
return TRUE;
}
//static
void LLFloaterGotoLine::show(LLScriptEdCore* editor_core)
{
if (sInstance && sInstance->mEditorCore && sInstance->mEditorCore != editor_core)
{
sInstance->closeFloater();
delete sInstance;
}
if (!sInstance)
{
// sInstance will be assigned in the constructor.
new LLFloaterGotoLine(editor_core);
}
sInstance->openFloater();
}
LLFloaterGotoLine::~LLFloaterGotoLine()
{
sInstance = NULL;
}
// static
void LLFloaterGotoLine::onBtnGoto(void *userdata)
{
LLFloaterGotoLine* self = (LLFloaterGotoLine*)userdata;
self->handleBtnGoto();
}
void LLFloaterGotoLine::handleBtnGoto()
{
S32 row = 0;
S32 column = 0;
row = getChild<LLUICtrl>("goto_line")->getValue().asInteger();
if (row >= 0)
{
if (mEditorCore && mEditorCore->mEditor)
{
mEditorCore->mEditor->deselect();
mEditorCore->mEditor->setCursor(row, column);
mEditorCore->mEditor->setFocus(TRUE);
}
}
}
bool LLFloaterGotoLine::hasAccelerators() const
{
if (mEditorCore)
{
return mEditorCore->hasAccelerators();
}
return FALSE;
}
BOOL LLFloaterGotoLine::handleKeyHere(KEY key, MASK mask)
{
if (mEditorCore)
{
return mEditorCore->handleKeyHere(key, mask);
}
return FALSE;
}
void LLFloaterGotoLine::onGotoBoxCommit()
{
S32 row = 0;
S32 column = 0;
row = getChild<LLUICtrl>("goto_line")->getValue().asInteger();
if (row >= 0)
{
if (mEditorCore && mEditorCore->mEditor)
{
mEditorCore->mEditor->setCursor(row, column);
S32 rownew = 0;
S32 columnnew = 0;
mEditorCore->mEditor->getCurrentLineAndColumn( &rownew, &columnnew, FALSE ); // don't include wordwrap
if (rownew == row && columnnew == column)
{
mEditorCore->mEditor->deselect();
mEditorCore->mEditor->setFocus(TRUE);
sInstance->closeFloater();
} //else do nothing (if the cursor-position didn't change)
}
}
}

View File

@ -0,0 +1,66 @@
/**
* @file llfloatergotoline.h
* @author MartinRJ
* @brief LLFloaterGotoLine class definition
*
* $LicenseInfo:firstyear=2012&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2012, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#ifndef LL_LLFLOATERGOTOLINE_H
#define LL_LLFLOATERGOTOLINE_H
#include "llfloater.h"
#include "lllineeditor.h"
#include "llpreviewscript.h"
class LLScriptEdCore;
class LLFloaterGotoLine : public LLFloater
{
public:
LLFloaterGotoLine(LLScriptEdCore* editor_core);
~LLFloaterGotoLine();
/*virtual*/ BOOL postBuild();
static void show(LLScriptEdCore* editor_core);
static void onBtnGoto(void* userdata);
void handleBtnGoto();
LLScriptEdCore* getEditorCore() { return mEditorCore; }
static LLFloaterGotoLine* getInstance() { return sInstance; }
virtual bool hasAccelerators() const;
virtual BOOL handleKeyHere(KEY key, MASK mask);
private:
LLScriptEdCore* mEditorCore;
static LLFloaterGotoLine* sInstance;
protected:
LLLineEditor* mGotoBox;
void onGotoBoxCommit();
};
#endif // LL_LLFLOATERGOTOLINE_H

View File

@ -86,6 +86,7 @@
#include "lltrans.h"
#include "llviewercontrol.h"
#include "llappviewer.h"
#include "llfloatergotoline.h"
const std::string HELLO_LSL =
"default\n"
@ -193,12 +194,17 @@ private:
LLScriptEdCore* mEditorCore;
static LLFloaterScriptSearch* sInstance;
protected:
LLLineEditor* mSearchBox;
void onSearchBoxCommit();
};
LLFloaterScriptSearch* LLFloaterScriptSearch::sInstance = NULL;
LLFloaterScriptSearch::LLFloaterScriptSearch(LLScriptEdCore* editor_core)
: LLFloater(LLSD()),
mSearchBox(NULL),
mEditorCore(editor_core)
{
buildFromFile("floater_script_search.xml");
@ -221,6 +227,9 @@ LLFloaterScriptSearch::LLFloaterScriptSearch(LLScriptEdCore* editor_core)
BOOL LLFloaterScriptSearch::postBuild()
{
mSearchBox = getChild<LLLineEditor>("search_text");
mSearchBox->setCommitCallback(boost::bind(&LLFloaterScriptSearch::onSearchBoxCommit, this));
mSearchBox->setCommitOnFocusLost(FALSE);
childSetAction("search_btn", onBtnSearch,this);
childSetAction("replace_btn", onBtnReplace,this);
childSetAction("replace_all_btn", onBtnReplaceAll,this);
@ -311,6 +320,15 @@ BOOL LLFloaterScriptSearch::handleKeyHere(KEY key, MASK mask)
return FALSE;
}
void LLFloaterScriptSearch::onSearchBoxCommit()
{
if (mEditorCore && mEditorCore->mEditor)
{
LLCheckBoxCtrl* caseChk = getChild<LLCheckBoxCtrl>("case_text");
mEditorCore->mEditor->selectNext(getChild<LLUICtrl>("search_text")->getValue().asString(), caseChk->get());
}
}
/// ---------------------------------------------------------------------------
/// LLScriptEdCore
/// ---------------------------------------------------------------------------
@ -499,6 +517,9 @@ void LLScriptEdCore::initMenu()
menuItem = getChild<LLMenuItemCallGL>("Search / Replace...");
menuItem->setClickCallback(boost::bind(&LLFloaterScriptSearch::show, this));
menuItem = getChild<LLMenuItemCallGL>("Go to line...");
menuItem->setClickCallback(boost::bind(&LLFloaterGotoLine::show, this));
menuItem = getChild<LLMenuItemCallGL>("Help...");
menuItem->setClickCallback(boost::bind(&LLScriptEdCore::onBtnHelp, this));

View File

@ -34,6 +34,7 @@
#include "llcombobox.h"
#include "lliconctrl.h"
#include "llframetimer.h"
#include "llfloatergotoline.h"
class LLLiveLSLFile;
class LLMessageSystem;
@ -49,6 +50,7 @@ class LLKeywordToken;
class LLVFS;
class LLViewerInventoryItem;
class LLScriptEdContainer;
class LLFloaterGotoLine;
// Inner, implementation class. LLPreviewScript and LLLiveLSLEditor each own one of these.
class LLScriptEdCore : public LLPanel
@ -58,6 +60,7 @@ class LLScriptEdCore : public LLPanel
friend class LLLiveLSLEditor;
friend class LLFloaterScriptSearch;
friend class LLScriptEdContainer;
friend class LLFloaterGotoLine;
protected:
// Supposed to be invoked only by the container.

View File

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<floater
legacy_header_height="18"
default_tab_group="1"
height="90"
layout="topleft"
name="script goto"
help_topic="script_goto"
title="GO TO LINE"
width="200">
<button
height="24"
label="OK"
label_selected="OK"
layout="topleft"
left="55"
name="goto_btn"
top="53"
width="90" />
<text
type="string"
length="1"
follows="left|top"
height="16"
layout="topleft"
left="10"
name="txt"
top="21"
width="65">
Go to line
</text>
<line_editor
border_style="line"
border_thickness="1"
follows="left|top"
height="16"
layout="topleft"
left="75"
max_length_bytes="9"
name="goto_line"
tab_group="1"
top="21"
width="85" />
</floater>

View File

@ -125,6 +125,10 @@
label="Search / Replace..."
layout="topleft"
name="Search / Replace..." />
<menu_item_call
label="Go to line..."
layout="topleft"
name="Go to line..." />
</menu>
<menu
top="0"