Exemplo n.º 1
0
        private void btnClose_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(currentTab?.scintilla.Text))
            {
                if (DialogResult.OK != MessageBox.Show(this, "Close this tab will delete its current contents, are you sure?", "Please confirm", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
                {
                    return;
                }
            }
            ExpressionTab tab = currentTab;

            int index = tabsLeft.SelectedIndex;

            tabsLeft.Controls.Remove(tab);
            DataTable dt = gridFiles.DataSource as DataTable;

            if (dt != null)
            {
                dt.Columns.Remove(tab.ID);
            }

            if (tabsLeft.TabCount == 0)
            {
                AddExpressionTab();
            }

            if (index >= tabsLeft.TabCount)
            {
                index = tabsLeft.TabCount - 1;
            }
            tabsLeft.SelectedIndex = index;

            reorderDatagridColumns();
        }
Exemplo n.º 2
0
        private ExpressionTab AddExpressionTab(string name = null, string content = null, int pos = -1)
        {
            if (name == null)
            {
                // find free name
                int      n     = tabsLeft.TabCount + 1;
                string[] names = expressionTabs.Select(t => t.Text).ToArray();
                while (names.Contains($"expr{n}"))
                {
                    n++;
                }
                name = $"expr{n}";
            }

            var tab = new ExpressionTab(name, settings);

            tab.highlighter        = new ELSyntax(jrAPI.FieldsHighlight, settings.ExtraFunctions);
            tab.jrAPI              = jrAPI;
            tab.Paused             = paused;
            tab.ZoomChanged       += expression_ZoomChanged;
            tab.ExpressionChanged += expression_TextChanged;
            tab.FunctionChanged   += expression_FunctionChanged;

            if (content != null)
            {
                tab.scintilla.Text = content;
            }
            if (pos >= 0)
            {
                tab.scintilla.GotoPosition(pos);
            }
            tabsLeft.TabPages.Add(tab);

            DataTable dt = gridFiles.DataSource as DataTable;

            if (dt != null)
            {
                dt.Columns.Add(tab.ID);
                gridFiles.Columns[tab.ID].HeaderText = tab.Text;
                gridFiles.Columns[tab.ID].SortMode   = DataGridViewColumnSortMode.NotSortable;
                reorderDatagridColumns();
            }

            tabsLeft.SelectedTab = tab;
            tab.scintilla.EmptyUndoBuffer();
            tab.scintilla.Focus();
            tab.Evaluate(currentFile);
            return(tab);
        }
Exemplo n.º 3
0
        void UpdateDatagrid(ExpressionTab tab, string expression)
        {
            // get visible rows to fetch them first
            int       first = gridFiles.FirstDisplayedScrollingRowIndex;
            int       count = gridFiles.DisplayedRowCount(true);
            DataTable data  = gridFiles.DataSource as DataTable;

            if (data == null)
            {
                return;
            }
            if (!data.Columns.Contains(tab.ID))
            {
                return;
            }

            List <JRFile> visible = new List <JRFile>();

            for (int i = first - 1; i <= first + count; i++)
            {
                if (i >= 0 && i < gridFiles.Rows.Count)
                {
                    visible.Add(gridFiles.Rows[i].Cells[0].Value as JRFile);
                }
            }

            // make list of rows - visible first
            List <DataRow> rows = new List <DataRow>();

            foreach (DataRow row in data.Rows)
            {
                if (visible.Contains(row[0] as JRFile))
                {
                    rows.Add(row);
                }
            }
            foreach (DataRow row in data.Rows)
            {
                if (!visible.Contains(row[0] as JRFile))
                {
                    rows.Add(row);
                }
            }

            Task.Run(() =>
            {
                // calculate expression and populate data
                Stopwatch sw            = new Stopwatch();
                List <object[]> rowData = new List <object[]>();
                int currRow             = 0;
                bool isEmpty            = string.IsNullOrWhiteSpace(expression);
                foreach (DataRow row in rows)
                {
                    if (tab.changed)
                    {
                        return;
                    }
                    //if (changed) return;  // TODO!!!! cancel current processing on changes
                    if (settings.ShowAPICallTime)
                    {
                        sw.Restart();
                    }
                    string value = isEmpty ? expression : jrAPI.resolveExpression(row[0] as JRFile, expression);
                    if (settings.ShowAPICallTime)
                    {
                        sw.Stop();
                    }
                    double time = settings.ShowAPICallTime && !isEmpty ? TimeSpan.FromTicks(sw.ElapsedTicks).TotalMilliseconds : 0;

                    rowData.Add(new object[] { row, value, time });
                    if (++currRow % 100 == 0)
                    {
                        var copy = new List <object[]>(rowData);
                        BeginInvoke(new MethodInvoker(() => UpdateDatagrid(tab.ID, copy)));
                        rowData.Clear();
                    }
                }
                BeginInvoke(new MethodInvoker(() => UpdateDatagrid(tab.ID, rowData)));
            });
        }