public WizardForm(PackForm parent) { InitializeComponent(); _parent = parent; gdItems.DataSource = _items; PopulateCombos(); foreach (string type in Pack.SpawnItemConfig.AttachmentTypes.Keys) { for (int i = 0; i < PackForm.MaxAttachmentsForType; i++) { var gc = gvItems.Columns.Add(); gc.Name = String.Format("{0}{1}{2}", PackForm.AttachmentColNamePrefix, type, i); gc.FieldName = gc.Name; gc.Caption = type; gc.UnboundType = UnboundColumnType.String; gc.Width = 30; gc.Visible = true; _attachTypeColMap.Add(gc, type); } } // instant commit (will be detached automatically when form closes) foreach (var cmb in _parent.AttachmentEditorsByType.Values) { GridUtility.ConfigureInstantCommit(gvItems, cmb); } }
private void OpenPack(string fileName, bool isShowDialog) { string formCaption = null; if (isShowDialog) { openPackDialog.InitialDirectory = _lastDirectory; if (openPackDialog.ShowDialog() != DialogResult.OK) { return; } fileName = openPackDialog.FileName; AddRecentPack(fileName); _lastDirectory = Path.GetDirectoryName(openPackDialog.FileName); } else if (!fileName.IsNullOrWhiteSpace()) { if (!File.Exists(fileName)) { return; } var frmOpened = MdiChildren.FirstOrDefault(frm => frm.Text == fileName); if (frmOpened != null) { frmOpened.Activate(); if (DialogUtility.ShowConfirm(true, "File is already opened, do you want to reopen it?") == DialogResult.Yes) { frmOpened.Close(); // проверяем, закрылось ли (могли предложить сохранить и закрытия не произошло) if (MdiChildren.Contains(frmOpened)) { return; } } else { return; } } } else { int index = MdiChildren.Length; do { formCaption = String.Format("Noname{0}", ++index); } while (MdiChildren.Any(frm => frm.Text == formCaption)); } try { var packForm = new PackForm(_levelTemplatePath, fileName); packForm.MdiParent = this; packForm.Activated += packForm_Activated; packForm.FormClosing += packForm_FormClosing; packForm.Disposed += packForm_Disposed; if (formCaption != null) { packForm.Text = formCaption; } packForm.Show(); UpdateFormState(); } catch (Exception ex) { DialogUtility.ShowError("Error while opening pack: {0}", ex.Message); } }
private void OpenPack(string fileName, bool isShowDialog) { string formCaption = null; if (isShowDialog) { openPackDialog.InitialDirectory = _lastDirectory; if (openPackDialog.ShowDialog() != DialogResult.OK) return; fileName = openPackDialog.FileName; AddRecentPack(fileName); _lastDirectory = Path.GetDirectoryName(openPackDialog.FileName); } else if (!fileName.IsNullOrWhiteSpace()) { if (!File.Exists(fileName)) return; var frmOpened = MdiChildren.FirstOrDefault(frm => frm.Text == fileName); if (frmOpened != null) { frmOpened.Activate(); if (DialogUtility.ShowConfirm(true, "File is already opened, do you want to reopen it?") == DialogResult.Yes) { frmOpened.Close(); // проверяем, закрылось ли (могли предложить сохранить и закрытия не произошло) if (MdiChildren.Contains(frmOpened)) return; } else { return; } } } else { int index = MdiChildren.Length; do { formCaption = String.Format("Noname{0}", ++index); } while (MdiChildren.Any(frm => frm.Text == formCaption)); } try { var packForm = new PackForm(_levelTemplatePath, fileName); packForm.MdiParent = this; packForm.Activated += packForm_Activated; packForm.FormClosing += packForm_FormClosing; packForm.Disposed += packForm_Disposed; if (formCaption != null) packForm.Text = formCaption; packForm.Show(); UpdateFormState(); } catch (Exception ex) { DialogUtility.ShowError("Error while opening pack: {0}", ex.Message); } }