//----------------------------------------------------------------------------------------- //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); }
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); } } }
//--------------------------------------------------------------------------------- private void createNewTreeToolStripMenuItem_Click(object sender, EventArgs e) { TaxonTreeNode root = new TaxonTreeNode(new TaxonDesc("root")); TaxonUtils.Save(root, true, true); TaxonUtils.SetOriginalRoot(root); }
//------------------------------------------------------------------- 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; } } } }
//--------------------------------------------------------------------------------- // 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)); }
//--------------------------------------------------------------------------------- private void ClearCommonFilterToolStripMenuItem_Click(object sender, EventArgs e) { TaxonUtils.UpdateCurrentFilters(() => { TaxonUtils.CurrentFilters.RemoveFilter <TaxonFilterUnnamed>(); TaxonUtils.CurrentFilters.RemoveFilter <TaxonFilterRedListCategory>(); }); }
//--------------------------------------------------------------------------------- private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) { if (TaxonUtils.Save(null, true, true)) { DataAreDirty = false; UpdateUI(); } }
//==================================================================================== // Misc functions // //--------------------------------------------------------------------------------- public void Save() { if (TaxonUtils.Save()) { DataAreDirty = false; UpdateUI(); } }
//------------------------------------------------------------------- public void MenuExport_Click(object sender, EventArgs e) { if (_MenuTaxonTreeNode == null) { return; } TaxonUtils.Save(_MenuTaxonTreeNode, true); }
private void radioButtonSelected_CheckedChanged(object sender, EventArgs e) { if (_SuspendEvents) { return; } _TaxonRef = radioButtonRoot.Checked ? TaxonUtils.Root : TaxonUtils.SelectedTaxon(); StartState_update(); }
public static string GetFolder() { string folder = Path.Combine(TaxonUtils.GetTaxonPath(), "ListOfTaxons"); if (!System.IO.Directory.Exists(folder)) { System.IO.Directory.CreateDirectory(folder); } return(folder); }
//--------------------------------------------------------------------------------- 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>()); } }
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); }
//------------------------------------------------------------------- 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); }
//------------------------------------------ // 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); } }
//--------------------------------------------------------------------------------- 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); }
//------------------------------------------------------------------- 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); }
//------------------------------------------------------------------- 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); } }
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); } }
//--------------------------------------------------------------------------------- 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); } }
//--------------------------------------------------------------------------------- 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); }
//----------------------------------------------------------------------------------------- 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); }
//-------------------------------------------------------------------------------------- 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); } }
//------------------------------------------------------------------- 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); } }
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; } }
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(); }
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(); }
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(); } }
//------------------------------------------------------------------- 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; } } } }
//========================================================================================= // 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); }