示例#1
0
        static public void CheckDictionariesForLanguage(string lp, ToolStripItemCollection collection)
        {
            foreach (ToolStripItem item in collection)
            {
                if (((ToolStripItem)item).Tag == null)
                {
                    continue;                                    // for delimiter with text "-"
                }
                RunDictContent dictContent = item.Tag as RunDictContent;

                if (dictContent.Providers.Count == 1) // ordinary item
                {
                    item.Enabled = dictContent.Providers[0].IsSupport(lp);
                }
                else // actions for headerItem e.g. {Search in All Idioms:}
                {
                    foreach (DictionaryProvider provider in dictContent.Providers)
                    {
                        if (provider.IsSupport(lp))
                        {
                            item.Enabled = true;
                            break;
                        }
                        //else Console.WriteLine();
                    }
                }
            }
        }
示例#2
0
        void AssignLastUsedDict(string name)
        {
            bool isAssigned = false;

            foreach (ToolStripItem item in toolStripDictionary.Items)
            {
                RunDictContent content = item.Tag as RunDictContent;
                // а как назначить последнюю группу словарей?????!!
                // if (content != null && content.Providers[0].ToString().Equals(name))
                if (content != null && content.Providers.Count == 1 && content.Providers[0].ToString().Equals(name))
                {
                    if (item is ToolStripButton)
                    {
                        ((ToolStripButton)item).Checked = true;
                    }
                    else
                    {
                        ((ToolStripMenuItem)item).Checked = true;
                    }
                    isAssigned = true;
                    break;
                }
            }
            if (!isAssigned)
            {
                AssignLastUsedDict(GoogleDictionary.MainTitle);
            }
        }
示例#3
0
 void AssignLastDict(string dictionaryProviderName)
 {
     foreach (ToolStripItem item in this.btOpenIn.DropDownItems)
     {
         if (item is ToolStripItem && ((ToolStripItem)item).Tag is RunDictContent)
         {
             RunDictContent content = (RunDictContent)((ToolStripItem)item).Tag;
             if (content.Providers.Count == 1 && content.Providers[0].ToString().Equals(dictionaryProviderName))
             {
                 item_Click(item, EventArgs.Empty);
                 break;
             }
         }
     }
 }
示例#4
0
        private void RegisterEvent()
        {
            if (string.IsNullOrEmpty(this.Word))
            {
                return;
            }
            DictionaryProvider provider = null;

            if (this.LastUsedDict != null)
            {
                RunDictContent dictContent = this.LastUsedDict.Tag as RunDictContent;
                if (dictContent != null && dictContent.Providers.Count > 0)
                {
                    provider = dictContent.Providers[0];
                }
            }

            HistoryItem hi = new HistoryItem(this.Word, provider); //, this.webBrowser1.TempContent);

            #region clear old content
            if (this.comboBox.Items.Contains(hi.Word))
            {
                this.comboBox.Items.Remove(hi.Word);
            }
            else
            {
                foreach (object ob in this.comboBox.Items)
                {
                    if (ob is HistoryItem && hi.Equals((HistoryItem)ob))
                    {
                        this.comboBox.Items.Remove(hi);
                    }
                }
            }
            #endregion
            this.comboBox.Items.Insert(0, hi);

            try {
                this.comboBox.SelectedValueChanged -= new System.EventHandler(this.comboBox_SelectedValueChanged);
                this.comboBox.SelectedIndex         = 0;
            }
            finally {
                this.comboBox.SelectedValueChanged += new System.EventHandler(this.comboBox_SelectedValueChanged);
            }
            UpdateFormCaption();
            CheckButtonsPrevNext();
        }
示例#5
0
        //            "<table><tr><td class=\"topForArticle\"><a href=\"{0}\" title=\"{1}\">{2} ({3})</a></td></tr></table>";

        /*
         * .topForArticle
         * {
         *      background-color: #C0C0C0; padding-right: 50px; padding-left: 50px;
         * }
         *
         * static readonly string TopForArticleTemplate = "{0}\r\n<table><tr>{0}</tr></table>\r\n";
         */
        #endregion

        public static void Dict_Click(object sender, EventArgs e)
        {
            RunDictContent dictContent = ((ToolStripItem)sender).Tag as RunDictContent;

            if (dictContent == null)
            {
                return;
            }
            string word = dictContent.TextWithSelection.CurrentLowerWord;

            if (string.IsNullOrEmpty(word))
            {
                string message = "A word is not specified";
                // if (Application.ProductName  == DictionaryBlend message += " (Drag-n-drop supported)." // "You must type a word
                MessageBox.Show(message, Application.ProductName,
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                LangPair lp = dictContent.TextWithSelection.LangDir;
                if (dictContent.UITarget != null)
                {
                    #region for async calling
                    WaitingUIObjectWithFinish waitObject = null;
                    //if ((dictContent.Providers.Count == 1) && !(dictContent.Providers[0] is FavoritProvider))
                    if (dictContent.TextWithSelection is ITextWithSelectionAndWaiting)
                    {
                        MethodInvoker onFinish = new MethodInvoker(AssignTextToControl);
                        waitObject = new WaitingUIObjectWithFinish(((ITextWithSelectionAndWaiting)dictContent.TextWithSelection).Control,
                                                                   ((ITextWithSelectionAndWaiting)dictContent.TextWithSelection).Picture, onFinish);
                        lastUITarget = dictContent.UITarget;
                        foreach (AsyncProvider provider in currentRequests)
                        {
                            if (provider.CurrentThread.IsAlive)
                            {
                                provider.CurrentThread.Abort();
                            }
                        }
                        currentRequests.Clear();
                        lock (resultContainer)
                            resultContainer.Clear();
                    }
                    #endregion

                    using (new WaitCursor(waitObject == null))
                    {
                        // System.Threading.Thread.Sleep(3000);

                        string dictBodies = "";
                        foreach (DictionaryProvider provider in dictContent.Providers)
                        {
                            //if (provider is FavoritProvider)
                            //{
                            //    new Gator.GatorStarter(word, lp.From, lp.To, null); // waitingUIObject
                            //    dictBodies = "See result in an external window";
                            //}
                            //else
                            {
                                if (!provider.IsSupport(lp.ToString()))
                                {
                                    continue;
                                }
                                string url           = provider.GetPublicUrl(word, lp);
                                string providerTitle = provider.Title;
                                if (provider.GetType().Name.ToLower().Contains("google"))
                                {
                                    providerTitle = "Google " + providerTitle;
                                }
                                string title = string.Format(topForArticleTemplate, url, providerTitle, provider.Copyright);
                                if (waitObject != null)
                                {
                                    currentRequests.Add(new AsyncProvider(word, lp, provider, waitObject, resultContainer, title));
                                }
                                else
                                {
                                    dictBodies += title;
                                    string content = provider.GetContent(word, lp);
                                    dictBodies += content;
                                }
                            }
                        }
                        if (waitObject == null)
                        {
                            dictContent.UITarget.TempContent = dictBodies;
                        }
                        dictContent.UITarget.AssignText(dictBodies);
                    }
                }
                else // here just working with urls and external browser
                {
                    #region Runner.OpenURL
                    foreach (DictionaryProvider provider in dictContent.Providers)
                    {
                        if (provider is FavoritProvider)
                        {
                            new Gator.GatorStarter(word, lp.From, lp.To, null); // waitingUIObject
                        }
                        else
                        {
                            if (!provider.IsSupport(lp.ToString()))
                            {
                                continue;
                            }
                            Runner.OpenURL(provider.GetPublicUrl(word, lp));
                        }
                    }
                    #endregion
                }
            }
        }