Ejemplo n.º 1
0
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            IWpfTextView view = AdaptersFactory.GetWpfTextView(textViewAdapter);

            Debug.Assert(view != null);

            ITextDocument document;

            if (!TextDocumentFactoryService.TryGetTextDocument(view.TextDataModel.DocumentBuffer, out document))
            {
                return;
            }

            string fileName = Path.GetFileName(document.FilePath);

            if (!fileName.Equals("robots.txt", StringComparison.InvariantCultureIgnoreCase))
            {
                return;
            }

            CommandFilter filter = new CommandFilter(view, SignatureHelpBroker);

            IOleCommandTarget next;

            ErrorHandler.ThrowOnFailure(textViewAdapter.AddCommandFilter(filter, out next));
            filter.Next = next;
        }
Ejemplo n.º 2
0
        public override bool CanHappen(string msg, [NotNull] Viewer viewer)
        {
            if (!PurchaseHelper.TryGetPawn(viewer.username, out _pawn))
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.NoPawn".Localize());

                return(false);
            }

            var worker = ArgWorker.CreateInstance(CommandFilter.Parse(msg).Skip(2));

            if (!worker.TryGetNextAsSkill(out SkillDef skillDef))
            {
                return(false);
            }

            _target = _pawn !.skills.skills.Where(s => !s.TotallyDisabled).FirstOrDefault(s => s.def.Equals(skillDef));

            if (_target == null)
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.InvalidSkillQuery".LocalizeKeyed(worker.GetLast()));

                return(false);
            }

            if ((int)_target.passion < 3)
            {
                return(true);
            }

            MessageHelper.ReplyToUser(viewer.username, "TKUtils.Passion.Full".Localize());

            return(false);
        }
Ejemplo n.º 3
0
#pragma warning restore 169


        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            IWpfTextView view = AdaptersFactory.GetWpfTextView(textViewAdapter);

            Debug.Assert(view != null);

            // check whether the document is named robots.txt
            ITextDocument document;

            if (!TextDocumentFactoryService.TryGetTextDocument(view.TextDataModel.DocumentBuffer, out document))
            {
                return;
            }

            string fileName = Path.GetFileName(document.FilePath);

            if (!fileName.Equals("robots.txt", StringComparison.InvariantCultureIgnoreCase))
            {
                return;
            }

            // register command filter
            CommandFilter filter = new CommandFilter(view,
                                                     _textBufferUndoManagerProvider.GetTextBufferUndoManager(view.TextBuffer).TextBufferUndoHistory
                                                     );

            IOleCommandTarget next;

            ErrorHandler.ThrowOnFailure(textViewAdapter.AddCommandFilter(filter, out next));
            filter.Next = next;
        }
Ejemplo n.º 4
0
        public override void RunCommand([NotNull] ITwitchMessage twitchMessage)
        {
            var    worker   = ArgWorker.CreateInstance(CommandFilter.Parse(twitchMessage.Message).Skip(1));
            string argument = worker.GetNext();

            switch (argument.ToLowerInvariant())
            {
            case "accept":
                ProcessAccept(twitchMessage.Username, worker.GetNextAsViewer());

                return;

            case "decline":
                ProcessDecline(twitchMessage.Username, worker.GetNextAsViewer());

                return;

            default:
                Viewer viewer = Viewers.All.Find(v => string.Equals(v.username, argument, StringComparison.InvariantCultureIgnoreCase));

                if (viewer != null)
                {
                    ProcessRequest(twitchMessage.Username, viewer);
                }
                else
                {
                    MessageHelper.ReplyToUser(twitchMessage.Username, "TKUtils.InvalidViewerQuery".LocalizeKeyed(worker.GetLast()));
                }

                return;
            }
        }
