Example #1
0
        public main()
        {
            Font = SystemFonts.MessageBoxFont;
            InitializeComponent();

            A.Initialize(this);
            ToolButton.toolTip = ToolCheckBox.toolTip = toolTip;
            Wait.form          = this;
            UI.LoadPreferences();
            focusTextbox.BackColor = horzSplitter.Panel1.BackColor = horzSplitter.Panel2.BackColor = vertSplitter.Panel1.BackColor = vertSplitter.Panel2.BackColor = UI.passiveBackColor;

            SuspendLayout();

            goButton = new ToolButton(bigButtonImages, 0, new EventHandler(OnRunClicked), null);
            goButton.SetText("Go");
            horzSplitter.Panel1.Controls.Add(goButton);
            addButton = new ToolButton(bigButtonImages, 7, new EventHandler(OnNewClicked), "New Query");
            horzSplitter.Panel1.Controls.Add(addButton);

            leftTabs                       = new NiceTabControl();
            leftTabs.MinHeight             = 32;
            leftTabs.ContextMenuStrip      = this.tabContextMenu;
            leftTabs.ImageList             = bigButtonImages;
            leftTabs.DropdownImageIndex    = 6;
            leftTabs.OnSelectedTabChanged += new EventHandler(OnLeftTabChanged);
            horzSplitter.Panel1.Controls.Add(leftTabs);

            rightTabs                       = new NiceTabControl();
            rightTabs.ImageList             = bigButtonImages;
            rightTabs.MinHeight             = 32;
            rightTabs.DropdownImageIndex    = 6;
            rightTabs.OnSelectedTabChanged += new EventHandler(OnRightTabChanged);
            rightTabs.AddTab("Structure", objectSplitter);   // , S.Get("showDatabaseObjects", true));
            rightTabs.AddTab("Query History", queryHistory); // , Settings.Get("showQueryHistory", false));
            rightTabs.AddTab("Log", logTextBox);             // , Settings.Get("showLog", false));
            horzSplitter.Panel2.Controls.Add(rightTabs);

            allObjectsTree = CreateObjectTree(objectSplitter.Panel2, "allObjectsTree", "All Objects");
            objectSplitter.Panel2.Controls.Add(allObjectsTree);
            activeObjectsTree = CreateObjectTree(objectSplitter.Panel1, "activeObjectsTree", "Active Objects");
            objectSplitter.Panel1.Controls.Add(activeObjectsTree);

            rowCount.Width  = FormsToolbox.GetTextWidth("00000000000000", Font);
            queryTime.Width = FormsToolbox.GetTextWidth(" 00:00 ", Font);
            rowCount.Text   = queryTime.Text = "";

            autoComplete = new AutoSuggest(this, editor);
            Controls.Add(autoComplete);

            editorHeader = new EditorHeader(this, autoComplete);
            horzSplitter.Panel1.Controls.Add(editorHeader);

            resultsList = new ResultsListView(this);
            resultsList.ContextMenuStrip = resultsMenu;
            vertSplitter.Panel2.Controls.Add(resultsList);
            Query.resultsList = resultsList;
            clipboardHelper   = new ClipboardHelper(editor, logTextBox, resultsList);

            queryHistory = new QueryListView();
            queryHistory.ContextMenuStrip = queryHistoryMenuStrip;
            horzSplitter.Panel2.Controls.Add(queryHistory);
            UpdateUIPreferences(false);

            Parser.onParsed = OnParsed;

            objectSplitter.SplitterWidth = vertSplitter.SplitterWidth = horzSplitter.SplitterWidth = 10;
            ResumeLayout();

            background.DoWork += new System.ComponentModel.DoWorkEventHandler(BackgroundInitialize);
            Background.status  = BackgroundStatus.Loading;
            background.RunWorkerAsync();

            Width  = Math.Max(600, T.Coalesce(S.initSettings.width, 900));
            Height = Math.Max(400, T.Coalesce(S.initSettings.height, 600));

            editor.MouseDown += new MouseEventHandler(OnEditorMouseDown);
            editor.KeyDown   += new KeyEventHandler(OnEditorKeyDown);
            editor.Leave     += new EventHandler(OnEditorLostFocus);
            timer.Tick       += OnIdle;

            loading = new Loading(this);
            StartBackgroundLoading();

            Application.Idle  += OnIdle;
            queryHistory.dirty = true;
        }
