-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c7f1242
Showing
53 changed files
with
8,145 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
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,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 14 | ||
VisualStudioVersion = 14.0.25123.0 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Draft", "Draft\Draft.csproj", "{B75A5943-2A5F-4B81-BA5D-D3FAF5DFF6B3}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{B75A5943-2A5F-4B81-BA5D-D3FAF5DFF6B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{B75A5943-2A5F-4B81-BA5D-D3FAF5DFF6B3}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{B75A5943-2A5F-4B81-BA5D-D3FAF5DFF6B3}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{B75A5943-2A5F-4B81-BA5D-D3FAF5DFF6B3}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
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,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> | ||
</startup> | ||
</configuration> |
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,212 @@ | ||
using FastColoredTextBoxNS; | ||
using MaterialSkin.Controls; | ||
using System; | ||
using System.IO; | ||
using System.Windows.Forms; | ||
|
||
namespace Draft | ||
{ | ||
public class CodeFile | ||
{ | ||
private IDEBox editor; | ||
private MaterialFlatButton button; | ||
public string realPath; | ||
public string virtualPath; | ||
public bool isSaved; | ||
public bool isModified = false; | ||
|
||
public CodeFile() | ||
{ | ||
this.virtualPath = Randomizer.aRandomFile(this.realPath, CodeFileManager.virtualFilePrefix); | ||
this.isSaved = false; | ||
this.createOnDisk(virtualPath); | ||
} | ||
|
||
public CodeFile(string path) | ||
{ | ||
this.realPath = path; | ||
this.virtualPath = Randomizer.aRandomFile(this.realPath, CodeFileManager.virtualFilePrefix); | ||
File.WriteAllText(virtualPath, File.ReadAllText(realPath)); | ||
this.isSaved = true; | ||
} | ||
|
||
public CodeFile(string[] param) | ||
{ | ||
this.realPath = param[0]; | ||
this.virtualPath = param[1]; | ||
this.isSaved = bool.Parse(param[2]); | ||
this.isModified = bool.Parse(param[3]); | ||
} | ||
|
||
public string getExtension() | ||
{ | ||
return new FileInfo(virtualPath).Extension; | ||
} | ||
|
||
public void bindToView() | ||
{ | ||
editor = new IDEBox(); | ||
switch (getExtension()) | ||
{ | ||
case ".c": | ||
case ".cpp": | ||
case ".cs": | ||
editor.Language = Language.CSharp; | ||
break; | ||
case ".html": | ||
editor.Language = Language.HTML; | ||
break; | ||
case ".js": | ||
editor.Language = Language.JS; | ||
break; | ||
case ".xml": | ||
editor.Language = Language.XML; | ||
break; | ||
case ".php": | ||
editor.Language = Language.PHP; | ||
break; | ||
case ".sql": | ||
editor.Language = Language.SQL; | ||
break; | ||
default: | ||
editor.Language = Language.Custom; | ||
break; | ||
} | ||
editor.Text = File.ReadAllText(virtualPath); | ||
editor.KeyDown += Editor_KeyDown; | ||
editor.TextChanged += Editor_TextChanged; | ||
MainForm.activeForm.idePanel.Controls.Add(editor); | ||
button = new MaterialFlatButton(); | ||
button.MouseUp += Button_MouseUp; | ||
MainForm.activeForm.leftPanel.Controls.Add(button); | ||
updateView(); | ||
} | ||
|
||
public void dropFromView() | ||
{ | ||
MainForm.activeForm.leftPanel.Controls.Remove(this.button); | ||
MainForm.activeForm.idePanel.Controls.Remove(this.editor); | ||
} | ||
|
||
public void updateView() | ||
{ | ||
string s = ""; | ||
if (isSaved) | ||
{ | ||
s += Path.GetFileName(realPath); | ||
if (isModified) s += "*"; | ||
} | ||
else s += "{DRAFT}"; | ||
button.Text = s; | ||
MainForm.activeForm.title.Text = s; | ||
} | ||
|
||
public void focus() | ||
{ | ||
this.editor.Focus(); | ||
} | ||
|
||
private void Editor_TextChanged(object sender, TextChangedEventArgs e) | ||
{ | ||
if (!isModified) | ||
{ | ||
modify(); | ||
} | ||
} | ||
|
||
private void Editor_KeyDown(object sender, KeyEventArgs e) | ||
{ | ||
if (e.Control) | ||
{ | ||
if (e.KeyCode == Keys.Enter) | ||
{ | ||
MainForm.activeForm.commandBar.textField.Focus(); | ||
} | ||
if (e.KeyCode == Keys.S) | ||
{ | ||
this.save(); | ||
} | ||
if (e.KeyCode == Keys.O) | ||
{ | ||
MainForm.fileManager.loadFile(); | ||
} | ||
else if (e.KeyCode == Keys.ControlKey) | ||
{ | ||
// only Ctrl here | ||
} | ||
} | ||
else if (e.KeyCode == Keys.Enter) | ||
{ | ||
synchronize(); | ||
} | ||
} | ||
|
||
void Button_MouseUp(object sender, MouseEventArgs e) | ||
{ | ||
if (e.Button == MouseButtons.Left) | ||
{ | ||
MainForm.fileManager.changeFile(this); | ||
} | ||
else if (e.Button == MouseButtons.Right) | ||
{ | ||
MainForm.fileManager.removeFile(this); | ||
} | ||
} | ||
|
||
public void createOnDisk(string filename) | ||
{ | ||
if (!Directory.Exists(Path.GetDirectoryName(filename))) | ||
{ | ||
Directory.CreateDirectory(Path.GetDirectoryName(filename)); | ||
} | ||
FileStream fs = File.Create(filename); | ||
fs.Close(); | ||
} | ||
|
||
public void browse() | ||
{ | ||
editor.BringToFront(); | ||
updateView(); | ||
} | ||
|
||
public void save() | ||
{ | ||
if (isSaved) | ||
{ | ||
File.WriteAllText(this.realPath, editor.Text); | ||
synchronize(); | ||
isModified = false; | ||
updateView(); | ||
} | ||
else | ||
{ | ||
SaveFileDialog sfd = new SaveFileDialog(); | ||
sfd.Title = "Save file to"; | ||
if (sfd.ShowDialog() == DialogResult.OK) | ||
{ | ||
realPath = sfd.FileName; | ||
isSaved = true; | ||
save(); | ||
} | ||
else return; | ||
} | ||
} | ||
|
||
public void synchronize() | ||
{ | ||
File.WriteAllText(this.virtualPath, editor.Text); | ||
updateView(); | ||
} | ||
|
||
public void modify() | ||
{ | ||
isModified = true; | ||
updateView(); | ||
} | ||
|
||
public string ToString() | ||
{ | ||
return realPath + "|" + virtualPath + "|" + isSaved + "|" + isModified; | ||
} | ||
} | ||
} |
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,151 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.Serialization; | ||
using System.Runtime.Serialization.Formatters.Binary; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
using System.Xml; | ||
|
||
namespace Draft | ||
{ | ||
public class CodeFileManager | ||
{ | ||
public static string managerFile = "manager"; | ||
public static string virtualFilePrefix = Path.GetTempPath() + "void\\"; | ||
public CodeFile currentFile; | ||
public List<CodeFile> openedFiles; | ||
|
||
public void updateView() | ||
{ | ||
foreach (var file in openedFiles) | ||
{ | ||
try | ||
{ | ||
file.bindToView(); | ||
} | ||
catch (Exception) | ||
{ | ||
openedFiles.Remove(file); | ||
} | ||
} | ||
currentFile.browse(); | ||
} | ||
|
||
public void newFile() | ||
{ | ||
CodeFile file = new CodeFile(); | ||
file.bindToView(); | ||
openedFiles.Add(file); | ||
changeFile(file); | ||
export(); | ||
} | ||
|
||
public void loadFile() | ||
{ | ||
OpenFileDialog ofd = new OpenFileDialog(); | ||
ofd.Title = "Open file"; | ||
ofd.Multiselect = true; | ||
if (ofd.ShowDialog() == DialogResult.OK) | ||
{ | ||
foreach (var file in ofd.FileNames) | ||
{ | ||
loadFile(file); | ||
} | ||
} | ||
} | ||
|
||
public void loadFile(string filename) | ||
{ | ||
foreach (var f in openedFiles) | ||
{ | ||
if (f.realPath == filename) | ||
{ | ||
f.browse(); | ||
return; | ||
} | ||
} | ||
CodeFile file = new CodeFile(filename); | ||
file.bindToView(); | ||
openedFiles.Add(file); | ||
changeFile(file); | ||
export(); | ||
} | ||
|
||
public void saveFile() | ||
{ | ||
currentFile.save(); | ||
export(); | ||
} | ||
|
||
public void synchronizeAll() | ||
{ | ||
foreach (var file in openedFiles) | ||
{ | ||
file.synchronize(); | ||
} | ||
} | ||
|
||
public void changeFile(CodeFile file) | ||
{ | ||
this.currentFile = file; | ||
file.browse(); | ||
file.focus(); | ||
export(); | ||
} | ||
|
||
public void removeFile(CodeFile file) | ||
{ | ||
if (openedFiles.Count == 1) newFile(); | ||
file.dropFromView(); | ||
openedFiles.Remove(file); | ||
if (!openedFiles.Contains(currentFile)) changeFile(openedFiles[0]); | ||
export(); | ||
} | ||
|
||
public void import() | ||
{ | ||
this.openedFiles = new List<CodeFile>(); | ||
if (!File.Exists(managerFile)) | ||
{ | ||
File.Create(managerFile).Close(); | ||
newFile(); | ||
} | ||
else | ||
{ | ||
try | ||
{ | ||
string[] lines = File.ReadAllLines(managerFile); | ||
for (int i = lines.Length-1; i > 0; i--) | ||
{ | ||
string[] ss = lines[i].Split('|'); | ||
if (!File.Exists(ss[0]) && ss[2] == "True") continue; | ||
this.openedFiles.Insert(0, new CodeFile(ss)); | ||
} | ||
int d = int.Parse(lines[0]); | ||
if (d >= openedFiles.Count) d = 0; | ||
this.currentFile = this.openedFiles[d]; | ||
updateView(); | ||
} | ||
catch (Exception) | ||
{ | ||
File.Delete(managerFile); | ||
import(); | ||
} | ||
} | ||
} | ||
|
||
public void export() | ||
{ | ||
List<string> lines = new List<string>(); | ||
lines.Add(this.openedFiles.IndexOf(this.currentFile) + ""); | ||
foreach (var file in openedFiles) | ||
{ | ||
lines.Add(file.ToString()); | ||
} | ||
File.WriteAllLines(managerFile, lines); | ||
} | ||
} | ||
} |
Oops, something went wrong.