aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llfloatersearchreplace.cpp
blob: a339a54a804426557004645018c1439ea3b7bc72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "llviewerprecompiledheaders.h"
#include "llcheckboxctrl.h"
#include "llfocusmgr.h"
#include "lluictrlfactory.h"

#include "llfloatersearchreplace.h"

const S32 SEARCH_REPLACE_WIDTH = 300;
const S32 SEARCH_REPLACE_HEIGHT = 120;
const std::string SEARCH_REPLACE_TITLE = "Search and Replace";

LLFloaterSearchReplace* LLFloaterSearchReplace::sInstance = NULL;

LLFloaterSearchReplace::LLFloaterSearchReplace() : mEditor(NULL),
	LLFloater(std::string("searchreplace"), LLRect(0, 0, SEARCH_REPLACE_WIDTH, SEARCH_REPLACE_HEIGHT), SEARCH_REPLACE_TITLE)
{
	LLUICtrlFactory::getInstance()->buildFloater(this, "floater_search_replace.xml");
}

LLFloaterSearchReplace::~LLFloaterSearchReplace()
{
	sInstance = NULL;
}

void LLFloaterSearchReplace::open()
{
	LLFloater::open();

	if (mEditor)
	{
		bool fReadOnly = mEditor->isReadOnly();
		childSetEnabled("replace_label", !fReadOnly);
		childSetEnabled("replace_text", !fReadOnly);
		childSetEnabled("replace_btn", !fReadOnly);
		childSetEnabled("replace_all_btn", !fReadOnly);
	}

	childSetFocus("search_text", TRUE);
}

BOOL LLFloaterSearchReplace::postBuild()
{
	childSetAction("search_btn", onBtnSearch, this);
	childSetAction("replace_btn", onBtnReplace, this);
	childSetAction("replace_all_btn", onBtnReplaceAll, this);

	setDefaultBtn("search_btn");

	return TRUE;
}

void LLFloaterSearchReplace::show(LLTextEditor* editor)
{
	if (!sInstance)
	{
		sInstance = new LLFloaterSearchReplace();
	}

	if ( (sInstance) && (editor) )
	{
		sInstance->mEditor = editor;

		LLFloater* newdependee, *olddependee = sInstance->getDependee();
		LLView* viewp = editor->getParent();
		while (viewp)
		{
			newdependee = dynamic_cast<LLFloater*>(viewp);
			if (newdependee)
			{
				if (newdependee != olddependee)
				{
					if (olddependee)
						olddependee->removeDependentFloater(sInstance);

					if (!newdependee->getHost())
						newdependee->addDependentFloater(sInstance);
					else
						newdependee->getHost()->addDependentFloater(sInstance);
				}
				break;
			}
			viewp = viewp->getParent();
		}

		sInstance->open();
	}
}

void LLFloaterSearchReplace::onBtnSearch(void* userdata)
{
	if ( (!sInstance) || (!sInstance->mEditor) || (!sInstance->getDependee()) )
		return;

	LLCheckBoxCtrl* caseChk = sInstance->getChild<LLCheckBoxCtrl>("case_text");
	sInstance->mEditor->selectNext(sInstance->childGetText("search_text"), caseChk->get());
}

void LLFloaterSearchReplace::onBtnReplace(void* userdata)
{
	if ( (!sInstance) || (!sInstance->mEditor) || (!sInstance->getDependee()) )
		return;

	LLCheckBoxCtrl* caseChk = sInstance->getChild<LLCheckBoxCtrl>("case_text");
	sInstance->mEditor->replaceText(sInstance->childGetText("search_text"), sInstance->childGetText("replace_text"), caseChk->get());
}

void LLFloaterSearchReplace::onBtnReplaceAll(void* userdata)
{
	if ( (!sInstance) || (!sInstance->mEditor) || (!sInstance->getDependee()) )
		return;

	LLCheckBoxCtrl* caseChk = sInstance->getChild<LLCheckBoxCtrl>("case_text");
	sInstance->mEditor->replaceTextAll(sInstance->childGetText("search_text"), sInstance->childGetText("replace_text"), caseChk->get());
}