text:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using EDDiscovery.Controls;
using EliteDangerousCore.DB;
using EliteDangerousCore;
using EliteDangerousCore.EDSM;
using EliteDangerousCore.EDDN;
using EDDiscovery.Forms;

namespace EDDiscovery.UserControls
{
    public partial class UserControlTravelGrid : UserControlCommonBase, IHistoryCursorNewStarList
    {
        #region Public IF

        //ucct interface
        public HistoryEntry GetCurrentHistoryEntry { get { return dataGridViewTravel.CurrentCell != null ? dataGridViewTravel.Rows[dataGridViewTravel.CurrentCell.RowIndex].Tag as HistoryEntry : null; } }

        //horrible.. needs removing, used by export.
        public TravelHistoryFilter GetHistoryFilter { get { return (TravelHistoryFilter)comboBoxHistoryWindow.SelectedItem ?? TravelHistoryFilter.NoFilter; } }

        #endregion

        #region Events

        // implement IHistoryCursor fields
        public event ChangedSelectionHEHandler OnTravelSelectionChanged;   // as above, different format, for certain older controls

        public event OnNewStarsSubPanelsHandler OnNewStarList;

        // for primary travel grid for auto note jump
        public delegate void KeyDownInCell(int asciikeycode, int rowno, int colno, bool note);
        public event KeyDownInCell OnKeyDownInCell;   // After a change of selection

        // for primary travel grid to chain stuff after display has been updated
        public delegate void AddedNewEntry(HistoryEntry he, HistoryList hl, bool accepted);
        public AddedNewEntry OnNewEntry;       // FIRED after discoveryform.onNewEntry->this.AddNewEntry completes

        #endregion

        #region Init

        private class Columns
        {
            public const int Time = 0;
            public const int Icon = 1;
            public const int Description = 2;
            public const int Information = 3;
            public const int Note = 4;
        }

        private int defaultRowHeight;

        private string DbFilterSave { get { return DBName("TravelHistoryControlEventFilter2" ); } }
        private string DbColumnSave { get { return DBName("TravelControl" ,  "DGVCol"); } }
        private string DbHistorySave { get { return DBName("EDUIHistory" ); } }
        private string DbFieldFilter { get { return DBName("TravelHistoryControlFieldFilter" ); } }
        private string DbOutlines { get { return DBName("TravelHistoryOutlines"); } }
        private string DbWordWrap { get { return DBName("TravelHistoryWordWrap"); } }

        private HistoryList current_historylist;        // the last one set, for internal refresh purposes on sort

        private BaseUtils.ConditionLists fieldfilter = new BaseUtils.ConditionLists();

        private Dictionary<long, DataGridViewRow> rowsbyjournalid = new Dictionary<long, DataGridViewRow>();

        FilterSelector cfs;

        Timer searchtimer;
        Timer todotimer;

        private Queue<Action> todo = new Queue<Action>();
        private bool loadcomplete = false;

        public UserControlTravelGrid()
        {
            InitializeComponent();
            var corner = dataGridViewTravel.TopLeftHeaderCell; // work around #1487
        }

        public override void Init()
        {
            //System.Diagnostics.Debug.WriteLine("Travel grid is " + this.GetHashCode());

            cfs = new FilterSelector(DbFilterSave);
            cfs.AddAllNone();
            cfs.AddJournalExtraOptions();
            cfs.AddJournalEntries();
            cfs.SaveSettings += EventFilterChanged;

            checkBoxCursorToTop.Checked = true;

            dataGridViewTravel.MakeDoubleBuffered();

            string filter = EliteDangerousCore.DB.UserDatabase.Instance.GetSettingString(DbFieldFilter, "");
            if (filter.Length > 0)
                fieldfilter.FromJSON(filter);        // load filter
#if !DEBUG
            writeEventInfoToLogDebugToolStripMenuItem.Visible = false;
            runActionsAcrossSelectionToolSpeechStripMenuItem.Visible = false;
            runSelectionThroughInaraSystemToolStripMenuItem.Visible = false;
            runEntryThroughProfileSystemToolStripMenuItem.Visible = false;
            runSelectionThroughIGAUDebugToolStripMenuItem.Visible = false;
#endif

            searchtimer = new Timer() { Interval = 500 };
            searchtimer.Tick += Searchtimer_Tick;

            todotimer = new Timer { Interval = 20 };
            todotimer.Tick += Todotimer_Tick;

            discoveryform.OnHistoryChange += HistoryChanged;
            discoveryform.OnNewEntry += AddNewEntry;
            discoveryform.OnNoteChanged += OnNoteChanged;

            contextMenuStripOutlines.SetToolStripState(EliteDangerousCore.DB.UserDatabase.Instance.GetSettingString(DbOutlines, ""));
            this.rollUpOffToolStripMenuItem.Click += new System.EventHandler(this.rolluplimitToolStripMenuItem_Click);
            this.rollUpAfterFirstToolStripMenuItem.Click += new System.EventHandler(this.rolluplimitToolStripMenuItem_Click);
            this.rollUpAfter5ToolStripMenuItem.Click += new System.EventHandler(this.rolluplimitToolStripMenuItem_Click);
            this.outliningOnOffToolStripMenuItem.Click += new System.EventHandler(this.toolStripOutliningToggle);
            this.scanEventsOutliningOnOffToolStripMenuItem.Click += new System.EventHandler(this.toolStripOutliningToggle);
            extCheckBoxOutlines.Checked = outliningOnOffToolStripMenuItem.Checked;

            extCheckBoxWordWrap.Checked = EliteDangerousCore.DB.UserDatabase.Instance.GetSettingBool(DbWordWrap, false);
            UpdateWordWrap();
            extCheckBoxWordWrap.Click += extCheckBoxWordWrap_Click;

            BaseUtils.Translator.Instance.Translate(this);
            BaseUtils.Translator.Instance.Translate(historyContextMenu, this);
            BaseUtils.Translator.Instance.Translate(contextMenuStripOutlines, this);
            BaseUtils.Translator.Instance.Translate(toolTip, this);

            TravelHistoryFilter.InitaliseComboBox(comboBoxHistoryWindow, DbHistorySave);

            dataViewScrollerPanel.LimitLargeChange = 4; // since row sizes can be variable, estimating large change on visible rows is problematic
        }

        private void ToolStripOutliningOn_CheckStateChanged(object sender, EventArgs e)
        {
            System.Diagnostics.Debug.WriteLine("outlining Change state");
        }

        public override void LoadLayout()
        {
            defaultRowHeight = dataGridViewTravel.RowTemplate.MinimumHeight = Math.Max(28, Font.ScalePixels(28));       // due to 24 bit icons
            DGVLoadColumnLayout(dataGridViewTravel, DbColumnSave);
        }

        public override void Closing()
        {
            todo.Clear();
            todotimer.Stop();
            searchtimer.Stop();
            DGVSaveColumnLayout(dataGridViewTravel, DbColumnSave);
            discoveryform.OnHistoryChange -= HistoryChanged;
            discoveryform.OnNewEntry -= AddNewEntry;
            searchtimer.Dispose();
        }

#endregion

        public override void InitialDisplay()
        {
            HistoryChanged(discoveryform.history);
        }

        int fdropdown, ftotalevents, ftotalfilters;     // filter totals
        public void HistoryChanged(HistoryList hl)           // on History change
        {
            HistoryChanged(hl, false);
        }

        public void HistoryChanged(HistoryList hl, bool disablesorting)           // on History change
        {
            if (hl == null)     // just for safety
                return;

            loadcomplete = false;
            current_historylist = hl;
            this.Cursor = Cursors.WaitCursor;
            extCheckBoxOutlines.Enabled = extCheckBoxWordWrap.Enabled = buttonExtExcel.Enabled = buttonFilter.Enabled = buttonField.Enabled = comboBoxHistoryWindow.Enabled = false;

            Tuple<long, int> pos = CurrentGridPosByJID();

            SortOrder sortorder = dataGridViewTravel.SortOrder;
            int sortcol = dataGridViewTravel.SortedColumn?.Index ?? -1;
            if (sortcol >= 0 && disablesorting)
            {
                dataGridViewTravel.Columns[sortcol].HeaderCell.SortGlyphDirection = SortOrder.None;
                sortcol = -1;
            }

            var filter = (TravelHistoryFilter)comboBoxHistoryWindow.SelectedItem ?? TravelHistoryFilter.NoFilter;

            List<HistoryEntry> result = filter.Filter(hl);
            fdropdown = hl.Count() - result.Count();

            result = HistoryList.FilterByJournalEvent(result, EliteDangerousCore.DB.UserDatabase.Instance.GetSettingString(DbFilterSave, "All"), out ftotalevents);

            result = FilterHelpers.FilterHistory(result, fieldfilter, discoveryform.Globals, out ftotalfilters);

            panelOutlining.Clear();
            dataGridViewTravel.Rows.Clear();
            rowsbyjournalid.Clear();

            dataGridViewTravel.Columns[0].HeaderText = EDDiscoveryForm.EDDConfig.GetTimeTitle();

            List<HistoryEntry[]> chunks = new List<HistoryEntry[]>();

            int chunksize = 500;
            for (int i = 0; i < result.Count; i += chunksize, chunksize = 2000)
            {
                HistoryEntry[] chunk = new HistoryEntry[i + chunksize > result.Count ? result.Count - i : chunksize];

                result.CopyTo(i, chunk, 0, chunk.Length);
                chunks.Add(chunk);
            }

            todo.Clear();
            string filtertext = textBoxFilter.Text;
            List<DataGridViewRow> rows = new List<DataGridViewRow>();

            Outlining outlining = null;     // only outline if in normal time decend more with no filter text
            bool rollupscans = false;
            int rollupolder = 0;
            if (filtertext.IsEmpty() && (sortcol < 0 || (sortcol == 0 && sortorder == SortOrder.Descending)) && outliningOnOffToolStripMenuItem.Checked)
            {
                outlining = new Outlining(panelOutlining);
                rollupscans = scanEventsOutliningOnOffToolStripMenuItem.Checked;
                rollupolder = rollUpOffToolStripMenuItem.Checked ? 0 : rollUpAfterFirstToolStripMenuItem.Checked ? 1 : 5;
            }

            extCheckBoxOutlines.Checked = outlining != null;

            System.Diagnostics.Stopwatch swtotal = new System.Diagnostics.Stopwatch();

            //int lrowno = 0;

            if (chunks.Count != 0)
            {
                var chunk = chunks[0];

                swtotal.Start();

                List<DataGridViewRow> rowstoadd = new List<DataGridViewRow>();
                foreach (var item in chunk)
                {
                    var row = CreateHistoryRow(item, filtertext);

                    if (row != null)
                    {
                        //row.Cells[2].Value = (lrowno++).ToString() + " " + item.Journalid + " " + (string)row.Cells[2].Value;
                        row.Visible = outlining?.Process(item, dataGridViewTravel.RowCount, rollupscans, rollupolder) ?? true;
                        rowstoadd.Add(row);
                    }
                }

                dataGridViewTravel.Rows.AddRange(rowstoadd.ToArray());

                if (dataGridViewTravel.MoveToSelection(rowsbyjournalid, ref pos, false, Columns.Information))
                    FireChangeSelection();
            }

            foreach (var chunk in chunks.Skip(1))
            {
                todo.Enqueue(() =>
                {
                    List<DataGridViewRow> rowstoadd = new List<DataGridViewRow>();

                    //System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start();

                    foreach (var item in chunk)
                    {
                        var row = CreateHistoryRow(item, filtertext);
                        if (row != null)
                        {
                            //row.Cells[2].Value = (lrowno++).ToString() + " " + item.Journalid + " " + (string)row.Cells[2].Value;
                            row.Visible = outlining?.Process(item, dataGridViewTravel.RowCount, rollupscans, rollupolder) ?? true;
                            rowstoadd.Add(row);
                        }
                    }

                    dataGridViewTravel.Rows.AddRange(rowstoadd.ToArray());

                    if (dataGridViewTravel.MoveToSelection(rowsbyjournalid, ref pos, false, Columns.Information))
                        FireChangeSelection();

                    //System.Diagnostics.Debug.WriteLine("T Chunk Load in " + sw.ElapsedMilliseconds);
                });
            }

            todo.Enqueue(() =>
            {
                if (chunks.Count != 0)
                {
                    if (outlining != null)
                    {
                        dataGridViewTravel.Rows[dataGridViewTravel.Rows.Count - 1].Visible = true;
                        outlining.ProcesslastLine(dataGridViewTravel.Rows.Count - 1, rollupolder);     // ensures we have a group at the end..
                        panelOutlining.UpdateAfterAdd();
                    }
                }

                System.Diagnostics.Debug.WriteLine(BaseUtils.AppTicks.TickCount + " TG TOTAL TIME " + swtotal.ElapsedMilliseconds);

                UpdateToolTipsForFilter();

                //System.Diagnostics.Trace.WriteLine(BaseUtils.AppTicks.TickCountLap(this) + " TG " + displaynumber + " Load Finish");

                if (dataGridViewTravel.MoveToSelection(rowsbyjournalid, ref pos, true, Columns.Information))
                    FireChangeSelection();

                if (sortcol >= 0)
                {
                    dataGridViewTravel.Sort(dataGridViewTravel.Columns[sortcol], (sortorder == SortOrder.Descending) ? ListSortDirection.Descending : ListSortDirection.Ascending);
                    dataGridViewTravel.Columns[sortcol].HeaderCell.SortGlyphDirection = sortorder;
                }

                this.Cursor = Cursors.Default;
                extCheckBoxOutlines.Enabled = extCheckBoxWordWrap.Enabled = buttonExtExcel.Enabled = buttonFilter.Enabled = buttonField.Enabled = comboBoxHistoryWindow.Enabled = true;

                loadcomplete = true;
            });

            todotimer.Start();
        }

