-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from aglasencnik/dev
Implemented graph export functionality
- Loading branch information
Showing
157 changed files
with
1,753 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,7 +78,6 @@ StyleCopReport.xml | |
*.obj | ||
*.iobj | ||
*.pch | ||
*.pdb | ||
*.ipdb | ||
*.pgc | ||
*.pgd | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using Microsoft.VisualStudio.Commanding; | ||
using Microsoft.VisualStudio.Text.Editor; | ||
using Microsoft.VisualStudio.Utilities; | ||
using System.ComponentModel.Composition; | ||
using System.IO; | ||
using Microsoft.VisualStudio.Text; | ||
using Microsoft.VisualStudio.Text.Editor.Commanding.Commands; | ||
|
||
namespace GraphvizVS.CommandHandlers; | ||
|
||
/// <summary> | ||
/// Represents the command handler for char commands. | ||
/// </summary> | ||
[Export(typeof(ICommandHandler))] | ||
[Name(nameof(TypeCharCommandHandler))] | ||
[ContentType(ContentTypes.Text)] | ||
[TextViewRole(PredefinedTextViewRoles.PrimaryDocument)] | ||
internal sealed class TypeCharCommandHandler : ICommandHandler<TypeCharCommandArgs> | ||
{ | ||
/// <summary> | ||
/// Gets the display name of the command handler. | ||
/// </summary> | ||
public string DisplayName => Vsix.Name; | ||
|
||
/// <summary> | ||
/// Executes command handler. | ||
/// </summary> | ||
/// <param name="args">TypeCharCommandArgs object</param> | ||
/// <param name="executionContext">CommandExecutionContext object</param> | ||
/// <returns>Whether key was overriden successfully.</returns> | ||
public bool ExecuteCommand(TypeCharCommandArgs args, CommandExecutionContext executionContext) | ||
{ | ||
var typedChar = args.TypedChar; | ||
var fileExtension = Path.GetExtension(args.SubjectBuffer.GetFileName() ?? ""); | ||
if (!string.IsNullOrWhiteSpace(fileExtension) && (fileExtension == ".dot" || fileExtension == ".DOT") && (typedChar == '/' || typedChar == '-')) | ||
{ | ||
args.TextView.TextBuffer.Insert(args.TextView.Caret.Position.BufferPosition, typedChar == '/' ? "//" : "->"); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/// <summary> | ||
/// Determines whether command handler is enabled. | ||
/// </summary> | ||
/// <param name="args">TypeCharCommandArgs object</param> | ||
/// <returns>CommandState object</returns> | ||
public CommandState GetCommandState(TypeCharCommandArgs args) => CommandState.Available; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using CliWrap; | ||
using GraphvizVS.Helpers; | ||
using GraphvizVS.Options; | ||
using Microsoft.VisualStudio.Imaging; | ||
using Microsoft.VisualStudio.Text; | ||
using Microsoft.Win32; | ||
|
||
namespace GraphvizVS.Commands; | ||
|
||
/// <summary> | ||
/// Represents the command to export the graph to a file. | ||
/// </summary> | ||
[Command(PackageIds.ExportGraphCommand)] | ||
internal sealed class ExportGraphCommand : BaseCommand<ExportGraphCommand> | ||
{ | ||
/// <summary> | ||
/// Executes the command. | ||
/// </summary> | ||
/// <param name="e">OleMenuCmdEventArgs object.</param> | ||
/// <returns>A task that represents the asynchronous operation.</returns> | ||
protected override async Task ExecuteAsync(OleMenuCmdEventArgs e) | ||
{ | ||
var docView = await VS.Documents.GetActiveDocumentViewAsync(); | ||
if (docView?.TextView is null) | ||
return; | ||
|
||
try | ||
{ | ||
var activeDocumentPath = DocumentHelper.GetActiveDocumentPath(); | ||
var activeDocumentExtension = Path.GetExtension(activeDocumentPath); | ||
if (string.IsNullOrWhiteSpace(activeDocumentExtension) || activeDocumentExtension.ToLower() != ".dot") | ||
return; | ||
|
||
var saveFileDialog = new SaveFileDialog | ||
{ | ||
Title = "Select graph save location", | ||
Filter = OutputFormatHelper.GetFilter() | ||
}; | ||
|
||
var dialogResult = saveFileDialog.ShowDialog(); | ||
if (dialogResult is null || !dialogResult.Value || string.IsNullOrWhiteSpace(saveFileDialog.FileName)) | ||
return; | ||
|
||
var fileName = saveFileDialog.FileName; | ||
if (string.IsNullOrWhiteSpace(fileName)) | ||
return; | ||
|
||
var flags = new List<string>(); | ||
|
||
if (!string.IsNullOrWhiteSpace(GeneralOptions.Instance.AdditionalFlags)) | ||
flags.Add(GeneralOptions.Instance.AdditionalFlags); | ||
|
||
flags.Add(OutputFormatHelper.GetOutputFormatArgument()); | ||
flags.Add(activeDocumentPath); | ||
flags.AddRange(["-o", fileName]); | ||
|
||
var result = await Cli.Wrap(CommandLineHelper.GetEnginePath()) | ||
.WithArguments(flags) | ||
.ExecuteAsync(); | ||
|
||
if (result.IsSuccess) | ||
await VS.MessageBox.ShowAsync("Graph export was successful!"); | ||
else | ||
await VS.MessageBox.ShowErrorAsync("Graph export has failed!"); | ||
} | ||
catch (Exception ex) | ||
{ | ||
var infoBar = await docView.TextView.CreateInfoBarAsync( | ||
new InfoBarModel([new InfoBarTextSpan("Something went wrong while exporting graph!")], KnownMonikers.DiagramError) | ||
); | ||
|
||
if (infoBar != null) | ||
await infoBar.TryShowInfoBarUIAsync(); | ||
|
||
await ex.LogAsync(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Executes after the initialization of the command. | ||
/// </summary> | ||
/// <returns>A task that represents the asynchronous operation.</returns> | ||
protected override Task InitializeCompletedAsync() | ||
{ | ||
Command.Supported = false; | ||
return base.InitializeCompletedAsync(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using GraphvizVS.ToolWindows; | ||
|
||
namespace GraphvizVS.Commands; | ||
|
||
/// <summary> | ||
/// Represents the command to open the graph preview window. | ||
/// </summary> | ||
[Command(PackageIds.OpenGraphPreviewWindowCommand)] | ||
internal sealed class OpenGraphPreviewWindowCommand : BaseCommand<OpenGraphPreviewWindowCommand> | ||
{ | ||
/// <summary> | ||
/// Executes the command. | ||
/// </summary> | ||
/// <param name="e">OleMenuCmdEventArgs object.</param> | ||
/// <returns>A task that represents the asynchronous operation.</returns> | ||
protected override async Task ExecuteAsync(OleMenuCmdEventArgs e) | ||
{ | ||
await GraphPreviewWindow.ShowAsync(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
namespace GraphvizVS.Enums; | ||
|
||
/// <summary> | ||
/// Represents the layout engine. | ||
/// </summary> | ||
public enum LayoutEngine | ||
{ | ||
Dot, | ||
Neato, | ||
Fdp, | ||
Sfdp, | ||
Circo, | ||
Twopi, | ||
Nop, | ||
Nop2, | ||
Osage, | ||
Patchwork, | ||
Custom | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
namespace GraphvizVS.Enums; | ||
|
||
/// <summary> | ||
/// Represents the output format. | ||
/// </summary> | ||
public enum OutputFormat | ||
{ | ||
BMP, | ||
CGIMAGE, | ||
CANON, | ||
DOT, | ||
GV, | ||
XDOT, | ||
XDOT12, | ||
XDOT14, | ||
EPS, | ||
EXR, | ||
FIG, | ||
GD, | ||
GD2, | ||
GIF, | ||
GTK, | ||
ICO, | ||
IMAP, | ||
IMAP_NP, | ||
ISMAP, | ||
CMAP, | ||
CMAPX, | ||
CMAPX_NP, | ||
JPG, | ||
JPEG, | ||
JPE, | ||
JP2, | ||
JSON, | ||
JSON0, | ||
DOT_JSON, | ||
XDOT_JSON, | ||
PDF, | ||
PIC, | ||
PCT, | ||
PICT, | ||
PLAIN, | ||
PLAIN_EXT, | ||
PNG, | ||
POV, | ||
PS, | ||
PS2, | ||
PSD, | ||
SGI, | ||
SVG, | ||
SVGZ, | ||
TGA, | ||
TIF, | ||
TIFF, | ||
TK, | ||
VML, | ||
VMLZ, | ||
VRML, | ||
WBMP, | ||
WEBP, | ||
XLIB, | ||
X11 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace GraphvizVS.Enums; | ||
|
||
/// <summary> | ||
/// Represents the type of the runtime. | ||
/// </summary> | ||
public enum RuntimeType | ||
{ | ||
Ebedded, | ||
Local, | ||
Custom | ||
} |
Binary file not shown.
Oops, something went wrong.