private void ImportFolder() { using (var fbd = new FolderBrowserDialog()) if (fbd.ShowDialog() == DialogResult.OK) { if (_rootFolder == null) { _rootFolder = new ImagesFolder(); _rootFolder.ImageAddConflict += RootFolderImageAddConflict; ImportFolder(_rootFolder, fbd.SelectedPath); AssignRootFolder(); } else { using (new TreeGridUpdater(_foldersTree)) { _suppressImagesListUpdate = true; try { ImportFolder(_activeFolder ?? _rootFolder, fbd.SelectedPath); } finally { _suppressImagesListUpdate = false; } } } } }
private void OpenFile() { if (!TrySaveChanges()) { return; } if (_openFileDialog.ShowDialog() == DialogResult.OK) { if (_rootFolder != null) { _rootFolder.ImageAddConflict -= RootFolderImageAddConflict; _rootFolder = null; DisposeLoadedImages(); } var fileName = _openFileDialog.FileName; if (fileName.ToLower().Contains(".resx")) { using (IResourceReader rd = new ResXResourceReader(fileName)) _rootFolder = new ImagesFolder(rd); } else { using (IResourceReader rd = new ResourceReader(fileName)) _rootFolder = new ImagesFolder(rd); } _rootFolder.ImageAddConflict += RootFolderImageAddConflict; _fileName = fileName; AssignRootFolder(); } }
public RootNode(ImagesFolder folder) { if (folder == null) { throw new ArgumentNullException("folder"); } _folder = folder; }
private ImagesFolder(string name, ImagesFolder parent) { _name = name; _parentFolder = parent; Parent = parent; Flags = NodeFlags.None; IsChanged = false; }
private void UpdateImagesListImageList(ImagesFolder folder) { var il = _imagesList.LargeImageList; _imagesList.LargeImageList = folder.CreateImageList(); if (il != null) { il.Dispose(); } }
private void ImportFolder(ImagesFolder folder, string folderPath) { var files = new Dictionary <string, List <string> >(); LoadImages(folderPath, false, string.Empty, files); foreach (var kvp in files) { var prefix = string.IsNullOrEmpty(kvp.Key) ? string.Empty : kvp.Key + ImagesFolder.NameSeparator; foreach (var file in kvp.Value) { var shortName = Path.GetFileNameWithoutExtension(file); folder.AddImage(folder.GetFullName(prefix + shortName), _loadedImages[file]); } } }
private void AddImage(string imageFileName) { try { Image img; if (!_loadedImages.TryGetValue(imageFileName, out img)) { img = Image.FromFile(imageFileName); _loadedImages.Add(imageFileName, img); } using (var inf = new ImageNameForm()) { if (_activeFolder != null) { inf.ImageNameChanged += ImageNameForm_ImageNameChanged; inf.ImageName = _activeFolder.GetFullName( Path.GetFileNameWithoutExtension(imageFileName)); } if (inf.ShowDialog() == DialogResult.OK) { if (_rootFolder == null) { _rootFolder = new ImagesFolder(); _rootFolder.ImageAddConflict += RootFolderImageAddConflict; _rootFolder.AddImage(inf.ImageName, img); AssignRootFolder(); } else { using (new TreeGridUpdater(_foldersTree)) _rootFolder.AddImage(inf.ImageName, img); } } } } catch (ArgumentException ex) { MessageBox.Show(ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void FillList(ImagesFolder folder) { _imagesList.BeginUpdate(); try { _imagesList.Items.Clear(); if (folder == null) { return; } UpdateImagesListImageList(folder); foreach (var info in folder.Images) { _imagesList.Items.Add(CreateImageItem(info)); } } finally { _imagesList.EndUpdate(); } }
private void AddImage(string fullName, string[] names, Image image) { var shortName = names[0]; if (names.Length == 1) { if (_images.ContainsKey(shortName)) { if (GetRootFolder().OnAddConflict(shortName, fullName)) { _images[shortName] = new ImageInfo(fullName, shortName, image); // TODO: Сделать более красиво. OnImageRemoved(fullName, shortName); OnImageAdded(fullName, shortName); } } else { _images.Add(shortName, new ImageInfo(fullName, shortName, image)); OnImageAdded(fullName, shortName); } return; } var folder = _folders.FirstOrDefault(f => f.Name == shortName); if (folder == null) { folder = new ImagesFolder(shortName, this); _folders.Add(folder); } var subNames = new string[names.Length - 1]; Array.Copy(names, 1, subNames, 0, names.Length - 1); folder.AddImage(fullName, subNames, image); }
private void FoldersTreeAfterActivateNode(ITreeNode activatedNode) { var node = _foldersTree.ActiveNode; if (_activeFolder != null) { _activeFolder.ImageAdded -= ImagesFolder_ImageAdded; _activeFolder.ImageRemoved -= ImagesFolder_ImageRemoved; } if (node != null) { _activeFolder = (ImagesFolder)node; _activeFolder.ImageAdded += ImagesFolder_ImageAdded; _activeFolder.ImageRemoved += ImagesFolder_ImageRemoved; FillList(_activeFolder); } else { _activeFolder = null; } UpdateButtonsStates(); }
public RootNode(ImagesFolder folder) { if (folder == null) throw new ArgumentNullException("folder"); _folder = folder; }
private void FillList(ImagesFolder folder) { _imagesList.BeginUpdate(); try { _imagesList.Items.Clear(); if (folder == null) return; UpdateImagesListImageList(folder); foreach (var info in folder.Images) _imagesList.Items.Add(CreateImageItem(info)); } finally { _imagesList.EndUpdate(); } }
private void UpdateImagesListImageList(ImagesFolder folder) { var il = _imagesList.LargeImageList; _imagesList.LargeImageList = folder.CreateImageList(); if (il != null) il.Dispose(); }
private void OpenFile() { if (!TrySaveChanges()) return; if (_openFileDialog.ShowDialog() == DialogResult.OK) { if (_rootFolder != null) { _rootFolder.ImageAddConflict -= RootFolderImageAddConflict; _rootFolder = null; DisposeLoadedImages(); } var fileName = _openFileDialog.FileName; if (fileName.ToLower().Contains(".resx")) using (IResourceReader rd = new ResXResourceReader(fileName)) _rootFolder = new ImagesFolder(rd); else using (IResourceReader rd = new ResourceReader(fileName)) _rootFolder = new ImagesFolder(rd); _rootFolder.ImageAddConflict += RootFolderImageAddConflict; _fileName = fileName; AssignRootFolder(); } }
private void ImportFolder(ImagesFolder folder, string folderPath) { var files = new Dictionary<string, List<string>>(); LoadImages(folderPath, false, string.Empty, files); foreach (var kvp in files) { var prefix = string.IsNullOrEmpty(kvp.Key) ? string.Empty : kvp.Key + ImagesFolder.NameSeparator; foreach (var file in kvp.Value) { var shortName = Path.GetFileNameWithoutExtension(file); folder.AddImage(folder.GetFullName(prefix + shortName), _loadedImages[file]); } } }