private void addAsset_Click(object sender, EventArgs e) { ToolStripMenuItem item = sender as ToolStripMenuItem; if (item == null || !(item.Tag is string)) return; MainForm mainForm = FindForm() as MainForm; if (mainForm == null || mainForm.ProjectModel == null) return; string assetPath = Path.Combine(mainForm.ProjectModel.WorkingDirectory, "assets"); string name = item.Tag as string; if (name == "Import") { string filter = "All known files|"; for (int i = 1; i < ASSET_TYPES.Length; ++i) filter += ASSET_FILTERS[i] + (i < ASSET_TYPES.Length - 1 ? ";" : ""); for (int i = 1; i < ASSET_TYPES.Length; ++i) filter += "|" + ASSET_TYPES[i] + "|" + ASSET_FILTERS[i]; OpenFileDialog dialog = new OpenFileDialog(); dialog.CheckPathExists = true; dialog.RestoreDirectory = true; dialog.Filter = filter; dialog.Multiselect = true; DialogResult result = dialog.ShowDialog(); if (result == DialogResult.OK && dialog.FileNames != null) { foreach (var fname in dialog.FileNames) { string dstFname = Path.Combine(m_viewPath, Path.GetFileName(fname)); if (fname == dstFname) continue; if (File.Exists(dstFname) && MetroMessageBox.Show(mainForm, dstFname + "\nDo you want to overwrite it?", "File already exists!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes) continue; File.Copy(fname, dstFname, true); } if (dialog.FileNames.Length == 1) m_owner.ShowAssetProperties(Utils.GetRelativePath(dialog.FileNames[0], assetPath + Path.DirectorySeparatorChar)); RefreshContent(); } } else { int idx = Array.IndexOf<string>(ASSET_TYPES, name); if (idx >= 0) { string ext = CREATE_ASSET_EXTENSIONS[idx]; if (!String.IsNullOrEmpty(ext)) { MetroPromptBox prompt = new MetroPromptBox(); prompt.Title = "Create asset"; prompt.Message = "File name:"; prompt.Value = name; DialogResult result = prompt.ShowDialog(); if (result == DialogResult.OK) { string path = Path.Combine(m_viewPath, prompt.Value + "." + ext); if (!File.Exists(path) || MetroMessageBox.Show(mainForm, path + "\nDo you want to overwrite it?", "File already exists!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { Directory.CreateDirectory(Path.GetDirectoryName(path)); using (File.AppendText(path)) { } RefreshContent(); m_owner.ShowAssetProperties(Utils.GetRelativePath(path, assetPath + Path.DirectorySeparatorChar)); } } } } } }
private void menuItem_rename_Click(object sender, EventArgs e) { ToolStripMenuItem menuItem = sender as ToolStripMenuItem; if (menuItem == null || !(menuItem.Tag is string)) return; string path = menuItem.Tag as string; if (Directory.Exists(path)) { DirectoryInfo info = new DirectoryInfo(path); if (!info.Exists) return; MetroPromptBox dialog = new MetroPromptBox(); dialog.Title = "Rename Directory"; dialog.Message = "Type new directory name:"; dialog.Value = info.Name; DialogResult result = dialog.ShowDialog(); if (result == DialogResult.OK) info.MoveTo(info.Parent.FullName + @"\" + dialog.Value); } else if (File.Exists(path)) { FileInfo info = new FileInfo(path); if (!info.Exists) return; MetroPromptBox dialog = new MetroPromptBox(); dialog.Title = "Rename File"; dialog.Message = "Type new file name:"; dialog.Value = info.Name; DialogResult result = dialog.ShowDialog(); if (result == DialogResult.OK) info.MoveTo(info.Directory.FullName + @"\" + dialog.Value); } RefreshContent(); }
private void m_generalNewProjectTile_Click(object sender, EventArgs e) { FolderBrowserDialog dialog = new FolderBrowserDialog(); dialog.ShowNewFolderButton = true; DialogResult result = dialog.ShowDialog(); if (result == DialogResult.OK) { MetroPromptBox prompt = new MetroPromptBox(); prompt.Title = "Enter project name:"; prompt.Value = "Project"; result = prompt.ShowDialog(); if (result == DialogResult.OK) CreateNewProject(dialog.SelectedPath, prompt.Value); } }