aboutsummaryrefslogtreecommitdiffstatsci
path: root/Samples/ShowCase
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2020-06-06 13:40:54 +0200
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>2020-06-06 13:40:54 +0200
commitc928fc85cd1faed7273722f99b2a1edd9de14299 (patch)
treef9344290fb876906205f9d8ab4b401ec3d040250 /Samples/ShowCase
parentd88c47659d248dbf5b4ec2b071906fafe013011e (diff)
slider as base for scrollbar, gauge widget
Diffstat (limited to 'Samples/ShowCase')
-rw-r--r--Samples/ShowCase/ShowCase.cs153
-rw-r--r--Samples/ShowCase/ShowCase.csproj3
-rw-r--r--Samples/ShowCase/ui/Button.template12
-rw-r--r--Samples/ShowCase/ui/ShowCase.style4
-rw-r--r--Samples/ShowCase/ui/showcase.crow46
5 files changed, 182 insertions, 36 deletions
diff --git a/Samples/ShowCase/ShowCase.cs b/Samples/ShowCase/ShowCase.cs
index 346c2d1d..48e209ec 100644
--- a/Samples/ShowCase/ShowCase.cs
+++ b/Samples/ShowCase/ShowCase.cs
@@ -34,40 +34,146 @@ namespace ShowCase
}
}
- string source = @"<Label Text='Hello World' Background='MediumSeaGreen' Margin='10'/>";
-
+ string source, origSource;
+ public string CurrentFile {
+ get { return Configuration.Global.Get<string> (nameof (CurrentFile)); }
+ set {
+ if (CurrentFile == value)
+ return;
+ Configuration.Global.Set (nameof (CurrentFile), value);
+ NotifyValueChanged (CurrentFile);
+ }
+ }
public string Source {
- get => Source;
+ get => source;
set {
if (source == value)
return;
source = value;
reloadFromSource ();
+ CMDSave.CanExecute = source != origSource;
NotifyValueChanged (source);
}
}
- public void goUpDirClick (object sender, MouseButtonEventArgs e)
+
+ public static Picture IcoNew = new SvgPicture ("#Icons.blank-file.svg");
+ public static Picture IcoOpen = new SvgPicture ("#Icons.open.svg");
+ public static Picture IcoSave = new SvgPicture ("#Icons.save.svg");
+ public static Picture IcoSaveAs = new SvgPicture ("#Icons.save.svg");
+ public static Picture IcoQuit = new SvgPicture ("#Icons.sign-out.svg");
+ public static Picture IcoUndo = new SvgPicture ("#Icons.undo.svg");
+ public static Picture IcoRedo = new SvgPicture ("#Icons.redo.svg");
+
+ public static Picture IcoCut = new SvgPicture ("#Icons.scissors.svg");
+ public static Picture IcoCopy = new SvgPicture ("#Icons.copy-file.svg");
+ public static Picture IcoPaste = new SvgPicture ("#Icons.paste-on-document.svg");
+
+ public Command CMDNew, CMDSave, CMDSaveAs, CMDUndo, CMDRedo, CMDCut, CMDCopy, CMDPaste;
+
+ void initCommands ()
{
- string root = Directory.GetDirectoryRoot (CurrentDir);
- if (CurrentDir == root)
+ CMDNew = new Command (new Action (onNewFile)) { Caption = "New", Icon = "#Icons.blank-file.svg", CanExecute = true };
+ CMDSave = new Command (new Action (onSave)) { Caption = "Save", Icon = "#Icons.save.svg", CanExecute = false };
+ CMDSaveAs = new Command (new Action (onSaveAs)) { Caption = "Save As...", Icon = "#Icons.save.svg", CanExecute = true };
+ /*CMDUndo = new Command (new Action (undo)) { Caption = "Undo", Icon = IcoUndo, CanExecute = false };
+ CMDRedo = new Command (new Action (redo)) { Caption = "Redo", Icon = IcoRedo, CanExecute = false };
+ CMDCut = new Command (new Action (cut)) { Caption = "Cut", Icon = IcoCut, CanExecute = false };
+ CMDCopy = new Command (new Action (copy)) { Caption = "Copy", Icon = IcoCopy, CanExecute = false };
+ CMDPaste = new Command (new Action (paste)) { Caption = "Paste", Icon = IcoPaste, CanExecute = false };*/
+ }
+
+ public new bool IsDirty {
+ get => origSource != source;
+ }
+ void onSave ()
+ {
+ if (!File.Exists (CurrentFile)) {
+ onSaveAs ();
return;
- CurrentDir = Directory.GetParent (CurrentDir).FullName;
+ }
+ save ();
+ }
+ void onSaveAs ()
+ {
+ string dir = Path.GetDirectoryName (CurrentFile);
+ if (string.IsNullOrEmpty (dir))
+ dir = Directory.GetCurrentDirectory ();
+ LoadIMLFragment (@"<FileDialog Width='60%' Height='50%' Caption='Save as ...' CurrentDirectory='" +
+ dir + "' SelectedFile='" +
+ Path.GetFileName(CurrentFile) + "' OkClicked='saveFileDialog_OkClicked'/>").DataSource = this;
+ }
+ void saveFileDialog_OkClicked (object sender, EventArgs e)
+ {
+ FileDialog fd = sender as FileDialog;
+
+ if (string.IsNullOrEmpty (fd.SelectedFileFullPath))
+ return;
+
+ if (File.Exists(fd.SelectedFileFullPath)) {
+ MessageBox mb = MessageBox.ShowModal (this, MessageBox.Type.YesNo, "File exists, overwrite?");
+ mb.Yes += (sender2, e2) => {
+ CurrentFile = fd.SelectedFileFullPath;
+ save ();
+ };
+ return;
+ }
+
+ CurrentFile = fd.SelectedFileFullPath;
+ save ();
+ }
+
+ void onNewFile () {
+ if (IsDirty) {
+ MessageBox mb = MessageBox.ShowModal (this, MessageBox.Type.YesNo, "Current file has unsaved changes, are you sure?");
+ mb.Yes += (sender, e) => newFile ();
+ } else
+ newFile ();
+ }
+ void newFile()
+ {
+ origSource = "";
+ Source = "<Widget Background='DarkGrey'/>";
+ if (!string.IsNullOrEmpty (CurrentFile))
+ CurrentFile = Path.Combine (Path.GetDirectoryName (CurrentFile), "newfile.crow");
+ else
+ CurrentFile = Path.Combine (CurrentDir, "newfile.crow");
+ }
+
+
+ void save () {
+ using (Stream s = new FileStream(CurrentFile, FileMode.Create)) {
+ s.WriteByte (0xEF);
+ s.WriteByte (0xBB);
+ s.WriteByte (0xBF);
+ byte [] buff = Encoding.UTF8.GetBytes (source);
+ s.Write (buff, 0, buff.Length);
+ }
+ origSource = source;
}
protected override void OnInitialized ()
{
+ initCommands ();
+
base.OnInitialized ();
if (string.IsNullOrEmpty (CurrentDir))
CurrentDir = Path.Combine (Directory.GetCurrentDirectory (), "Interfaces");
+
Widget g = Load ("#ShowCase.showcase.crow");
- g.DataSource = this;
crowContainer = g.FindByName ("CrowContainer") as Container;
+ g.DataSource = this;
+
+ if (!File.Exists(CurrentFile))
+ origSource = Source = @"<Label Text='Hello World' Background='MediumSeaGreen' Margin='10'/>";
+
//I set an empty object as datasource at this level to force update when new
//widgets are added to the interface
crowContainer.DataSource = new object ();
hideError ();
+
+ reloadFromFile ();
}
static void App_KeyboardKeyDown (object sender, KeyEventArgs e)
@@ -81,6 +187,14 @@ namespace ShowCase
#endif
}
+ public void goUpDirClick (object sender, MouseButtonEventArgs e)
+ {
+ string root = Directory.GetDirectoryRoot (CurrentDir);
+ if (CurrentDir == root)
+ return;
+ CurrentDir = Directory.GetParent (CurrentDir).FullName;
+ }
+
void Dv_SelectedItemChanged (object sender, SelectionChangeEventArgs e)
{
FileSystemInfo fi = e.NewValue as FileSystemInfo;
@@ -88,11 +202,15 @@ namespace ShowCase
return;
if (fi is DirectoryInfo)
return;
-
- using (Stream s = new FileStream (fi.FullName, FileMode.Open)) {
- using (StreamReader sr = new StreamReader (s))
- Source = sr.ReadToEnd ();
+
+ if (IsDirty) {
+ MessageBox mb = MessageBox.ShowModal (this, MessageBox.Type.YesNo, "Current file has unsaved changes, are you sure?");
+ mb.Yes += (mbsender, mbe) => { CurrentFile = fi.FullName; reloadFromFile (); };
+ return;
}
+
+ CurrentFile = fi.FullName;
+ reloadFromFile ();
}
void showError (Exception ex)
@@ -104,7 +222,16 @@ namespace ShowCase
{
NotifyValueChanged ("ShowError", false);
}
-
+ void reloadFromFile ()
+ {
+ if (File.Exists (CurrentFile)) {
+ using (Stream s = new FileStream (CurrentFile, FileMode.Open)) {
+ using (StreamReader sr = new StreamReader (s))
+ origSource = sr.ReadToEnd ();
+ }
+ Source = origSource;
+ }
+ }
void reloadFromSource ()
{
hideError ();
diff --git a/Samples/ShowCase/ShowCase.csproj b/Samples/ShowCase/ShowCase.csproj
index ad2019cb..2bc30765 100644
--- a/Samples/ShowCase/ShowCase.csproj
+++ b/Samples/ShowCase/ShowCase.csproj
@@ -5,7 +5,4 @@
<LogicalName>ShowCase.%(Filename)%(Extension)</LogicalName>
</EmbeddedResource>
</ItemGroup>
- <ItemGroup>
- <None Remove="..\common\ui\Interfaces\basicTests\7.crow" />
- </ItemGroup>
</Project> \ No newline at end of file
diff --git a/Samples/ShowCase/ui/Button.template b/Samples/ShowCase/ui/Button.template
new file mode 100644
index 00000000..c7e2fa06
--- /dev/null
+++ b/Samples/ShowCase/ui/Button.template
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+<Border Background="{./Background}" MinimumSize="50,20" Name="Content"
+ Foreground="Transparent" CornerRadius="{../CornerRadius}" BorderWidth="1"
+ MouseEnter="{Foreground=vgradient|0:White|0.2:Grey|0.9:Grey|1:Black};{caption.Foreground=White}"
+ MouseLeave="{Foreground=Transparent};{caption.Foreground=LightGrey}"
+ MouseDown="{Foreground=vgradient|0:Black|0.05:Grey|0.85:Grey|1:White}"
+ MouseUp="{Foreground=vgradient|0:White|0.2:Grey|0.9:Grey|1:Black}">
+ <HorizontalStack Margin="2">
+ <Image Style="Icon" Path="{./Icon}"/>
+ <Label Font="{./Font}" Name="caption" Margin="3" Foreground="LightGrey" Text="{./Caption}"/>
+ </HorizontalStack>
+</Border> \ No newline at end of file
diff --git a/Samples/ShowCase/ui/ShowCase.style b/Samples/ShowCase/ui/ShowCase.style
new file mode 100644
index 00000000..0d688507
--- /dev/null
+++ b/Samples/ShowCase/ui/ShowCase.style
@@ -0,0 +1,4 @@
+IcoButton {
+ Template = "#ShowCase.Button.template";
+ Background = "Onyx";
+} \ No newline at end of file
diff --git a/Samples/ShowCase/ui/showcase.crow b/Samples/ShowCase/ui/showcase.crow
index 4805e96e..5405a5ef 100644
--- a/Samples/ShowCase/ui/showcase.crow
+++ b/Samples/ShowCase/ui/showcase.crow
@@ -1,32 +1,38 @@
<?xml version="1.0"?>
-<HorizontalStack Background="DarkGrey" Margin="2">
+<HorizontalStack Background="DarkGrey" >
<VerticalStack Width="25%">
- <HorizontalStack Height="Fit">
+ <HorizontalStack Height="Fit" Margin="2" Background="Onyx">
<Image Margin="2" Width="16" Height="16" Path="#Crow.Icons.level-up.svg" MouseClick="./goUpDirClick"
Background="Jet" MouseEnter="{Background=Grey}" MouseLeave="{Background=Jet}" />
<TextBox Text="{²CurrentDir}" Margin="2"/>
</HorizontalStack>
- <DirectoryView Name="dv" CurrentDirectory="{CurrentDir}" SelectedItemChanged="Dv_SelectedItemChanged"/>
+ <DirectoryView Margin="1" Name="dv" CurrentDirectory="{CurrentDir}" SelectedItemChanged="Dv_SelectedItemChanged"/>
</VerticalStack>
- <Splitter Width="6"/>
+ <Splitter Width="6" />
<VerticalStack>
<Container Name="CrowContainer" Height="60%" Background="Black"/>
<Splitter/>
- <HorizontalStack>
- <Scroller Name="scroller1" Background="White"
- Margin="2" ScrollY="{../scrollbar1.Value}"
- ValueChanged="./_scroller_ValueChanged">
- <TextBox VerticalAlignment="Top"
- Text="{²Source}" Multiline="true" TextAlignment="TopLeft"
- Font="Courriernew 10"/>
- </Scroller>
- <ScrollBar Name="scrollbar1" Value="{../scroller1.ScrollY}"
- LargeIncrement="{../scroller1.PageHeight}" SmallIncrement="30"
- CursorSize="{../scroller1.ChildHeightRatio}"
- Maximum="{../scroller1.MaxScrollY}" Orientation="Vertical"
- Width="14" />
- </HorizontalStack>
- <Label Visible="{ShowError}" Text="{ErrorMessage}" Background="Red" Foreground="White" Width="Stretched" Margin="2"
- Multiline="true"/>
+ <VerticalStack>
+ <HorizontalStack Height="Fit">
+ <Button Style="IcoButton" Command="{CMDNew}" />
+ <Button Style="IcoButton" Command="{CMDSave}" />
+ <Button Style="IcoButton" Command="{CMDSaveAs}" />
+ </HorizontalStack>
+ <HorizontalStack>
+ <Scroller Name="scroller1" Background="White"
+ Margin="2" ScrollY="{../scrollbar1.Value}"
+ ValueChanged="./_scroller_ValueChanged">
+ <TextBox VerticalAlignment="Top"
+ Text="{²Source}" Multiline="true" TextAlignment="TopLeft"
+ Font="Courriernew 10"/>
+ </Scroller>
+ <ScrollBar Name="scrollbar1" Value="{../scroller1.ScrollY}"
+ LargeIncrement="{../scroller1.PageHeight}" SmallIncrement="30"
+ CursorSize="{../scroller1.ChildHeightRatio}" Maximum="{../scroller1.MaxScrollY}" />
+ </HorizontalStack>
+ <Label Text="{CurrentFile}" Width="Stretched"/>
+ <Label Visible="{ShowError}" Text="{ErrorMessage}" Background="Red" Foreground="White" Width="Stretched" Margin="2"
+ Multiline="true"/>
+ </VerticalStack>
</VerticalStack>
</HorizontalStack>