        private void Todotimer_Tick(object sender, EventArgs e)
        {
            if (todo.Count != 0)
            {
                var act = todo.Dequeue();
                act();
            }
            else
            {
                todotimer.Stop();
            }
        }

        private void AddNewEntry(HistoryEntry he, HistoryList hl)           // on new entry from discovery system
        {
            if (!loadcomplete)
            {
                todo.Enqueue(() => AddNewEntry(he, hl));
                return;
            }

            bool add = he.IsJournalEventInEventFilter(EliteDangerousCore.DB.UserDatabase.Instance.GetSettingString(DbFilterSave, "All"));

            if (!add)                   // filtered out, update filter total and display
            {
                ftotalevents++;
                UpdateToolTipsForFilter();
            }

            if (add && !FilterHelpers.FilterHistory(he, fieldfilter, discoveryform.Globals))
            {
                add = false;
                ftotalfilters++;
                UpdateToolTipsForFilter();
            }

            if (add)
            {
                var row = CreateHistoryRow(he, textBoxFilter.Text);
                if (row != null)
                    dataGridViewTravel.Rows.Insert(0, row);
            }

            if (OnNewEntry != null)
                OnNewEntry(he, hl, add);

            if (add)
            {
                var filter = (TravelHistoryFilter)comboBoxHistoryWindow.SelectedItem ?? TravelHistoryFilter.NoFilter;

                if (filter.MaximumNumberOfItems != null)
                {
                    for (int r = dataGridViewTravel.Rows.Count - 1; r >= dataGridViewTravel.Rows.Count; r--)
                    {
                        dataGridViewTravel.Rows.RemoveAt(r);
                    }
                }

                if (filter.MaximumDataAge != null)
                {
                    for (int r = dataGridViewTravel.Rows.Count - 1; r > 0; r--)
                    {
                        var rhe = dataGridViewTravel.Rows[r].Tag as HistoryEntry;
                        if (rhe != null && rhe.AgeOfEntry() > filter.MaximumDataAge)
                        {
                            dataGridViewTravel.Rows.RemoveAt(r);
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                if (checkBoxCursorToTop.Checked && dataGridViewTravel.DisplayedRowCount(false) > 0)   // Move focus to new row
                {
                    //System.Diagnostics.Debug.WriteLine("Auto Sel");
                    dataGridViewTravel.ClearSelection();
                    int rowno = dataGridViewTravel.Rows.GetFirstRow(DataGridViewElementStates.Visible);
                    if (rowno != -1)
                        dataGridViewTravel.CurrentCell = dataGridViewTravel.Rows[rowno].Cells[1];       // its the current cell which needs to be set, moves the row marker as well

                    FireChangeSelection();
                }
            }
        }

        private DataGridViewRow CreateHistoryRow(HistoryEntry item, string search)
        {
            //string debugt = item.Journalid + "  " + item.System.id_edsm + " " + item.System.GetHashCode() + " "; // add on for debug purposes to a field below

            DateTime time = EDDiscoveryForm.EDDConfig.ConvertTimeToSelectedFromUTC(item.EventTimeUTC);
            item.journalEntry.FillInformation(out string EventDescription, out string EventDetailedInfo);
            string note = (item.snc != null) ? item.snc.Note : "";

            if (search.HasChars())
            {
                string timestr = time.ToString();
                int rown = EDDConfig.Instance.OrderRowsInverted ? item.Indexno : (discoveryform.history.Count - item.Indexno + 1);
                string entryrow = rown.ToStringInvariant();
                bool matched = timestr.IndexOf(search, StringComparison.InvariantCultureIgnoreCase) >= 0 ||
                                item.EventSummary.IndexOf(search, StringComparison.InvariantCultureIgnoreCase) >= 0 ||
                                EventDescription.IndexOf(search, StringComparison.InvariantCultureIgnoreCase) >= 0 ||
                                note.IndexOf(search, StringComparison.InvariantCultureIgnoreCase) >= 0 ||
                                entryrow.IndexOf(search, StringComparison.InvariantCultureIgnoreCase) >= 0;
                if (!matched)
                    return null;
            }

            var rw = dataGridViewTravel.RowTemplate.Clone() as DataGridViewRow;

            rw.CreateCells(dataGridViewTravel, time, "", item.EventSummary, EventDescription, note);

            rw.Tag = item;  //tag on row

            rw.DefaultCellStyle.ForeColor = (item.System.HasCoordinate || !item.IsFSDCarrierJump) ? discoveryform.theme.VisitedSystemColor : discoveryform.theme.NonVisitedSystemColor;

            string tip = item.EventSummary + Environment.NewLine + EventDescription + Environment.NewLine + EventDetailedInfo;

            rw.Cells[0].ToolTipText = tip;
            rw.Cells[1].ToolTipText = tip;
            rw.Cells[2].ToolTipText = tip;
            rw.Cells[3].ToolTipText = tip;
            rw.Cells[4].ToolTipText = tip;

            rowsbyjournalid[item.Journalid] = rw;
            return rw;

        }

        private void UpdateToolTipsForFilter()
        {
            string ms = string.Format(" showing {0} original {1}".T(EDTx.UserControlTravelGrid_TT1), dataGridViewTravel.Rows.Count, current_historylist?.Count() ?? 0);
            comboBoxHistoryWindow.SetTipDynamically(toolTip, fdropdown > 0 ? string.Format("Filtered {0}".T(EDTx.UserControlTravelGrid_TTFilt1), fdropdown + ms) : "Select the entries by age, ".T(EDTx.UserControlTravelGrid_TTSelAge) + ms);
            toolTip.SetToolTip(buttonFilter, (ftotalevents > 0) ? string.Format("Filtered {0}".T(EDTx.UserControlTravelGrid_TTFilt2), ftotalevents + ms) : "Filter out entries based on event type, ".T(EDTx.UserControlTravelGrid_TTEvent) + ms);
            toolTip.SetToolTip(buttonField, (ftotalfilters > 0) ? string.Format("Total filtered out {0}".T(EDTx.UserControlTravelGrid_TTFilt3), ftotalfilters + ms) : "Filter out entries matching the field selection, ".T(EDTx.UserControlTravelGrid_TTTotal) + ms);
        }

        private void dataGridViewTravel_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
        {
            if ( e.Column.Index == 0 )
            {
                e.SortDataGridViewColumnDate();
            }
        }

        Tuple<long, int> CurrentGridPosByJID()          // Returns JID, column index.  JID = -1 if cell is not defined
        {
            long jid = (dataGridViewTravel.CurrentCell != null) ? ((HistoryEntry)(dataGridViewTravel.Rows[dataGridViewTravel.CurrentCell.RowIndex].Tag)).Journalid : -1;
            int cellno = (dataGridViewTravel.CurrentCell != null) ? dataGridViewTravel.CurrentCell.ColumnIndex : 0;
            return new Tuple<long, int>(jid, cellno);
        }

        public void GotoPosByJID(long jid)
        {
            int rowno = DataGridViewControlHelpersStaticFunc.FindGridPosByID(rowsbyjournalid,jid, true);
            if (rowno >= 0)
            {
                dataGridViewTravel.CurrentCell = dataGridViewTravel.Rows[rowno].Cells[Columns.Information];
                dataGridViewTravel.Rows[rowno].Selected = true;
                FireChangeSelection();
            }
        }

        public void FireChangeSelection()
        {
            System.Diagnostics.Debug.WriteLine("TG Fire Change sel" );

            if (dataGridViewTravel.CurrentCell != null)
            {
                int row = dataGridViewTravel.CurrentCell.RowIndex;
                //System.Diagnostics.Debug.WriteLine("TG:Fire Change Sel row" + row);
                OnTravelSelectionChanged?.Invoke(dataGridViewTravel.Rows[row].Tag as HistoryEntry, current_historylist, true);
            }
            else if (current_historylist != null && current_historylist.Count > 0)
                OnTravelSelectionChanged?.Invoke(current_historylist.Last(), current_historylist, false);
        }

        private void comboBoxHistoryWindow_SelectedIndexChanged(object sender, EventArgs e)
        {
            EliteDangerousCore.DB.UserDatabase.Instance.PutSettingString(DbHistorySave, comboBoxHistoryWindow.Text);

            if (current_historylist != null)
            {
                HistoryChanged(current_historylist);        // fires lots of events
            }
        }

        private void dataGridViewTravel_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            FireChangeSelection();
        }

        int keyrepeatcount = 0;     // 1 is first down, 2 is second.  on 2+ we call the check selection to update the screen.  The final key up finished the job.

        private void dataGridViewTravel_KeyDown(object sender, KeyEventArgs e)
        {
            //System.Diagnostics.Debug.WriteLine("Key down " + e.KeyCode + " " + dataGridViewTravel.CurrentCell.RowIndex + ":" + dataGridViewTravel.CurrentCell.ColumnIndex);
            keyrepeatcount++;

            if (keyrepeatcount > 1)
                CheckForSelection(e.KeyCode);

            //System.Diagnostics.Debug.WriteLine("KC " + (int)e.KeyCode + " " + (int)e.KeyData + " " + e.KeyValue);
        }

        private void dataGridViewTravel_KeyPress(object sender, KeyPressEventArgs e)
        {
            //System.Diagnostics.Debug.WriteLine("KP " + (int)e.KeyChar);

            if (OnKeyDownInCell != null && dataGridViewTravel.CurrentCell != null )
                OnKeyDownInCell(e.KeyChar, dataGridViewTravel.CurrentCell.RowIndex, dataGridViewTravel.CurrentCell.ColumnIndex, dataGridViewTravel.CurrentCell.ColumnIndex == Columns.Note);
        }

        private void dataGridViewTravel_KeyUp(object sender, KeyEventArgs e)
        {
            //System.Diagnostics.Debug.WriteLine("Key up " + e.KeyCode + " " + dataGridViewTravel.CurrentCell.RowIndex + ":" + dataGridViewTravel.CurrentCell.ColumnIndex);
            CheckForSelection(e.KeyCode);
            keyrepeatcount = 0;
        }

        void CheckForSelection(Keys code)
        {
            bool cursorkeydown = (code == Keys.Up || code == Keys.Down || code == Keys.PageDown || code == Keys.PageUp || code == Keys.Left || code == Keys.Right);

            if (cursorkeydown)
                FireChangeSelection();
        }

        private void OnNoteChanged(Object sender,HistoryEntry he, bool committed)
        {
            if (!loadcomplete)
            {
                todo.Enqueue(() => OnNoteChanged(sender, he, committed));
                return;
            }

            if (rowsbyjournalid.ContainsKey(he.Journalid) ) // if we can find the grid entry
            {
                string s = (he.snc != null) ? he.snc.Note : "";     // snc may have gone null, so cope with it
                //System.Diagnostics.Debug.WriteLine("TG:Note changed " + s);
                rowsbyjournalid[he.Journalid].Cells[Columns.Note].Value = s;
            }
        }

        private void textBoxFilter_TextChanged(object sender, EventArgs e)
        {
            searchtimer.Stop();
            searchtimer.Start();
            //System.Diagnostics.Debug.WriteLine(Environment.TickCount % 10000 + "Char");
        }

        private void Searchtimer_Tick(object sender, EventArgs e)
        {
            if (!loadcomplete)
            {
                return;
            }

            searchtimer.Stop();
            this.Cursor = Cursors.WaitCursor;
            HistoryChanged(current_historylist);
            this.Cursor = Cursors.Default;
        }

        private void dataGridViewTravel_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            DataGridView grid = sender as DataGridView;
            PaintEventColumn(grid, e,
                            discoveryform.history.Count, (HistoryEntry)dataGridViewTravel.Rows[e.RowIndex].Tag,
                            grid.RowHeadersWidth + grid.Columns[0].Width, grid.Columns[1].Width, true);
        }

        public static void PaintEventColumn(DataGridView grid, DataGridViewRowPostPaintEventArgs e,
                                             int totalentries, HistoryEntry he,
                                             int hpos, int colwidth, bool showfsdmapcolour)
        {
            System.Diagnostics.Debug.Assert(he != null);    // Trip for debug builds if something is wrong,
            if (he == null)                                 // otherwise, ignore it and return.
                return;

            int rown = EDDConfig.Instance.OrderRowsInverted ? he.Indexno : (totalentries - he.Indexno + 1);
            string rowIdx = rown.ToString();

            var headerBounds = new Rectangle(e.RowBounds.Left, e.RowBounds.Top, grid.RowHeadersWidth, e.RowBounds.Height);

            using (var centerFormat = new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center })
            {
                e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                using (Brush br = new SolidBrush(grid.RowHeadersDefaultCellStyle.ForeColor))
                    e.Graphics.DrawString(rowIdx, grid.RowHeadersDefaultCellStyle.Font, br, headerBounds, centerFormat);
            }

            int noicons = (he.IsFSDCarrierJump && showfsdmapcolour) ? 2 : 1;
            if (he.StartMarker || he.StopMarker)
                noicons++;

            BookmarkClass bk = null;
            if (he.IsLocOrJump)
            {
                bk = GlobalBookMarkList.Instance.FindBookmarkOnSystem(he.System.Name);
                if (bk != null)
                    noicons++;
            }

            int padding = 4;
            int size = 24;

            if (size * noicons > (colwidth - 2))
                size = (colwidth - 2) / noicons;

            int hstart = (hpos + colwidth / 2) - size / 2 * noicons - padding / 2 * (noicons - 1);

            int top = (e.RowBounds.Top + e.RowBounds.Bottom) / 2 - size / 2;

            e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;

            e.Graphics.DrawImage(he.journalEntry.Icon, new Rectangle(hstart, top, size, size));
            hstart += size + padding;

            if (he.journalEntry is IJournalJumpColor && showfsdmapcolour)
            {
                Color c = Color.FromArgb(((IJournalJumpColor)he.journalEntry).MapColor);

                using (Brush b = new SolidBrush(c))
                {
                    e.Graphics.FillEllipse(b, new Rectangle(hstart + 2, top + 2, size - 6, size - 6));
                }

                hstart += size + padding;
            }

            if (he.StartMarker)
            {
                e.Graphics.DrawImage(Icons.Controls.TravelGrid_FlagStart, new Rectangle(hstart, top, size, size));
                hstart += size + padding;
            }
            else if (he.StopMarker)
            {
                e.Graphics.DrawImage(Icons.Controls.TravelGrid_FlagStop, new Rectangle(hstart, top, size, size));
                hstart += size + padding;
            }
            if (bk != null)
            {
                e.Graphics.DrawImage(Icons.Controls.Map3D_Bookmarks_Star, new Rectangle(hstart, top, size, size));
            }
        }

#region Right/Left Clicks

