private void RenameThumbnail(string oldName, LabeledThumbnail labeledThumbnail) { if (oldName == labeledThumbnail.NameLable) return; var newPath = labeledThumbnail.ImagePath.Replace(@"\" + oldName, @"\" + labeledThumbnail.NameLable); File.Move(labeledThumbnail.ImagePath, newPath); labeledThumbnail.ImagePath = newPath; Globals.ThisAddIn.ShapePresentation.RenameShape(oldName, labeledThumbnail.NameLable); Globals.ThisAddIn.SyncShapeRename(oldName, labeledThumbnail.NameLable, CurrentCategory); }
private void RemoveThumbnail(LabeledThumbnail thumbnail, bool removeSelection = true) { if (removeSelection && _selectedThumbnail.Contains(thumbnail)) { _selectedThumbnail.Remove(thumbnail); } myShapeFlowLayout.Controls.Remove(thumbnail); if (myShapeFlowLayout.Controls.Count == 0) { ShowNoShapeMessage(); } }
private void MultiSelectClickHandler(LabeledThumbnail clickedThumbnail) { if (MouseButtons != MouseButtons.Left && MouseButtons != MouseButtons.Right) return; // for right click, if selection > 1, the context menu should appear with selection // remained, else we should change the focus. Specially, when selection > 1, some of // the options in the context menu serves for the clicked item, such as rename. if (MouseButtons == MouseButtons.Right) { if (_selectedThumbnail.Count > 1 && _selectedThumbnail.Contains(clickedThumbnail)) { _selectedThumbnail.Remove(clickedThumbnail); _selectedThumbnail.Insert(0, clickedThumbnail); return; } } // if Ctrl key is not holding, i.e. not doing multi-selecting, all highlighed // thumbnail should be dehighlighted if (!ModifierKeys.HasFlag(Keys.Control)) { foreach (var thumbnail in _selectedThumbnail) { thumbnail.DeHighlight(); } _selectedThumbnail.Clear(); } if (!_selectedThumbnail.Contains(clickedThumbnail)) { // highlight the thumbnail and add the clicked thumbnail to the collection clickedThumbnail.Highlight(); _selectedThumbnail.Insert(0, clickedThumbnail); FocusSelected(); } else { // turn off the highlighting if the clicked thumbnail is currently highlighted if (ModifierKeys.HasFlag(Keys.Control)) { clickedThumbnail.DeHighlight(); _clickOnSelected = false; _selectedThumbnail.Remove(clickedThumbnail); } } }
private void FirstClickOnThumbnail(LabeledThumbnail clickedThumbnail) { if (_selectedThumbnail == null) return; if (_selectedThumbnail.Count != 0) { // this flag doesn't apply for multi selection, thus turn off _clickOnSelected = false; // common part, end editing if (_selectedThumbnail[0].State == LabeledThumbnail.Status.Editing) { _selectedThumbnail[0].FinishNameEdit(); } else if (_selectedThumbnail[0] == clickedThumbnail) { _clickOnSelected = true; } MultiSelectClickHandler(clickedThumbnail); } else { clickedThumbnail.Highlight(); _selectedThumbnail.Insert(0, clickedThumbnail); FocusSelected(); } }
public void AddCustomShape(string shapeName, string shapePath, bool immediateEditing) { DehighlightSelected(); var labeledThumbnail = new LabeledThumbnail(shapePath, shapeName) { ContextMenuStrip = shapeContextMenuStrip }; labeledThumbnail.Click += LabeledThumbnailClick; labeledThumbnail.DoubleClick += LabeledThumbnailDoubleClick; labeledThumbnail.NameEditFinish += NameEditFinishHandler; myShapeFlowLayout.Controls.Add(labeledThumbnail); if (myShapeFlowLayout.Controls.Contains(_noShapePanel)) { myShapeFlowLayout.Controls.Remove(_noShapePanel); } myShapeFlowLayout.ScrollControlIntoView(labeledThumbnail); _selectedThumbnail.Insert(0, labeledThumbnail); if (immediateEditing) { labeledThumbnail.StartNameEdit(); } else { // the shape must be sorted immediately since the name has been // setteled ReorderThumbnail(labeledThumbnail); } }
private void ReorderThumbnail(LabeledThumbnail labeledThumbnail) { var index = FindLabeledThumbnailIndex(labeledThumbnail.NameLable); // if the current control is the only control or something goes wrong, don't need // to reorder if (index == -1 || index >= myShapeFlowLayout.Controls.Count) { return; } myShapeFlowLayout.Controls.SetChildIndex(labeledThumbnail, index); }