Esempio n. 1
0
        private void OnKeyDown(object sender, KeyEventArgs e)
        {
            if (Settings?.IsReadOnlyMode == true)
            {
                return;
            }
            if (Readonly)
            {
                return;
            }

            if (e.Key == Key.Enter || e.Key == Key.Tab)
            {
                var text = TagCtrl.CaretPosition.GetTextInRun(LogicalDirection.Backward);

                if (string.IsNullOrWhiteSpace(text) && e.Key == Key.Enter)
                {
                    e.Handled = true;
                }
                else if (string.IsNullOrWhiteSpace(text) && e.Key == Key.Tab)
                {
                    e.Handled = false;
                }
                else
                {
                    TagSource.Add(text);
                    e.Handled = true;

                    Changed?.Invoke(this);
                }

                AutocompletePopup.IsOpen = false;
            }
        }
Esempio n. 2
0
        public TagFileName(string RelativePath, MapfileVersion ver, TagSource source)
        {
            m_RelativePath = RelativePath;
            m_Version      = ver;
            m_TagSource    = source;

            //TODO:  run "Exists" test on source to see if we need to set the NotFound flag
        }
            public Tagger(
                IThreadingContext threadingContext,
                IAsynchronousOperationListener listener,
                IForegroundNotificationService notificationService,
                TagSource tagSource,
                ITextBuffer subjectBuffer)
            {
                Contract.ThrowIfNull(subjectBuffer);

                _subjectBuffer           = subjectBuffer;
                _cancellationTokenSource = new CancellationTokenSource();

                _batchChangeNotifier = new BatchChangeNotifier(
                    threadingContext,
                    subjectBuffer, listener, notificationService, NotifyEditorNow, _cancellationTokenSource.Token);

                _tagSource = tagSource;

                _tagSource.OnTaggerAdded(this);
                _tagSource.TagsChangedForBuffer += OnTagsChangedForBuffer;
                _tagSource.Paused  += OnPaused;
                _tagSource.Resumed += OnResumed;

                // There is a many-to-one relationship between Taggers and TagSources.  i.e. one
                // tag-source can be used by many Taggers.  As such, we may be a tagger that is
                // wrapping a tag-source that has already produced tags and had sent out the
                // notifications about those tags.
                //
                // However, we still want to notify the code consuming us that we have tags to
                // display.  That way, tags can display as soon as possible when someone creates
                // a new tagger for a view/buffer.
                //
                // Note: we have to do this in the future instead of right now because we haven't
                // even been returned to the caller for them to hook up to change notifications
                // from us.
                notificationService.RegisterNotification(
                    () =>
                {
                    if (this.TagsChanged == null)
                    {
                        // don't bother reporting tags if no one is listening.
                        return;
                    }

                    var tags = _tagSource.TryGetTagIntervalTreeForBuffer(_subjectBuffer);
                    if (tags != null)
                    {
                        var collection = new NormalizedSnapshotSpanCollection(
                            tags.GetSpans(_subjectBuffer.CurrentSnapshot).Select(ts => ts.Span));
                        this.NotifyEditorNow(collection);
                    }
                },
                    listener.BeginAsyncOperation(GetType().FullName + ".ctor-ReportInitialTags"),
                    _cancellationTokenSource.Token);
            }
Esempio n. 4
0
        private TagSource GetOrCreateTagSource(ITextView textViewOpt, ITextBuffer subjectBuffer)
        {
            if (!this.TryRetrieveTagSource(textViewOpt, subjectBuffer, out var tagSource))
            {
                tagSource = new TagSource(textViewOpt, subjectBuffer, this, _asyncListener, _notificationService);

                this.StoreTagSource(textViewOpt, subjectBuffer, tagSource);
                tagSource.Disposed += (s, e) => this.RemoveTagSource(textViewOpt, subjectBuffer);
            }

            return(tagSource);
        }
