예제 #1
0
        //-----------------------------------------------------------------------------------------
        //méthode load
        public static Config Load(string _name)
        {
            string filename = TaxonUtils.GetConfigFileName(_name);

            if (File.Exists(filename))
            {
                try
                {
                    XmlSerializer deserializer = new XmlSerializer(typeof(Config));
                    TextReader    reader       = new StreamReader(filename);
                    object        obj          = deserializer.Deserialize(reader);
                    reader.Close();
                    (obj as Config).Name = _name;
                    (obj as Config).AfterLoad();
                    return(obj as Config);
                }
                catch (Exception e)
                {
                    Loggers.WriteError(LogTags.Congif, "Exception while loading config file : \n    " + filename + "\n" + e.Message);
                }
            }
            Config result = new Config(_name);

            result.AfterLoad();
            return(result);
        }
예제 #2
0
 void PasteClipboard(TaxonTreeNode _to)
 {
     if (Clipboard.ContainsData("TaxonTreeNodeXmlMemoryStream"))
     {
         object o = Clipboard.GetData("TaxonTreeNodeXmlMemoryStream");
         if (o is System.IO.MemoryStream ms)
         {
             TaxonTreeNode node = TaxonTreeNode.LoadXMLFromMemory(ms);
             if (node != null)
             {
                 ImportNode(_to, node);
             }
         }
     }
     else if (Clipboard.ContainsData(DataFormats.Text))
     {
         string name = Clipboard.GetText();
         if (name == null)
         {
             return;
         }
         TaxonTreeNode node = Root.FindTaxonByFullName(name);
         if (node != null)
         {
             TaxonUtils.GotoTaxon(node);
             TaxonUtils.SelectTaxon(node);
         }
     }
 }
예제 #3
0
        //---------------------------------------------------------------------------------
        private void createNewTreeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TaxonTreeNode root = new TaxonTreeNode(new TaxonDesc("root"));

            TaxonUtils.Save(root, true, true);
            TaxonUtils.SetOriginalRoot(root);
        }
예제 #4
0
 //-------------------------------------------------------------------
 private void TextBoxSearch_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Return)
     {
         e.Handled = true;
         if (textBoxSearch.Text.Length < 2)
         {
             TaxonSearchAsync.Search(_Root, textBoxSearch.Text);
         }
         if (listBoxResult.Items.Count > 0)
         {
             TaxonTreeNode taxon = listBoxResult.GetAt(0);
             if (taxon != null)
             {
                 TaxonUtils.GotoTaxon(taxon);
                 TaxonUtils.SelectTaxon(taxon);
             }
         }
     }
     if (e.KeyCode == Keys.Down)
     {
         if (listBoxResult.Items.Count > 0)
         {
             e.Handled = true;
             listBoxResult.Focus();
             if (listBoxResult.SelectedIndex == -1)
             {
                 listBoxResult.SelectedIndex = 0;
             }
         }
     }
 }
