private void RefreshCommandEnabled() { FileSaveCommand.RefreshEnabled(); FileSaveAsCommand.RefreshEnabled(); EditCutCommand.RefreshEnabled(); EditCopyCommand.RefreshEnabled(); EditPasteCommand.RefreshEnabled(); EditDeleteCommand.RefreshEnabled(); }
private void InitializeCommands() { FileNewCircuitCommand = new FileNewCircuitCommand(this); BindMenuItem(newToolStripMenuItem, FileNewCircuitCommand); FileOpenCircuitCommand = new FileOpenCircuitCommand(this); BindMenuItem(openToolStripMenuItem, FileOpenCircuitCommand); FileSaveCommand = new FileSaveCommand(this); BindMenuItem(saveToolStripMenuItem, FileSaveCommand); FileSaveAsCommand = new FileSaveAsCommand(this); BindMenuItem(saveAsToolStripMenuItem, FileSaveAsCommand); FileExitCommand = new FileExitCommand(); BindMenuItem(exitToolStripMenuItem, FileExitCommand); EditCutCommand = new EditCutCommand(this); BindMenuItem(cutToolStripMenuItem, EditCutCommand); EditCopyCommand = new EditCopyCommand(this); BindMenuItem(copyToolStripMenuItem, EditCopyCommand); EditPasteCommand = new EditPasteCommand(this); BindMenuItem(pasteToolStripMenuItem, EditPasteCommand); EditDeleteCommand = new EditDeleteCommand(this); BindMenuItem(deleteToolStripMenuItem, EditDeleteCommand); ToolsOptionsCommand = new ToolsOptionsCommand(this); BindMenuItem(optionsToolStripMenuItem, ToolsOptionsCommand); HelpAboutCommand = new HelpAboutCommand(this); BindMenuItem(aboutToolStripMenuItem, HelpAboutCommand); MdiChildActivate += (sender, args) => RefreshCommandEnabled(); }
private void DoFileSaveCommand(object parameter) { // There must be a shader. if (CurrentShader == null) { throw new ArgumentException("There is no current shader to save."); } // If there is no path, just use Save As. if (string.IsNullOrEmpty(CurrentShader.Path)) { // Call Save As. FileSaveAsCommand.DoExecute(null); // We're done here. return; } // Save the file. try { // Open the file stream. using (FileStream stream = new FileStream(parameter as string, FileMode.Create)) { // Create a writer and write the source. TextWriter writer = new StreamWriter(stream); writer.Write(CurrentShader.Source); writer.Flush(); stream.Flush(); } } catch (Exception e) { // Re-throw the exception. throw new ApplicationException("Failed to save the shader.", e); } }