コード例 #1
0
        public WordDefCollection()
        {
            WordDefArray = new ArrayList();
            WordComparer comparer = new WordComparer();

            comparer.ComparisonMethod = WordComparer.ComparisonType.trans;
            WordDef.SetSortOrder(WordDef.SortOrder.Ascending);
        }
コード例 #2
0
 public void Add(WordDef wd)
 {
     comparer.ComparisonMethod = WordComparer.ComparisonType.tibetan;
     WordDefArray.Add(wd);
     //    WordDefArray.Sort(comparer);
     //IEnumerable<string> filteredNames = names.OrderBy(n => n.Length);
     index++;
     scrollIndex = index;
 }
コード例 #3
0
        public override bool Equals(Object obj)
        {
            bool retVal = false;

            if (obj != null)
            {
                WordDef lObj = (WordDef)obj;
                if (lObj.Trans == this.Trans)
                {
                    retVal = true;
                }
            }
            return(retVal);
        }
コード例 #4
0
        // loop through and bring up prior search. Called on hotkey CTRL + ALT + special key
        private void ShowPrior()
        {
            WordDef       wd      = (WordDef)wdColl.GetPriorElement();
            StringBuilder strData = new StringBuilder();
            string        t       = wd.Tibetan;

            strData.Append(wd.Wylie);
            strData.Append(" - ");
            strData.AppendLine(wd.Trans);
            wd              = null;
            txtScan.Text    = t;
            txtScanDef.Text = strData.ToString();
            strData         = null;
        }
コード例 #5
0
        public int CompareTo(WordDef p2, WordComparer.ComparisonType comparisonMethod)
        {
            switch (comparisonMethod)
            {
            case WordComparer.ComparisonType.tibetan:
                return(tibetan.CompareTo(p2.tibetan));

            case WordComparer.ComparisonType.trans:
                return(trans.CompareTo(p2.trans));

            case WordComparer.ComparisonType.wylie:
                return(trans.CompareTo(p2.wylie));

            default:
                return(trans.CompareTo(p2.trans));
            }
        }
コード例 #6
0
        private void ShowPrior()
        {
            WordDef       wd         = (WordDef)wdColl.GetPriorElement();
            StringBuilder strBalloon = new StringBuilder();
            string        t          = wd.Tibetan;

            strBalloon.Append(wd.Wylie);
            strBalloon.Append(" - ");
            strBalloon.AppendLine(wd.Trans);
            wd = null;
            //FormatMenuBuild(iData);
            //SupportedMenuBuild(iData);
            //ContextMenuBuild();

            //if (_lookup.Count > 0)
            //{
            txtTibetan.Text = t;
            txtTrans.Text   = strBalloon.ToString();
        }
コード例 #7
0
        private bool RetrievedDefinition()
        {
            // bool FoundNewWord = false;
            bool FoundNewWord = false; //04/27/2012 have to fix this.. what if it's the same word as prior, so we don't go to dict.

            try
            {
                WordDef wd = GetTranslation(clipBoardText);
                if (wd != null)
                {
                    wdColl.Add(wd);
                    wd           = null;
                    FoundNewWord = true;
                }
                else //04/27/2012
                {
                    FoundNewWord = false;
                }
                PriorLookup = clipBoardText;
            }
            catch (Exception e) { }

            return(FoundNewWord);
        }
