Пример #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);
        }
Пример #2
0
        public static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            splash = new SplashScreen();
            splash.Show();

            try
            {
                SettingsManagement.Load();
                FileTemplate.Unpack();
                ProjTemplate.Load();

                if (SettingsManagement.AutocompleteEnable)
                {
                    KeywordImageGen.GenerateKeywordImages();
                }
            }
            catch (Exception ex)
            {
                ErrorReportWindow.Show(ex, "Initialization Error");
            }

            try
            {
                UpdateMech.CheckForUpdates();
            }
            catch (Exception ex)
            {
                ErrorReportWindow.Show(ex, "Error Checking Updates");
            }

            try
            {
                AVRProject newProject = new AVRProject();

                if (args.Length > 0)
                {
                    string fname = args[0];

                    if (newProject.Open(fname) == true)
                    {
                        SettingsManagement.AddFileAsMostRecent(fname);
                    }
                    else
                    {
                        MessageBox.Show("Error, failed to open file");
                    }
                }
                else if (SettingsManagement.OpenLastProject)
                {
                    if (string.IsNullOrEmpty(SettingsManagement.LastProjectPath) == false)
                    {
                        if (newProject.Open(SettingsManagement.LastProjectPath) == true)
                        {
                            SettingsManagement.AddFileAsMostRecent(SettingsManagement.LastProjectPath);
                        }
                        else
                        {
                            MessageBox.Show("Error, failed to open file");
                        }
                    }
                }

                KeywordScanner.Initialize();

                Application.Run(new IDEWindow(newProject));

                if (newProject.IsReady)
                {
                    if (SettingsManagement.SaveRecentList() == false)
                    {
                        MessageBox.Show("Error, Could Not Save Recent File List");
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorReportWindow.Show(ex, "Main IDE Error");
            }

            try
            {
                if (UpdateMech.HasFinishedChecking)
                {
                    if (UpdateMech.UpdateAvailable)
                    {
                        try
                        {
                            if (MessageBox.Show("An Updated Version of AVR Project IDE is Available (" + SettingsManagement.Version + " to " + UpdateMech.NewBuildID + "). Would you like to download it?", "Update Available", MessageBoxButtons.YesNo) == DialogResult.Yes)
                            {
                                System.Diagnostics.Process.Start(Properties.Resources.WebsiteURL);
                            }
                        }
                        catch (Exception ex)
                        {
                            ErrorReportWindow.Show(ex, "Updater Error");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorReportWindow.Show(ex, "Error Checking Updates");
            }

            try
            {
                if (SettingsManagement.LastRunVersion != SettingsManagement.Version)
                {
                    NotifyOfUserAction();
                }

                SettingsManagement.LastRunVersion = SettingsManagement.Version;
            }
            catch { }
        }
Пример #3
0
        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();
            }
        }
Пример #4
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);
        }
Пример #5
0
        private void scint_CharAdded(object sender, CharAddedEventArgs e)
        {
            if (SettingsManagement.AutocompleteEnable == false)
            {
                return;
            }

            if (scint.AutoComplete.IsActive == false && "abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ#".Contains(e.Ch) && scint.PositionIsOnComment(scint.CurrentPos) == false)
            {
                string line    = scint.Lines.Current.Text;
                int    lineLen = scint.Caret.Position - scint.Lines.Current.StartPosition;
                line = Environment.NewLine + line + Environment.NewLine;
                bool inString = false;
                bool inChar   = false;
                for (int i = 2; i < lineLen + 2; i++)
                {
                    if (line[i] == '\\' && line[i + 1] == '\\' && (inString || inChar))
                    {
                        line = line.Remove(i, 2);
                        line = line.Insert(i, "  ");
                    }
                    else if (line[i] == '"' && line[i - 1] != '\\' && inChar == false)
                    {
                        inString = !inString;
                    }
                    else if (line[i] == '\'' && line[i - 1] != '\\' && inString == false)
                    {
                        inChar = !inChar;
                    }
                }

                if (inString == false && inChar == false)
                {
                    if (e.Ch == '#')
                    {
                        lastAutocompleteList = KeywordScanner.GetPreprocKeywords();

                        string w = scint.GetWordFromPosition(scint.CurrentPos);

                        bool found = false;
                        foreach (string i in lastAutocompleteList)
                        {
                            if (i.StartsWith(w))
                            {
                                found = true;
                                break;
                            }
                        }

                        if (found)
                        {
                            scint.AutoComplete.Show(lastAutocompleteList);
                        }
                    }
                    else
                    {
                        lastAutocompleteList = KeywordScanner.GetKeywordsUpTo(file, scint.Text.Substring(0, scint.NativeInterface.WordStartPosition(scint.CurrentPos, true)));

                        string w = scint.GetWordFromPosition(scint.CurrentPos);

                        bool found = false;
                        foreach (string i in lastAutocompleteList)
                        {
                            if (i.StartsWith(w))
                            {
                                found = true;
                                break;
                            }
                        }

                        if (found)
                        {
                            scint.AutoComplete.Show(lastAutocompleteList);
                        }
                    }
                }
            }
        }