private void AssociationDropDownMenu_Delete(object sender, RoutedEventArgs e) { MenuItem mi = sender as MenuItem; Element element = mi.DataContext as Element; try { if (element != null) { LogControl.Write( element, LogEventAccess.AssociationContextMenu, LogEventType.Delete, LogEventStatus.Begin, null); DeleteWindow dw; DeleteMessageType dmt = DeleteMessageType.Default; if (element.IsLocalHeading) { dmt = DeleteMessageType.HeadingWithChildren; } else if (element.AssociationType == ElementAssociationType.File) { dmt = DeleteMessageType.File; } else { dmt = DeleteMessageType.Shortcut; } dw = new DeleteWindow(dmt); if (dw.ShowDialog().Value == true) { if (element.IsLocalHeading) { elementControl.DeleteElement(element); } else { elementControl.Demote(element); elementControl.RemoveAssociation(element); } LogControl.Write( element, LogEventAccess.AssociationContextMenu, LogEventType.Delete, LogEventStatus.End, LogEventInfo.DeleteType + LogControl.COMMA + dmt.ToString()); } else { LogControl.Write( element, LogEventAccess.AssociationContextMenu, LogEventType.Delete, LogEventStatus.Cancel, null); } } } catch (Exception ex) { MessageBox.Show("Oops!\nSomething unexpected happened, please close this Planz window and reopen."); //MessageBox.Show("AssociationDropDownMenu_Delete\n" + ex.Message); LogControl.Write( element, LogEventAccess.AssociationContextMenu, LogEventType.Delete, LogEventStatus.Error, LogEventInfo.ErrorMessage + LogControl.COMMA + ex.Message); } }
private void RibbonCommandDelete_Executed(object sender, ExecutedRoutedEventArgs e) { LogEventAccess lea = LogEventAccess.Ribbon; if (sender is TextBox) { lea = LogEventAccess.Hotkey; } else if (sender is System.Windows.Controls.MenuItem) { lea = LogEventAccess.NodeContextMenu; } else if (sender is Planz.MainWindow) { lea = LogEventAccess.Ribbon; } Element targetElement = elementControl.CurrentElement; try { if (targetElement != null) { DeleteMessageType dmt = DeleteMessageType.Default; if (elementControl.SelectedElements.Count <= 1) { switch (targetElement.Type) { case ElementType.Heading: if (targetElement.IsRemoteHeading) { dmt = DeleteMessageType.InplaceExpansionHeading; } else { if (elementControl.HasChildOrContent(targetElement)) { dmt = DeleteMessageType.HeadingWithChildren; } else { dmt = DeleteMessageType.HeadingWithoutChildren; } } break; case ElementType.Note: if (targetElement.HasAssociation) { switch (targetElement.AssociationType) { case ElementAssociationType.File: dmt = DeleteMessageType.NoteWithFileAssociation; break; case ElementAssociationType.FileShortcut: case ElementAssociationType.Web: case ElementAssociationType.Email: dmt = DeleteMessageType.NoteWithShortcutAssociation; break; }; } else { dmt = DeleteMessageType.NoteWithoutAssociation; } break; }; if (dmt == DeleteMessageType.HeadingWithoutChildren || dmt == DeleteMessageType.NoteWithoutAssociation) { LogControl.Write( targetElement, lea, LogEventType.Delete, LogEventStatus.Begin, null); Element nextElement = elementControl.FindNextElementAfterDeletion(targetElement); elementControl.DeleteElement(targetElement); if (nextElement != null) { GetFocusToElementTextBox(nextElement, nextElement.NoteText.Length, false, false); } LogControl.Write( nextElement, lea, LogEventType.Delete, LogEventStatus.End, LogEventInfo.DeleteType + LogControl.COMMA + dmt.ToString()); } else { LogControl.Write( targetElement, lea, LogEventType.Delete, LogEventStatus.Begin, null); DeleteWindow dw = new DeleteWindow(dmt); if (dw.ShowDialog().Value == true) { Element nextElement = elementControl.FindNextElementAfterDeletion(targetElement); elementControl.DeleteElement(targetElement); if (nextElement != null) { GetFocusToElementTextBox(nextElement, nextElement.NoteText.Length, false, false); } LogControl.Write( nextElement, lea, LogEventType.Delete, LogEventStatus.End, LogEventInfo.DeleteType + LogControl.COMMA + dmt.ToString()); } else { LogControl.Write( targetElement, lea, LogEventType.Delete, LogEventStatus.Cancel, null); } } } else { LogControl.Write( targetElement, lea, LogEventType.Delete, LogEventStatus.Begin, null); dmt = DeleteMessageType.MultipleItems; DeleteWindow dw = new DeleteWindow(dmt); if (dw.ShowDialog().Value == true) { Element nextElement = elementControl.FindNextElementAfterDeletion(targetElement); for (int i = 0; i < elementControl.SelectedElements.Count; i++) { elementControl.DeleteElement(elementControl.SelectedElements[i]); } elementControl.SelectedElements.Clear(); if (nextElement != null) { GetFocusToElementTextBox(nextElement, nextElement.NoteText.Length, false, false); } LogControl.Write( nextElement, lea, LogEventType.Delete, LogEventStatus.End, LogEventInfo.DeleteType + LogControl.COMMA + dmt.ToString()); } else { LogControl.Write( targetElement, lea, LogEventType.Delete, LogEventStatus.Cancel, null); } } } } catch (Exception ex) { MessageBox.Show("Oops!\nSomething unexpected happened, please close this Planz window and reopen."); //MessageBox.Show("RibbonCommandDelete_Executed\n" + ex.Message); LogControl.Write( targetElement, lea, LogEventType.Delete, LogEventStatus.Error, LogEventInfo.ErrorMessage + LogControl.COMMA + ex.Message); } }
public void PowerDDelete(Element element, PowerDDeleteType pddt) { switch (pddt) { case PowerDDeleteType.Delete: DeleteMessageType dmt = DeleteMessageType.Default; switch (element.Type) { case ElementType.Heading: if (element.IsRemoteHeading) { dmt = DeleteMessageType.InplaceExpansionHeading; } else { if (HasChildOrContent(element)) { dmt = DeleteMessageType.HeadingWithChildren; } else { dmt = DeleteMessageType.HeadingWithoutChildren; } } break; case ElementType.Note: if (element.HasAssociation) { switch (element.AssociationType) { case ElementAssociationType.File: dmt = DeleteMessageType.NoteWithFileAssociation; break; case ElementAssociationType.FileShortcut: case ElementAssociationType.Web: case ElementAssociationType.Email: dmt = DeleteMessageType.NoteWithShortcutAssociation; break; }; } else { dmt = DeleteMessageType.NoteWithoutAssociation; } break; }; if (dmt == DeleteMessageType.HeadingWithoutChildren || dmt == DeleteMessageType.NoteWithoutAssociation) { } else { DeleteWindow dw = new DeleteWindow(dmt); if (dw.ShowDialog().Value == true) { } else { return; } } DeleteElement(element); break; case PowerDDeleteType.Undo: string folderPath = String.Empty; string oldGuid = String.Empty; Element oldElement = null; if (element.PowerDStatus == PowerDStatus.Done && element.TempData != String.Empty) { folderPath = element.TempData.Split('|')[0]; oldGuid = element.TempData.Split('|')[1]; DatabaseControl temp_dbControl = new DatabaseControl(folderPath); temp_dbControl.OpenConnection(); foreach (Element ele in temp_dbControl.GetAllElementFromXML()) { if (ele.ID.ToString() == oldGuid) { oldElement = ele; break; } } temp_dbControl.RemoveElementFromXML(oldElement); temp_dbControl.CloseConnection(); if (oldElement != null && oldElement.AssociationURI != String.Empty) { if (oldElement.AssociationType == ElementAssociationType.File) { System.IO.File.Delete(element.AssociationURIFullPath); System.IO.File.Move(folderPath + oldElement.AssociationURI, element.Path + oldElement.AssociationURI); element.AssociationType = ElementAssociationType.File; AssignICCInfo(element, element.Path + oldElement.AssociationURI); } else { System.IO.File.Delete(folderPath + oldElement.AssociationURI); } } } element.FontColor = ElementColor.Black.ToString(); element.TempData = String.Empty; element.PowerDStatus = PowerDStatus.None; element.IsVisible = Visibility.Visible; break; }; UpdateElement(element); }