Пример #1
0
 public void Setup(Item currentItem, scrollData currentScrollList)
 {
     item           = currentItem;
     nameLabel.text = item.itemName;
     priceText.text = item.price.ToString();
     scrollList     = currentScrollList;
 }
Пример #2
0
 private void RemoveItem(Item itemToRemove, scrollData shopList)
 {
     for (int i = shopList.itemList.Count - 1; i >= 0; i--)
     {
         if (shopList.itemList[i] == itemToRemove)
         {
             shopList.itemList.RemoveAt(i);
         }
     }
 }
Пример #3
0
        public int OnBeforeSave(uint docCookie)
        {
            var document = FindDocument(docCookie);

            //if no document - do nothing
            if (document == null)
            {
                return(VSConstants.S_OK);
            }

            //preserving cursor position
            IVsTextView textViewCurrent;

            _txtMngr.GetActiveView(1, null, out textViewCurrent);
            int line   = 0;
            int column = 0;

            textViewCurrent.GetCaretPos(out line, out column);

            //preserving breakpoints
            List <breakPointData> breakPointsPreserved = new List <breakPointData>();

            foreach (Breakpoint breakPoint in _dte.Debugger.Breakpoints)
            {
                if (breakPoint.File == _dte.ActiveDocument.FullName)
                {
                    breakPointData newBreakPoint = new breakPointData();

                    newBreakPoint.fileColumn    = breakPoint.FileColumn;
                    newBreakPoint.fileLine      = breakPoint.FileLine;
                    newBreakPoint.language      = breakPoint.Language;
                    newBreakPoint.condition     = breakPoint.Condition;
                    newBreakPoint.functionName  = breakPoint.FunctionName;
                    newBreakPoint.conditionType = breakPoint.ConditionType;

                    newBreakPoint.hitCount     = breakPoint.CurrentHits;
                    newBreakPoint.hitCountType = breakPoint.HitCountType;

                    breakPointsPreserved.Add(newBreakPoint);
                }
            }



            //preserving scroll position
            scrollData horizontal = new scrollData();
            scrollData vertical   = new scrollData();

            textViewCurrent.GetScrollInfo(0, out horizontal.piMinUnit, out horizontal.piMaxUnit, out horizontal.piVisibleUnits, out horizontal.piFirstVisible);
            textViewCurrent.GetScrollInfo(1, out vertical.piMinUnit, out vertical.piMaxUnit, out vertical.piVisibleUnits, out vertical.piFirstVisible);

            //reading
            string text = GetDocumentText(document);

            //getting options
            string endLineSymbol = "";

            switch (_settingsPage.newLine)
            {
            case SettingsPage.NewLineSymbol.Current:
                endLineSymbol = "$1";
                break;

            case SettingsPage.NewLineSymbol.Windows:
                endLineSymbol = "\r\n";
                break;

            case SettingsPage.NewLineSymbol.Unix:
                endLineSymbol = "\n";
                break;

            case SettingsPage.NewLineSymbol.VisualStudio:
                endLineSymbol = Environment.NewLine;
                break;

            default:
                endLineSymbol = Environment.NewLine;
                break;
            }

            text = Regex.Replace(text, "[ \t]+?(\r\n|\n|\r)", endLineSymbol, RegexOptions.Compiled);

            //fixed to avoid adding a new line
            text = Regex.Replace(text, "[ \t]+?($)", "$1", RegexOptions.Compiled | RegexOptions.Multiline);

            //replace EOLs based on the setting
            text = Regex.Replace(text, "(\r\n|\n|\r)", endLineSymbol, RegexOptions.Compiled);

            //setting
            SetDocumentText(document, text);

            //we need to change the column position as it is possible that there were spaces before the trim operation
            StringReader reader      = new StringReader(text);
            int          currentLine = 0;
            bool         breaked     = false;

            while (reader.Peek() != -1)
            {
                string currentLineText = reader.ReadLine();
                if (currentLine < line)
                {
                    ++currentLine;
                }
                else
                {
                    if (column > currentLineText.Length)
                    {
                        column = currentLineText.Length;
                    }
                    breaked = true;
                    break;
                }
            }

            //special case: empty last line
            if (breaked == false)
            {
                column = 0;
            }

            reader.Close();
            reader = null;

            //restoring breakpoints
            foreach (breakPointData breakPoint in breakPointsPreserved)
            {
                _dte.Debugger.Breakpoints.Add("", Path.GetFileName(_dte.ActiveDocument.FullName), breakPoint.fileLine, breakPoint.fileColumn, breakPoint.condition, breakPoint.conditionType, breakPoint.language, "", 1, "", breakPoint.hitCount, breakPoint.hitCountType);
            }

            //restoring cursor position
            textViewCurrent.SetCaretPos(line, column);

            //restoring scroll
            textViewCurrent.SetScrollPosition(0, horizontal.piFirstVisible);
            textViewCurrent.SetScrollPosition(1, vertical.piFirstVisible);

            return(VSConstants.S_OK);
        }
Пример #4
0
 void AddItem(Item itemToAdd, scrollData shopList)
 {
     shopList.itemList.Add(itemToAdd);
 }