From cfde4a8c8e5bd125ff5cfe3b50965a259d40301b Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Tue, 6 Mar 2012 19:55:29 +0000 Subject: [PATCH] windows: implement Add page --- SparkleShare/SparkleControllerBase.cs | 2 +- SparkleShare/Windows/Program.cs | 73 ++----- SparkleShare/Windows/SparkleAbout.cs | 8 +- SparkleShare/Windows/SparkleSetup.cs | 187 ++++++++++++++++-- SparkleShare/Windows/SparkleSetupWindow.cs | 3 - SparkleShare/Windows/SparkleShare.csproj | 28 +-- SparkleShare/Windows/SparkleStatusIcon.cs | 15 +- .../Windows/controls/ExampleTextBox.cs | 96 --------- .../Windows/controls/TablessControl.cs | 21 -- 9 files changed, 221 insertions(+), 212 deletions(-) delete mode 100644 SparkleShare/Windows/controls/ExampleTextBox.cs delete mode 100644 SparkleShare/Windows/controls/TablessControl.cs diff --git a/SparkleShare/SparkleControllerBase.cs b/SparkleShare/SparkleControllerBase.cs index f66a8b15..9b5403b0 100644 --- a/SparkleShare/SparkleControllerBase.cs +++ b/SparkleShare/SparkleControllerBase.cs @@ -244,7 +244,7 @@ namespace SparkleShare { public void UIHasLoaded () { - // if (FirstRun) + if (FirstRun) ShowSetupWindow (PageType.Setup); } diff --git a/SparkleShare/Windows/Program.cs b/SparkleShare/Windows/Program.cs index a867960b..f24b288d 100644 --- a/SparkleShare/Windows/Program.cs +++ b/SparkleShare/Windows/Program.cs @@ -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 - } } } diff --git a/SparkleShare/Windows/SparkleAbout.cs b/SparkleShare/Windows/SparkleAbout.cs index 35c2439e..316515f5 100644 --- a/SparkleShare/Windows/SparkleAbout.cs +++ b/SparkleShare/Windows/SparkleAbout.cs @@ -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 () { diff --git a/SparkleShare/Windows/SparkleSetup.cs b/SparkleShare/Windows/SparkleSetup.cs index c96f6722..fa006d49 100644 --- a/SparkleShare/Windows/SparkleSetup.cs +++ b/SparkleShare/Windows/SparkleSetup.cs @@ -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: Name\nDescription + 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 (); }; diff --git a/SparkleShare/Windows/SparkleSetupWindow.cs b/SparkleShare/Windows/SparkleSetupWindow.cs index 6bb334c6..8d0d4e7e 100644 --- a/SparkleShare/Windows/SparkleSetupWindow.cs +++ b/SparkleShare/Windows/SparkleSetupWindow.cs @@ -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); diff --git a/SparkleShare/Windows/SparkleShare.csproj b/SparkleShare/Windows/SparkleShare.csproj index 30c3a2d0..a456f9b9 100644 --- a/SparkleShare/Windows/SparkleShare.csproj +++ b/SparkleShare/Windows/SparkleShare.csproj @@ -104,9 +104,6 @@ - - Component - True @@ -126,11 +123,9 @@ + - - Component - True True @@ -140,9 +135,6 @@ SparkleEventLogController.cs - - Program.cs - @@ -215,9 +207,22 @@ SparkleSetup.cs Designer + + Pixmaps\about.png + Pixmaps\side-splash.png + + Pixmaps\tutorial-slide-1-windows.png + + + Pixmaps\tutorial-slide-3-windows.png + + + plugins\bitbucket.png + Always + @@ -226,10 +231,6 @@ - - plugins\bitbucket.png - Always - plugins\github.png Always @@ -393,7 +394,6 @@ - diff --git a/SparkleShare/Windows/SparkleStatusIcon.cs b/SparkleShare/Windows/SparkleStatusIcon.cs index 78996657..bf62a715 100644 --- a/SparkleShare/Windows/SparkleStatusIcon.cs +++ b/SparkleShare/Windows/SparkleStatusIcon.cs @@ -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 { } } } + + + + + + + diff --git a/SparkleShare/Windows/controls/ExampleTextBox.cs b/SparkleShare/Windows/controls/ExampleTextBox.cs deleted file mode 100644 index c054afaf..00000000 --- a/SparkleShare/Windows/controls/ExampleTextBox.cs +++ /dev/null @@ -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; - } - } - } -} diff --git a/SparkleShare/Windows/controls/TablessControl.cs b/SparkleShare/Windows/controls/TablessControl.cs deleted file mode 100644 index 0618f531..00000000 --- a/SparkleShare/Windows/controls/TablessControl.cs +++ /dev/null @@ -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); - } - - } -}