From 369e736e3f0cc5ca043c5f29dfc5193f688a637f Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Wed, 14 Jul 2010 05:37:58 -0700 Subject: 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 --- linden/indra/newview/llpreviewnotecard.cpp | 126 ++++++++++++++++++++++++++++- 1 file changed, 125 insertions(+), 1 deletion(-) (limited to 'linden/indra/newview/llpreviewnotecard.cpp') 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 @@ #include "llassetuploadresponders.h" #include "llviewerwindow.h" #include "llbutton.h" +#include "llfilepicker.h" #include "llfloatersearchreplace.h" #include "llinventorymodel.h" #include "lllineeditor.h" @@ -664,7 +665,23 @@ LLTextEditor* LLPreviewNotecard::getEditor() void LLPreviewNotecard::initMenu() { - LLMenuItemCallGL* menuItem = getChild("Undo"); + // File menu + + LLMenuItemCallGL* menuItem = getChild("Save Menu"); + menuItem->setMenuCallback(onSaveMenu, this); + menuItem->setEnabledCallback(enableSaveMenu); + + menuItem = getChild("Export Text..."); + menuItem->setMenuCallback(onExportTextMenu, this); + menuItem->setEnabledCallback(enableExportTextMenu); + + menuItem = getChild("Import Text..."); + menuItem->setMenuCallback(onImportTextMenu, this); + menuItem->setEnabledCallback(enableImportTextMenu); + + // Edit menu + + menuItem = getChild("Undo"); menuItem->setMenuCallback(onUndoMenu, this); menuItem->setEnabledCallback(enableUndoMenu); @@ -697,6 +714,77 @@ void LLPreviewNotecard::initMenu() menuItem->setEnabledCallback(NULL); } +//static +void LLPreviewNotecard::onSaveMenu(void* userdata) +{ + LLPreviewNotecard* preview = (LLPreviewNotecard*)userdata; + if (preview) + { + preview->saveIfNeeded(); + } +} + +//static +void LLPreviewNotecard::onExportTextMenu(void* userdata) +{ + LLPreviewNotecard* preview = (LLPreviewNotecard*)userdata; + + if (preview) + { + LLViewerTextEditor* editor = preview->getChild("Notecard Editor"); + if (editor) + { + LLFilePicker& file_picker = LLFilePicker::instance(); + const LLViewerInventoryItem *item = preview->getItem(); + if (!file_picker.getSaveFile(LLFilePicker::FFSAVE_TEXT, item ? LLDir::getScrubbedFileName(item->getName()) : LLStringUtil::null)) + { + return; + } + + std::string filename = file_picker.getFirstFile(); + std::string scriptText = editor->getText(); + std::ofstream fout(filename.c_str()); + fout << scriptText; + fout.close(); + } + } +} + +//static +void LLPreviewNotecard::onImportTextMenu(void* userdata) +{ + LLPreviewNotecard* preview = (LLPreviewNotecard*)userdata; + + if (preview) + { + LLViewerTextEditor* editor = preview->getChild("Notecard Editor"); + if (editor) + { + LLFilePicker& file_picker = LLFilePicker::instance(); + if (!file_picker.getOpenFile(LLFilePicker::FFLOAD_TEXT)) + { + return; + } + + std::string filename = file_picker.getFirstFile(); + std::ifstream fin(filename.c_str()); + + editor->clear(); + + std::string line; + while (!fin.eof()) + { + getline(fin, line); + line = line + "\n"; + editor->insertText(line); + } + fin.close(); + + preview->saveIfNeeded(); + } + } +} + // static void LLPreviewNotecard::onSearchMenu(void* userdata) { @@ -809,6 +897,42 @@ void LLPreviewNotecard::onDeselectMenu(void* userdata) } } +//static +BOOL LLPreviewNotecard::enableSaveMenu(void* userdata) +{ + LLPreviewNotecard* self = (LLPreviewNotecard*)userdata; + if (!self) return FALSE; + LLViewerTextEditor* editor = self->getChild("Notecard Editor"); + if (!editor) return FALSE; + return !editor->isPristine(); +} + +//static +BOOL LLPreviewNotecard::enableExportTextMenu(void* userdata) +{ + LLPreviewNotecard* self = (LLPreviewNotecard*)userdata; + if (!self) return FALSE; + LLViewerTextEditor* editor = self->getChild("Notecard Editor"); + if (!editor) return FALSE; + + // request the asset + const LLInventoryItem* item = self->getItem(); + return (item && (gAgent.allowOperation(PERM_MODIFY, item->getPermissions(), GP_OBJECT_MANIPULATE) || gAgent.isGodlike())); +} + +//static +BOOL LLPreviewNotecard::enableImportTextMenu(void* userdata) +{ + LLPreviewNotecard* self = (LLPreviewNotecard*)userdata; + if (!self) return FALSE; + LLViewerTextEditor* editor = self->getChild("Notecard Editor"); + if (!editor) return FALSE; + + // request the asset + const LLInventoryItem* item = self->getItem(); + return (item && (gAgent.allowOperation(PERM_MODIFY, item->getPermissions(), GP_OBJECT_MANIPULATE) || gAgent.isGodlike())); +} + // static BOOL LLPreviewNotecard::enableUndoMenu(void* userdata) { -- cgit v1.1