aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llpreviewnotecard.cpp
diff options
context:
space:
mode:
authorMcCabe Maxsted2010-07-14 05:37:58 -0700
committerMcCabe Maxsted2010-07-15 02:10:45 -0700
commit369e736e3f0cc5ca043c5f29dfc5193f688a637f (patch)
tree3bd98dc61cd19a256c04fd6c39439ca0f713dfb3 /linden/indra/newview/llpreviewnotecard.cpp
parentApplied slviewer-0-v12350-StutteringAndLagInAudioEngine_v2.patch from Cool Vi... (diff)
downloadmeta-impy-369e736e3f0cc5ca043c5f29dfc5193f688a637f.zip
meta-impy-369e736e3f0cc5ca043c5f29dfc5193f688a637f.tar.gz
meta-impy-369e736e3f0cc5ca043c5f29dfc5193f688a637f.tar.bz2
meta-impy-369e736e3f0cc5ca043c5f29dfc5193f688a637f.tar.xz
Added basic File menu to notecards (save, import, export) and made the script editor File menu consistent with it. TODO: create new notecard format that includes attached inventory
Diffstat (limited to 'linden/indra/newview/llpreviewnotecard.cpp')
-rw-r--r--linden/indra/newview/llpreviewnotecard.cpp126
1 files changed, 125 insertions, 1 deletions
diff --git a/linden/indra/newview/llpreviewnotecard.cpp b/linden/indra/newview/llpreviewnotecard.cpp
index 4260434..be5d801 100644
--- a/linden/indra/newview/llpreviewnotecard.cpp
+++ b/linden/indra/newview/llpreviewnotecard.cpp
@@ -40,6 +40,7 @@
40#include "llassetuploadresponders.h" 40#include "llassetuploadresponders.h"
41#include "llviewerwindow.h" 41#include "llviewerwindow.h"
42#include "llbutton.h" 42#include "llbutton.h"
43#include "llfilepicker.h"
43#include "llfloatersearchreplace.h" 44#include "llfloatersearchreplace.h"
44#include "llinventorymodel.h" 45#include "llinventorymodel.h"
45#include "lllineeditor.h" 46#include "lllineeditor.h"
@@ -664,7 +665,23 @@ LLTextEditor* LLPreviewNotecard::getEditor()
664 665
665void LLPreviewNotecard::initMenu() 666void LLPreviewNotecard::initMenu()
666{ 667{
667 LLMenuItemCallGL* menuItem = getChild<LLMenuItemCallGL>("Undo"); 668 // File menu
669
670 LLMenuItemCallGL* menuItem = getChild<LLMenuItemCallGL>("Save Menu");
671 menuItem->setMenuCallback(onSaveMenu, this);
672 menuItem->setEnabledCallback(enableSaveMenu);
673
674 menuItem = getChild<LLMenuItemCallGL>("Export Text...");
675 menuItem->setMenuCallback(onExportTextMenu, this);
676 menuItem->setEnabledCallback(enableExportTextMenu);
677
678 menuItem = getChild<LLMenuItemCallGL>("Import Text...");
679 menuItem->setMenuCallback(onImportTextMenu, this);
680 menuItem->setEnabledCallback(enableImportTextMenu);
681
682 // Edit menu
683
684 menuItem = getChild<LLMenuItemCallGL>("Undo");
668 menuItem->setMenuCallback(onUndoMenu, this); 685 menuItem->setMenuCallback(onUndoMenu, this);
669 menuItem->setEnabledCallback(enableUndoMenu); 686 menuItem->setEnabledCallback(enableUndoMenu);
670 687
@@ -697,6 +714,77 @@ void LLPreviewNotecard::initMenu()
697 menuItem->setEnabledCallback(NULL); 714 menuItem->setEnabledCallback(NULL);
698} 715}
699 716
717//static
718void LLPreviewNotecard::onSaveMenu(void* userdata)
719{
720 LLPreviewNotecard* preview = (LLPreviewNotecard*)userdata;
721 if (preview)
722 {
723 preview->saveIfNeeded();
724 }
725}
726
727//static
728void LLPreviewNotecard::onExportTextMenu(void* userdata)
729{
730 LLPreviewNotecard* preview = (LLPreviewNotecard*)userdata;
731
732 if (preview)
733 {
734 LLViewerTextEditor* editor = preview->getChild<LLViewerTextEditor>("Notecard Editor");
735 if (editor)
736 {
737 LLFilePicker& file_picker = LLFilePicker::instance();
738 const LLViewerInventoryItem *item = preview->getItem();
739 if (!file_picker.getSaveFile(LLFilePicker::FFSAVE_TEXT, item ? LLDir::getScrubbedFileName(item->getName()) : LLStringUtil::null))
740 {
741 return;
742 }
743
744 std::string filename = file_picker.getFirstFile();
745 std::string scriptText = editor->getText();
746 std::ofstream fout(filename.c_str());
747 fout << scriptText;
748 fout.close();
749 }
750 }
751}
752
753//static
754void LLPreviewNotecard::onImportTextMenu(void* userdata)
755{
756 LLPreviewNotecard* preview = (LLPreviewNotecard*)userdata;
757
758 if (preview)
759 {
760 LLViewerTextEditor* editor = preview->getChild<LLViewerTextEditor>("Notecard Editor");
761 if (editor)
762 {
763 LLFilePicker& file_picker = LLFilePicker::instance();
764 if (!file_picker.getOpenFile(LLFilePicker::FFLOAD_TEXT))
765 {
766 return;
767 }
768
769 std::string filename = file_picker.getFirstFile();
770 std::ifstream fin(filename.c_str());
771
772 editor->clear();
773
774 std::string line;
775 while (!fin.eof())
776 {
777 getline(fin, line);
778 line = line + "\n";
779 editor->insertText(line);
780 }
781 fin.close();
782
783 preview->saveIfNeeded();
784 }
785 }
786}
787
700// static 788// static
701void LLPreviewNotecard::onSearchMenu(void* userdata) 789void LLPreviewNotecard::onSearchMenu(void* userdata)
702{ 790{
@@ -809,6 +897,42 @@ void LLPreviewNotecard::onDeselectMenu(void* userdata)
809 } 897 }
810} 898}
811 899
900//static
901BOOL LLPreviewNotecard::enableSaveMenu(void* userdata)
902{
903 LLPreviewNotecard* self = (LLPreviewNotecard*)userdata;
904 if (!self) return FALSE;
905 LLViewerTextEditor* editor = self->getChild<LLViewerTextEditor>("Notecard Editor");
906 if (!editor) return FALSE;
907 return !editor->isPristine();
908}
909
910//static
911BOOL LLPreviewNotecard::enableExportTextMenu(void* userdata)
912{
913 LLPreviewNotecard* self = (LLPreviewNotecard*)userdata;
914 if (!self) return FALSE;
915 LLViewerTextEditor* editor = self->getChild<LLViewerTextEditor>("Notecard Editor");
916 if (!editor) return FALSE;
917
918 // request the asset
919 const LLInventoryItem* item = self->getItem();
920 return (item && (gAgent.allowOperation(PERM_MODIFY, item->getPermissions(), GP_OBJECT_MANIPULATE) || gAgent.isGodlike()));
921}
922
923//static
924BOOL LLPreviewNotecard::enableImportTextMenu(void* userdata)
925{
926 LLPreviewNotecard* self = (LLPreviewNotecard*)userdata;
927 if (!self) return FALSE;
928 LLViewerTextEditor* editor = self->getChild<LLViewerTextEditor>("Notecard Editor");
929 if (!editor) return FALSE;
930
931 // request the asset
932 const LLInventoryItem* item = self->getItem();
933 return (item && (gAgent.allowOperation(PERM_MODIFY, item->getPermissions(), GP_OBJECT_MANIPULATE) || gAgent.isGodlike()));
934}
935
812// static 936// static
813BOOL LLPreviewNotecard::enableUndoMenu(void* userdata) 937BOOL LLPreviewNotecard::enableUndoMenu(void* userdata)
814{ 938{