/// <summary> /// Deletes a row in accord with <c><see cref="Undo()">Undo()</see></c> /// or <c><see cref="Redo()">Redo()</see></c>. /// </summary> void DeleteRow() { //logfile.Log("UndoRedo.DeleteRow()"); int r = _it.r._id; _grid.Delete(r); _grid.ClearSelects(); if (r >= _grid.RowCount) { r = _grid.RowCount - 1; } _grid.EnsureDisplayedRow(r); _grid._f.EnableRoweditOperations(); int invalid = YataGrid.INVALID_GRID | YataGrid.INVALID_FROZ | YataGrid.INVALID_ROWS; if (_grid.Propanel != null && _grid.Propanel.Visible) { invalid |= YataGrid.INVALID_PROP; } _grid.Invalidator(invalid); if (Settings._autorder && Yata.order() != 0) { _grid._f.layout(); } }
/// <summary> /// Deletes an array of rows in accord with /// <c><see cref="Undo()">Undo()</see></c> or /// <c><see cref="Redo()">Redo()</see></c>. /// </summary> void DeleteArray() { //logfile.Log("UndoRedo.DeleteArray()"); _grid._f.Obfuscate(); DrawRegulator.SuspendDrawing(_grid); for (int a = _it.array.Length - 1; a != -1; --a) // reverse delete. { _grid.Delete(_it.array[a]._id, false); } _grid.Calibrate(); _grid.ClearSelects(); int r = _it.array[0]._id; if (r >= _grid.RowCount) { r = _grid.RowCount - 1; } _grid.EnsureDisplayedRow(r); _grid._f.EnableRoweditOperations(); DrawRegulator.ResumeDrawing(_grid); _grid._f.Obfuscate(false); if (Settings._autorder && Yata.order() != 0) { _grid._f.layout(); } }
/// <summary> /// cTor. /// </summary> /// <param name="cell"></param> /// <param name="f"></param> /// <remarks>Check that the <c><see cref="Cell.text">Cell.text</see></c> /// of <paramref name="cell"/> parses to a valid value before invoking /// this <c>TalkDialog</c>.</remarks> internal TalkDialog(Cell cell, Yata f) { _f = f; InitializeComponent(); Initialize(YataDialog.METRIC_LOC); string strref = cell.text; if (strref == gs.Stars) { strref = "0"; } Text = " tlk - " + strref; _eId_init = Int32.Parse(strref, CultureInfo.InvariantCulture); if (_eId_init == TalkReader.invalid || (_eId_init & TalkReader.bitCusto) == 0) { _dict = TalkReader.DictDialo; lo = TalkReader.loDialo; hi = TalkReader.hiDialo; } else { _dict = TalkReader.DictCusto; lo = TalkReader.loCusto; hi = TalkReader.hiCusto; _init = true; cb_Custo.Checked = true; _init = false; } if (_eId_init != TalkReader.invalid) { _eId_init &= TalkReader.strref; } tb_Strref.Text = _eId_init.ToString(CultureInfo.InvariantCulture); // <- sets '_eId' and 'rt_Copyable.Text' if (TalkReader.AltLabel != null) { cb_Custo.Text = TalkReader.AltLabel; } if ((bu_Accept.Enabled = !Yata.Table.Readonly)) { bu_Accept.Select(); } else { bu_Cancel.Select(); } }
const int _padHoriSort = 12; // additional horizontal text padding to the right in the colheads for the sort-arrow #endregion Fields (static) #region Methods (static) /// <summary> /// Sets standard <c><see cref="HeightColhead"/></c>, /// <c><see cref="HeightRow"/></c>, and minimum cell-width /// <c><see cref="_wId"/></c>. Also caches width of "****" in /// <c><see cref="_wStars"/></c>. /// </summary> /// <param name="f"></param> /// <remarks>These values are the same for all loaded tables.</remarks> internal static void SetStaticMetrics(Yata f) { HeightColhead = YataGraphics.MeasureHeight(YataGraphics.HEIGHT_TEST, f.FontAccent) + _padVert * 2; HeightRow = YataGraphics.MeasureHeight(YataGraphics.HEIGHT_TEST, f.Font) + _padVert * 2; _wId = YataGraphics.MeasureWidth(gs.Id, f.Font) + _padHoriRowhead * 2; _wStars = YataGraphics.MeasureWidth(gs.Stars, f.Font); }
/// <summary> /// cTor. /// </summary> /// <param name="title">a caption on the titlebar</param> /// <param name="label">info to be displayed with a proportional font</param> /// <param name="copyable">info to be displayed with a fixed font in a /// RichTextBox so it can be copied</param> /// <param name="f">parent <c><see cref="Yata"/></c></param> /// <param name="color"></param> /// <param name="goto"></param> /// <param name="reset"></param> internal DifferDialog( string title, string label, string copyable, Yata f, Color color, bool @goto, bool reset) { _f = f; InitializeComponent(); Initialize(YataDialog.METRIC_LOC, true); Text = title; bu_Goto.Visible = @goto; bu_Reset.Visible = reset; la_Info.ForeColor = color; la_Info.Height = YataGraphics.MeasureHeight(label, Font) + 15; // +15 = label's pad top+bot +5 la_Info.Text = label; int w; if (!String.IsNullOrEmpty(copyable)) { copyable += Environment.NewLine; // add a blank line to bot of the copyable text. w = GetWidth(copyable) + 30; // +30 = parent panel's pad left+right +5 pa_Copyable.Height = GetHeight(copyable) + 20; // +20 = parent panel's pad top+bot +5 rt_Copyable.Text = copyable; } else { pa_Copyable.Visible = false; pa_Copyable.Height = w = 0; } if (w < WIDTH_Min) { w = WIDTH_Min; } ClientSize = new Size(w + 20, // +20 = pad real and imagined. la_Info.Height + pa_Copyable.Height + bu_Okay.Height); MinimumSize = new Size(Width, Height); Show(_f); // Yata is owner. }
/// <summary> /// Inserts an array of rows in accord with /// <c><see cref="Undo()">Undo()</see></c> or /// <c><see cref="Redo()">Redo()</see></c>. /// </summary> void InsertArray() { //logfile.Log("UndoRedo.InsertArray()"); _grid._f.Obfuscate(); DrawRegulator.SuspendDrawing(_grid); int cols = _it.array[0].Length; var fields = new string[cols]; Row row; for (int a = 0; a != _it.array.Length; ++a) { row = _it.array[a]; for (int c = 0; c != cols; ++c) { fields[c] = String.Copy(row[c].text); } _grid.Insert(row._id, fields, false, row._brush); for (int c = 0; c != row.Length; ++c) { _grid[row._id, c].loadchanged = row[c].loadchanged; } } _grid.Calibrate(0, _grid.RowCount - 1); _grid.ClearSelects(false, true); int r = _it.array[0]._id; _grid.Rows[r].selected = true; // _grid.RangeSelect = _it.array.Length - 1; // that's problematic ... wrt/ re-Sorted cols // and since only 1 row shall ever be selected you can't just select them all either. _grid.EnsureDisplayedRow(r); // TODO: EnsureDisplayedRows() // NOTE: Does not select the row's cells. DrawRegulator.ResumeDrawing(_grid); _grid._f.Obfuscate(false); if (Settings._autorder && Yata.order() != 0) { _grid._f.layout(); } }
/// <summary> /// cTor. /// </summary> /// <param name="f"><c><see cref="Yata"/></c></param> internal InputCelltextDialog(Yata f) { _f = f; InitializeComponent(); Initialize(YataDialog.METRIC_FUL); la_Head.Text = HEAD; tb_Input.Text = (_f as Yata)._copytext[0, 0]; MinimumSize = new Size(w_Min, Height); MaximumSize = new Size(Int32.MaxValue, Height); tb_Input.Select(); }
/// <summary> /// cTor. /// </summary> /// <param name="f">parent <c><see cref="Yata"/></c></param> /// <param name="selc">the currently selected col-id; default -2 enables /// defaultval input</param> internal InputDialog(Yata f, int selc = DEFVAL) { _f = f; _selc = selc; InitializeComponent(); Initialize(YataDialog.METRIC_FUL); if (_selc != DEFVAL) { Text = " yata - Colhead text"; tb_Input.Text = _colabel; if (Settings._strict) // show 'allow extended punctuation' toggle -> { cb_Punctuation = new CheckBox(); cb_Punctuation.Text = "accept nonstandard punctuation"; cb_Punctuation.TextAlign = ContentAlignment.MiddleLeft; cb_Punctuation.Padding = new Padding(9, 2, 0, 0); cb_Punctuation.Size = new Size(100, hCheckbox); cb_Punctuation.Dock = DockStyle.Top; cb_Punctuation.TabIndex = 1; cb_Punctuation.Checked = true; cb_Punctuation.CheckedChanged += checkedchanged_Punctuation; Controls.Add(cb_Punctuation); cb_Punctuation.BringToFront(); ClientSize = new Size(ClientSize.Width, ClientSize.Height + hCheckbox); cb_Punctuation.Checked = false; // call checkedchanged_Punctuation() at start. } } else { Text = " yata - Default value"; tb_Input.Text = _defaultval; } MinimumSize = new Size(MIN_w, Height); MaximumSize = new Size(Int32.MaxValue, Height); tb_Input.Select(); }
/// <summary> /// Calculates and maintains rowhead width wrt/ current Font across all /// tabs/tables. /// </summary> /// <param name="f"></param> internal static void metricStaticHeads(Yata f) { YataGrid table; int rows = 0, rowsTest; // row-headers' width stays uniform across all tabpages int tabs = f.Tabs.TabCount; int tab = 0; for (; tab != tabs; ++tab) // find the table w/ most rows -> { table = f.Tabs.TabPages[tab].Tag as YataGrid; if ((rowsTest = table.RowCount - 1) > rows) { rows = rowsTest; } } string texttest = "9"; // determine how many nines need to be measured -> while ((rows /= 10) != 0) { texttest += "9"; } WidthRowhead = YataGraphics.MeasureWidth(texttest, f.FontAccent) + _padHoriRowhead * 2; for (tab = 0; tab != tabs; ++tab) { table = f.Tabs.TabPages[tab].Tag as YataGrid; table.WidthTable = WidthRowhead; foreach (var col in table.Cols) { table.WidthTable += col.width(); } table._panelRows.Width = WidthRowhead; table._panelCols.Height = HeightColhead; metricFrozenLabels(table); } }
/// <summary> /// Clones a specified <c>Font</c> and reduces it in size (if necessary) /// to fit in dialogs. /// </summary> /// <param name="font">a <c>Font</c> to potentially reduce in size</param> /// <returns>a <c>Font</c> that's roughly the size of Yata's default /// <c>Font</c></returns> internal static Font CreateDialogFont(ICloneable font) { var fontdialog = font.Clone() as Font; string label = fontdialog.Name; FontStyle style = Yata.getStyleStandard(fontdialog.FontFamily); // the font as it appears in a dialog is smaller than the same font // with the SAME pointsize as it appears on the table ... float pts = fontdialog.SizeInPoints; while (YataGraphics.MeasureHeight(YataGraphics.HEIGHT_TEST, fontdialog) > YataGraphics.hFontDefault) { fontdialog.Dispose(); fontdialog = new Font(label, pts -= 0.75F, style); } return(fontdialog); }
/// <summary> /// Inserts a row in accord with <c><see cref="Undo()">Undo()</see></c> /// or <c><see cref="Redo()">Redo()</see></c>. /// </summary> void InsertRow() { //logfile.Log("UndoRedo.InsertRow()"); Row row = _it.r; var fields = new string[row.Length]; for (int c = 0; c != row.Length; ++c) { fields[c] = String.Copy(row[c].text); } int r = row._id; _grid.Insert(r, fields, true, row._brush); for (int c = 0; c != row.Length; ++c) { _grid[r, c].loadchanged = row[c].loadchanged; } _grid.ClearSelects(false, true); _grid.Rows[r].selected = true; _grid.EnsureDisplayedRow(r); int invalid = YataGrid.INVALID_GRID | YataGrid.INVALID_FROZ | YataGrid.INVALID_ROWS; if (_grid.Propanel != null && _grid.Propanel.Visible) { invalid |= YataGrid.INVALID_PROP; } _grid.Invalidator(invalid); if (Settings._autorder && Yata.order() != 0) { _grid._f.layout(); } }
/// <summary> /// A dialog for the user to input <c>Classes.2da</c> info. /// </summary> /// <param name="f"></param> /// <param name="cell"></param> internal InfoInputClasses(Yata f, Cell cell) { _f = f; // don't try to pass these to a InfoInputDialog.cTor _cell = cell; // because the designer will scream blue murder. InitializeComponent(); // NOTE: Don't bother inheriting from YataDialog since setting the // font is the only benefit -> if (Settings._font2dialog != null) { Font = Settings._font2dialog; } else { Font = Settings._fontdialog; } init(); }
/// <summary> /// About dialog. /// </summary> /// <param name="f">parent</param> internal About(Yata f) { _f = f; InitializeComponent(); Initialize(YataDialog.METRIC_LOC); AssemblyName an = Assembly.GetExecutingAssembly().GetName(); string ver = "Ver " + an.Version.Major + "." + an.Version.Minor + "." + an.Version.Build + "." + an.Version.Revision; #if DEBUG ver += " - debug"; #else ver += " - release"; #endif DateTime dt = Assembly.GetExecutingAssembly().GetLinkerTime(true); ver += Environment.NewLine + Environment.NewLine + String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:yyyy MMM d} {0:HH}:{0:mm}:{0:ss} UTC", // {0:zzz} dt); ver += Environment.NewLine + Environment.NewLine + "This is a derivative work of the guy who invented the wheel and" + " that bloke who made the notches on a 40,000 year old piece of" + " petrified wood that are thought to be the beginnings of" + " mathematics. But I'd guess their copyrights are out of date."; ver += Environment.NewLine + Environment.NewLine + "Executive Producer: Arnie the stuffed armadillo"; la_Text.Text = ver; bu_Close.Select(); }
/// <summary> /// cTor. Instantiates Yata's clipboard dialog. /// </summary> internal ClipboardEditor(Yata f) { _f = f; InitializeComponent(); Initialize(YataDialog.METRIC_FUL); switch (_current) { case Current.Clipboard: rb_Clipboard.Checked = true; break; case Current.RowsBuffer: rb_RowsBuffer.Checked = true; break; case Current.ColBuffer: rb_ColBuffer.Checked = true; break; case Current.CellsBuffer: rb_CellsBuffer.Checked = true; break; } bu_Begone.Select(); Show(_f); // Yata is owner. _inited = true; }
/// <summary> /// The editor for Settings.Cfg. /// </summary> /// <param name="f">pointer to <c><see cref="Yata"/></c></param> /// <param name="lines">array of <c>strings</c> in user's current /// settings file</param> internal SettingsEditor(Yata f, string[] lines) { _f = f; InitializeComponent(); Initialize(YataDialog.METRIC_FUL); if (lines.Length != 0) { var sb = new StringBuilder(); for (int i = 0; i != lines.Length; ++i) { sb.AppendLine(lines[i].Trim()); } rtb_Settings.Text = sb.ToString(); } bu_Insert.Visible = CheckInsertVisible(); rtb_Settings.Select(); Show(_f); // Yata is owner. }
/// <summary> /// Overwrites a row in accord with /// <c><see cref="Undo()">Undo()</see></c> or /// <c><see cref="Redo()">Redo()</see></c>. /// </summary> void Overwrite() { //logfile.Log("UndoRedo.Overwrite()"); Row row = _it.r; int r = row._id; _grid.Rows[r] = row.Clone() as Row; _grid.Calibrate(r); _grid.ClearSelects(false, true); _grid.Rows[r].selected = true; _grid.EnsureDisplayedRow(r); _grid.Invalidator(YataGrid.INVALID_GRID | YataGrid.INVALID_ROWS); if (Settings._autorder && Yata.order() != 0) { _grid._f.layout(); } }
/// <summary> /// cTor. /// </summary> internal CodePageDialog(Yata f, Encoding enc) { _f = f; InitializeComponent(); Initialize(YataDialog.METRIC_FUL); string head = "The 2da file appears to have ANSI encoding." + " Please enter the codepage of its text."; if (enc == null) { head += Environment.NewLine + Environment.NewLine + "The #codepage in Settings.Cfg is invalid."; enc = Encoding.GetEncoding(0); } la_Head.Text = head; _pre = enc.CodePage; tb_Codepage.Text = enc.CodePage.ToString(CultureInfo.InvariantCulture); bu_Accept.Select(); }
/// <summary> /// Assigns <c><see cref="Yata"/></c> to <c><see cref="_f"/></c>. /// </summary> /// <param name="f"></param> /// <remarks>I'm doing it this way so that this <c>YataStrip</c> can be /// instantiated and built in <c>Yata's</c> designer, rather than /// passing <paramref name="f"/> into the cTor. /// /// /// Cheers. Welcome to winforms workaround #2368.</remarks> internal void setYata(Yata f) { _f = f; }
/// <summary> /// Handles a click on the Load ... button. /// </summary> /// <param name="sender"><c><see cref="bu_Load"/></c></param> /// <param name="e"></param> void click_btnLoad(object sender, EventArgs e) { if (!cb_Custo.Checked) { using (var ofd = new OpenFileDialog()) { ofd.Title = " Select Dialog.Tlk"; ofd.Filter = Yata.GetTlkFilter(); ofd.FileName = "dialog.tlk"; ofd.AutoUpgradeEnabled = false; if (ofd.ShowDialog() == DialogResult.OK) { TalkReader.Load(ofd.FileName, (_f as Yata).it_PathTalkD); } } lo = TalkReader.loDialo; hi = TalkReader.hiDialo; } else { using (var ofd = new OpenFileDialog()) { ofd.Title = " Select a TalkTable"; ofd.Filter = Yata.GetTlkFilter(); ofd.FileName = "*.tlk"; ofd.AutoUpgradeEnabled = false; if (ofd.ShowDialog() == DialogResult.OK) { TalkReader.Load(ofd.FileName, (_f as Yata).it_PathTalkC, true); } } lo = TalkReader.loCusto; hi = TalkReader.hiCusto; } enable(); if (_dict.ContainsKey(_eId)) { rt_Copyable.Text = _dict[_eId]; } else { rt_Copyable.Text = String.Empty; } if (TalkReader.AltLabel != null) { cb_Custo.Text = TalkReader.AltLabel; } else { cb_Custo.Text = "Custom"; } }
/// <summary> /// cTor. /// </summary> /// <param name="f"><c><see cref="Yata"/></c></param> internal FontDialog(Yata f) { _f = f; InitializeComponent(); Initialize(YataDialog.METRIC_FUL, true, true); tb_FontSize.BackColor = Color.White; tb_FontString.BackColor = Colors.TextboxBackground; // Safely ensure that Yata's current font is good to go // else set defaults -> int font_init = -1; // for showing the initial font's characteristics in the list -> int font_test = -1; // DEBUG -> //LogValidStyles(); //LogAllFonts(); //LogFontFiles(); Font font; foreach (var ff in FontFamily.Families) { FontStyle style = getStyle(ff); if (style != FontStyleInvalid) { font = new Font(ff, 10, style); if (font.Name == ff.Name) // safety. { if (font_init == -1) // look for Yata's current font -> { ++font_test; if (font.Name == _f.Font.Name) { font_init = font_test; } } _ffs.Add(ff); list_Font.Items.Add(font); _fonts.Add(font); // '_fonts' is purely storage for Disposal of the fonts used to render the fontlist. } else { font.Dispose(); } } } float size_init; FontStyle style_init; if (font_init != -1) { list_Font.SelectedIndex = font_init; style_init = _f.Font.Style; size_init = _f.Font.SizeInPoints; } else { list_Font.SelectedIndex = 0; // you'd better have at least 1 font on your system buckwheat /lol style_init = getStyle(_ffs[0]); size_init = 10F; } cb_Bold.Checked = (style_init & FontStyle.Bold) != 0; cb_Ital.Checked = (style_init & FontStyle.Italic) != 0; cb_Undr.Checked = (style_init & FontStyle.Underline) != 0; cb_Strk.Checked = (style_init & FontStyle.Strikeout) != 0; tb_FontSize.Text = size_init.ToString(CultureInfo.InvariantCulture); tb_FontSize.MouseWheel += size_mousewheel; // NOTE: Mousewheel event is not shown in the designer. _init = false; changefont(list_Font, EventArgs.Empty); _t1.Tick += t1_tick; _t1.Interval = 100; Show(_f); // Yata is owner. }
/// <summary> /// cTor. /// </summary> /// <param name="f">the <c><see cref="Yata"/></c></param> /// <param name="r">the currently selected row-id</param> /// <param name="copyfillenabled"><c>true</c> if at least one /// <c><see cref="Row"/></c> has been copied into /// <c><see cref="Yata"/>._copyr</c></param> internal RowCreatorDialog(Yata f, int r, bool copyfillenabled) { _f = f; InitializeComponent(); Initialize(YataDialog.METRIC_LOC, true); if (r != -1) { _strt = StrtType.Insert; _stop = StopType.Count; } else { _strt = StrtType.Add; rb_FillSelected.Enabled = false; la_FillSelected.ForeColor = SystemColors.GrayText; } if (!copyfillenabled) { rb_FillCopied.Enabled = false; la_FillCopied.ForeColor = SystemColors.GrayText; } _init = true; switch (_strt) { case StrtType.Add: rb_StartAdd.Checked = tb_StartAdd.Enabled = true; rb_StartInsert.Checked = tb_StartInsert.Enabled = false; break; case StrtType.Insert: rb_StartAdd.Checked = tb_StartAdd.Enabled = false; rb_StartInsert.Checked = tb_StartInsert.Enabled = true; break; } switch (_stop) { case StopType.non: rb_StopFinish.Checked = tb_StopFinish.Enabled = _strt == StrtType.Add; rb_StopCount.Checked = tb_StopCount.Enabled = _strt == StrtType.Insert; break; case StopType.Finish: rb_StopFinish.Checked = tb_StopFinish.Enabled = true; rb_StopCount.Checked = tb_StopCount.Enabled = false; break; case StopType.Count: rb_StopFinish.Checked = tb_StopFinish.Enabled = false; rb_StopCount.Checked = tb_StopCount.Enabled = true; break; } tb_StartAdd.Text = Yata.Table.Rows.Count.ToString(CultureInfo.InvariantCulture); tb_StartInsert.Text = (r + 1).ToString(CultureInfo.InvariantCulture); int result = Int32.Parse(_count, CultureInfo.InvariantCulture); // shall be valid and greater than 0. Control tb; if (rb_StartAdd.Checked) // readonly - shall be valid. { tb = tb_StartAdd; bu_Accept.Text = ADD; } else // rb_StartInsert.Checked // shall be valid. { tb = tb_StartInsert; bu_Accept.Text = INSERT; } tb_StopFinish.Text = (Int32.Parse(tb.Text, CultureInfo.InvariantCulture) + result - 1).ToString(CultureInfo.InvariantCulture); tb_StopCount.Text = _count; _init = false; tb_StartAdd.BackColor = Colors.TextboxReadonly; if (rb_StartInsert.Checked) { tb_StartInsert.BackColor = Colors.TextboxSelected; } else { tb_StartInsert.BackColor = Colors.TextboxBackground; } if (rb_StopFinish.Checked) { tb_StopFinish.BackColor = Colors.TextboxSelected; tb_StopCount.BackColor = Colors.TextboxBackground; } else // rb_StopCount.Checked { tb_StopFinish.BackColor = Colors.TextboxBackground; tb_StopCount.BackColor = Colors.TextboxSelected; } bu_Accept.Select(); }