Example #1
0
 /// <summary>
 /// Opens given file in notepad++
 /// </summary>
 public static bool OpenFile(string file)
 {
     if (!File.Exists(file))
     {
         UserCommunication.Notify(@"Can't find/open the following file :<br>" + file, MessageImg.MsgHighImportance, "Warning", "File not found", 5);
         return(false);
     }
     if (GetOpenedFiles.Contains(file))
     {
         SwitchToDocument(file);
         return(true);
     }
     return(Win32Api.SendMessage(Handle, NppMsg.NPPM_DOOPEN, 0, file).ToInt64() > 0);
 }
Example #2
0
        /// <summary>
        /// Switch to a document, can be already opened or not, can decide to remember the current position to jump back to it
        /// </summary>
        public static void Goto(string document, int position, int line, int column, bool saveHistoric)
        {
            if (!File.Exists(document))
            {
                UserCommunication.Notify(@"Can't find/open the following file :<br>" + document, MessageImg.MsgHighImportance, "Warning", "File not found", 5);
                return;
            }
            if (saveHistoric)
            {
                _goToHistory.Push(new Tuple <string, int, Point>(CurrentFileInfo.Path, Sci.FirstVisibleLine, Sci.CurrentPoint));
            }

            if (!String.IsNullOrEmpty(document) && !document.Equals(CurrentFileInfo.Path))
            {
                if (GetOpenedFiles.Contains(document))
                {
                    SwitchToDocument(document);
                }
                else
                {
                    OpenFile(document);
                }
            }

            if (position >= 0)
            {
                Sci.GoToLine(Sci.LineFromPosition(position));
                Sci.SetSel(position);
            }
            else if (line >= 0)
            {
                Sci.GoToLine(line);
                if (column >= 0)
                {
                    Sci.SetSel(Sci.GetPosFromLineColumn(line, column));
                }
                else
                {
                    Sci.SetSel(Sci.GetLine(line).Position);
                }
            }

            Sci.GrabFocus();
            Plug.OnUpdateSelection();
        }