public void OpenFiles(string[] files) { var connectionInfo = this.connectionsManager.ResolveConnection(); if (connectionInfo == null) { return; } this.dockPanel.ColoseInitialDocument(); connectionInfo.Connect(); // Open file(s) foreach (string fn in files) { QueryTab queryTab = null; try { queryTab = this.CreateQueryTab(string.Empty, connectionInfo); queryTab.QueryText = File.ReadAllText(fn); queryTab.FileName = fn; // Modified flag is set during loading because the document // "changes" (from nothing to something). So, clear it again. queryTab.MarkSaved(); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().Name); if (queryTab != null) { this.dockPanel.RemoveTab(queryTab.Parent as DockContent); } return; } // ICSharpCode.TextEditor doesn't have any built-in code folding // strategies, so I've included a simple one. Apparently, the // foldings are not updated automatically, so in this demo the user // cannot add or remove folding regions after loading the file. //-- editor.Document.FoldingManager.FoldingStrategy = new RegionFoldingStrategy(); //-- editor.Document.FoldingManager.UpdateFoldings(null, null); } }
private bool SaveEditor(QueryTab editor, string fileName) { try { File.WriteAllText(fileName, editor.QueryText); editor.FileName = fileName; editor.MarkSaved(); // The syntax highlighting strategy doesn't change // automatically, so do it manually. //editor.Document.HighlightingStrategy = // HighlightingStrategyFactory.CreateHighlightingStrategyForFile(editor.FileName); return(true); } catch (Exception ex) { MessageBox.Show(this, ex.Message, ex.GetType().Name); return(false); } }