コード例 #1
0
        public static bool OpenSharedScript(IPragmaEditor currentEditor, ConnectionParams cp)
        {
            if (currentEditor != null && currentEditor.ContentModified)
            {
                DialogResult dlgRes = MessageBox.Show("Save changes to \"" + currentEditor.Caption + "\" before opening another script in current script editor", "Save Script", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                if (dlgRes == DialogResult.Cancel)
                {
                    return(false);
                }
                else if (dlgRes == DialogResult.Yes)
                {
                    currentEditor.SaveContent();
                }
            }

            SharedScriptsItemData data = frmSharedScriptSelectDialog.ShowOpenSharedScriptDialog_SingleSelect();

            if (data != null && currentEditor != null)
            {
                currentEditor.Caption                    = data.Name;
                currentEditor.Icon                       = PragmaSQL.Properties.Resources.sharedScript;
                currentEditor.ContentPersister           = new SharedScriptContentPersister();
                currentEditor.ContentPersister.Data      = data;
                currentEditor.ContentPersister.Hint      = "This is a shared script: " + data.Name;
                currentEditor.ContentInfo                = currentEditor.ContentPersister.Hint;
                currentEditor.ContentPersister.FilePath  = data.Name;
                currentEditor.ActiveDocument.TextContent = data.Script;
                currentEditor.ContentModified            = false;
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #2
0
ファイル: frmSaveScripts.cs プロジェクト: Eisai/pragmasql
        private static bool CheckIfShallShow(DockPanel dockPanel, IPragmaEditor skipThis)
        {
            bool result = false;
            int  cnt    = 0;

            if (dockPanel != null)
            {
                if (dockPanel.DocumentStyle == DocumentStyle.SystemMdi)
                {
                    foreach (Form form in Program.MainForm.MdiChildren)
                    {
                        if (form is IPragmaEditor && form != skipThis)
                        {
                            if ((form as IPragmaEditor).ContentModified)
                            {
                                return(true);
                            }
                        }
                    }
                }
                else
                {
                    IList <IDockContent> contents = new List <IDockContent>();

                    foreach (FloatWindow wnd in dockPanel.FloatWindows)
                    {
                        foreach (DockPane pane in wnd.NestedPanes)
                        {
                            foreach (IDockContent content in pane.Contents)
                            {
                                if (!contents.Contains(content) && (content is IPragmaEditor) && content != skipThis)
                                {
                                    contents.Add(content);
                                    if ((content as IPragmaEditor).ContentModified)
                                    {
                                        return(true);
                                    }
                                }
                            }
                        }
                    }

                    IDockContent[] docs = dockPanel.DocumentsToArray();
                    foreach (IDockContent content in docs)
                    {
                        if (!contents.Contains(content) && (content is IPragmaEditor) && content != skipThis)
                        {
                            if ((content as IPragmaEditor).ContentModified)
                            {
                                return(true);
                            }
                        }
                    }
                }
            }
            return(result);
        }
コード例 #3
0
ファイル: frmSaveScripts.cs プロジェクト: Eisai/pragmasql
        public static DialogResult ShowSaveScriptsDialog(DockPanel dockPanel, IPragmaEditor skipThis)
        {
            if (!CheckIfShallShow(dockPanel, skipThis))
            {
                return(DialogResult.Ignore);
            }

            frmSaveScripts frm = new frmSaveScripts();

            frm.PopulateList(dockPanel, skipThis);
            return(frm.ShowDialog());
        }
コード例 #4
0
ファイル: frmSaveScripts.cs プロジェクト: Eisai/pragmasql
 private void btnSaveChecked_Click(object sender, EventArgs e)
 {
     foreach (ListViewItem item in lv.Items)
     {
         IPragmaEditor editor = item.Tag as IPragmaEditor;
         if (item.Checked)
         {
             editor.SaveContent();
         }
         editor.CheckSave = false;
     }
     DialogResult = DialogResult.OK;
 }
コード例 #5
0
ファイル: frmSaveScripts.cs プロジェクト: Eisai/pragmasql
        private void btnSkipAll_Click(object sender, EventArgs e)
        {
            DialogResult dlgRes = MessageBox.Show("Do you really want to skip changes?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);

            if (dlgRes == DialogResult.No)
            {
                return;
            }

            foreach (ListViewItem item in lv.Items)
            {
                IPragmaEditor editor = item.Tag as IPragmaEditor;
                editor.CheckSave = false;
            }
            DialogResult = DialogResult.Ignore;
        }
コード例 #6
0
ファイル: frmSaveScripts.cs プロジェクト: Eisai/pragmasql
        public void PopulateList(DockPanel dockPanel, IPragmaEditor skipThis)
        {
            if (dockPanel != null)
            {
                if (dockPanel.DocumentStyle == DocumentStyle.SystemMdi)
                {
                    foreach (Form form in Program.MainForm.MdiChildren)
                    {
                        if (form is IPragmaEditor && form != skipThis)
                        {
                            AddToList(form as IPragmaEditor);
                        }
                    }
                }
                else
                {
                    IList <IDockContent> contents = new List <IDockContent>();
                    foreach (FloatWindow wnd in dockPanel.FloatWindows)
                    {
                        foreach (DockPane pane in wnd.NestedPanes)
                        {
                            foreach (IDockContent content in pane.Contents)
                            {
                                if (!contents.Contains(content) && (content is IPragmaEditor) && content != skipThis)
                                {
                                    if ((content as IPragmaEditor).ContentModified)
                                    {
                                        contents.Add(content);
                                        AddToList(content as IPragmaEditor);
                                    }
                                }
                            }
                        }
                    }

                    IDockContent[] docs = dockPanel.DocumentsToArray();
                    foreach (IDockContent content in docs)
                    {
                        if (!contents.Contains(content) && (content is IPragmaEditor) && content != skipThis)
                        {
                            AddToList(content as IPragmaEditor);
                        }
                    }
                }
            }
        }
コード例 #7
0
        public static bool SaveAsSharedScript(IPragmaEditor currentEditor, string itemName)
        {
            if (currentEditor == null)
            {
                return(false);
            }

            SharedScriptsItemData savedItemData = frmSharedScriptSelectDialog.ShowSaveSharedScriptDialog(currentEditor.ActiveDocument.TextContent, currentEditor.Caption);

            if (savedItemData == null)
            {
                return(false);
            }
            currentEditor.Caption                   = savedItemData.Name;
            currentEditor.Icon                      = PragmaSQL.Properties.Resources.sharedScript;
            currentEditor.ContentPersister          = new SharedScriptContentPersister();
            currentEditor.ContentPersister.Data     = savedItemData;
            currentEditor.ContentPersister.Hint     = "This is a shared script: " + savedItemData.Name;
            currentEditor.ContentInfo               = currentEditor.ContentPersister.Hint;
            currentEditor.ContentPersister.FilePath = savedItemData.Name;

            return(true);
        }
コード例 #8
0
ファイル: frmSaveScripts.cs プロジェクト: Eisai/pragmasql
        /*
         * private int GetImageIndex(EditorContentType contentType)
         * {
         * switch (contentType)
         * {
         *  case EditorContentType.File:
         *    return 0;
         *  case EditorContentType.SharedSnippet:
         *    return 1;
         *  default:
         *    return -1;
         * }
         * }
         */

        private void AddToList(IPragmaEditor scriptEditor)
        {
            if (scriptEditor == null || !scriptEditor.ContentModified)
            {
                return;
            }

            if (scriptEditor.ContentPersister == null)
            {
                return;
            }

            ListViewGroup group = null;

            if (_groups.ContainsKey(scriptEditor.ContentPersister.ContentType))
            {
                group = _groups[scriptEditor.ContentPersister.ContentType];
            }

            ListViewItem item = new ListViewItem(scriptEditor.Caption, 0, group);

            lv.Items.Add(item);
            item.Checked = true;

            if (scriptEditor.LastModifiedOn.HasValue)
            {
                item.SubItems.Add(scriptEditor.LastModifiedOn.Value.ToString());
            }
            else
            {
                item.SubItems.Add(String.Empty);
            }

            item.SubItems.Add(scriptEditor.ContentPersister.FilePath);
            item.Tag = scriptEditor;
        }
コード例 #9
0
        public static bool OpenSharedScripts(IPragmaEditor currentEditor, ConnectionParams cp)
        {
            bool result = false;

            if (currentEditor != null && currentEditor.ContentModified)
            {
                DialogResult dlgRes = MessageBox.Show("Save changes to \"" + currentEditor.Caption + "\" before opening another script in current script editor", "Save Script", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                if (dlgRes == DialogResult.Cancel)
                {
                    return(false);
                }
                else if (dlgRes == DialogResult.Yes)
                {
                    currentEditor.SaveContent();
                }
            }

            IList <IPragmaEditor>         editors = new List <IPragmaEditor>();
            IList <SharedScriptsItemData> scripts = frmSharedScriptSelectDialog.ShowOpenSharedScriptDialog_MultiSelect();
            int           i   = 0;
            IPragmaEditor frm = null;

            foreach (SharedScriptsItemData data in scripts)
            {
                if (data.Type != GenericItemType.Item)
                {
                    continue;
                }

                i++;
                if (i == 1 && currentEditor != null)
                {
                    currentEditor.Caption                    = data.Name;
                    currentEditor.Icon                       = PragmaSQL.Properties.Resources.sharedScript;
                    currentEditor.ContentPersister           = new SharedScriptContentPersister();
                    currentEditor.ContentPersister.Data      = data;
                    currentEditor.ContentPersister.Hint      = "This is a shared script: " + data.Name;
                    currentEditor.ContentInfo                = currentEditor.ContentPersister.Hint;
                    currentEditor.ContentPersister.FilePath  = data.Name;
                    currentEditor.ActiveDocument.TextContent = data.Script;
                    currentEditor.ContentModified            = false;
                    result = true;
                    continue;
                }
                if (cp != null)
                {
                    frm = ScriptEditorFactory.OpenSharedScript(data, cp);
                    editors.Add(frm);
                }
                else
                {
                    frm = TextEditorFactory.OpenSharedScript(data);
                    editors.Add(frm);
                }
            }

            foreach (IPragmaEditor editor in editors)
            {
                if (editor is frmScriptEditor)
                {
                    ScriptEditorFactory.ShowScriptEditor(editor as frmScriptEditor);
                }
                else if (editor is frmTextEditor)
                {
                    TextEditorFactory.ShowTextEditor(editor as frmTextEditor);
                }
            }

            return(result);
        }