예제 #5
0
        //---------------------------------------------------------------------------------
        // debut de database
        //Database.SQL DataBase = new Database.SQL();

        //---------------------------------------------------------------------------------
        public Form1(string[] args)
        {
            //----- tip manager
            TipManager.Start();

            //----- menu
            InitializeComponent();
            ApplyTheme();
            UpdateUI();

            //----- args
            if (args.Length > 0 && File.Exists(args[0]))
            {
                FileInfo fi = new FileInfo(args[0]);
                TaxonUtils.MyConfig.TaxonPath     = fi.Directory.FullName;
                TaxonUtils.MyConfig.TaxonFileName = fi.Name;
            }

            //----- load
            DateTime      startLoad  = DateTime.Now;
            TaxonTreeNode loadedNode = null;

            if (TaxonUtils.Exists())
            {
                loadedNode = TaxonTreeNode.Load(TaxonUtils.GetTaxonFileName());
            }
            if (loadedNode == null)
            {
                if (!TaxonTreeNode.LoadHasBeenCanceled() && !TaxonUtils.MyConfig.emptyTreeAtStartup)
                {
                    Loggers.WriteError(LogTags.Data, "Cannot open taxon file data : \n\n    " + TaxonUtils.GetTaxonFileName());
                }
            }
            else
            {
                string message = "open " + TaxonUtils.GetTaxonFileName() + " successful";
                message += "\n    " + loadedNode.Count() + " taxon loaded";
                message += "\n    " + loadedNode.Count(ClassicRankEnum.Espece) + " " + VinceToolbox.Helpers.enumHelper.GetEnumDescription(ClassicRankEnum.Espece);
                message += "," + loadedNode.Count(ClassicRankEnum.SousEspece) + " " + VinceToolbox.Helpers.enumHelper.GetEnumDescription(ClassicRankEnum.SousEspece);
                Loggers.WriteInformation(LogTags.Data, message);
            }

            FormAbout.SetSplashScreenMessage(".. End initialization ...");
            TaxonUtils.SetOriginalRoot(loadedNode);
            TaxonUtils.MainWindow = this;

            DateTime endLoad = DateTime.Now;

            TaxonControlList.OnRegisterTaxonControl      += TaxonControlList_OnRegisterTaxonControl;
            TaxonControlList.OnInitTaxonControlAfterLoad += TaxonControlList_OnInitTaxonControlAfterLoad;
            TaxonControlList.OnUnregisterTaxonControl    += TaxonControlList_OnUnregisterTaxonControl;
            SystemConfig.OnRunningModeChanged            += SystemConfig_OnRunningModeChanged;
            SystemConfig_OnRunningModeChanged(null, EventArgs.Empty);

            TaxonUtils.MyConfig.ToUI();
            taxonGraph_AddOneIfNone();

            Loggers.WriteInformation(LogTags.Data, "Total loading time: " + (int)((endLoad - startLoad).TotalMilliseconds));
        }
예제 #6
0
 //---------------------------------------------------------------------------------
 private void ClearCommonFilterToolStripMenuItem_Click(object sender, EventArgs e)
 {
     TaxonUtils.UpdateCurrentFilters(() =>
     {
         TaxonUtils.CurrentFilters.RemoveFilter <TaxonFilterUnnamed>();
         TaxonUtils.CurrentFilters.RemoveFilter <TaxonFilterRedListCategory>();
     });
 }
예제 #7
0
 //---------------------------------------------------------------------------------
 private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (TaxonUtils.Save(null, true, true))
     {
         DataAreDirty = false;
         UpdateUI();
     }
 }
예제 #8
0
        //====================================================================================
        // Misc functions
        //

        //---------------------------------------------------------------------------------
        public void Save()
        {
            if (TaxonUtils.Save())
            {
                DataAreDirty = false;
                UpdateUI();
            }
        }
예제 #9
0
 //-------------------------------------------------------------------
 public void MenuExport_Click(object sender, EventArgs e)
 {
     if (_MenuTaxonTreeNode == null)
     {
         return;
     }
     TaxonUtils.Save(_MenuTaxonTreeNode, true);
 }
예제 #10
0
 private void radioButtonSelected_CheckedChanged(object sender, EventArgs e)
 {
     if (_SuspendEvents)
     {
         return;
     }
     _TaxonRef = radioButtonRoot.Checked ? TaxonUtils.Root : TaxonUtils.SelectedTaxon();
     StartState_update();
 }
예제 #11
0
        public static string GetFolder()
        {
            string folder = Path.Combine(TaxonUtils.GetTaxonPath(), "ListOfTaxons");

            if (!System.IO.Directory.Exists(folder))
            {
                System.IO.Directory.CreateDirectory(folder);
            }
            return(folder);
        }
예제 #12
0
 //---------------------------------------------------------------------------------
 private void HideUnnamedToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (TaxonUtils.CurrentFilters.GetFilter <TaxonFilterUnnamed>() != null)
     {
         TaxonUtils.UpdateCurrentFilters(() => TaxonUtils.CurrentFilters.RemoveFilter <TaxonFilterUnnamed>());
     }
     else
     {
         TaxonUtils.UpdateCurrentFilters(() => TaxonUtils.CurrentFilters.AddFilter <TaxonFilterUnnamed>());
     }
 }
