예제 #1
0
        public bool RenameNode(TreeNode node, string newName)
        {
            newName = newName.Trim();

            if (newName.Contains(" "))
            {
                return(false);
            }

            foreach (char c in Path.GetInvalidFileNameChars())
            {
                if (newName.Contains(c))
                {
                    return(false);
                }
            }

            if (Path.GetExtension(newName) != Path.GetExtension(node.Text))
            {
                if ((newName.ToLowerInvariant().EndsWith(".c") || newName.ToLowerInvariant().EndsWith(".cpp") || newName.ToLowerInvariant().EndsWith(".asm") || newName.ToLowerInvariant().EndsWith(".s")) && (node.Text.ToLowerInvariant().EndsWith(".h") || node.Text.ToLowerInvariant().EndsWith(".hpp")))
                {
                    return(false);
                }

                if ((newName.ToLowerInvariant().EndsWith(".h") || newName.ToLowerInvariant().EndsWith(".hpp")) && (node.Text.ToLowerInvariant().EndsWith(".c") || node.Text.ToLowerInvariant().EndsWith(".cpp") || node.Text.ToLowerInvariant().EndsWith(".s") || node.Text.ToLowerInvariant().EndsWith(".asm")))
                {
                    return(false);
                }
            }

            ProjectFile f;

            if (project.FileList.TryGetValue(node.Text.ToLowerInvariant(), out f))
            {
                if (f.Exists == false)
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }

            if (project.FileList.TryGetValue(newName.ToLowerInvariant(), out f) == false)
            {
                if (project.FileList.TryGetValue(node.Text.ToLowerInvariant(), out f))
                {
                    string newPath = f.FileDir + Path.DirectorySeparatorChar + newName;
                    if (File.Exists(newPath) == false)
                    {
                        try
                        {
                            EditorPanel editor = null;
                            if (editorList.TryGetValue(node.Text.ToLowerInvariant(), out editor))
                            {
                                editor.WatchingForChange = false;
                            }
                            File.Move(f.FileAbsPath, newPath);

                            f.FileAbsPath = newPath;

                            if (editor != null)
                            {
                                editorList.Remove(node.Text.ToLowerInvariant());
                                editorList.Add(newName.ToLowerInvariant(), editor);
                                editor.File.FileAbsPath  = newPath;
                                editor.Text              = newName;
                                editor.TabText           = newName;
                                editor.WatchingForChange = true;
                            }
                        }
                        catch { return(false); }

                        node.ToolTipText = f.FileRelPathTo(project.DirPath);

                        project.FileList.Remove(node.Text.ToLowerInvariant());
                        project.FileList.Add(newName.ToLowerInvariant(), f);

                        if (project.Save() == SaveResult.Failed)
                        {
                            MessageBox.Show("Error saving project");
                        }

                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
예제 #2
0
        private void Search()
        {
            string searchString = txtSearch.Text;

            if (string.IsNullOrEmpty(searchString))
            {
                return;
            }

            bool matchCase = chkMatchCase.Checked;
            bool wholeWord = chkWholeWord.Checked;
            bool wordStart = chkWordStart.Checked;
            bool escape    = chkEscape.Checked;

            SearchFlags flags = SearchFlags.Empty;

            if (matchCase)
            {
                flags |= SearchFlags.MatchCase;
            }

            if (wholeWord)
            {
                flags |= SearchFlags.WholeWord;
            }

            if (wordStart)
            {
                flags |= SearchFlags.WordStart;
            }

            if (escape)
            {
                searchString = searchString.Replace("\\\\", "\\");
                searchString = searchString.Replace("\\t", "\t");
                searchString = searchString.Replace("\\r", "\r");
                searchString = searchString.Replace("\\n", "\n");
            }

            listSearchResults.Items.Clear();

            foreach (KeyValuePair <string, EditorPanel> i in editorList)
            {
                EditorPanel editor = i.Value;

                string fileName = editor.FileName;

                Scintilla scint = editor.Scint;

                List <Range> results = editor.FindAll(searchString, flags);

                foreach (Range r in results)
                {
                    int    lineNum = scint.Lines.FromPosition(r.Start).Number;
                    string resLine = scint.Lines[lineNum].Text.TrimEnd();

                    string hoverTxt = "";
                    if (lineNum >= 2)
                    {
                        hoverTxt += scint.Lines[lineNum - 2].Text.TrimEnd() + Environment.NewLine;
                    }
                    if (lineNum >= 1)
                    {
                        hoverTxt += scint.Lines[lineNum - 1].Text.TrimEnd() + Environment.NewLine;
                    }

                    hoverTxt += scint.Lines[lineNum].Text.TrimEnd() + Environment.NewLine;

                    if (lineNum < scint.Lines.Count - 1)
                    {
                        hoverTxt += scint.Lines[lineNum + 1].Text.TrimEnd() + Environment.NewLine;
                    }
                    if (lineNum < scint.Lines.Count - 2)
                    {
                        hoverTxt += scint.Lines[lineNum + 2].Text.TrimEnd() + Environment.NewLine;
                    }

                    hoverTxt = hoverTxt.TrimEnd();

                    ListViewItem lvi = new ListViewItem(new string[] { resLine, fileName, (lineNum + 1).ToString(), r.Start.ToString(), r.End.ToString(), });
                    lvi.ToolTipText = hoverTxt;

                    listSearchResults.Items.Add(lvi);
                }
            }

            ShowResults();
        }
예제 #3
0
        public EditorPanel OpenEditor(string fileName)
        {
            ProjectFile file;
            if (project.FileList.TryGetValue(fileName.ToLowerInvariant(), out file))
            {
                // file is in project, so open the editor and attach events
                EditorPanel editor = new EditorPanel(file, project, this);
                editor.OnRename += new RenamedEventHandler(editor_OnRename);
                editor.EditorClosed += new EditorPanel.EditorClosedEvent(editor_EditorClosed);
                editor.CloseAllExceptMe += new EditorPanel.CloseAllButMe(editor_CloseAllExceptMe);

                file.Node.ImageKey = "file.ico";
                file.Node.SelectedImageKey = "file.ico";
                file.Node.StateImageKey = "file.ico";

                // add editor to list and show it
                editorList.Add(fileName.ToLowerInvariant(), editor);
                editor.Show(dockPanel1, DockState.Document);

                lastEditor = editor;

                // return reference to work with
                return editor;
            }
            return null;
        }
예제 #4
0
        public void GotoEditor(string fileName)
        {
            EditorPanel editor = null;
            if (editorList.TryGetValue(fileName.ToLowerInvariant(), out editor) == false)
            {
                editor = OpenEditor(fileName);
            }
            if (editor != null)
            {
                editor.BringToFront();
                editor.Activate();
                editor.Scint.Focus();

                lastEditor = editor;
            }
        }
예제 #5
0
        private void GotoEditor(string fileName, int selectionStart, int selectionEnd)
        {
            EditorPanel editor = null;
            if (editorList.TryGetValue(fileName.ToLowerInvariant(), out editor) == false)
            {
                editor = OpenEditor(fileName);
            }
            if (editor != null)
            {
                editor.BringToFront();
                editor.Activate();

                editor.Scint.Focus();

                editor.Scint.Caret.Position = selectionStart;
                editor.Scint.GoTo.Position(selectionStart);
                editor.Scint.Selection.Start = selectionStart;
                editor.Scint.Selection.End = selectionEnd;

                lastEditor = editor;
            }
        }
예제 #6
0
        private void GotoEditor(string fileName, int line)
        {
            EditorPanel editor = null;
            if (editorList.TryGetValue(fileName.ToLowerInvariant(), out editor) == false)
            {
                // not open, open it first, OpenEditor will add it to the dictionary
                editor = OpenEditor(fileName);
            }

            if (editor != null)
            {
                editor.BringToFront();
                editor.Activate();

                // note that line index and number are off by 1

                editor.Scint.Focus();
                editor.Scint.Caret.Position = editor.Scint.Lines[line - 1].StartPosition;
                editor.Scint.GoTo.Line(line - 1);
                editor.Scint.Selection.Start = editor.Scint.Lines[line - 1].StartPosition;
                editor.Scint.Selection.End = editor.Scint.Lines[line - 1].StartPosition;

                lastEditor = editor;
            }
        }
예제 #7
0
 private void dockPanel1_ActiveDocumentChanged(object sender, EventArgs e)
 {
     if (dockPanel1.ActiveDocument != null)
     {
         if (dockPanel1.ActiveDocument.GetType() == typeof(EditorPanel))
         {
             lastEditor = (EditorPanel)dockPanel1.ActiveDocument;
             project.LastFile = lastEditor.FileName;
         }
     }
 }