Пример #1
0
        /// <summary>
        /// Fills the currently displayed lists of styles from the parsetree provided
        /// </summary>
        /// <param name="t">The parse tree to extract the styles from</param>
        public void UpdateStyleList()
        {
            if (ParseTree == null)
            {
                return;
            }
            string oldNodeStyle = NodeStyle, oldEdgeStyle = EdgeStyle;

            TikzStyles.Clear();
            foreach (string s in ParseTree.styles.Keys)
            {
                TikzStyles.Add(s);
            }

            NodeStyle = oldNodeStyle;
            EdgeStyle = oldEdgeStyle;
        }
Пример #2
0
        /// <summary>
        /// Loads a file.
        /// Raises an exception on error.
        /// </summary>
        /// <param name="cFile">Specify file to load. This must be a full path (not relative).</param>
        public void LoadFile(string cFile)
        {
            //bool LoadedCorrectly = false;
            if (!File.Exists(cFile))
            {
                throw new Exception("The file: " + cFile + " does not exist.");
            }
            //MessageBox.Show("Error: File not found: " + cFile, "File not found", MessageBoxButton.OK, MessageBoxImage.Error);
            //RecentFileList.RemoveFile(cFile);
            //return;


            //clean everything before loading file:
            //CleanupForNewFile();

            //set current dir to dir containing cFile.
            Helper.SetCurrentWorkingDir(Helper.WorkingDirOptions.DirFromFile, cFile);
            //MainWindow.AddStatusLine("Working directory is now: " + Helper.GetCurrentWorkingDir());


            string newcode = File.ReadAllText(cFile);

            //bmp = null; //tikzDisplay1.SetUnavailable(); // new file is directly compiled... but set unavailable in case error occurs
            ParseTree = null;   //(null, currentBB);
            TikzStyles.Clear(); //ClearStyleLists();
            FilePath    = cFile;
            ChangesMade = false;
            //CurFileNeverSaved = false;

            Document = new TextDocument(newcode);
            //Document.Insert(0, newcode);
            ChangesMade = false;  // set here since txtCode sets ChangesMade on Text change

            // start watching for external changes
            fileWatcher.Path   = Path.GetDirectoryName(FilePath); // Directory.GetCurrentDirectory();
            fileWatcher.Filter = Path.GetFileName(FilePath);      //ShortFileName;
            fileWatcher.EnableRaisingEvents = true;
        }
Пример #3
0
        void AsyncParser_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
        {
            AsyncParserResultType Result = e.Result as AsyncParserResultType;

            if (Result == null)
            {
                throw new Exception("AsyncParser_RunWorkerCompleted() can only handle e.Result  of type AsyncParserResultType!");
            }

            // in case of outdated parse -> ignore
            if (Result.DocumentID != DocumentID)
            {
                return;
            }

            //check if error occurred
            if (Result.Error != null && Result.Error is RecognitionException)
            {
                RecognitionException ex = Result.Error as RecognitionException;
                string errmsg           = ANTLRErrorMsg.ToString(ex, simpletikzParser.tokenNames);
                MainWindow.AddStatusLine("Couldn't parse code. " + errmsg, true);
                if (ex.Line == 0 && ex.CharPositionInLine == -1)
                {
                    addProblemMarker(errmsg, Document.LineCount, 0, Severity.ERROR, ShortFileName);
                }
                else
                {
                    addProblemMarker(errmsg, ex.Line, ex.CharPositionInLine, Severity.ERROR, ShortFileName);
                }
                ParseTree = null;
                TikzStyles.Clear();
            }
            else if (Result.Error != null)
            {
                string errmsg = Result.Error.GetType().ToString();
                if (Result.Error is Exception)
                {
                    errmsg += ":" + ((Exception)Result.Error).Message;
                }
                MainWindow.AddStatusLine("Couldn't parse code. " + errmsg, true);
                ParseTree = null;
                TikzStyles.Clear();
            }
            else
            {
                // parsing succesfull
                Tikz_ParseTree tp = Result.ParseTree as Tikz_ParseTree;
                ParseTree = tp;

                // if no other changes are pending, we can turn on editing again
                AllowEditing = true;

                // fill the style list
                UpdateStyleList();

                //now check if a warning occured. That would be a parser error in an included file.
                if (Result.Warning != null && Result.Warning is RecognitionException)
                {
                    RecognitionException ex = Result.Warning as RecognitionException;
                    string errmsg           = ANTLRErrorMsg.ToString(ex, simpletikzParser.tokenNames);
                    MainWindow.AddStatusLine("Couldn't parse included file. " + errmsg, true);
                    if (ex.Line == 0 && ex.CharPositionInLine == -1)
                    {
                        addProblemMarker(errmsg, Document.LineCount, 0, Severity.WARNING, Result.WarningSource);
                    }
                    else
                    {
                        addProblemMarker(errmsg, ex.Line, ex.CharPositionInLine, Severity.WARNING, Result.WarningSource);
                    }
                }
                else if (Result.Warning != null && Result.Warning is ParserException)
                {
                    ParserException pe = Result.Warning as ParserException;
                    addProblemMarker(this, pe.e);
                }
                else if (Result.Warning != null && Result.Warning is Exception)
                {
                    string errmsg = ((Exception)Result.Warning).Message;
                    MainWindow.AddStatusLine("Couldn't parse included file " + Result.WarningSource + ". " + errmsg, true);
                }
            }

            // Restart parser if necessary
            ParseNeeded = ParseNeeded;
        }