예제 #13
0
        public static void CreateFromDirectory(TaxonTreeNode _root, string path)
        {
            TaxonSearch searchTool    = new TaxonSearch(_root, true, true);
            int         countFound    = 0;
            int         countNotFound = 0;

            string[] files = Directory.GetFiles(path, "*.txt");

            string logFilename = Path.Combine(TaxonUtils.GetTaxonLocationPath(), "CreateFromDirectory.log");

            using (StreamWriter log = new StreamWriter(logFilename))
            {
                using (ProgressDialog progressDlg = new ProgressDialog())
                {
                    progressDlg.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
                    progressDlg.Show();

                    ProgressItem parseFiles = progressDlg.Add("parseFiles", "", 0, files.Length);
                    foreach (string file in files)
                    {
                        parseFiles.Inc(file);
                        log.WriteLine("Import " + file + ":");
                        France.Departement dep = France.Data.Departements.GetDepartementFromName(Path.GetFileNameWithoutExtension(file));
                        if (dep == null)
                        {
                            log.WriteLine("  associated departement not found");
                            continue;
                        }

                        TaxonList.ImportFileResult resultImport = TaxonList.ImportFile(file, searchTool);
                        log.WriteLine("  " + resultImport.TaxonsFound + " taxons found");
                        log.WriteLine("  " + resultImport.TaxonNotFound + " taxons not found");

                        countFound    += resultImport.TaxonsFound;
                        countNotFound += resultImport.TaxonNotFound;

                        TaxonList taxons = new TaxonList();
                        taxons.FromTaxonTreeNodeList(resultImport.List);
                        taxons.HasFile  = true;
                        taxons.FileName = Path.Combine(TaxonUtils.GetTaxonLocationPath(), dep.Id + ".xml");
                        taxons.Save();
                    }
                }
            }

            string message = "Create location data from directory " + path + ": \n";

            message += String.Format("    taxons found: {0}\n", countFound);
            message += String.Format("    taxons not found: {0}\n", countNotFound);
            message += String.Format("for more details, look at " + logFilename + " file, and all other generated logs");
            Loggers.WriteInformation(LogTags.Location, message);
        }
예제 #14
0
 //-------------------------------------------------------------------
 private void OnSelect(object sender, EventArgs e)
 {
     if (!(sender is ToolStripMenuItem))
     {
         return;
     }
     if (!((sender as ToolStripMenuItem).Tag is TaxonTreeNode node))
     {
         return;
     }
     TaxonUtils.GotoTaxon(node);
     TaxonUtils.SelectTaxon(node);
 }
예제 #15
0
 //------------------------------------------
 // recupère tous les fils quelquesoit leur génération mais avec une image
 public void GetAllChildrenWithImageRecursively(List <TaxonTreeNode> _allChildren)
 {
     if (Desc.HasImage && TaxonUtils.MatchCurrentFilters(this))
     {
         _allChildren.Add(this);
     }
     if (!HasChildrenWithImage)
     {
         return;
     }
     foreach (TaxonTreeNode child in _Children)
     {
         child.GetAllChildrenWithImageRecursively(_allChildren);
     }
 }
예제 #16
0
        //---------------------------------------------------------------------------------
        public void loadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string        filename = TaxonUtils.GetTaxonFileName();
            TaxonTreeNode node     = TaxonUtils.Load(ref filename);

            if (node == null)
            {
                return;
            }
            TaxonUtils.MyConfig.TaxonPath     = Path.GetDirectoryName(filename);
            TaxonUtils.MyConfig.TaxonFileName = Path.GetFileName(filename);
            TaxonUtils.SetOriginalRoot(node);
            TaxonUtils.Invalidate();
            TaxonUtils.GotoTaxon(node);
        }
예제 #17
0
        //-------------------------------------------------------------------
        public void MenuImport_Click(object sender, EventArgs e)
        {
            if (_MenuTaxonTreeNode == null)
            {
                return;
            }
            string        filename   = TaxonUtils.MyConfig.TaxonFileName;
            TaxonTreeNode importNode = TaxonUtils.Import(ref filename);

            if (importNode == null)
            {
                return;
            }
            ImportNode(_MenuTaxonTreeNode, importNode);
        }
예제 #18
0
 //-------------------------------------------------------------------
 private void FavoritesToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (_MenuTaxonTreeNode == null)
     {
         return;
     }
     if (TaxonUtils.Favorites.Contains(_MenuTaxonTreeNode.GetOriginal()))
     {
         TaxonUtils.FavoritesRemove(_MenuTaxonTreeNode);
     }
     else
     {
         TaxonUtils.FavoritesAdd(_MenuTaxonTreeNode);
     }
 }
