/// <summary> /// Begins the process of renaming. /// </summary> private void StartRename(bool useInline, string oldName, string newName) { if (!string.IsNullOrEmpty(newName)) { OnApply(null, oldName, newName); return; } if (useInline) { var sci = PluginBase.MainForm.CurrentDocument.SciControl; int position = sci.WordEndPosition(sci.CurrentPos, true); var inlineRename = new InlineRename(sci, oldName, position, null, null, isRenamePackage ? new bool?() : new bool?(true), Target); inlineRename.Apply += OnApply; inlineRename.Cancel += OnCancel; } else { string title = " " + string.Format(TextHelper.GetString("Title.RenameDialog"), oldName); string label = TextHelper.GetString("Label.NewName"); var dialog = new LineEntryDialog(title, label, oldName); switch (dialog.ShowDialog()) { case DialogResult.OK: OnApply(null, oldName, dialog.Line.Trim()); break; case DialogResult.Cancel: OnCancel(null); break; } } }
public static void AddToQueue(ASResult target, bool outputResults) { string originalName = RefactoringHelper.GetRefactorTargetName(target); string label = TextHelper.GetString("Label.NewName"); string title = string.Format(TextHelper.GetString("Title.RenameDialog"), originalName); LineEntryDialog askName = new LineEntryDialog(title, label, originalName); if (askName.ShowDialog() == DialogResult.OK) { string newName = askName.Line.Trim(); if (newName.Length == 0 || newName == originalName) { return; } queue.Add(new Rename(target, outputResults, newName)); if (ASContext.Context.CurrentModel.haXe && target.Member != null && (target.Member.Flags & (FlagType.Getter | FlagType.Setter)) > 0) { List <MemberModel> list = target.Member.Parameters; if (list[0].Name == "get") { RenameMember(target.InClass, "get_" + originalName, "get_" + newName, outputResults); } if (list[1].Name == "set") { RenameMember(target.InClass, "set_" + originalName, "set_" + newName, outputResults); } } if (currentCommand == null) { ExecuteFirst(); } } }
/// <summary> /// Invoked when the user selects the "Extract Method" command /// </summary> private void ExtractMethodClicked(Object sender, EventArgs e) { try { String newName = "newMethod"; String label = TextHelper.GetString("Label.NewName"); String title = TextHelper.GetString("Title.ExtractMethodDialog"); LineEntryDialog askName = new LineEntryDialog(title, label, newName); var result = askName.ShowDialog(); if (result != DialogResult.OK) { return; } if (askName.Line.Trim().Length > 0 && askName.Line.Trim() != newName) { newName = askName.Line.Trim(); } var command = CommandFactoryProvider.GetFactoryForCurrentDocument().CreateExtractMethodCommand(newName); command.Execute(); } catch (Exception ex) { ErrorManager.ShowError(ex); } }
static string AskForCommit(string message) { if (PluginMain.SCSettings.NeverCommit) { return(null); } var title = TextHelper.GetString("FlashDevelop.Title.ConfirmDialog"); var msg = TextHelper.GetString("Info.CreateCommit"); using (LineEntryDialog led = new LineEntryDialog(title, msg, message)) { var result = led.ShowDialog(); if (result == DialogResult.Cancel) //Never { PluginMain.SCSettings.NeverCommit = true; return(null); } if (result != DialogResult.Yes || led.Line == "") { return(null); } return(led.Line); } }
void Commit_Click(object sender, EventArgs e) { String title = TextHelper.GetString("Label.Commit"); String msg = TextHelper.GetString("Info.EnterMessage"); LineEntryDialog led = new LineEntryDialog(title, msg, ""); if (led.ShowDialog() != DialogResult.OK || led.Line == "") { return; } new CommitCommand(GetPathsArray(), led.Line); }
/// <summary> /// This retrieves the new name from the user /// </summary> private String GetNewName(String originalName) { String label = TextHelper.GetString("Label.NewName"); String title = String.Format(TextHelper.GetString("Title.RenameDialog"), originalName); String suggestion = originalName; LineEntryDialog askName = new LineEntryDialog(title, label, suggestion); DialogResult choice = askName.ShowDialog(); if (choice == DialogResult.OK && askName.Line.Trim().Length > 0 && askName.Line.Trim() != originalName) { return(askName.Line.Trim()); } return(null); }
/// <summary> /// This retrieves the new name from the user /// </summary> private String GetNewName(String originalName) { String label = TextHelper.GetString("Label.NewName"); String title = String.Format(TextHelper.GetString("Title.RenameDialog"), originalName); LineEntryDialog askName = new LineEntryDialog(title, label, originalName); if (askName.ShowDialog() == DialogResult.OK) { string newName = askName.Line.Trim(); if (newName.Length > 0 && newName != originalName) { return(newName); } } return(null); }
void OnGenerateHXMLClick(object sender, EventArgs e) { const string defaultOutput = "build.hxml"; var label = TextHelper.GetString("ProjectManager.Label.FileName"); var dialog = new LineEntryDialog("Generate hxml build file...", label, defaultOutput); if (dialog.ShowDialog() != DialogResult.OK) { return; } var output = dialog.Line.Trim(); if (output.Length == 0) { var project = (HaxeProject)PluginBase.CurrentProject; output = Path.Combine(project.Directory, defaultOutput); } GenerateHXMLBuildFile(output); }
public static void CheckAuthorName() { if (nameAsked) { return; } nameAsked = true; foreach (Argument arg in PluginBase.Settings.CustomArguments) { if (arg.Key == "DefaultUser" && arg.Value == "...") { String caption = TextHelper.GetString("Title.AuthorName"); LineEntryDialog prompt = new LineEntryDialog(caption, "Author", ""); if (prompt.ShowDialog() == DialogResult.OK) { arg.Value = prompt.Line; } } } }
/// <summary> /// This retrieves the new name from the user /// </summary> static string GetNewName() { var newName = "newVar"; var label = TextHelper.GetString("Label.NewName"); var title = TextHelper.GetString("Title.ExtractLocalVariableDialog"); var askName = new LineEntryDialog(title, label, newName); var choice = askName.ShowDialog(); var sci = PluginBase.MainForm.CurrentDocument.SciControl; if (choice != DialogResult.OK) { sci.DisableAllSciEvents = false; return(null); } sci.DisableAllSciEvents = false; var name = askName.Line.Trim(); if (name.Length > 0 && name != newName) { newName = name; } return(newName); }
public void AddXmlFile(string inDirectory) { string caption = "Add Xml File"; string label = "File Name:"; string defaultLine = "New File.xml"; LineEntryDialog dialog = new LineEntryDialog(caption, label, defaultLine); if (dialog.ShowDialog() == DialogResult.OK) { try { string xmlDeclaration = "<?xml version=\"1.0\" ?>"; string path = Path.Combine(inDirectory, dialog.Line); OnFileCreated(path); // MIKA: DETECT EOL AND ENCODING Encoding encoding = this.fdActions.GetDefaultEncoding(); string eolMarker = this.fdActions.GetDefaultEOLMarker(); using (FileStream stream = File.Open(path, FileMode.CreateNew)) { StreamWriter writer = new StreamWriter(stream, encoding); writer.Write(xmlDeclaration + eolMarker); writer.Flush(); } DocumentSeekRequest = xmlDeclaration.Length + eolMarker.Length; OpenFile(path); } catch (Exception exception) { ErrorHandler.ShowInfo("Could not add the file: " + exception.Message); } } }
/// <summary> /// Invoked when the user selects the "Extract Local Variable" command /// </summary> private void ExtractLocalVariableClicked(Object sender, EventArgs e) { try { String suggestion = "newVar"; String label = TextHelper.GetString("Label.NewName"); String title = TextHelper.GetString("Title.ExtractLocalVariableDialog"); LineEntryDialog askName = new LineEntryDialog(title, label, suggestion); DialogResult choice = askName.ShowDialog(); if (choice == DialogResult.OK && askName.Line.Trim().Length > 0 && askName.Line.Trim() != suggestion) { suggestion = askName.Line.Trim(); } if (choice == DialogResult.OK) { ExtractLocalVariableCommand command = new ExtractLocalVariableCommand(suggestion); command.Execute(); } } catch (Exception ex) { ErrorManager.ShowError(ex); } }
public void AddFileFromTemplate(Project project, string inDirectory, string templatePath, bool noName) { try { // the template could be named something like "MXML.fdt", or maybe "Class.as.fdt" string extension = ""; string fileName = Path.GetFileNameWithoutExtension(templatePath); string caption = TextHelper.GetString("Label.AddNew") + " "; if (fileName.IndexOf('.') > -1) { // it's something like Class.as.fdt extension = Path.GetExtension(fileName); // .as if (noName) { caption += extension.Substring(1).ToUpper() + " " + TextHelper.GetString("Label.File"); fileName = TextHelper.GetString("Label.NewFile"); } else { caption += Path.GetFileNameWithoutExtension(fileName); fileName = TextHelper.GetString("Label.New") + Path.GetFileNameWithoutExtension(fileName).Replace(" ", ""); // just Class } } else { // something like MXML.fdt extension = "." + fileName.ToLower(); caption += fileName + " " + TextHelper.GetString("Label.File"); fileName = TextHelper.GetString("Label.NewFile"); } // let plugins handle the file creation Hashtable info = new Hashtable(); info["templatePath"] = templatePath; info["inDirectory"] = inDirectory; DataEvent de = new DataEvent(EventType.Command, "ProjectManager.CreateNewFile", info); EventManager.DispatchEvent(this, de); if (de.Handled) { return; } LineEntryDialog dialog = new LineEntryDialog(caption, TextHelper.GetString("Label.FileName"), fileName + extension); dialog.SelectRange(0, fileName.Length); if (dialog.ShowDialog() == DialogResult.OK) { FlashDevelopActions.CheckAuthorName(); string newFilePath = Path.Combine(inDirectory, dialog.Line); if (!Path.HasExtension(newFilePath) && extension != ".ext") { newFilePath = Path.ChangeExtension(newFilePath, extension); } if (!ConfirmOverwrite(newFilePath)) { return; } // save this so when we are asked to process args, we know what file it's talking about lastFileFromTemplate = newFilePath; mainForm.FileFromTemplate(templatePath, newFilePath); } } catch (UserCancelException) { } catch (Exception exception) { ErrorManager.ShowError(exception); } }
public void Copy(string fromPath, string toPath) { if (CancelAction(ProjectFileActionsEvents.FileCopy, new string[] { fromPath, toPath })) { return; } try { // try to fix toPath if it's a filename if (File.Exists(toPath)) { toPath = Path.GetDirectoryName(toPath); } // avoid recursive copy if (Directory.Exists(fromPath) && toPath.StartsWith(fromPath, StringComparison.OrdinalIgnoreCase)) { throw new IOException(TextHelper.GetString("Info.RecursiveCopyDetected")); } toPath = Path.Combine(toPath, Path.GetFileName(fromPath)); // create copies of a file if (toPath == fromPath) { string copyPath = Path.Combine( Path.GetDirectoryName(toPath), String.Format(TextHelper.GetString("Label.CopyOf"), Path.GetFileNameWithoutExtension(fromPath)) ) + Path.GetExtension(fromPath); int copies = 1; while (File.Exists(copyPath)) { copies++; copyPath = Path.Combine( Path.GetDirectoryName(toPath), String.Format(TextHelper.GetString("Label.CopyOf") + " ({1})", Path.GetFileNameWithoutExtension(fromPath), copies) ) + Path.GetExtension(fromPath); } // offer to choose the new name string label = TextHelper.GetString("Info.NewDuplicateName"); string title = String.Format(TextHelper.GetString("Info.DuplicatingFile"), Path.GetFileName(toPath)); string suggestion = Path.GetFileNameWithoutExtension(copyPath); LineEntryDialog askName = new LineEntryDialog(title, label, suggestion); DialogResult choice = askName.ShowDialog(); if (choice == DialogResult.OK && askName.Line.Trim().Length > 0) { copyPath = Path.Combine(Path.GetDirectoryName(toPath), askName.Line.Trim()) + Path.GetExtension(toPath); } else { throw new UserCancelException(); } toPath = copyPath; } if (!ConfirmOverwrite(toPath)) { return; } OnFileCreated(toPath); if (Directory.Exists(fromPath)) { CopyDirectory(fromPath, toPath); } else { File.Copy(fromPath, toPath, true); } OnFilePasted(fromPath, toPath); } catch (UserCancelException uex) { throw uex; } catch (Exception exception) { ErrorManager.ShowError(exception); } }
public void AddClass(Project project, string inDirectory) { string caption = "Add New Class"; string label = "Class Name:"; string defaultLine = "NewClass"; LineEntryDialog dialog = new LineEntryDialog(caption, label, defaultLine); if (dialog.ShowDialog() == DialogResult.OK) { try { string name = Path.GetFileNameWithoutExtension(dialog.Line); string path = Path.Combine(inDirectory, name + ".as"); OnFileCreated(path); // figure out the best classpath to build from string classpath = project.AbsoluteClasspaths.GetClosestParent(path); // no luck? try the global classpaths! if (classpath == null) { PathCollection globalPaths = new PathCollection(); foreach (string cp in Settings.GlobalClasspaths.Split(';')) { globalPaths.Add(cp); } classpath = globalPaths.GetClosestParent(path); } // still no luck? nothing else we can do if (classpath == null) { throw new Exception("An appropriate project classpath could not be located to create the class from."); } // figure out the full class name cleverly string className = PathHelper.GetRelativePath(classpath, path); className = className.Replace(".as", ""); className = className.Replace(Path.DirectorySeparatorChar, '.'); string constructor = className; int p = className.LastIndexOf('.'); if (p >= 0) { constructor = className.Substring(p + 1); } // MIKA: DETECT EOL AND ENCODING Encoding encoding = this.fdActions.GetDefaultEncoding(); string eolMarker = this.fdActions.GetDefaultEOLMarker(); using (FileStream stream = File.Open(path, FileMode.CreateNew)) { StreamWriter writer = new StreamWriter(stream, encoding); string code = eolMarker; code += "class " + className + eolMarker; code += "{" + eolMarker; code += "\tfunction " + constructor + "()" + eolMarker; code += "\t{" + eolMarker; code += "\t\t"; DocumentSeekRequest = code.Length; code += eolMarker; code += "\t}" + eolMarker; code += "}" + eolMarker; writer.Write(code); writer.Flush(); } OpenFile(path); } catch (Exception exception) { ErrorHandler.ShowInfo("Could not add the class: " + exception.Message); } } }
public void HandleEvent(Object sender, NotifyEvent e, HandlingPriority priority) { TextEvent te = e as TextEvent; DataEvent de = e as DataEvent; switch (e.Type) { case EventType.UIStarted: // for some reason we have to do this on the next message loop for the tree // state to be restored properly. pluginUI.BeginInvoke((MethodInvoker) delegate { BroadcastMenuInfo(); BroadcastToolBarInfo(); OpenLastProject(); }); break; case EventType.FileOpening: // if this is a project file, we can handle it ourselves if (FileInspector.IsProject(te.Value)) { te.Handled = true; OpenProjectSilent(te.Value); } break; case EventType.FileOpen: SetDocumentIcon(MainForm.CurrentDocument); OpenNextFile(); // it's safe to open any other files on the queue break; case EventType.FileSave: TabColors.UpdateTabColors(Settings); break; case EventType.FileSwitch: TabColors.UpdateTabColors(Settings); break; case EventType.ProcessStart: break; case EventType.ProcessEnd: break; case EventType.ApplySettings: TabColors.UpdateTabColors(Settings); break; case EventType.Command: if (de.Action.StartsWith("ProjectManager.")) { if (de.Action == ProjectManagerCommands.NewProject) { NewProject(); e.Handled = true; } else if (de.Action == ProjectManagerCommands.OpenProject) { if (de.Data != null && File.Exists((string)de.Data)) { OpenProjectSilent((string)de.Data); } else { OpenProject(); } e.Handled = true; } else if (de.Action == ProjectManagerCommands.SendProject) { BroadcastProjectInfo(activeProject); e.Handled = true; } else if (de.Action == ProjectManagerCommands.LineEntryDialog) { Hashtable info = (Hashtable)de.Data; LineEntryDialog askName = new LineEntryDialog((string)info["title"], (string)info["label"], (string)info["suggestion"]); DialogResult choice = askName.ShowDialog(); if (choice == DialogResult.OK && askName.Line.Trim().Length > 0 && askName.Line.Trim() != (string)info["suggestion"]) { info["suggestion"] = askName.Line.Trim(); } if (choice == DialogResult.OK) { e.Handled = true; } } } break; case EventType.Keys: e.Handled = HandleKeyEvent(e as KeyEvent); break; } }