EXT-2278 : "Save Texture As" for bottom panel

EXT-2310 : "Save Texture As" for inventory right-click menu

"Save Texture As" now works properly and brings up the texture preview while saving.
Also added "Save Texture As" to the right-click inventory context menu.

--HG--
branch : avatar-pipeline
master
Loren Shih 2009-11-06 17:35:05 -05:00
parent 98eb085b64
commit 2aa981ac23
8 changed files with 92 additions and 56 deletions

View File

@ -3086,6 +3086,49 @@ void LLTextureBridge::openItem()
}
}
void LLTextureBridge::buildContextMenu(LLMenuGL& menu, U32 flags)
{
lldebugs << "LLTextureBridge::buildContextMenu()" << llendl;
std::vector<std::string> items;
std::vector<std::string> disabled_items;
if(isInTrash())
{
items.push_back(std::string("Purge Item"));
if (!isItemRemovable())
{
disabled_items.push_back(std::string("Purge Item"));
}
items.push_back(std::string("Restore Item"));
}
else
{
items.push_back(std::string("Open"));
items.push_back(std::string("Properties"));
getClipboardEntries(true, items, disabled_items, flags);
items.push_back(std::string("Texture Separator"));
items.push_back(std::string("Save As"));
}
hide_context_entries(menu, items, disabled_items);
}
// virtual
void LLTextureBridge::performAction(LLFolderView* folder, LLInventoryModel* model, std::string action)
{
if ("save_as" == action)
{
LLFloaterReg::showInstance("preview_texture", LLSD(mUUID), TAKE_FOCUS_YES);
LLPreviewTexture* preview_texture = LLFloaterReg::findTypedInstance<LLPreviewTexture>("preview_texture", mUUID);
if (preview_texture)
{
preview_texture->openToSave();
}
}
else LLItemBridge::performAction(folder, model, action);
}
// +=================================================+
// | LLSoundBridge |
// +=================================================+
@ -3134,7 +3177,7 @@ void LLSoundBridge::openSoundPreview(void* which)
void LLSoundBridge::buildContextMenu(LLMenuGL& menu, U32 flags)
{
lldebugs << "LLTextureBridge::buildContextMenu()" << llendl;
lldebugs << "LLSoundBridge::buildContextMenu()" << llendl;
std::vector<std::string> items;
std::vector<std::string> disabled_items;

View File

@ -383,6 +383,8 @@ class LLTextureBridge : public LLItemBridge
public:
virtual LLUIImagePtr getIcon() const;
virtual void openItem();
virtual void buildContextMenu(LLMenuGL& menu, U32 flags);
virtual void performAction(LLFolderView* folder, LLInventoryModel* model, std::string action);
protected:
LLTextureBridge(LLInventoryPanel* inventory, const LLUUID& uuid, LLInventoryType::EType type) :

View File

@ -265,7 +265,7 @@ LLLandmark* LLLandmarksPanel::getCurSelectedLandmark() const
return NULL;
}
LLFolderViewItem* LLLandmarksPanel::getCurSelectedItem () const
LLFolderViewItem* LLLandmarksPanel::getCurSelectedItem() const
{
return mCurrentSelectedList ? mCurrentSelectedList->getRootFolder()->getCurSelectedItem() : NULL;
}

View File

@ -69,7 +69,7 @@ protected:
bool isLandmarkSelected() const;
bool isReceivedFolderSelected() const;
LLLandmark* getCurSelectedLandmark() const;
LLFolderViewItem* getCurSelectedItem () const;
LLFolderViewItem* getCurSelectedItem() const;
void updateSortOrder(LLInventoryPanel* panel, bool byDate);
//LLRemoteParcelInfoObserver interface

View File

@ -41,6 +41,7 @@
#include "llinventorypanel.h"
#include "llfiltereditor.h"
#include "llfloaterreg.h"
#include "llpreviewtexture.h"
#include "llscrollcontainer.h"
#include "llsdserialize.h"
#include "llspinctrl.h"
@ -965,18 +966,11 @@ void LLPanelMainInventory::onCustomAction(const LLSD& userdata)
}
const LLUUID& item_id = current_item->getListener()->getUUID();
LLFilePicker& file_picker = LLFilePicker::instance();
const LLInventoryItem* item = gInventory.getItem(item_id);
if( !file_picker.getSaveFile( LLFilePicker::FFSAVE_TGA, item ? LLDir::getScrubbedFileName(item->getName()) : LLStringUtil::null) )
LLPreviewTexture* preview_texture = LLFloaterReg::showTypedInstance<LLPreviewTexture>("preview_texture", LLSD(item_id), TAKE_FOCUS_YES);
if (preview_texture)
{
// User canceled or we failed to acquire save file.
return;
preview_texture->openToSave();
}
// remember the user-approved/edited file name.
const LLUUID& asset_id = item->getAssetUUID();
LLPointer<LLViewerFetchedTexture> image = LLViewerTextureManager::getFetchedTexture(asset_id, MIPMAP_TRUE, FALSE, LLViewerTexture::LOD_TEXTURE);
image->setLoadedCallback( on_file_loaded_for_save,
0, TRUE, FALSE, new std::string(file_picker.getFirstFile()) );
}
}
@ -1002,6 +996,7 @@ BOOL LLPanelMainInventory::isActionEnabled(const LLSD& userdata)
}
return can_delete;
}
return FALSE;
}
if (command_name == "save_texture")
{
@ -1010,8 +1005,9 @@ BOOL LLPanelMainInventory::isActionEnabled(const LLSD& userdata)
{
return (current_item->getListener()->getInventoryType() == LLInventoryType::IT_TEXTURE);
}
return FALSE;
}
return FALSE;
return TRUE;
}
bool LLPanelMainInventory::handleDragAndDropToTrash(BOOL drop, EDragAndDropType cargo_type, EAcceptance* accept)
@ -1027,36 +1023,3 @@ bool LLPanelMainInventory::handleDragAndDropToTrash(BOOL drop, EDragAndDropType
}
return true;
}
void on_file_loaded_for_save(BOOL success,
LLViewerFetchedTexture *src_vi,
LLImageRaw* src,
LLImageRaw* aux_src,
S32 discard_level,
BOOL final,
void* userdata)
{
std::string *filename = (std::string*) userdata;
if (final && success)
{
LLPointer<LLImageTGA> image_tga = new LLImageTGA;
if( !image_tga->encode( src ) )
{
LLSD args;
args["FILE"] = *filename;
LLNotifications::instance().add("CannotEncodeFile", args);
}
else if( !image_tga->save( *filename ) )
{
LLSD args;
args["FILE"] = *filename;
LLNotifications::instance().add("CannotWriteFile", args);
}
}
if(!success )
{
LLNotifications::instance().add("CannotDownloadFile");
}
}

