Beispiel #1
0
        private bool ReadFromFile(string path)
        {
            path = Program.CleanFilePath(path);

            bool success = true;

            try
            {
                scint.Text = System.IO.File.ReadAllText(file.FileAbsPath).TrimEnd();
            }
            catch { success = false; }

            KeywordScanner.FeedFileContent(file, scint.Text);
            KeywordScanner.DoMoreWork();

            scint.Modified = false;
            hasChanged     = false;
            scint.UndoRedo.EmptyUndoBuffer();

            return(success);
        }
        private void PopulateList()
        {
            rootNode.Text = project.FileName;

            //treeView1.SuspendLayout();

            sourceFolderList.Clear();
            headerFolderList.Clear();
            otherFolderList.Clear();

            sourceNodeList.Clear();
            headerNodeList.Clear();
            otherNodeList.Clear();

            sourceNode.Nodes.Clear();
            headerNode.Nodes.Clear();
            otherNode.Nodes.Clear();

            foreach (ProjectFile file in project.FileList.Values)
            {
                if (SettingsManagement.AutocompleteEnable)
                {
                    KeywordScanner.FeedFileContent(file);
                }

                TreeNode tn = file.Node;

                tn.ToolTipText = file.FileRelProjPath;

                // attach the menu
                tn.ContextMenuStrip = nodeRClickMenu;

                if (file.Exists == false)
                {
                    tn.ImageKey         = "missing.ico";
                    tn.SelectedImageKey = "missing.ico";
                    tn.StateImageKey    = "missing.ico";
                }
                else
                {
                    if (file.IsOpen)
                    {
                        tn.ImageKey         = "file.ico";
                        tn.SelectedImageKey = "file.ico";
                        tn.StateImageKey    = "file.ico";
                    }
                    else
                    {
                        tn.ImageKey         = "file2.ico";
                        tn.SelectedImageKey = "file2.ico";
                        tn.StateImageKey    = "file2.ico";
                    }
                }

                string ext = file.FileExt;
                if (ext == "s" || ext == "c" || ext == "cpp" || ext == "cxx" || ext == "pde")
                {
                    // only source files can be compiled

                    if (file.ToCompile)
                    {
                        tn.Checked = true;
                    }

                    sourceNodeList.Add(tn);
                    //sourceNode.Nodes.Add(tn);
                }
                else if (ext == "h" || ext == "hpp")
                {
                    //headerNode.Nodes.Add(tn);
                    headerNodeList.Add(tn);
                }
                else
                {
                    //otherNode.Nodes.Add(tn);
                    otherNodeList.Add(tn);
                }
            }

            sourceNodeList.Sort((x, y) => string.Compare(x.Text, y.Text));
            sourceNode.Nodes.AddRange(sourceNodeList.ToArray());

            headerNodeList.Sort((x, y) => string.Compare(x.Text, y.Text));
            headerNode.Nodes.AddRange(headerNodeList.ToArray());

            otherNodeList.Sort((x, y) => string.Compare(x.Text, y.Text));
            otherNode.Nodes.AddRange(otherNodeList.ToArray());

            treeView1.ExpandAll();

            //treeView1.ResumeLayout();

            if (SettingsManagement.AutocompleteEnable)
            {
                KeywordScanner.DoMoreWork();
            }
        }
Beispiel #3
0
        private bool WriteToFile(string path, bool backup)
        {
            // obviously the filesystem watcher will know if you rewrite the file, so disable it
            bool wasWatching = WatchingForChange;

            WatchingForChange = false;

            path = Program.CleanFilePath(path);

            bool success = true;

            if (Program.MakeSurePathExists(path.Substring(0, path.LastIndexOf(Path.DirectorySeparatorChar))) == false)
            {
                return(false);
            }

            string content = scint.Text.TrimEnd();

            try
            {
                KeywordScanner.FeedFileContent(file, content);
                KeywordScanner.DoMoreWork();
            }
            catch { }

            if (backup)
            {
                for (int i = 0; i <= SAVERETRY; i++)
                {
                    try
                    {
                        System.IO.File.WriteAllText(path + ".bk", content);
                        break;
                    }
                    catch (Exception ex)
                    {
                        if (i == SAVERETRY)
                        {
                            success = false;
                            //ErrorReportWindow.Show(ex, "Save Error");
                            //
                            break;
                        }
                        System.Threading.Thread.Sleep(SAVERETRYDELAY);
                    }
                }
            }

            for (int i = 0; i <= SAVERETRY; i++)
            {
                try
                {
                    System.IO.File.WriteAllText(path, content);
                    break;
                }
                catch (Exception ex)
                {
                    if (i == SAVERETRY)
                    {
                        success = false;
                        ErrorReportWindow.Show(ex, "Save Error");

                        break;
                    }
                    System.Threading.Thread.Sleep(SAVERETRYDELAY);
                }
            }

            if (backup && success)
            {
                try
                {
                    System.IO.File.Delete(path + ".bk");
                }
                catch { }
            }

            WatchingForChange = wasWatching;

            return(success);
        }