Ejemplo n.º 1
0
        /// <summary>
        /// Adds a new dictionary info item to the dictionary
        /// </summary>
        /// <param name="inf">The info item to add as a 'DictionaryInfo'</param>
        public void Add(int idContent, string title, string description, string url, TooltipDictionary.TooltipType tooltipType)
        {
            var inf = new DictionaryInfo()
            {
                IdContent     = idContent
                , Title       = title
                , Description = description
                , Url         = url
                , TooltipType = tooltipType
                , Index       = dicList.Count + 1
            };

            if (MainForm.IdContentUrlRegEx_v2.IsMatch(url))
            {
                var questionInfo = GetByTitle(0, "\\\\" + url.Substring(2));
                if (questionInfo != null)
                {
                    inf.Description = questionInfo.Description;
                }
            }
            else
            if (MainForm.IdContentUrlRegEx_v1.IsMatch(url))
            {
                var questionInfo = GetByTitle(0, "\\\\" + url.Substring(7));
                if (questionInfo != null)
                {
                    inf.Description = questionInfo.Description;
                }
            }
            dicList.Add(inf);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Removes an existing items from the dictionary
 /// </summary>
 /// <param name="inf">The info item to remove as a 'DictionaryInfo'</param>
 public void Remove(DictionaryInfo inf)
 {
     try
     {
         dicList.Remove(inf);
     }
     catch { throw new Exception("InfNotFoundInDictinaryException"); };
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns all the occurences of the specified title whithin the dictionary
        /// </summary>
        /// <param name="infTitle">The dictionary info item to get</param>
        /// <returns>If no occurence was found a new empty list will be returned</returns>
        public DictionaryInfo GetByTitle(int idContent, string infTitle)
        {
            DictionaryInfo result = dicList.Find(x => x.IdContent == idContent && (string.Compare(x.Title, infTitle, true) == 0));

            if (result == null)
            {
                result = dicList.Find(x => x.IdContent == 0 && (string.Compare(x.Title, infTitle, true) == 0));
                //if (result != null)
                //  result.Description = dicList[result.Index].Description;
            }
            return(result);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Edits the specified dictionary info item according to the specified value
 /// </summary>
 /// <param name="inf">The desired info item from the dictionary</param>
 /// <param name="title">The new title. This value can be null to return the existing title</param>
 /// <param name="description">The new description. This value can be null to return the existing description</param>
 public void Edit(DictionaryInfo inf, string title, string description, int idContent, int tooltipType, string url)
 {
     if (dicList.Contains(inf))
     {
         inf.Title       = title;
         inf.Description = description;
         inf.TooltipType = (TooltipDictionary.TooltipType)tooltipType;
         inf.IdContent   = idContent;
         inf.Url         = url;
     }
     else
     {
         throw new Exception("ElementNotFoundException");
     };
 }
Ejemplo n.º 5
0
        public static bool DeleteItem(int idContent, string word)
        {
            bool result = false;

            if (MessageBox.Show("Удалить всплывающую подсказку для слова '" + word + "'", "Подтверждение удаления", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
            {
                if (TooltipDictionary.DeleteWordTooltip(idContent, word))
                {
                    DictionaryInfo deletedWord = eDictionary.GetByTitle(idContent, word);
                    eDictionary.Remove(deletedWord);
                    HelpDT.Rows.Remove(GetHelpDtRow(idContent, word));
                    result = true;
                }
            }
            return(result);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Adds a new dictionary info item to the dictionary
 /// </summary>
 /// <param name="inf">The info item to add as a 'DictionaryInfo'</param>
 public void Add(DictionaryInfo inf)
 {
     inf.Index = dicList.Count + 1;
     dicList.Add(inf);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Checks wheather a dictionary info item that has the same
 /// Title, Description and Index exists in the dictionary or not
 /// </summary>
 /// <param name="inf">The dictionary info item to check for</param>
 /// <returns></returns>
 public bool Exists(DictionaryInfo inf)
 {
     return(dicList.Contains(inf));
 }
Ejemplo n.º 8
0
        private void ShowToolTip()
        {
            //Проверка, что курсор находится не за пределами слова и не ниже последней строки
            bool cursorInWordContains = (_lastMouseCoord.X >= _startWordLocation.X && _lastMouseCoord.X <= _endWordLocation.X);

            //(Application.OpenForms[0] as MainForm).Text = string.Format("_lastMouseCoord.X >= _startWordLocation.X && _lastMouseCoord.X <= _endWordLocation.X: {0}>={1} && {2}<={3}"
            //  , _lastMouseCoord.X, _startWordLocation.X, _lastMouseCoord.X, _endWordLocation.X);
            if (!cursorInWordContains /* || IsMousePosOutOfLastLine()*/)
            {
                this.HideTooltip();
                return;
            }

            DictionaryInfo wordDefinition = Dictionary.GetByTitle(Convert.ToInt32((Application.OpenForms[0] as MainForm).GetCurrentQuestionId().ToString()), _toolTipWord);

            if (wordDefinition != null)
            {
                this.Title       = _toolTipWord;
                this.Description = wordDefinition.Description;
                this.Url         = wordDefinition.Url;
                this.Footer      = string.Empty;
                if (!string.IsNullOrEmpty(wordDefinition.Url))
                {
                    MainForm mf = Application.OpenForms[0] as MainForm;
                    if (MainForm.IdContentUrlRegEx_v1.IsMatch(wordDefinition.Url))
                    {
                        if (mf.GetCurrentQuestionId().ToString() != wordDefinition.Url.Substring(7))
                        {
                            this.Footer = "Нажмите Ctrl+LeftMouse для быстрого перехода на вопрос";
                        }
                    }
                    else
                    if (MainForm.IdContentUrlRegEx_v2.IsMatch(wordDefinition.Url))
                    {
                        if (mf.GetCurrentQuestionId().ToString() != wordDefinition.Url.Substring(2))
                        {
                            this.Footer = "Нажмите Ctrl+LeftMouse для быстрого перехода на вопрос";
                        }
                    }
                    else
                    {
                        this.Footer = "Нажмите Ctrl+LeftMouse для открытия страницы в браузере";
                    }
                }
                int xPosition = _lastMouseCoord.X + 5;
                if (xPosition + lblDescription.MaximumSize.Width > _rtb.Width)
                {
                    xPosition = xPosition - lblDescription.MaximumSize.Width;
                }
                if (xPosition < 0)
                {
                    xPosition = 0;
                }

                int yPosition = _lastMouseCoord.Y + 5;
                if (yPosition + this.Height > _rtb.Height)
                {
                    yPosition = yPosition - this.Height;
                }
                if (yPosition < 0)
                {
                    yPosition = 0;
                }

                this.Location = new Point(xPosition, yPosition);
                this.ShowTooltip();
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Изменить всплывающую подсказку у слова
        /// </summary>
        public static bool UpdateWordToolTip(int idContent, string word, int tooltipType, string comment, string url, string groupName, string foreColor, int oldIdContent, string oldWord)
        {
            if ((oldIdContent != idContent || string.Compare(word, oldWord, true) != 0) &&
                eDictionary.Contains(idContent, word))
            {
                MessageBox.Show(string.Format("Слово \"{0}\" уже есть в категории \"{1}\"", word, idContent == 0 ? Constants.PUBLIC_DICTIONARY_CATEGORY : Constants.PRIVATE_DICTIONARY_CATEGORY)
                                , "Дублирование подсказки", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }
            QuotedStr(ref word);
            QuotedStr(ref comment);
            QuotedStr(ref url);
            QuotedStr(ref groupName);
            QuotedStr(ref foreColor);
            QuotedStr(ref oldWord);

            if (G.ExecSQLiteQuery(
                    string.Format("UPDATE word_tooltip SET id_content={0}, word='{1}', tooltip_type={2}, comment='{3}', url_adr='{4}', group_name='{5}', fore_color='{6}' WHERE id_content='{7}' AND word='{8}'"
                                  , idContent, word, tooltipType, comment, url, groupName, foreColor, oldIdContent, oldWord)))
            {
                DictionaryInfo oldDicInfo        = eDictionary.GetByTitle(oldIdContent, oldWord);
                string         selectQuestionSql = "select question from vopros where id_content={0}";
                if (MainForm.IdContentUrlRegEx_v1.IsMatch(url) &&
                    G.ExecSQLiteQuery(string.Format(selectQuestionSql, url.Substring(7))) &&
                    G.DT.Rows.Count == 1)
                {
                    eDictionary.Edit(oldDicInfo, word, G.DT.Rows[0][0].ToString(), idContent, tooltipType, url);
                }
                else
                if (MainForm.IdContentUrlRegEx_v2.IsMatch(url) &&
                    G.ExecSQLiteQuery(string.Format(selectQuestionSql, url.Substring(2))) &&
                    G.DT.Rows.Count == 1)
                {
                    eDictionary.Edit(oldDicInfo, word, G.DT.Rows[0][0].ToString(), idContent, tooltipType, url);
                }
                else
                {
                    eDictionary.Edit(oldDicInfo, word, comment, idContent, tooltipType, url);
                }

                TreeNode parentNodeLevel1 = TooltipDictionary.TV_Dictionary.SelectedNode.Parent;
                // Редактировать слово в дереве
                if (TooltipDictionary.TV_Dictionary.SelectedNode.Text == word &&
                    (parentNodeLevel1.Text == groupName || parentNodeLevel1.Text == Constants.WithoutGroup) &&
                    TooltipDictionary.TV_Dictionary.SelectedNode.Name == idContent.ToString())
                {
                    TooltipDictionary.TV_Dictionary.SelectedNode.ForeColor = System.Drawing.Color.FromName(foreColor);
                }
                else
                {
                    TooltipDictionary.TV_Dictionary.SelectedNode.Remove();
                    if (parentNodeLevel1.Nodes.Count == 0)
                    {
                        TreeNode parentNodeLevel0 = parentNodeLevel1.Parent;
                        parentNodeLevel1.Remove();
                        if (parentNodeLevel0.Nodes.Count == 0)
                        {
                            parentNodeLevel0.Remove();
                        }
                    }
                    DictionaryEditor.AddNode(idContent, groupName, word, foreColor, true);
                }

                // Пересоздать запись в HelpDGV
                HelpDT.Rows.Remove(GetHelpDtRow(oldIdContent, oldWord));
                AddHelpRow(idContent, word, comment, foreColor, url);
                return(true);
            }
            return(false);
        }