Ejemplo n.º 5
0
        private void Start()
        {
            _commandFilter    = new CommandFilter();
            _executedCommands = new CircularBuffer <string>(_commandHistoryCount);

            _inputField.onEndEdit.AddListener((string cmd) =>
            {
                if (UnityEngine.Input.GetKeyDown(_submitKey))
                {
                    Execute(cmd);
                }
            });

#if UNITY_5_3_OR_NEWER
            _inputField.onValueChanged.AddListener((string prefix) =>
            {
                _suggestionsContainer.Display(_commandFilter.FilterByName(prefix));
            });
#else
            _inputField.onValueChange.AddListener((string prefix) =>
            {
                _suggestionsContainer.Display(_commandFilter.FilterByName(prefix));
            });
#endif

            _executeButton.onClick.AddListener(() =>
            {
                Execute(_inputField.text);
            });
        }
Ejemplo n.º 6
0
        public override void RunCommand([NotNull] ITwitchMessage twitchMessage)
        {
            if (!PurchaseHelper.TryGetPawn(twitchMessage.Username, out Pawn pawn))
            {
                twitchMessage.Reply("TKUtils.NoPawn".Localize());

                return;
            }

            List <string> queries = CommandFilter.Parse(twitchMessage.Message).Skip(1).Select(PurchaseHelper.ToToolkit).ToList();

            if (queries.Count <= 0)
            {
                queries.AddRange(DefaultStats);
            }

            List <StatDef> container = queries.Select(FindStat).Where(s => s != null).ToList();

            if (container.Count <= 0)
            {
                return;
            }

            CommandRouter.MainThreadCommands.Enqueue(
                () =>
            {
                MessageHelper.ReplyToUser(twitchMessage.Username, container.Select(s => FormatStat(pawn, s)).SectionJoin());
            }
                );
        }
Ejemplo n.º 7
0
        public override void RunCommand([NotNull] ITwitchMessage twitchMessage)
        {
            var worker = ArgWorker.CreateInstance(CommandFilter.Parse(twitchMessage.Message).Skip(1));

            if (!worker.TryGetNextAsInt(out int amount, 1))
            {
                return;
            }

            List <string> viewers = Viewers.ParseViewersFromJsonAndFindActiveViewers();

            if (viewers == null || viewers.Count <= 0)
            {
                return;
            }

            var count = 0;

            foreach (string username in viewers)
            {
                Viewers.GetViewer(username).GiveViewerCoins(amount);
                count++;
            }

            twitchMessage.Reply("TKUtils.GiveAll".LocalizeKeyed(amount.ToString("N0"), count.ToString("N0")));
        }
Ejemplo n.º 8
0
        public override bool CanHappen(string msg, [NotNull] Viewer viewer)
        {
            if (!PurchaseHelper.TryGetPawn(viewer.username, out _pawn))
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.NoPawn".Localize());

                return(false);
            }

            var worker = ArgWorker.CreateInstance(CommandFilter.Parse(msg).Skip(2));

            if (!worker.TryGetNextAsItem(out _item) || !_item.IsValid())
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.InvalidItemQuery".LocalizeKeyed(worker.GetLast()));

                return(false);
            }

            if (_item.TryGetError(out string error))
            {
                MessageHelper.ReplyToUser(viewer.username, error);

                return(false);
            }

            if (!(_item.Thing.Thing is { IsWeapon : true }) || _item.Thing.ItemData?.IsEquippable != true)
Ejemplo n.º 9
0
 private void ParseDataParameter(CommandFilter filter)
 {
     foreach (var parameter in _filter.Parameters)
     {
         filter.AddParam(parameter.Key, parameter.Value);
     }
 }
Ejemplo n.º 10
0
        public override void RunCommand([NotNull] ITwitchMessage message)
        {
            string code = CommandFilter.Parse(message.Message).Skip(1).FirstOrDefault();

            if (code.NullOrEmpty())
            {
                return;
            }

            if (!Data.ColorIndex.TryGetValue(code !.ToLowerInvariant(), out Color color) && !ColorUtility.TryParseHtmlString(code, out color))
            {
                MessageHelper.ReplyToUser(message.Username, "TKUtils.NotAColor".LocalizeKeyed(code));

                return;
            }

            if (!PurchaseHelper.TryGetPawn(message.Username, out Pawn pawn))
            {
                MessageHelper.ReplyToUser(message.Username, "TKUtils.NoPawn".Localize());

                return;
            }

            pawn.story.favoriteColor = new Color(color.r, color.g, color.b, 1f);
            message.Reply("TKUtils.FavoriteColor.Complete".Localize());
        }
