Skip to content

Commit

Permalink
Merge branch 'Multityping-fixednow' into Development
Browse files Browse the repository at this point in the history
  • Loading branch information
LarsHoendervangers committed Oct 30, 2021
2 parents f894b07 + c20f31f commit 80771b2
Show file tree
Hide file tree
Showing 18 changed files with 353 additions and 273 deletions.
7 changes: 6 additions & 1 deletion JSharp-IDE/JSharp-IDE/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
xmlns:local="clr-namespace:JSharp_IDE"
StartupUri="MainWindow.xaml">
<Application.Resources>

<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/ToastNotifications.Messages;component/Themes/Default.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

</Application.Resources>
</Application>
5 changes: 2 additions & 3 deletions JSharp-IDE/JSharp-IDE/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public Compiler(string compilerPath, MainWindowViewModel mwvm)
/// <param name="pathRes">Resources directory</param>
public void Compile(string pathOut, string pathSrc, string pathLib, string pathRes)
{
new Thread(() =>
{

using (var compileTask = new Process())
{
//Checks
Expand Down Expand Up @@ -116,7 +115,7 @@ string fileFinderCompiler(string pathFiles)
compileTask.WaitForExit();
compileTask.Close();
}
}).Start();

}

/// <summary>
Expand Down
20 changes: 0 additions & 20 deletions JSharp-IDE/JSharp-IDE/ErrorWindow.xaml

This file was deleted.

37 changes: 0 additions & 37 deletions JSharp-IDE/JSharp-IDE/ErrorWindow.xaml.cs

This file was deleted.

1 change: 1 addition & 0 deletions JSharp-IDE/JSharp-IDE/JSharp-IDE.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Ookii.Dialogs.Wpf" Version="4.0.0" />
<PackageReference Include="ToastNotifications.Messages" Version="2.5.1" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion JSharp-IDE/JSharp-IDE/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

<view:ProjectHierarchyView Width="Auto" Grid.Column="0" Grid.Row="2" Grid.RowSpan="2"/>

<TabControl Grid.Row="2" Grid.Column="2" Width="Auto" Name="TabControl"/>
<TabControl Grid.Row="2" Grid.Column="2" Width="Auto" Name="TabControl" />

<GridSplitter Grid.Column="0" Width="5" HorizontalAlignment="Right" Grid.RowSpan="1" Grid.Row="2" IsTabStop="False"/>

Expand Down
2 changes: 2 additions & 0 deletions JSharp-IDE/JSharp-IDE/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,7 @@ public void Stop(object sender, CancelEventArgs e)
}*/
Environment.Exit(Environment.ExitCode);
}


}
}
18 changes: 15 additions & 3 deletions JSharp-IDE/JSharp-IDE/Network/Connection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using JSharp_Shared;
using JSharp_IDE.View;
using JSharp_Shared;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
Expand All @@ -15,6 +15,7 @@
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using ToastNotifications.Messages;

