コード例 #1
0
        private void btnAddRule_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string[] filenames;

                var fileChooser = new OpenFileDialog();
                fileChooser.Title            = "Add rules";
                fileChooser.InitialDirectory = GSApp.settings.RulesDirAbs;
                fileChooser.Filter           = "grammar rule file (*.grxml)|*.grxml|xml file (*.xml)|*.xml";
                fileChooser.Multiselect      = true;
                if ((Boolean)fileChooser.ShowDialog(this))
                {
                    filenames = fileChooser.FileNames;

                    if (filenames.GetLength(0) == 0)
                    {
                        MessageBox.Show("Error in rule loading. RuleSet unchanged",
                                        "Error in rule loading.", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    else
                    {
                        foreach (string filename in filenames)
                        {
                            try
                            {
                                var tempRuleObj = GSApp.settings.filer.Open(filename);
                                Ruleset.Add((grammarRule)tempRuleObj[0]);
                                var ruleFileName = MyIOPath.GetRelativePath(filename,
                                                                            GSApp.settings.RulesDirAbs);
                                var ruleNumber = listBoxOfRules.Items.Count + 1;
                                var li         = new ListBoxItem();
                                li.Content = ruleNumber + ". " + ruleFileName;
                                listBoxOfRules.Items.Add(li);
                                Ruleset.ruleFileNames.Add(ruleFileName);
                            }
                            catch
                            {
                                MessageBox.Show("Error in loading rule: " + filename,
                                                "Error in rule loading.", MessageBoxButton.OK,
                                                MessageBoxImage.Information);
                            }
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                ErrorLogger.Catch(exc);
            }
        }
コード例 #2
0
 private void refreshTextBoxes()
 {
     if (newSettings.CustomShapesFile.Length == 0)
     {
         txtCustomShapes.Text = c2b;
     }
     else
     {
         txtCustomShapes.Text = newSettings.CustomShapesFile;
     }
     if (newSettings.WorkingDirAbsolute.Length == 0)
     {
         txtWorkingDirectory.Text = c2b;
     }
     else
     {
         txtWorkingDirectory.Text         = newSettings.WorkingDirAbsolute;
         txtWorkingRelativeDirectory.Text = newSettings.WorkingDirRelative;
     }
     if (newSettings.InputDir.Length == 0)
     {
         txtInputDirectory.Text = c2b;
     }
     else
     {
         txtInputDirectory.Text = newSettings.InputDir;
     }
     if (newSettings.OutputDir.Length == 0)
     {
         txtOutputDirectory.Text = c2b;
     }
     else
     {
         txtOutputDirectory.Text = newSettings.OutputDir;
     }
     if (newSettings.RulesDir.Length == 0)
     {
         txtRulesDirectory.Text = c2b;
     }
     else
     {
         txtRulesDirectory.Text = newSettings.RulesDir;
     }
     if ((bool)chkGetHelpFromOnline.IsChecked)
     {
         txtHelpDirectory.IsEnabled = btnHelpDirectory.IsEnabled = false;
     }
     else
     {
         txtHelpDirectory.IsEnabled = btnHelpDirectory.IsEnabled = true;
         if (newSettings.LocalHelpDir.Length == 0)
         {
             txtHelpDirectory.Text = c2b;
         }
         else
         {
             txtHelpDirectory.Text = newSettings.LocalHelpDir;
         }
     }
     if (newSettings.SearchDir.Length == 0)
     {
         txtSearchDirectory.Text = c2b;
     }
     else
     {
         txtSearchDirectory.Text = newSettings.SearchDir;
     }
     if (newSettings.GraphLayoutDir.Length == 0)
     {
         txtGraphLayoutDirectory.Text = c2b;
     }
     else
     {
         txtGraphLayoutDirectory.Text = newSettings.GraphLayoutDir;
     }
     if (newSettings.DefaultSeedFileName.Length == 0)
     {
         txtDefaultSeedGraph.Text = c2b;
     }
     else
     {
         txtDefaultSeedGraph.Text = newSettings.DefaultSeedFileName;
     }
     if (newSettings.CompiledRuleFunctions.Length == 0)
     {
         txtCompiledRulesDLL.Text = c2b;
     }
     else
     {
         txtCompiledRulesDLL.Text = newSettings.CompiledRuleFunctions;
     }
     for (var i = 0; i != 10; i++)
     {
         if (i < newSettings.numOfRuleSets)
         {
             if (i >= newSettings.defaultRSFileNames.Count)
             {
                 newSettings.defaultRSFileNames.Add("");
             }
             if (newSettings.defaultRSFileNames[i].Length == 0)
             {
                 RSText[i].Text = c2b;
             }
             else
             {
                 RSText[i].Text = MyIOPath.GetRelativePath(newSettings.defaultRSFileNames[i], newSettings.RulesDirAbs);
             }
             RSText[i].Visibility   = Visibility.Visible;
             RSButton[i].Visibility = Visibility.Visible;
         }
         else
         {
             RSButton[i].Visibility = Visibility.Hidden;
             RSText[i].Visibility   = Visibility.Hidden;
         }
     }
 }