From: jpbruyere Date: Thu, 26 Jan 2017 23:21:48 +0000 (+0100) Subject: icon menuitem, PopWidth and PopHeight, commands X-Git-Tag: v0.5.1~28^2~2 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=d341658c5ea7d20d06d441b5aa11a13414fbe073;p=jp%2Fcrow.git icon menuitem, PopWidth and PopHeight, commands --- diff --git a/Crow.csproj b/Crow.csproj index 25e7f10d..d74f12f2 100644 --- a/Crow.csproj +++ b/Crow.csproj @@ -185,6 +185,7 @@ + @@ -294,6 +295,12 @@ + + + + + + diff --git a/CrowIDE/CrowIDE.csproj b/CrowIDE/CrowIDE.csproj index ec173d3d..b144ccce 100644 --- a/CrowIDE/CrowIDE.csproj +++ b/CrowIDE/CrowIDE.csproj @@ -79,10 +79,12 @@ CrowIDE.MembersView.template - + + Crow.MenuItem.template + diff --git a/CrowIDE/Default.style b/CrowIDE/Default.style deleted file mode 100644 index 19be18b7..00000000 --- a/CrowIDE/Default.style +++ /dev/null @@ -1,3 +0,0 @@ -TextBox { - Margin = 1; -} \ No newline at end of file diff --git a/CrowIDE/src/CrowIDE.cs b/CrowIDE/src/CrowIDE.cs index afaab3a4..55a907b2 100644 --- a/CrowIDE/src/CrowIDE.cs +++ b/CrowIDE/src/CrowIDE.cs @@ -31,6 +31,16 @@ namespace CrowIDE { class CrowIDE : OpenTKGameWindow { + public Command CMDLoad = new Command(new Action(() => System.Diagnostics.Debug.WriteLine("Open"))) { Caption = "Open", Icon = new SvgPicture("#Crow.Icons.open-file.svg")}; + public Command CMDSave = new Command(new Action(() => System.Diagnostics.Debug.WriteLine("Save"))) { Caption = "Save", Icon = new SvgPicture("#Crow.Icons.open-file.svg")}; + public Command CMDQuit = new Command(new Action(() => System.Diagnostics.Debug.WriteLine("Quit"))) { Caption = "Quit", Icon = new SvgPicture("#Crow.Icons.exit-symbol.svg")}; +// public Command CMDSave = new Command(actionOpenFile) { Caption = "Open...", Icon = new SvgPicture("#Crow.Icons.open-file.svg")}; +// public Command CMDQuit = new Command(actionOpenFile) { Caption = "Open...", Icon = new SvgPicture("#Crow.Icons.open-file.svg")}; + public Command CMDCut = new Command(new Action(() => System.Diagnostics.Debug.WriteLine("Cut"))) { Caption = "Cut", Icon = new SvgPicture("#Crow.Icons.scissors.svg")}; + public Command CMDCopy = new Command(new Action(() => System.Diagnostics.Debug.WriteLine("Copy"))) { Caption = "Copy", Icon = new SvgPicture("#Crow.Icons.copy-file.svg")}; + public Command CMDPaste = new Command(new Action(() => System.Diagnostics.Debug.WriteLine("Paste"))) { Caption = "Paste", Icon = new SvgPicture("#Crow.Icons.paste-on-document.svg")}; + public Command CMDHelp = new Command(new Action(() => System.Diagnostics.Debug.WriteLine("Help"))) { Caption = "Help", Icon = new SvgPicture("#Crow.Icons.question.svg")}; + [STAThread] static void Main () { @@ -87,8 +97,13 @@ namespace CrowIDE if (g != null) CrowInterface.DeleteWidget (g); } + protected void onCommandSave(object sender, MouseButtonEventArgs e){ System.Diagnostics.Debug.WriteLine("save"); } + + void actionOpenFile(){ + System.Diagnostics.Debug.WriteLine ("OpenFile action"); + } } } \ No newline at end of file diff --git a/CrowIDE/ui/IDE.style b/CrowIDE/ui/IDE.style index 5d39b25f..ec6f79b3 100644 --- a/CrowIDE/ui/IDE.style +++ b/CrowIDE/ui/IDE.style @@ -1,9 +1,4 @@ -icon { - Focusable=true; - Width=32; - Height=32; - Margin=2; - CornerRadius=5; - MouseEnter = {Background=UnitedNationsBlue;} - MouseLeave = {Background=Transparent;} +Icon { + Width=16; + Height=16; } diff --git a/CrowIDE/ui/MenuItem.template b/CrowIDE/ui/MenuItem.template new file mode 100644 index 00000000..8a6dfba9 --- /dev/null +++ b/CrowIDE/ui/MenuItem.template @@ -0,0 +1,25 @@ + + + + + + + diff --git a/CrowIDE/ui/imlEditor.crow b/CrowIDE/ui/imlEditor.crow index ad589bcb..97df6eb5 100644 --- a/CrowIDE/ui/imlEditor.crow +++ b/CrowIDE/ui/imlEditor.crow @@ -1,26 +1,26 @@  - + - - - - - + + + + + - - - - + + + + - - - + + + - + diff --git a/Default.style b/Default.style index c4a8279e..89e54719 100644 --- a/Default.style +++ b/Default.style @@ -22,12 +22,10 @@ Menu { VerticalAlignment = Top; } MenuItem { - Height = Fit; - Width = Fit; Background = Transparent; Foreground = LightGray; - Open = {Background = Mantis;Foreground=Jet;} - Close = {Foreground=LightGray;Background=Transparent;} + MouseEnter = {Background = vgradient|0:UnitedNationsBlue|1:Onyx;Foreground=White;} + MouseLeave = {Foreground=LightGray;Background=Transparent;} } MessageBox { Width=200; diff --git a/Icons/copy-file.svg b/Icons/copy-file.svg new file mode 100644 index 00000000..63c2dd37 --- /dev/null +++ b/Icons/copy-file.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/Icons/exit-symbol.svg b/Icons/exit-symbol.svg new file mode 100644 index 00000000..3fbaa0d2 --- /dev/null +++ b/Icons/exit-symbol.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/Icons/open-file.svg b/Icons/open-file.svg new file mode 100644 index 00000000..d5c6a84d --- /dev/null +++ b/Icons/open-file.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/Icons/paste-on-document.svg b/Icons/paste-on-document.svg new file mode 100644 index 00000000..b0a705ee --- /dev/null +++ b/Icons/paste-on-document.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/Icons/question.svg b/Icons/question.svg new file mode 100644 index 00000000..fb8e3d3f --- /dev/null +++ b/Icons/question.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Icons/scissors.svg b/Icons/scissors.svg new file mode 100644 index 00000000..4b5a2255 --- /dev/null +++ b/Icons/scissors.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/Templates/DirectoryView.template b/Templates/DirectoryView.template index 55d652a9..f7c74a9d 100755 --- a/Templates/DirectoryView.template +++ b/Templates/DirectoryView.template @@ -6,7 +6,7 @@ @@ -15,7 +15,7 @@ - + diff --git a/src/Command.cs b/src/Command.cs index 35a7facc..f7a12465 100644 --- a/src/Command.cs +++ b/src/Command.cs @@ -35,16 +35,20 @@ namespace Crow #endregion #region CTOR - public Command () + public Command (Action _executeAction) { + execute = _executeAction; } #endregion + Action execute; + string caption; + Picture icon; bool isEnabled; - - [XmlAttributeAttribute()][DefaultValue(true)] + #region Public properties + [XmlAttributeAttribute][DefaultValue(true)] public virtual bool IsEnabled { get { return isEnabled; } set { @@ -54,7 +58,7 @@ namespace Crow NotifyValueChanged ("IsEnabled", isEnabled); } } - [XmlAttributeAttribute()][DefaultValue("Unamed Command")] + [XmlAttributeAttribute][DefaultValue("Unamed Command")] public virtual string Caption { get { return caption; } set { @@ -65,5 +69,27 @@ namespace Crow } } + [XmlAttributeAttribute] + public Picture Icon { + get { return icon; } + set { + if (icon == value) + return; + icon = value; + NotifyValueChanged ("Icon", icon); + } + } + #endregion + + public void Execute(){ + if (execute != null) + execute (); + } + internal void raiseAllValuesChanged(){ + NotifyValueChanged ("IsEnabled", isEnabled); + NotifyValueChanged ("Icon", icon); + NotifyValueChanged ("Caption", caption); + } + } } diff --git a/src/GraphicObjects/Button.cs b/src/GraphicObjects/Button.cs index 1cfbe85c..c73062f0 100644 --- a/src/GraphicObjects/Button.cs +++ b/src/GraphicObjects/Button.cs @@ -26,7 +26,6 @@ namespace Crow public event EventHandler Pressed; public event EventHandler Released; - public event EventHandler Clicked; #region TemplatedContainer overrides public override GraphicObject Content { @@ -34,7 +33,7 @@ namespace Crow return _contentContainer == null ? null : _contentContainer.Child; } set { - if (_contentContainer != null) + if (_contentContainer != null) _contentContainer.SetChild(value); } } @@ -69,24 +68,24 @@ namespace Crow [XmlAttributeAttribute][DefaultValue("Button")] public string Caption { - get { return caption; } + get { return caption; } set { if (caption == value) return; - caption = value; + caption = value; NotifyValueChanged ("Caption", caption); } - } + } [XmlAttributeAttribute][DefaultValue("#Crow.Images.button.svg")] public string Image { - get { return image; } + get { return image; } set { if (image == value) return; - image = value; + image = value; NotifyValueChanged ("Image", image); } - } + } [XmlAttributeAttribute][DefaultValue(false)] public bool IsPressed { diff --git a/src/GraphicObjects/Image.cs b/src/GraphicObjects/Image.cs index fa036b97..281011ad 100644 --- a/src/GraphicObjects/Image.cs +++ b/src/GraphicObjects/Image.cs @@ -11,66 +11,81 @@ namespace Crow { Picture _pic; string _svgSub; - bool scaled; - [XmlAttributeAttribute()][DefaultValue(true)] + bool scaled, keepProps; + + #region Public properties + [XmlAttributeAttribute][DefaultValue(true)] public virtual bool Scaled { get { return scaled; } set { if (scaled == value) return; - scaled = value; + scaled = value; NotifyValueChanged ("Scaled", scaled); if (_pic == null) return; _pic.Scaled = scaled; RegisterForGraphicUpdate (); } - } - bool keepProps; - [XmlAttributeAttribute()][DefaultValue(true)] + } + [XmlAttributeAttribute][DefaultValue(true)] public virtual bool KeepProportions { get { return keepProps; } set { if (keepProps == value) return; - keepProps = value; + keepProps = value; NotifyValueChanged ("KeepProportions", keepProps); if (_pic == null) return; _pic.KeepProportions = keepProps; RegisterForGraphicUpdate (); } - } - [XmlAttributeAttribute("Path")] + } + [XmlAttributeAttribute] public string Path { - get { return _pic == null ? null : _pic.Path; } - set { + get { return _pic == null ? "" : _pic.Path; } + set { + if (value == Path) + return; try { - if (string.IsNullOrEmpty(value)){ - _pic = null; - return; - } - lock(CurrentInterface.LayoutMutex){ - LoadImage (value); - _pic.Scaled = scaled; - _pic.KeepProportions = keepProps; + if (string.IsNullOrEmpty(value)) + Picture = null; + else { + lock(CurrentInterface.LayoutMutex){ + LoadImage (value); + } } } catch (Exception ex) { Debug.WriteLine (ex.Message); _pic = null; } + NotifyValueChanged ("Path", Path); } } - - [XmlAttributeAttribute()][DefaultValue(null)] + [XmlAttributeAttribute] public string SvgSub { get { return _svgSub; } set { + if (_svgSub == value) + return; _svgSub = value; RegisterForGraphicUpdate (); } } - + [XmlAttributeAttribute] + public Picture Picture { + get { return _pic; } + set { + if (_pic == value) + return; + _pic = value; + NotifyValueChanged ("Picture", _pic); + RegisterForGraphicUpdate (); + } + } + #endregion + #region CTOR public Image () : base() { @@ -80,14 +95,17 @@ namespace Crow #region Image Loading public void LoadImage (string path) { + Picture pic; + if (path.EndsWith (".svg", true, System.Globalization.CultureInfo.InvariantCulture)) + pic = new SvgPicture (); + else + pic = new BmpPicture (); - if (path.EndsWith (".svg", true, System.Globalization.CultureInfo.InvariantCulture)) - _pic = new SvgPicture (); - else - _pic = new BmpPicture (); + pic.LoadImage (path); + pic.Scaled = scaled; + pic.KeepProportions = keepProps; - _pic.LoadImage (path); - RegisterForGraphicUpdate (); + Picture = pic; } #endregion @@ -95,12 +113,13 @@ namespace Crow protected override int measureRawSize (LayoutingType lt) { if (_pic == null) - _pic = "#Crow.Images.Icons.IconAlerte.svg"; + return 2 * Margin; + //_pic = "#Crow.Images.Icons.IconAlerte.svg"; //TODO:take scalling in account if (lt == LayoutingType.Width) return _pic.Dimensions.Width + 2 * Margin; else - return _pic.Dimensions.Height + 2 * Margin; + return _pic.Dimensions.Height + 2 * Margin; } protected override void onDraw (Context gr) { diff --git a/src/GraphicObjects/Menu.cs b/src/GraphicObjects/Menu.cs index 1a7a3f95..66d23194 100644 --- a/src/GraphicObjects/Menu.cs +++ b/src/GraphicObjects/Menu.cs @@ -31,8 +31,10 @@ namespace Crow #endregion Orientation orientation; + bool autoOpen = false; - [XmlAttributeAttribute()][DefaultValue(Orientation.Horizontal)] + #region Public properties + [XmlAttributeAttribute][DefaultValue(Orientation.Horizontal)] public Orientation Orientation { get { return orientation; } set { @@ -42,12 +44,12 @@ namespace Crow NotifyValueChanged ("Orientation", orientation); } } - bool autoOpen = false; [XmlIgnore]public bool AutomaticOpenning { get { return autoOpen; } set { autoOpen = value; } } + #endregion public override void AddItem (GraphicObject g) { diff --git a/src/GraphicObjects/MenuItem.cs b/src/GraphicObjects/MenuItem.cs index 80b5759d..adec326f 100644 --- a/src/GraphicObjects/MenuItem.cs +++ b/src/GraphicObjects/MenuItem.cs @@ -32,12 +32,14 @@ namespace Crow public event EventHandler Open; public event EventHandler Close; - public event EventHandler Execute; string caption; - Command command;//TODO + Command command; + Picture icon; bool isOpened; + Measure popWidth, popHeight; + #region Public properties [XmlAttributeAttribute][DefaultValue(false)] public bool IsOpened { get { return isOpened; } @@ -54,38 +56,87 @@ namespace Crow onClose (this, null); } } - [XmlAttributeAttribute][DefaultValue(null)] public virtual Command Command { get { return command; } set { if (command == value) return; + + if (command != null) { + command.raiseAllValuesChanged (); + command.ValueChanged -= Command_ValueChanged; + } + command = value; + + if (command != null) { + command.ValueChanged += Command_ValueChanged; + command.raiseAllValuesChanged (); + } + NotifyValueChanged ("Command", command); } } - [XmlAttributeAttribute][DefaultValue("MenuItem")] public string Caption { - get { return caption; } + get { return Command == null ? caption : Command.Caption; } set { if (caption == value) return; caption = value; - NotifyValueChanged ("Caption", caption); + + if (command == null)//raise value changed only if not bound to a command + NotifyValueChanged ("Caption", caption); + } + } + [XmlAttributeAttribute] + public Picture Icon { + get { return Command == null ? icon : Command.Icon;; } + set { + if (icon == value) + return; + icon = value; + if (command == null) + NotifyValueChanged ("Icon", icon); } } - + [XmlAttributeAttribute()][DefaultValue("Fit")] + public virtual Measure PopWidth { + get { return popWidth; } + set { + if (popWidth == value) + return; + popWidth = value; + NotifyValueChanged ("PopWidth", popWidth); + } + } + [XmlAttributeAttribute()][DefaultValue("Fit")] + public virtual Measure PopHeight { + get { return popHeight; } + set { + if (popHeight == value) + return; + popHeight = value; + NotifyValueChanged ("PopHeight", popHeight); + } + } + #endregion + public override void AddItem (GraphicObject g) { base.AddItem (g); g.NotifyValueChanged ("PopDirection", Alignment.Right); } + void Command_ValueChanged (object sender, ValueChangeEventArgs e) + { + NotifyValueChanged (e.MemberName, e.NewValue); + } void onMI_Click (object sender, MouseButtonEventArgs e) { - Execute.Raise (this, null); + if (command != null) + command.Execute (); if(!IsOpened) (LogicalParent as Menu).AutomaticOpenning = false; } diff --git a/src/GraphicObjects/Popper.cs b/src/GraphicObjects/Popper.cs index 84088355..8c79ce24 100644 --- a/src/GraphicObjects/Popper.cs +++ b/src/GraphicObjects/Popper.cs @@ -38,6 +38,7 @@ namespace Crow string caption; Alignment popDirection; GraphicObject _content; + Measure popWidth, popHeight; public event EventHandler Pop; public event EventHandler Unpop; @@ -53,6 +54,26 @@ namespace Crow NotifyValueChanged ("Caption", caption); } } + [XmlAttributeAttribute()][DefaultValue("Fit")] + public virtual Measure PopWidth { + get { return popWidth; } + set { + if (popWidth == value) + return; + popWidth = value; + NotifyValueChanged ("PopWidth", popWidth); + } + } + [XmlAttributeAttribute()][DefaultValue("Fit")] + public virtual Measure PopHeight { + get { return popHeight; } + set { + if (popHeight == value) + return; + popHeight = value; + NotifyValueChanged ("PopHeight", popHeight); + } + } [XmlAttributeAttribute()][DefaultValue(false)] public bool IsPopped { @@ -164,18 +185,6 @@ namespace Crow } #region GraphicObject overrides - public override void OnLayoutChanges (LayoutingType layoutType) - { - base.OnLayoutChanges (layoutType); - - if (_content == null) - return; - - if (layoutType == LayoutingType.Width) - _content.MinimumSize = new Size (this.Slot.Width, _content.MinimumSize.Height); - } - - public override void onMouseClick (object sender, MouseButtonEventArgs e) { if (_canPop)