namespace JSharp_IDE.Network
{
Expand Down Expand Up @@ -148,7 +149,6 @@ public static Connection GetConnection(string ip, int port)
/// <param name="json">The json with a command in it.</param>
private void Command(JObject json)
{
Debug.WriteLine(json.ToString());
JToken token;
if (json.TryGetValue("instruction", out token))
{
Expand Down Expand Up @@ -177,6 +177,7 @@ private void Command(JObject json)
private void Ok(JObject json)
{
//Deques it because it is ok
if (this.feedbackQueu.Count > 0)
this.feedbackQueu.Dequeue();
Debug.WriteLine("Action successfull");
}
Expand All @@ -189,7 +190,8 @@ private void Ok(JObject json)
private void Failed(JObject json)
{
//Show the dequed message because an error
MessageBox.Show(this.feedbackQueu.Dequeue(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
if (this.feedbackQueu.Count > 0)
MessageBox.Show(this.feedbackQueu.Dequeue(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
Debug.WriteLine("Action failed");
}

Expand All @@ -207,8 +209,13 @@ private void RequestedProject(JObject json)
{
Project.UpdateFile(file.SelectToken("filePath").ToString(), file.SelectToken("data").ToString());
}

Project.UpdateTreeView(Project.ProjectDirectory);
Debug.WriteLine("Updated file(s)");
Debug.WriteLine("Received all project data");


Application.Current.Dispatcher.Invoke(() => Project.notifier.ShowInformation("Project is now downloaded and ready for edit."));
}

/// <summary>
Expand All @@ -223,6 +230,7 @@ private void UpdatedProject(JObject json)
if (json.SelectToken("data.flag").ToString() == "0")
{
//Remove files


} else
{
Expand All @@ -233,6 +241,10 @@ private void UpdatedProject(JObject json)
}
}
Debug.WriteLine("Updated file(s)");
MainWindow.CodePanels.Dispatcher.Invoke(() =>
{
MainWindow.CodePanels.UpdateLayout();
});
}

/// <summary>
Expand Down
103 changes: 83 additions & 20 deletions JSharp-IDE/JSharp-IDE/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,31 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using ToastNotifications;
using ToastNotifications.Lifetime;
using ToastNotifications.Messages;
using ToastNotifications.Position;

namespace JSharp_IDE
{
public class Project
{
public static string ProjectDirectory { get; set; }
public static string ProjectName { get; set; }
public static Notifier notifier = new Notifier(cfg =>
{
cfg.PositionProvider = new WindowPositionProvider(
parentWindow: Application.Current.MainWindow,
corner: Corner.BottomRight,
offsetX: 10,
offsetY: 10);

cfg.LifetimeSupervisor = new TimeAndCountBasedLifetimeSupervisor(
notificationLifetime: TimeSpan.FromSeconds(7),
maximumNotificationCount: MaximumNotificationCount.FromCount(5));

cfg.Dispatcher = Application.Current.Dispatcher;
});

/// <summary>
/// Creates a new project with the correct file structure.
Expand Down Expand Up @@ -47,13 +65,13 @@ public static void CreateNewProject()
public static void SignInToProject()
{
string path = OpenFolderDialog();
ProjectDirectory = path;
if (path != null)
{
Directory.CreateDirectory(Path.Combine(path, "src"));
Directory.CreateDirectory(Path.Combine(path, "out"));
Directory.CreateDirectory(Path.Combine(path, "lib"));
Directory.CreateDirectory(Path.Combine(path, "res"));
UpdateTreeView(path);
}
}

Expand Down Expand Up @@ -261,28 +279,67 @@ public static void UpdateFile(string path, string data)
{
try
{
//Update file on disk
Debug.WriteLine($"Full path: {Path.Combine(ProjectDirectory, path)}\n" +
$"Updating file {path}: {data}");
//Check if the folder structure exists.
new FileInfo(Path.Combine(ProjectDirectory, path)).Directory.Create();
//Combine the path with the computers folder path to get the exact location.
File.WriteAllBytes(Path.Combine(ProjectDirectory, path), Convert.FromBase64String(data));
//Update file in editor


foreach (TabItem item in MainWindow.CodePanels.Items)
{
if (item.Tag.ToString() == path)
MainWindow.CodePanels.Dispatcher.Invoke(() =>
{
RichTextBoxView box = item.Content as RichTextBoxView;
box.Dispatcher.Invoke(() =>
if (item.Tag.ToString() == path)
{
box.Update(path);
});
//Check syntax on the whole document.
Task.Run(async () => await TextFormatter.OnTextPasted(box.RichTextBox));
break;
}
RichTextBox box = item.Content as RichTextBox;
MainWindow.CodePanels.Items.Dispatcher.Invoke(() =>
{

//Disabling input if there are changes
if (RichTextBoxViewModel.Enabled)
{
RichTextBoxViewModel.Enabled = false;
RichTextBoxView.FileUpdateTimer.Start();
notifier.ShowInformation("The project is locked.");
} else
{
//Extending input disabled timer so there ar no conflicts
RichTextBoxView.FileUpdateTimer.Stop();
RichTextBoxView.FileUpdateTimer.Start();
}

//Updating textview.
FlowDocument doc = box.Document;
doc.Blocks.Clear();
int count = 0;

//Add each line to the document as a separate block.
foreach (string line in File.ReadAllLines(Path.Combine(ProjectDirectory, path)))
{
Paragraph p = new Paragraph();
p.Inlines.Add(new Run(line));
p.Margin = new Thickness(0);
doc.Blocks.Add(p);
count++;
}


});


}



});




}


} catch (Exception e)
{
Debug.WriteLine($"File update failed: {e.Message}");
Expand Down Expand Up @@ -313,14 +370,20 @@ public static void SendFileToServer()
localPath = (MainWindow.CodePanels.SelectedItem as TabItem).Tag.ToString();
}
});
Debug.WriteLine("Updating file " + localPath);
localPath = GetLocalPath(localPath);
Debug.WriteLine("Localpath: " + localPath);
MainWindowViewModel.SaveAllOpenedFiles();
Connection c = Connection.Instance;
if (c != null && localPath != null)

if (localPath != null)
{
c.SendCommand(JSONCommand.UpdateFiles(new NetworkFile[] { new NetworkFile(localPath, File.ReadAllBytes(Path.Combine(ProjectDirectory, localPath))) }, 1));
Debug.WriteLine("Updating file " + localPath);
localPath = GetLocalPath(localPath);
Debug.WriteLine("Localpath: " + localPath);
MainWindowViewModel.SaveAllOpenedFiles();
Connection c = Connection.Instance;
if (c != null && localPath != null)
{
c.SendCommand(JSONCommand.UpdateFiles(new NetworkFile[] { new NetworkFile(localPath, File.ReadAllBytes(Path.Combine(ProjectDirectory, localPath))) }, 1));


}
}
}

Expand Down
11 changes: 5 additions & 6 deletions JSharp-IDE/JSharp-IDE/TextFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Documents;
Expand All @@ -18,7 +19,7 @@ class TextFormatter
// Keywords
// The color determines which color the regex matches get.
private static SolidColorBrush keyWordColor = Brushes.Orange;
private static string keywords = @"(\b(public|private|class|void|import|protected|static|final|enum|synchronized|super|this|boolean|while|for|;|true|false|case|break|if|switch|else|int|new|return|try|catch|finally|implements|extends)\b\s*)";
private static string keywords = @"(\b(public|private|class|void|import|protected|static|final|enum|synchronized|super|this|boolean|while|for|;|true|false|case|break|if|switch|else|int|new|return|try|catch|finally|implements|extends|package)\b\s*)";
private static string symbols = @"(;|,)";

// Annotations
Expand Down Expand Up @@ -57,11 +58,9 @@ await Task.Run(() =>
return 1;
}

/// <summary>
/// Checks the whole file for regex
/// </summary>
/// <param name="rtb"></param>
/// <returns>1 when finished</returns>



public static async Task<int> OnTextPasted(RichTextBox rtb)
{
await Task.Run(() =>
Expand Down
Loading

0 comments on commit 80771b2

Please sign in to comment.