示例#1
0
    /// <summary>
    /// Called when opening a document, when handle created but text still not loaded.
    /// </summary>
    public static void DocHandleCreated(SciCode doc)
    {
        Program.Settings.edit_styles.ToScintilla(doc);

        doc.Call(SCI_MARKERDEFINE, SciCode.c_markerUnderline, SC_MARK_UNDERLINE);
        doc.Call(SCI_MARKERSETBACK, SciCode.c_markerUnderline, 0xe0e0e0);

        _InitFolding(doc);
    }
示例#2
0
 unsafe void Api.IDropTarget.DragOver(int grfKeyState, POINT p, ref int effect)
 {
     if ((effect = _GetEffect(effect, grfKeyState)) != 0)
     {
         _GetDropPos(ref p, out _);
         var z = new Sci_DragDropData {
             x = p.x, y = p.y
         };
         _sci.Call(SCI_DRAGDROP, 1, &z);
     }
 }
示例#3
0
    /// <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);
    }