private void AddGeneratedFilesToProject(CodeWriterOutput output)
 {
     foreach (string file in output.CodeFileNames)
     {
         ProjectHelpers.AddFileToActiveProject(file);
     }
 }
        private async Task GenerateAsync(SpriteDocument sprite, bool hasUpdated = false)
        {
            _dte.StatusBar.Text = "Generating sprite...";

            if (!hasUpdated)
            {
                ProjectHelpers.AddFileToActiveProject(sprite.FileName);
            }

            //Default file name is the sprite name with specified file extension.
            string imageFile = Path.ChangeExtension(sprite.FileName, sprite.FileExtension);

            IEnumerable <SpriteFragment> fragments = await SpriteGenerator.MakeImage(sprite, imageFile, UpdateSpriteAsync);

            if (!hasUpdated)
            {
                ProjectHelpers.AddFileToProject(sprite.FileName, imageFile);
                EditorExtensionsPackage.DTE.ItemOperations.OpenFile(sprite.FileName);
            }

            await Export(fragments, imageFile, sprite);

            if (sprite.Optimize)
            {
                await new ImageCompressor().CompressFilesAsync(imageFile);
            }

            _dte.StatusBar.Text = "Sprite generated";
        }
Exemple #3
0
        private void Execute()
        {
            try
            {
                string parentPath = selectedFiles.FirstOrDefault(o => o.ToLower(CultureInfo.CurrentCulture).Contains(scriptTypingsFolder));
                parentPath = parentPath.Remove(parentPath.ToLower(CultureInfo.CurrentCulture).IndexOf(scriptTypingsFolder, StringComparison.OrdinalIgnoreCase) + scriptTypingsFolder.Length);
                string fullPath = Path.Combine(parentPath, hubsT4FileName);

                if (File.Exists(fullPath))
                {
                    MessageBox.Show("A Hubs.tt file already exists", "Web Essentials", MessageBoxButtons.OK);
                    return;
                }

                string extensionDir = Path.GetDirectoryName(typeof(HubsT4Menu).Assembly.Location);
                string settingsFile = Path.Combine(extensionDir, @"Resources\settings-defaults\" + hubsT4FileName);
                File.Copy(settingsFile, fullPath);

                ProjectHelpers.AddFileToActiveProject(fullPath);

                _dte.ItemOperations.OpenFile(fullPath);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Something went wrong =(" + Environment.NewLine + Environment.NewLine + ex.ToString(), "Web Essentials", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
            }
        }
Exemple #4
0
        public static async void SaveClipboardImageToFile(IDataObject data, string fileName)
        {
            if (data.GetDataPresent(DataFormats.FileDrop))
            {
                string original = ((string[])data.GetData(DataFormats.FileDrop))[0];

                if (File.Exists(original))
                {
                    File.Copy(original, fileName, true);
                }
            }
            else
            {
                using (Bitmap image = (Bitmap)data.GetData("System.Drawing.Bitmap"))
                    using (MemoryStream ms = new MemoryStream())
                    {
                        image.Save(ms, GetImageFormat(Path.GetExtension(fileName)));
                        byte[] buffer = ms.ToArray();
                        await FileHelpers.WriteAllBytesRetry(fileName, buffer);
                    }
            }

            ImageCompressor compressor = new ImageCompressor();
            await compressor.CompressFilesAsync(fileName).HandleErrors("compressing " + fileName);

            ProjectHelpers.AddFileToActiveProject(fileName);
        }
Exemple #5
0
        private void CopyFileToProject(string fileName)
        {
            string file = Path.Combine(_folder, fileName);

            if (!File.Exists(file))
            {
                string assembly = Assembly.GetExecutingAssembly().Location;
                string folder   = Path.GetDirectoryName(assembly);
                string source   = Path.Combine(folder, "NPM\\Resources\\", fileName);

                File.Copy(source, file, false);
                ProjectHelpers.AddFileToActiveProject(file, "None");
            }
        }
 private void Execute()
 {
     try
     {
         Directory.CreateDirectory(Path.GetDirectoryName(_referencesJsPath));
         File.WriteAllText(_referencesJsPath, "/// <autosync enabled=\"true\" />", Encoding.UTF8);
         ProjectHelpers.AddFileToActiveProject(_referencesJsPath);
         EditorExtensionsPackage.DTE.ItemOperations.OpenFile(_referencesJsPath);
     }
     catch (IOException)
     {
         Logger.ShowMessage("Can't write to the folder: " + _referencesJsPath);
     }
 }
Exemple #7
0
        private async System.Threading.Tasks.Task Execute()
        {
            try
            {
                Directory.CreateDirectory(Path.GetDirectoryName(_referencesJsPath));
                await FileHelpers.WriteAllTextRetry(_referencesJsPath, "/// <autosync enabled=\"true\" />");

                ProjectHelpers.AddFileToActiveProject(_referencesJsPath);
                EditorExtensionsPackage.DTE.ItemOperations.OpenFile(_referencesJsPath);
            }
            catch (IOException)
            {
                Logger.ShowMessage("Can't write to the folder: " + _referencesJsPath);
            }
        }
Exemple #8
0
        protected override bool Execute(ExtractCommandId commandId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (TextView == null)
            {
                return(false);
            }

            string content   = TextView.Selection.SelectedSpans[0].GetText();
            string extension = Path.GetExtension(_dte.ActiveDocument.FullName).ToLowerInvariant();

            if (!_possible.Contains(extension.ToUpperInvariant()))
            {
                extension = ".css";
            }

            string name = Interaction.InputBox("Specify the name of the file", "Web Essentials", "file1" + extension).Trim();

            if (!string.IsNullOrEmpty(name))
            {
                if (string.IsNullOrEmpty(Path.GetExtension(name)))
                {
                    name = name + extension;
                }

                string fileName = Path.Combine(Path.GetDirectoryName(_dte.ActiveDocument.FullName), name);

                if (!File.Exists(fileName))
                {
                    using (EditorExtensionsPackage.UndoContext("Extract to file..."))
                    {
                        using (StreamWriter writer = new StreamWriter(fileName, false, new UTF8Encoding(true)))
                        {
                            writer.Write(content);
                        }

                        ProjectHelpers.AddFileToActiveProject(fileName);
                        TextView.TextBuffer.Delete(TextView.Selection.SelectedSpans[0].Span);
                        _dte.ItemOperations.OpenFile(fileName);
                    }
                }
                else
                {
                    Logger.ShowMessage("The file already exists.");
                }
            }

            return(true);
        }
Exemple #9
0
            private void MakeChanges(string root, string fileName)
            {
                var    element    = this.HtmlSmartTag.Element;
                var    textBuffer = this.HtmlSmartTag.TextBuffer;
                string text       = textBuffer.CurrentSnapshot.GetText(element.InnerRange.Start, element.InnerRange.Length);

                string reference = GetReference(element, fileName, root);

                using (EditorExtensionsPackage.UndoContext((this.DisplayText)))
                {
                    textBuffer.Replace(new Span(element.Start, element.Length), reference);
                    File.WriteAllText(fileName, text, Encoding.UTF8);
                    EditorExtensionsPackage.DTE.ItemOperations.OpenFile(fileName);
                    ProjectHelpers.AddFileToActiveProject(fileName);
                }
            }
Exemple #10
0
            private async Task DownloadFileAsync(Uri url, string fileName)
            {
                try
                {
                    using (WebClient client = new WebClient())
                    {
                        await client.DownloadFileTaskAsync(url, fileName);
                    }

                    ProjectHelpers.AddFileToActiveProject(fileName);
                }
                catch (Exception ex)
                {
                    Logger.ShowMessage(ex.Message);
                }
            }
        /// <summary>
        /// xsd生成wsdl
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void XsdCommandInvoke(object sender, EventArgs e)
        {
            var items = ProjectHelpers.GetSelectedItemPaths(_dte);

            if (items.Count() == 1 &&
                (items.ElementAt(0).ToLower().EndsWith(".xsd", StringComparison.OrdinalIgnoreCase)))
            {
                var _file         = items.ElementAt(0);
                var fileInfo      = new FileInfo(_file);
                var folder        = fileInfo.Directory?.FullName;
                var project       = ProjectHelpers.GetActiveProject().FullName;
                var projectInfo   = new FileInfo(project);
                var folderproject = projectInfo.Directory?.FullName;
                if (!string.IsNullOrEmpty(folder))
                {
                    WsdlWizardForm wizard = null;
                    try
                    {
                        wizard = new WsdlWizardForm(_file);
                        wizard.WsdlLocation          = folder;
                        wizard.DefaultPathForImports = "";
                        wizard.ProjectRootDirectory  = folderproject;
                        wizard.ShowDialog();

                        string wsdlFile = "";
                        if (wizard.DialogResult == DialogResult.OK)
                        {
                            if (wizard.WsdlLocation.Length > 0)
                            {
                                wsdlFile = wizard.WsdlLocation;
                                ProjectHelpers.AddFileToActiveProject(wsdlFile);
                                //ProcessCodeGenerationRequest(wsdlFile);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ProjectHelpers.AddError(_package, ex.ToString());
                        MessageBox.Show(ex.Message, "WSDL Wizard", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        if (wizard != null)
                        {
                            wizard.Close();
                        }
                    }
                }
            }
        }
Exemple #12
0
            private async Task MakeChanges(string root, string fileName)
            {
                var    element    = this.HtmlSmartTag.Element;
                var    textBuffer = this.HtmlSmartTag.TextBuffer;
                string text       = textBuffer.CurrentSnapshot.GetText(element.InnerRange.Start, element.InnerRange.Length);

                string reference = GetReference(element, fileName, root);

                using (WebEssentialsPackage.UndoContext((this.DisplayText)))
                {
                    textBuffer.Replace(new Span(element.Start, element.Length), reference);
                    await FileHelpers.WriteAllTextRetry(fileName, text);

                    WebEssentialsPackage.DTE.ItemOperations.OpenFile(fileName);
                    ProjectHelpers.AddFileToActiveProject(fileName);
                }
            }
Exemple #13
0
        private async Task GenerateAsync(SpriteDocument sprite)
        {
            _dte.StatusBar.Text = "Generating sprite...";

            string imageFile;
            var    fragments = SpriteGenerator.CreateImage(sprite, out imageFile);

            ProjectHelpers.AddFileToActiveProject(sprite.FileName);
            ProjectHelpers.AddFileToProject(sprite.FileName, imageFile);

            await Export(fragments, imageFile, sprite);

            if (sprite.Optimize)
            {
                await new ImageCompressor().CompressFilesAsync(imageFile);
            }

            _dte.StatusBar.Text = "Sprite generated";
        }
Exemple #14
0
            public override void Invoke()
            {
                string value = HtmlSmartTag.Element.GetAttribute("ng-controller").Value;

                if (string.IsNullOrEmpty(value))
                {
                    value = "myController";
                }

                string folder = ProjectHelpers.GetProjectFolder(EditorExtensionsPackage.DTE.ActiveDocument.FullName);
                string file;

                using (var dialog = new SaveFileDialog())
                {
                    dialog.FileName         = value + ".js";
                    dialog.DefaultExt       = ".js";
                    dialog.Filter           = "JS files | *.js";
                    dialog.InitialDirectory = folder;

                    if (dialog.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }

                    file = dialog.FileName;
                }

                EditorExtensionsPackage.DTE.UndoContext.Open(this.DisplayText);

                string script = GetScript(value);

                File.WriteAllText(file, script);

                ProjectHelpers.AddFileToActiveProject(file);
                EditorExtensionsPackage.DTE.ItemOperations.OpenFile(file);

                EditorExtensionsPackage.DTE.UndoContext.Close();
            }
Exemple #15
0
        private async Task MakeChanges(string root, string fileName)
        {
            string text      = Element.GetText(Element.InnerRange).Trim();
            string reference = GetReference(Element, fileName, root);

            using (WebEssentialsPackage.UndoContext((this.DisplayText)))
            {
                using (ITextEdit edit = TextBuffer.CreateEdit())
                {
                    edit.Replace(new Span(Element.Start, Element.Length), reference);
                    edit.Apply();
                }

                await FileHelpers.WriteAllTextRetry(fileName, text);

                ProjectHelpers.AddFileToActiveProject(fileName);
                WebEssentialsPackage.DTE.ItemOperations.OpenFile(fileName);

                await Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => {
                    WebEssentialsPackage.ExecuteCommand("Edit.FormatDocument");
                }), DispatcherPriority.ApplicationIdle, null);
            }
        }
Exemple #16
0
        public async override void Invoke(CancellationToken cancellationToken)
        {
            string value = _ngController.Value;

            if (string.IsNullOrEmpty(value))
            {
                value = "myController";
            }

            string folder = ProjectHelpers.GetProjectFolder(WebEssentialsPackage.DTE.ActiveDocument.FullName);
            string file;

            using (var dialog = new SaveFileDialog())
            {
                dialog.FileName         = value + ".js";
                dialog.DefaultExt       = ".js";
                dialog.Filter           = "JS files | *.js";
                dialog.InitialDirectory = folder;

                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                file = dialog.FileName;
            }

            using (WebEssentialsPackage.UndoContext((this.DisplayText)))
            {
                string script = GetScript(value);
                await FileHelpers.WriteAllTextRetry(file, script);

                ProjectHelpers.AddFileToActiveProject(file);
                WebEssentialsPackage.DTE.ItemOperations.OpenFile(file);
            }
        }
Exemple #17
0
        private async Task GenerateAsync(SpriteDocument sprite, bool hasUpdated = false)
        {
            _dte.StatusBar.Text = "Generating sprite...";

            if (ProjectHelpers.GetProjectItem(sprite.FileName) == null)
            {
                ProjectHelpers.AddFileToActiveProject(sprite.FileName);
            }

            string imageFile = Path.ChangeExtension(sprite.FileName, sprite.FileExtension);

            if (string.IsNullOrEmpty(sprite.OutputDirectory))
            {
                imageFile = ProjectHelpers.GetAbsolutePathFromSettings(sprite.OutputDirectory, Path.ChangeExtension(sprite.FileName, sprite.FileExtension));
            }

            ProjectHelpers.CreateDirectoryInProject(imageFile);

            IEnumerable <SpriteFragment> fragments = await SpriteGenerator.MakeImage(sprite, imageFile, UpdateSpriteAsync);

            ProjectHelpers.AddFileToProject(sprite.FileName, imageFile);

            if (!hasUpdated)
            {
                WebEssentialsPackage.DTE.ItemOperations.OpenFile(sprite.FileName);
            }

            await Export(fragments, imageFile, sprite);

            if (sprite.Optimize)
            {
                await new ImageCompressor().CompressFilesAsync(imageFile);
            }

            _dte.StatusBar.Text = "Sprite generated";
        }