From 38aee32ca946f51db4ab34c5eac0944824dd8a9c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Thu, 2 Mar 2017 05:17:43 +0100 Subject: [PATCH 1/1] first commit --- .gitignore | 41 ++++++ CrowEdit.cs | 228 +++++++++++++++++++++++++++++++++ CrowEdit.csproj | 102 +++++++++++++++ CrowEdit.sln | 17 +++ LICENSE.md | 21 +++ README.md | 1 + packages.config | 5 + ui/MenuItem.template | 25 ++++ ui/icons/basic_floppydisk.svg | 15 +++ ui/icons/blank-file.svg | 6 + ui/icons/center-align.svg | 9 ++ ui/icons/cogwheel.svg | 7 + ui/icons/copy-file.svg | 6 + ui/icons/edit.svg | 6 + ui/icons/file-code.svg | 9 ++ ui/icons/folder.svg | 6 + ui/icons/font-file.svg | 7 + ui/icons/inbox.svg | 7 + ui/icons/light-bulb.svg | 7 + ui/icons/outbox.svg | 7 + ui/icons/paragraph.svg | 6 + ui/icons/paste-on-document.svg | 6 + ui/icons/previous.svg | 6 + ui/icons/question.svg | 7 + ui/icons/reply.svg | 6 + ui/icons/scissors.svg | 6 + ui/icons/search.svg | 6 + ui/icons/share-arrow.svg | 6 + ui/icons/sign-out.svg | 7 + ui/icons/text-file.svg | 9 ++ ui/icons/text-label.svg | 7 + ui/icons/tools.svg | 8 ++ ui/icons/zoom-in.svg | 7 + ui/icons/zoom-out.svg | 7 + ui/main.crow | 43 +++++++ ui/openFile.crow | 6 + ui/saveFile.crow | 3 + 37 files changed, 678 insertions(+) create mode 100644 .gitignore create mode 100644 CrowEdit.cs create mode 100644 CrowEdit.csproj create mode 100644 CrowEdit.sln create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 packages.config create mode 100644 ui/MenuItem.template create mode 100644 ui/icons/basic_floppydisk.svg create mode 100644 ui/icons/blank-file.svg create mode 100644 ui/icons/center-align.svg create mode 100644 ui/icons/cogwheel.svg create mode 100644 ui/icons/copy-file.svg create mode 100644 ui/icons/edit.svg create mode 100644 ui/icons/file-code.svg create mode 100644 ui/icons/folder.svg create mode 100644 ui/icons/font-file.svg create mode 100644 ui/icons/inbox.svg create mode 100644 ui/icons/light-bulb.svg create mode 100644 ui/icons/outbox.svg create mode 100644 ui/icons/paragraph.svg create mode 100644 ui/icons/paste-on-document.svg create mode 100644 ui/icons/previous.svg create mode 100644 ui/icons/question.svg create mode 100644 ui/icons/reply.svg create mode 100644 ui/icons/scissors.svg create mode 100644 ui/icons/search.svg create mode 100644 ui/icons/share-arrow.svg create mode 100644 ui/icons/sign-out.svg create mode 100644 ui/icons/text-file.svg create mode 100644 ui/icons/text-label.svg create mode 100644 ui/icons/tools.svg create mode 100644 ui/icons/zoom-in.svg create mode 100644 ui/icons/zoom-out.svg create mode 100755 ui/main.crow create mode 100644 ui/openFile.crow create mode 100644 ui/saveFile.crow diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..88e1fca --- /dev/null +++ b/.gitignore @@ -0,0 +1,41 @@ +#Autosave files +*~ + +#build +build/ +[Oo]bj/ +[Bb]in/ +packages/ +TestResults/ + +# globs +Makefile.in +*.DS_Store +*.sln.cache +*.suo +*.cache +*.pidb +*.userprefs +*.usertasks +config.log +config.make +config.status +aclocal.m4 +install-sh +autom4te.cache/ +*.user +*.tar.gz +tarballs/ +test-results/ +Thumbs.db + +#Mac bundle stuff +*.dmg +*.app + +#resharper +*_Resharper.* +*.Resharper + +#dotCover +*.dotCover diff --git a/CrowEdit.cs b/CrowEdit.cs new file mode 100644 index 0000000..1e0323f --- /dev/null +++ b/CrowEdit.cs @@ -0,0 +1,228 @@ +// +// Main.cs +// +// Author: +// Jean-Philippe Bruyère +// +// Copyright (c) 2017 jp +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +using Crow; +using System.IO; +using System.Collections.Generic; + +namespace CrowEdit +{ + public class CrowEdit : CrowWindow + { + public Command CMDNew, CMDOpen, CMDSave, CMDSaveAs, CMDQuit, CMDUndo, CMDRedo, CMDCut, CMDCopy, CMDPaste, CMDHelp, CMDAbout; + + string _curDir = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments); + string _curFilePath = "unamed.txt"; + string _text = "", _origText=""; + + List undoStack = new List(); + List redoStack = new List(); + + public string Text { + get { return _text; } + set { + if (_text == value) + return; + undoStack.Add (_text); + CMDUndo.CanExecute = true; + redoStack.Clear (); + CMDRedo.CanExecute = false; + _text = value; + NotifyValueChanged ("Text", _text); + NotifyValueChanged ("IsDirty", IsDirty); + } + } + bool isDirty = false; + public bool IsDirty { get { return _text != _origText; }} + + public string CurrentDir { + get { return _curDir; } + set { + if (_curDir == value) + return; + _curDir = value; + NotifyValueChanged ("CurrentDir", _curDir); + } + } + public string CurFilePath { + get { return _curFilePath; } + set { + if (_curFilePath == value) + return; + _curFilePath = value; + NotifyValueChanged ("CurFilePath", _curFilePath); + } + } + public string CurFileFullPath { get { return Path.Combine(CurrentDir,CurFilePath); }} + + void initCommands(){ + CMDNew = new Command(new Action(() => newFile())) { Caption = "New", Icon = new SvgPicture("#CrowEdit.ui.icons.blank-file.svg")}; + CMDOpen = new Command(new Action(() => openFileDialog())) { Caption = "Open...", Icon = new SvgPicture("#CrowEdit.ui.icons.outbox.svg")}; + CMDSave = new Command(new Action(() => saveFileDialog())) { Caption = "Save", Icon = new SvgPicture("#CrowEdit.ui.icons.inbox.svg"), CanExecute = false}; + CMDSaveAs = new Command(new Action(() => saveFileDialog())) { Caption = "Save As...", Icon = new SvgPicture("#CrowEdit.ui.icons.inbox.svg"), CanExecute = false}; + CMDQuit = new Command(new Action(() => Quit (null, null))) { Caption = "Quit", Icon = new SvgPicture("#CrowEdit.ui.icons.sign-out.svg")}; + CMDUndo = new Command(new Action(() => undo())) { Caption = "Undo", Icon = new SvgPicture("#CrowEdit.ui.icons.reply.svg"), CanExecute = false}; + CMDRedo = new Command(new Action(() => redo())) { Caption = "Redo", Icon = new SvgPicture("#CrowEdit.ui.icons.share-arrow.svg"), CanExecute = false}; + CMDCut = new Command(new Action(() => Quit (null, null))) { Caption = "Cut", Icon = new SvgPicture("#CrowEdit.ui.icons.scissors.svg"), CanExecute = false}; + CMDCopy = new Command(new Action(() => Quit (null, null))) { Caption = "Copy", Icon = new SvgPicture("#CrowEdit.ui.icons.copy-file.svg"), CanExecute = false}; + CMDPaste = new Command(new Action(() => Quit (null, null))) { Caption = "Paste", Icon = new SvgPicture("#CrowEdit.ui.icons.paste-on-document.svg"), CanExecute = false}; + CMDHelp = new Command(new Action(() => System.Diagnostics.Debug.WriteLine("help"))) { Caption = "Help", Icon = new SvgPicture("#CrowEdit.ui.icons.question.svg")}; + + } + void newFile(){ + CurFilePath = "unamed.txt"; + _origText = _text = ""; + NotifyValueChanged ("Text", _text); + NotifyValueChanged ("IsDirty", false); + redoStack.Clear (); + undoStack.Clear (); + CMDRedo.CanExecute = false; + CMDUndo.CanExecute = false; + NotifyValueChanged ("CurFileFullPath", CurFileFullPath); + } + void undo(){ + string step = undoStack [undoStack.Count -1]; + redoStack.Add (_text); + CMDRedo.CanExecute = true; + undoStack.RemoveAt(undoStack.Count -1); + + _text = step; + + NotifyValueChanged ("Text", _text); + NotifyValueChanged ("IsDirty", IsDirty); + + if (undoStack.Count == 0) + CMDUndo.CanExecute = false; + } + void redo(){ + string step = redoStack [redoStack.Count -1]; + undoStack.Add (_text); + CMDUndo.CanExecute = true; + redoStack.RemoveAt(redoStack.Count -1); + _text = step; + NotifyValueChanged ("Text", _text); + NotifyValueChanged ("IsDirty", IsDirty); + + if (redoStack.Count == 0) + CMDRedo.CanExecute = false; + } + void openFileDialog(){ + Load ("#CrowEdit.ui.openFile.crow").DataSource = this; + } + void saveFileDialog(){ + Load ("#CrowEdit.ui.saveFile.crow").DataSource = this; + } + void openFileDialog_OkClicked (object sender, EventArgs e) + { + FileDialog fd = sender as FileDialog; + if (string.IsNullOrEmpty (fd.SelectedFile)) + return; + CurFilePath = fd.SelectedFile; + CurrentDir = fd.SelectedDirectory; + + using (StreamReader sr = new StreamReader (CurFileFullPath)) { + _origText = sr.ReadToEnd (); + } + _text = _origText; + + NotifyValueChanged ("Text", _text); + NotifyValueChanged ("IsDirty", false); + redoStack.Clear (); + undoStack.Clear (); + CMDRedo.CanExecute = false; + CMDUndo.CanExecute = false; + + NotifyValueChanged ("CurFileFullPath", CurFileFullPath); + } + void saveFileDialog_OkClicked (object sender, EventArgs e) + { + FileDialog fd = sender as FileDialog; + + if (!string.IsNullOrEmpty (fd.SelectedFile)) + CurFilePath = fd.SelectedFile; + CurrentDir = fd.SelectedDirectory; + + System.Diagnostics.Debug.WriteLine (CurFileFullPath); +// using (StreamWriter sr = new StreamWriter (fd.SelectedFile)) { +// sr.Write(_text); +// } + _origText = _text; + + NotifyValueChanged ("IsDirty", false); + NotifyValueChanged ("CurFileFullPath", CurFileFullPath); + } + void onTextChanged (object sender, TextChangeEventArgs e) + { + System.Diagnostics.Debug.WriteLine ("text changed"); + NotifyValueChanged ("IsDirty", IsDirty); + } + + [STAThread] + static void Main () + { + using (CrowEdit win = new CrowEdit ()) { + win.Run (30); + } + } + public CrowEdit () + : base(800, 600,"Crow Simple Editor") + {} + + protected override void OnLoad (EventArgs e) + { + base.OnLoad (e); + + this.ValueChanged += CrowEdit_ValueChanged; + initCommands (); + + Load ("#CrowEdit.ui.main.crow").DataSource = this; + NotifyValueChanged ("CurFileFullPath", CurFileFullPath); + } + + void textView_KeyDown (object sender, Crow.KeyboardKeyEventArgs e) + { + if (e.Control) { + if (e.Key == Key.W) { + if (e.Shift) + CMDRedo.Execute (); + else + CMDUndo.Execute (); + } + } + } + + void CrowEdit_ValueChanged (object sender, ValueChangeEventArgs e) + { + if (e.MemberName == "IsDirty" && isDirty != (bool)e.NewValue) { + isDirty = (bool)e.NewValue; + if (isDirty) { + CMDSave.CanExecute = true; + CMDSaveAs.CanExecute = true; + }else{ + CMDSave.CanExecute = false; + CMDSaveAs.CanExecute = false; + } + } + } + + } +} + diff --git a/CrowEdit.csproj b/CrowEdit.csproj new file mode 100644 index 0000000..4f9c898 --- /dev/null +++ b/CrowEdit.csproj @@ -0,0 +1,102 @@ + + + + Debug + AnyCPU + {AAA67D93-458E-4DD7-9CDA-4EC7F73D47FF} + Exe + CrowEdit + CrowEdit + v4.5 + CrowEdit.CrowEdit + $(SolutionDir)build/$(Configuration) + $(SolutionDir)build/obj/$(Configuration) + + + + + + + + true + full + false + prompt + 4 + false + DEBUG;TRACE + + + none + true + 0 + false + + + + + + + + + + + + + + + + + + + + + + + + + + packages\OpenTK.2.0.0\lib\net20\OpenTK.dll + + + + + + packages\Crow.OpenTK.0.5.1\lib\net45\Crow.dll + + + gtk-sharp-3.0 + + + + + + + + + + + + + + + + + + + + + Crow.MenuItem.template + + + + + + + + + + + + + \ No newline at end of file diff --git a/CrowEdit.sln b/CrowEdit.sln new file mode 100644 index 0000000..6d85afc --- /dev/null +++ b/CrowEdit.sln @@ -0,0 +1,17 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CrowEdit", "CrowEdit.csproj", "{AAA67D93-458E-4DD7-9CDA-4EC7F73D47FF}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Release|Any CPU = Release|Any CPU + Debug|Any CPU = Debug|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AAA67D93-458E-4DD7-9CDA-4EC7F73D47FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AAA67D93-458E-4DD7-9CDA-4EC7F73D47FF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AAA67D93-458E-4DD7-9CDA-4EC7F73D47FF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AAA67D93-458E-4DD7-9CDA-4EC7F73D47FF}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..63bb0bf --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) [2017] [Jean-Philippe Bruyère] + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..66a5dab --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# CrowEdit diff --git a/packages.config b/packages.config new file mode 100644 index 0000000..9875ed7 --- /dev/null +++ b/packages.config @@ -0,0 +1,5 @@ + + + + + diff --git a/ui/MenuItem.template b/ui/MenuItem.template new file mode 100644 index 0000000..5752b08 --- /dev/null +++ b/ui/MenuItem.template @@ -0,0 +1,25 @@ + + + + + + + diff --git a/ui/icons/basic_floppydisk.svg b/ui/icons/basic_floppydisk.svg new file mode 100644 index 0000000..55d901d --- /dev/null +++ b/ui/icons/basic_floppydisk.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + diff --git a/ui/icons/blank-file.svg b/ui/icons/blank-file.svg new file mode 100644 index 0000000..8136979 --- /dev/null +++ b/ui/icons/blank-file.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/ui/icons/center-align.svg b/ui/icons/center-align.svg new file mode 100644 index 0000000..92e3fac --- /dev/null +++ b/ui/icons/center-align.svg @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/ui/icons/cogwheel.svg b/ui/icons/cogwheel.svg new file mode 100644 index 0000000..c104c47 --- /dev/null +++ b/ui/icons/cogwheel.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/ui/icons/copy-file.svg b/ui/icons/copy-file.svg new file mode 100644 index 0000000..63c2dd3 --- /dev/null +++ b/ui/icons/copy-file.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/ui/icons/edit.svg b/ui/icons/edit.svg new file mode 100644 index 0000000..73569d8 --- /dev/null +++ b/ui/icons/edit.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/ui/icons/file-code.svg b/ui/icons/file-code.svg new file mode 100644 index 0000000..2dc00db --- /dev/null +++ b/ui/icons/file-code.svg @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/ui/icons/folder.svg b/ui/icons/folder.svg new file mode 100644 index 0000000..ee1f82b --- /dev/null +++ b/ui/icons/folder.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/ui/icons/font-file.svg b/ui/icons/font-file.svg new file mode 100644 index 0000000..20beac1 --- /dev/null +++ b/ui/icons/font-file.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/ui/icons/inbox.svg b/ui/icons/inbox.svg new file mode 100644 index 0000000..6aa6714 --- /dev/null +++ b/ui/icons/inbox.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/ui/icons/light-bulb.svg b/ui/icons/light-bulb.svg new file mode 100644 index 0000000..4193a75 --- /dev/null +++ b/ui/icons/light-bulb.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/ui/icons/outbox.svg b/ui/icons/outbox.svg new file mode 100644 index 0000000..bd8d7d9 --- /dev/null +++ b/ui/icons/outbox.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/ui/icons/paragraph.svg b/ui/icons/paragraph.svg new file mode 100644 index 0000000..826aa63 --- /dev/null +++ b/ui/icons/paragraph.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/ui/icons/paste-on-document.svg b/ui/icons/paste-on-document.svg new file mode 100644 index 0000000..b0a705e --- /dev/null +++ b/ui/icons/paste-on-document.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/ui/icons/previous.svg b/ui/icons/previous.svg new file mode 100644 index 0000000..566c8a3 --- /dev/null +++ b/ui/icons/previous.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/ui/icons/question.svg b/ui/icons/question.svg new file mode 100644 index 0000000..fb8e3d3 --- /dev/null +++ b/ui/icons/question.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/ui/icons/reply.svg b/ui/icons/reply.svg new file mode 100644 index 0000000..d008cb3 --- /dev/null +++ b/ui/icons/reply.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/ui/icons/scissors.svg b/ui/icons/scissors.svg new file mode 100644 index 0000000..4b5a225 --- /dev/null +++ b/ui/icons/scissors.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/ui/icons/search.svg b/ui/icons/search.svg new file mode 100644 index 0000000..4a931b3 --- /dev/null +++ b/ui/icons/search.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/ui/icons/share-arrow.svg b/ui/icons/share-arrow.svg new file mode 100644 index 0000000..e0eb246 --- /dev/null +++ b/ui/icons/share-arrow.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/ui/icons/sign-out.svg b/ui/icons/sign-out.svg new file mode 100644 index 0000000..c5951fc --- /dev/null +++ b/ui/icons/sign-out.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/ui/icons/text-file.svg b/ui/icons/text-file.svg new file mode 100644 index 0000000..eafca90 --- /dev/null +++ b/ui/icons/text-file.svg @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/ui/icons/text-label.svg b/ui/icons/text-label.svg new file mode 100644 index 0000000..8fa9196 --- /dev/null +++ b/ui/icons/text-label.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/ui/icons/tools.svg b/ui/icons/tools.svg new file mode 100644 index 0000000..5326f19 --- /dev/null +++ b/ui/icons/tools.svg @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/ui/icons/zoom-in.svg b/ui/icons/zoom-in.svg new file mode 100644 index 0000000..60c41d1 --- /dev/null +++ b/ui/icons/zoom-in.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/ui/icons/zoom-out.svg b/ui/icons/zoom-out.svg new file mode 100644 index 0000000..bd4eec3 --- /dev/null +++ b/ui/icons/zoom-out.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/ui/main.crow b/ui/main.crow new file mode 100755 index 0000000..f4e4d44 --- /dev/null +++ b/ui/main.crow @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ui/openFile.crow b/ui/openFile.crow new file mode 100644 index 0000000..8686dd5 --- /dev/null +++ b/ui/openFile.crow @@ -0,0 +1,6 @@ + + + diff --git a/ui/saveFile.crow b/ui/saveFile.crow new file mode 100644 index 0000000..3e26223 --- /dev/null +++ b/ui/saveFile.crow @@ -0,0 +1,3 @@ + + + -- 2.47.3