Esempio n. 5
0
        public static bool TryParse(string uri, out TagSource source)
        {
            source = null;

            //GithubTagSource github;

            //if (String.IsNullOrEmpty(uri))
            //{
            //}
            //else if (GithubTagSource.TryParse(uri, out github))
            //{
            //    source = github;
            //}

            return(source != null);
        }
Esempio n. 6
0
            public Tagger(
                IAsynchronousOperationListener listener,
                IForegroundNotificationService notificationService,
                TagSource tagSource,
                ITextBuffer subjectBuffer)
            {
                Contract.ThrowIfNull(subjectBuffer);

                _subjectBuffer       = subjectBuffer;
                _batchChangeNotifier = new BatchChangeNotifier(subjectBuffer, listener, notificationService, ReportChangedSpan);

                _tagSource = tagSource;

                _tagSource.OnTaggerAdded(this);
                _tagSource.TagsChangedForBuffer += OnTagsChangedForBuffer;
                _tagSource.Paused  += OnPaused;
                _tagSource.Resumed += OnResumed;
            }
Esempio n. 7
0
        private void AutocompleteContent_Selected(object sender, RoutedEventArgs e)
        {
            if (Settings?.IsReadOnlyMode == true)
            {
                return;
            }

            if (AutocompleteContent.SelectedIndex >= 0 && AutocompleteContent.SelectedValue != null)
            {
                var tag = (string)AutocompleteContent.SelectedValue;

                TagSource.Add(tag);

                Changed?.Invoke(this);

                AutocompletePopup.IsOpen = false;
            }
        }
Esempio n. 8
0
        private void ShowTagChooser()
        {
            void Update(string name, bool check)
            {
                if (check)
                {
                    if (TagSource.Any(t => t.ToLower() == name.ToLower()))
                    {
                        return;
                    }
                    TagSource.Add(name);
                    TriggerChanged(name);
                }
                else
                {
                    var rm = TagSource.FirstOrDefault(t => t.ToLower() == name.ToLower());
                    if (rm != null)
                    {
                        TagSource.Remove(rm);
                        TriggerChanged(name);
                    }
                }
            }

            List <CheckableTag> tags = Repository.EnumerateAllTags().Distinct().OrderBy(p => p.ToLower()).Select(p => new CheckableTag(p, Update)).ToList();

            if (tags.Count == 0)
            {
                return;                            // no tags
            }
            foreach (var tm in TagSource)
            {
                foreach (var t in tags.Where(p => p.Name.ToLower() == tm))
                {
                    t.Checked = true;
                }
            }

            TagChoosePopupList.ItemsSource = tags;

            TagChoosePopup.IsOpen = true;
        }
Esempio n. 9
0
 private void StoreTagSource(ITextView textViewOpt, ITextBuffer subjectBuffer, TagSource tagSource)
 {
     if (textViewOpt != null)
     {
         textViewOpt.AddPerSubjectBufferProperty(subjectBuffer, _uniqueKey, tagSource);
     }
     else
     {
         subjectBuffer.Properties.AddProperty(_uniqueKey, tagSource);
     }
 }
Esempio n. 10
0
 private bool TryRetrieveTagSource(ITextView textViewOpt, ITextBuffer subjectBuffer, out TagSource tagSource)
 {
     return(textViewOpt != null
         ? textViewOpt.TryGetPerSubjectBufferProperty(subjectBuffer, _uniqueKey, out tagSource)
         : subjectBuffer.Properties.TryGetProperty(_uniqueKey, out tagSource));
 }
 public Tagger(TagSource tagSource)
 {
     _tagSource = tagSource;
     _tagSource.OnTaggerAdded(this);
 }
