Esempio n. 1
0
        // form initializer
        private void Main_Load(object sender, EventArgs e)
        {
            // show the splash screen
            this.loading = new Loading();
            this.loading.Show();
            this.loading.Refresh();

            // set the current directory to the executable dir (staring via shortcut or through associated file could set the working dir to a wrong one)
            System.IO.Directory.SetCurrentDirectory(System.IO.Path.GetDirectoryName(Application.ExecutablePath));

            this.CreateEditor();

            this.needsSaving = false;

            this.currentOverlayIndex = 0;
         
            // load XML configuration
            Config.Load();

            this.InitializeGGen();

            // make sure the OpenGL control is shown (so the OpenGL context is created)
            this.SelectTab(Tabs.Output3D);
            this.SelectTab(Tabs.Code);

            // is OGL ready to rock?
            if (this.viewport.Context == null)
            {
                System.Windows.Forms.MessageBox.Show("Failed to initialize OpenGL." + Environment.NewLine + Environment.NewLine + "The 3D View function will not be available while using this application. If you are sure you have working graphics acceleration with OpenGL 1.4 support, please contact me with details of your system on email address found in the Help -> About GeoGen Studio dialog.");
            }

            // make sure the parameter property grid knows where to look for its items 
            this.parameters.SelectedObject = parameters.Item;

            // ScintillaNet doesn't support the simple TextChanged ecent (not it like the visual event list)
            //this.editor.TextInserted += editor_TextInserted;
            //this.editor.TextDeleted += editor_TextInserted;

            

            // make the output picturebox have zero size (no output is available)
            this.output.Width = 0;
            this.output.Height = 0;

            this.LoadOverlays();

            // open last opened file if requested
            string ext = this.fileFromShell == null ? "" : this.fileFromShell.Substring(this.fileFromShell.LastIndexOf('.'), this.fileFromShell.Length - this.fileFromShell.LastIndexOf('.')).ToLower();
            
            if (this.fileFromShell != null && !(ext == ".shd" || ext == ".bmp" || ext == ".png" || ext == ".jpg"))
            {
                this.editor.Text = System.IO.File.ReadAllText(this.fileFromShell);
                this.knownFile = true;
                this.needsSaving = false;
                this.config.lastFile = this.fileFromShell;
                this.fileFromShell = null; // the file was already loaded and will not be useful any more
            }
            else if (this.config.openLastFileOnStartup && this.config.lastFile != "" && System.IO.File.Exists(this.config.lastFile))
            {              
                this.editor.Text = System.IO.File.ReadAllText(this.config.lastFile);
                this.knownFile = true;
                this.needsSaving = false;
            }
            else
            {
                // trigger the "new file" button click, so the template is loaded (without doubling the code)
                this.newToolStripMenuItem_Click(sender, e);
            }

            // output and viewport zooming event
            this.MouseWheel += new MouseEventHandler(Form1_MouseWheel);

            this.config.Save();

            this.ScheduleSyntaxCheck();



            System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(GGenAPIData));            

            try
            {
                System.IO.StreamReader reader = System.IO.File.OpenText(Program.BasePath + "/config/apidata.xml");

                GGenAPIData apiData = (GGenAPIData) xs.Deserialize(reader);

                foreach(ICSharpCode.AvalonEdit.CodeCompletion.ICompletionData item in apiData.constants){
                    this.completionData.Add(item);
                }

                foreach (ICSharpCode.AvalonEdit.CodeCompletion.ICompletionData item in apiData.methods)
                {
                    this.completionData.Add(item);
                }

                this.completionData.Sort(new CompletionDataComparer());
            }
            catch(Exception ex){
                this.WriteToConsole("Could not load code completion data");
            }

            // fill in the search window (possibly from the data loaded from the config file)
            this.searchWindow.textBox1.Text = this.config.searchString;
            this.searchWindow.textBox2.Text = this.config.replaceString;
            this.searchWindow.matchCase.Checked = this.config.searchMode == StringComparison.Ordinal;

            // show this form and close the splash screen
            this.Opacity = 1.0;
            
            this.loading.FadeOut();

            if(this.fileFromShell != null){
                this.ClearData();
                this.ClearData3D();
                this.ReloadMaps(this.fileFromShell);
            }
        }