<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Excel = Microsoft.Office.Interop.Excel;
using Office = Microsoft.Office.Core;

namespace ExcelQueryServiceAddIn
{
    public partial class ThisAddIn
    {
        private ExcelQueryServiceControl queryServiceControl;
        private Microsoft.Office.Tools.CustomTaskPane myCustomTaskPane;

        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
            RemoveQueryServiceTaskPane();
        }

        public void AddQueryServiceTaskPane()
        {
            if (myCustomTaskPane == null)
            {
                queryServiceControl = new ExcelQueryServiceControl();
                myCustomTaskPane = this.CustomTaskPanes.Add(queryServiceControl, "Query Service Control");
                myCustomTaskPane.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionRight;
                myCustomTaskPane.Width = 300;
                myCustomTaskPane.Visible = true;
            }
            else if (myCustomTaskPane.Visible == false)
            {
                myCustomTaskPane.Visible = true;
            }
        }

        public void RemoveQueryServiceTaskPane()
        {
            try
            {
                if (myCustomTaskPane != null && this.CustomTaskPanes.Contains(myCustomTaskPane))
                {<commit_msg>Code changes to implement [#17124] Need ability to "unmap" a cell and remove the item from the "List"<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Excel = Microsoft.Office.Interop.Excel;
using Office = Microsoft.Office.Core;

namespace ExcelQueryServiceAddIn
{
    public partial class ThisAddIn
    {
        private ExcelQueryServiceControl queryServiceControl;
        private Microsoft.Office.Tools.CustomTaskPane myCustomTaskPane;
        private Office.CommandBarButton XMLUnmapButton;
        private Office.CommandBarButton CellUnmapButton;

        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            AddUnmapButtonMenuCommand();
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
            RemoveQueryServiceTaskPane();
        }

        public void AddUnmapButtonMenuCommand() 
        {
            Office._CommandBarButtonEvents_ClickEventHandler xButtonHandler =
                new Office._CommandBarButtonEvents_ClickEventHandler(unmapXMLClick);

            Office._CommandBarButtonEvents_ClickEventHandler cButtonHandler =
                new Office._CommandBarButtonEvents_ClickEventHandler(unmapHeaderClick);

            XMLUnmapButton = (Office.CommandBarButton)Application.CommandBars["XML Range Popup"].Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, true);
            XMLUnmapButton.Click += xButtonHandler;
            XMLUnmapButton.Caption = "Unmap Values";
            XMLUnmapButton.Visible = true;

            CellUnmapButton = (Office.CommandBarButton)Application.CommandBars["Cell"].Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, true);
            CellUnmapButton.Click += cButtonHandler;
            CellUnmapButton.Caption = "Clear Cell";
            CellUnmapButton.Visible = true;
        }

        private void unmapXMLClick(Office.CommandBarButton button, ref bool Cancel)
        {
            Excel.Range selected = (Excel.Range)this.Application.Selection;           
            selected.Cells.Clear();
            selected.Cells.ClearContents();
            selected.Cells.ClearFormats();
            selected.Cells.ClearNotes();

            string selectedRangeString = ((Excel.Worksheet)selected.Parent).Name + "!" + selected.get_Address(Type.Missing, Type.Missing, Excel.XlReferenceStyle.xlA1, Type.Missing, Type.Missing);
            Excel.Worksheet cdeList = (Excel.Worksheet)this.Application.Sheets["cde_list"];

            Excel.Range c = (Excel.Range)cdeList.Cells[2, 1];
            for (int i = 3; c.Value2 != null; i++)
            {
                c = (Excel.Range)cdeList.Cells[i, 1];
                string text = c.Text.ToString();
                if (text.Contains(selectedRangeString))
                    break;
            }

            cdeList.Unprotect("dummy_password");
            c.Clear();
            c.Next.Clear();
            c.Next.Next.Clear();
            c.Next.Next.Next.Clear();
            cdeList.Protect("dummy_password", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

        }

        private void unmapHeaderClick(Office.CommandBarButton button, ref bool Cancel)
        {
            Excel.Range selected = (Excel.Range)this.Application.Selection;
   
            selected.Cells.Clear();
            selected.Cells.ClearContents();
            selected.Cells.ClearFormats();
            selected.Cells.ClearNotes();

        }

        public void AddQueryServiceTaskPane()
        {
            if (myCustomTaskPane == null)
            {
                queryServiceControl = new ExcelQueryServiceControl();
                myCustomTaskPane = this.CustomTaskPanes.Add(queryServiceControl, "Query Service Control");
                myCustomTaskPane.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionRight;
                myCustomTaskPane.Width = 300;
                myCustomTaskPane.Visible = true;
            }
            else if (myCustomTaskPane.Visible == false)
            {
                myCustomTaskPane.Visible = true;
            }
        }

        public void RemoveQueryServiceTaskPane()
        {
            try
            {
                if (myCustomTaskPane != null && this.CustomTaskPanes.Contains(myCustomTaskPane))
                {
{'fraction_non_alphanumeric': 0.0855036855036855, 'fraction_numerical': 0.0027846027846027844, 'mean_word_length': 2.2987574284170718, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6962342', 'n_tokens_mistral': 1626, 'n_tokens_neox': 1528, 'n_words': 293}