PageRenderTime 53ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/settings/project/ProjectConditionsPanel.cs

https://github.com/moscrif/ide
C# | 460 lines | 305 code | 118 blank | 37 comment | 69 complexity | 611221193272e04bb3442efa80baa49b MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using Gtk;
  4. using Moscrif.IDE.Workspace;
  5. using Moscrif.IDE.Controls;
  6. using MessageDialogs = Moscrif.IDE.Controls.MessageDialog;
  7. using System.Linq;
  8. using Moscrif.IDE.Iface.Entities;
  9. namespace Moscrif.IDE.Option
  10. {
  11. internal class ProjectConditionsPanel : OptionsPanel
  12. {
  13. ProjectConditionsWidget widget;
  14. Project project ;
  15. public override Widget CreatePanelWidget()
  16. {
  17. return widget = new ProjectConditionsWidget(project,ParentDialog);
  18. }
  19. public override void ApplyChanges()
  20. {
  21. widget.Store();
  22. }
  23. public override void ShowPanel()
  24. {
  25. }
  26. public override bool ValidateChanges()
  27. {
  28. return true;
  29. }
  30. public override void Initialize(PreferencesDialog dialog, object dataObject)
  31. {
  32. base.Initialize(dialog, dataObject);
  33. if (dataObject.GetType() == typeof(Project))
  34. project=(Project)dataObject;
  35. }
  36. public override string Label {
  37. get { return MainClass.Languages.Translate("conditions"); }
  38. }
  39. public override string Icon {
  40. get { return "conditions.png"; }
  41. }
  42. }
  43. public partial class ProjectConditionsWidget : Gtk.Bin
  44. {
  45. private Project project;
  46. private List<Condition> conditions;
  47. private bool generatePublishList = false;
  48. private int maxCond = 0;
  49. Gtk.Window parentWindow;
  50. Gtk.ListStore conditionStore = new Gtk.ListStore(typeof(int), typeof(string),typeof(Condition));
  51. Gtk.ListStore ruleStore = new Gtk.ListStore(typeof(int), typeof(string),typeof(Rule));
  52. public ProjectConditionsWidget(Project project,Gtk.Window parent)
  53. {
  54. parentWindow = parent;
  55. this.Build();
  56. this.project = project;
  57. tvConditions.AppendColumn(MainClass.Languages.Translate("id"), new Gtk.CellRendererText(), "text", 0);
  58. tvConditions.AppendColumn(MainClass.Languages.Translate("name"), new Gtk.CellRendererText(), "text", 1);
  59. tvRules.AppendColumn(MainClass.Languages.Translate("id"), new Gtk.CellRendererText(), "text", 0);
  60. tvRules.AppendColumn(MainClass.Languages.Translate("name"), new Gtk.CellRendererText(), "text", 1);
  61. /*if(project.SelectResolution != null)
  62. resolutions = new List<int>( project.SelectResolution);
  63. else
  64. resolutions = new List<int>();*/
  65. tvConditions.Model = conditionStore;
  66. tvRules.Model = ruleStore;
  67. //tvResolution.Selection.Mode = Gtk.SelectionMode.Multiple;
  68. if ( project.ConditoinsDefine == null) return;
  69. this.conditions = new List<Condition>();
  70. //this.resolution = project.Resolution.Clone();
  71. //foreach (Rule rl in MainClass.Settings.Resolution.Rules ){
  72. //Gtk.TreeIter tir = resolStore.AppendValues(rl.Id,rl.Name,rl.Specific,rl);
  73. //if (this.project.Resolution != null) {
  74. // int indx = MainClass.Settings.Resolution.Rules.FindIndex(x=> x.Id == rl.Id);
  75. //if (indx > -1)
  76. // tvResolution.Selection.SelectIter(tir);
  77. //}
  78. //}
  79. //conditions = new List<Condition>(project.ConditoinsDefine.ToArray());
  80. conditions =MainClass.Tools.Clone(project.ConditoinsDefine);
  81. TreeIter ti = new TreeIter();
  82. foreach (Condition cd in conditions){
  83. ti = conditionStore.AppendValues(cd.Id,cd.Name,cd);
  84. if (maxCond < cd.Id) maxCond = cd.Id;
  85. }
  86. tvConditions.Selection.Changed += delegate(object sender, EventArgs e)
  87. {
  88. ruleStore.Clear();
  89. Condition cd =GetSelected();
  90. if (cd == null ) return;
  91. foreach (Rule rl in cd.Rules){
  92. ruleStore.AppendValues(rl.Id,rl.Name,rl);
  93. }
  94. };
  95. if (conditions.Count>0)
  96. tvConditions.Selection.SelectIter(ti);
  97. //project.ConditoinsDefine
  98. /*tvResolution.Selection.Changed+= delegate(object sender, EventArgs e) {
  99. generatePublishList = true;
  100. };*/
  101. }
  102. private Condition GetSelected()
  103. {
  104. TreeSelection ts = tvConditions.Selection;
  105. TreeIter ti = new TreeIter();
  106. ts.GetSelected(out ti);
  107. TreePath[] tp = ts.GetSelectedRows();
  108. if (tp.Length < 1)
  109. return null;
  110. return (Condition)tvConditions.Model.GetValue(ti, 2);
  111. }
  112. public void Store()
  113. {
  114. if(project.ConditoinsDefine!= null)
  115. project.ConditoinsDefine.Clear();
  116. project.ConditoinsDefine = new List<Condition>(conditions.ToArray());
  117. //project.Resolution.Rules.Clear();
  118. /*project.SelectResolution = new List<int>();
  119. project.SelectResolution = new List<int>(resolutions);
  120. string name = MainClass.Settings.Resolution.Name;
  121. tvResolution.Selection.SelectedForeach(delegate (Gtk.TreeModel model, Gtk.TreePath path, Gtk.TreeIter iter){
  122. Rule rule = (Rule)model.GetValue(iter, 3);
  123. //project.Resolution.Rules.Add(rule);
  124. project.SelectResolution.Add(rule.Id);
  125. });
  126. string name2 = MainClass.Settings.Resolution.Name;*/
  127. if (generatePublishList)
  128. project.GeneratePublishCombination();
  129. }
  130. protected virtual void OnBtnAddCondClicked (object sender, System.EventArgs e)
  131. {
  132. if(!MainClass.LicencesSystem.CheckFunction("conditions",parentWindow)){
  133. return;
  134. }
  135. EntryDialog ed = new EntryDialog("",MainClass.Languages.Translate("new_conditions"),parentWindow);
  136. int result = ed.Run();
  137. if (result == (int)ResponseType.Ok){
  138. string newStr = ed.TextEntry;
  139. if (!String.IsNullOrEmpty(newStr) ){
  140. Condition cdFind = conditions.Find(x=>x.Name.ToUpper() ==newStr.ToUpper());
  141. if (cdFind != null){
  142. MessageDialogs md = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("conditions_is_exist", cdFind.Name), "", Gtk.MessageType.Error,parentWindow);
  143. md.ShowDialog();
  144. ed.Destroy();
  145. return;
  146. }
  147. Condition cd= new Condition();
  148. cd.Name =newStr;
  149. maxCond ++;
  150. cd.Id = maxCond;
  151. conditionStore.AppendValues(maxCond,cd.Name,cd);
  152. conditions.Add(cd);
  153. }
  154. }
  155. ed.Destroy();
  156. }
  157. protected virtual void OnBtnDeleteCondClicked (object sender, System.EventArgs e)
  158. {
  159. if(!MainClass.LicencesSystem.CheckFunction("conditions",parentWindow)){
  160. return;
  161. }
  162. TreeSelection ts = tvConditions.Selection;
  163. TreeIter ti = new TreeIter();
  164. ts.GetSelected(out ti);
  165. TreePath[] tp = ts.GetSelectedRows();
  166. if (tp.Length < 1)
  167. return ;
  168. Condition cd = (Condition)tvConditions.Model.GetValue(ti, 2);
  169. if (cd == null) return;
  170. MessageDialogs md = new MessageDialogs(MessageDialogs.DialogButtonType.YesNo, MainClass.Languages.Translate("delete_conditions", cd.Name), "", Gtk.MessageType.Question,parentWindow);
  171. int result = md.ShowDialog();
  172. if (result != (int)Gtk.ResponseType.Yes)
  173. return;
  174. conditions.Remove(cd);
  175. ruleStore.Clear();
  176. conditionStore.Remove(ref ti);
  177. }
  178. protected virtual void OnBtnEditCondClicked (object sender, System.EventArgs e)
  179. {
  180. if(!MainClass.LicencesSystem.CheckFunction("conditions",parentWindow)){
  181. return;
  182. }
  183. TreeSelection ts = tvConditions.Selection;
  184. TreeIter ti = new TreeIter();
  185. ts.GetSelected(out ti);
  186. TreePath[] tp = ts.GetSelectedRows();
  187. if (tp.Length < 1)
  188. return ;
  189. Condition cd = (Condition)tvConditions.Model.GetValue(ti, 2);
  190. if (cd == null) return;
  191. EntryDialog ed = new EntryDialog(cd.Name,MainClass.Languages.Translate("new_conditions"),parentWindow);
  192. int result = ed.Run();
  193. if (result == (int)ResponseType.Ok){
  194. string newStr = ed.TextEntry;
  195. if (!String.IsNullOrEmpty(newStr) ){
  196. if (newStr == cd.Name) return;
  197. Condition cdFind = conditions.Find(x=>x.Name.ToUpper() ==newStr.ToUpper());
  198. if (cdFind != null){
  199. MessageDialogs md = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("conditions_is_exist", cdFind.Name), "", Gtk.MessageType.Error,parentWindow);
  200. md.ShowDialog();
  201. ed.Destroy();
  202. return;
  203. }
  204. Condition cdEdited = conditions.Find(x => x.Id == cd.Id);
  205. if (cdEdited == null){
  206. MessageDialogs md = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("unspecified_error"), "", Gtk.MessageType.Error,parentWindow);
  207. md.ShowDialog();
  208. ed.Destroy();
  209. return;
  210. }
  211. cdEdited.Name=newStr;
  212. conditionStore.SetValues(ti,cdEdited.Id,cdEdited.Name,cdEdited);
  213. //conditions.Find(cd).Name =ed.TextEntry;
  214. }
  215. }
  216. ed.Destroy();
  217. }
  218. protected virtual void OnBtnAddRulesClicked (object sender, System.EventArgs e)
  219. {
  220. if(!MainClass.LicencesSystem.CheckFunction("conditions",parentWindow)){
  221. return;
  222. }
  223. TreeSelection ts = tvConditions.Selection;
  224. TreeIter ti = new TreeIter();
  225. ts.GetSelected(out ti);
  226. TreePath[] tp = ts.GetSelectedRows();
  227. if (tp.Length < 1)
  228. return ;
  229. Condition cd = (Condition)tvConditions.Model.GetValue(ti, 2);
  230. if (cd == null) return;
  231. EntryDialog ed = new EntryDialog("",MainClass.Languages.Translate("new_rule"),parentWindow);
  232. int result = ed.Run();
  233. if (result == (int)ResponseType.Ok){
  234. string newStr = ed.TextEntry;
  235. if (!String.IsNullOrEmpty(newStr) ){
  236. int maxCountRule = 0;
  237. foreach (Rule rlf in cd.Rules){
  238. if (maxCountRule < rlf.Id) maxCountRule = rlf.Id;
  239. }
  240. Rule rlFind = cd.Rules.Find(x=>x.Name.ToUpper() ==newStr.ToUpper());
  241. if (rlFind != null){
  242. MessageDialogs md = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("rule_is_exist", rlFind.Name), "", Gtk.MessageType.Error,parentWindow);
  243. md.ShowDialog();
  244. ed.Destroy();
  245. return;
  246. }
  247. Rule rl= new Rule();
  248. rl.Name =newStr;
  249. maxCountRule++;
  250. rl.Id = maxCountRule;
  251. ruleStore.AppendValues(maxCountRule,rl.Name,rl);
  252. Condition cd2 = conditions.Find(x => x.Id == cd.Id);
  253. cd2.Rules.Add(rl);
  254. conditionStore.SetValues(ti,cd2.Id,cd2.Name,cd2);
  255. }
  256. }
  257. ed.Destroy();
  258. }
  259. protected virtual void OnBtnDeleteCond1Clicked(object sender, System.EventArgs e)
  260. {
  261. if(!MainClass.LicencesSystem.CheckFunction("conditions",parentWindow)){
  262. return;
  263. }
  264. TreeSelection ts = tvConditions.Selection;
  265. TreeIter ti = new TreeIter();
  266. ts.GetSelected(out ti);
  267. TreePath[] tp = ts.GetSelectedRows();
  268. if (tp.Length < 1)
  269. return ;
  270. Condition cd = (Condition)tvConditions.Model.GetValue(ti, 2);
  271. if (cd == null) return;
  272. TreeSelection tsR = tvRules.Selection;
  273. TreeIter tiR = new TreeIter();
  274. tsR.GetSelected(out tiR);
  275. TreePath[] tpR = tsR.GetSelectedRows();
  276. if (tpR.Length < 1)
  277. return ;
  278. Rule rl = (Rule)tvRules.Model.GetValue(tiR, 2);
  279. if (rl == null) return;
  280. MessageDialogs md = new MessageDialogs(MessageDialogs.DialogButtonType.YesNo, MainClass.Languages.Translate("delete_rule", rl.Name), "", Gtk.MessageType.Question,parentWindow);
  281. int result = md.ShowDialog();
  282. if (result != (int)Gtk.ResponseType.Yes)
  283. return;
  284. ruleStore.Remove(ref tiR);
  285. Condition cd2 = conditions.Find(x => x.Id == cd.Id);
  286. cd2.Rules.Remove(rl);
  287. conditionStore.SetValues(ti,cd2.Id,cd2.Name,cd2);
  288. }
  289. protected virtual void OnBtnEditCond1Clicked (object sender, System.EventArgs e)
  290. {
  291. if(!MainClass.LicencesSystem.CheckFunction("conditions",parentWindow)){
  292. return;
  293. }
  294. TreeSelection ts = tvConditions.Selection;
  295. TreeIter ti = new TreeIter();
  296. ts.GetSelected(out ti);
  297. TreePath[] tp = ts.GetSelectedRows();
  298. if (tp.Length < 1)
  299. return ;
  300. Condition cd = (Condition)tvConditions.Model.GetValue(ti, 2);
  301. if (cd == null) return;
  302. TreeSelection tsR = tvRules.Selection;
  303. TreeIter tiR = new TreeIter();
  304. tsR.GetSelected(out tiR);
  305. TreePath[] tpR = tsR.GetSelectedRows();
  306. if (tpR.Length < 1)
  307. return ;
  308. Rule rl = (Rule)tvRules.Model.GetValue(tiR, 2);
  309. EntryDialog ed = new EntryDialog(rl.Name,MainClass.Languages.Translate("new_name"));
  310. int result = ed.Run();
  311. if (result == (int)ResponseType.Ok){
  312. string newStr = ed.TextEntry;
  313. if (!String.IsNullOrEmpty(newStr) ){
  314. Rule rlFind = cd.Rules.Find(x=>x.Name.ToUpper() ==newStr.ToUpper());
  315. if (rlFind != null){
  316. MessageDialogs md = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("rule_is_exist", rlFind.Name), "", Gtk.MessageType.Error,parentWindow);
  317. md.ShowDialog();
  318. ed.Destroy();
  319. return;
  320. }
  321. Condition cd2 = conditions.Find(x => x.Id == cd.Id);
  322. cd2.Rules.Remove(rl);
  323. rl.Name =newStr;
  324. ruleStore.SetValues(tiR,rl.Id,rl.Name,rl);
  325. cd2.Rules.Add(rl);
  326. conditionStore.SetValues(ti,cd2.Id,cd2.Name,cd2);
  327. //cd.Rules.Add(rl);
  328. }
  329. }
  330. ed.Destroy();
  331. }
  332. protected virtual void OnBtnTestClicked (object sender, System.EventArgs e)
  333. {
  334. //Console.WriteLine("project.Conditions>>"+project.ConditoinsDefine.Count);
  335. }
  336. }
  337. }