//=====================================================================
// CTor
WxTreeView::WxTreeView(TreeHandler* handler,
- TimestampDatabaseHandler* tdh,
GimmickView* gimmick,
wxWindow* parent,
const wxWindowID id)
: wxPanel(parent,id),
- TreeView(handler, tdh, gimmick)
+ TreeView(handler, gimmick)
{
GimmickDebugMessage(1,"WxTreeView::WxTreeView"
<<std::endl);
i < handler->GetTree().GetNumberOfLevels() -1;
++i)
{
-
GimmickDebugMessage(5,"Creating view for level "<<i
<<std::endl);
LevelType level;
#if wxUSE_MENUS
+ // Column Menu
menu =new wxMenu;
wxMenuItem* m1=menu->Append(wxID_ANY, _T("&Sort ascending"));
wxMenuItem* m2=menu->Append(wxID_ANY, _T("&Sort descending"));
Connect( mAscendingID, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(WxTreeView::OnPopupSort) );
Connect( mDescendingID, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(WxTreeView::OnPopupSort) );
Connect( mFilterID, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(WxTreeView::OnPopupFilter) );
-
-#endif // wxUSE_MENUS
+
+ //ItemMenu
+ menuItem =new wxMenu;
+ wxMenuItem* m1Item=menuItem->Append(wxID_ANY, _T("&Anonymize"));
+ wxMenuItem* m2Item=menuItem->Append(wxID_ANY, _T("&Local Copy"));
+ wxMenuItem* m3Item=menuItem->Append(wxID_ANY, _T("&Edit Fields"));
+
+ mAnonymizingID=m1Item->GetId();
+ mLocalCopyID=m2Item->GetId();
+ mEditFieldID=m3Item->GetId();
+ //Connect( mAnonymizingID, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(WxTreeView::OnAnonymize) );
+ Connect( mLocalCopyID, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(WxTreeView::OnLocalCopy) );
+ Connect( mEditFieldID, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(WxTreeView::OnEditField) );
+
+
+#endif // wxUSE_MENUS
/// Initialize the first level splitter
sizer->Add( mLevelList[0].wxSplitter ,1, wxGROW ,0);
//=====================================================================
- const std::vector<tree::Node*>& WxTreeView::GetSelected(int level)
+ const std::vector<tree::Node*>& WxTreeView::GetSelected(int level)
{
// if (GetSelectedUpToDate(level))
-
int l = level - 1;
// the selection of upper level
- std::vector<tree::Node*>& sel(mLevelList[level-1].Selected);
+ std::vector<tree::Node*>& sel(mLevelList[l].Selected);
sel.clear();
-
- if (level == 1)
+ if (level == 1)
{
sel.push_back(GetTreeHandler()->GetTree().GetTree());
}
- else if (level < 5)
+ else if (level < mLevelList.size()+2 )
{
- int n = GetCtrl(l-1)->GetItemCount();
- for (int i = 0; i < n; i++)
+ long item = -1;
+ for ( ;; )
+ {
+ item = GetCtrl(l-1)->GetNextItem(item,
+ wxLIST_NEXT_ALL,
+ wxLIST_STATE_SELECTED);
+ if ( item == -1 )
+ break;
+ long adr = GetCtrl(l-1)->GetItemData(item);
+ tree::Node* n = ((ItemData*)adr)->node;
+ if(mLastSelected==item)
+ {
+ std::vector<tree::Node*>::iterator it;
+ it = sel.begin();
+ it = sel.insert ( it , n );
+ }
+ else
+ {
+
+ sel.push_back(n);
+ }
+
+ }
+ /*int n = GetCtrl(l-1)->GetItemCount();
+ for (int i = 0; i<n; i++)
{
+ std::cout<<GetCtrl(l-1)->GetItemState(i,wxLIST_STATE_SELECTED)<<std::endl;
if ( GetCtrl(l-1)->GetItemState(i,wxLIST_STATE_SELECTED))
{
long adr = GetCtrl(l-1)->GetItemData(i);
}
else
{
+
sel.push_back(n);
}
}
- }
+ }*/
}
else
{
// NOTHING
- }
-
-
+ }
// return mLevelList[level-1].Selected;
return sel;
{
needRefresh=true;
}
- GetTimestampDatabaseHandler()->RemoveNode("PATH",(*i));
- GetTreeHandler()->Remove(*i);
+ tree::Node* n= (tree::Node*)(*i);
+ GetTreeHandler()->LoadChildren((*i),4);
+ GetGimmickView()->AddIgnoreFile(n);
+ GetTreeHandler()->Remove(*i);
}
if(needRefresh && mLastLevel>1)
}
//=====================================================================
- //=====================================================================
+ //=====================================================================
/// Recursive method called upon by UpdateLevel to refresh all windows
void WxTreeView::RecursiveUpdateLevel( int level )
{
<<level
<<")"<<std::endl);
-
+
const std::vector<tree::Node*>& sel(GetSelected(level));
-
+
int l = level - 1;
-
+
// to speed up inserting we hide the control temporarily
GetCtrl(l)->Hide();
GetCtrl(l)->DeleteAllItems();
int _id=0;
//Adds items and sets their attributes
-
+
GetTreeHandler()->LoadChildren(*i,1);
tree::Node::ChildrenListType::reverse_iterator j;
for (j = (*i)->GetChildrenList().rbegin();
j!= (*i)->GetChildrenList().rend();
++j)
{
- GimmickDebugMessage(1,
- "adding children "
- <<(*j)->GetLabel()
- <<"'"
- <<std::endl);
-
- wxListItem item;
- item.SetMask(wxLIST_MASK_STATE |
- wxLIST_MASK_TEXT |
- // wxLIST_MASK_IMAGE |
- wxLIST_MASK_DATA |
- // wxLIST_MASK_WIDTH |
- wxLIST_MASK_FORMAT
- );
-
- ItemData* data = new ItemData;
- data->node = *j;
- data->id = _id;
-
- item.SetId(_id);
- item.SetData(data);
-
- _id++;
- GetCtrl(l)->InsertItem(item);
-
- //Setting attributes
- for (int k=0; k<GetCtrl(l)->GetColumnCount(); ++k)
- {
- std::string val;
- // Temporary correction : it works but no explanation about the problem FCY
- if(k==0 && level <3)
- val = (*j)->GetAttribute("NumberOfChildren");
- else
- val = (*j)->GetAttribute(mLevelList[l].key[k]);
- if(((*j)->GetAttributeDescriptor(mLevelList[l].key[k])).isDateEntry()) // Date
- {
- boost::gregorian::date d1(boost::gregorian::from_undelimited_string(val));
- val = to_iso_extended_string(d1);
- }
- else if(((*j)->GetAttributeDescriptor(mLevelList[l].key[k])).isTimeEntry()) // Time
- {
- if (val != "" || val != " ")
- val = val.substr(0,2) + " : " + val.substr(2,2) + " : " + val.substr(4,2);
- }
- else
- {
-
- }
- if (val.size()==0) val = "?";
- item.SetText( crea::std2wx(val));
- item.SetColumn(k);
- GetCtrl(l)->SetItem(item);
- }
-
- }
+ GimmickDebugMessage(1,
+ "adding children "
+ <<(*j)->GetLabel()
+ <<"'"
+ <<std::endl);
+
+ wxListItem item;
+ item.SetMask(wxLIST_MASK_STATE |
+ wxLIST_MASK_TEXT |
+ // wxLIST_MASK_IMAGE |
+ wxLIST_MASK_DATA |
+ // wxLIST_MASK_WIDTH |
+ wxLIST_MASK_FORMAT
+ );
+
+ ItemData* data = new ItemData;
+ data->node = *j;
+ data->id = _id;
+
+ item.SetId(_id);
+ item.SetData(data);
+
+ _id++;
+ GetCtrl(l)->InsertItem(item);
+
+ //Setting attributes
+ for (int k=0; k<GetCtrl(l)->GetColumnCount(); ++k)
+ {
+ std::string val;
+ // Temporary correction : it works but no explanation about the problem FCY
+
+ if(k==0 && level <3)
+ {
+ val = (*j)->GetAttribute("NumberOfChildren");
+ }
+ else
+ val = (*j)->GetAttribute(mLevelList[l].key[k]);
+ if(((*j)->GetAttributeDescriptor(mLevelList[l].key[k])).isDateEntry()) // Date
+ {
+ // std::cout << "["<<val<< "]" << std::endl;
+ std::string valtmp(val);
+ try
+ {
+ boost::gregorian::date d1(boost::gregorian::from_undelimited_string(val));
+ val = to_iso_extended_string(d1);
+ }
+ catch (...)
+ {
+ val = valtmp;
+ }
+ // std::cout << "["<<val<< "]" << std::endl;
+ }
+ else if(((*j)->GetAttributeDescriptor(mLevelList[l].key[k])).isTimeEntry()) // Time
+ {
+ if ((val.size()>6) &&
+ (val != "" || val != " "))
+ val = val.substr(0,2) + " : "
+ + val.substr(2,2) + " : "
+ + val.substr(4,2);
+ }
+ else
+ {
+
+ }
+ if (val.size()==0) val = "?";
+ item.SetText( crea::std2wx(val));
+ item.SetColumn(k);
+ GetCtrl(l)->SetItem(item);
+ }
+
+ }
}
-
+
SortLevel(l);
GetCtrl(l)->Show();
- }
+ }
//=====================================================================
-
-
+
+
//================================================================
void WxTreeView::OnItemDeSelected(wxListEvent& event)
{
if ( GetCtrl(level) == obj ) break;
}
SetSelectedUpToDate(level,false);
- // to allow a first selection in images TreeView
- if (level==mLevelList.size()-1)
- OnItemSelected(event);
+ // to allow a first selection in images TreeView
+ if (level==mLevelList.size()-1)
+ OnItemSelected(event);
}
//================================================================
-
+
//================================================================
void WxTreeView::OnItemSelected(wxListEvent& event)
{
+
GimmickDebugMessage(1,
GetTreeHandler()->GetTree().GetLabel()
<<" WxTreeView::OnItemSelected"<<std::endl);
// Validate selected images if the selection is at image level
if (level==(mLevelList.size()-1)) //&&mProcess)
{
- if(event.GetEventType()==10145)
+ if(event.GetEventType()==wxEVT_COMMAND_LIST_ITEM_SELECTED)
{
- ValidateSelectedImages (true);
+ ValidateSelectedImages (true);
}
else
{
- ValidateSelectedImages (false);
+ ValidateSelectedImages (false);
}
}
PopupMenu(menu, clientpt);
}
+
+ //================================================================
+ //================================================================
+
+ void WxTreeView::OnItemMenu(wxListEvent &event)
+ {
+ wxPoint clientpt;
+ clientpt.x = wxGetMousePosition().x - this->GetScreenPosition().x;
+ clientpt.y = wxGetMousePosition().y - this->GetScreenPosition().y;
+ senderCtrl = event.GetEventObject();
+ unsigned int level = 0;
+ for (level = 0; level<mLevelList.size(); ++level)
+ {
+ if ( GetCtrl(level) == senderCtrl ) break;
+ }
+ long* ptr=0;
+ int flag;
+ mLastRightLevel=level;
+ mLastRightSelected=GetCtrl(level)->HitTest(wxPoint(0,clientpt.y-8),flag,ptr);
+ PopupMenu(menuItem, clientpt);
+ }
+
//================================================================
//================================================================
GimmickDebugMessage(7,
"WxTreeView::OnEndLabelEdit"
<<std::endl);
- wxObject* ctrl = event.GetEventObject();
unsigned int level = 0;
for (level = 0; level<mLevelList.size(); ++level)
{
}
//================================================================
+ //================================================================
+ void WxTreeView::OnLocalCopy(wxCommandEvent& event)
+ {
+ wxBusyCursor busy;
+
+ unsigned int tempLevel = mLastLevel;
+ mLastLevel+=1;
+ const std::vector<tree::Node*>& sel=GetSelected(mLastLevel+1);
+
+ if(sel.size() != 0)
+ {
+ bool copy=false;
+ std::stringstream out;
+ std::string levelName=GetTreeHandler()->GetTree().GetLevelDescriptor(mLastLevel).GetName();
+ out<<"Copy ";
+ out<<sel.size();
+ if(sel.size()>1&&levelName.at(levelName.size()-1)!='s')
+ {
+ out<<" "<<levelName;
+ out<<"s to .gimmick?";
+ }
+ else
+ {
+ out<<" "<<GetTreeHandler()->GetTree().GetLevelDescriptor(mLastLevel).GetName()<<" to .gimmick?";
+ }
+ if (wxMessageBox(crea::std2wx(out.str()),
+ _T("Remove Files"),
+ wxYES_NO,this ) == wxYES)
+ {
+ copy = true;
+ }
+ if(copy)
+ {
+ std::vector<std::string> s;
+ GetFilenamesAsString(sel,s);
+ GetGimmickView()->CopyFiles(s);
+ }
+ }
+ else
+ {
+ mLastLevel = tempLevel;
+ }
+
+
+ }
+ //================================================================
+
+ //================================================================
+ void WxTreeView::OnEditField(wxCommandEvent& event)
+ {
+ if(mLastRightSelected!=-1)
+ {
+ tree::Node* node=((ItemData*)GetCtrl(mLastRightLevel)->GetItemData(mLastRightSelected))->node;
+ tree::LevelDescriptor::AttributeDescriptorListType::const_iterator a;
+ std::vector<std::string> names;
+ std::vector<std::string> keys;
+ for (a = GetTreeHandler()->GetTree().GetAttributeDescriptorList(mLastRightLevel+1).begin();
+ a != GetTreeHandler()->GetTree().GetAttributeDescriptorList(mLastRightLevel+1).end();
+ ++a)
+ {
+ if(a->GetFlags()==creaImageIO::tree::AttributeDescriptor::EDITABLE)
+ {
+ names.push_back(a->GetName());
+ keys.push_back(a->GetKey());
+ }
+ }
+ GetGimmickView()->CreateEditFieldsDialog(node,names,keys);
+ }
+ }
+ //================================================================
+
//================================================================
void WxTreeView::SortLevel(int level)
{
}
if(GetCtrl(level)->GetItemState(item, wxLIST_STATE_SELECTED)==0 )
{
+
adr = GetCtrl(level)->GetItemData(item);
nod = ((ItemData*)adr)->node;
nodes.push_back(nod);
}
}
- //================================================================
- void WxTreeView::SetColor(int l, int item)
+ //================================================================
+ void WxTreeView::GetFilenamesAsString(const std::vector<tree::Node*>& nodes, std::vector<std::string>&s)
{
- int colorId=12;
- GetCtrl(l)->SetItemTextColour(item, wxColourDatabase().Find
- (crea::std2wx(mColorPalette[colorId])));
- GetCtrl(l)->SetItemState(item,wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED, wxLIST_STATE_SELECTED); /*
- int colorId=0;
- //Setting the color according to the parent
- if(l==0)
- {
- item.SetBackgroundColour
- (wxColourDatabase().Find
- (crea::std2wx(mColorPalette[colorId])));
- mColorMap.insert
- (NodeColorPair
- (*j,wxColourDatabase().Find
- (crea::std2wx(mColorPalette[colorId]))));
- if(colorId<64)
+ std::vector<tree::Node*>::const_iterator i;
+
+ for (i=nodes.begin(); i!=nodes.end(); ++i)
+ {
+ if((*i)->GetLevel()<mLevelList.size())
{
- colorId++;
+ GetTreeHandler()->LoadChildren(*i,0);
+ GetFilenamesAsString((*i)->GetChildrenList(),s);
}
- else
- {
- colorId=0;
- }
- }
- else if(l!=mLevelList.size()-1)
+ else
{
- item.SetBackgroundColour(mColorMap[*i]);
- mColorMap.insert(NodeColorPair(*j,mColorMap[*i]));
+ std::string filename=(*i)->GetAttribute("FullFileName");
+ s.push_back(filename);
+ }
+ }
+ }
+
+ //================================================================
+
+ //================================================================
+ void WxTreeView::GetAttributes(std::vector<std::string>& areShown, std::vector<std::string>& notShown, int level)
+ {
+ areShown.clear();
+ notShown.clear();
+ tree::LevelDescriptor::AttributeDescriptorListType::const_iterator a;
+ for (a = GetTreeHandler()->GetTree().GetAttributeDescriptorList(level).begin();
+ a != GetTreeHandler()->GetTree().GetAttributeDescriptorList(level).end();
+ ++a)
+ {
+ if(a->GetFlags()==creaImageIO::tree::AttributeDescriptor::EDITABLE && IsAttributeVisible(a->GetName(),level))
+ {
+ areShown.push_back(a->GetName());
}
- else
- {
- item.SetBackgroundColour(mColorMap[*i]);
- }*/
+ }
+ notShown=mLevelList[level-1].notShownAtts;
}
+
//================================================================
- void WxTreeView::CreateColorPalette()
+ void WxTreeView::SetNonVisibleAttributes(const std::vector<std::string>& notShown, int nlevel)
{
- GimmickDebugMessage(6,"WxTreeView::CreateColorPalette");
- mColorPalette.push_back("WHITE");
- mColorPalette.push_back("LIGHT GREY");
- mColorPalette.push_back("AQUAMARINE");
- mColorPalette.push_back("MEDIUM FOREST GREEN");
- mColorPalette.push_back("INDIAN RED");
- mColorPalette.push_back("KHAKI");
- mColorPalette.push_back("ORANGE");
- mColorPalette.push_back("LIGHT BLUE");
- mColorPalette.push_back("LIGHT STEEL BLUE");
- mColorPalette.push_back("PINK");
- mColorPalette.push_back("PLUM");
- mColorPalette.push_back("PURPLE");
- mColorPalette.push_back("RED");
- mColorPalette.push_back("SEA GREEN");
- mColorPalette.push_back("SIENNA");
- mColorPalette.push_back("SKY BLUE");
- mColorPalette.push_back("SLATE BLUE");
- mColorPalette.push_back("SPRING GREEN");
- mColorPalette.push_back("TAN");
- mColorPalette.push_back("THISTLE");
- mColorPalette.push_back("TURQUOISE");
- mColorPalette.push_back("VIOLET");
- mColorPalette.push_back("VIOLET RED");
- mColorPalette.push_back("WHEAT");
- mColorPalette.push_back("YELLOW");
- mColorPalette.push_back("YELLOW GREEN");
- mColorPalette.push_back("BLUE");
- mColorPalette.push_back("BLUE VIOLET");
- mColorPalette.push_back("BROWN");
- mColorPalette.push_back("CADET BLUE");
- mColorPalette.push_back("CORAL");
- mColorPalette.push_back("CORNFLOWER BLUE");
- mColorPalette.push_back("CYAN");
- mColorPalette.push_back("DARK GREY");
- mColorPalette.push_back("DARK GREEN");
- mColorPalette.push_back("DARK OLIVE GREEN");
- mColorPalette.push_back("DARK ORCHID");
- mColorPalette.push_back("DARK SLATE BLUE");
- mColorPalette.push_back("DARK SLATE GREY");
- mColorPalette.push_back("DARK TURQUOISE");
- mColorPalette.push_back("FIREBRICK");
- mColorPalette.push_back("FOREST GREEN");
- mColorPalette.push_back("GOLD");
- mColorPalette.push_back("GOLDENROD");
- mColorPalette.push_back("GREY");
- mColorPalette.push_back("GREEN");
- mColorPalette.push_back("GREEN YELLOW");
- mColorPalette.push_back("LIME GREEN");
- mColorPalette.push_back("MAGENTA");
- mColorPalette.push_back("MAROON");
- mColorPalette.push_back("MEDIUM AQUAMARINE");
- mColorPalette.push_back("MEDIUM BLUE");
- mColorPalette.push_back("MEDIUM GOLDENROD");
- mColorPalette.push_back("MEDIUM ORCHID");
- mColorPalette.push_back("MEDIUM SEA GREEN");
- mColorPalette.push_back("MEDIUM SLATE BLUE");
- mColorPalette.push_back("MEDIUM SPRING GREEN");
- mColorPalette.push_back("MEDIUM TURQUOISE");
- mColorPalette.push_back("MEDIUM VIOLET RED");
- mColorPalette.push_back("MIDNIGHT BLUE");
- mColorPalette.push_back("NAVY");
- mColorPalette.push_back("ORANGE RED");
- mColorPalette.push_back("ORCHID, PALE GREEN");
- mColorPalette.push_back("STEEL BLUE");
- mColorPalette.push_back("BLACK");
+ mLevelList[nlevel].notShownAtts=notShown;
+ }
+
+ //================================================================
+ void WxTreeView::CreateCtrl(std::vector<std::string>& notShown, int nlevel)
+ {
+ int ctrl_style = wxLC_REPORT | wxLC_VRULES;
+ int col_style = wxLIST_FORMAT_LEFT;
+ LevelType level;
+ mLevelList[nlevel].SelectedUpToDate = true;
+ mLevelList[nlevel].SortColumn = 0;
+ mLevelList[nlevel].key.clear();
+
+ mLevelList[nlevel].wxCtrl = new wxListCtrl(mLevelList[nlevel].wxSplitter,
+ nlevel,
+ wxDefaultPosition,
+ wxDefaultSize,
+ ctrl_style);
+ wxWindow* oldWin=mLevelList[nlevel].wxSplitter->GetWindow1();
+ mLevelList[nlevel].wxSplitter->ReplaceWindow(oldWin,mLevelList[nlevel].wxCtrl);
+ mLevelList[nlevel].wxSplitter->Initialize(mLevelList[nlevel].wxCtrl);
+
+ // Create the columns : one for each attribute of the level
+ int col = 0;
+ std::string title;
+ tree::LevelDescriptor::AttributeDescriptorListType::const_iterator a;
+ for (a = GetTreeHandler()->GetTree().GetAttributeDescriptorList(nlevel+1).begin();
+ a != GetTreeHandler()->GetTree().GetAttributeDescriptorList(nlevel+1).end();
+ ++a)
+ {
+ if(a->GetFlags()!=creaImageIO::tree::AttributeDescriptor::PRIVATE && IsAttributeVisible(a->GetName(),nlevel+1))
+ {
+ title=a->GetName();
+ std::string temp = a->GetKey();
+ if (temp.compare("ID") != 0)
+ {
+ mLevelList[nlevel].wxCtrl->InsertColumn(col,
+ crea::std2wx(title),
+ col_style);
+ col++;
+ }
+ mLevelList[nlevel].key.push_back(a->GetKey());
+ }
+
+ }
+ oldWin->Destroy();
+ UpdateLevel(1);
+ }
+
+ //================================================================
+ bool WxTreeView::IsAttributeVisible(const std::string& val, int level)
+ {
+ std::vector<std::string> ns=mLevelList[level-1].notShownAtts;
+ std::vector<std::string>::iterator it;
+ bool found=false;
+ for(it=ns.begin();it!=ns.end()&&!found;++it)
+ {
+ if(val.compare(*it)==0)
+ {
+ found=true;
+ }
+ }
+
+ return !found;
}
+
+ //================================================================
//================================================================
BEGIN_EVENT_TABLE(WxTreeView, wxPanel)
/*
*/
EVT_LIST_KEY_DOWN(-1, WxTreeView::OnKeyDown)
EVT_LIST_ITEM_SELECTED(-1, WxTreeView::OnItemSelected)
-
+ EVT_LIST_ITEM_RIGHT_CLICK(-1, WxTreeView::OnItemMenu)
EVT_LIST_ITEM_DESELECTED(-1, WxTreeView::OnItemDeSelected)
/*
EVT_LIST_KEY_DOWN(LIST_CTRL, MyListCtrl::OnListKeyDown)