        HistoryEntry rightclickhe = null;
        int rightclickrow = -1;
        HistoryEntry leftclickhe = null;
        int leftclickrow = -1;

        private void dataGridViewTravel_MouseDown(object sender, MouseEventArgs e)
        {
            dataGridViewTravel.HandleClickOnDataGrid(e, out leftclickrow, out rightclickrow);
            rightclickhe = (rightclickrow != -1) ? (HistoryEntry)dataGridViewTravel.Rows[rightclickrow].Tag : null;
            leftclickhe = (leftclickrow != -1) ? (HistoryEntry)dataGridViewTravel.Rows[leftclickrow].Tag : null;
        }

        private void dataGridViewTravel_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (leftclickrow >= 0)                                                   // Click expands it..
            {
                leftclickhe.journalEntry.FillInformation(out string EventDescription, out string EventDetailedInfo);
                DataGridViewRow row = dataGridViewTravel.Rows[leftclickrow];

                bool expanded = row.Cells[Columns.Information].Tag != null;

                if (expanded) // put it back to original text
                {
                    row.Cells[Columns.Information].Value = EventDescription;
                    for (int i = 0; i < row.Cells.Count; i++)
                        row.Cells[i].Style.WrapMode = DataGridViewTriState.NotSet;
                    row.Cells[Columns.Information].Tag = null;
                }
                else
                {
                    string infodetailed = EventDescription.AppendPrePad(EventDetailedInfo, Environment.NewLine);        // make up detailed line
                    if (leftclickhe.journalEntry is EliteDangerousCore.JournalEvents.JournalLocOrJump)
                    {
                        string travelinfo = leftclickhe.TravelInfo();
                        if (travelinfo != null)
                            infodetailed = travelinfo + Environment.NewLine + infodetailed;
                    }

                    using (Graphics g = Parent.CreateGraphics())
                    {
                        int maxh = 0;
                        for (int i = 0; i < row.Cells.Count; i++)
                        {
                            if (row.Cells[i].Value is string)
                            {
                                string s = i == Columns.Information ? infodetailed : (string)row.Cells[i].Value;
                                int h = (int)(g.MeasureString(s, dataGridViewTravel.Font, dataGridViewTravel.Columns[i].Width - 4).Height + 2);
                                maxh = Math.Max(maxh, h);
                            }
                        }

                        if (maxh > dataGridViewTravel.Height * 3 / 4) // unreasonable amount of space to show it.
                        {
                            ExtendedControls.InfoForm info = new ExtendedControls.InfoForm();
                            info.Info(EDDiscoveryForm.EDDConfig.ConvertTimeToSelectedFromUTC(leftclickhe.EventTimeUTC) + ": " + leftclickhe.EventSummary,
                                FindForm().Icon, infodetailed);
                            info.Size = new Size(1200, 800);
                            info.Show(FindForm());
                        }
                        else
                        {
                            row.Cells[Columns.Information].Value = infodetailed;

                            if (!extCheckBoxWordWrap.Checked)
                            {
                                for (int i = 0; i < row.Cells.Count; i++)
                                    row.Cells[i].Style.WrapMode = DataGridViewTriState.True;
                            }
                        }

                        row.Cells[Columns.Information].Tag = true;      // mark expanded
                    }
                }

                dataViewScrollerPanel.UpdateScroll();
            }
        }

