Browse Source

Preserve original TBSelectList behavior as it is used outside of our tree view

Josh Engebretson 10 years ago
parent
commit
c5e26e1aeb

+ 2 - 0
Script/AtomicEditor/ui/frames/ProjectFrame.ts

@@ -254,6 +254,8 @@ class ProjectFrame extends ScriptWidget {
             var db = ToolCore.getAssetDatabase();
 
             var asset = db.getAssetByGUID(selectedId);
+            if (!asset)
+                return;
 
             if (asset.isFolder)
                 this.refreshContent(asset);

+ 7 - 1
Source/Atomic/UI/UIListView.cpp

@@ -403,6 +403,7 @@ UIListView::UIListView(Context* context, bool createWidget) :
     source_(0), itemLookupId_(0), multiSelect_(false)
 {
     rootList_ = new UISelectList(context);
+    rootList_->SetUIListView(true);
 
     // dummy filter so filter is called
     rootList_->SetFilter(" ");
@@ -834,7 +835,12 @@ bool UIListView::OnEvent(const tb::TBWidgetEvent &ev)
             }
 
         }
-}
+    }
+
+    if (ev.type == EVENT_TYPE_SHORTCUT)
+    {
+        return false;
+    }
 
     return UIWidget::OnEvent(ev);
 }

+ 10 - 1
Source/Atomic/UI/UISelectList.cpp

@@ -83,7 +83,6 @@ void UISelectList::SelectItem(int index, bool selected)
 
 }
 
-
 void UISelectList::SetValue(int value)
 {
     if (!widget_)
@@ -258,4 +257,14 @@ void UISelectList::SelectPreviousItem()
     ((TBSelectList*)widget_)->ChangeValue(TB_KEY_UP);
 }
 
+void UISelectList::SetUIListView(bool value)
+{
+    if (!widget_)
+        return;
+
+    ((TBSelectList*)widget_)->SetUIListView(value);
+
+}
+
+
 }

+ 2 - 0
Source/Atomic/UI/UISelectList.h

@@ -68,6 +68,8 @@ public:
     void SelectNextItem();
     void SelectPreviousItem();
 
+    void SetUIListView(bool value);
+
 protected:
 
     void HandleUIUpdate(StringHash eventType, VariantMap& eventData);

+ 11 - 0
Source/AtomicEditor/Editors/SceneEditor3D/SceneEditor3D.cpp

@@ -346,6 +346,17 @@ void SceneEditor3D::Redo()
     editHistory_->Redo();
 }
 
+void SceneEditor3D::Copy()
+{
+    selection_->Copy();
+}
+
+void SceneEditor3D::Paste()
+{
+    selection_->Paste();
+}
+
+
 void SceneEditor3D::HandleSceneEditSceneModified(StringHash eventType, VariantMap& eventData)
 {
     SetModified(true);    

+ 2 - 0
Source/AtomicEditor/Editors/SceneEditor3D/SceneEditor3D.h

@@ -72,6 +72,8 @@ public:
 
     void Undo();
     void Redo();
+    void Copy();
+    void Paste();
 
     ProjectUserPrefs* GetUserPrefs();
 

+ 4 - 0
Source/AtomicEditor/Editors/SceneEditor3D/SceneView3D.cpp

@@ -331,6 +331,10 @@ void SceneView3D::HandleUIUnhandledShortcut(StringHash eventType, VariantMap& ev
         sceneEditor_->Undo();
     else if (id == TBIDC("redo"))
         sceneEditor_->Redo();
+    else if (id == TBIDC("copy"))
+        sceneEditor_->Copy();
+    else if (id == TBIDC("paste"))
+        sceneEditor_->Paste();
 
     return;
 

+ 23 - 14
Source/ThirdParty/TurboBadger/tb_select.cpp

@@ -28,6 +28,7 @@ TBSelectList::TBSelectList()
 	, m_scroll_to_current(false)
     , m_header_lng_string_id(TBIDC("TBList.header"))
     , m_sort_callback(select_list_sort_cb)
+    , m_ui_list_view(false)
 {
 	SetSource(&m_default_source);
 	SetIsFocusable(true);
@@ -213,6 +214,9 @@ void TBSelectList::SetValue(int value)
 	if (value == m_value)
 		return;
 
+    if (!m_ui_list_view)
+        SelectItem(m_value, false);
+
 	m_value = value;
 	SelectItem(m_value, true);
 	ScrollToSelectedItem();
@@ -249,10 +253,11 @@ TBID TBSelectList::GetSelectedItemID()
 
 void TBSelectList::SelectItem(int index, bool selected)
 {
-    //if (TBWidget *widget = GetItemWidget(index))
-    //{
-    //    widget->SetState(WIDGET_STATE_SELECTED, selected);
-    //}
+    if (!m_ui_list_view)
+    {
+        if (TBWidget *widget = GetItemWidget(index))
+            widget->SetState(WIDGET_STATE_SELECTED, selected);
+    }
 }
 
 TBWidget *TBSelectList::GetItemWidget(int index)
@@ -305,15 +310,20 @@ bool TBSelectList::OnEvent(const TBWidgetEvent &ev)
 
 		int index = ev.target->data.GetInt();
 
-        if (TBWidget *widget = GetItemWidget(index))
+        if (!m_ui_list_view)
+            SetValue(index);
+        else
         {
-            TBWidgetEvent change_ev(EVENT_TYPE_CUSTOM);
-            // TBIDC does not register the string with the UI system
-            TBID refid("select_list_selection_changed");
-            change_ev.ref_id = refid;
-            change_ev.modifierkeys = ev.modifierkeys;
-            // forward to delegate
-            widget->InvokeEvent(change_ev);
+            if (TBWidget *widget = GetItemWidget(index))
+            {
+                TBWidgetEvent change_ev(EVENT_TYPE_CUSTOM);
+                // TBIDC does not register the string with the UI system
+                TBID refid("select_list_selection_changed");
+                change_ev.ref_id = refid;
+                change_ev.modifierkeys = ev.modifierkeys;
+                // forward to delegate
+                widget->InvokeEvent(change_ev);
+            }
         }
 
 		// If we're still around, invoke the click event too.
@@ -357,7 +367,7 @@ bool TBSelectList::OnEvent(const TBWidgetEvent &ev)
 
 bool TBSelectList::ChangeValue(SPECIAL_KEY key)
 {
-	if (!m_source || !m_layout.GetContentRoot()->GetFirstChild())
+    if (m_ui_list_view || !m_source || !m_layout.GetContentRoot()->GetFirstChild())
 		return false;
 
 	bool forward;
@@ -387,7 +397,6 @@ bool TBSelectList::ChangeValue(SPECIAL_KEY key)
 	// Select and focus what we found
 	if (current)
 	{
-        SelectAllItems(false);
 		SetValue(current->data.GetInt());
 		return true;
 	}

+ 3 - 0
Source/ThirdParty/TurboBadger/tb_select.h

@@ -88,6 +88,8 @@ public:
     TBID GetItemID(int index) const;
     int GetNumItems() const;
 
+    void SetUIListView(bool value) { m_ui_list_view = value; }
+
 	virtual void OnInflate(const INFLATE_INFO &info);
 	virtual void OnSkinChanged();
 	virtual void OnProcess();
@@ -108,6 +110,7 @@ protected:
 	TBStr m_filter;
 	bool m_list_is_invalid;
 	bool m_scroll_to_current;
+    bool m_ui_list_view;
 	TBID m_header_lng_string_id;
 private:
     TBSelectListSortCallback m_sort_callback;