windows: implement Add page

This commit is contained in:
Hylke Bons 2012-03-06 19:55:29 +00:00
parent 466a2146f3
commit cfde4a8c8e
9 changed files with 221 additions and 212 deletions

View file

@ -244,7 +244,7 @@ namespace SparkleShare {
public void UIHasLoaded ()
{
// if (FirstRun)
if (FirstRun)
ShowSetupWindow (PageType.Setup);
}

View file

@ -16,17 +16,9 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
#if __MonoCS__
using Mono.Unix;
//using Mono.Unix.Native;
#endif
using SparkleLib;
@ -41,23 +33,20 @@ namespace SparkleShare {
// Short alias for the translations
public static string _ (string s)
{
#if __MonoCS__
{
#if __MonoCS__
return Catalog.GetString (s);
#else
return Strings.T(s);
#endif
#else
return Strings.T (s);
#endif
}
#if !__MonoCS__
#if !__MonoCS__
[STAThread]
#endif
#endif
public static void Main (string [] args)
{
SetUiCulture();
// Parse the command line options
bool show_help = false;
OptionSet option_set = new OptionSet () {
@ -87,20 +76,12 @@ namespace SparkleShare {
UI = new SparkleUI ();
UI.Run ();
}
#if !__MonoCS__
// For now we must do GC.Collect to free some internal handles, otherwise
// in debug mode you can got assertion message.
#if !__MonoCS__
// Suppress assertion messages in debug mode
GC.Collect (GC.MaxGeneration, GCCollectionMode.Forced);
GC.WaitForPendingFinalizers ();
CefSharp.CEF.Shutdown (); // Shutdown CEF.
#endif
}
public static void SetUiCulture()
{
//var culture = CultureInfo.GetCultureInfo ("en"); // FIXME: test only
//System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
#endif
}
@ -116,10 +97,10 @@ namespace SparkleShare {
Console.WriteLine (_("This is free software, and you are welcome to redistribute it "));
Console.WriteLine (_("under certain conditions. Please read the GNU GPLv3 for details."));
Console.WriteLine (" ");
Console.WriteLine (_("SparkleShare automatically syncs Git repositories in "));
Console.WriteLine (_("the ~/SparkleShare folder with their remote origins."));
Console.WriteLine (_("SparkleShare is a collaboration and sharing tool that is "));
Console.WriteLine (_("designed to keep things simple and to stay out of your way."));
Console.WriteLine (" ");
Console.WriteLine (_("Usage: sparkleshare [start|stop|restart] [OPTION]..."));
Console.WriteLine (_("Usage: sparkleshare [start|stop|restart|version] [OPTION]..."));
Console.WriteLine (_("Sync SparkleShare folder with remote repositories."));
Console.WriteLine (" ");
Console.WriteLine (_("Arguments:"));
@ -129,32 +110,10 @@ namespace SparkleShare {
}
// Prints the version information
public static void PrintVersion ()
{
Console.WriteLine (_("SparkleShare " + Defines.VERSION));
Environment.Exit (0);
}
#if __MonoCS__
// Strange magic needed by SetProcessName ()
[DllImport ("libc")]
private static extern int prctl (int option, byte [] arg2, IntPtr arg3, IntPtr arg4, IntPtr arg5);
#endif
// Sets the Unix process name to 'sparkleshare' instead of 'mono'
private static void SetProcessName (string name)
{
#if __MonoCS__
try {
if (prctl (15, Encoding.ASCII.GetBytes (name + "\0"), IntPtr.Zero, IntPtr.Zero, IntPtr.Zero) != 0)
throw new ApplicationException ("Error setting process name: " +
Mono.Unix.Native.Stdlib.GetLastError ());
} catch (EntryPointNotFoundException) {
Console.WriteLine ("SetProcessName: Entry point not found");
}
#endif
}
}
}

View file

@ -96,11 +96,7 @@ namespace SparkleShare {
Height = 260
};
image.Source =
System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
Icons.about.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty,
BitmapSizeOptions.FromWidthAndHeight(640, 260));
image.Source = SparkleUIHelpers.GetBitmap ("about");
Label version = new Label () {
@ -112,7 +108,7 @@ namespace SparkleShare {
this.updates = new Label () {
Content = "Checking for updates...",
FontSize = 11,
Foreground = new SolidColorBrush (Color.FromRgb(45, 62, 81))
Foreground = new SolidColorBrush (Color.FromRgb (45, 62, 81))
};
TextBlock credits = new TextBlock () {

View file

@ -16,12 +16,18 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Media;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms.Integration;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Data;
using System.Media;
using WPF = System.Windows.Controls;
namespace SparkleShare {
@ -67,7 +73,6 @@ namespace SparkleShare {
TextBox name_box = new TextBox () {
Text = Controller.GuessedUserName,
Width = 175
};
@ -140,34 +145,178 @@ namespace SparkleShare {
case PageType.Add: {
Header = "Where's your project hosted?";
ListView list_view = new ListView () {
Width = 419,
Height = 195,
SelectionMode = SelectionMode.Single
};
GridView grid_view = new GridView ();
grid_view.Columns.Add (
new GridViewColumn {
DisplayMemberBinding = new Binding ("Text")
}
);
// TODO:
// - Disable column headers
// - Add plugin images
// - Nicer markup: <b>Name</b>\n<small>Description</small>
foreach (SparklePlugin plugin in Controller.Plugins) {
list_view.Items.Add (
new {
Text = plugin.Name + "\n" + plugin.Description
});
}
list_view.View = grid_view;
list_view.SelectedIndex = Controller.SelectedPluginIndex;
TextBlock address_label = new TextBlock () {
Text = "Address:",
FontWeight = FontWeights.Bold
};
TextBox address_box = new TextBox () {
Width = 200,
Text = Controller.PreviousAddress
};
TextBlock address_help_label = new TextBlock () {
Text = "",
FontSize = 11,
Foreground = new SolidColorBrush (Color.FromRgb (128, 128, 128))
};
TextBlock path_label = new TextBlock () {
Text = "Remote Path:",
FontWeight = FontWeights.Bold,
Width = 200
};
TextBox path_box = new TextBox () {
Width = 200,
Text = Controller.PreviousPath
};
TextBlock path_help_label = new TextBlock () {
Text = "",
FontSize = 11,
Width = 200,
Foreground = new SolidColorBrush (Color.FromRgb (128, 128, 128))
};
Button cancel_button = new Button () {
Content = "Cancel"
};
Button add_button = new Button () {
Content = "Add"
};
Content = "Cancel"
};
Button add_button = new Button () {
Content = "Add"
};
ContentCanvas.Children.Add (list_view);
Canvas.SetTop (list_view, 70);
Canvas.SetLeft (list_view, 185);
ContentCanvas.Children.Add (address_label);
Canvas.SetTop (address_label, 285);
Canvas.SetLeft (address_label, 185);
ContentCanvas.Children.Add (address_box);
Canvas.SetTop (address_box, 305);
Canvas.SetLeft (address_box, 185);
ContentCanvas.Children.Add (address_help_label);
Canvas.SetTop (address_help_label, 330);
Canvas.SetLeft (address_help_label, 185);
ContentCanvas.Children.Add (path_label);
Canvas.SetTop (path_label, 285);
Canvas.SetRight (path_label, 30);
ContentCanvas.Children.Add (path_box);
Canvas.SetTop (path_box, 305);
Canvas.SetRight (path_box, 30);
ContentCanvas.Children.Add (path_help_label);
Canvas.SetTop (path_help_label, 330);
Canvas.SetRight (path_help_label, 30);
Buttons.Add (add_button);
Buttons.Add (cancel_button);
Controller.ChangeAddressFieldEvent += delegate (string text,
string example_text, FieldState state) {
Dispatcher.Invoke ((Action) delegate {
address_box.Text = text;
address_box.IsEnabled = (state == FieldState.Enabled);
address_help_label.Text = example_text;
});
};
Controller.ChangePathFieldEvent += delegate (string text,
string example_text, FieldState state) {
Dispatcher.Invoke ((Action) delegate {
path_box.Text = text;
path_box.IsEnabled = (state == FieldState.Enabled);
path_help_label.Text = example_text;
});
};
Controller.UpdateAddProjectButtonEvent += delegate (bool button_enabled) {
Dispatcher.Invoke ((Action) delegate {
add_button.IsEnabled = button_enabled;
});
};
list_view.SelectionChanged += delegate {
Controller.SelectedPluginChanged (list_view.SelectedIndex);
};
list_view.KeyDown += delegate {
Controller.SelectedPluginChanged (list_view.SelectedIndex);
};
address_box.TextChanged += delegate {
Controller.CheckAddPage (
address_box.Text,
path_box.Text,
list_view.SelectedIndex
);
};
path_box.TextChanged += delegate {
Controller.CheckAddPage (
address_box.Text,
path_box.Text,
list_view.SelectedIndex
);
};
cancel_button.Click += delegate {
Controller.PageCancelled ();
};
add_button.Click += delegate {
Controller.AddPageCompleted ("github.com", "hbons/Stuff"); // TODO
Controller.AddPageCompleted (address_box.Text, path_box.Text);
};
Controller.CheckAddPage (
address_box.Text,
path_box.Text,
list_view.SelectedIndex
);
break;
}
@ -312,6 +461,7 @@ namespace SparkleShare {
Description = "All files added to your project folders are synced automatically with " +
"the host and your team members.";
Button continue_button = new Button () {
Content = "Continue"
};
@ -335,8 +485,21 @@ namespace SparkleShare {
Content = "Continue"
};
WPF.Image slide_image = new WPF.Image () {
Width = 350,
Height = 200
};
slide_image.Source = SparkleUIHelpers.GetBitmap ("tutorial-slide-3-windows");
ContentCanvas.Children.Add (slide_image);
Canvas.SetLeft (slide_image, 215);
Canvas.SetTop (slide_image, 130);
Buttons.Add (continue_button);
continue_button.Click += delegate {
Controller.TutorialPageCompleted ();
};

View file

@ -25,7 +25,6 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Reflection;
namespace SparkleShare {
@ -74,11 +73,9 @@ namespace SparkleShare {
Height = 482
};
this.side_splash.Source = SparkleUIHelpers.GetBitmap ("side-splash");
ContentCanvas.Children.Add (this.bar);
Canvas.SetRight (bar, 0);
Canvas.SetBottom (bar, 0);

View file

@ -104,9 +104,6 @@
</Compile>
<Compile Include="ApplicationSchemeHandler.cs" />
<Compile Include="AssemblyInfo.cs" />
<Compile Include="controls\ExampleTextBox.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="FileSchemeHandler.cs" />
<Compile Include="Icons.Designer.cs">
<AutoGen>True</AutoGen>
@ -126,11 +123,9 @@
<Compile Include="SparkleController.cs" />
<Compile Include="SparkleEventLog.cs" />
<Compile Include="SparkleSetup.cs" />
<Compile Include="Program.cs" />
<Compile Include="SparkleStatusIcon.cs" />
<Compile Include="SparkleUIHelpers.cs" />
<Compile Include="controls\TablessControl.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Strings.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
@ -140,9 +135,6 @@
<Link>SparkleEventLogController.cs</Link>
</Compile>
<Compile Include="SparkleSetupWindow.cs" />
<Compile Include="..\Program.cs">
<Link>Program.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\SparkleLib\windows\SparkleLib.csproj">
@ -215,9 +207,22 @@
<DependentUpon>SparkleSetup.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="..\..\data\about.png">
<Link>Pixmaps\about.png</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\..\data\side-splash.png">
<Link>Pixmaps\side-splash.png</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\..\data\tutorial-slide-1-windows.png">
<Link>Pixmaps\tutorial-slide-1-windows.png</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\..\data\tutorial-slide-3-windows.png">
<Link>Pixmaps\tutorial-slide-3-windows.png</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\..\data\plugins\bitbucket.png">
<Link>plugins\bitbucket.png</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="Icons.tt">
@ -226,10 +231,6 @@
</None>
</ItemGroup>
<ItemGroup>
<None Include="..\..\data\plugins\bitbucket.png">
<Link>plugins\bitbucket.png</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="..\..\data\plugins\github.png">
<Link>plugins\github.png</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
@ -393,7 +394,6 @@
<Content Include="..\..\data\icons\sparkleshare.ico" />
</ItemGroup>
<ItemGroup>
<Folder Include="New Folder\" />
<Folder Include="Pixmaps\" />
</ItemGroup>
</Project>

View file

@ -25,6 +25,7 @@ using System.Windows.Controls;
using System.Windows;
using System.Windows.Controls.Primitives;
namespace SparkleShare {
public class SparkleStatusIcon : Control {
@ -40,7 +41,6 @@ namespace SparkleShare {
private WinForms.NotifyIcon notify_icon = new WinForms.NotifyIcon () {
Text = "SparkleShare",
Visible = true
};
@ -55,6 +55,11 @@ namespace SparkleShare {
public SparkleStatusIcon ()
{
LostFocus += delegate {
this.context_menu.IsOpen = false;
};
notify_icon.Icon = Icon.FromHandle(Icons.document_added_12.GetHicon());
AnimationFrames = CreateAnimationFrames ();
Animation = CreateAnimation ();
@ -65,7 +70,6 @@ namespace SparkleShare {
SetNormalState ();
//TODO quit item event
Controller.UpdateQuitItemEvent += delegate (bool enable) {
Dispatcher.Invoke ((Action) delegate {
@ -404,3 +408,10 @@ namespace SparkleShare {
}
}
}

View file

@ -1,96 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace SparkleShare.controls {
public class ExampleTextBox : TextBox {
private bool ExampleTextActive = true;
private bool OnTextChangedActive = true;
private bool _focused = false;
private string _ExampleText = "";
public string ExampleText
{
get { return _ExampleText; }
set
{
_ExampleText = value;
if (ExampleTextActive)
ActivateExampleText ();
}
}
public override string Text
{
get
{
if (ExampleTextActive)
return "";
return base.Text;
}
set
{
if (String.IsNullOrEmpty (value)) {
ActivateExampleText ();
} else {
ExampleTextActive = false;
ForeColor = System.Drawing.SystemColors.WindowText;
base.Text = value;
}
}
}
private void ActivateExampleText ()
{
OnTextChangedActive = false;
base.Text = ExampleText;
OnTextChangedActive = true;
ExampleTextActive = true;
ForeColor = System.Drawing.SystemColors.InactiveCaptionText;
}
protected override void OnTextChanged (EventArgs e)
{
if (!OnTextChangedActive)
return;
bool Empty = String.IsNullOrEmpty (base.Text);
if (Empty) {
ActivateExampleText ();
SelectAll ();
} else if (ExampleTextActive) {
ExampleTextActive = false;
ForeColor = System.Drawing.SystemColors.WindowText;
}
base.OnTextChanged (e);
}
protected override void OnEnter (EventArgs e)
{
base.OnEnter (e);
if (ExampleTextActive && MouseButtons == MouseButtons.None) {
SelectAll ();
_focused = true;
}
}
protected override void OnLeave (EventArgs e)
{
base.OnLeave (e);
_focused = false;
}
protected override void OnMouseUp (MouseEventArgs mevent)
{
base.OnMouseUp (mevent);
if (!_focused) {
if (ExampleTextActive && SelectionLength == 0)
SelectAll ();
_focused = true;
}
}
}
}

View file

@ -1,21 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace SparkleShare.controls {
public class TablessControl : TabControl {
protected override void WndProc (ref Message m)
{
if (m.Msg == 0x1328 && !DesignMode)
m.Result = (IntPtr)1;
else
base.WndProc (ref m);
}
}
}