예제 #19
0
 void OnChangedDelegate(FileSystemEventArgs e)
 {
     InitHtml();
     if (TaxonUtils.SelectedTaxon() == null)
     {
         return;
     }
     if (System.IO.Path.GetFileNameWithoutExtension(e.Name).ToLower() == TaxonUtils.SelectedTaxon().Desc.RefMultiName.Main.ToLower())
     {
         TreeOfLife.Controls.TaxonControlList.OnReselectTaxon(TaxonUtils.MainGraph.Selected);
     }
     else if (e.Name.StartsWith("_Style") || e.Name.StartsWith("_Template"))
     {
         TreeOfLife.Controls.TaxonControlList.OnReselectTaxon(TaxonUtils.MainGraph.Selected);
     }
 }
예제 #20
0
        //---------------------------------------------------------------------------------
        private void importToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fbd    = new FolderBrowserDialog();
            DialogResult        result = fbd.ShowDialog();

            TaxonTreeNode node = TaxonTreeNode.ImportOTT(fbd.SelectedPath);

            if (node == null)
            {
                return;
            }

            if (TaxonUtils.Save(node, true, true))
            {
                TaxonUtils.SetOriginalRoot(node);
            }
        }
예제 #21
0
 //---------------------------------------------------------------------------------
 private void _MultiImages_DoubleClick(object sender, Controls.TaxonMultiImageSoundControl.OnClickImageEventArgs e)
 {
     if (!(sender is Controls.TaxonMultiImageSoundControl))
     {
         return;
     }
     if (e.Taxon == null)
     {
         return;
     }
     if (_CurrentTaxon != e.Taxon)
     {
         TaxonUtils.GotoTaxon(e.Taxon);
         TaxonUtils.SelectTaxon(e.Taxon);
         return;
     }
     NumberInMultiImageControl = 1;
     _MultiImages.ScrollTo(e.ImageIndex, e.Item?.Bounds);
 }
예제 #22
0
        //-----------------------------------------------------------------------------------------
        void FavoritesToUI()
        {
            TaxonTreeNode root = TaxonUtils.OriginalRoot;

            if (root == null)
            {
                return;
            }

            List <TaxonTreeNode> favFound = new List <TaxonTreeNode>();

            foreach (string fav in Favorites)
            {
                TaxonTreeNode taxon = root.FindTaxonByFullName(fav);
                if (taxon != null)
                {
                    favFound.Add(taxon);
                }
            }
            TaxonUtils.FavoritesSet(favFound);
        }
예제 #23
0
        //--------------------------------------------------------------------------------------
        protected override void OnMouseDoubleClick(MouseEventArgs e)
        {
            if (MouseDoubleClickMode == MouseDoubleClickModeEnum.DoNothing)
            {
                return;
            }
            if (SelectedItem == null)
            {
                return;
            }
            if (!(SelectedItem is Taxon))
            {
                return;
            }

            TaxonUtils.GotoTaxon(SelectedItem as Taxon);
            if (MouseDoubleClickMode == MouseDoubleClickModeEnum.SelectTaxon)
            {
                TaxonUtils.SelectTaxon(SelectedItem as Taxon);
            }
        }
예제 #24
0
 //-------------------------------------------------------------------
 protected override void OnMouseDoubleClick(MouseEventArgs e)
 {
     if (Selected != null && ShortcutModeKeyOn())
     {
         foreach (ShortcutData data in ShortcutModeDatas.Values)
         {
             if (data.Siblings.TryGetValue(Selected, out Rectangle R))
             {
                 ShortcutModeClear();
                 TaxonUtils.MoveTaxonTo(Selected, R);
                 return;
             }
         }
     }
     if (BelowMouse == null)
     {
         TaxonTreeNode taxon = TaxonUtils.Root;
         TaxonUtils.SelectTaxon(taxon);
         TaxonUtils.GotoTaxon(taxon);
     }
 }
예제 #25
0
 private void ButtonBrowseDestination_Click(object sender, EventArgs e)
 {
     using (var fbd = new FolderBrowserDialog())
     {
         fbd.Description = "Select destination folder";
         if (textBoxDestination.Text != "")
         {
             fbd.SelectedPath = textBoxDestination.Text;
         }
         else
         {
             fbd.SelectedPath = TaxonUtils.GetTaxonPath();
         }
         DialogResult result = fbd.ShowDialog();
         if (result != DialogResult.OK || string.IsNullOrWhiteSpace(fbd.SelectedPath))
         {
             return;
         }
         textBoxDestination.Text = fbd.SelectedPath;
     }
 }
