private void LoadFile(string FileName) { this.ResetViewers(); this.LoadedThings_ = null; if (FileName != null && File.Exists(FileName)) { this.Enabled = false; FileScanner FS = new FileScanner(); FS.ScanFile(this, FileName); this.LoadedThings_ = FS.FileContents; this.LoadedItems_ = new ThingList <Item>(); if (FS.FileContents != null) { int LoadCount = 0; if (FS.FileContents.Count > 0) { this.tabViewers.TabPages.Add(this.tabViewerGeneral); this.tabViewers.Visible = true; Application.DoEvents(); foreach (IThing T in FS.FileContents) { ListView LV = this.MaybeAddListView(T.TypeName); int IconIndex = -1; { Image Icon = T.GetIcon(); if (Icon != null) { IconIndex = this.ListIcons_.Images.Count; this.ListIcons_.Images.Add(Icon); } } ListViewItem LVI = LV.Items.Add(T.TypeName, IconIndex); LVI.Tag = T; for (int i = 1; i < LV.Columns.Count; ++i) { LVI.SubItems.Add(""); } foreach (string Field in T.GetFields()) { if (!LV.Columns.ContainsKey(Field)) { LV.Columns.Add(Field, T.GetFieldName(Field), 60, HorizontalAlignment.Left, -1); LVI.SubItems.Add(""); } LVI.SubItems[LV.Columns[Field].Index].Text = T.GetFieldText(Field); } if (T is Item) { if (this.cmbItems.Items.Count == 0) { this.tabViewers.TabPages.Add(this.tabViewerItems); } this.cmbItems.Items.Add(T); this.LoadedItems_.Add(T as Item); } else if (T is Graphic) { if (this.cmbImageChooser.Items.Count == 0) { this.tabViewers.TabPages.Add(this.tabViewerImages); } this.cmbImageChooser.Items.Add(T); } if ((++LoadCount % 100) == 0) { Application.DoEvents(); } } this.btnThingListSaveImages.Enabled = (this.ListIcons_.Images.Count != 0); this.chkShowIcons.Enabled = (this.ListIcons_.Images.Count != 0); Application.DoEvents(); foreach (ListView LV in this.ListViews_.Values) { if (this.ListIcons_.Images.Count == 0) { LV.SmallImageList = null; } LV.HeaderStyle = ColumnHeaderStyle.Clickable; } this.ResizeListColumns(); } if (this.cmbImageChooser.Items.Count > 0) { this.cmbImageChooser.SelectedItem = null; this.tabViewers.SelectedTab = this.tabViewerImages; this.cmbImageChooser.Select(); this.cmbImageChooser.SelectedIndex = 0; Application.DoEvents(); } if (this.cmbItems.Items.Count > 0) { this.cmbItems.SelectedItem = null; this.tabViewers.SelectedTab = this.tabViewerItems; this.cmbItems.Select(); this.cmbItems.SelectedIndex = 0; Application.DoEvents(); } } if (!this.tabViewers.Visible) { this.pnlNoViewers.Visible = true; } this.Enabled = true; } }
private void LoadFile(string FileName) { this.ResetViewers(); this.LoadedThings_ = null; if (FileName != null && File.Exists(FileName)) { this.Enabled = false; FileScanner FS = new FileScanner(); FS.ScanFile(this, FileName); this.LoadedThings_ = FS.FileContents; this.LoadedItems_ = new ThingList<Item>(); if (FS.FileContents != null) { int LoadCount = 0; if (FS.FileContents.Count > 0) { this.tabViewers.TabPages.Add(this.tabViewerGeneral); this.tabViewers.Visible = true; Application.DoEvents(); foreach (IThing T in FS.FileContents) { ListView LV = this.MaybeAddListView(T.TypeName); int IconIndex = -1; { Image Icon = T.GetIcon(); if (Icon != null) { IconIndex = this.ListIcons_.Images.Count; this.ListIcons_.Images.Add(Icon); } } ListViewItem LVI = LV.Items.Add(T.TypeName, IconIndex); LVI.Tag = T; for (int i = 1; i < LV.Columns.Count; ++i) LVI.SubItems.Add(""); foreach (string Field in T.GetFields()) { if (!LV.Columns.ContainsKey(Field)) { LV.Columns.Add(Field, T.GetFieldName(Field), 60, HorizontalAlignment.Left, -1); LVI.SubItems.Add(""); } LVI.SubItems[LV.Columns[Field].Index].Text = T.GetFieldText(Field); } if (T is Item) { if (this.cmbItems.Items.Count == 0) this.tabViewers.TabPages.Add(this.tabViewerItems); this.cmbItems.Items.Add(T); this.LoadedItems_.Add(T as Item); } else if (T is Graphic) { if (this.cmbImageChooser.Items.Count == 0) this.tabViewers.TabPages.Add(this.tabViewerImages); this.cmbImageChooser.Items.Add(T); } if ((++LoadCount % 100) == 0) Application.DoEvents(); } this.btnThingListSaveImages.Enabled = (this.ListIcons_.Images.Count != 0); this.chkShowIcons.Enabled = (this.ListIcons_.Images.Count != 0); Application.DoEvents(); foreach (ListView LV in this.ListViews_.Values) { if (this.ListIcons_.Images.Count == 0) LV.SmallImageList = null; LV.HeaderStyle = ColumnHeaderStyle.Clickable; } this.ResizeListColumns(); } if (this.cmbImageChooser.Items.Count > 0) { this.cmbImageChooser.SelectedItem = null; this.tabViewers.SelectedTab = this.tabViewerImages; this.cmbImageChooser.Select(); this.cmbImageChooser.SelectedIndex = 0; Application.DoEvents(); } if (this.cmbItems.Items.Count > 0) { this.cmbItems.SelectedItem = null; this.tabViewers.SelectedTab = this.tabViewerItems; this.cmbItems.Select(); this.cmbItems.SelectedIndex = 0; Application.DoEvents(); } } if (!this.tabViewers.Visible) this.pnlNoViewers.Visible = true; this.Enabled = true; } }