From f3d6931fc360c9265d0aa96884c884e900bed72f Mon Sep 17 00:00:00 2001 From: Player Dagostino Date: Tue, 2 Aug 2011 20:07:55 +0200 Subject: [PATCH] Another port from CoolViewer of the notecard floater, featuring a menu and search/replace. --- indra/newview/CMakeLists.txt | 2 + indra/newview/llpreview.cpp | 21 ++ indra/newview/llpreviewnotecard.cpp | 229 +++++++++++++++++- indra/newview/llpreviewnotecard.h | 21 ++ indra/newview/llpreviewscript.cpp | 174 ++----------- indra/newview/llpreviewscript.h | 3 +- .../xui/en-us/floater_preview_notecard.xml | 47 +++- .../floater_preview_notecard_keep_discard.xml | 80 ++++-- 8 files changed, 386 insertions(+), 191 deletions(-) diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt index 89cd31abb..5c5746da7 100644 --- a/indra/newview/CMakeLists.txt +++ b/indra/newview/CMakeLists.txt @@ -231,6 +231,7 @@ set(viewer_SOURCE_FILES llfloaterproperties.cpp llfloaterregioninfo.cpp llfloaterreporter.cpp + llfloatersearchreplace.cpp llfloaterscriptdebug.cpp llfloatersellland.cpp llfloatersettingsdebug.cpp @@ -709,6 +710,7 @@ set(viewer_HEADER_FILES llfloaterproperties.h llfloaterregioninfo.h llfloaterreporter.h + llfloatersearchreplace.h llfloaterscriptdebug.h llfloatersellland.h llfloatersettingsdebug.h diff --git a/indra/newview/llpreview.cpp b/indra/newview/llpreview.cpp index 9961003ed..367ead596 100644 --- a/indra/newview/llpreview.cpp +++ b/indra/newview/llpreview.cpp @@ -46,6 +46,9 @@ #include "llviewerobject.h" #include "llviewerobjectlist.h" #include "lldbstrings.h" +#include "llfloatersearchreplace.h" +#include "llpreviewnotecard.h" +#include "llpreviewscript.h" #include "llagent.h" #include "llvoavatar.h" #include "llselectmgr.h" @@ -576,6 +579,24 @@ void LLMultiPreview::tabOpen(LLFloater* opened_floater, bool from_click) { opened_preview->loadAsset(); } + + LLFloater* search_floater = LLFloaterSearchReplace::getInstance(); + if (search_floater && search_floater->getDependee() == this) + { + LLPreviewNotecard* notecard_preview; LLPreviewLSL* script_preview; + if ((notecard_preview = dynamic_cast(opened_preview)) != NULL) + { + LLFloaterSearchReplace::show(notecard_preview->getEditor()); + } + else if ((script_preview = dynamic_cast(opened_preview)) != NULL) + { + LLFloaterSearchReplace::show(script_preview->getEditor()); + } + else + { + search_floater->setVisible(FALSE); + } + } } //static diff --git a/indra/newview/llpreviewnotecard.cpp b/indra/newview/llpreviewnotecard.cpp index 06d9a1ae4..261cda5b3 100644 --- a/indra/newview/llpreviewnotecard.cpp +++ b/indra/newview/llpreviewnotecard.cpp @@ -35,12 +35,14 @@ #include "llpreviewnotecard.h" #include "llinventory.h" +#include "llmenugl.h" #include "llagent.h" #include "llagentcamera.h" #include "llassetuploadresponders.h" #include "llviewerwindow.h" #include "llbutton.h" +#include "llfloatersearchreplace.h" #include "llinventorymodel.h" #include "lllineeditor.h" #include "llnotify.h" @@ -111,7 +113,6 @@ LLPreviewNotecard::LLPreviewNotecard(const std::string& name, else { LLUICtrlFactory::getInstance()->buildFloater(this,"floater_preview_notecard.xml"); - childSetAction("Save",onClickSave,this); // childSetAction("Get Items", onClickGetItems, this); // @@ -125,6 +126,7 @@ LLPreviewNotecard::LLPreviewNotecard(const std::string& name, } } } + childSetAction("Save",onClickSave,this); // only assert shape if not hosted in a multifloater if (!getHost()) @@ -153,6 +155,8 @@ LLPreviewNotecard::LLPreviewNotecard(const std::string& name, editor->setHandleEditKeysDirectly(TRUE); } + initMenu(); + gAgentCamera.changeCameraToDefault(); } @@ -222,6 +226,12 @@ BOOL LLPreviewNotecard::handleKeyHere(KEY key, MASK mask) return TRUE; } + if ('F' == key && (mask & MASK_CONTROL) && !(mask & (MASK_SHIFT | MASK_ALT))) + { + LLFloaterSearchReplace::show(getChild("Notecard Editor")); + return TRUE; + } + return LLPreview::handleKeyHere(key, mask); } @@ -775,4 +785,221 @@ LLTextEditor* LLPreviewNotecard::getEditor() return getChild("Notecard Editor"); } +void LLPreviewNotecard::initMenu() +{ + LLMenuItemCallGL* menuItem = getChild("Undo"); + menuItem->setMenuCallback(onUndoMenu, this); + menuItem->setEnabledCallback(enableUndoMenu); + + menuItem = getChild("Redo"); + menuItem->setMenuCallback(onRedoMenu, this); + menuItem->setEnabledCallback(enableRedoMenu); + + menuItem = getChild("Cut"); + menuItem->setMenuCallback(onCutMenu, this); + menuItem->setEnabledCallback(enableCutMenu); + + menuItem = getChild("Copy"); + menuItem->setMenuCallback(onCopyMenu, this); + menuItem->setEnabledCallback(enableCopyMenu); + + menuItem = getChild("Paste"); + menuItem->setMenuCallback(onPasteMenu, this); + menuItem->setEnabledCallback(enablePasteMenu); + + menuItem = getChild("Select All"); + menuItem->setMenuCallback(onSelectAllMenu, this); + menuItem->setEnabledCallback(enableSelectAllMenu); + + menuItem = getChild("Deselect"); + menuItem->setMenuCallback(onDeselectMenu, this); + menuItem->setEnabledCallback(enableDeselectMenu); + + menuItem = getChild("Search / Replace..."); + menuItem->setMenuCallback(onSearchMenu, this); + menuItem->setEnabledCallback(NULL); +} + +// static +void LLPreviewNotecard::onSearchMenu(void* userdata) +{ + LLPreviewNotecard* self = (LLPreviewNotecard*)userdata; + if (self) + { + LLViewerTextEditor* editor = self->getChild("Notecard Editor"); + if (editor) + { + LLFloaterSearchReplace::show(editor); + } + } +} + +// static +void LLPreviewNotecard::onUndoMenu(void* userdata) +{ + LLPreviewNotecard* self = (LLPreviewNotecard*)userdata; + if (self) + { + LLViewerTextEditor* editor = self->getChild("Notecard Editor"); + if (editor) + { + editor->undo(); + } + } +} + +// static +void LLPreviewNotecard::onRedoMenu(void* userdata) +{ + LLPreviewNotecard* self = (LLPreviewNotecard*)userdata; + if (self) + { + LLViewerTextEditor* editor = self->getChild("Notecard Editor"); + if (editor) + { + editor->redo(); + } + } +} + +// static +void LLPreviewNotecard::onCutMenu(void* userdata) +{ + LLPreviewNotecard* self = (LLPreviewNotecard*)userdata; + if (self) + { + LLViewerTextEditor* editor = self->getChild("Notecard Editor"); + if (editor) + { + editor->cut(); + } + } +} + +// static +void LLPreviewNotecard::onCopyMenu(void* userdata) +{ + LLPreviewNotecard* self = (LLPreviewNotecard*)userdata; + if (self) + { + LLViewerTextEditor* editor = self->getChild("Notecard Editor"); + if (editor) + { + editor->copy(); + } + } +} + +// static +void LLPreviewNotecard::onPasteMenu(void* userdata) +{ + LLPreviewNotecard* self = (LLPreviewNotecard*)userdata; + if (self) + { + LLViewerTextEditor* editor = self->getChild("Notecard Editor"); + if (editor) + { + editor->paste(); + } + } +} + +// static +void LLPreviewNotecard::onSelectAllMenu(void* userdata) +{ + LLPreviewNotecard* self = (LLPreviewNotecard*)userdata; + if (self) + { + LLViewerTextEditor* editor = self->getChild("Notecard Editor"); + if (editor) + { + editor->selectAll(); + } + } +} + +// static +void LLPreviewNotecard::onDeselectMenu(void* userdata) +{ + LLPreviewNotecard* self = (LLPreviewNotecard*)userdata; + if (self) + { + LLViewerTextEditor* editor = self->getChild("Notecard Editor"); + if (editor) + { + editor->deselect(); + } + } +} + +// static +BOOL LLPreviewNotecard::enableUndoMenu(void* userdata) +{ + LLPreviewNotecard* self = (LLPreviewNotecard*)userdata; + if (!self) return FALSE; + LLViewerTextEditor* editor = self->getChild("Notecard Editor"); + if (!editor) return FALSE; + return editor->canUndo(); +} + +// static +BOOL LLPreviewNotecard::enableRedoMenu(void* userdata) +{ + LLPreviewNotecard* self = (LLPreviewNotecard*)userdata; + if (!self) return FALSE; + LLViewerTextEditor* editor = self->getChild("Notecard Editor"); + if (!editor) return FALSE; + return editor->canRedo(); +} + +// static +BOOL LLPreviewNotecard::enableCutMenu(void* userdata) +{ + LLPreviewNotecard* self = (LLPreviewNotecard*)userdata; + if (!self) return FALSE; + LLViewerTextEditor* editor = self->getChild("Notecard Editor"); + if (!editor) return FALSE; + return editor->canCut(); +} + +// static +BOOL LLPreviewNotecard::enableCopyMenu(void* userdata) +{ + LLPreviewNotecard* self = (LLPreviewNotecard*)userdata; + if (!self) return FALSE; + LLViewerTextEditor* editor = self->getChild("Notecard Editor"); + if (!editor) return FALSE; + return editor->canCopy(); +} + +// static +BOOL LLPreviewNotecard::enablePasteMenu(void* userdata) +{ + LLPreviewNotecard* self = (LLPreviewNotecard*)userdata; + if (!self) return FALSE; + LLViewerTextEditor* editor = self->getChild("Notecard Editor"); + if (!editor) return FALSE; + return editor->canPaste(); +} + +// static +BOOL LLPreviewNotecard::enableSelectAllMenu(void* userdata) +{ + LLPreviewNotecard* self = (LLPreviewNotecard*)userdata; + if (!self) return FALSE; + LLViewerTextEditor* editor = self->getChild("Notecard Editor"); + if (!editor) return FALSE; + return editor->canSelectAll(); +} + +// static +BOOL LLPreviewNotecard::enableDeselectMenu(void* userdata) +{ + LLPreviewNotecard* self = (LLPreviewNotecard*)userdata; + if (!self) return FALSE; + LLViewerTextEditor* editor = self->getChild("Notecard Editor"); + if (!editor) return FALSE; + return editor->canDeselect(); +} + // EOF diff --git a/indra/newview/llpreviewnotecard.h b/indra/newview/llpreviewnotecard.h index 04568bf65..442673c0c 100644 --- a/indra/newview/llpreviewnotecard.h +++ b/indra/newview/llpreviewnotecard.h @@ -45,6 +45,8 @@ class LLTextEditor; class LLViewerTextEditor; +class LLTextEditor; +class LLMenuBarGL; class LLButton; class AIFilePicker; @@ -117,6 +119,25 @@ protected: virtual const char *getTitleName() const { return "Note"; } + void initMenu(); + + static void onSearchMenu(void* userdata); + static void onUndoMenu(void* userdata); + static void onRedoMenu(void* userdata); + static void onCutMenu(void* userdata); + static void onCopyMenu(void* userdata); + static void onPasteMenu(void* userdata); + static void onSelectAllMenu(void* userdata); + static void onDeselectMenu(void* userdata); + + static BOOL enableUndoMenu(void* userdata); + static BOOL enableRedoMenu(void* userdata); + static BOOL enableCutMenu(void* userdata); + static BOOL enableCopyMenu(void* userdata); + static BOOL enablePasteMenu(void* userdata); + static BOOL enableSelectAllMenu(void* userdata); + static BOOL enableDeselectMenu(void* userdata); + protected: LLViewerTextEditor* mEditor; LLButton* mSaveBtn; diff --git a/indra/newview/llpreviewscript.cpp b/indra/newview/llpreviewscript.cpp index e4abac51d..fb3cf4880 100644 --- a/indra/newview/llpreviewscript.cpp +++ b/indra/newview/llpreviewscript.cpp @@ -77,6 +77,7 @@ #include "lldir.h" #include "llcombobox.h" //#include "llfloaterchat.h" +#include "llfloatersearchreplace.h" #include "llviewerstats.h" #include "llviewertexteditor.h" #include "llviewerwindow.h" @@ -134,10 +135,6 @@ const S32 SCRIPT_MIN_HEIGHT = const S32 MAX_EXPORT_SIZE = 1000; -const S32 SCRIPT_SEARCH_WIDTH = 300; -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; @@ -148,148 +145,6 @@ static bool have_script_upload_cap(LLUUID& object_id) return object && (! object->getRegion()->getCapability("UpdateScriptTask").empty()); } -/// --------------------------------------------------------------------------- -/// LLFloaterScriptSearch -/// --------------------------------------------------------------------------- -class LLFloaterScriptSearch : public LLFloater -{ -public: - LLFloaterScriptSearch(std::string title, LLRect rect, LLScriptEdCore* editor_core); - ~LLFloaterScriptSearch(); - - static void show(LLScriptEdCore* editor_core); - static void onBtnSearch(void* userdata); - void handleBtnSearch(); - - static void onBtnReplace(void* userdata); - void handleBtnReplace(); - - static void onBtnReplaceAll(void* userdata); - void handleBtnReplaceAll(); - - LLScriptEdCore* getEditorCore() { return mEditorCore; } - static LLFloaterScriptSearch* getInstance() { return sInstance; } - - void open(); /*Flawfinder: ignore*/ - -private: - - LLScriptEdCore* mEditorCore; - - static LLFloaterScriptSearch* sInstance; -}; - -LLFloaterScriptSearch* LLFloaterScriptSearch::sInstance = NULL; - -LLFloaterScriptSearch::LLFloaterScriptSearch(std::string title, LLRect rect, LLScriptEdCore* editor_core) - : LLFloater("script search",rect,title), mEditorCore(editor_core) -{ - - LLUICtrlFactory::getInstance()->buildFloater(this,"floater_script_search.xml"); - - childSetAction("search_btn", onBtnSearch,this); - childSetAction("replace_btn", onBtnReplace,this); - childSetAction("replace_all_btn", onBtnReplaceAll,this); - - setDefaultBtn("search_btn"); - - if (!getHost()) - { - LLRect curRect = getRect(); - translate(rect.mLeft - curRect.mLeft, rect.mTop - curRect.mTop); - } - - sInstance = this; - - childSetFocus("search_text", TRUE); - - // find floater in which script panel is embedded - LLView* viewp = (LLView*)editor_core; - while(viewp) - { - LLFloater* floaterp = dynamic_cast(viewp); - if (floaterp) - { - floaterp->addDependentFloater(this); - break; - } - viewp = viewp->getParent(); - } -} - -//static -void LLFloaterScriptSearch::show(LLScriptEdCore* editor_core) -{ - if (sInstance && sInstance->mEditorCore && sInstance->mEditorCore != editor_core) - { - sInstance->close(); - delete sInstance; - } - - if (!sInstance) - { - S32 left = 0; - S32 top = 0; - gFloaterView->getNewFloaterPosition(&left,&top); - - // sInstance will be assigned in the constructor. - new LLFloaterScriptSearch("Script Search",LLRect(left,top,left + SCRIPT_SEARCH_WIDTH,top - SCRIPT_SEARCH_HEIGHT),editor_core); - } - - sInstance->open(); /*Flawfinder: ignore*/ -} - -LLFloaterScriptSearch::~LLFloaterScriptSearch() -{ - sInstance = NULL; -} - -// static -void LLFloaterScriptSearch::onBtnSearch(void *userdata) -{ - LLFloaterScriptSearch* self = (LLFloaterScriptSearch*)userdata; - self->handleBtnSearch(); -} - -void LLFloaterScriptSearch::handleBtnSearch() -{ - LLCheckBoxCtrl* caseChk = getChild("case_text"); - mEditorCore->mEditor->selectNext(childGetText("search_text"), caseChk->get()); -} - -// static -void LLFloaterScriptSearch::onBtnReplace(void *userdata) -{ - LLFloaterScriptSearch* self = (LLFloaterScriptSearch*)userdata; - self->handleBtnReplace(); -} - -void LLFloaterScriptSearch::handleBtnReplace() -{ - LLCheckBoxCtrl* caseChk = getChild("case_text"); - mEditorCore->mEditor->replaceText(childGetText("search_text"), childGetText("replace_text"), caseChk->get()); -} - -// static -void LLFloaterScriptSearch::onBtnReplaceAll(void *userdata) -{ - LLFloaterScriptSearch* self = (LLFloaterScriptSearch*)userdata; - self->handleBtnReplaceAll(); -} - -void LLFloaterScriptSearch::handleBtnReplaceAll() -{ - LLCheckBoxCtrl* caseChk = getChild("case_text"); - mEditorCore->mEditor->replaceTextAll(childGetText("search_text"), childGetText("replace_text"), caseChk->get()); -} - -void LLFloaterScriptSearch::open() /*Flawfinder: ignore*/ -{ - LLFloater::open(); /*Flawfinder: ignore*/ - childSetFocus("search_text", TRUE); -} - - /// --------------------------------------------------------------------------- /// LLScriptEdCore /// --------------------------------------------------------------------------- @@ -433,14 +288,6 @@ LLScriptEdCore::LLScriptEdCore( LLScriptEdCore::~LLScriptEdCore() { deleteBridges(); - - // If the search window is up for this editor, close it. - LLFloaterScriptSearch* script_search = LLFloaterScriptSearch::getInstance(); - if (script_search && script_search->getEditorCore() == this) - { - script_search->close(); - delete script_search; - } } BOOL LLScriptEdCore::tick() @@ -484,6 +331,10 @@ void LLScriptEdCore::initMenu() menuItem->setMenuCallback(onSelectAllMenu, this); menuItem->setEnabledCallback(enableSelectAllMenu); + menuItem = getChild("Deselect"); + menuItem->setMenuCallback(onDeselectMenu, this); + menuItem->setEnabledCallback(enableDeselectMenu); + menuItem = getChild("Search / Replace..."); menuItem->setMenuCallback(onSearchMenu, this); menuItem->setEnabledCallback(NULL); @@ -931,7 +782,10 @@ void LLScriptEdCore::onBtnUndoChanges( void* userdata ) void LLScriptEdCore::onSearchMenu(void* userdata) { LLScriptEdCore* sec = (LLScriptEdCore*)userdata; - LLFloaterScriptSearch::show(sec); + if (sec && sec->mEditor) + { + LLFloaterSearchReplace::show(sec->mEditor); + } } // static @@ -1339,7 +1193,10 @@ void LLPreviewLSL::onSearchReplace(void* userdata) { LLPreviewLSL* self = (LLPreviewLSL*)userdata; LLScriptEdCore* sec = self->mScriptEd; - LLFloaterScriptSearch::show(sec); + if (sec && sec->mEditor) + { + LLFloaterSearchReplace::show(sec->mEditor); + } } // static @@ -2193,7 +2050,10 @@ void LLLiveLSLEditor::onSearchReplace(void* userdata) LLLiveLSLEditor* self = (LLLiveLSLEditor*)userdata; LLScriptEdCore* sec = self->mScriptEd; - LLFloaterScriptSearch::show(sec); + if (sec && sec->mEditor) + { + LLFloaterSearchReplace::show(sec->mEditor); + } } struct LLLiveLSLSaveData diff --git a/indra/newview/llpreviewscript.h b/indra/newview/llpreviewscript.h index f4390927d..436d68d4f 100644 --- a/indra/newview/llpreviewscript.h +++ b/indra/newview/llpreviewscript.h @@ -51,7 +51,6 @@ class LLScrollListCtrl; class LLViewerObject; struct LLEntryAndEdCore; class LLMenuBarGL; -class LLFloaterScriptSearch; class LLKeywordToken; class AIFilePicker; @@ -61,7 +60,6 @@ class LLScriptEdCore : public LLPanel, public LLEventTimer friend class LLPreviewScript; friend class LLPreviewLSL; friend class LLLiveLSLEditor; - friend class LLFloaterScriptSearch; public: LLScriptEdCore( @@ -204,6 +202,7 @@ protected: static void onSaveBytecodeComplete(const LLUUID& asset_uuid, void* user_data, S32 status, LLExtStat ext_status); public: static LLPreviewLSL* getInstance(const LLUUID& uuid); + LLTextEditor* getEditor() { return mScriptEd->mEditor; } protected: static void* createScriptEdPanel(void* userdata); diff --git a/indra/newview/skins/default/xui/en-us/floater_preview_notecard.xml b/indra/newview/skins/default/xui/en-us/floater_preview_notecard.xml index b7064e8fd..5307864c6 100644 --- a/indra/newview/skins/default/xui/en-us/floater_preview_notecard.xml +++ b/indra/newview/skins/default/xui/en-us/floater_preview_notecard.xml @@ -1,13 +1,10 @@ -