Ejemplo n.º 11
0
        public override bool CanHappen(string msg, [NotNull] Viewer viewer)
        {
            if (!PurchaseHelper.TryGetPawn(viewer.username, out _pawn))
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.NoPawn".Localize());

                return(false);
            }

            var worker = ArgWorker.CreateInstance(CommandFilter.Parse(msg).Skip(2));

            if (!worker.TryGetNextAsTrait(out _thisShop) || !worker.TryGetNextAsTrait(out _thatShop))
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.InvalidTraitQuery".LocalizeKeyed(worker.GetLast()));

                return(false);
            }

            if (!IsUsable(_thisShop, _thatShop))
            {
                MessageHelper.ReplyToUser(
                    viewer.username,
                    $"TKUtils.{(_thisShop.CanRemove ? "" : "Remove")}Trait.Disabled".LocalizeKeyed((_thisShop.CanRemove ? _thatShop : _thisShop).Name.CapitalizeFirst())
                    );

                return(false);
            }

            if (TraitHelper.GetTotalTraits(_pawn) >= AddTraitSettings.maxTraits && WouldExceedLimit())
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.ReplaceTrait.Violation".LocalizeKeyed(_thisShop.Name, _thatShop.Name));

                return(false);
            }

            if (!viewer.CanAfford(TotalPrice))
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.InsufficientBalance".LocalizeKeyed(TotalPrice.ToString("N0"), viewer.GetViewerCoins().ToString("N0")));

                return(false);
            }

            if (!PassesCharacterCheck(viewer))
            {
                return(false);
            }

            if (!PassesModCheck(viewer))
            {
                return(false);
            }

            if (!PassesValidationCheck(viewer))
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 12
0
        internal void Connect(ITextBuffer textBuffer)
        {
            Requires.NotNull(textBuffer, nameof(textBuffer));

            this.TextBuffer         = textBuffer;
            this.filter             = this.CreateCommandFilter(textBuffer);
            this.ErrorListPresenter = new ErrorListPresenter(this.WpfTextView, this.core);
        }
Ejemplo n.º 13
0
        public void CommandFilterRestrictsExecutionTest(IMessage message, CommandFilter filter, BotConfiguration configuration, bool canExecute)
        {
            IServiceCollection services = new ServiceCollection();

            services.AddSingleton(configuration);

            Assert.Equal(canExecute, filter.CanExecuteInContext(message, services.BuildServiceProvider()));
        }
Ejemplo n.º 14
0
        public void Add_Already_Added_Exception()
        {
            var filter = new CommandFilter();

            filter.Add <MockCommand>();

            Assert.That(() => filter.Add <MockCommand>(), Throws.InvalidOperationException);
        }
Ejemplo n.º 15
0
        public override bool CanHappen(string msg, [NotNull] Viewer viewer)
        {
            if (CommandBase.GetOrFindPawn(viewer.username) != null)
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.HasPawn".Localize());

                return(false);
            }

            _map = Helper.AnyPlayerMap;

            if (_map == null)
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.NoMap".Localize());

                return(false);
            }

            if (!CellFinder.TryFindRandomEdgeCellWith(p => _map.reachability.CanReachColony(p) && !p.Fogged(_map), _map, CellFinder.EdgeRoadChance_Neutral, out _loc))
            {
                TkUtils.Logger.Warn("No reachable location to spawn a viewer pawn!");

                return(false);
            }

            GetDefaultKind();

            if (!TkSettings.PurchasePawnKinds)
            {
                return(CanPurchaseRace(viewer, _pawnKindItem));
            }

            var worker = ArgWorker.CreateInstance(CommandFilter.Parse(msg).Skip(2));

            if (!worker.TryGetNextAsPawn(out PawnKindItem temp) || _pawnKindItem?.ColonistKindDef == null)
            {
                if (worker.GetLast().NullOrEmpty())
                {
                    return(CanPurchaseRace(viewer, _pawnKindItem !));
                }

                MessageHelper.ReplyToUser(viewer.username, "TKUtils.InvalidKindQuery".LocalizeKeyed(worker.GetLast()));

                return(false);
            }

            _pawnKindItem = temp;
            _kindDef      = _pawnKindItem.ColonistKindDef;

            if (_kindDef.RaceProps.Humanlike)
            {
                return(CanPurchaseRace(viewer, _pawnKindItem));
            }

            MessageHelper.ReplyToUser(viewer.username, "TKUtils.BuyPawn.Humanlike".Localize());

            return(false);
        }