예제 #26
0
        private void buttonStart_Click(object sender, EventArgs e)
        {
            List <TaxonTreeNode> Species = new List <TaxonTreeNode>();

            TaxonUtils.Root.GetAllChildrenRecursively(Species, ClassicRankEnum.Espece);
            TaxonUtils.Root.GetAllChildrenRecursively(Species, ClassicRankEnum.SousEspece);

            _TaxonInput = new List <TaxonTreeNode>();
            foreach (TaxonTreeNode taxon in Species)
            {
                if (taxon.Desc.HasImage)
                {
                    _TaxonInput.Add(taxon);
                }
            }

            if (_Input == DataEnum.French)
            {
                Species     = _TaxonInput;
                _TaxonInput = new List <TaxonTreeNode>();
                foreach (TaxonTreeNode taxon in Species)
                {
                    if (taxon.Desc.HasFrenchName)
                    {
                        _TaxonInput.Add(taxon);
                    }
                }
            }

            if (Species.Count == 0)
            {
                MessageBox.Show("No taxon found for this game", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            _CurrentInput = TaxonUtils.RandomTaxon(_TaxonInput, 1)[0];
            _State        = StateEnum.InGame;
            UpdatePanel();
            InitGame();
        }
예제 #27
0
        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TaxonDialog.NewTaxon dlg = new TaxonDialog.NewTaxon(null)
            {
                TopMost        = true,
                CheckNameUsage = true
            };
            dlg.ShowDialog();
            if (dlg.DialogResult != DialogResult.OK)
            {
                return;
            }

            TaxonDesc desc = new TaxonDesc(dlg.TaxonName);

            TaxonTreeNode root = new TaxonTreeNode(desc);

            TaxonUtils.SetOriginalRoot(root);
            TaxonUtils.MyConfig.TaxonFileName = "";
            TaxonUtils.MyConfig.saved         = false;
            TaxonUtils.MainGraph.Root         = root;
            TaxonUtils.MainGraph.ResetView();
        }
예제 #28
0
        public void SaveBin(string _fileName)
        {
            TaxonUtils.LockMainWindow();
            try
            {
                using (ProgressDialog progressDlg = new ProgressDialog())
                {
                    progressDlg.StartPosition = FormStartPosition.CenterScreen;
                    progressDlg.Show();

                    ProgressItem piSave = progressDlg.Add("Saving ...", null, 0, Count());
                    using (FileStream fs = File.Create(_fileName, 65536, FileOptions.None))
                    {
                        using (DeflateStream deflateStream = new DeflateStream(fs, CompressionMode.Compress))
                        {
                            using (BinaryWriter w = new BinaryWriter(deflateStream))
                            //using (BinaryWriter w = new BinaryWriter(fs))
                            {
                                w.Write(SaveBinVersion);
                                SaveBin(w, new SaveBinProgress(piSave));
                                w.Close();
                                deflateStream.Close();
                                fs.Close();
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Loggers.WriteError(LogTags.Data, "Exception while saving config file : \n    " + _fileName + "\n" + e.Message);
            }
            finally
            {
                TaxonUtils.UnlockMainWindow();
            }
        }
예제 #29
0
 //-------------------------------------------------------------------
 protected override void OnMouseUp(MouseEventArgs e)
 {
     if (move)
     {
         _InertiaMove.EndSamples();
         move = false;
         return;
     }
     mouseDown = false;
     if (e.Button == MouseButtons.Left)
     {
         if (!_EditionToolInfo.DoAction())
         {
             if (BelowMouse == null)
             {
                 TaxonUtils.GotoTaxon(Selected);
             }
             else
             {
                 Selected = BelowMouse;
             }
         }
     }
 }
예제 #30
0
        //=========================================================================================
        // Taxon graph messages
        //

        //---------------------------------------------------------------------------------
        private void taxonGraph_OnSelectedChanged(object sender, EventArgs e)
        {
            TaxonUtils.HistoryAdd(TaxonUtils.MainGraph.Selected);
            TaxonControlList.OnSelectTaxon(TaxonUtils.MainGraph.Selected);
            //TaxonControlList.OnSelectTaxon(TaxonUtils.MainGraph.SelectedInOriginal);
        }