[chronojump] tags can be deleted



commit 6803c224b38fc79134cf58441c2b4614842cb4ca
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Dec 1 17:36:02 2020 +0100

    tags can be deleted

 src/gui/app1/session/addEdit.cs          |  2 +-
 src/gui/app1/session/tagSessionSelect.cs | 23 ++++++++++++++++++++++-
 src/sqlite/tagSession.cs                 | 18 ++++++++++++++++++
 3 files changed, 41 insertions(+), 2 deletions(-)
---
diff --git a/src/gui/app1/session/addEdit.cs b/src/gui/app1/session/addEdit.cs
index 950033ca..3e588dd8 100644
--- a/src/gui/app1/session/addEdit.cs
+++ b/src/gui/app1/session/addEdit.cs
@@ -545,7 +545,7 @@ public partial class ChronoJumpWindow
 
                tagSessionSelect = new TagSessionSelect();
 
-               tagSessionSelect.PassVariables(currentSession.UniqueID);
+               tagSessionSelect.PassVariables(currentSession.UniqueID, preferences.askDeletion);
 
                tagSessionSelect.FakeButtonDone.Clicked -= new EventHandler(on_select_tags_clicked_done);
                tagSessionSelect.FakeButtonDone.Clicked += new EventHandler(on_select_tags_clicked_done);
diff --git a/src/gui/app1/session/tagSessionSelect.cs b/src/gui/app1/session/tagSessionSelect.cs
index 5a7ec94c..3200f1b5 100644
--- a/src/gui/app1/session/tagSessionSelect.cs
+++ b/src/gui/app1/session/tagSessionSelect.cs
@@ -32,6 +32,7 @@ public class TagSessionSelect
 {
        //passed variables
        private int currentSessionID;
+       private bool askDeletion;
 
        private ArrayList allTags_list; //all available tags
        private ArrayList allTags_listPrint;
@@ -43,9 +44,11 @@ public class TagSessionSelect
 
        public Gtk.Button FakeButtonDone;
 
-       public void PassVariables(int currentSessionID)
+       public void PassVariables(int currentSessionID, bool askDeletion)
        {
                this.currentSessionID = currentSessionID;
+               this.askDeletion = askDeletion;
+
                FakeButtonDone = new Gtk.Button();
        }
 
@@ -254,7 +257,25 @@ public class TagSessionSelect
 
                Sqlite.Close();
        }
+
        private void on_tag_session_win_row_delete_prequestion (object o, EventArgs args)
        {
+               if(askDeletion) {
+                       ConfirmWindow confirmWin = ConfirmWindow.Show(Catalog.GetString(
+                                               "Are you sure you want to delete this tag?"), "", "");
+                       confirmWin.Button_accept.Clicked += new EventHandler(on_tag_session_win_row_delete);
+               } else
+                       on_tag_session_win_row_delete (o, args);
+       }
+       private void on_tag_session_win_row_delete (object o, EventArgs args)
+       {
+               LogB.Information("row delete at tag_session");
+
+               int tagID = genericWin.TreeviewSelectedUniqueID;
+               LogB.Information(tagID.ToString());
+
+               SqliteTagSession.Delete(false, tagID);
+
+               genericWin.Delete_row_accepted();
        }
 }
diff --git a/src/sqlite/tagSession.cs b/src/sqlite/tagSession.cs
index eeeea302..689621cc 100644
--- a/src/sqlite/tagSession.cs
+++ b/src/sqlite/tagSession.cs
@@ -105,6 +105,24 @@ class SqliteTagSession : Sqlite
                return array;
        }
 
+       //deletes the tag and also all related rows on sessionTagSession
+       public static void Delete (bool dbconOpened, int uniqueID)
+       {
+               openIfNeeded(dbconOpened);
+
+               dbcmd.CommandText = "DELETE FROM " + table +
+                               " WHERE uniqueID = " + uniqueID.ToString();
+               LogB.SQL(dbcmd.CommandText.ToString());
+               dbcmd.ExecuteNonQuery();
+
+               dbcmd.CommandText = "DELETE FROM " + Constants.SessionTagSessionTable +
+                               " WHERE tagSessionID = " + uniqueID.ToString();
+               LogB.SQL(dbcmd.CommandText.ToString());
+               dbcmd.ExecuteNonQuery();
+
+               closeIfNeeded(dbconOpened);
+       }
+
 }
 
 class SqliteSessionTagSession : Sqlite


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]