Ejemplo n.º 16
0
        public void can_invoke_command_filters()
        {
            var filters      = CommandFilter.GetFilters(Assembly.GetExecutingAssembly());
            var findAndRun   = filters.First(f => f.Name == "FindAndRunCommand");
            var headerFooter = filters.First(f => f.Name == "HeaderAndFooterFilter");

            findAndRun.Invoke(null, null).ToString().ShouldEqual("I am the result of running the app");
            headerFooter.Invoke(null, findAndRun).ToString().ShouldEqual("-----\nI am the result of running the app\n-------\n");
        }
Ejemplo n.º 17
0
        public void Contains()
        {
            var filter = new CommandFilter();

            Assert.That(filter.Contains <MockCommand>(), Is.False);

            filter.Add <MockCommand>();

            Assert.That(filter.Contains <MockCommand>(), Is.True);
        }
Ejemplo n.º 18
0
        public void Enable_Get_Set()
        {
            var filter = new CommandFilter();

            Assert.That(filter.Enable, Is.False);

            filter.Enable = true;

            Assert.That(filter.Enable, Is.True);
        }
Ejemplo n.º 19
0
        public void Remove()
        {
            var filter = new CommandFilter();

            Assert.That(filter.Remove <MockCommand>(), Is.False);

            filter.Add <MockCommand>();

            Assert.That(filter.Remove <MockCommand>(), Is.True);
        }
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            IWpfTextView view = AdaptersFactory.GetWpfTextView(textViewAdapter);
            Debug.Assert(view != null);

            CommandFilter filter = new CommandFilter(view, CompletionBroker);

            IOleCommandTarget next;
            ErrorHandler.ThrowOnFailure(textViewAdapter.AddCommandFilter(filter, out next));
            filter.Next = next;
        }
Ejemplo n.º 21
0
 /// <summary>
 /// Fires when a view is unregistered.
 /// </summary>
 /// <param name="pView">[in] Pointer to the <see cref="T:Microsoft.VisualStudio.TextManager.Interop.IVsTextView"/> interface identifying the view that was unregistered.</param>
 public void OnUnregisterView(IVsTextView pView)
 {
     foreach (Type filterType in CommandFilters)
     {
         CommandFilter filter = Activator.CreateInstance(filterType) as CommandFilter;
         if (filter != null)
         {
             pView.RemoveCommandFilter(filter);
         }
     }
 }
Ejemplo n.º 22
0
        private void AttachToVsTextView(IVsTextView shimView, IWpfTextView editorView)
        {
            // Add command filter to IVsTextView. If something goes wrong, throw.
            var commandFilter = new CommandFilter(this.copyDataService, editorView);

            var nextCommandTarget = default(IOleCommandTarget);
            int returnValue = shimView.AddCommandFilter(commandFilter, out nextCommandTarget);
            Marshal.ThrowExceptionForHR(returnValue);
            Contract.ThrowIfNull(nextCommandTarget);

            commandFilter.Next = nextCommandTarget;
        }
Ejemplo n.º 23
0
        public void can_find_command_filters()
        {
            var filters = CommandFilter.GetFilters(Assembly.GetExecutingAssembly());

            (filters.Count > 1).ShouldBeTrue();

            filters.Select(f => f.FullName).ShouldContain("MooGet.Specs.CLI.CommandFilterSpec.FindAndRunCommand");
            filters.Select(f => f.FullName).ShouldContain("MooGet.Specs.CLI.CommandFilterSpec.HeaderAndFooterFilter");
            filters.Select(f => f.Name).ShouldContain("FindAndRunCommand");
            filters.Select(f => f.Name).ShouldContain("HeaderAndFooterFilter");
            filters.Select(f => f.Description).ShouldContain("I am the description ...");
        }
