PageRenderTime 104ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/Tags/DateTag.cs

https://github.com/rggjan/Tomboy-Todo-List
C# | 133 lines | 53 code | 14 blank | 66 comment | 4 complexity | 529e2a17c9c31717333cbe5a9f12dfa8 MD5 | raw file
Possible License(s): LGPL-2.1
  1. // Permission is hereby granted, free of charge, to any person obtaining
  2. // a copy of this software and associated documentation files (the
  3. // "Software"), to deal in the Software without restriction, including
  4. // without limitation the rights to use, copy, modify, merge, publish,
  5. // distribute, sublicense, and/or sell copies of the Software, and to
  6. // permit persons to whom the Software is furnished to do so, subject to
  7. // the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be
  10. // included in all copies or substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  13. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  15. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  16. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  17. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  18. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. //
  20. // Authors:
  21. // Jan Rüegg <rggjan@gmail.com>
  22. // Gabriel Walch <walchg@student.ethz.ch>
  23. // Gerd Zellweger <mail@gerdzellweger.com>
  24. //
  25. using System;
  26. using System.Collections.Generic;
  27. using Gtk;
  28. namespace Tomboy.TaskManager
  29. {
  30. /// <summary>
  31. /// Tag that identifies a duedate.
  32. /// It is responsible for listening to clicks (opening calendar dialog), but also finding the duedate later on
  33. /// </summary>
  34. public class DateTag : NoteTag
  35. {
  36. /// <summary>
  37. /// Calendar passed to the Dialog
  38. /// </summary>
  39. private Calendar calendar;
  40. private TextRange range;
  41. private NoteEditor editor;
  42. private TaskManagerNoteAddin addin;
  43. /// <summary>
  44. /// Initialisation with the name and the tasknote
  45. /// </summary>
  46. /// <param name="name">
  47. /// A <see cref="System.String"/>
  48. /// </param>
  49. /// <param name="addin">
  50. /// A <see cref="TaskManagerNoteAddin"/>
  51. /// </param>
  52. public DateTag (string name, TaskManagerNoteAddin addin) : base (name)
  53. {
  54. this.addin = addin;
  55. }
  56. public override void Initialize (string elementName)
  57. {
  58. base.Initialize (elementName);
  59. //Underline = Pango.Underline.Single;
  60. Foreground = "purple";
  61. CanActivate = true;
  62. CanGrow = true;
  63. }
  64. /// <summary>
  65. /// Handles the click on the datetag:
  66. /// Opens up a calendar dialog
  67. /// </summary>
  68. /// <param name="editor">
  69. /// A <see cref="NoteEditor"/>
  70. /// </param>
  71. /// <param name="start">
  72. /// A <see cref="Gtk.TextIter"/>
  73. /// </param>
  74. /// <param name="end">
  75. /// A <see cref="Gtk.TextIter"/>
  76. /// </param>
  77. /// <returns>
  78. /// A <see cref="System.Boolean"/>
  79. /// </returns>
  80. protected override bool OnActivate (NoteEditor editor, Gtk.TextIter start, Gtk.TextIter end)
  81. {
  82. calendar = new Calendar ();
  83. range = new TextRange (start, end);
  84. this.editor = editor;
  85. Dialog dialog = new Dialog ();
  86. dialog.Modal = true;
  87. dialog.VBox.Add (calendar);
  88. dialog.VBox.ShowAll ();
  89. dialog.AddButton ("OK", ResponseType.Ok);
  90. dialog.AddButton ("Cancel", ResponseType.Cancel);
  91. dialog.Response += new ResponseHandler (OnDialogResponse);
  92. dialog.Run ();
  93. dialog.Destroy ();
  94. return true;
  95. }
  96. /// <summary>
  97. /// Gets the selected date from the calendar and updates the region of the duedate
  98. /// </summary>
  99. /// <param name="obj">
  100. /// A <see cref="System.Object"/>
  101. /// </param>
  102. /// <param name="args">
  103. /// A <see cref="ResponseArgs"/>
  104. /// </param>
  105. void OnDialogResponse (object obj, ResponseArgs args)
  106. {
  107. if (args.ResponseId != ResponseType.Ok)
  108. return;
  109. TextIter start = range.Start;
  110. TextIter end = range.End;
  111. string newdate = calendar.GetDate ().ToShortDateString ();
  112. editor.Buffer.Delete (ref start, ref end);
  113. editor.Buffer.InsertWithTags (ref start, newdate, new TextTag[]{this});
  114. Task t = addin.Utils.GetTask (start);
  115. if (t != null)
  116. t.TagUpdate ();
  117. }
  118. }
  119. }