/// <summary> /// Рекурсивный подсчёт файлов /// </summary> /// <param name="d"></param> void RecursiveCalculateFiles(Project.Dir d) { numFiles += d.Entries.Length; foreach (Project.Dir cd in d.Dirs) { RecursiveCalculateFiles(cd); } }
private void nsUpButton_Click(object sender, EventArgs e) { if (currentDir.Parent != null) { currentDir = currentDir.Parent; Populate(); } }
/// <summary> /// Переход на уровень вверх в инспекторе /// </summary> private void projectDirUp_Click(object sender, EventArgs e) { Project.Dir dr = projectInspector.Tag as Project.Dir; if (dr != null) { if (dr.Parent != null) { PopulateManager(dr.Parent); } } }
/// <summary> /// Создание меню создаваемых файлов /// </summary> /// <param name="col">Список для добавления</param> private void AddCreationMenuItems(ToolStripItemCollection col) { // Папка col.Add(ControlStrings.InspectorContextFolder, ShadowImage.CompiledFromImage(InspectorIcons.Folder, 16, 1), (sndr, args) => { Project.Dir d = projectInspector.Tag as Project.Dir; CreateItemDialog dlg = new CreateItemDialog(ControlStrings.InspectorContextFolder); dlg.ExistingNames = d.UsedNames; DialogResult dr = dlg.ShowDialog(); if (dr == System.Windows.Forms.DialogResult.OK) { localFileEvent = true; NSDirectoryInspector.Entry en = new NSDirectoryInspector.Entry(); en.IsDirectory = true; en.Name = dlg.SpecifiedName; en.Tag = Project.CreateDir(dlg.SpecifiedName, d); projectInspector.Entries.Add(en); projectInspector.SelectedEntry = en; localFileEvent = false; } }); if (Editor.CreatableList.Length > 0) { col.Add(new ToolStripSeparator()); foreach (Editor.FileCreator fc in Editor.CreatableList) { col.Add(fc.Name, ShadowImage.CompiledFromImage(fc.Icon, 16, 1), (sndr, args) => { Project.Dir cd = projectInspector.Tag as Project.Dir; Editor.FileCreator f = fc; if (cd != null) { CreateItemDialog dlg = new CreateItemDialog(fc.Name); dlg.Extension = f.Extension; dlg.ExistingNames = cd.UsedNames; if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { localFileEvent = true; Project.Entry ce = Project.CreateEntry(dlg.SpecifiedName, cd); NSDirectoryInspector.Entry en = new NSDirectoryInspector.Entry(); en.IsDirectory = false; en.Name = System.IO.Path.GetFileNameWithoutExtension(dlg.SpecifiedName); en.Icon = ce.Icon; en.Tag = (object)ce; projectInspector.Entries.Add(en); projectInspector.SelectedEntry = en; localFileEvent = false; } } }); } } }
protected override void OnShown(EventArgs e) { base.OnShown(e); prevFile = Dropper.File; if (Dropper.File != null) { currentDir = Dropper.File.Parent; } else { currentDir = Project.BaseDir; } Populate(true); Preview.PreviewsReady += Preview_PreviewsReady; Focus(); }
/// <summary> /// Фоновая поточная работа /// </summary> void ThreadedWork() { // Сканирование файлов для копирования RecursiveCalculateFiles(copyDir); // Копирование папки CopiedDir = RecursiveCopyDir(copyDir, newParent); List <Project.Dir> dirs = newParent.Dirs.ToList(); dirs.Add(CopiedDir); dirs.Sort((a, b) => { return(a.ShortName.CompareTo(b.ShortName)); }); newParent.Dirs = dirs.ToArray(); // Копирование закончено threadComplete = true; }
/// <summary> /// Двойной щелчок по файлу в инспекторе /// </summary> private void projectInspector_MouseDoubleClick(object sender, MouseEventArgs e) { NSDirectoryInspector.Entry en = projectInspector.SelectedEntry; if (en != null) { if (en.IsDirectory) { Project.Dir dr = en.Tag as Project.Dir; if (dr != null) { PopulateManager(dr); } } else { // TODO: Открытие файла } } }
private void submitButton_Click(object sender, EventArgs e) { if (inspector.SelectedEntry != null) { if (inspector.SelectedEntry.IsDirectory) { currentDir = inspector.SelectedEntry.Tag as Project.Dir; inspector.SelectedEntry = null; submitButton.Enabled = false; Populate(); } else { DialogResult = System.Windows.Forms.DialogResult.OK; Dropper.File = inspector.SelectedEntry.Tag as Project.Entry; Close(); } } }
/// <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 }); } }
/// <summary> /// Двойной щелчок по файлу в инспекторе /// </summary> private void projectInspector_MouseDoubleClick(object sender, MouseEventArgs e) { if (e.Button == System.Windows.Forms.MouseButtons.Left) { NSDirectoryInspector.Entry en = projectInspector.SelectedEntry; if (en != null) { if (en.IsDirectory) { Project.Dir dr = en.Tag as Project.Dir; if (dr != null) { PopulateManager(dr); } } else { OpenEditor(en.Tag as Project.Entry); } } } }
/// <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; }
/// <summary> /// Событие, связанное с директорией проекта /// </summary> public static void ProjectDirEvent(Project.Dir d, Project.FileEvent ev) { System.Diagnostics.Debug.WriteLine("Dir " + d.Name + ev.ToString()); }
/// <summary> /// Загрузка метаданных /// </summary> /// <param name="dir"></param> public MetaFile(Project.Dir dir) { Parent = dir; LoadFile(); }
/// <summary> /// Создание копирующего диалога /// </summary> public DirectoryCopyDialog(Project.Dir dir, Project.Dir parent) { InitializeComponent(); copyDir = dir; newParent = parent; }
/// <summary> /// Рекурсивное копирование директории /// </summary> /// <param name="cd">Директория</param> /// <param name="parent">Новый родитель</param> /// <returns>Скопированная директория</returns> Project.Dir RecursiveCopyDir(Project.Dir cd, Project.Dir parent) { // Подбор имени папки string dirName = cd.ShortName; while (Directory.Exists(parent.FullPath + "/" + dirName)) { dirName += " - Copy"; } // Создание папки Directory.CreateDirectory(parent.FullPath + "/" + dirName); // Создание объекта папки Project.Dir d = new Project.Dir(); d.Parent = parent; d.Name = parent != Project.BaseDir ? parent.Name + "/" + dirName : dirName; // Внутренние части List <Project.Dir> dirs = new List <Project.Dir>(); List <Project.Entry> entries = new List <Project.Entry>(); if (!abortCopy) { // Копирование файлов foreach (Project.Entry e in cd.Entries) { // Создание записи currentFileName = e.Name; filesCopied++; Project.Entry ce = new Project.Entry(); ce.Name = e.Name; ce.Parent = d; ce.Meta = e.Meta; entries.Add(ce); // Копирование файла File.Copy(e.FullPath, ce.FullPath); // Выход если отмена if (abortCopy) { break; } } // Копирование папок foreach (Project.Dir dr in cd.Dirs) { dirs.Add(RecursiveCopyDir(dr, d)); // Выход если отмена if (abortCopy) { break; } } } d.Dirs = dirs.ToArray(); d.Entries = entries.ToArray(); // Сохранение папки return(d); }
/// <summary> /// Клик по файлу в инспекторе /// </summary> private void projectInspector_MouseClick(object sender, MouseEventArgs e) { NSDirectoryInspector.Entry en = projectInspector.SelectedEntry; bool free = false; if (en != null) { free = Project.OperableFile(en.Tag); } if (e.Button == System.Windows.Forms.MouseButtons.Right) { NSContextMenu cm = new NSContextMenu(); if (en != null) { // Открытие файла cm.Items.Add(ControlStrings.InspectorContextOpen, ShadowImage.CompiledFromImage(InspectorIcons.MenuOpen, 16, 1), (sndr, args) => { if (en != null) { if (en.IsDirectory) { Project.Dir dr = en.Tag as Project.Dir; if (dr != null) { PopulateManager(dr); } } else { OpenEditor(en.Tag as Project.Entry); } } }); } // Создание файла ToolStripMenuItem crItem = new ToolStripMenuItem(ControlStrings.InspectorContextCreate, ShadowImage.CompiledFromImage(InspectorIcons.MenuAdd, 16, 1)); crItem.DropDown = new NSContextMenu(); AddCreationMenuItems(crItem.DropDown.Items); cm.Items.Add(crItem); // Разделитель cm.Items.Add(new ToolStripSeparator()); if (en != null) { // Смена имени cm.Items.Add(new ToolStripMenuItem(ControlStrings.InspectorContextRename, ShadowImage.CompiledFromImage(InspectorIcons.MenuRename, 16, 1), (sndr, args) => { string[] used; string ext = ""; if (en.IsDirectory) { used = (en.Tag as Project.Dir).UsedNames; } else { used = (en.Tag as Project.Entry).Parent.UsedNames; ext = System.IO.Path.GetExtension((en.Tag as Project.Entry).Name); } RenameItemDialog rd = new RenameItemDialog(en.Name); rd.SpecifiedName = en.Name; rd.Extension = ext; rd.ExistingNames = used; needProjectRescan = false; if (rd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (en.IsDirectory) { Project.RenameItem(en.Tag as Project.Dir, rd.SpecifiedName); } else { Project.RenameItem(en.Tag as Project.Entry, rd.SpecifiedName); } } }) { Enabled = free }); // Копирование cm.Items.Add(new ToolStripMenuItem(ControlStrings.InspectorContextCopy, ShadowImage.CompiledFromImage(InspectorIcons.MenuCopy, 16, 1), (sndr, args) => { if (en != null) { copyingDir = null; copyingEntry = null; if (en.IsDirectory) { copyingDir = en.Tag as Project.Dir; } else { copyingEntry = en.Tag as Project.Entry; } } }) { Enabled = free }); } // Вставка ToolStripMenuItem ps = new ToolStripMenuItem(ControlStrings.InspectorContextPaste, ShadowImage.CompiledFromImage(InspectorIcons.MenuPaste, 16, 1), (sndr, args) => { Project.Dir bd = (Project.Dir)projectInspector.Tag; localFileEvent = true; needProjectRescan = false; if (copyingDir != null) { Project.Dir cd = Project.CopyDir(copyingDir, bd); NSDirectoryInspector.Entry fen = new NSDirectoryInspector.Entry(); fen.IsDirectory = true; fen.Name = cd.ShortName; fen.Tag = (object)cd; projectInspector.Entries.Add(fen); projectInspector.SelectedEntry = fen; } else if (copyingEntry != null) { Project.Entry ce = Project.CopyEntry(copyingEntry, bd); NSDirectoryInspector.Entry fen = new NSDirectoryInspector.Entry(); fen.IsDirectory = false; fen.Name = System.IO.Path.GetFileNameWithoutExtension(ce.Name); fen.Icon = ce.Icon; fen.Tag = (object)ce; projectInspector.Entries.Add(fen); projectInspector.SelectedEntry = fen; } localFileEvent = false; }); ps.Enabled = copyingDir != null || copyingEntry != null; cm.Items.Add(ps); if (en != null) { // Удаление cm.Items.Add(new ToolStripMenuItem(ControlStrings.InspectorContextDelete, ShadowImage.CompiledFromImage(InspectorIcons.MenuDelete, 16, 1), (sndr, args) => { if (en != null) { RemoveEntry(en); } }) { Enabled = free }); } cm.Show(inspectorPopupLocation); } }
/// <summary> /// Клик по файлу в инспекторе /// </summary> private void projectInspector_MouseClick(object sender, MouseEventArgs e) { NSDirectoryInspector.Entry en = projectInspector.SelectedEntry; bool free = false; if (en != null) { free = Project.LegalFile(en.Tag); } if (e.Button == System.Windows.Forms.MouseButtons.Right) { NSContextMenu cm = new NSContextMenu(); if (en != null) { // Открытие файла cm.Items.Add(ControlStrings.InspectorContextOpen, ShadowImage.CompiledFromImage(InspectorIcons.MenuOpen, 16, 1), (sndr, args) => { if (en != null) { if (en.IsDirectory) { Project.Dir dr = en.Tag as Project.Dir; if (dr != null) { PopulateManager(dr); } } else { OpenEditor(en.Tag as Project.Entry); } } }); } // Создание файла ToolStripMenuItem crItem = new ToolStripMenuItem(ControlStrings.InspectorContextCreate, ShadowImage.CompiledFromImage(InspectorIcons.MenuAdd, 16, 1)); crItem.DropDown = new NSContextMenu(); AddCreationMenuItems(crItem.DropDown.Items); cm.Items.Add(crItem); // Разделитель cm.Items.Add(new ToolStripSeparator()); if (en != null) { // Смена имени cm.Items.Add(new ToolStripMenuItem(ControlStrings.InspectorContextRename, ShadowImage.CompiledFromImage(InspectorIcons.MenuRename, 16, 1), (sndr, args) => { }) { Enabled = free }); // Копирование cm.Items.Add(new ToolStripMenuItem(ControlStrings.InspectorContextCopy, ShadowImage.CompiledFromImage(InspectorIcons.MenuCopy, 16, 1), (sndr, args) => { if (en != null) { copyingDir = null; copyingEntry = null; if (en.IsDirectory) { copyingDir = en.Tag as Project.Dir; } else { copyingEntry = en.Tag as Project.Entry; } } }) { Enabled = free }); } // Вставка ToolStripMenuItem ps = new ToolStripMenuItem(ControlStrings.InspectorContextPaste, ShadowImage.CompiledFromImage(InspectorIcons.MenuPaste, 16, 1), (sndr, args) => { }); ps.Enabled = copyingDir != null || copyingEntry != null; cm.Items.Add(ps); if (en != null) { // Удаление cm.Items.Add(new ToolStripMenuItem(ControlStrings.InspectorContextDelete, ShadowImage.CompiledFromImage(InspectorIcons.MenuDelete, 16, 1), (sndr, args) => { if (en.IsDirectory) { if (Project.DeleteDir(en.Tag as Project.Dir)) { projectInspector.SelectedEntry = null; projectInspector.Entries.Remove(en); } } else { if (Project.DeleteEntry(en.Tag as Project.Entry)) { projectInspector.SelectedEntry = null; projectInspector.Entries.Remove(en); } } projectRemove.Enabled = false; }) { Enabled = free }); } cm.Show(inspectorPopupLocation); } }
/// <summary> /// Событие, связанное с директорией проекта /// </summary> public static void ProjectDirEvent(Project.Dir d, Project.FileEvent ev) { System.Diagnostics.Debug.WriteLine("Dir " + d.Name + " " + ev.ToString()); if (W != null) { // Обновление редакторов if (Editors != null) { foreach (BaseForm b in Editors) { needProjectRescan = false; b.FileEditor.ProjectDirEvent(d, ev); } } // Обновление инспектора if (!W.localFileEvent) { Project.Dir cd = W.projectInspector.Tag as Project.Dir; switch (ev) { case Project.FileEvent.Created: if (d.Parent == cd) { W.projectInspector.Entries.Add(new NSDirectoryInspector.Entry() { IsDirectory = true, Tag = (object)d, Name = d.ShortName }); W.projectInspector.Invalidate(); } break; case Project.FileEvent.Modified: case Project.FileEvent.Renamed: if (d.Parent == cd) { object od = (object)d; foreach (NSDirectoryInspector.Entry en in W.projectInspector.Entries) { if (en.Tag == od) { en.Name = d.ShortName; W.projectInspector.Invalidate(); break; } } } break; case Project.FileEvent.Deleted: if (d == cd) { PopulateManager(d.Parent); } else if (d.Parent == cd) { object od = (object)d; foreach (NSDirectoryInspector.Entry en in W.projectInspector.Entries) { if (en.Tag == od) { W.projectInspector.Entries.Remove(en); W.projectInspector.Invalidate(); break; } } } break; } } } }
/// <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; } } } }