Esempio n. 12
0
        private void OnTextChanged(object sender, TextChangedEventArgs e)
        {
            if (Settings?.IsReadOnlyMode == true)
            {
                return;
            }
            if (Readonly)
            {
                return;
            }

            var para = TagCtrl.CaretPosition.Paragraph;

            if (para != null && e.Changes.Any(c => c.RemovedLength > 0))
            {
                var doctags = para.Inlines
                              .OfType <InlineUIContainer>()
                              .Select(r => r.Child)
                              .Cast <ContentPresenter>()
                              .Select(p => p.Content.ToString())
                              .ToList();

                if (!TagSource.SequenceEqual(doctags))
                {
                    TagSource.SynchronizeCollection(doctags);

                    Changed?.Invoke(this);
                }
            }

            var text = new TextRange(TagCtrl.Document.ContentStart, TagCtrl.Document.ContentEnd).Text.Trim();

            if (text.Length >= 2 && Repository != null && Settings != null && Settings.TagAutocomplete)
            {
                var hints = Repository
                            .EnumerateAllTags()
                            .Concat(new[] { AppSettings.TAG_MARKDOWN, AppSettings.TAG_LIST })
                            .OrderBy(p => p)
                            .Distinct()
                            .Except(TagSource)
                            .Where(t => t.ToLower().StartsWith(text.ToLower()))
                            .ToList();

                if (hints.Any())
                {
                    AutocompleteContent.Items.SynchronizeGenericCollection(hints);
                    AutocompleteContent.SelectedIndex = -1;

                    AutocompletePopup.Width  = MainGrid.ActualWidth;
                    AutocompletePopup.IsOpen = true;
                }
                else
                {
                    AutocompletePopup.IsOpen = false;
                }
            }
            else
            {
                AutocompletePopup.IsOpen = false;
            }


            OnExplicitPropertyChanged("FormattedText");
        }
Esempio n. 13
0
        private void DetermineTagSource()
        {
            //priority goes local, local shared, prefab, archive
            bool bFound = false;

            //highest priority:  debug
            if (RelativePath.IndexOf(":") != -1)
            {
                m_TagSource = TagSource.Debug;
                bFound      = true;
            }

            //is it local project
            if (!bFound)
            {
                string proj_path = OptionsManager.ActiveProjectPath;
                proj_path += RelativePath;
                if (proj_path.Length < 250)
                {
                    if (File.Exists(proj_path))
                    {
                        m_TagSource = TagSource.LocalProject;
                        bFound      = true;
                    }
                }
            }

            //is it local shared/common?
            if (!bFound)
            {
                string shared_path = OptionsManager.GetSharedTagsPath(m_Version);
                shared_path += RelativePath;
                if (shared_path.Length < 250)
                {
                    if (File.Exists(shared_path))
                    {
                        m_TagSource = TagSource.LocalShared;
                        bFound      = true;
                    }
                }
            }

            //is it a prefab?
            if (!bFound)
            {
                if (ProjectManager.PrefabList != null)
                {
                    TagFileName[] tfn_list = ProjectManager.PrefabList;
                    for (int i = 0; i < tfn_list.Length; i++)
                    {
                        if (RelativePath == tfn_list[i].RelativePath)
                        {
                            //todo: figure out how to access the prefab source data
                            //if(File.Exists(prefab_path))
                            //{
                            //  m_TagSource = TagSource.Prefab;
                            //  bFound = true;
                            //}
                        }
                    }
                }
            }

            if (!bFound)
            {
                m_TagSource = TagSource.Archive;

                switch (m_Version)
                {
                case MapfileVersion.HALOPC:
                case MapfileVersion.HALOCE:
                    bFound = TagLibraryManager.HaloPC.FileExists(m_RelativePath);
                    break;

                case MapfileVersion.XHALO1:
                    bFound = TagLibraryManager.HaloXbox.FileExists(m_RelativePath);
                    break;

                case MapfileVersion.XHALO2:
                    bFound = TagLibraryManager.Halo2Xbox.FileExists(m_RelativePath);
                    break;
                }
                //TODO:  verify file exists in archive
            }

            if (!bFound)
            {
                m_TagSource = TagSource.NotFound;
            }
        }