Exemplo n.º 1
0
        /// <summary>
        /// Копирование файла в другую папку
        /// </summary>
        /// <param name="e">Файл для копирования</param>
        /// <param name="parent">Папка</param>
        /// <returns>Скопированный файл</returns>
        public static Entry CopyEntry(Entry en, Dir parent)
        {
            // Подбор имени
            string fileName = Path.GetFileNameWithoutExtension(en.Name);
            string ext      = Path.GetExtension(en.Name);
            string folder   = en.Parent.FullPath;

            while (File.Exists(folder + "/" + fileName + ext))
            {
                fileName += " - Copy";
            }

            // Копирование файла
            File.Copy(en.FullPath, folder + "/" + fileName + ext);

            // Создание записи
            Entry e = new Entry();

            e.Name   = fileName + ext;
            e.Parent = parent;
            e.Meta   = en.Meta;
            e.Icon   = Preview.Get(e.FullPath);
            List <Entry> fl = parent.Entries.ToList();

            fl.Add(e);
            fl.Sort((a, b) => {
                return(a.Name.CompareTo(b.Name));
            });
            parent.Entries = fl.ToArray();
            MainForm.ProjectEntryEvent(e, FileEvent.Created);
            return(e);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Изменение имени файла
 /// </summary>
 /// <param name="e">Файл для переименовывания</param>
 /// <param name="newName">Новое имя</param>
 /// <returns>True если файл переименован</returns>
 public static bool RenameItem(Project.Entry e, string newName)
 {
     if (newName.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
     {
         return(false);
     }
     if (newName != e.Name)
     {
         string oldfull = e.FullPath;
         byte[] meta    = null;
         if (newName.ToLower() != e.Name.ToLower())
         {
             meta   = e.Meta;
             e.Meta = null;
         }
         e.Name = newName;
         e.Icon = Preview.Get(e.FullPath);
         if (meta != null)
         {
             e.Meta = meta;
         }
         File.Move(oldfull, e.FullPath);
         MainForm.ProjectEntryEvent(e, FileEvent.Renamed);
     }
     return(true);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Создание нового файла
        /// </summary>
        /// <param name="name">Имя файла</param>
        /// <param name="parent">Родительский каталог</param>
        /// <returns></returns>
        public static Entry CreateEntry(string name, Project.Dir parent)
        {
            // Поиск похожего
            List <Entry> fl = new List <Entry>(parent.Entries);

            foreach (Entry f in fl)
            {
                if (f.Name.ToLower() == name.ToLower())
                {
                    return(null);
                }
            }

            // Запись на диск
            File.Create(parent.FullPath + "/" + name).Close();

            // Создание файла
            Entry e = new Entry();

            e.Name   = name;
            e.Parent = parent;
            e.Icon   = Preview.Get(e.FullPath);
            fl.Add(e);
            fl.Sort((a, b) => {
                return(a.Name.CompareTo(b.Name));
            });
            parent.Entries = fl.ToArray();
            MainForm.ProjectEntryEvent(e, FileEvent.Created);
            return(e);
        }
Exemplo n.º 4
0
        private void Populate(bool select = false)
        {
            // Очистка
            inspector.Entries.Clear();

            // Путь до папки
            fileLabel.Text       = currentDir.Name;
            submitButton.Enabled = false;

            // Заполнение папками
            foreach (Project.Dir d in currentDir.Dirs)
            {
                inspector.Entries.Add(new NSDirectoryInspector.Entry()
                {
                    IsDirectory = true,
                    Name        = System.IO.Path.GetFileName(d.Name),
                    Tag         = (object)d
                });
            }

            // Заполнение файлами
            foreach (Project.Entry e in currentDir.Entries)
            {
                if (Dropper.FileSupported(e.Name))
                {
                    if (e.Icon == null)
                    {
                        e.Icon = Preview.Get(e.FullPath);
                    }
                    inspector.Entries.Add(new NSDirectoryInspector.Entry()
                    {
                        IsDirectory = false,
                        Name        = System.IO.Path.GetFileNameWithoutExtension(e.Name),
                        Icon        = e.Icon,
                        Tag         = (object)e
                    });
                    if (select && prevFile == e)
                    {
                        inspector.SelectedEntry = inspector.Entries[inspector.Entries.Count - 1];
                        submitButton.Enabled    = true;
                    }
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Заполнение менеджера проекта
        /// </summary>
        /// <param name="dir">Директория для открытия</param>
        static void PopulateManager(Project.Dir dir)
        {
            // Очистка
            W.projectInspector.Entries.Clear();
            W.projectInspector.Tag = (object)dir;

            // Путь до папки
            string path = "Проект" + dir.Name.Substring(Project.BaseDir.Name.Length).Replace("\\", "/");

            if (!path.EndsWith("/"))
            {
                path += "/";
            }
            W.projectDir.Text = path;

            // Заполнение папками
            foreach (Project.Dir d in dir.Dirs)
            {
                W.projectInspector.Entries.Add(new NSDirectoryInspector.Entry()
                {
                    IsDirectory = true,
                    Name        = System.IO.Path.GetFileName(d.Name),
                    Tag         = (object)d
                });
            }

            // Заполнение файлами
            foreach (Project.Entry e in dir.Entries)
            {
                if (e.Icon == null)
                {
                    e.Icon = Preview.Get(System.IO.Path.Combine(dir.Name, e.Name));
                }
                W.projectInspector.Entries.Add(new NSDirectoryInspector.Entry()
                {
                    IsDirectory = false,
                    Name        = System.IO.Path.GetFileNameWithoutExtension(e.Name),
                    Icon        = e.Icon,
                    Tag         = (object)e
                });
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Заполнение менеджера проекта
        /// </summary>
        /// <param name="dir">Директория для открытия</param>
        protected static void PopulateManager(Project.Dir dir)
        {
            // Очистка
            W.projectInspector.Entries.Clear();
            W.projectInspector.Tag = (object)dir;

            // Путь до папки
            W.projectDir.Text = dir.Name;

            // Заполнение папками
            foreach (Project.Dir d in dir.Dirs)
            {
                W.projectInspector.Entries.Add(new NSDirectoryInspector.Entry()
                {
                    IsDirectory = true,
                    Name        = System.IO.Path.GetFileName(d.Name),
                    Tag         = (object)d
                });
            }

            // Заполнение файлами
            foreach (Project.Entry e in dir.Entries)
            {
                if (e.Icon == null)
                {
                    e.Icon = Preview.Get(e.FullPath);
                }
                W.projectInspector.Entries.Add(new NSDirectoryInspector.Entry()
                {
                    IsDirectory = false,
                    Name        = System.IO.Path.GetFileNameWithoutExtension(e.Name),
                    Icon        = e.Icon,
                    Tag         = (object)e
                });
            }

            W.projectRemove.Enabled = false;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Событие, связанное с файлом проекта
        /// </summary>
        public static void ProjectEntryEvent(Project.Entry e, Project.FileEvent ev)
        {
            System.Diagnostics.Debug.WriteLine("File " + e.ProjectPath + " " + ev.ToString());
            if (W != null)
            {
                // Обновление редакторов
                if (Editors != null)
                {
                    foreach (BaseForm b in Editors)
                    {
                        needProjectRescan = false;
                        b.FileEditor.ProjectEntryEvent(e, ev);
                    }
                }

                // Обновление инспектора
                if (!W.localFileEvent)
                {
                    Project.Dir cd = W.projectInspector.Tag as Project.Dir;
                    switch (ev)
                    {
                    case Project.FileEvent.Created:
                        if (e.Parent == cd)
                        {
                            if (e.Icon == null)
                            {
                                e.Icon = Preview.Get(e.FullPath);
                            }
                            W.projectInspector.Entries.Add(new NSDirectoryInspector.Entry()
                            {
                                IsDirectory = false,
                                Tag         = (object)e,
                                Name        = Path.GetFileNameWithoutExtension(e.Name),
                                Icon        = e.Icon
                            });
                            W.projectInspector.Invalidate();
                        }
                        break;

                    case Project.FileEvent.Modified:
                    case Project.FileEvent.Renamed:
                        if (e.Parent == cd)
                        {
                            object oe = (object)e;
                            if (ev == Project.FileEvent.Modified)
                            {
                                e.Icon = Preview.Get(e.FullPath);
                            }
                            foreach (NSDirectoryInspector.Entry en in W.projectInspector.Entries)
                            {
                                if (en.Tag == oe)
                                {
                                    en.Name = Path.GetFileNameWithoutExtension(e.Name);
                                    en.Icon = e.Icon;
                                    W.projectInspector.Invalidate();
                                    break;
                                }
                            }
                        }
                        break;

                    case Project.FileEvent.Deleted:
                        if (e.Parent == cd)
                        {
                            object oe = (object)e;
                            foreach (NSDirectoryInspector.Entry en in W.projectInspector.Entries)
                            {
                                if (en.Tag == oe)
                                {
                                    W.projectInspector.Entries.Remove(en);
                                    W.projectInspector.Invalidate();
                                    break;
                                }
                            }
                        }
                        break;
                    }
                }
            }
        }