void clTreeCtrlPanel::OnRenameFile(wxCommandEvent& event) { wxArrayString files, folders; wxArrayTreeItemIds fileItems, folderItems; GetSelections(folders, folderItems, files, fileItems); if(files.empty()) return; // Prompt and rename each file for(size_t i = 0; i < files.size(); ++i) { wxFileName oldname(files.Item(i)); wxString newname = ::clGetTextFromUser(_("Rename File"), _("New Name:"), oldname.GetFullName(), wxStrlen(oldname.GetName())); if(!newname.IsEmpty() && (newname != oldname.GetFullName())) { clTreeCtrlData* d = GetItemData(fileItems.Item(i)); if(d) { wxFileName oldpath = d->GetPath(); wxFileName newpath = oldpath; newpath.SetFullName(newname); if(::wxRenameFile(oldpath.GetFullPath(), newpath.GetFullPath(), false)) { DoRenameItem(fileItems.Item(i), oldname.GetFullName(), newname); } } } } }
void FossRecWidget::SelectedActive(bool s) { QList<bool> selections = GetSelections(); for (int i=0; i<FossilRecords.count(); i++) if (selections[i]) FossilRecords[i]->recording=s; RefreshMe(); }
void FossRecWidget::SelectedSparse(int s) { QList<bool> selections = GetSelections(); for (int i=0; i<FossilRecords.count(); i++) if (selections[i]) FossilRecords[i]->sparsity=s; RefreshMe(); }
void clTreeCtrlPanel::OnDeleteFile(wxCommandEvent& event) { wxArrayString folders, files; wxArrayTreeItemIds folderItems, fileItems; GetSelections(folders, folderItems, files, fileItems); if(files.empty()) return; wxString message; message << _("Are you sure you want to delete the selected files?"); wxRichMessageDialog dialog(EventNotifier::Get()->TopFrame(), message, _("Confirm"), wxYES_NO | wxCANCEL | wxNO_DEFAULT | wxCENTER | wxICON_WARNING); dialog.SetYesNoLabels(_("Delete Files"), _("No")); wxWindowUpdateLocker locker(GetTreeCtrl()); wxArrayTreeItemIds deletedItems; if(dialog.ShowModal() == wxID_YES) { wxLogNull nl; for(size_t i = 0; i < files.size(); ++i) { if(::wxRemoveFile(files.Item(i))) { deletedItems.Add(fileItems.Item(i)); } } } // Update the UI for(size_t i = 0; i < deletedItems.size(); ++i) { // Before we delete the item from the tree, update the parent cache UpdateItemDeleted(deletedItems.Item(i)); // And now remove the item from the tree GetTreeCtrl()->Delete(deletedItems.Item(i)); } }
int ALIGN_DISTRIBUTE_TOOL::AlignCenterY( const TOOL_EVENT& aEvent ) { ALIGNMENT_RECTS itemsToAlign; ALIGNMENT_RECTS locked_items; if( !GetSelections( itemsToAlign, locked_items, []( const ALIGNMENT_RECT left, const ALIGNMENT_RECT right) { return ( left.second.GetCenter().y < right.second.GetCenter().y ); } ) ) return 0; BOARD_COMMIT commit( m_frame ); commit.StageItems( m_selectionTool->GetSelection(), CHT_MODIFY ); auto targetY = selectTarget( itemsToAlign, locked_items, []( const ALIGNMENT_RECT& aVal ) { return aVal.second.GetCenter().y; } ); // Move the selected items for( auto& i : itemsToAlign ) { int difference = targetY - i.second.GetCenter().y; BOARD_ITEM* item = i.first; // Don't move a pad by itself unless editing the footprint if( item->Type() == PCB_PAD_T && m_frame->IsType( FRAME_PCB ) ) item = item->GetParent(); item->Move( wxPoint( 0, difference ) ); } commit.Push( _( "Align to center" ) ); return 0; }
void HierTreeCtrl::OnRename() { wxArrayTreeItemIds selItems; GetSelections(selItems); wxTreeItemId selItem = selItems.Item(0); EditLabel(selItem); }
void wxListBox::DoSetSelection(int N, bool select) { wxCHECK_RET( IsValid(N), wxT("invalid index in wxListBox::SetSelection") ); MacSetSelection( N , select ) ; GetSelections( m_selectionPreImage ) ; }
void FileExplorerTab::OnContextMenu(wxTreeEvent& event) { wxTreeItemId item = event.GetItem(); wxMenu* menu = GetBaseContextMenu(); if(item.IsOk() && menu) { wxArrayString folders, files; GetSelections(folders, files); if(!files.IsEmpty() && folders.IsEmpty()) { // Let the plugins alter it clContextMenuEvent fileMenuEvent(wxEVT_CONTEXT_MENU_FILE); fileMenuEvent.SetMenu(menu); fileMenuEvent.SetStrings(files); EventNotifier::Get()->ProcessEvent(fileMenuEvent); } else if(folders.GetCount() == 1) { clContextMenuEvent folderMenuEvent(wxEVT_CONTEXT_MENU_FOLDER); folderMenuEvent.SetMenu(menu); folderMenuEvent.SetPath(folders.Item(0)); EventNotifier::Get()->ProcessEvent(folderMenuEvent); } PluginManager::Get()->HookPopupMenu(menu, MenuTypeFileExplorer); PopupMenu(menu); } wxDELETE(menu); }
void clTreeCtrlPanel::OnFindInFilesFolder(wxCommandEvent& event) { wxArrayString folders, files; GetSelections(folders, files); if(folders.IsEmpty()) return; clGetManager()->OpenFindInFileForPaths(folders); }
void HierTreeCtrl::OnBeginDrag(wxTreeEvent& event) { GetSelections(draggedItems); //wxPoint clientpt = event.GetPoint(); //wxPoint screenpt = ClientToScreen(clientpt); event.Allow(); }
void clTreeCtrlPanel::OnOpenFile(wxCommandEvent& event) { wxArrayString folders, files; GetSelections(folders, files); for(size_t i = 0; i < files.size(); ++i) { clGetManager()->OpenFile(files.Item(i)); } }
void clTreeCtrlPanel::OnCloseFolder(wxCommandEvent& event) { wxArrayString paths, files; wxArrayTreeItemIds items, fileItems; GetSelections(paths, items, files, fileItems); if(items.IsEmpty()) return; for(size_t i = 0; i < items.GetCount(); ++i) { DoCloseFolder(items.Item(i)); } }
void wxListBoxBase::UpdateOldSelections() { // We need to remember the selection even in single-selection case on // Windows, so that we don't send an event when the user clicks on an // already selected item. #ifndef __WXMSW__ if (HasFlag(wxLB_MULTIPLE) || HasFlag(wxLB_EXTENDED)) #endif { GetSelections( m_oldSelections ); } }
TreeItemInfo clTreeCtrlPanel::GetSelectedItemInfo() { TreeItemInfo info; wxArrayString folders, files; GetSelections(folders, files); folders.insert(folders.end(), files.begin(), files.end()); if(folders.empty()) return info; info.m_paths = folders; info.m_item = wxTreeItemId(); return info; }
int SelectionList::GetSelection(const std::string &name) const { int retval = -1; for(int i = 0; i < GetNumSelections(); ++i) { if(GetSelections(i).GetName() == name) { retval = i; break; } } return retval; }
bool wxListBox::IsSelected(int N) const { // In Motif, no simple way to determine if the item is selected. wxArrayInt theSelections; int count = GetSelections (theSelections); if (count == 0) return false; else { int j; for (j = 0; j < count; j++) if (theSelections[j] == N) return true; } return false; }
bool wxListBox::OS2Command( WXUINT uParam , WXWORD WXUNUSED(wId)) { wxEventType eEvtType; if (uParam == LN_SELECT) { eEvtType = wxEVT_COMMAND_LISTBOX_SELECTED; } else if (uParam == LN_ENTER) { eEvtType = wxEVT_COMMAND_LISTBOX_DOUBLECLICKED; } else { // // Some event we're not interested in // return false; } wxCommandEvent vEvent( eEvtType ,m_windowId ); vEvent.SetEventObject(this); wxArrayInt aSelections; int n; int nCount = GetSelections(aSelections); if (nCount > 0) { n = aSelections[0]; if (HasClientObjectData()) vEvent.SetClientObject(GetClientObject(n)); else if ( HasClientUntypedData() ) vEvent.SetClientData(GetClientData(n)); vEvent.SetString(GetString(n)); } else { n = -1; } vEvent.SetInt(n); return GetEventHandler()->ProcessEvent(vEvent); } // end of wxListBox::OS2Command
void wxListBox::MacDoClick() { wxArrayInt aSelections; int n ; size_t count = GetSelections(aSelections); if ( count == m_selectionPreImage.GetCount() ) { bool hasChanged = false ; for ( size_t i = 0 ; i < count ; ++i ) { if ( aSelections[i] != m_selectionPreImage[i] ) { hasChanged = true ; break ; } } if ( !hasChanged ) { return ; } } m_selectionPreImage = aSelections; wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, m_windowId); event.SetEventObject( this ); if ( count > 0 ) { n = aSelections[0]; if ( HasClientObjectData() ) event.SetClientObject( GetClientObject(n) ); else if ( HasClientUntypedData() ) event.SetClientData( GetClientData(n) ); event.SetString(GetString(n)); } else { n = -1; } event.SetInt(n); GetEventHandler()->ProcessEvent(event); }
void HierTreeCtrl::OnDelete() { GetSelections(draggedItems); wxTreeItemId item; for (size_t i = 0; i < draggedItems.GetCount(); ++i) { item = draggedItems.Item(i); if (item == GetRootItem() || item == NULL) { break; } Delete(item); } draggedItems.Clear(); }
int FossRecWidget::findclosest(int x, int y, int min) { //find closest selected item to the given position. Return -1 if its further than min away int dist2=99999999; int closest=-1; QList<bool> selections = GetSelections(); for (int i=0; i<FossilRecords.count(); i++) if (selections[i]) { int dist=(FossilRecords[i]->xpos-x)*(FossilRecords[i]->xpos-x) + (FossilRecords[i]->ypos-y)*(FossilRecords[i]->ypos-y); if (dist<dist2) { dist2=dist; closest=i; } } if (sqrt((double)dist2)<min) return closest; else return -1; }
void wxListBoxBase::UpdateOldSelections() { // When the control becomes empty, any previously remembered selections are // invalid anyhow, so just forget them. if ( IsEmpty() ) { m_oldSelections.clear(); return; } // We need to remember the selection even in single-selection case on // Windows, so that we don't send an event when the user clicks on an // already selected item. #ifndef __WXMSW__ if (HasFlag(wxLB_MULTIPLE) || HasFlag(wxLB_EXTENDED)) #endif { GetSelections( m_oldSelections ); } }
void clTreeCtrlPanel::OnRefresh(wxCommandEvent& event) { wxArrayString paths, files; wxArrayTreeItemIds items, fileItems; GetSelections(paths, items, files, fileItems); if(items.IsEmpty()) return; // Close the selected folders std::vector<std::pair<wxString, bool> > topFolders; for(size_t i = 0; i < items.GetCount(); ++i) { topFolders.push_back(std::make_pair(paths.Item(i), GetTreeCtrl()->IsExpanded(items.Item(i)))); DoCloseFolder(items.Item(i)); } // Re-add them for(size_t i = 0; i < topFolders.size(); ++i) { wxTreeItemId itemFolder = DoAddFolder(GetTreeCtrl()->GetRootItem(), topFolders.at(i).first); DoExpandItem(itemFolder, topFolders.at(i).second); } GetTreeCtrl()->SortChildren(GetTreeCtrl()->GetRootItem()); ToggleView(); }
/* Under all platforms there is no reaction when pressing "ENTER". Expected would be e.g. to open the file in an editor. */ void cbTreeCtrl::OnKeyDown(wxKeyEvent& event) { // Don't care about special key combinations if (event.GetModifiers()!=wxMOD_NONE) { event.Skip(); return; } wxArrayTreeItemIds selections; // Don't care if no selection has been made if ( GetSelections(selections)<1 ) { event.Skip(); return; } long keycode = event.GetKeyCode(); wxTreeItemId itemId = selections[0]; // Don't care if item is invalid if ( !itemId.IsOk() ) { event.Skip(); return; } switch (keycode) { case WXK_RETURN: case WXK_NUMPAD_ENTER: { wxTreeEvent te = wxTreeEvent(wxEVT_COMMAND_TREE_ITEM_ACTIVATED, this, itemId); wxPostEvent(this, te); break; } default: event.Skip(); } }
void wxListBox::DoSetSelection(int N, bool select) { m_inSetValue = true; if (select) { #if 0 if (m_windowStyle & wxLB_MULTIPLE) { int *selections = NULL; int n = GetSelections (&selections); // This hack is supposed to work, to make it possible // to select more than one item, but it DOESN'T under Motif 1.1. XtVaSetValues ((Widget) m_mainWidget, XmNselectionPolicy, XmMULTIPLE_SELECT, NULL); int i; for (i = 0; i < n; i++) XmListSelectPos ((Widget) m_mainWidget, selections[i] + 1, False); XmListSelectPos ((Widget) m_mainWidget, N + 1, False); XtVaSetValues ((Widget) m_mainWidget, XmNselectionPolicy, XmEXTENDED_SELECT, NULL); } else #endif // 0 XmListSelectPos ((Widget) m_mainWidget, N + 1, False); } else XmListDeselectPos ((Widget) m_mainWidget, N + 1); m_inSetValue = false; }
void FossRecWidget::RefreshMe() { QList<bool> selections=GetSelections(); //write in all the current records ui->treeWidget->clear(); if (FossilRecords.count()==0) return; ui->treeWidget->setUniformRowHeights(true); ui->treeWidget->setUpdatesEnabled(false); for (int i=0; i<FossilRecords.count(); i++) { QStringList strings; QString temp; strings.append(FossilRecords[i]->name); temp.sprintf("%d",FossilRecords[i]->xpos); strings.append(temp); temp.sprintf("%d",FossilRecords[i]->ypos); strings.append(temp); temp.sprintf("%d",FossilRecords[i]->startage); strings.append(temp); temp.sprintf("%d",FossilRecords[i]->sparsity); strings.append(temp); temp.sprintf("%d",FossilRecords[i]->recorded); strings.append(temp); if (FossilRecords[i]->recording) strings.append("Yes"); else strings.append("No"); QTreeWidgetItem *item=new QTreeWidgetItem(strings); item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); ui->treeWidget->addTopLevelItem(item); } //redo selections for (int i=0; i<selections.count(); i++) ui->treeWidget->topLevelItem(i)->setSelected(selections[i]); ui->treeWidget->setUpdatesEnabled(true); return; }
void wxListBoxBase::DeselectAll(int itemToLeaveSelected) { if ( HasMultipleSelection() ) { wxArrayInt selections; GetSelections(selections); size_t count = selections.GetCount(); for ( size_t n = 0; n < count; n++ ) { int item = selections[n]; if ( item != itemToLeaveSelected ) Deselect(item); } } else // single selection { int sel = GetSelection(); if ( sel != wxNOT_FOUND && sel != itemToLeaveSelected ) { Deselect(sel); } } }
void wxListBoxBase::UpdateOldSelections() { if (HasFlag(wxLB_MULTIPLE) || HasFlag(wxLB_EXTENDED)) GetSelections( m_oldSelections ); }
bool wxListBoxBase::CalcAndSendEvent() { wxArrayInt selections; GetSelections(selections); bool selected = true; if ( selections.empty() && m_oldSelections.empty() ) { // nothing changed, just leave return false; } const size_t countSel = selections.size(), countSelOld = m_oldSelections.size(); if ( countSel == countSelOld ) { bool changed = false; for ( size_t idx = 0; idx < countSel; idx++ ) { if (selections[idx] != m_oldSelections[idx]) { changed = true; break; } } // nothing changed, just leave if ( !changed ) return false; } int item = wxNOT_FOUND; if ( selections.empty() ) { selected = false; item = m_oldSelections[0]; } else // we [still] have some selections { // Now test if any new item is selected bool any_new_selected = false; for ( size_t idx = 0; idx < countSel; idx++ ) { item = selections[idx]; if ( m_oldSelections.Index(item) == wxNOT_FOUND ) { any_new_selected = true; break; } } if ( !any_new_selected ) { // No new items selected, now test if any new item is deselected bool any_new_deselected = false; for ( size_t idx = 0; idx < countSelOld; idx++ ) { item = m_oldSelections[idx]; if ( selections.Index(item) == wxNOT_FOUND ) { any_new_deselected = true; break; } } if ( any_new_deselected ) { // indicate that this is a selection selected = false; } else { item = wxNOT_FOUND; // this should be impossible } } } wxASSERT_MSG( item != wxNOT_FOUND, "Logic error in wxListBox selection event generation code" ); m_oldSelections = selections; return SendEvent(wxEVT_LISTBOX, item, selected); }
void wxCheckListBox::OnKeyDown(wxKeyEvent& event) { // what do we do? enum { NONE, TOGGLE, SET, CLEAR } oper; switch ( event.GetKeyCode() ) { case WXK_SPACE: oper = TOGGLE; break; case WXK_NUMPAD_ADD: case '+': oper = SET; break; case WXK_NUMPAD_SUBTRACT: case '-': oper = CLEAR; break; default: oper = NONE; } if ( oper != NONE ) { wxArrayInt selections; int count = 0; if ( HasMultipleSelection() ) { count = GetSelections(selections); } else { int sel = GetSelection(); if (sel != -1) { count = 1; selections.Add(sel); } } for ( int i = 0; i < count; i++ ) { int nItem = selections[i]; switch ( oper ) { case TOGGLE: Toggle(nItem); break; case SET: case CLEAR: Check(nItem, oper == SET); break; default: wxFAIL_MSG( wxT("what should this key do?") ); } // we should send an event as this has been done by the user and // not by the program SendEvent(nItem); } } else // nothing to do { event.Skip(); } }
void wxGxTreeView::OnBeginDrag(wxTreeEvent& event) { //event.Skip(); wxTreeItemId item = event.GetItem(); if(!item.IsOk()) return; SelectItem(item); //TODO: wxDELETE(pDragData) somethere wxDataObjectComposite *pDragData = new wxDataObjectComposite(); wxGISStringDataObject *pNamesData = new wxGISStringDataObject(wxDataFormat(wxT("application/x-vnd.wxgis.gxobject-name"))); pDragData->Add(pNamesData, true); wxFileDataObject *pFileData = new wxFileDataObject(); pDragData->Add(pFileData, false); //wxGISDecimalDataObject *pIDsData = new wxGISDecimalDataObject(wxDataFormat(wxT("application/x-vnd.wxgis.gxobject-id"))); //pDragData->Add(pIDsData, false); //TODO: create dataobject for QGIS // wxDataObjectSimple* pDataObjectSimple = new wxDataObjectSimple(wxDataFormat(wxT("application/x-vnd.qgis.qgis.uri"))); // my_data->Add(pDataObjectSimple); // // wxMemoryOutputStream *pstream = new wxMemoryOutputStream(); // wxDataOutputStream dostr(*pstream); // wxArrayTreeItemIds treearray; size_t count = GetSelections(treearray); if(count == 0) return; //first is catalog memory address to prevent different app drop //pIDsData->AddDecimal((long)GetGxCatalog()); for(size_t i = 0; i < count; ++i) { wxGxTreeItemData* pData = (wxGxTreeItemData*)GetItemData(treearray[i]); if(pData == NULL) continue; wxGxObject* pGxObject = m_pCatalog->GetRegisterObject(pData->m_nObjectID); if(pGxObject == NULL) continue; wxString sSystemPath(pGxObject->GetPath(), wxConvUTF8); pFileData->AddFile(sSystemPath); pNamesData->AddString(pGxObject->GetFullName()); //pIDsData->AddDecimal(pGxObject->GetId()); } wxDropSource dragSource( this ); dragSource.SetData( *pDragData ); wxDragResult result = dragSource.DoDragDrop( wxDrag_DefaultMove ); // IGxObject* pParentGxObject(NULL); // for(size_t i = 0; i < count; ++i) // { // wxGxTreeItemData* pData = (wxGxTreeItemData*)GetItemData(treearray[i]); // if(pData == NULL) // continue; // // IGxObjectSPtr pGxObject = m_pCatalog->GetRegisterObject(pData->m_nObjectID); // pParentGxObject = pGxObject->GetParent(); // wxString sSystemPath(pGxObject->GetInternalName(), wxConvUTF8); // pFileData->AddFile(sSystemPath); // dostr.WriteString(sSystemPath); // wxStreamBuffer* theBuffer = pstream->GetOutputStreamBuffer(); // // pDataObjectSimple->SetData(theBuffer->GetBufferSize(), theBuffer->GetBufferStart()); // } //// IGxObjectUI* pGxObjectUI = dynamic_cast<IGxObjectUI*>(pGxObject.get()); ////if(pGxObjectUI) ////{ //// wxDataFormat frm = pGxObjectUI->GetDataFormat(); //// if(frm.GetType() != wxDF_INVALID) //// my_data.SetFormat(frm); ////} // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // wxFileDataObject my_data; // wxArrayTreeItemIds treearray; // size_t count = GetSelections(treearray); // if(count == 0) // return; // wxGxObject* pParentGxObject(NULL); // for(size_t i = 0; i < count; ++i) // { // wxGxTreeItemData* pData = (wxGxTreeItemData*)GetItemData(treearray[i]); // if(pData == NULL) // continue; // wxGxObject* pGxObject = m_pCatalog->GetRegisterObject(pData->m_nObjectID); // pParentGxObject = pGxObject->GetParent(); // wxString sSystemPath(pGxObject->GetPath(), wxConvUTF8); // my_data.AddFile(sSystemPath); // } // wxDropSource dragSource( this ); //dragSource.SetData( my_data ); //wxDragResult result = dragSource.DoDragDrop( ); }