        private void dataGridViewTravel_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            panelOutlining.Clear();
            extCheckBoxOutlines.Checked = false;
        }

        #endregion

        #region Outlining

        private void extButtonOutlines_Click(object sender, EventArgs e)
        {
            if (extCheckBoxOutlines.Checked == true && outliningOnOffToolStripMenuItem.Checked)     // if going checked.. means it was unchecked
            {
                HistoryChanged(current_historylist, true);      // Reapply, disabled by sorting etc
            }
            else
            {
                var p = extCheckBoxOutlines.PointToScreen(new Point(0, extCheckBoxOutlines.Height));
                contextMenuStripOutlines.Font = this.Font;
                contextMenuStripOutlines.Show(p);
            }
        }

        private void toolStripOutliningToggle(object sender, EventArgs e)
        {
            EliteDangerousCore.DB.UserDatabase.Instance.PutSettingString(DbOutlines, contextMenuStripOutlines.GetToolStripState());
            extCheckBoxOutlines.Checked = outliningOnOffToolStripMenuItem.Checked;
            if (outliningOnOffToolStripMenuItem.Checked || sender == outliningOnOffToolStripMenuItem)
                HistoryChanged(current_historylist, true);
        }

        private void rolluplimitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem tmi = sender as ToolStripMenuItem;
            rollUpOffToolStripMenuItem.Checked = tmi == rollUpOffToolStripMenuItem;         // makes them work as radio buttons
            rollUpAfterFirstToolStripMenuItem.Checked = tmi == rollUpAfterFirstToolStripMenuItem;
            rollUpAfter5ToolStripMenuItem.Checked = tmi == rollUpAfter5ToolStripMenuItem;
            EliteDangerousCore.DB.UserDatabase.Instance.PutSettingString(DbOutlines, contextMenuStripOutlines.GetToolStripState());
            if (outliningOnOffToolStripMenuItem.Checked )
                HistoryChanged(current_historylist, true);
        }

        #endregion

        #region TravelHistoryRightClick

        private void historyContextMenu_Opening(object sender, CancelEventArgs e)
        {
            if (dataGridViewTravel.SelectedCells.Count == 0)      // need something selected  stops context menu opening on nothing..
                e.Cancel = true;

            HistoryEntry prev = discoveryform.history.PreviousFrom(rightclickhe, true);    // null can be passed in safely

            if (rightclickhe != null)
            {
                if (rightclickhe.StartMarker)
                {
                    toolStripMenuItemStartStop.Text = "Clear Start marker".T(EDTx.UserControlTravelGrid_CSTART);
                }
                else if (rightclickhe.StopMarker)
                {
                    toolStripMenuItemStartStop.Text = "Clear Stop marker".T(EDTx.UserControlTravelGrid_CSTOP);
                }
                else if (rightclickhe.isTravelling)
                {
                    toolStripMenuItemStartStop.Text = "Set Stop marker for travel calculations".T(EDTx.UserControlTravelGrid_SETSTOPTC);
                }
                else
                {
                    toolStripMenuItemStartStop.Text = "Set Start marker for travel calculations".T(EDTx.UserControlTravelGrid_SETSTARTTC);
                }
            }
            else
            {
                toolStripMenuItemStartStop.Text = "Set Start/Stop point for travel calculations".T(EDTx.UserControlTravelGrid_SETSTSTOP); ;
            }

            mapGotoStartoolStripMenuItem.Enabled = (rightclickhe != null && rightclickhe.System.HasCoordinate);
            viewOnEDSMToolStripMenuItem.Enabled = (rightclickhe != null);
            toolStripMenuItemStartStop.Enabled = (rightclickhe != null);
            removeJournalEntryToolStripMenuItem.Enabled = (rightclickhe != null);
            sendUnsyncedScanToEDDNToolStripMenuItem.Enabled = (rightclickhe != null && EDDNClass.IsDelayableEDDNMessage(rightclickhe.EntryType, rightclickhe.EventTimeUTC) && !rightclickhe.EDDNSync);
            runActionsOnThisEntryToolStripMenuItem.Enabled = (rightclickhe != null);
            setNoteToolStripMenuItem.Enabled = (rightclickhe != null);
            writeEventInfoToLogDebugToolStripMenuItem.Enabled = (rightclickhe != null);
            copyJournalEntryToClipboardToolStripMenuItem.Enabled = (rightclickhe != null);
            createEditBookmarkToolStripMenuItem.Enabled = (rightclickhe != null);
            gotoEntryNumberToolStripMenuItem.Enabled = dataGridViewTravel.Rows.Count > 0;
            removeSortingOfColumnsToolStripMenuItem.Enabled = dataGridViewTravel.SortedColumn != null;
            gotoNextStartStopMarkerToolStripMenuItem.Enabled = (rightclickhe != null);
        }

        private void removeSortingOfColumnsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            HistoryChanged(current_historylist, true);
        }

        private void mapGotoStartoolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!discoveryform.Map.Is3DMapsRunning)            // if not running, click the 3dmap button
                discoveryform.Open3DMap(GetCurrentHistoryEntry);

            if (discoveryform.Map.Is3DMapsRunning)             // double check here! for paranoia.
            {
                if (discoveryform.Map.MoveToSystem(rightclickhe.System))
                    discoveryform.Map.Show();
            }
        }

        private void starMapColourToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IEnumerable<DataGridViewRow> selectedRows = dataGridViewTravel.SelectedCells.Cast<DataGridViewCell>()
                                                           .Select(cell => cell.OwningRow)
                                                           .Distinct();
            ColorDialog mapColorDialog = new ColorDialog();
            mapColorDialog.AllowFullOpen = true;
            mapColorDialog.FullOpen = true;
            HistoryEntry sp2 = (HistoryEntry)selectedRows.First().Tag;
            mapColorDialog.Color = Color.Red;

            if (mapColorDialog.ShowDialog(FindForm()) == DialogResult.OK)
            {
                this.Cursor = Cursors.WaitCursor;

                foreach (DataGridViewRow r in selectedRows)
                {
                    HistoryEntry sp = (HistoryEntry)r.Tag;
                    System.Diagnostics.Debug.Assert(sp != null);
                    sp.journalEntry.UpdateMapColour(mapColorDialog.Color.ToArgb());
                }

                this.Cursor = Cursors.Default;
                HistoryChanged(current_historylist);
            }
        }

        private void hideSystemToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IEnumerable<DataGridViewRow> selectedRows = dataGridViewTravel.SelectedCells.Cast<DataGridViewCell>()
                .Select(cell => cell.OwningRow)
                .Distinct();

            this.Cursor = Cursors.WaitCursor;

            foreach (DataGridViewRow r in selectedRows)
            {
                HistoryEntry sp = (HistoryEntry)r.Tag;
                System.Diagnostics.Debug.Assert(sp != null);
                sp.journalEntry.UpdateCommanderID(-1);
                rowsbyjournalid.Remove(sp.Journalid);
            }

            // Remove rows
            if (selectedRows.Count<DataGridViewRow>() == dataGridViewTravel.Rows.Count)
            {
                dataGridViewTravel.Rows.Clear();
                rowsbyjournalid.Clear();
            }
            else
            {
                foreach (DataGridViewRow row in selectedRows.ToList<DataGridViewRow>())
                {
                    dataGridViewTravel.Rows.Remove(row);
                }
            }

            this.Cursor = Cursors.Default;
        }

        private void moveToAnotherCommanderToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IEnumerable<DataGridViewRow> selectedRows = dataGridViewTravel.SelectedCells.Cast<DataGridViewCell>()
                .Select(cell => cell.OwningRow)
                .Distinct();

            List<HistoryEntry> listsyspos = new List<HistoryEntry>();

            this.Cursor = Cursors.WaitCursor;
            foreach (DataGridViewRow r in selectedRows)
            {
                HistoryEntry sp = (HistoryEntry)r.Tag;
                System.Diagnostics.Debug.Assert(sp != null);
                listsyspos.Add(sp);
                rowsbyjournalid.Remove(sp.Journalid);
            }

            EDDiscovery.Forms.MoveToCommander movefrm = new EDDiscovery.Forms.MoveToCommander();

            movefrm.Init();

            DialogResult red = movefrm.ShowDialog(FindForm());
            if (red == DialogResult.OK)
            {
                foreach (HistoryEntry sp in listsyspos)
                {
                    sp.journalEntry.UpdateCommanderID(movefrm.selectedCommander.Nr);
                }

                foreach (DataGridViewRow row in selectedRows)
                {
                    dataGridViewTravel.Rows.Remove(row);
                }
            }

            this.Cursor = Cursors.Default;
        }

        private void trilaterationToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddSystemToOthers(dist:true);
        }

        private void wantedSystemsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddSystemToOthers(wanted:true);
        }

        private void bothToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddSystemToOthers(dist:true, wanted:true);
        }

        private void routeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddSystemToOthers(expedition:true);
        }

        private void explorationPanelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddSystemToOthers(exploration:true);
        }

        private void AddSystemToOthers(bool dist = false, bool wanted = false, bool expedition = false, bool exploration = false)
        {
            IEnumerable<DataGridViewRow> selectedRows = dataGridViewTravel.SelectedCells.Cast<DataGridViewCell>()
                                                                        .Select(cell => cell.OwningRow)
                                                                        .Distinct()
                                                                        .OrderBy(cell => cell.Index);

            this.Cursor = Cursors.WaitCursor;

            List<string> systemnamelist = new List<string>();

            string lastname = "";
            foreach (DataGridViewRow r in selectedRows)
            {
                HistoryEntry sp = (HistoryEntry)r.Tag;

                if (!sp.System.Name.Equals(lastname))
                {
                    lastname = sp.System.Name;
                    systemnamelist.Add(lastname);
                }
            }

            if (dist)
                FireNewStarList(systemnamelist, OnNewStarsPushType.TriSystems);

            if (wanted)
                FireNewStarList(systemnamelist, OnNewStarsPushType.TriWanted);

            if (expedition)
                FireNewStarList(systemnamelist, OnNewStarsPushType.Expedition);

            if (exploration)
                FireNewStarList(systemnamelist, OnNewStarsPushType.Exploration);

            this.Cursor = Cursors.Default;
        }

        public void FireNewStarList(List<string> system, OnNewStarsPushType pushtype)
        {
            OnNewStarList?.Invoke(system, pushtype);
        }

        private void viewOnEDSMToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            EliteDangerousCore.EDSM.EDSMClass edsm = new EDSMClass();
            long? id_edsm = rightclickhe.System?.EDSMID;

            if (id_edsm <= 0)
            {
                id_edsm = null;
            }

            if (!edsm.ShowSystemInEDSM(rightclickhe.System.Name, id_edsm))
                ExtendedControls.MessageBoxTheme.Show(FindForm(), "System could not be found - has not been synched or EDSM is unavailable".T(EDTx.UserControlTravelGrid_NotSynced));

            this.Cursor = Cursors.Default;
        }

        private void toolStripMenuItemStartStop_Click(object sender, EventArgs e)
        {
            discoveryform.history.SetStartStop(rightclickhe);
            discoveryform.RefreshHistoryAsync();
        }

        private void removeJournalEntryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string warning = ("Confirm you wish to remove this entry" + Environment.NewLine + "It may reappear if the logs are rescanned").T(EDTx.UserControlTravelGrid_Remove);
            if (ExtendedControls.MessageBoxTheme.Show(FindForm(), warning, "Warning".T(EDTx.Warning), MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                JournalEntry.Delete(rightclickhe.Journalid);
                discoveryform.RefreshHistoryAsync();
            }
        }

        private void sendUnsyncedScanToEDDNToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (EDDNClass.IsDelayableEDDNMessage(rightclickhe.EntryType, rightclickhe.EventTimeUTC) && !rightclickhe.EDDNSync)
            {
                EDDNSync.SendEDDNEvent(discoveryform.LogLine, rightclickhe);
            }
        }

        private void runActionsOnThisEntryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            discoveryform.ActionRunOnEntry(rightclickhe, Actions.ActionEventEDList.UserRightClick(rightclickhe));
        }

        private void setNoteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (Forms.SetNoteForm noteform = new Forms.SetNoteForm(rightclickhe, discoveryform))
            {
                if (noteform.ShowDialog(FindForm()) == DialogResult.OK)
                {
                    rightclickhe.SetJournalSystemNoteText(noteform.NoteText, true , EDCommander.Current.SyncToEdsm);

                    discoveryform.NoteChanged(this,rightclickhe, true);
                }
            }
        }

        private void writeEventInfoToLogDebugToolStripMenuItem_Click(object sender, EventArgs e)        //DEBUG ONLY
        {
            BaseUtils.Variables cv = new BaseUtils.Variables();
            cv.AddPropertiesFieldsOfClass(rightclickhe.journalEntry, "", new Type[] { typeof(System.Drawing.Image), typeof(System.Drawing.Icon), typeof(System.Drawing.Bitmap), typeof(Newtonsoft.Json.Linq.JObject) }, 5);
            discoveryform.LogLine(cv.ToString(separ: Environment.NewLine));
            //if (rightclicksystem.ShipInformation != null)
            //    discoveryform.LogLine(rightclicksystem.ShipInformation.ToString());
        }

        private void copyJournalEntryToClipboardToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Newtonsoft.Json.Linq.JObject jo = rightclickhe.journalEntry.GetJson();
            string json = jo?.ToString(Newtonsoft.Json.Formatting.Indented);
            if (json != null)
            {
                SetClipboardText(json);
                discoveryform.LogLine(json);
            }
        }

        private void createEditBookmarkToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BookmarkForm bookmarkForm = new BookmarkForm(discoveryform.history);
            BookmarkClass existing = GlobalBookMarkList.Instance.FindBookmarkOnSystem(rightclickhe.System.Name);
            DateTime timeutc;
            if (existing != null)
            {
                timeutc = existing.TimeUTC;
                bookmarkForm.Bookmark(existing);
            }
            else
            {
                timeutc = DateTime.UtcNow;
                bookmarkForm.NewSystemBookmark(rightclickhe.System, "", timeutc);
            }
            DialogResult dr = bookmarkForm.ShowDialog();
            if (dr == DialogResult.OK)
            {
                GlobalBookMarkList.Instance.AddOrUpdateBookmark(existing, true, rightclickhe.System.Name, rightclickhe.System.X, rightclickhe.System.Y, rightclickhe.System.Z,
                    timeutc, bookmarkForm.Notes, bookmarkForm.SurfaceLocations);
            }
            if (dr == DialogResult.Abort && existing != null)
            {
                GlobalBookMarkList.Instance.Delete(existing);
            }

            dataGridViewTravel.Refresh();
        }

        private void gotoEntryNumberToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int curi = rightclickhe != null ? (EDDConfig.Instance.OrderRowsInverted ? rightclickhe.Indexno : (discoveryform.history.Count - rightclickhe.Indexno + 1)) : 0;
            int selrow = dataGridViewTravel.JumpToDialog(this.FindForm(), curi, r =>
            {
                HistoryEntry he = r.Tag as HistoryEntry;
                return EDDConfig.Instance.OrderRowsInverted ? he.Indexno : (discoveryform.history.Count - he.Indexno + 1);
            });

            if (selrow >= 0)
            {
                dataGridViewTravel.ClearSelection();
                dataGridViewTravel.CurrentCell = dataGridViewTravel.Rows[selrow].Cells[1];
                FireChangeSelection();
            }
        }

        private void gotoNextStartStopMarkerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            for( int rown = rightclickrow+1; rown < dataGridViewTravel.Rows.Count; rown++ )
            {
                DataGridViewRow r = dataGridViewTravel.Rows[rown];
                if (r.Visible)
                {
                    HistoryEntry h = r.Tag as HistoryEntry;
                    if (h.StartMarker || h.StopMarker)
                    {
                        dataGridViewTravel.DisplayRow(r.Index, true);
                        dataGridViewTravel.ClearSelection();
                        dataGridViewTravel.Rows[r.Index].Selected = true;
                        break;
                    }
                }
            }
        }

        #endregion

        #region Event Filter

        private void buttonFilter_Click(object sender, EventArgs e)
        {
            Button b = sender as Button;
            cfs.Filter(b, this.FindForm());
        }

        private void EventFilterChanged(object sender, bool same, Object e)
        {
            if (!same)
                HistoryChanged(current_historylist,true);
        }

        private void buttonField_Click(object sender, EventArgs e)
        {
            BaseUtils.ConditionLists res = FilterHelpers.ShowDialog(FindForm(), fieldfilter, discoveryform, "History: Filter out fields".T(EDTx.UserControlTravelGrid_THF));
            if (res != null)
            {
                fieldfilter = res;
                EliteDangerousCore.DB.UserDatabase.Instance.PutSettingString(DbFieldFilter, fieldfilter.GetJSON());
                HistoryChanged(current_historylist);
            }
        }

        #endregion

        #region Word wrap

        private void extCheckBoxWordWrap_Click(object sender, EventArgs e)
        {
            EliteDangerousCore.DB.UserDatabase.Instance.PutSettingBool(DbWordWrap, extCheckBoxWordWrap.Checked);
            UpdateWordWrap();
        }

        private void UpdateWordWrap()
        {
            dataGridViewTravel.DefaultCellStyle.WrapMode = extCheckBoxWordWrap.Checked ? DataGridViewTriState.True : DataGridViewTriState.False;
            dataGridViewTravel.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCells;
            dataViewScrollerPanel.UpdateScroll();
        }

        #endregion

        #region DEBUG clicks - only for special people who build the debug version!

        private void runSelectionThroughInaraSystemToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (rightclickhe != null)
            {
                List<Newtonsoft.Json.Linq.JToken> list = EliteDangerousCore.Inara.InaraSync.NewEntryList(rightclickhe);

                foreach (Newtonsoft.Json.Linq.JToken j in list)
                {
                    j["eventTimestamp"] = DateTime.UtcNow.ToStringZulu();       // mangle time to now to allow it to send.
                    if (j["eventName"].Str() == "addCommanderMission")
                    {
                        j["eventData"]["missionExpiry"] = DateTime.UtcNow.AddDays(1).ToStringZulu();       // mangle mission time to now to allow it to send.
                    }
                    if (j["eventName"].Str() == "setCommunityGoal")
                    {
                        j["eventData"]["goalExpiry"] = DateTime.UtcNow.AddDays(5).ToStringZulu();       // mangle expiry time
                    }
                }

                Newtonsoft.Json.Linq.JObject jo = rightclickhe.journalEntry.GetJson();
                string json = jo?.ToString();
                discoveryform.LogLine(json);

                EliteDangerousCore.Inara.InaraClass inara = new EliteDangerousCore.Inara.InaraClass(EDCommander.Current);
                string str = inara.ToJSONString(list);
                discoveryform.LogLine(str);
                System.IO.File.WriteAllText(@"c:\code\inaraentry.json", str);

                if (list.Count > 0)
                {
                    string strres = inara.Send(list);
                    discoveryform.LogLine(strres);
                }
                else
                    discoveryform.LogLine("No Events");
            }
        }

        private void runEntryThroughProfileSystemToolStripMenuItem_Click(object sender, EventArgs e)
        {
            discoveryform.CheckActionProfile(rightclickhe);
        }

        private void runSelectionThroughIGAUDebugToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (rightclickhe != null)
            {
                EliteDangerousCore.IGAU.IGAUSync.NewEvent(discoveryform.LogLine, rightclickhe);
            }
        }

        private void runActionsAcrossSelectionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string laststring = "";
            string lasttype = "";
            int lasttypecount = 0;

            discoveryform.ActionController.AsyncMode = false;     // to force it to do all the action code before returning..

            if (dataGridViewTravel.SelectedRows.Count > 0)
            {
                List<DataGridViewRow> rows = (from DataGridViewRow x in dataGridViewTravel.SelectedRows where x.Visible orderby x.Index select x).ToList();
                foreach (DataGridViewRow rw in rows)
                {
                    HistoryEntry he = rw.Tag as HistoryEntry;
                    // System.Diagnostics.Debug.WriteLine("Row " + rw.Index + " " + he.EventSummary + " " + he.EventDescription);

                    bool same = he.journalEntry.EventTypeStr.Equals(lasttype);
                    if (!same || lasttypecount < 10)
                    {
                        lasttype = he.journalEntry.EventTypeStr;
                        lasttypecount = (same) ? ++lasttypecount : 0;

                        discoveryform.ActionController.SetPeristentGlobal("GlobalSaySaid", "");
                        BaseUtils.FunctionHandlers.SetRandom(new Random(rw.Index + 1));
                        discoveryform.ActionRunOnEntry(he, Actions.ActionEventEDList.UserRightClick(he));

                        Newtonsoft.Json.Linq.JObject jo = he.journalEntry.GetJson();
                        string json = jo?.ToString(Newtonsoft.Json.Formatting.None);

                        string s = discoveryform.ActionController.Globals["GlobalSaySaid"];

                        if (s.Length > 0 && !s.Equals(laststring))
                        {
                            System.Diagnostics.Debug.WriteLine("Call ts(j='" + json?.Replace("'", "\\'") + "',s='" + s.Replace("'", "\\'") + "',r=" + (rw.Index + 1).ToStringInvariant() + ")");
                            laststring = s;
                        }
                    }
                }
            }
        }

