diff options
author | Loren Shih <seraph@lindenlab.com> | 2009-11-05 21:51:35 -0500 |
---|---|---|
committer | Loren Shih <seraph@lindenlab.com> | 2009-11-05 21:51:35 -0500 |
commit | 96345c7420a38ce6cf385bac644d5d243ff17395 (patch) | |
tree | 2066208621db3160fedd2d2f15911a6ce8b2b2dc | |
parent | 3cff39dd4abd4cacd25375b1749f8485d1567aad (diff) |
EXT-2278 : "Save Texture As" for bottom panel
--HG--
branch : avatar-pipeline
-rw-r--r-- | indra/newview/llpanelmaininventory.cpp | 73 | ||||
-rw-r--r-- | indra/newview/llpanelmaininventory.h | 2 | ||||
-rw-r--r-- | indra/newview/skins/default/xui/en/menu_inventory_gear_default.xml | 22 |
3 files changed, 85 insertions, 12 deletions
diff --git a/indra/newview/llpanelmaininventory.cpp b/indra/newview/llpanelmaininventory.cpp index 9f0eed2cbe..bdfff9b2ab 100644 --- a/indra/newview/llpanelmaininventory.cpp +++ b/indra/newview/llpanelmaininventory.cpp @@ -34,6 +34,7 @@ #include "llpanelmaininventory.h"
#include "lldndbutton.h"
+#include "llfilepicker.h"
#include "llfloaterinventory.h"
#include "llinventorybridge.h"
#include "llinventoryfunctions.h"
@@ -45,9 +46,18 @@ #include "llspinctrl.h"
#include "lltooldraganddrop.h"
#include "llviewermenu.h"
+#include "llviewertexturelist.h"
static LLRegisterPanelClassWrapper<LLPanelMainInventory> t_inventory("panel_main_inventory"); // Seraph is this redundant with constructor?
+void on_file_loaded_for_save(BOOL success,
+ LLViewerFetchedTexture *src_vi,
+ LLImageRaw* src,
+ LLImageRaw* aux_src,
+ S32 discard_level,
+ BOOL final,
+ void* userdata);
+
///----------------------------------------------------------------------------
/// LLFloaterInventoryFinder
///----------------------------------------------------------------------------
@@ -906,6 +916,9 @@ void LLPanelMainInventory::onClipboardAction(const LLSD& userdata) void LLPanelMainInventory::onCustomAction(const LLSD& userdata)
{
+ if (!isActionEnabled(userdata))
+ return;
+
const std::string command_name = userdata.asString();
if (command_name == "new_window")
{
@@ -945,6 +958,25 @@ void LLPanelMainInventory::onCustomAction(const LLSD& userdata) }
if (command_name == "save_texture")
{
+ LLFolderViewItem* current_item = getActivePanel()->getRootFolder()->getCurSelectedItem();
+ if (!current_item)
+ {
+ return;
+ }
+
+ 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) )
+ {
+ // User canceled or we failed to acquire save file.
+ return;
+ }
+ // 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()) );
}
}
@@ -971,6 +1003,14 @@ BOOL LLPanelMainInventory::isActionEnabled(const LLSD& userdata) return can_delete;
}
}
+ if (command_name == "save_texture")
+ {
+ LLFolderViewItem* current_item = getActivePanel()->getRootFolder()->getCurSelectedItem();
+ if (current_item)
+ {
+ return (current_item->getListener()->getInventoryType() == LLInventoryType::IT_TEXTURE);
+ }
+ }
return FALSE;
}
@@ -987,3 +1027,36 @@ 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");
+ }
+}
diff --git a/indra/newview/llpanelmaininventory.h b/indra/newview/llpanelmaininventory.h index f7b9fd383e..29e9baa6cf 100644 --- a/indra/newview/llpanelmaininventory.h +++ b/indra/newview/llpanelmaininventory.h @@ -89,6 +89,7 @@ protected: void startSearch();
void toggleFindOptions();
+ void onSelectionChange(LLInventoryPanel *panel, const std::deque<LLFolderViewItem*>& items, BOOL user_action);
static BOOL filtersVisible(void* user_data);
void onClearSearch();
@@ -121,7 +122,6 @@ protected: void onCustomAction(const LLSD& command_name);
bool handleDragAndDropToTrash(BOOL drop, EDragAndDropType cargo_type, EAcceptance* accept);
- void onSelectionChange(LLInventoryPanel *panel, const std::deque<LLFolderViewItem*>& items, BOOL user_action);
private:
LLFloaterInventoryFinder* getFinder();
diff --git a/indra/newview/skins/default/xui/en/menu_inventory_gear_default.xml b/indra/newview/skins/default/xui/en/menu_inventory_gear_default.xml index 1592ba7bc7..435a3e6d34 100644 --- a/indra/newview/skins/default/xui/en/menu_inventory_gear_default.xml +++ b/indra/newview/skins/default/xui/en/menu_inventory_gear_default.xml @@ -76,15 +76,15 @@ function="Inventory.GearDefault.Custom.Action" parameter="empty_lostnfound" /> </menu_item_call> - <menu_item_call - label="Save Texture As" - layout="topleft" - name="save_texture"> - <on_click - function="Inventory.GearDefault.Custom.Action" - parameter="save_texture" /> - <on_enable - function="Inventory.GearDefault.Enable" - parameter="save_texture" /> - </menu_item_call> + <menu_item_call + label="Save Texture As" + layout="topleft" + name="Save Texture As"> + <on_click + function="Inventory.GearDefault.Custom.Action" + parameter="save_texture" /> + <on_enable + function="Inventory.GearDefault.Enable" + parameter="save_texture" /> + </menu_item_call> </menu> |