summaryrefslogtreecommitdiff
path: root/indra
diff options
context:
space:
mode:
authorWolfGang <flamin2k8@gmail.com>2026-01-20 17:28:48 +0000
committerGitHub <noreply@github.com>2026-01-20 19:28:48 +0200
commit9391458d5c1211d2845a8978411e54fb4127234e (patch)
treed0e0aeca0099fed978c9b4637511883ad3d2fdad /indra
parentb4f75c4cd53192573e8245eb5fe63a65734d0a1b (diff)
Add notecard name to tempfile created for editing notecard externally (#5291, #5297)
Diffstat (limited to 'indra')
-rw-r--r--indra/newview/llpreviewnotecard.cpp71
-rw-r--r--indra/newview/llpreviewnotecard.h5
2 files changed, 67 insertions, 9 deletions
diff --git a/indra/newview/llpreviewnotecard.cpp b/indra/newview/llpreviewnotecard.cpp
index cecda23e7b..526fb6c8aa 100644
--- a/indra/newview/llpreviewnotecard.cpp
+++ b/indra/newview/llpreviewnotecard.cpp
@@ -70,10 +70,16 @@ LLPreviewNotecard::LLPreviewNotecard(const LLSD& key) //const LLUUID& item_id,
: LLPreview( key )
{
const LLInventoryItem *item = getItem();
+ std::string note_name = "New Note";
if (item)
{
mAssetID = item->getAssetUUID();
+ if (!item->getName().empty())
+ {
+ note_name = item->getName();
+ }
}
+ mNoteName = note_name;
}
LLPreviewNotecard::~LLPreviewNotecard()
@@ -101,15 +107,21 @@ bool LLPreviewNotecard::postBuild()
mEditBtn->setCommitCallback(boost::bind(&LLPreviewNotecard::openInExternalEditor, this));
const LLInventoryItem* item = getItem();
+ std::string note_name = mNoteName;
mDescEditor = getChild<LLLineEditor>("desc");
mDescEditor->setCommitCallback(boost::bind(&LLPreview::onText, mDescEditor, this));
if (item)
{
+ if (!item->getName().empty())
+ {
+ note_name = item->getName();
+ }
mDescEditor->setValue(item->getDescription());
bool source_library = mObjectUUID.isNull() && gInventory.isObjectDescendentOf(item->getUUID(), gInventory.getLibraryRootFolderID());
mDeleteBtn->setEnabled(!source_library);
}
+ mNoteName = note_name;
mDescEditor->setPrevalidate(&LLTextValidate::validateASCIIPrintableNoPipe);
return LLPreview::postBuild();
@@ -230,6 +242,7 @@ void LLPreviewNotecard::loadAsset()
// request the asset.
const LLInventoryItem* item = getItem();
bool fail = false;
+ std::string note_name = mNoteName;
if(item)
{
@@ -238,6 +251,10 @@ void LLPreviewNotecard::loadAsset()
bool allow_copy = gAgent.allowOperation(PERM_COPY, perm, GP_OBJECT_MANIPULATE);
bool allow_modify = canModify(mObjectUUID, item);
bool source_library = mObjectUUID.isNull() && gInventory.isObjectDescendentOf(mItemUUID, gInventory.getLibraryRootFolderID());
+ if(!item->getName().empty())
+ {
+ note_name = item->getName();
+ }
if (allow_copy || gAgent.isGodlike())
{
@@ -338,6 +355,8 @@ void LLPreviewNotecard::loadAsset()
fail = true;
}
+ mNoteName = note_name;
+
if (fail)
{
mEditor->setText(LLStringUtil::null);
@@ -574,12 +593,23 @@ bool LLPreviewNotecard::saveIfNeeded(LLInventoryItem* copyitem, bool sync)
void LLPreviewNotecard::syncExternal()
{
// Sync with external editor.
- std::string tmp_file = getTmpFileName();
- if (LLFile::isfile(tmp_file)) // file exists
+ std::string note_name = getCleanNameForTmpFile();
+ std::string tmp_file = getTmpFileName(note_name);
+ llstat s;
+ if (LLFile::stat(tmp_file, &s) != 0)
{
- if (mLiveFile) mLiveFile->ignoreNextUpdate();
- writeToFile(tmp_file);
+ // file doesn't exist, try with empty name
+ note_name.clear();
+ tmp_file = getTmpFileName(note_name);
+ if (LLFile::stat(tmp_file, &s) != 0)
+ {
+ // file doesn't exist, with either name, give up
+ return;
+ }
}
+
+ if (mLiveFile) mLiveFile->ignoreNextUpdate();
+ writeToFile(tmp_file);
}
/*virtual*/
@@ -742,8 +772,16 @@ void LLPreviewNotecard::openInExternalEditor()
delete mLiveFile; // deletes file
// Save the notecard to a temporary file.
- std::string filename = getTmpFileName();
- writeToFile(filename);
+ std::string note_name = getCleanNameForTmpFile();
+ std::string filename = getTmpFileName(note_name);
+ if(!writeToFile(filename)) {
+ // In case some characters from notecard name are forbidden
+ // and not accounted for, name is too long or some other issue,
+ // try file that doesn't include notecard name
+ note_name.clear();
+ filename = getTmpFileName(note_name);
+ writeToFile(filename);
+ }
// Start watching file changes.
mLiveFile = new LLLiveLSLFile(filename, boost::bind(&LLPreviewNotecard::onExternalChange, this, _1));
@@ -851,8 +889,21 @@ bool LLPreviewNotecard::writeToFile(const std::string& filename)
return true;
}
+std::string LLPreviewNotecard::getCleanNameForTmpFile() const
+{
+ std::string note_name = mNoteName;
+ if(note_name.empty()) {
+ note_name = "New note";
+ }
+ static const std::set<char> forbidden_chars{ '<', '>', ':', '"', '\\', '/', '|', '?', '*' };
+ note_name.erase(
+ std::remove_if(note_name.begin(), note_name.end(), [](char c) {
+ return forbidden_chars.contains(c);
+ }), note_name.end());
+ return note_name;
+}
-std::string LLPreviewNotecard::getTmpFileName()
+std::string LLPreviewNotecard::getTmpFileName(const std::string& note_name) const
{
std::string notecard_id = mObjectID.asString() + "_" + mItemUUID.asString();
@@ -861,7 +912,11 @@ std::string LLPreviewNotecard::getTmpFileName()
LLMD5 notecard_id_hash((const U8 *)notecard_id.c_str());
notecard_id_hash.hex_digest(notecard_id_hash_str);
- return std::string(LLFile::tmpdir()) + "sl_notecard_" + notecard_id_hash_str + ".txt";
+ if(note_name.empty()) {
+ return std::string(LLFile::tmpdir()) + "sl_notecard_" + notecard_id_hash_str + ".txt";
+ } else {
+ return std::string(LLFile::tmpdir()) + "sl_notecard_" + note_name + "_" + notecard_id_hash_str + ".txt";
+ }
}
diff --git a/indra/newview/llpreviewnotecard.h b/indra/newview/llpreviewnotecard.h
index be3c804f9b..a7289ebc9a 100644
--- a/indra/newview/llpreviewnotecard.h
+++ b/indra/newview/llpreviewnotecard.h
@@ -108,7 +108,8 @@ protected:
bool onExternalChange(const std::string& filename);
bool loadNotecardText(const std::string& filename);
bool writeToFile(const std::string& filename);
- std::string getTmpFileName();
+ std::string getCleanNameForTmpFile() const;
+ std::string getTmpFileName(const std::string& note_name) const;
protected:
LLViewerTextEditor* mEditor = nullptr;
@@ -118,6 +119,8 @@ protected:
LLButton* mDeleteBtn = nullptr;
LLUICtrl* mLockBtn = nullptr;
+ std::string mNoteName;
+
LLUUID mAssetID;
LLUUID mObjectID;