internal SciCode(FileNode file, SciText.FileLoaderSaver fls) { //_edit = edit; _fn = file; _fls = fls; this.Dock = DockStyle.Fill; this.Name = "Code_text"; this.AccessibleRole = AccessibleRole.Document; this.AllowDrop = true; ZInitImagesStyle = ZImagesStyle.AnyString; if (fls.IsBinary) { ZInitReadOnlyAlways = true; } }
/// <summary> /// If f is already open, unhides its control. /// Else loads f text and creates control. If fails, does not change anything. /// Hides current file's control. /// Returns false if failed to read file. /// Does not save text of previously active document. /// </summary> /// <param name="f"></param> /// <param name="newFile">Should be true if opening the file first time after creating.</param> public bool ZOpen(FileNode f, bool newFile) { Debug.Assert(!Program.Model.IsAlien(f)); if (f == _activeDoc?.ZFile) { return(true); } bool focus = _activeDoc?.Focused ?? false; var doc = ZGetOpenDocOf(f); if (doc != null) { if (_activeDoc != null) { _activeDoc.Visible = false; } _activeDoc = doc; _activeDoc.Visible = true; _UpdateUI_EditEnabled(); ZActiveDocChanged?.Invoke(); } else { var path = f.FilePath; byte[] text = null; SciText.FileLoaderSaver fls = default; try { text = fls.Load(path); } catch (Exception ex) { AOutput.Write("Failed to open file. " + ex.Message); } if (text == null) { return(false); } if (_activeDoc != null) { _activeDoc.Visible = false; } doc = new SciCode(f, fls); doc.AccessibleName = f.Name; doc.AccessibleDescription = path; _docs.Add(doc); _activeDoc = doc; this.Controls.Add(doc); doc._Init(text, newFile); _UpdateUI_EditEnabled(); ZActiveDocChanged?.Invoke(); //CodeInfo.FileOpened(doc); } if (focus && !newFile) { _activeDoc.Focus(); } else //don't focus now, or then cannot select treeview items with keyboard etc. Focus on mouse move in editor control. { _openFocus.onMM ??= (object sender, MouseEventArgs e) => { var c = sender as Control; if (!c.FindForm().Hwnd().IsActive) { return; } if (_openFocus.dist >= 0) //if new file, don't focus until mouse moved away from tree { int dist = (int)AMath.Distance(Program.Model.TreeControl.Hwnd().Rect, AMouse.XY); if (dist < _openFocus.dist + 10) { if (dist < _openFocus.dist) { _openFocus.dist = dist; } return; } } c.MouseMove -= _openFocus.onMM; c.Focus(); }; _activeDoc.MouseMove += _openFocus.onMM; _openFocus.dist = newFile ? int.MaxValue - 10 : -1; } _activeDoc.Call(SCI_SETWRAPMODE, Program.Settings.edit_wrap); //fast and does nothing if already is in that wrap state _activeDoc.ZImages.Visible = Program.Settings.edit_noImages ? AnnotationsVisible.ANNOTATION_HIDDEN : AnnotationsVisible.ANNOTATION_STANDARD; _UpdateUI_IsOpen(); Panels.Find.ZUpdateQuickResults(true); return(true); }