Skip to content

Commit

Permalink
Studio: Added Copy Project Url and Project Id to Tools Menu
Browse files Browse the repository at this point in the history
  • Loading branch information
NizamLZ committed Aug 28, 2017
1 parent 90cbc27 commit cdb3093
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 13 deletions.
26 changes: 26 additions & 0 deletions ANAConversationStudio/Helpers/StudioContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,32 @@ private async Task<T> HitPost<T, TReq>(string api, TReq requestData, bool strict
return respParsed;
}
}

public static bool IsProjectLoaded(bool showMsg)
{
if (Current?.ChatServer?.ServerUrl == null)
{
if (showMsg)
MessageBox.Show("No chat flow is loaded. Please load a chat flow and try again.");
return false;
}
return true;
}

public static string CurrentProjectUrl()
{
return Current?.ChatServer?.ServerUrl + "/api/Conversation/chat?projectId=" + CurrentProjectId();
}

public static string CurrentProjectId()
{
return Current?.ChatFlow?.ProjectId;
}

public static ANAProject CurrentProject()
{
return Current?.ChatFlowProjects?.FirstOrDefault(x => x._id == Current?.ChatFlow?.ProjectId);
}
}

public class APIResponse
Expand Down
3 changes: 2 additions & 1 deletion ANAConversationStudio/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,8 @@
<MenuItem Header="Tools" Height="30">
<MenuItem Header="Launch Simulator" Click="ConvSimMenuClick"/>
<MenuItem Header="Launch Current Chat in Simulator (F5)" Click="ConvSimWithChatMenuClick"/>

<MenuItem Header="Copy Chat URL" Click="CopyChatURLClick"/>
<MenuItem Header="Copy Project Id" Click="CopyProjectIdClick"/>
</MenuItem>
<MenuItem Header="Help" Name="HelpMenu" Height="30">
<MenuItem Header="No Update Available!" Click="UpdateMenuClick" IsEnabled="False" Name="UpdateMenuItem"/>
Expand Down
29 changes: 17 additions & 12 deletions ANAConversationStudio/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,8 @@ private void ConvSimWithChatMenuClick(object sender, RoutedEventArgs e)

private void StartChatInSimulator()
{
if (StudioContext.Current?.ChatServer?.ServerUrl == null)
{
System.Windows.MessageBox.Show("No project is loaded at the moment");
return;
}
Process.Start("anaconsim://app?chatflow=" + Uri.EscapeDataString(StudioContext.Current.ChatServer.ServerUrl + "/api/Conversation/chat?projectId=" + StudioContext.Current.ChatFlow.ProjectId));
if (StudioContext.IsProjectLoaded(true))
Process.Start("anaconsim://app?chatflow=" + Uri.EscapeDataString(StudioContext.CurrentProjectUrl()));
}

private void StartInSimulator_Executed(object sender, ExecutedRoutedEventArgs e)
Expand All @@ -332,13 +328,10 @@ public void ExportUIElementAsImage(UIElement element, Rect cropRect)
//Add some margin to the image
cropRect.Inflate(cropRect.Width / 40, cropRect.Height / 40);

var currentProj = StudioContext.Current?.ChatFlowProjects?.FirstOrDefault(x => x._id == StudioContext.Current?.ChatFlow?.ProjectId);

if (currentProj == null)
{
MessageBox.Show("No chat flow is loaded. Please load a chat flow and try again.");
if (!StudioContext.IsProjectLoaded(true))
return;
}

var currentProj = StudioContext.CurrentProject();

var resolution = 200;
var scale = resolution / 96d;
Expand Down Expand Up @@ -383,6 +376,18 @@ static System.Drawing.Bitmap CropImage(System.Drawing.Image originalImage, Syste
}
return croppedImage;
}

private void CopyProjectIdClick(object sender, RoutedEventArgs e)
{
if (StudioContext.IsProjectLoaded(true))
Clipboard.SetText(StudioContext.CurrentProjectId());
}

private void CopyChatURLClick(object sender, RoutedEventArgs e)
{
if (StudioContext.IsProjectLoaded(true))
Clipboard.SetText(StudioContext.CurrentProjectUrl());
}
}

/// <summary>
Expand Down

0 comments on commit cdb3093

Please sign in to comment.