#endregion

#region Excel

        private void buttonExtExcel_Click(object sender, EventArgs e)
        {
            Forms.ExportForm frm = new Forms.ExportForm();
            frm.Init(new string[] { "View", "FSD Jumps only", "With Notes only" , "With Notes, no repeat"  });

            if (frm.ShowDialog(FindForm()) == DialogResult.OK)
            {
                BaseUtils.CSVWriteGrid grd = new BaseUtils.CSVWriteGrid();
                grd.SetCSVDelimiter(frm.Comma);

                List<SystemNoteClass> sysnotecache = new List<SystemNoteClass>();
                string[] colh = null;

                grd.GetLineStatus += delegate (int r)
                {
                    if (r < dataGridViewTravel.Rows.Count)
                    {
                        HistoryEntry he = (HistoryEntry)dataGridViewTravel.Rows[r].Tag;
                        return (dataGridViewTravel.Rows[r].Visible &&
                                he.EventTimeUTC.CompareTo(frm.StartTimeUTC) >= 0 &&
                                he.EventTimeUTC.CompareTo(frm.EndTimeUTC) <= 0) ? BaseUtils.CSVWriteGrid.LineStatus.OK : BaseUtils.CSVWriteGrid.LineStatus.Skip;
                    }
                    else
                        return BaseUtils.CSVWriteGrid.LineStatus.EOF;
                };

                if (frm.SelectedIndex == 1)     // export fsd jumps
                {
                    colh = new string[] { "Time", "Name", "X", "Y", "Z", "Distance", "Fuel Used", "Fuel Left", "Boost", "Note" };

                    grd.VerifyLine += delegate (int r)      // addition qualifier for FSD jump
                    {
                        HistoryEntry he = (HistoryEntry)dataGridViewTravel.Rows[r].Tag;
                        return he.EntryType == JournalTypeEnum.FSDJump;
                    };

                    grd.GetLine += delegate (int r)
                    {
                        HistoryEntry he = (HistoryEntry)dataGridViewTravel.Rows[r].Tag;
                        EliteDangerousCore.JournalEvents.JournalFSDJump fsd = he.journalEntry as EliteDangerousCore.JournalEvents.JournalFSDJump;

                        return new Object[] {
                            EDDConfig.Instance.ConvertTimeToSelectedFromUTC(fsd.EventTimeUTC),
                            fsd.StarSystem,
                            fsd.StarPos.X,
                            fsd.StarPos.Y,
                            fsd.StarPos.Z,
                            fsd.JumpDist,
                            fsd.FuelUsed,
                            fsd.FuelLevel,
                            fsd.BoostUsed,
                            he.snc != null ? he.snc.Note : "",
                        };

                    };
                }
                else
                {
                    colh = new string[] { "Time", "Event", "System", "Body",            //0
                                          "Ship", "Summary", "Description", "Detailed Info",        //4
                                          "Note", "Travel Dist", "Travel Time", "Travel Jumps",     //8
                                          "Travelled MisJumps" , "X", "Y","Z" ,     //12
                                          "JID", "EDSMID" , "EDDBID" };             //16

                    grd.GetLine += delegate (int r)
                    {
                        HistoryEntry he = (HistoryEntry)dataGridViewTravel.Rows[r].Tag;
                        he.journalEntry.FillInformation(out string EventDescription, out string EventDetailedInfo);
                        return new Object[] {
                            EDDConfig.Instance.ConvertTimeToSelectedFromUTC(he.EventTimeUTC),
                            he.EventSummary,
                            (he.System != null) ? he.System.Name : "Unknown",    // paranoia
                            he.WhereAmI,
                            he.ShipInformation != null ? he.ShipInformation.Name : "Unknown",
                            he.EventSummary,
                            EventDescription,
                            EventDetailedInfo,
                            dataGridViewTravel.Rows[r].Cells[4].Value,
                            he.isTravelling ? he.TravelledDistance.ToString("0.0") : "",
                            he.isTravelling ? he.TravelledSeconds.ToString() : "",
                            he.isTravelling ? he.Travelledjumps.ToString() : "",
                            he.isTravelling ? he.TravelledMissingjump.ToString() : "",
                            he.System.X,
                            he.System.Y,
                            he.System.Z,
                            he.Journalid,
                            he.System.EDSMID,
                            he.System.EDDBID,
                        };
                    };

                    if (frm.SelectedIndex == 2 || frm.SelectedIndex == 3)     // export notes
                    {
                        grd.VerifyLine += delegate (int r)      // second hook to reject line
                        {
                            HistoryEntry he = (HistoryEntry)dataGridViewTravel.Rows[r].Tag;
                            if (he.snc != null)
                            {
                                if (sysnotecache.Contains(he.snc))
                                    return false;
                                else
                                {
                                    if (frm.SelectedIndex == 3)
                                        sysnotecache.Add(he.snc);
                                    return true;
                                }
                            }
                            else
                                return false;
                        };
                    }
                }

                grd.GetHeader += delegate (int c)
                {
                    return (c < colh.Length && frm.IncludeHeader) ? colh[c] : null;
                };

                grd.WriteGrid(frm.Path, frm.AutoOpen, FindForm());
            }

        }

        #endregion
    }
}


