private void BtnOkClick(object sender, System.EventArgs e) { DialogResult = DialogResult.None; string layoutName = LayoutName; if (string.IsNullOrEmpty(layoutName)) { m_toolTip.Show(m_txtLayout, null, ToolTipIcon.Warning, "Layout name cannot be empty!"); return; } if (!WindowLayoutService.IsValidLayoutName(layoutName)) { m_toolTip.Show(m_txtLayout, null, ToolTipIcon.Warning, "Invalid layout name!"); return; } if (m_existingItems.Contains(layoutName)) { m_toolTip.Show(m_txtLayout, null, ToolTipIcon.Warning, "A layout with this name already exists!"); return; } DialogResult = DialogResult.OK; }
public static string IsValidName(string layoutName) { if (string.IsNullOrEmpty(layoutName)) { return("Layout name is empty"); } if (!WindowLayoutService.IsValidLayoutName(layoutName)) { return("Layout name contains invalid characters"); } return(null); }
string IsValidName(string layoutName) { if (string.IsNullOrEmpty(layoutName)) { return("Layout name is empty"); } if (!WindowLayoutService.IsValidLayoutName(layoutName)) { return("Layout name contains invalid characters"); } if (m_existingItems.Contains(layoutName)) { return("Layout name already exists"); } return(null); }
private void LayoutsAfterLabelEdit(object sender, LabelEditEventArgs e) { ListViewItem lstItem = m_layouts.Items[e.Item]; Point toolTipPos = GetSubItemTopRightPoint(lstItem.SubItems[0]); string oldName = lstItem.Text; string newName = e.Label; // Invalid label if (string.IsNullOrEmpty(newName)) { e.CancelEdit = true; m_toolTip.Show(m_layouts, toolTipPos, null, ToolTipIcon.Warning, "Name can't be empty!"); return; } // No duplicates if (m_names.Contains(newName)) { e.CancelEdit = true; if (string.Compare(newName, oldName) != 0) { m_toolTip.Show(m_layouts, toolTipPos, null, ToolTipIcon.Warning, "A layout with this name already exists!"); } return; } // No invalid characters if (!WindowLayoutService.IsValidLayoutName(newName)) { e.CancelEdit = true; m_toolTip.Show(m_layouts, toolTipPos, null, ToolTipIcon.Warning, "Name contains illegal characters!"); return; } // Keep track of renames { var tag = (LayoutTag)lstItem.Tag; m_renamedLayouts[tag.OldName] = newName; } // Rename in the name of layouts list { m_names.Remove(oldName); m_names.Add(newName); } // Rename screenshot try { m_screenshot.Image = null; // Dispose of existing screenshot so it can be renamed Image image; if (m_screenshots.TryGetValue(oldName, out image)) { image.Dispose(); m_screenshots.Remove(oldName); } // // Try and remove existing screenshot on disk // string sourceFile = Path.Combine( m_screenshotDirectory.FullName + Path.DirectorySeparatorChar, oldName + WindowLayoutServiceCommandsBase.ScreenshotExtension); if (!File.Exists(sourceFile)) { return; } string destFile = Path.Combine( m_screenshotDirectory.FullName + Path.DirectorySeparatorChar, newName + WindowLayoutServiceCommandsBase.ScreenshotExtension); File.Move(sourceFile, destFile); // Add renamed screenshot back if (File.Exists(destFile)) { m_screenshots.Add(newName, Image.FromFile(destFile)); } } catch (Exception ex) { Outputs.WriteLine( OutputMessageType.Error, "Manage Layouts: Exception " + "renaming screenshot: {0}", ex.Message); } finally { // Try and use the renamed screenshot Image image; if (m_screenshots.TryGetValue(newName, out image)) { m_screenshot.Image = image; } } }