llfloatersearchreplace.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /**
  2. * @file llfloatersearchreplace.cpp
  3. * @brief LLFloaterSearchReplace class implementation
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewergpl$
  6. *
  7. * Copyright (c) 2002-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llcheckboxctrl.h"
  34. #include "lluictrlfactory.h"
  35. #include "llfloatersearchreplace.h"
  36. LLFloaterSearchReplace::LLFloaterSearchReplace(const LLSD&)
  37. : mEditor(NULL)
  38. {
  39. LLUICtrlFactory::getInstance()->buildFloater(this,
  40. "floater_search_replace.xml");
  41. }
  42. //virtual
  43. void LLFloaterSearchReplace::open()
  44. {
  45. LLFloater::open();
  46. if (mEditor)
  47. {
  48. bool read_only = mEditor->isReadOnly();
  49. childSetEnabled("replace_label", !read_only);
  50. childSetEnabled("replace_text", !read_only);
  51. childSetEnabled("replace_btn", !read_only);
  52. childSetEnabled("replace_all_btn", !read_only);
  53. }
  54. childSetFocus("search_text", true);
  55. }
  56. //virtual
  57. bool LLFloaterSearchReplace::postBuild()
  58. {
  59. childSetAction("search_btn", onBtnSearch, this);
  60. childSetAction("replace_btn", onBtnReplace, this);
  61. childSetAction("replace_all_btn", onBtnReplaceAll, this);
  62. setDefaultBtn("search_btn");
  63. return true;
  64. }
  65. //static
  66. void LLFloaterSearchReplace::show(LLTextEditor* editor)
  67. {
  68. // creates a new floater if needed
  69. LLFloaterSearchReplace* self = getInstance();
  70. if (self && editor)
  71. {
  72. self->mEditor = editor;
  73. LLFloater* newdependee;
  74. LLFloater* olddependee = self->getDependee();
  75. LLView* viewp = editor->getParent();
  76. while (viewp)
  77. {
  78. newdependee = viewp->asFloater();
  79. if (newdependee)
  80. {
  81. if (newdependee != olddependee)
  82. {
  83. if (olddependee)
  84. {
  85. olddependee->removeDependentFloater(self);
  86. }
  87. if (!newdependee->getHost())
  88. {
  89. newdependee->addDependentFloater(self);
  90. }
  91. else
  92. {
  93. newdependee->getHost()->addDependentFloater(self);
  94. }
  95. }
  96. break;
  97. }
  98. viewp = viewp->getParent();
  99. }
  100. // brings old instance to foreground if needed and refreshes labels
  101. self->open();
  102. }
  103. }
  104. //static
  105. void LLFloaterSearchReplace::onBtnSearch(void* userdata)
  106. {
  107. LLFloaterSearchReplace* self = (LLFloaterSearchReplace*)userdata;
  108. if (self && self->mEditor && self->getDependee())
  109. {
  110. LLCheckBoxCtrl* check = self->getChild<LLCheckBoxCtrl>("case_text");
  111. self->mEditor->selectNext(self->childGetText("search_text"),
  112. check->get());
  113. }
  114. }
  115. //static
  116. void LLFloaterSearchReplace::onBtnReplace(void* userdata)
  117. {
  118. LLFloaterSearchReplace* self = (LLFloaterSearchReplace*)userdata;
  119. if (self && self->mEditor && self->getDependee())
  120. {
  121. LLCheckBoxCtrl* check = self->getChild<LLCheckBoxCtrl>("case_text");
  122. self->mEditor->replaceText(self->childGetText("search_text"),
  123. self->childGetText("replace_text"),
  124. check->get());
  125. }
  126. }
  127. //static
  128. void LLFloaterSearchReplace::onBtnReplaceAll(void* userdata)
  129. {
  130. LLFloaterSearchReplace* self = (LLFloaterSearchReplace*)userdata;
  131. if (self && self->mEditor && self->getDependee())
  132. {
  133. LLCheckBoxCtrl* check = self->getChild<LLCheckBoxCtrl>("case_text");
  134. self->mEditor->replaceTextAll(self->childGetText("search_text"),
  135. self->childGetText("replace_text"),
  136. check->get());
  137. }
  138. }