コード例 #1
0
        private void CreateFile(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var    dte    = VsHelpers.GetService <DTE, DTE2>();
            string folder = VsHelpers.GetSelectedItemPath(out object item);

            if (string.IsNullOrEmpty(folder))
            {
                return;
            }

            string fileName = Path.Combine(folder, Constants.FileName);

            if (File.Exists(fileName))
            {
                MessageBox.Show(Resources.Text.EditorConfigFileAlreadyExist, Vsix.Name, MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                File.WriteAllText(fileName, Constants.DefaultFileContent);
                ProjectItem newItem = AddFileToHierarchy(item, fileName);

                if (newItem != null)
                {
                    VsHelpers.OpenFile(fileName);
                }
            }
        }
コード例 #2
0
        public override int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (pguidCmdGroup == _commandGroup && nCmdID == _commandId)
            {
                var document = EditorConfigDocument.FromTextBuffer(_buffer);
                EditorConfigDocument parent = document?.Parent;

                if (parent != null)
                {
                    VsHelpers.PreviewDocument(parent.FileName);
                }
                else
                {
                    var statusBar = Package.GetGlobalService(typeof(SVsStatusbar)) as IVsStatusbar;
                    statusBar.IsFrozen(out int frozen);

                    if (frozen == 0)
                    {
                        statusBar.SetText("This is a root document with no inheritance");
                    }
                }

                return(VSConstants.S_OK);
            }

            return(Next.Exec(pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
        }
コード例 #3
0
        private void InitializeInheritance()
        {
            VsHelpers.SatisfyImportsOnce(this);

            var componentModel = (IComponentModel)Package.GetGlobalService(typeof(SComponentModel));

            if (componentModel == null)
            {
                return;
            }

            IContentTypeRegistryService contentTypeRegistry = componentModel.DefaultExportProvider.GetExportedValue <IContentTypeRegistryService>();

            _contentType = contentTypeRegistry.GetContentType(Constants.LanguageName);

            if (DocumentService.TryGetTextDocument(TextBuffer, out ITextDocument doc))
            {
                FileName = doc.FilePath;
            }
        }
コード例 #4
0
        private void CreateInheritance(string parentFileName, int padding)
        {
            Dispatcher.VerifyAccess();

            string fileName = _adornmentLayer.TextView.TextBuffer.GetFileName();

            if (string.IsNullOrEmpty(fileName))
            {
                return;
            }

            string shortcut = GetShortcut();

            if (!string.IsNullOrEmpty(shortcut))
            {
                ToolTip = $"Navigate to immediate parent ({shortcut})";
            }

            string relative = PackageUtilities.MakeRelative(fileName, parentFileName);

            var inherits = new ThemedTextBlock()
            {
                Text     = ("└─  " + relative).PadLeft(relative.Length + 4 + padding),// "→ " + relative,
                FontSize = 16,
                Cursor   = Cursors.Hand,
                ToolTip  = "Click to open " + parentFileName,
                Margin   = new System.Windows.Thickness(0, 3, 0, 0),
            };

            inherits.MouseLeftButtonDown += (s, e) =>
            {
                Dispatcher.VerifyAccess();

                e.Handled = true;
                VsHelpers.PreviewDocument(parentFileName);
                Telemetry.TrackUserTask("InheritanceNavigated");
            };

            Children.Add(inherits);
        }