Ejemplo n.º 24
0
        public override void RunCommand([NotNull] ITwitchMessage twitchMessage)
        {
            string             query = CommandFilter.Parse(twitchMessage.Message).Skip(1).FirstOrDefault();
            ResearchProjectDef project;

            if (query.NullOrEmpty())
            {
                project = Current.Game.researchManager.currentProj;
            }
            else
            {
                project = DefDatabase <ResearchProjectDef> .AllDefs.FirstOrDefault(
                    p => p.defName.EqualsIgnoreCase(query) || p.label.ToToolkit().EqualsIgnoreCase(query !.ToToolkit())
                    );


                if (project == null)
                {
                    ThingDef thing = DefDatabase <ThingDef> .AllDefs.FirstOrDefault(
                        t => t.defName.EqualsIgnoreCase(query) || t.label?.ToToolkit()?.EqualsIgnoreCase(query !.ToToolkit()) == true
                        );

                    project = thing?.recipeMaker?.researchPrerequisite;
                    project ??= thing?.recipeMaker?.researchPrerequisites?.FirstOrDefault(p => !p.IsFinished);
                }
            }

            if (project == null)
            {
                twitchMessage.Reply(
                    (!query.NullOrEmpty() ? "TKUtils.Research.InvalidQuery".LocalizeKeyed(query) : "TKUtils.Research.None".Localize()).WithHeader("Research".Localize())
                    );

                return;
            }

            var segments = new List <string> {
                ResponseHelper.JoinPair(project.LabelCap, project.ProgressPercent.ToStringPercent())
            };

            if (project.prerequisites != null && !project.PrerequisitesCompleted)
            {
                List <ResearchProjectDef> prerequisites = project.prerequisites;

                string[] container = prerequisites.Where(prerequisite => !prerequisite.IsFinished)
                                     .Select(prerequisite => ResponseHelper.JoinPair(prerequisite.LabelCap, prerequisite.ProgressPercent.ToStringPercent()))
                                     .ToArray();

                segments.Add(ResponseHelper.JoinPair("ResearchPrerequisites".Localize(), container.SectionJoin()));
            }

            twitchMessage.Reply(segments.GroupedJoin().WithHeader("Research".Localize()));
        }
Ejemplo n.º 25
0
        private void AttachToVsTextView(IVsTextView shimView, IWpfTextView editorView)
        {
            // Add command filter to IVsTextView. If something goes wrong, throw.
            var commandFilter = new CommandFilter(this.copyDataService, editorView);

            var nextCommandTarget = default(IOleCommandTarget);
            int returnValue       = shimView.AddCommandFilter(commandFilter, out nextCommandTarget);

            Marshal.ThrowExceptionForHR(returnValue);
            Contract.ThrowIfNull(nextCommandTarget);

            commandFilter.Next = nextCommandTarget;
        }
Ejemplo n.º 26
0
        public override void RunCommand([NotNull] ITwitchMessage twitchMessage)
        {
            var worker = ArgWorker.CreateInstance(CommandFilter.Parse(twitchMessage.Message).Skip(1));

            if (!worker.TryGetNextAsViewer(out Viewer viewer) || !worker.TryGetNextAsInt(out int amount))
            {
                return;
            }

            viewer.GiveViewerCoins(amount);
            Store_Logger.LogGiveCoins(twitchMessage.Username, viewer.username, amount);
            twitchMessage.Reply("TKUtils.GiveCoins.Done".LocalizeKeyed(amount.ToString("N0"), viewer.username, viewer.GetViewerCoins().ToString("N0")));
        }
Ejemplo n.º 27
0
        public static ToolkitChatCommand GetChatCommand(string commandText)
        {
            string baseCommand = CommandFilter.Parse(commandText).FirstOrDefault();

            if (baseCommand == null)
            {
                return(null);
            }

            return(DefDatabase <ToolkitChatCommand> .AllDefsListForReading.FirstOrDefault(
                       c => c.commandText.EqualsIgnoreCase(baseCommand)
                       ));
        }
