Exemple #1
0
        void menuCommand_BeforeQueryStatus(object sender, System.EventArgs e)
        {
            OleMenuCommand menuCommand = sender as OleMenuCommand;

            _buffer = ProjectHelpers.GetCurentTextBuffer();

            menuCommand.Enabled = _buffer != null && _buffer.ContentType.IsOfType("javascript");
        }
        private static async Task UpdateSheetRulesAsync(string file, IEnumerable <CssSelectorChangeData> set)
        {
            ////Get off the UI thread
            //await Task.Factory.StartNew(() => { });
            var doc = DocumentFactory.GetDocument(file, true);

            if (doc == null)
            {
                return;
            }

            var oldSnapshotOnChange = doc.IsProcessingUnusedCssRules;
            var window = EditorExtensionsPackage.DTE.ItemOperations.OpenFile(file);

            window.Activate();
            var buffer         = ProjectHelpers.GetCurentTextBuffer();
            var flattenedRules = FlattenRules(doc);
            var allEdits       = new List <CssRuleBlockSyncAction>();

            doc.IsProcessingUnusedCssRules = false;
            doc.Reparse(buffer.CurrentSnapshot.GetText());

            foreach (var item in set)
            {
                var selectorName  = RuleRegistry.StandardizeSelector(item.Rule);
                var matchingRules = flattenedRules.Where(x => string.Equals(x.CleansedSelectorName, selectorName, StringComparison.Ordinal)).OrderBy(x => x.Offset).ToList();
                var rule          = matchingRules[item.RuleIndex];
                var actions       = await CssRuleDefinitionSync.ComputeSyncActionsAsync(rule.Source, item.NewValue, item.OldValue);

                allEdits.AddRange(actions);
            }

            var compositeEdit = buffer.CreateEdit();

            try
            {
                foreach (var action in allEdits)
                {
                    action(window, compositeEdit);
                }
            }
            catch
            {
                compositeEdit.Cancel();
            }
            finally
            {
                if (!compositeEdit.Canceled)
                {
                    compositeEdit.Apply();
                    EditorExtensionsPackage.ExecuteCommand("Edit.FormatDocument");
                    window.Document.Save();
                }
            }

            //await Task.Delay(2000); //<-- Try to wait for the files to actually save
            doc.IsProcessingUnusedCssRules = oldSnapshotOnChange;
        }
Exemple #3
0
        public void NavigateTo()
        {
            WebEssentialsPackage.DTE.ItemOperations.OpenFile(_file);

            Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() =>
            {
                var view       = ProjectHelpers.GetCurentTextView();
                var textBuffer = ProjectHelpers.GetCurentTextBuffer();
                var span       = new SnapshotSpan(textBuffer.CurrentSnapshot, _selector.Start, _selector.Length);
                var point      = new SnapshotPoint(textBuffer.CurrentSnapshot, _selector.Start + _selector.Length);

                view.ViewScroller.EnsureSpanVisible(span);
                view.Caret.MoveTo(point);
                view.Selection.Select(span, false);
            }), DispatcherPriority.ApplicationIdle, null);
        }
Exemple #4
0
        private static void MoveCursorToEdit(Window window, IRange range, int offset = 0)
        {
            var selection = window.Document.Selection as TextSelection;

            if (selection != null)
            {
                try
                {
                    var buffer = ProjectHelpers.GetCurentTextBuffer();
                    int line;
                    int column;

                    buffer.GetLineColumnFromPosition(range.Start, out line, out column);
                    selection.GotoLine(line + 1 + offset);
                }
                catch
                {
                }
            }
        }