public IIDE NewIDE(IVirtualMachine machine, ICodeEditor codeEditor , IInputPort inputPort = null, int withInputPortIndex = -1 , IOutputPort outputPort = null, int withOutputPortIndex = -1 , bool withConsole = false) { if (!IsInitialized) { throw new InvalidOperationException(); } (codeEditor as Form).MdiParent = MainForm as Form; IIDE newIde = new IDE(machine, codeEditor); newIde.ParentWorkplace = this; newIde.ShowingMessage += MainSymbolService.ShowMessage; newIde.AskingUser += MainSymbolService.AskUser; newIde.OpeningFileByUser += MainSymbolService.OpenFileByUser; newIde.SavingFileByUser += MainSymbolService.SaveFileByUser; if (inputPort != null && withInputPortIndex >= -1) { newIde.MachineInsertInputPort(withInputPortIndex, inputPort); } if (outputPort != null && withOutputPortIndex >= -1) { newIde.MachineInsertOutputPort(withOutputPortIndex, outputPort); } if (withConsole && (inputPort != null || outputPort != null)) { IInputDevice newConsoleAsInputDevice; IOutputDevice newConsoleAsOutputDevice = null; if (inputPort != null) { InputDeviceTypeInfo consoleDeviceTypeInfo = InputDeviceBuilder.RegisteredTypes.Find(i => i.TypeFullName == typeof(ConsoleDevice).FullName); if (consoleDeviceTypeInfo != null) { NewInputDevice(consoleDeviceTypeInfo, out newConsoleAsInputDevice); newConsoleAsOutputDevice = newConsoleAsInputDevice as IOutputDevice; newIde.MachineSetInputDevice(inputPort, newConsoleAsInputDevice); } } if (outputPort != null) { if (newConsoleAsOutputDevice != null) { newIde.MachineSetOutputDevice(outputPort, newConsoleAsOutputDevice); } else { OutputDeviceTypeInfo consoleDeviceTypeInfo = OutputDeviceBuilder.RegisteredTypes.Find(i => i.TypeFullName == typeof(ConsoleDevice).FullName); if (consoleDeviceTypeInfo != null) { NewOutputDevice(consoleDeviceTypeInfo, out newConsoleAsOutputDevice); newIde.MachineSetOutputDevice(outputPort, newConsoleAsOutputDevice); } } } } newIde.Machine.Id = MachinesIdCounter++; newIde.Machine.CustomName = newIde.Machine.ToString(); newIde.Id = IdeIdCounter++; newIde.ProgramFile.ShortFileName = GetNewProgramFileShortName(newIde); newIde.Title = GetNewIDEtitle(newIde); newIde.ConfigFile.ShortFileName = newIde.Title; IDEs.Add(newIde); OnGotUpdated(); return(newIde); }
public bool NewInputDevice(InputDeviceTypeInfo inputDeviceTypeInfo, out IInputDevice newInputDevice) { if (inputDeviceTypeInfo == null) { throw new NullReferenceException(); } newInputDevice = inputDeviceTypeInfo != null? InputDeviceBuilder.GetNew(inputDeviceTypeInfo) : null; if (newInputDevice as IFileInputable != null) { var openingFileDialogArgs = new OpenFileByUserEventArgs() { InitialDirectory = (MainForm.SelectedIDE.ProgramFile.FileName.IsNotNullOrEmpty()) ? Path.GetDirectoryName(MainForm.SelectedIDE.ProgramFile.FileName) : (MainForm.SelectedIDE.ParentWorkplace.MainForm.RecentFiles.Count > 2) ? Path.GetDirectoryName(MainForm.SelectedIDE.ParentWorkplace.MainForm.RecentFiles[0]) : Path.GetDirectoryName(Application.ExecutablePath), Filter = "Text Files (*.txt)|*.txt|Binary Files (*.bin)|*.txt|All Files (*.*)|*.*", FilterIndex = 3, RestoreDirectory = true }; OpeningFileByUser?.Invoke(this, openingFileDialogArgs); if (openingFileDialogArgs.Answer == DialogResult.OK) { try { FileInfo fInfo = new FileInfo(openingFileDialogArgs.FileName); if (fInfo.Exists) { (newInputDevice as IFileInputable).FileName = openingFileDialogArgs.FileName; } else { return(false); } } catch (Exception ex) { return(false); } } else { return(false); } } if (newInputDevice != null) { this.InputDevices.Add(newInputDevice); newInputDevice.ParentWorkplace = this; newInputDevice.Id = this.InputDevices.Count - 1; } if (newInputDevice as IOutputDevice != null) { this.OutputDevices.Add(newInputDevice as IOutputDevice); } return(true); }