예제 #1
0
 internal TehthuParser(Tehthu t)
 {
     try
     {
         teh = t;
         FileStream fs = t.getFile().OpenRead();
         if(!fs.CanRead)
             throw new IOException("Can not read from file " + teh.getFile().Name);
         reader = new StreamReader(fs);
         lineno = 0;
         recalcRegexes();
         advance();
     }
     catch(SystemException se)
     {
         throw new IOException("Can not read from file " + teh.getFile().Name + "\n" + se.Message);
     }
 }
예제 #2
0
 internal OdsParser(Tehthu t)
 {
     this.teh = t;
     this.file = t.getFile();
     OdsReaderWriter orw = new OdsReaderWriter();
     DataSet ds = orw.ReadOdsFile(file.FullName);
     dt = ds.Tables["Dictionary"];
     if(dt == null)
     {
         dt = ds.Tables["Sheet1"];
         if(dt == null)
         {
             dt = ds.Tables[0];
             if(dt == null)
             {
                 teh.putLogLine("Parser error: Couldn't find a spreadsheet containing the dictionary. The dictionary will be empty for this Tehthu session.");
                 return;
             }
         }
     }
 }
예제 #3
0
        private static Tehthu loadFile(string ff)
        {
            Tehthu t = new Tehthu(ff);

            return t;
        }
예제 #4
0
        //This method handles TWO files:
        //(1) The file to initialize as the dictionary. Passed as `fi'
        //(2) The settings file. Refer to `settingsFile' member.
        static void initialize(FileInfo fi, Gtk.Entry input, Gtk.Button send, Gtk.Notebook nb, Gtk.Button leftButton, Gtk.Button rightButton)
        {
            if(teh != null)
            {
                teh.disconnectFromLog();
                teh = null;
            }
            teh = loadFile(fi.FullName);
            teh.connectToLog();

            if(!monitor.IsAlive)
            {
                monitor.Start();
            }
            else
            {
                monitor.Abort();
                monitor = new System.Threading.Thread(MainClass.ConsoleEater);
                monitor.Start();
            }

            if(!teh.reparse())
            {
                Gtk.MessageDialog m_d = new Gtk.MessageDialog(mainwindow, DialogFlags.DestroyWithParent, MessageType.Error, ButtonsType.Ok, "Error: Your dictionary file could not be parsed. Make sure it is not open in any other application, check the format, and try again.", new object[]{"Ok"});
                m_d.Run();
                System.Environment.Exit(0);
            }

            //We're still here, there were no fatal exceptions, so this dict is "safe" for opening on startup (we hope)
            //Remember this fact in the .tehthuconfig file.
            if(settingsFile != null)
            {
                TextWriter tw = new StreamWriter(settingsFile.OpenWrite());
                tw.WriteLine(teh.getFile().FullName);
                tw.Flush();
                tw.Close();
            }

            input.IsEditable = true;
            input.Sensitive = true;
            send.Sensitive = true;

            Gtk.Label inputTabLabel = (Gtk.Label) nb.GetTabLabel(nb.GetNthPage(0));
            inputTabLabel.Text = "Input ("
                + (leftToRight ? teh.getLeftLanguageName() : teh.getRightLanguageName())
                + ")";

            Gtk.Label outputTabLabel = (Gtk.Label) nb.GetTabLabel(nb.GetNthPage(1));
            outputTabLabel.Text = "Output ("
                + (leftToRight ? teh.getRightLanguageName() : teh.getLeftLanguageName())
                + ")";

            leftButton.Label = teh.getLeftLanguageName() + "-to-" + teh.getRightLanguageName();
            rightButton.Label = teh.getRightLanguageName() + "-to-" + teh.getLeftLanguageName();
            input.GrabFocus();
        }