Ejemplo n.º 28
0
        public static object ExtensionTestCommand(string[] args, CommandFilter command)
        {
            var arguments = new List <string>(args);

            if (arguments.Contains("--with-header"))
            {
                arguments.Remove("--with-header");
                return("HEADER\n------\n" + command.Invoke(arguments.ToArray()));
            }
            else
            {
                return(command.Invoke(args));
            }
        }
Ejemplo n.º 29
0
        public override void RunCommand([NotNull] ITwitchMessage twitchMessage)
        {
            _invoker = twitchMessage.Username;
            string[] segments = CommandFilter.Parse(twitchMessage.Message).Skip(1).ToArray();
            string   category = segments.FirstOrFallback("");
            string   query    = segments.Skip(1).FirstOrFallback("");

            if (!Index.TryGetValue(category.ToLowerInvariant(), out Category result))
            {
                query = category;
            }

            PerformLookup(result, query);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Fires when a view is registered.
        /// </summary>
        /// <param name="pView">[in] Pointer to the <see cref="T:Microsoft.VisualStudio.TextManager.Interop.IVsTextView"/> interface identifying the view that was registered. </param>
        public void OnRegisterView(IVsTextView pView)
        {
            // If this view belongs to a document that had no views before the document
            // has been opened. It's time to notify the CloneDetectiveManager about it.
            // However there is a problem: The text buffer represented by textLines has
            // not been initialized yet, i.e. the file name is not set and the file
            // content is not loaded yet. So we need to subscribe to the text buffer to
            // get notified when the file load procedure completed.

            //IVsTextLines textLines;
            //ErrorHandler.ThrowOnFailure(pView.GetBuffer(out textLines));
            //if (textLines == null)
            //{
            //    return;
            //}

            //TextBufferDataEventSink textBufferDataEventSink = new TextBufferDataEventSink();
            //IConnectionPoint connectionPoint;
            //uint cookie;

            //IConnectionPointContainer textBufferData = (IConnectionPointContainer)textLines;
            //Guid interfaceGuid = typeof(IVsTextBufferDataEvents).GUID;
            //textBufferData.FindConnectionPoint(ref interfaceGuid, out connectionPoint);
            //connectionPoint.Advise(textBufferDataEventSink, out cookie);

            //textBufferDataEventSink.TextLines = textLines;
            //textBufferDataEventSink.ConnectionPoint = connectionPoint;
            //textBufferDataEventSink.Cookie = cookie;

            //添加filter到view
            foreach (Type filterType in CommandFilters)
            {
                CommandFilter filter = Activator.CreateInstance(filterType) as CommandFilter;
                if (filter != null)
                {
                    pView.AddCommandFilter(filter, out filter.NextCommandTarget);
                }
            }

            //TextViewWindow.FromHandle(pView.GetWindowHandle());


            RegisterHandler1 handler = RegisterViewEvent;

            if (handler != null)
            {
                handler(pView);
            }
        }
Ejemplo n.º 31
0
        private void MetroWindow_Loaded(object sender, RoutedEventArgs e)
        {
            //Application.Current.UpdateContentWindows(this);
            $"{Title} Loading...".INFO();

            CommandRefresh.Hide();
            CommandFilter.Hide();

            if (Content is BrowerPage)
            {
                CommandPageRead.Show();
                CommandRefreshThumb.ToolTip = "Refresh";
                PreftchingProgress.Hide();
            }
            else
                CommandPageRead.Hide();

            if (Content is IllustDetailPage ||
                Content is IllustImageViewerPage ||
                Content is SearchResultPage ||
                Content is HistoryPage)
            {
                CommandRefresh.Show();
                if (!(Content is IllustImageViewerPage))
                {
                    CommandRefreshThumb.Show();
                    PreftchingProgress.Show();
                    CommandFilter.Show();
                }
            }

            if (Content is BatchProcessPage)
            {
                LeftWindowCommands.Hide();
                RightWindowCommands.Hide();
                ShowMinButton = true;
                ShowMaxRestoreButton = false;
                ResizeMode = ResizeMode.CanMinimize;
            }

            if (Application.Current.DropBoxExists() == null)
                CommandDropbox.IsChecked = false;
            else
                CommandDropbox.IsChecked = true;

            this.AdjustWindowPos();

            Commands.SaveOpenedWindows.Execute(null);
        }
Ejemplo n.º 32
0
        async void LoadCommands()
        {
            await StopCommandsSubscription();

            bool          loaded = false;
            CommandFilter filter = new CommandFilter()
            {
                End       = filterCommandsEnd,
                Start     = filterCommandsStart,
                SortOrder = SortOrder.DESC
            };
            var list = new IncrementalLoadingCollection <Command>(async(take, skip) =>
            {
                filter.Skip = (int)skip;
                filter.Take = (int)take;
                try
                {
                    Debug.WriteLine("CMD LOAD START");
                    var commands = await ClientService.Current.GetCommandsAsync(deviceId, filter);
                    Debug.WriteLine("CMD LOAD END");
                    return(commands);
                }
                catch (Exception ex)
                {
                    Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        new MessageDialog(ex.Message, "Error").ShowAsync();
                    });
                    throw ex;
                }
            }, 20);

            list.IsLoadingChanged += (s, isLoading) =>
            {
                LoadingItems += isLoading ? 1 : -1;
                if (!isLoading && !loaded)
                {
                    StartCommandsSubscription();
                    if (s.Count > 0)
                    {
                        // makes server response faster
                        filter.End = s.First().Timestamp;
                    }
                    loaded = true;
                }
            };
            CommandsObservable = list;
        }
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            IWpfTextView view = AdaptersFactory.GetWpfTextView(textViewAdapter);
            Debug.Assert(view != null);

            ITextDocument document;
            if (!TextDocumentFactoryService.TryGetTextDocument(view.TextDataModel.DocumentBuffer, out document))
                return;

            string fileName = Path.GetFileName(document.FilePath);
            if (!fileName.Equals("robots.txt", StringComparison.InvariantCultureIgnoreCase))
                return;

            CommandFilter filter = new CommandFilter(view, CompletionBroker);

            IOleCommandTarget next;
            ErrorHandler.ThrowOnFailure(textViewAdapter.AddCommandFilter(filter, out next));
            filter.Next = next;
        }