Example #2
0
        protected void OnIdle(Object sender, EventArgs e)
        {
            if (inIdle)
            {
                return;
            }

            if (loading.started)
            {
                loading.UpdateProgress();
                focusTextbox.Focus();
            }

            if (A.loading)
            {
                return;
            }

            if (A.currentStatus == Status.Closing)
            {
                return;
            }

            if (Background.status == BackgroundStatus.Loading)
            {
                return;
            }

            if (A.db == null)
            {
                return;
            }

            inIdle = true;
            idles++;
            if (loading.Visible)
            {
                if (!A.uiLoaded)
                {
                    UiLoad();
                }
                DoneLoading();
            }
            else if (A.ready)
            {
                int workDone = 0;
                editorHeader.OnIdle(selectedQuery);
                if (queryWaitCursorEnabled && A.currentStatus != Status.Executing)
                {
                    Cursor = Cursors.Default;
                    editor.UseWaitCursor   = false;
                    queryWaitCursorEnabled = false;
                    goButton.SetText("Go", 0);
                }
                else if (queryWaitCursorEnabled && Cursor != Cursors.WaitCursor)
                {
                    queryWaitCursorEnabled = true;
                    Cursor = Cursors.WaitCursor;
                    editor.UseWaitCursor = true;
                    goButton.Cursor      = Cursors.Default;
                }
                if (A.currentStatus == Status.LoadingRows)
                {
                    UpdateProgress();
                    workDone += 5;
                }
                if (layoutDirty)
                {
                    layoutDirty = false;
                    UpdateLeftPanelLayout();
                    UpdateRightPanelLayout();
                    workDone += 5;
                }
                if (tabsDirty)
                {
                    UpdateLeftTabs();
                    workDone++;
                }
                if (tabPositionsDirty)
                {
                    SaveTabPositions();
                    workDone += 1;
                }
                if (resultsList.resultsReady)
                {
                    resultsList.LoadResults();
                    workDone           += 10;
                    allObjectsTreeDirty = true;
                }
                if (resultsList.lastColumnDirty)
                {
                    resultsList.UpdateLastColumn();
                    workDone++;
                }
                if (parseViewsDirty)
                {
                    UpdateParseViews();
                    workDone += 10;
                }
                if (queryHistory != null && queryHistory.dirty)
                {
                    queryHistory.UpdateQueryHistory();
                    workDone += 10;
                }
                if (workDone < 20)
                {
                    if (allObjectsTreeDirty)
                    {
                        allObjectsTreeDirty = false;
                        // activeObjectsTree.tree.UpdateObjects(false);
                        allObjectsTree.tree.UpdateObjects(false);
                        workDone += 10;
                    }

                    if (objectTreesDirty)
                    {
                        objectTreesDirty = false;
                        activeObjectsTree.tree.UpdateObjects(true);
                        allObjectsTree.tree.UpdateObjects(true);
                    }

                    if (queryHistory.columnWidthsDirty >= 0)
                    {
                        queryHistory.UpdateColumnWidths();
                    }
                    if (Environment.TickCount - lastStatusUpdate > 500)
                    {
                        UpdateStatusBar();
                        workDone += 2;
                    }
                    activeObjectsTree.OnIdle();
                    if (maximizedChanged != 0 && Environment.TickCount - maximizedChanged > 1000)
                    {
                        Settings.initSettings.maximized = WindowState == FormWindowState.Maximized;
                        maximizedChanged = 0;
                    }
                    if (Parser.suggestionsReady)
                    {
                        Parser.suggestionsReady = false;
                        editorHeader.UpdateSuggestions();
                    }

                    if (WriteMessagesToLog() > 10)
                    {
                        workDone += 10;
                    }

                    if (workDone == 0)
                    {
                        if (Parser.OnIdle(editor.Text, editor.CurrentPosition))
                        {
                            workDone += 5;
                        }
                    }

                    if (workDone == 0)
                    {
                        resultsList.FixForScroll();
                    }
                }
            }
            inIdle = false;
        }