PageRenderTime 59ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/NekoKun.Editor/Core/WelcomePage.cs

https://bitbucket.org/nekokun/nekokun
C# | 146 lines | 128 code | 16 blank | 2 comment | 22 complexity | e31e1089aa68671322b9975cd1493c89 MD5 | raw file
Possible License(s): MIT, CC-BY-SA-3.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. namespace NekoKun
  9. {
  10. public partial class WelcomePage : NekoKun.UI.LynnForm
  11. {
  12. public string Result;
  13. protected List<string> projects;
  14. public WelcomePage()
  15. {
  16. InitializeComponent();
  17. projects = SettingsManager.GlobalSettings["DocumentFramework.MRUProjects"] as List<string> ?? new List<string>();
  18. ReloadListbox();
  19. this.listbox.MouseMove += new MouseEventHandler(listbox_MouseMove);
  20. this.listbox.MouseClick += new MouseEventHandler(listbox_MouseClick);
  21. this.listbox.KeyDown += new KeyEventHandler(listbox_KeyDown);
  22. this.listbox.AllowDrop = true;
  23. this.listbox.DragEnter += new DragEventHandler(listbox_DragEnter);
  24. this.listbox.DragDrop += new DragEventHandler(listbox_DragDrop);
  25. }
  26. void listbox_DragDrop(object sender, DragEventArgs e)
  27. {
  28. if (e.Data.GetDataPresent(System.Windows.Forms.DataFormats.FileDrop))
  29. {
  30. try
  31. {
  32. string[] files = e.Data.GetData(System.Windows.Forms.DataFormats.FileDrop) as string[];
  33. SetResult(files[0]);
  34. }
  35. catch { }
  36. }
  37. }
  38. void listbox_DragEnter(object sender, DragEventArgs e)
  39. {
  40. if (e.Data.GetDataPresent(System.Windows.Forms.DataFormats.FileDrop))
  41. e.Effect = DragDropEffects.Copy;
  42. }
  43. private void ReloadListbox()
  44. {
  45. this.listbox.Items.Clear();
  46. this.listbox.Items.Add("???? . . . ");
  47. this.listbox.Items.Add("?????? . . . ");
  48. this.listbox.Items.AddRange(projects.ToArray());
  49. }
  50. void listbox_KeyDown(object sender, KeyEventArgs e)
  51. {
  52. if (e.Modifiers == Keys.None && e.KeyCode == Keys.Enter)
  53. {
  54. ParseIndex(this.listbox.SelectedIndex);
  55. }
  56. }
  57. void listbox_MouseClick(object sender, MouseEventArgs e)
  58. {
  59. ParseIndex(this.listbox.IndexFromPoint(e.Location));
  60. }
  61. private void ParseIndex(int p)
  62. {
  63. if (p == 0)
  64. {
  65. CreateProjectWizard wizard = new CreateProjectWizard();
  66. if (wizard.ShowDialog(this) == DialogResult.OK)
  67. {
  68. SetResult(wizard.FileName);
  69. }
  70. }
  71. else if (p == 1)
  72. {
  73. OpenFileDialog dialog = new OpenFileDialog();
  74. dialog.AddExtension = true;
  75. //dialog.AutoUpgradeEnabled = true;
  76. dialog.CheckFileExists = true;
  77. dialog.CheckPathExists = true;
  78. dialog.DefaultExt = "nkproj";
  79. dialog.DereferenceLinks = true;
  80. dialog.Filter = "NekoKun ?? (*.nkproj)|*.nkproj";
  81. dialog.Multiselect = false;
  82. dialog.ShowReadOnly = false;
  83. dialog.SupportMultiDottedExtensions = true;
  84. dialog.ValidateNames = true;
  85. if (dialog.ShowDialog(this) == DialogResult.OK)
  86. {
  87. SetResult(dialog.FileName);
  88. }
  89. }
  90. else if (p >= 2 && p <= this.projects.Count + 2)
  91. {
  92. SetResult(this.projects[p - 2]);
  93. }
  94. //throw new NotImplementedException();
  95. }
  96. void AddMRU(string filename)
  97. {
  98. List<string> newp = new List<string>();
  99. if (System.IO.File.Exists(filename))
  100. newp.Add(System.IO.Path.GetFullPath(filename));
  101. foreach (string item in this.projects)
  102. {
  103. if (System.IO.File.Exists(item) && (!newp.Contains(System.IO.Path.GetFullPath(item))))
  104. {
  105. newp.Add(item);
  106. }
  107. }
  108. this.projects = newp;
  109. SettingsManager.GlobalSettings["DocumentFramework.MRUProjects"] = this.projects;
  110. SettingsManager.GlobalSettings.Commit();
  111. }
  112. void SetResult(string filename)
  113. {
  114. AddMRU(filename);
  115. if (!System.IO.File.Exists(filename))
  116. {
  117. MessageBox.Show(this, "????????“" + filename + "”?", "NekoKun", MessageBoxButtons.OK, MessageBoxIcon.Error);
  118. this.ReloadListbox();
  119. return;
  120. }
  121. this.DialogResult = DialogResult.OK;
  122. this.Result = filename;
  123. this.Close();
  124. }
  125. void listbox_MouseMove(object sender, MouseEventArgs e)
  126. {
  127. this.listbox.SelectedItem = null;
  128. }
  129. }
  130. }