Ejemplo n.º 34
0
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            IWpfTextView textView = _editorFactory.GetWpfTextView(textViewAdapter);
            if (textView == null)
            {
                return;
            }

            if (_telemetrySession == null)
            {
                _telemetrySession = TelemetrySessionForPPT.Create(this.GetType().Assembly);
            }

            IOleCommandTarget next;
            var commandFilter = new CommandFilter(textView, _peekBroker, _telemetrySession);
            int hr = textViewAdapter.AddCommandFilter(commandFilter, out next);
            if (next != null)
            {
                commandFilter.Next = next;
            }
        }
#pragma warning restore 169


        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            IWpfTextView view = AdaptersFactory.GetWpfTextView(textViewAdapter);
            Debug.Assert(view != null);

            // check whether the document is named robots.txt
            ITextDocument document;
            if (!TextDocumentFactoryService.TryGetTextDocument(view.TextDataModel.DocumentBuffer, out document))
                return;

            string fileName = Path.GetFileName(document.FilePath);
            if (!fileName.Equals("robots.txt", StringComparison.InvariantCultureIgnoreCase))
                return;
            
            // register command filter
            CommandFilter filter = new CommandFilter(view,
                _textBufferUndoManagerProvider.GetTextBufferUndoManager(view.TextBuffer).TextBufferUndoHistory
            );

            IOleCommandTarget next;
            ErrorHandler.ThrowOnFailure(textViewAdapter.AddCommandFilter(filter, out next));
            filter.Next = next;
        }
Ejemplo n.º 36
0
 public CommandImpl(DiscreteCommand discreteCommand, CommandFilter filter)
 {
     discrete_command = discreteCommand;
     this.filter = filter;
 }