View File

@ -48,6 +48,7 @@
#include "lltextbox.h"
#include "lltextureview.h"
#include "llui.h"
#include "llviewerinventory.h"
#include "llviewertexture.h"
#include "llviewertexturelist.h"
#include "lluictrlfactory.h"
@ -63,7 +64,7 @@ const F32 PREVIEW_TEXTURE_MIN_ASPECT = 0.005f;
LLPreviewTexture::LLPreviewTexture(const LLSD& key)
: LLPreview( key ),
: LLPreview(key),
mLoadingFullImage( FALSE ),
mShowKeepDiscard(FALSE),
mCopyToInv(FALSE),
@ -71,7 +72,8 @@ LLPreviewTexture::LLPreviewTexture(const LLSD& key)
mUpdateDimensions(TRUE),
mLastHeight(0),
mLastWidth(0),
mAspectRatio(0.f)
mAspectRatio(0.f),
mPreviewToSave(FALSE)
{
const LLInventoryItem *item = getItem();
if(item)
@ -104,6 +106,10 @@ LLPreviewTexture::LLPreviewTexture(const LLSD& key)
mIsCopyable = TRUE;
}
if (key.has("save_as"))
{
mPreviewToSave = TRUE;
}
//Called from floater reg: LLUICtrlFactory::getInstance()->buildFloater(this, "floater_preview_texture.xml", FALSE);
}
@ -181,6 +187,12 @@ void LLPreviewTexture::draw()
if ( mImage.notNull() )
{
// Automatically bring up SaveAs dialog if we opened this to save the texture.
if (mPreviewToSave)
{
mPreviewToSave = FALSE;
saveAs();
}
// Draw the texture
glColor3f( 1.f, 1.f, 1.f );
gl_draw_scaled_image(interior.mLeft,
@ -209,7 +221,7 @@ void LLPreviewTexture::draw()
if( mLoadingFullImage )
{
LLFontGL::getFontSansSerif()->renderUTF8(LLTrans::getString("Receiving:"), 0,
LLFontGL::getFontSansSerif()->renderUTF8(LLTrans::getString("Receiving"), 0,
interior.mLeft + 4,
interior.mBottom + 4,
LLColor4::white, LLFontGL::LEFT, LLFontGL::BOTTOM,
@ -304,6 +316,11 @@ void LLPreviewTexture::onFocusReceived()
LLPreview::onFocusReceived();
}
void LLPreviewTexture::openToSave()
{
mPreviewToSave = TRUE;
}
// static
void LLPreviewTexture::onFileLoadedForSave(BOOL success,
LLViewerFetchedTexture *src_vi,
@ -356,6 +373,7 @@ void LLPreviewTexture::onFileLoadedForSave(BOOL success,
{
LLNotifications::instance().add("CannotDownloadFile");
}
}

View File

@ -67,8 +67,7 @@ public:
S32 discard_level,
BOOL final,
void* userdata );
void openToSave();
protected:
void init();
/* virtual */ BOOL postBuild();
@ -77,14 +76,17 @@ protected:
private:
void updateDimensions();
LLUUID mImageID;
LLUUID mImageID;
LLPointer<LLViewerFetchedTexture> mImage;
BOOL mLoadingFullImage;
std::string mSaveFileName;
LLFrameTimer mSavedFileTimer;
BOOL mShowKeepDiscard;
BOOL mCopyToInv;
// Save the image once it's loaded.
BOOL mPreviewToSave;
// This is stored off in a member variable, because the save-as
// button and drag and drop functionality need to know.
BOOL mIsCopyable;
@ -94,6 +96,4 @@ private:
F32 mAspectRatio;
BOOL mUpdateDimensions;
};
#endif // LL_LLPREVIEWTEXTURE_H

View File

@ -550,6 +550,16 @@
function="Inventory.DoToSelected"
parameter="deactivate" />
</menu_item_call>
<menu_item_separator
layout="topleft" />
<menu_item_call
label="Save As"
layout="topleft"
name="Save As">
<menu_item_call.on_click
function="Inventory.DoToSelected"
parameter="save_as" />
</menu_item_call>
<menu_item_separator
layout="topleft" />
<menu_item_call