text:
package com.isha.routes;

public class SigninResponse {

	private String token;

	public SigninResponse() {
		super();
		// TODO Auto-generated constructor stub
	}

	public SigninResponse(String token) {
		super();
		this.token = token;
	}

	public String getToken() {
		return token;
	}

	public void setToken(String token) {
		this.token = token;
	}

}

redpajama_set_name: RedPajamaGithub


text:
 Input string:
    <input type="text" id="inputString">
    <button type="submit" onclick="stringToArray()">Submit</button>


text:
A simple 1337 speak translator.

- Take english characters
- Downcase characters
- Converts vowels and consonants 'S' and 'T' to 1337 speak

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'leetize'
```

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install leetize

## Usage

    irb(main):001:0> require 'leetize'
    => true
    irb(main):002:0> Leetize.translate("Hello world!")
    => "h3ll0 w0rld!"

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/Cloudplement/leetize.

## Code Status

[![Build Status](https://travis-ci.org/Cloudplement/leetize.svg?branch=master)](https://travis-ci.org/Cloudplement/leetize) [![Code Climate](https://codeclimate.com/github/Cloudplement/leetize/badges/gpa.svg)](https://codeclimate.com/github/Cloudplement/leetize)

## License

The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).


text:
package kieker.tools.slastic.metamodel.componentDeployment.impl;

import kieker.tools.slastic.metamodel.componentDeployment.*;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;

import org.eclipse.emf.ecore.impl.EFactoryImpl;

import org.eclipse.emf.ecore.plugin.EcorePlugin;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model <b>Factory</b>.
 * <!-- end-user-doc -->
 * @generated
 */
public class ComponentDeploymentFactoryImpl extends EFactoryImpl implements ComponentDeploymentFactory {
	/**
	 * Creates the default factory implementation.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public static ComponentDeploymentFactory init() {
		try {
			ComponentDeploymentFactory theComponentDeploymentFactory = (ComponentDeploymentFactory)EPackage.Registry.INSTANCE.getEFactory("http:///metamodel/componentDeployment.ecore");
			if (theComponentDeploymentFactory != null) {
				return theComponentDeploymentFactory;
			}
		}
		catch (Exception exception) {
			EcorePlugin.INSTANCE.log(exception);
		}
		return new ComponentDeploymentFactoryImpl();
	}

	/**
	 * Creates an instance of the factory.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ComponentDeploymentFactoryImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public EObject create(EClass eClass) {
		switch (eClass.getClassifierID()) {
			case ComponentDeploymentPackage.DEPLOYMENT_COMPONENT: return createDeploymentComponent();
			case ComponentDeploymentPackage.COMPONENT_DEPLOYMENT_MODEL: return createComponentDeploymentModel();
			default:
				throw new IllegalArgumentException("The class '" + eClass.getName() + "' is not a valid classifier");
		}
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public DeploymentComponent createDeploymentComponent() {
		DeploymentComponentImpl deploymentComponent = new DeploymentComponentImpl();
		return deploymentComponent;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ComponentDeploymentModel createComponentDeploymentModel() {
		ComponentDeploymentModelImpl componentDeploymentModel = new ComponentDeploymentModelImpl();
		return componentDeploymentModel;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ComponentDeploymentPackage getComponentDeploymentPackage() {
		return (ComponentDeploymentPackage)getEPackage();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @deprecated
	 * @generated
	 */
	@Deprecated
	public static ComponentDeploymentPackage getPackage() {
		return ComponentDeploymentPackage.eINSTANCE;
	}

} //ComponentDeploymentFactoryImpl


text:
'use strict'

require('../css/user/create.css')
require('../js/user/create.js')
require('../js/public/user_bar.js')


text:
title: 'Update Notarizations'
taxonomy:
    category:
        - docs
---

## How to Update Notarizations
With the previous example, it's clear that tampering with a file's content will cause it to fail the content's hash check when we try to verify it on Apostille. This is an amazing security feature that protects against unauthorized edits to a file. However, **authorized** updates by the owner (or group of owners) to a document are possible, and they leave a transparent audit trail.

The file below was modified as you can see from its date and does not pass an audit.
It's my file from before, and I need to update the changes...

![](Update%20Notarizations1.jpg)

On the Services page select Apostille History and you should find your document there along with the Update button. Note that there are two publicly notarized files, which don't have any buttons. The reason for this is because these files were publicly notarized and transferred to a public sync account so they cannot be updated or transferred.

![](Update%20Notarizations2.jpg)

Enter your password and upload a new version of the file with the original filename. You will be prompted to download your updated Apostille.

![](Update%20Notarizations3.jpg)

If you go to your Apostille history again, you will see the updated notarization on top of the list, with a new file hash.

![](Update%20Notarizations4.jpg)


text:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<feed><tipo>Rua</tipo><logradouro>Angá</logradouro><bairro>Vila Formosa</bairro><cidade>São Paulo</cidade><uf>SP</uf><cep>03360000</cep></feed>


text:
title:  Un gând de încheiere
date:  04/02/2022
---

"Scopul lui Satana era acela de a produce o despărţire veşnică între Dumnezeu şi om, însă, în Hristos, ajungem mult mai strâns uniţi cu Dumnezeu decât dacă n-am fi căzut niciodată în păcat. Luând natura noastră, Mântuitorul S-a legat de omenire cu o legătură ce nu se va rupe niciodată […] Aceasta era garanţia că Dumnezeu Îşi va împlini Cuvântul. «Un Copil ni s-a născut, un Fiu ni s-a dat şi domnia va fi pe umărul Lui.» Dumnezeu a adoptat natura omenească în persoana Fiului Său şi a dus-o în cerul preaînalt. «Fiul omului» este Cel care are parte la tronul universului. «Fiul omului» este Acela pe care-L vor numi: «Minunat, Sfetnic, Dumnezeu tare, Părintele veşniciilor, Domn al păcii» (Isaia 9:6). EU SUNT este Mijlocitorul între Dumnezeu şi neamul omenesc, unindu-i prin mâinile Sale întinse. Acela care este «sfânt, nevinovat, fără pată, despărţit de păcătoşi» nu Se ruşinează să ne numească fraţi (Evrei 7:26; 2:11). În Hristos, familia pământească şi familia cerească sunt legate.

Hristos glorificat este Fratele nostru. Cerul este învelit în corp omenesc şi neamul omenesc este strâns la sânul Iubirii Infinite." – Ellen G. White, Hristos, Lumina lumii/Viaţa lui Iisus, pp. 25, 26.

STUDIU LA RÂND – BIBLIA ŞI CARTEA EVANGHELIZARE

**Biblia: Geneza 10-16, Evanghelizare**

`1. Cum se numea întâiul născut al lui Canaan?`

`2. Ce a căpătat Avram din pricina Sarei în Egipt?`

`3. Ce gest cu mâna a făcut Avram când a jurat în faţa împăratului Sodomei?`

`4. Cine avea să fie ca un măgar sălbatic printre oameni?`

Evanghelizare, Secţiunea 17, subcapitolul "Lucrarea de evanghelizare pentru copii"

`5. Care două elemente trebuie combinate în activitatea pentru copii?`


text:
<?php
class Ticket897 extends TPage {

	public function onButtonClicked($sender, $param) {
		$this->Output->Text = date('Y-m-d', $this->Date->TimeStamp);
	}

}


text:
package akka.persistence.jdbc.dao

import akka.persistence.jdbc.TestSpec

class SlickSnapshotDaoTest extends TestSpec {
  it should "" in {
  }
}


text:
//
//  BFTask+Notification.h
//  Pods
//
//  Created by Felix Dumit on 11/30/16.
//
//

#import <Bolts/BFTask.h>

@interface NSNotificationCenter (Bolts)

/**
 Waits for NSNotification to post notification named

 @param notificationName notificationName name of the notification to be waited on
 @param object to observe the notification
 @return a task that completes when the notification is posted, the result contains the userInfo of the notification
 */
-(BFTask*)waitForNotificationNamed:(NSString*)notificationName object:(id)object;

-(BFTask<NSNotification*>*)waitForNotificationNamed:(NSString*)notificationName;

@end


text:
import fs from 'fs'
import path from 'path'

import { run, css } from './util/run'

test('important boolean', () => {
  let config = {
    important: true,
    darkMode: 'class',
    content: [path.resolve(__dirname, './important-boolean.test.html')],
    corePlugins: { preflight: false },
    plugins: [
      function ({ addComponents, addUtilities }) {
        addComponents(
          {
            '.btn': {
              button: 'yes',
            },
          },
          { respectImportant: true }
        )
        addComponents(
          {
            '@font-face': {
              'font-family': 'Inter',
            },
            '@page': {
              margin: '1cm',
            },
          },
          { respectImportant: true }
        )
        addUtilities(
          {
            '.custom-util': {
              button: 'no',
            },
          },
          { respectImportant: false }
        )
      },
    ],
  }

  let input = css`
    @tailwind base;
    @tailwind components;
    @layer components {
      .custom-component {
        @apply font-bold;
      }
      .custom-important-component {
        @apply text-center !important;
      }
    }
    @tailwind utilities;
  `

  return run(input, config).then((result) => {
    let expectedPath = path.resolve(__dirname, './important-boolean.test.css')
    let expected = fs.readFileSync(expectedPath, 'utf8')

    expect(result.css).toMatchFormattedCss(expected)
  })
})


text:
#ifndef _FTAPE_READ_H
#define _FTAPE_READ_H

/*      ftape-read.c defined global vars.
 */

/*      ftape-read.c defined global functions.
 */
extern int _ftape_read(char *buff, int req_len);
extern int read_header_segment(byte * address);
extern int read_segment(unsigned segment, byte * address, int *eof_mark,
			int read_ahead);
extern void ftape_zap_read_buffers(void);

#endif				/* _FTAPE_READ_H */


text:
var url = "https://spreadsheets.google.com/feeds/list/1FDj0f6QfSqkge9lr2ifXoLFQOnMs9z9iDhkA9h42jCA/od6/public/values?alt=json";

 // array per contenere i dati/oggetto
var dati = [];
var scala = 20;

var distribution = new Array(360);

function setup() {

  pixelDensity(displayDensity());
  createCanvas(windowWidth, windowHeight);

  // richiedi i dati formato JSON e poi chiama la funzione gotSpreadsheet
  loadJSON(url, gotSpreadsheet);
  //print("ciao");
  colorMode(RGB);
  rectMode(CENTER);

} // setup()

function draw() {

frameRate(60);
background(255);

push();

fill(80);
textStyle (BOLD);
textFont("Roboto");
textSize(28);
text("DEATH VIRUS", 230, 100);
textStyle (NORMAL);
textSize(14);
text("Mortality by Influence in Italy", 232, 120);
textStyle (NORMAL);
textSize(10);
text("2006 - 2011", 170, 140);

pop();

// piccolo loop per verificare di avere i dati,
// stampa su schermo cerchi con i colori presenti nel google doc

  var padding = width/(dati.length+1);
  var padding2 = height/(dati.length+1);

  for (var i = 0; i < dati.length; i++) {

  var r2 = random (0,1);
  var r = random (0,1);

  var ellipsexd = padding + i *padding + r+40;
  var ellipseyd = height/2+r2;

  var ellipsex = padding + i * padding +r;
  var ellipsey = height/2 +r2;

  var ellipsew = 3;

  var testoy = height/2 +r2+160;
  var testox = padding + i * padding +r;

  var testoypro = height/2 +160;
  var testoxpro = padding + i * padding ;

  if (mouseX >= testoxpro-60 && mouseX <= testoxpro+20 && mouseY >= testoypro-30 && mouseY <= testoypro+10) {
    // fill(255,0,0,255);
    // rect(0,0, 200, 200);

        push();

        fill(0);
        textFont("Roboto");
        textSize(34);
        textAlign(CENTER);
        text(dati[i].anno, testoxpro-20, testoypro);

        textAlign(CENTER, TOP);
        textFont("Roboto");

        fill(65,105,225);

        textSize(25);
        text(dati[i].decuomini, testoxpro-49, testoypro+30);
        textSize(14);
        text("Uomini", testoxpro-49, testoypro+60);

        fill(249,132,229);

        textSize(25);
        text(dati[i].decdonne, testoxpro+11, testoypro+30);
        textSize(14);
        text("Donne", testoxpro+11, testoypro+60);

        for (var j = 0; j < dati[i].decuomini; j++){

            fill(65,105,225);
            ellipse(ellipsex+random(20)-50, ellipsey-random(dati[i].decuomini)+100, ellipsew,ellipsew);

        }

        for (var j = 0; j < dati[i].decdonne; j++){

            fill(249,132,229);
            ellipse(ellipsexd+random(25)-50, ellipseyd-random(dati[i].decdonne)+100, ellipsew,ellipsew);

        }

        pop();

      } else {

    fill(120);
    textFont("Roboto");
    textSize(28);
    text(dati[i].anno, testoxpro-20, testoypro);

    fill(170);

    for (var j = 0; j < dati[i].dectotale; j++){

    ellipse(ellipsex+random(60)-50, ellipsey-random(dati[i].decuomini)+100, ellipsew,ellipsew);

    }

  }

    noStroke();
    textAlign(CENTER);

  }

}

// draw()

function gotSpreadsheet(colori) {
  println(colori.feed.entry.length); // < debug, numero righe della tabella
  for (var i = 0; i < colori.feed.entry.length; i++) {
    // costruzione dell'oggetto singolo, la riga
    var colore = {
                  // dati, nomi delle colonne, i parametri
                  "anno": colori.feed.entry[i].gsx$anno.$t,
                  "decuomini": colori.feed.entry[i].gsx$decuomini.$t,
                  "decdonne": colori.feed.entry[i].gsx$decdonne.$t,
                  "popolazioneu": colori.feed.entry[i].gsx$popolazioneu.$t,
                  "popolazioned": colori.feed.entry[i].gsx$popolazioned.$t,
                  "tassou": colori.feed.entry[i].gsx$tassou.$t,
                  "tassod": colori.feed.entry[i].gsx$tassod.$t,
                  "dectotale": colori.feed.entry[i].gsx$dectotale.$t,

              }
              println(colore); // < debug, verifica oggetto 1x1

    dati.push(colore); // < inserimento nell'array del dato
  }
} // gotSpreadsheet(colori)

// se ridimensiona la finestra ricalcola width e height canvas
function windowResized() {
  resizeCanvas(windowWidth, windowHeight);
}


text:
breadpool.tests package
=======================

Submodules
----------

breadpool.tests.test_pool module
--------------------------------

.. automodule:: breadpool.tests.test_pool
    :members:
    :undoc-members:
    :show-inheritance:

breadpool.tests.testutil module
-------------------------------

.. automodule:: breadpool.tests.testutil
    :members:
    :undoc-members:
    :show-inheritance:

Module contents
---------------

.. automodule:: breadpool.tests
    :members:
    :undoc-members:
    :show-inheritance:


text:
(function() {

	var SpeedMatch = {};
	SpeedMatch.init = function(ctn) {
		var html = ['
SpeedMatch----Thanks http://mootools.net/slickspeed

stop testsstart tests
'],
			titles = [];
		for (var i = 0; i < SpeedMatchConfig.players.length; i++) {
			var player = SpeedMatchConfig.players[i];
			html.push('');
			titles.push(player.title);
		}
		html.push('

cases	', titles.join('	'), '

', '

', SpeedMatchConfig.cases.join('	' + new Array(titles.length + 1).join('	', '') + '

', ''), '	' + new Array(titles.length + 1).join('	', '') + '

', '

final time (less is better)	', new Array(titles.length + 1).join('0	', ''), '

', '
', '
Legend
', '

the faster	the slower	exception thrown or zero elements found	different returned elements
', '

', '
');
		//document.write(html.join(''));
		ctn.innerHTML = html.join('');
		forEach(document.getElementsByTagName('iframe'), function(el, i) {
			el.src = SpeedMatchConfig.players[i].url;
			SpeedMatchConfig.players[i].iframeEl = el;
		});
	};

	function forEach(iterable, fn, bind) {
		for (var i = 0, j = iterable.length; i < j; i++) fn.call(bind, iterable[i], i, iterable);
	}

	//test start

	window.onload = function() {
		setTimeout(function() {
			var players = SpeedMatchConfig.players,
				cases = SpeedMatchConfig.cases;

			var frameworks = {};

			forEach(players, function(player) {
				try {
					player.test = window.frames[player.iframeEl.name].test;
				} catch (ex) {
					alert(player.title + ' is not ready.');
				}
			});

			var tbody = document.getElementById('tbody');
			var tfoot = document.getElementById('tfoot');
			var lastrow = tfoot.getElementsByTagName('tr')[0];

			var controls = document.getElementById('controls');

			var links = controls.getElementsByTagName('a');

			var start = links[1];
			var stop = links[0];

			start.onclick = function() {
				testRunner();
				return false;
			};

			stop.onclick = function() {
				clearTimeout(timer);
				timer = null;
				return false;
			};

			var score = [];
			var scores = [];

			for (var i = 0; i < players.length; i++) {
				scores[i] = lastrow.getElementsByTagName('td')[i];
				score[i] = 0;
			}

			var tests = [];

			forEach(cases, function(matchcase, i) {
				var row = tbody.getElementsByTagName('tr')[i];
				for (var name = 0; name < players.length; name++) {
					var player = players[name];
					var cell = row.getElementsByTagName('td')[name];
					tests.push({
						'execute': player.test,
						'matchcase': matchcase,
						'name': name,
						'row': row,
						'cell': cell
					});
				}
			});

			var timer = null;

			var testRunner = function() {
				var test = tests.shift();
				if (!test) return;
				var d0 = new Date();
				var ex = '';
				try {
					var results = test.execute(test.matchcase);
				} catch (e) {
					ex = e;
				}
				var dDelta = new Date() - d0;
				test.cell.className = 'test';
				test.cell.innerHTML = dDelta + ' ms | ' + results;
				test.cell.speed = dDelta;
				if (ex) {
					test.cell.innerHTML = dDelta + ' ms | </g, '') + '">error returned';
					test.cell.className += ' exception';
					test.cell.found = results;
					test.cell.error = true;
				} else {
					test.cell.found = results;
					test.cell.error = false;
				}

				score[test.name] += test.cell.speed;
				scores[test.name].innerHTML = ' ' + score[test.name] + ' ';

				if (test.cell == test.row.lastChild) colourRow(test.row);
				timer = setTimeout(testRunner, 250);
			};

			var colourRow = function(row) {

				var cells = [];

				var tds = row.getElementsByTagName('td');
				forEach(tds, function(td) {
					cells.push(td);
				});

				var speeds = [];

				forEach(cells, function(cell, i) {
					if (!cell.error) speeds[i] = cell.speed;
					//error, so we exclude it from colouring good. does not affect score (it should?).
					else speeds[i] = 99999999999999999999999;
				});

				var min = Math.min.apply(this, speeds);
				var max = Math.max.apply(this, speeds);

				var found = [];
				var mismatch = false;
				forEach(cells, function(cell, i) {
					found.push(cell.found);
					if (!mismatch) {
						forEach(found, function(n) {
							if (!cell.error && cell.found != undefined && n && cell.found != n) {
								mismatch = true;
								return;
							}
						});
					}
					if (cell.speed == min) cell.className += ' good';
					else if (cell.speed == max) cell.className += ' bad';
					else cell.className += ' normal';
				});

				if (mismatch) {
					forEach(cells, function(cell, i) {
						if (cell.found != undefined) cell.className += ' mismatch';
					});
				}

			};

		}, 1000);
	};

	window.SpeedMatch = SpeedMatch;

}());


text:
title: Settings
product: remmina-plugin-ultravnc
depth: 1
---

# Basic tab

![Basic tab](/resources/remmina-plugin-ultravnc/archive/latest/english/general.png?classes=center)

## Server (server)
The server address to connect to.
## Password (password)
The password used to establish the connection.
## Force replace $ in \$ in the password (replacedollar)
Substitutues \$ in the password with just $, useful for some UltraVNC launchers.


text:
from pyknon.genmidi import Midi
from pyknon.music import Note

notes1 = [Note(value=0, octave=4).transposition(9),Note(value=2, octave=4).transposition(9)]
print(notes1)
midi = Midi(1, tempo=80)
midi.seq_notes(notes1, track=0)
midi.write("demo.mid")


text:
angular.module('search', [])

.controller('DocsSearchCtrl', ['$scope', '$location', 'docsSearch', function($scope, $location, docsSearch) {
  function clearResults() {
    $scope.results = [];
    $scope.colClassName = null;
    $scope.hasResults = false;
  }

  $scope.search = function(q) {
    var MIN_SEARCH_LENGTH = 2;
    if(q.length >= MIN_SEARCH_LENGTH) {
      docsSearch(q).then(function(hits) {
        var results = {};
        angular.forEach(hits, function(hit) {
          var area = hit.area;

          var limit = (area == 'api') ? 40 : 14;
          results[area] = results[area] || [];
          if(results[area].length < limit) {
            results[area].push(hit);
          }
        });

        var totalAreas = 0;
        for(var i in results) {
          ++totalAreas;
        }
        if(totalAreas > 0) {
          $scope.colClassName = 'cols-' + totalAreas;
        }
        $scope.hasResults = totalAreas > 0;
        $scope.results = results;
      });
    }
    else {
      clearResults();
    }
    if(!$scope.$$phase) $scope.$apply();
  };

  $scope.submit = function() {
    var result;
    for(var i in $scope.results) {
      result = $scope.results[i][0];
      if(result) {
        break;
      }
    }
    if(result) {
      $location.path(result.path);
      $scope.hideResults();
    }
  };

  $scope.hideResults = function() {
    clearResults();
    $scope.q = '';
  };
}])

.controller('Error404SearchCtrl', ['$scope', '$location', 'docsSearch',
        function($scope, $location, docsSearch) {
  docsSearch($location.path().split(/[\/\.:]/).pop()).then(function(results) {
    $scope.results = {};
    angular.forEach(results, function(result) {
      var area = $scope.results[result.area] || [];
      area.push(result);
      $scope.results[result.area] = area;
    });
  });
}])

.provider('docsSearch', function() {

  // This version of the service builds the index in the current thread,
  // which blocks rendering and other browser activities.
  // It should only be used where the browser does not support WebWorkers
  function localSearchFactory($http, $timeout, NG_PAGES) {

    console.log('Using Local Search Index');

    // Create the lunr index
    var index = lunr(function() {
      this.ref('path');
      this.field('titleWords', {boost: 50});
      this.field('members', { boost: 40});
      this.field('keywords', { boost : 20 });
    });

    // Delay building the index by loading the data asynchronously
    var indexReadyPromise = $http.get('js/search-data.json').then(function(response) {
      var searchData = response.data;
      // Delay building the index for 500ms to allow the page to render
      return $timeout(function() {
        // load the page data into the index
        angular.forEach(searchData, function(page) {
          index.add(page);
        });
      }, 500);
    });

    // The actual service is a function that takes a query string and
    // returns a promise to the search results
    // (In this case we just resolve the promise immediately as it is not
    // inherently an async process)
    return function(q) {
      return indexReadyPromise.then(function() {
        var hits = index.search(q);
        var results = [];
        angular.forEach(hits, function(hit) {
          results.push(NG_PAGES[hit.ref]);
        });
        return results;
      });
    };
  }
  localSearchFactory.$inject = ['$http', '$timeout', 'NG_PAGES'];

  // This version of the service builds the index in a WebWorker,
  // which does not block rendering and other browser activities.
  // It should only be used where the browser does support WebWorkers
  function webWorkerSearchFactory($q, $rootScope, NG_PAGES) {

    console.log('Using WebWorker Search Index')

    var searchIndex = $q.defer();
    var results;

    var worker = new Worker('js/search-worker.js');

    // The worker will send us a message in two situations:
    // - when the index has been built, ready to run a query
    // - when it has completed a search query and the results are available
    worker.onmessage = function(oEvent) {
      $rootScope.$apply(function() {

        switch(oEvent.data.e) {
          case 'index-ready':
            searchIndex.resolve();
            break;
          case 'query-ready':
            var pages = oEvent.data.d.map(function(path) {
              return NG_PAGES[path];
            });
            results.resolve(pages);
            break;
        }
      });
    };

    // The actual service is a function that takes a query string and
    // returns a promise to the search results
    return function(q) {

      // We only run the query once the index is ready
      return searchIndex.promise.then(function() {

        results = $q.defer();
        worker.postMessage({ q: q });
        return results.promise;
      });
    };
  }
  webWorkerSearchFactory.$inject = ['$q', '$rootScope', 'NG_PAGES'];

  return {
    $get: window.Worker ? webWorkerSearchFactory : localSearchFactory
  };
})

.directive('focused', function($timeout) {
  return function(scope, element, attrs) {
    element[0].focus();
    element.on('focus', function() {
      scope.$apply(attrs.focused + '=true');
    });
    element.on('blur', function() {
      // have to use $timeout, so that we close the drop-down after the user clicks,
      // otherwise when the user clicks we process the closing before we process the click.
      $timeout(function() {
        scope.$eval(attrs.focused + '=false');
      });
    });
    scope.$eval(attrs.focused + '=true');
  };
})

.directive('docsSearchInput', ['$document',function($document) {
  return function(scope, element, attrs) {
    var ESCAPE_KEY_KEYCODE = 27,
        FORWARD_SLASH_KEYCODE = 191;
    angular.element($document[0].body).on('keydown', function(event) {
      var input = element[0];
      if(event.keyCode == FORWARD_SLASH_KEYCODE && document.activeElement != input) {
        event.stopPropagation();
        event.preventDefault();
        input.focus();
      }
    });

    element.on('keydown', function(event) {
      if(event.keyCode == ESCAPE_KEY_KEYCODE) {
        event.stopPropagation();
        event.preventDefault();
        scope.$apply(function() {
          scope.hideResults();
        });
      }
    });
  };
}]);


text:
// Package wait provides tools for polling or listening for changes
// to a condition.
package wait // import "k8s.io/apimachinery/pkg/util/wait"


text:
package org.hswebframework.web.file.web;

import org.hswebframework.web.file.FileServiceConfiguration;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.HttpEntity;
import org.springframework.http.MediaType;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.reactive.server.WebTestClient;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.BodyInserters;

import static org.junit.Assert.*;

@WebFluxTest(ReactiveFileController.class)
@RunWith(SpringRunner.class)
@ImportAutoConfiguration(FileServiceConfiguration.class)
public class ReactiveFileControllerTest {

    static {
        System.setProperty("hsweb.file.upload.static-file-path","./target/upload");
//        System.setProperty("hsweb.file.upload.use-original-file-name","true");
    }

    @Autowired
    WebTestClient client;

    @Test
    public void test(){
       client.post()
                .uri("/file/static")
               .contentType(MediaType.MULTIPART_FORM_DATA)
               .body(BodyInserters.fromMultipartData("file",new HttpEntity<>(new ClassPathResource("test.json"))))
               .exchange()
                .expectStatus()
               .isOk();

    }
}


text:
<?php

namespace backend\controllers;
use yii\web\Controller;
use yii\data\Pagination;
use backend\models\Country;

class CountryController extends Controller{
    public function actionIndex(){
        $query = Country::find();
        $pagination = new Pagination([
            'defaultPageSize'=> 5,
            'totalCount'=>$query->count()
        ]);

        $countries = $query->orderBy('name')
            ->offset($pagination->offset)
            ->limit($pagination->limit)
            ->all();
        return $this->render('index', [
                'countries'=>$countries,
                'pagination'=>$pagination
            ]);
    }
}


text:
' Copyright (c) Microsoft. All rights reserved.

Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Net.Http
Imports Windows.ApplicationModel.Background
Imports Windows.Devices.Enumeration
Imports Windows.Devices.I2C
Imports Windows.System.Threading
' The Background Application template is documented at http://go.microsoft.com/fwlink/?LinkID=533884&clcid=0x409

Public NotInheritable Class StartupTask
	Implements IBackgroundTask
    Dim deferral As BackgroundTaskDeferral
    Dim sensor As I2cDevice
    Dim timer As ThreadPoolTimer
    Public Async Sub Run(taskInstance As IBackgroundTaskInstance) Implements IBackgroundTask.Run
        deferral = taskInstance.GetDeferral()
        Dim aqs = I2cDevice.GetDeviceSelector("I2C1")
        Dim dis As IReadOnlyList(Of DeviceInformation) = Await DeviceInformation.FindAllAsync(aqs)

        sensor = Await I2cDevice.FromIdAsync(dis(0).Id, New I2cConnectionSettings(&H40))
        timer = ThreadPoolTimer.CreatePeriodicTimer(AddressOf Timer_Tick, TimeSpan.FromSeconds(2))

    End Sub

    Public Sub Timer_Tick(timer As ThreadPoolTimer)
        Dim tempCommand(0 To 0) As Byte
        tempCommand(0) = &HE3
        Dim tempData(0 To 1) As Byte
        sensor.WriteRead(tempCommand, tempData)
        Dim byte0 As Int32 = tempData(0)
        Dim byte1 As Int32 = tempData(1)
        Dim rawReading As Short = byte0 << 8 Or byte1
        Dim tempRatio As Double = rawReading / 65536.0
        Dim temperature As Double = (-46.85 + (175.72 * tempRatio)) * 9.0 / 5.0 + 32
        System.Diagnostics.Debug.WriteLine("Temp: " + temperature.ToString())

        Dim humidityCommand(0 To 0) As Byte
        humidityCommand(0) = &HE5
        Dim humidityData(0 To 1) As Byte
        sensor.WriteRead(humidityCommand, humidityData)
        byte0 = humidityData(0)
        byte1 = humidityData(1)
        rawReading = byte0 << 8 Or byte1
        Dim humidityRatio As Double = rawReading / 65536.0
        Dim humidity As Double = -6 + (125 * humidityRatio)
        System.Diagnostics.Debug.WriteLine("Humidity: " + humidity.ToString())

    End Sub
End Class


text:
In this test case you can check response codes from certain URLs. There is possibility of excluding individual codes, URLs and patterns (they are ignored by that test)
as well as including them (only them will be tested by that test). For more information about excluding/including see [[Status Codes Data Filters|StatusCodesDataFilters]].

If any code is filtered by certain test, the result is failure (see screenshot below).

![Status codes failure](assets/suiteReport/status-codes-failure.png)

Otherwise test's result is successful (like on the screenshot below).

![Status codes success](assets/suiteReport/status-codes-success.png)

Additionally, if [[excluding filter|StatusCodesDataFilters]] is used, excluded codes are presented in additional section.

##### What vulnerabilities it discovers
* All status codes with a number higher than 400 are potential errors and indicate that the resource that is used by a page is unreachable (e.g. a page logo image, a page layout css file)
* Status code errors affect SEO (e.g. google page ranking is lowered for pages with 404 status codes).


text:
<root>
  <node value="test_%complex-parameter.subparam3.value%" />
  <escape value="this%% should be escaped %%" />
</root>