Inheritance: ITreeNode
コード例 #1
0
        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;
                            }
                        }
                    }
                }
        }
コード例 #2
0
        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();
            }
        }
コード例 #3
0
 public RootNode(ImagesFolder folder)
 {
     if (folder == null)
     {
         throw new ArgumentNullException("folder");
     }
     _folder = folder;
 }
コード例 #4
0
 private ImagesFolder(string name, ImagesFolder parent)
 {
     _name         = name;
     _parentFolder = parent;
     Parent        = parent;
     Flags         = NodeFlags.None;
     IsChanged     = false;
 }
コード例 #5
0
ファイル: ImagesFolder.cs プロジェクト: rsdn/janus
		private ImagesFolder(string name, ImagesFolder parent)
		{
			_name = name;
			_parentFolder = parent;
			Parent = parent;
			Flags = NodeFlags.None;
			IsChanged = false;
		}
コード例 #6
0
        private void UpdateImagesListImageList(ImagesFolder folder)
        {
            var il = _imagesList.LargeImageList;

            _imagesList.LargeImageList = folder.CreateImageList();
            if (il != null)
            {
                il.Dispose();
            }
        }
コード例 #7
0
        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]);
                }
            }
        }
コード例 #8
0
        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);
            }
        }
コード例 #9
0
        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();
            }
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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();
        }
コード例 #12
0
ファイル: MainForm.cs プロジェクト: rsdn/janus
			public RootNode(ImagesFolder folder)
			{
				if (folder == null)
					throw new ArgumentNullException("folder");
				_folder = folder;
			}
コード例 #13
0
ファイル: MainForm.cs プロジェクト: rsdn/janus
		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);
			}
		}
コード例 #14
0
ファイル: MainForm.cs プロジェクト: rsdn/janus
		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();
			}
		}
コード例 #15
0
ファイル: MainForm.cs プロジェクト: rsdn/janus
		private void UpdateImagesListImageList(ImagesFolder folder)
		{
			var il = _imagesList.LargeImageList;
			_imagesList.LargeImageList = folder.CreateImageList();
			if (il != null)
				il.Dispose();
		}
コード例 #16
0
ファイル: MainForm.cs プロジェクト: rsdn/janus
		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();
			}
		}
コード例 #17
0
ファイル: MainForm.cs プロジェクト: rsdn/janus
		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]);
				}
			}
		}
コード例 #18
0
ファイル: MainForm.cs プロジェクト: rsdn/janus
		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;
							}
						}
					}
				}
		}
コード例 #19
0
ファイル: ImagesFolder.cs プロジェクト: rsdn/janus
		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);
		}
コード例 #20
0
ファイル: MainForm.cs プロジェクト: rsdn/janus
		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();
		}