コード例 #8
0
        private bool ClipboardSearch(IDataObject iData)
        {
            //bool FoundNewLinks = false;
            bool FoundNewWord = false;

            //
            // If it is not text then quit
            // cannot search bitmap etc
            //


            byte[] unicodeData = null;



            try
            {
                strClipboardText = (string)iData.GetData(DataFormats.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return(false);
            }
            if (strClipboardText.StartsWith("?"))
            {
                try
                {
                    //unicodeData = iData.GetData(DataFormats.UnicodeText).;
                    strClipboardText = iData.GetData(DataFormats.UnicodeText).ToString();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    return(false);
                }
            }


            //if (String.IsNullOrEmpty(PriorLookup))
            //{
            //    PriorLookup = strClipboardText;

            //}

            if (!PriorLookup.Equals(strClipboardText))
            {
                try
                {
                    WordDef wd = GetTranslation(strClipboardText);
                    if (wd != null)
                    {
                        //  _lookup.Enqueue(wd);
                        wdColl.Add(wd);
                        wd           = null;
                        FoundNewWord = true;
                    }

                    PriorLookup = strClipboardText;
                }
                catch (Exception e) { }
            }

            //if (!_lookup.Contains(strClipboardText))
            //{
            //    _lookup.Enqueue(strClipboardText);
            //    FoundNewWord = true;
            //}
            // Hyperlinks e.g. http://www.server.com/folder/file.aspx
            //Regex rxURL = new Regex(@"(\b(?:http|https|ftp|file)://[^\s]+)", RegexOptions.IgnoreCase);
            //rxURL.Match(strClipboardText);

            //foreach (Match rm in rxURL.Matches(strClipboardText))
            //{
            //    if(!_hyperlink.Contains(rm.ToString()))
            //    {
            //        _hyperlink.Enqueue(rm.ToString());
            //        FoundNewLinks = true;
            //    }
            //}

            // Files and folders - \\servername\foldername\
            // TODO needs work
            //Regex rxFile = new Regex(@"(\b\w:\\[^ ]*)", RegexOptions.IgnoreCase);
            //rxFile.Match(strClipboardText);

            //foreach (Match rm in rxFile.Matches(strClipboardText))
            //{
            //    if(!_hyperlink.Contains(rm.ToString()))
            //    {
            //        _hyperlink.Enqueue(rm.ToString());
            //        FoundNewLinks = true;
            //    }
            //}

            // UNC Files
            // TODO needs work
            //Regex rxUNC = new Regex(@"(\\\\[^\s/:\*\?\" + "\"" + @"\<\>\|]+)", RegexOptions.IgnoreCase);
            //rxUNC.Match(strClipboardText);

            //foreach (Match rm in rxUNC.Matches(strClipboardText))
            //{
            //    if(!_hyperlink.Contains(rm.ToString()))
            //    {
            //        _hyperlink.Enqueue(rm.ToString());
            //        FoundNewLinks = true;
            //    }
            //}

            // UNC folders
            // TODO needs work
            //Regex rxUNCFolder = new Regex(@"(\\\\[^\s/:\*\?\" + "\"" + @"\<\>\|]+\\)", RegexOptions.IgnoreCase);
            //rxUNCFolder.Match(strClipboardText);

            //foreach (Match rm in rxUNCFolder.Matches(strClipboardText))
            //{
            //    if(!_hyperlink.Contains(rm.ToString()))
            //    {
            //        _hyperlink.Enqueue(rm.ToString());
            //        FoundNewLinks = true;
            //    }
            //}

            // Email Addresses
            //Regex rxEmailAddress = new Regex(@"([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)", RegexOptions.IgnoreCase);
            //rxEmailAddress.Match(strClipboardText);

            //foreach (Match rm in rxEmailAddress.Matches(strClipboardText))
            //{
            //    if(!_hyperlink.Contains(rm.ToString()))
            //    {
            //        _hyperlink.Enqueue("mailto:" + rm.ToString());
            //        FoundNewLinks = true;
            //    }
            //}

            return(FoundNewWord);
        }
コード例 #9
0
        private void GetClipboardData()
        {
            if (blnFirstTimeThrough)
            {
                blnFirstTimeThrough = false;
                return;
            }
            //
            // Data on the clipboard uses the
            // IDataObject interface
            //
            strClipboardText = "";
            string      sText;
            IDataObject iData   = new DataObject();
            string      strText = "clipmon";
            IntPtr      hData;

            try
            {
                iData = Clipboard.GetDataObject();

                //if ( ((string)iData.GetData(DataFormats.Text)).StartsWith("?")  )
                //{
                //    if (iData.GetDataPresent(DataFormats.UnicodeText))
                //    {
                //        //ctlClipboardText.Rtf = (string)iData.GetData(DataFormats.Rtf);
                //        string ss = (string)iData.GetData(DataFormats.UnicodeText);

                //    }


                //    //hData = GetClipboardData(CF_UNICODETEXT);
                //    //if (hData.ToInt32() == 0)
                //    //{
                //    //    return;
                //    //}

                //    //sText = ConvertToString(hData);
                //}

                //Clipboard.GetDataObject();
            }
            catch (System.Runtime.InteropServices.ExternalException externEx)
            {
                // Copying a field definition in Access 2002 causes this sometimes?
                Debug.WriteLine("InteropServices.ExternalException: {0}", externEx.Message);
                return;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return;
            }

            //
            // Get RTF if it is present
            //
            if (iData.GetDataPresent(DataFormats.Text))
            {
                //ctlClipboardText.Rtf = (string)iData.GetData(DataFormats.Rtf);

                //if(iData.GetDataPresent(DataFormats.Text))
                //{
                //    strText = "RTF";
                //}
            }
            else
            {
                //
                // Get Text if it is present
                //
                if (iData.GetDataPresent(DataFormats.UnicodeText))
                {
                    //ctlClipboardText.Text = (string)iData.GetData(DataFormats.Text);

                    //strText = "Text";

                    //Debug.WriteLine((string)iData.GetData(DataFormats.Text));
                }
                else
                {
                    //
                    // Only show RTF or TEXT
                    //
                    txtTrans.Text = "(cannot display this format)";
                    return;
                }
            }

            //   notAreaIcon.Tooltip = strText;

            if (ClipboardSearch(iData))
            {
                //
                // New word go look up.
                //
                System.Text.StringBuilder strBalloon = new System.Text.StringBuilder(100);

                //foreach (string objLink in _lookup)
                //{
                //    strBalloon.Append(objLink.ToString()  + "\n");
                //}

                //    WordDef wd = (WordDef)_lookup.Dequeue();

                WordDef wd = (WordDef)wdColl.Current;

                string t = wd.Tibetan;
                strBalloon.Append(wd.Wylie);
                strBalloon.Append(" - ");
                strBalloon.AppendLine(wd.Trans);
                wd = null;
                //FormatMenuBuild(iData);
                //SupportedMenuBuild(iData);
                //ContextMenuBuild();

                //if (_lookup.Count > 0)
                //{
                txtTibetan.Text = t;
                txtTrans.Text   = strBalloon.ToString();
                //   notAreaIcon.BalloonDisplay(NotificationAreaIcon.NOTIFYICONdwInfoFlags.NIIF_INFO, "Links", strBalloon.ToString());
                //}
            }
            else
            {
                txtTibetan.Text = strClipboardText;
                txtTrans.Text   = "Not Found";
            }
        }
コード例 #10
0
        private void GetClipboardFromData()
        {
            if (blnFirstTimeThrough)  // we don't want to throw clipboard data in there from somewhere else
            {
                blnFirstTimeThrough = false;
                return;
            }

            IDataObject iData = new DataObject();

            try { iData = Clipboard.GetDataObject(); }
            catch (System.Runtime.InteropServices.ExternalException externEx)
            {
                // ErrorLog.WriteLog(DateTime.Now + "Error frmDagYigScan, GetClipboardData, System.Runtime.InteropServices.ExternalException ERR: " + externEx.Message);
                MessageBox.Show("There was a problem capturing this data: " + externEx.ToString());
                return;
            }
            catch (Exception ex)
            {
                MessageBox.Show("There was a problem capturing this data: " + ex.ToString());
                return;
            }

            if (!iData.GetDataPresent(DataFormats.Text) && !iData.GetDataPresent(DataFormats.Rtf) &&
                !iData.GetDataPresent(DataFormats.UnicodeText))
            {
                return;
            }

            // check if found and if it's a brand new word (may already be in word collection)
            // and if it is new, retrieve from DB
            //04/27/2012 What if clipboard picks up blank string randomly from somewhere else - why, where? not sure.
            // we end up replacing whatever was put in the txtScan with "not found"
            if (string.IsNullOrEmpty(GetClipBoardText(iData)))
            {
                return;
            }
            if (PriorLookup.Equals(clipBoardText))
            {
                return;
            }

            //   if (ClipboardSearch(iData))
            if (RetrievedDefinition())
            {
                System.Text.StringBuilder strData = new System.Text.StringBuilder();
                WordDef wd = (WordDef)wdColl.Current;
                string  t  = wd.Tibetan;
                strData.Append(wd.Wylie);
                strData.Append(" - ");
                strData.AppendLine(wd.Trans);
                wd              = null;
                txtScan.Text    = t;
                txtScanDef.Text = strData.ToString();
                strData         = null;
            }
            else
            {
                txtScan.Text    = clipBoardText; // global string. Filled in by ClipboardSearch() method
                txtScanDef.Text = "Not Found";
            }
        }