Esempio n. 1
0
        private void ShowSyncingPage(string name)
        {
            Reset();

            Header      = "Syncing folder ‘" + name + "’…";
            Description = "This may take a while.\n" +
                          "Are you sure it’s not coffee o'clock?";


            ProgressIndicator = new NSProgressIndicator()
            {
                Frame = new RectangleF(190, Frame.Height - 200, 640 - 150 - 80, 20),
                Style = NSProgressIndicatorStyle.Bar
            };

            ProgressIndicator.StartAnimation(this);

            ContentView.AddSubview(ProgressIndicator);


            FinishButton = new NSButton()
            {
                Title   = "Finish",
                Enabled = false
            };

            Buttons.Add(FinishButton);

            ShowAll();
        }
Esempio n. 2
0
        private void CreateEventLog()
        {
            OpenFolderButton = new NSButton(new RectangleF(16, 12, 120, 32))
            {
                Title      = "Open Folder",
                BezelStyle = NSBezelStyle.Rounded,
                Font       = SparkleUI.Font
            };

            OpenFolderButton.Activated += delegate {
                SparkleShare.Controller.OpenSparkleShareFolder(LocalPath);
            };

            ContentView.AddSubview(OpenFolderButton);


            CloseButton = new NSButton(new RectangleF(480 - 120 - 16, 12, 120, 32))
            {
                Title      = "Close",
                BezelStyle = NSBezelStyle.Rounded,
                Font       = SparkleUI.Font
            };

            CloseButton.Activated += delegate {
                InvokeOnMainThread(delegate {
                    PerformClose(this);
                });
            };

            ContentView.AddSubview(CloseButton);


            string name = Path.GetFileName(LocalPath);

            Title = String.Format("Events in ‘{0}’", name);

            Separator = new NSBox(new RectangleF(0, 58, 480, 1))
            {
                BorderColor = NSColor.LightGray,
                BoxType     = NSBoxType.NSBoxCustom
            };

            ContentView.AddSubview(Separator);


            ProgressIndicator = new NSProgressIndicator()
            {
                Style = NSProgressIndicatorStyle.Spinning,
                Frame = new RectangleF(Frame.Width / 2 - 10, Frame.Height / 2 + 10, 20, 20)
            };

            ProgressIndicator.StartAnimation(this);

            WebView = new WebView(new RectangleF(0, 59, 480, 559), "", "")
            {
                PolicyDelegate = new SparkleWebPolicyDelegate()
            };

            Update();
        }
        protected override IView OnConvertToView(FigmaNode currentNode, ViewNode parentNode, ViewRenderService rendererService)
        {
            var frame = (FigmaFrame)currentNode;

            var progressIndicator = new NSProgressIndicator();

            progressIndicator.Configure(frame);

            frame.TryGetNativeControlType(out var controlType);
            frame.TryGetNativeControlVariant(out var controlVariant);

            progressIndicator.ControlSize = ViewHelper.GetNSControlSize(controlVariant);

            FigmaGroup group = frame.children
                               .OfType <FigmaGroup>()
                               .FirstOrDefault(s => (s.name == ComponentString.STYLE_DETERMINATE || s.name == ComponentString.STYLE_INDETERMINATE) && s.visible);

            if (group?.name == ComponentString.STYLE_DETERMINATE)
            {
                progressIndicator.Indeterminate = false;
                progressIndicator.MinValue      = 0;
                progressIndicator.MaxValue      = 1;
                progressIndicator.DoubleValue   = 0.618;
            }

            if (group.name == ComponentString.STYLE_INDETERMINATE)
            {
                progressIndicator.Indeterminate = true;
            }

            return(new View(progressIndicator));
        }
Esempio n. 4
0
        public override void DidFinishLaunching(NSNotification notification)
        {
            mainWindowController = new MainWindowController();
            mainWindowController.Window.MakeKeyAndOrderFront(this);

            var progressIndicator = new NSProgressIndicator(new CGRect(50, 0, 400, 200))
            {
                DoubleValue   = 0,
                Indeterminate = false
            };

            double progressValue = 0;

            NSTimer.CreateRepeatingScheduledTimer(.5, timer => {
                if (!NSThread.Current.IsMainThread)
                {
                    throw new System.InvalidOperationException("NSTimer should invoke on main?");
                }

                if (progressValue >= 100)
                {
                    progressValue = 0;
                }
                progressValue += 20;
                progressIndicator.DoubleValue = progressValue;
            });

            mainWindowController.Window.ContentView.AddSubview(progressIndicator);
        }
Esempio n. 5
0
        public SearchBarView()
        {
            TranslatesAutoresizingMaskIntoConstraints = false;
            WantsLayer            = true;
            Layer.BackgroundColor = NSColor.White.CGColor;

            searchIcon       = new NSImageView();
            searchIcon.Image = NSImage.ImageNamed("Search");
            searchIcon.TranslatesAutoresizingMaskIntoConstraints = false;

            SearchField = new NSTextField();
            SearchField.DrawsBackground = false;
            SearchField.FocusRingType   = NSFocusRingType.None;
            SearchField.Bordered        = false;
            SearchField.TranslatesAutoresizingMaskIntoConstraints = false;
            SearchField.Font              = NSFont.FromFontName("SF UI Display Regular", 14);
            SearchField.TextColor         = NSColor.FromRgb(100, 100, 100);
            SearchField.PlaceholderString = "Search music here...";

            ProgressIndicator = new NSProgressIndicator();
            ProgressIndicator.TranslatesAutoresizingMaskIntoConstraints = false;
            ProgressIndicator.Style = NSProgressIndicatorStyle.Spinning;
            //ProgressIndicator.Hidden = true;

            AddSubview(searchIcon);
            AddSubview(SearchField);
            AddSubview(ProgressIndicator);

            ProgressIndicator.StartAnimation(this);

            BuildConstraints();
        }
Esempio n. 6
0
        //largely ported from azure-activedirectory-library-for-objc
        //ADAuthenticationViewController.m
        public override void LoadWindow()
        {
            var parentWindow = callerWindow ?? NSApplication.SharedApplication.MainWindow;

            CGRect windowRect;

            if (parentWindow != null)
            {
                windowRect = parentWindow.Frame;
            }
            else
            {
                // If we didn't get a parent window then center it in the screen
                windowRect = NSScreen.MainScreen.Frame;
            }

            // Calculate the center of the current main window so we can position our window in the center of it
            CGRect centerRect = CenterRect(windowRect, new CGRect(0, 0, DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT));

            var window = new NSWindow(centerRect, NSWindowStyle.Titled | NSWindowStyle.Closable | NSWindowStyle.Resizable, NSBackingStore.Buffered, true)
            {
                BackgroundColor         = NSColor.Red,
                WeakDelegate            = this,
                AccessibilityIdentifier = "ADAL_SIGN_IN_WINDOW"
            };

            var contentView = window.ContentView;

            contentView.AutoresizesSubviews = true;

            webView = new WebView(contentView.Frame, null, null)
            {
                FrameLoadDelegate       = this,
                PolicyDelegate          = this,
                AutoresizingMask        = NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable,
                AccessibilityIdentifier = "ADAL_SIGN_IN_WEBVIEW"
            };

            contentView.AddSubview(webView);

            progressIndicator = new NSProgressIndicator(new CGRect(DEFAULT_WINDOW_WIDTH / 2 - 16, DEFAULT_WINDOW_HEIGHT / 2 - 16, 32, 32))
            {
                Style = NSProgressIndicatorStyle.Spinning,
                // Keep the item centered in the window even if it's resized.
                AutoresizingMask = NSViewResizingMask.MinXMargin | NSViewResizingMask.MaxXMargin | NSViewResizingMask.MinYMargin | NSViewResizingMask.MaxYMargin
            };

            // On OS X there's a noticable lag between the window showing and the page loading, so starting with the spinner
            // at least make it looks like something is happening.
            progressIndicator.Hidden = false;
            progressIndicator.StartAnimation(null);

            contentView.AddSubview(progressIndicator);

            Window = window;

            webView.MainFrameUrl = url;
        }
Esempio n. 7
0
        void IView.SetViewModel(IViewModel viewModel)
        {
            this.viewModel = viewModel;

            var autoUpdateButton = new NSButton {
                BezelStyle    = NSBezelStyle.SmallSquare,
                Bordered      = true,
                ImagePosition = NSCellImagePosition.ImageOverlaps,
                ImageScaling  = NSImageScale.ProportionallyDown,
                Image         = NSImage.ImageNamed("PendingUpdateNotification.png"),
                Title         = ""
            };

            autoUpdateButton.SetButtonType(NSButtonType.MomentaryPushIn);
            autoUpdateButton.Target = this;
            autoUpdateButton.Action = new ObjCRuntime.Selector("OnRestartButtonClicked:");

            var autoUpdateProgressIndicator = new NSProgressIndicator {
                Style       = NSProgressIndicatorStyle.Spinning,
                ControlSize = NSControlSize.Small
            };

            var updateAutoUpdateButton = Updaters.Create(
                () => viewModel.AutoUpdateButton,
                btn => {
                SetToolbarItemVisibility(pendingUpdateNotificationButton,
                                         btn.state != AutoUpdateButtonState.Hidden);
                NSView view;
                if (btn.state == AutoUpdateButtonState.ProgressIcon)
                {
                    view = autoUpdateProgressIndicator;
                }
                else
                {
                    view = autoUpdateButton;
                }
                if (view == autoUpdateProgressIndicator)
                {
                    autoUpdateProgressIndicator.StartAnimation(this);
                }
                else
                {
                    autoUpdateProgressIndicator.StopAnimation(this);
                }
                view.ToolTip = btn.tooltip;
                pendingUpdateNotificationButton.View = view;
            }
                );

            var updateActiveTab = Updaters.Create(() => viewModel.ActiveTab,
                                                  value => ActivateTab(viewModel.VisibleTabs[value].Id));

            viewModel.ChangeNotification.CreateSubscription(() => {
                updateAutoUpdateButton();
                updateActiveTab();
            });
        }
 void SetProgress(NSProgressIndicator progressBar, int percent)
 {
     if (!NSThread.IsMain)
     {
         InvokeOnMainThread(() => SetProgress(progressBar, percent));
         return;
     }
     ProgressBar.DoubleValue = percent;
 }
        // TODO: Window needs to be made resizable
        public SparkleEventLog()
            : base()
        {
            Title    = "Recent Events";
            Delegate = new SparkleEventsDelegate ();

            SetFrame (new RectangleF (0, 0, 480, 640), true);
            Center ();

            StyleMask = (NSWindowStyle.Closable |
                         NSWindowStyle.Miniaturizable |
                         NSWindowStyle.Titled);

            MaxSize     = new SizeF (480, 640);
            MinSize     = new SizeF (480, 640);
            HasShadow   = true;
            BackingType = NSBackingStore.Buffered;

            ContentView.AddSubview (Separator);

            this.progress_indicator = new NSProgressIndicator () {
                Style = NSProgressIndicatorStyle.Spinning,
                Frame = new RectangleF (this.web_view.Frame.Width / 2 - 10, this.web_view.Frame.Height / 2 + 10, 20, 20)
            };

            this.progress_indicator.StartAnimation (this);
            ContentView.AddSubview (this.progress_indicator);

            UpdateContent (null);
            UpdateChooser (null);
            OrderFrontRegardless ();

            // Hook up the controller events
            this.controller.UpdateChooserEvent += delegate (string [] folders) {
                InvokeOnMainThread (delegate {
                    UpdateChooser (folders);
                });
            };

            this.controller.UpdateContentEvent += delegate (string html) {
                InvokeOnMainThread (delegate {
                    UpdateContent (html);
                });
            };

            this.controller.ContentLoadingEvent += delegate {
                InvokeOnMainThread (delegate {
                    if (this.web_view.Superview == ContentView)
                        this.web_view.RemoveFromSuperview ();

                    ContentView.AddSubview (this.progress_indicator);
                });
            };
        }
Esempio n. 10
0
        public NSView CreateView()
        {
            indicator                        = new NSProgressIndicator();
            indicator.Style                  = NSProgressIndicatorStyle.Bar;
            indicator.ControlSize            = NSControlSize.Regular;
            indicator.IsDisplayedWhenStopped = true;
            indicator.Indeterminate          = false;

            indicator.MinValue = minimum;
            indicator.MaxValue = maximum;

            return(indicator);
        }
        public MacDebuggerObjectValueView(MacObjectValueTreeView treeView) : base(treeView, "value")
        {
            spinner = new NSProgressIndicator(new CGRect(0, 0, ImageSize, ImageSize))
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Style         = NSProgressIndicatorStyle.Spinning,
                Indeterminate = true
            };

            statusIcon = new NSImageView {
                TranslatesAutoresizingMaskIntoConstraints = false
            };

            colorPreview = new NSView(new CGRect(0, 0, ImageSize, ImageSize))
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                WantsLayer = true
            };

            valueButton = new NSButton {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Title      = GettextCatalog.GetString("Show More"),
                BezelStyle = NSBezelStyle.Inline
            };
            valueButton.Cell.UsesSingleLineMode = true;
            UpdateFont(valueButton, -3);
            valueButton.Activated += OnValueButtonActivated;

            int imageSize = treeView.CompactView ? CompactImageSize : ImageSize;

            viewerButton = new NSButton {
                AccessibilityTitle = GettextCatalog.GetString("Open Value Visualizer"),
                Image = GetImage(Gtk.Stock.Edit, imageSize, imageSize),
                TranslatesAutoresizingMaskIntoConstraints = false
            };
            viewerButton.BezelStyle = NSBezelStyle.Inline;
            viewerButton.Bordered   = false;
            viewerButton.Activated += OnViewerButtonActivated;

            TextField = new MacDebuggerTextField(this)
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                LineBreakMode        = NSLineBreakMode.Clipping,
                MaximumNumberOfLines = 1,
                DrawsBackground      = false,
                Bordered             = false,
                Editable             = false
            };

            AddSubview(TextField);
        }
Esempio n. 12
0
        /*
         * void ShowFolderSeletionPage()
         * {
         *  Header = Properties_Resources.Which;
         *  Description = "";
         *  bool firstRepo = true;
         *  Repositories = new List<RootFolder>();
         *  Loader = new Dictionary<string,AsyncNodeLoader> ();
         *  foreach (KeyValuePair<String, String> repository in Controller.repositories)
         *  {
         *      RootFolder repo = new RootFolder() {
         *          Name = repository.Value,
         *          Id = repository.Key,
         *          Address = Controller.saved_address.ToString()
         *      };
         *      Repositories.Add(repo);
         *      if (firstRepo)
         *      {
         *          repo.Selected = true;
         *          firstRepo = false;
         *      }
         *      else
         *      {
         *          repo.Selected = false;
         *      }
         *      CmisRepoCredentials cred = new CmisRepoCredentials()
         *      {
         *          UserName = Controller.saved_user,
         *          Password = Controller.saved_password,
         *          Address = Controller.saved_address,
         *          RepoId = repository.Key
         *      };
         *      AsyncNodeLoader asyncLoader = new AsyncNodeLoader(repo, cred, PredefinedNodeLoader.LoadSubFolderDelegate, PredefinedNodeLoader.CheckSubFolderDelegate);
         *      asyncLoader.UpdateNodeEvent += delegate {
         *          InvokeOnMainThread(delegate {
         *              DataSource.UpdateCmisTree(repo);
         *              NSOutlineView view = OutlineController.OutlineView();
         *              for (int i = 0; i < view.RowCount; ++i) {
         *                  view.ReloadItem(view.ItemAtRow(i));
         *              }
         *          });
         *      };
         *      asyncLoader.Load(repo);
         *      Loader.Add(repo.Id, asyncLoader);
         *  }
         *  DataSource = new CmisTree.CmisTreeDataSource(Repositories);
         *  DataSource.SelectedEvent += delegate (NSCmisTree cmis, int selected) {
         *      InvokeOnMainThread(delegate {
         *          RootFolder selectedRoot = null;
         *          foreach (RootFolder root in Repositories) {
         *              Node node = cmis.GetNode(root);
         *              if (node != null) {
         *                  if (node.Parent == null && node.Selected == false) {
         *                      selectedRoot = root;
         *                  }
         *                  node.Selected = (selected != 0);
         *                  DataSource.UpdateCmisTree(root);
         *              }
         *          }
         *
         *          NSOutlineView view = OutlineController.OutlineView();
         *          if (selectedRoot != null) {
         *              foreach (RootFolder root in Repositories) {
         *                  if (root != selectedRoot) {
         *                      root.Selected = false;
         *                      DataSource.UpdateCmisTree(root);
         *                  }
         *              }
         *              view.ReloadData();
         *          } else {
         *              for (int i = 0; i < view.RowCount; ++i) {
         *                  view.ReloadItem(view.ItemAtRow(i));
         *              }
         *          }
         *      });
         *  };
         *  DataDelegate = new OutlineViewDelegate ();
         *  OutlineController = new CmisOutlineController (DataSource,DataDelegate);
         *  ContinueButton = new NSButton() {
         *      Title = Properties_Resources.Continue,
         *      Enabled = (Repositories.Count > 0)
         *  };
         *  CancelButton = new NSButton() {
         *      Title = Properties_Resources.Cancel
         *  };
         *  NSButton BackButton = new NSButton() {
         *      Title = Properties_Resources.Back
         *  };
         * //            DataDelegate.SelectionChanged += delegate
         * //            {
         * //                InvokeOnMainThread(delegate {
         * //                    NSOutlineView view = OutlineController.OutlineView();
         * //                    if (view.SelectedRow >= 0) {
         * //                        ContinueButton.Enabled = true;
         * //                    } else {
         * //                        ContinueButton.Enabled = false;
         * //                    }
         * //                });
         * //            };
         *  DataDelegate.ItemExpanded += delegate(NSNotification notification)
         *  {
         *      InvokeOnMainThread(delegate {
         *          NSCmisTree cmis = notification.UserInfo["NSObject"] as NSCmisTree;
         *          if (cmis == null) {
         *              Console.WriteLine("ItemExpanded Error");
         *              return;
         *          }
         *
         *          NSCmisTree cmisRoot = cmis;
         *          while (cmisRoot.Parent != null) {
         *              cmisRoot = cmisRoot.Parent;
         *          }
         *          RootFolder root = Repositories.Find(x=>x.Name.Equals(cmisRoot.Name));
         *          if (root == null) {
         *              Console.WriteLine("ItemExpanded find root Error");
         *              return;
         *          }
         *
         *          Node node = cmis.GetNode(root);
         *          if (node == null) {
         *              Console.WriteLine("ItemExpanded find node Error");
         *              return;
         *          }
         *          Loader[root.Id].Load(node);
         *      });
         *  };
         *  ContinueButton.Activated += delegate
         *  {
         *      InvokeOnMainThread(delegate {
         *          NSOutlineView view = OutlineController.OutlineView();
         * //                    NSCmisTree cmis = (NSCmisTree)(view.ItemAtRow(view.SelectedRow));
         * //                    while (cmis.Parent != null)
         * //                        cmis = cmis.Parent;
         * //                    RootFolder root = Repositories.Find(x=>x.Name.Equals(cmis.Name));
         *          RootFolder root = Repositories.Find(x=>(x.Selected != false));
         *          if (root != null)
         *          {
         *              foreach (AsyncNodeLoader task in Loader.Values)
         *                  task.Cancel();
         *              Controller.saved_repository = root.Id;
         *              List<string> ignored = NodeModelUtils.GetIgnoredFolder(root);
         *              List<string> selected = NodeModelUtils.GetSelectedFolder(root);
         *              Controller.Add2PageCompleted(root.Id, root.Path, ignored.ToArray(), selected.ToArray());
         *          }
         *      });
         *  };
         *  CancelButton.Activated += delegate
         *  {
         *      InvokeOnMainThread(delegate
         *      {
         *          foreach (AsyncNodeLoader task in Loader.Values)
         *              task.Cancel();
         *          Controller.PageCancelled();
         *      });
         *  };
         *  BackButton.Activated += delegate
         *  {
         *      InvokeOnMainThread(delegate
         *      {
         *          foreach (AsyncNodeLoader task in Loader.Values)
         *              task.Cancel();
         *          Controller.BackToPage1();
         *      });
         *  };
         *
         *  OutlineController.View.Frame = new RectangleF (190, 60, 400, 240);
         *  ContentView.AddSubview(OutlineController.View);
         *  Buttons.Add(ContinueButton);
         *  Buttons.Add(BackButton);
         *  Buttons.Add(CancelButton);
         * } */

        void ShowSyncingPage()
        {
            Header            = Properties_Resources.AddingFolder + " ‘" + Controller.SyncingReponame + "’…";
            Description       = Properties_Resources.MayTakeTime;
            ProgressIndicator = new NSProgressIndicator()
            {
                Frame         = new RectangleF(190, Frame.Height - 200, 640 - 150 - 80, 20),
                Style         = NSProgressIndicatorStyle.Bar,
                MinValue      = 0.0,
                MaxValue      = 100.0,
                Indeterminate = false,
                DoubleValue   = Controller.ProgressBarPercentage
            };
            ProgressIndicator.StartAnimation(this);
            ContentView.AddSubview(ProgressIndicator);
        }
Esempio n. 13
0
 void InvokeWithProgress(Action<ProgressContext, Action<string, ProgressContext>> action, NSProgressIndicator indicator)
 {
     ProgressContext progress = new ProgressContext();
     progress.Progressing += (sender, eventArgs) => {
         if (eventArgs.Percent < 100) {
             indicator.StartAnimation(this);
         }
         else {
             indicator.StopAnimation(this);
         }
     };
     action(progress, (message, context) => InvokeOnMainThread((NSAction) delegate {
         indicator.StopAnimation(this);
         AppController.OperationFailureHandler(message, context);
     }));
 }
        public BrowseLocalFilesController()
            : base(NSObject.AllocAndInitInstance("BrowseLocalFilesController"))
        {
            Unused.Value = NSBundle.loadNibNamed_owner(NSString.Create("BrowseLocalFiles"), this);

            m_table = new IBOutlet<NSTableView>(this, "table").Value;
            m_table.setDoubleAction("doubleClicked:");
            m_table.setTarget(this);

            m_searchField =  new IBOutlet<NSSearchField>(this, "searchField").Value;
            m_search =  new IBOutlet<NSSearchFieldCell>(this, "search").Value;
            m_spinner =  new IBOutlet<NSProgressIndicator>(this, "progress").Value;

            Broadcaster.Register("opened directory", this);
            Broadcaster.Register("closed directory", this);
            Broadcaster.Register("directory changed", this);
        }
Esempio n. 15
0
        void ShowSyncingPage()
        {
            Header.StringValue      = Properties_Resources.AddingFolder + " ‘" + Controller.SyncingReponame + "’…";
            Description.StringValue = Properties_Resources.MayTakeTime;
            NSProgressIndicator progress = new NSProgressIndicator()
            {
                Frame         = new RectangleF(0, 140, 300, 20),
                Style         = NSProgressIndicatorStyle.Bar,
                MinValue      = 0.0,
                MaxValue      = 100.0,
                Indeterminate = false,
                DoubleValue   = Controller.ProgressBarPercentage
            };

            progress.StartAnimation(this);
            Content.ContentView = progress;
        }
Esempio n. 16
0
        public NSView CreateView()
        {
            indicator                        = new NSProgressIndicator();
            indicator.Style                  = NSProgressIndicatorStyle.Bar;
            indicator.ControlSize            = NSControlSize.Regular;
            indicator.IsDisplayedWhenStopped = true;
            indicator.Indeterminate          = style == ProgressBarStyle.Marquee;

            indicator.MinValue = minimum;
            indicator.MaxValue = maximum;

            if (style == ProgressBarStyle.Marquee)
            {
                indicator.StartAnimation(indicator);
            }

            return(indicator);
        }
Esempio n. 17
0
        public void TableViewDoubleClick(NSObject sender)
        {
//			NSTableView tv = (NSTableView)sender;
//			Console.WriteLine("TableView: {0}", tv);
            ScheduledClass c = scheduleFetcher.ScheduledClasses[(int)tableView.ClickedRow];

//			webPanel = new NSPanel();
            webPanel           = new NSWindow();
            webPanel.StyleMask = NSWindowStyle.Resizable | webPanel.StyleMask;
            webPanel.SetContentSize(new CGSize(Window.ContentView.Frame.Size.Width, 500.0f));
            webView = new WebView(new CGRect(0.0f, 50.0f, Window.ContentView.Frame.Size.Width, 450.0f), "", "");
            webView.AutoresizingMask = NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable;
            webPanel.ContentView.AddSubview(webView);

            webView.WeakResourceLoadDelegate = this;
            webView.WeakFrameLoadDelegate    = this;

            progressBar                  = new NSProgressIndicator(new CGRect(25.0f, 12.0f, Window.ContentView.Frame.Size.Width - 175.0f, 25.0f));
            progressBar.Style            = NSProgressIndicatorStyle.Bar;
            progressBar.Indeterminate    = false;
            progressBar.AutoresizingMask = NSViewResizingMask.WidthSizable;
            webPanel.ContentView.AddSubview(progressBar);
            progressBar.MinValue    = 0;
            progressBar.MaxValue    = 100;
            progressBar.DoubleValue = progress;

            NSButton closebutton = new NSButton(new CGRect(webPanel.Frame.Width - 125.0f, 12.0f, 100.0f, 25.0f));

            closebutton.Title            = "Close";
            closebutton.BezelStyle       = NSBezelStyle.Rounded;
            closebutton.Target           = this;
            closebutton.Action           = new Selector("closePanel:");
            closebutton.AutoresizingMask = NSViewResizingMask.MinXMargin;
            webPanel.DefaultButtonCell   = closebutton.Cell;
            webPanel.ContentView.AddSubview(closebutton);

            webView.MainFrameUrl = c.Href;
//			Window.BeginSheet(webPanel, (nint) => {
//
//			});
            NSApplication.SharedApplication.BeginSheet(webPanel, Window);

            //NSWorkspace.SharedWorkspace.OpenUrl(new NSUrl(c.Href));
        }
Esempio n. 18
0
		public void TableViewDoubleClick(NSObject sender)
		{
//			NSTableView tv = (NSTableView)sender;
//			Console.WriteLine("TableView: {0}", tv);
			ScheduledClass c = scheduleFetcher.ScheduledClasses[(int)tableView.ClickedRow];

//			webPanel = new NSPanel();
			webPanel = new NSWindow();
			webPanel.StyleMask = NSWindowStyle.Resizable | webPanel.StyleMask;
			webPanel.SetContentSize(new CGSize(Window.ContentView.Frame.Size.Width, 500.0f));
			webView = new WebView(new CGRect(0.0f, 50.0f, Window.ContentView.Frame.Size.Width, 450.0f), "", "");
			webView.AutoresizingMask = NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable;
			webPanel.ContentView.AddSubview(webView);

			webView.WeakResourceLoadDelegate = this;
			webView.WeakFrameLoadDelegate = this;

			progressBar = new NSProgressIndicator(new CGRect(25.0f, 12.0f, Window.ContentView.Frame.Size.Width-175.0f, 25.0f));
			progressBar.Style = NSProgressIndicatorStyle.Bar;
			progressBar.Indeterminate = false;
			progressBar.AutoresizingMask = NSViewResizingMask.WidthSizable;
			webPanel.ContentView.AddSubview(progressBar);
			progressBar.MinValue = 0;
			progressBar.MaxValue = 100;
			progressBar.DoubleValue = progress;

			NSButton closebutton = new NSButton(new CGRect(webPanel.Frame.Width - 125.0f, 12.0f, 100.0f, 25.0f));
			closebutton.Title = "Close";
			closebutton.BezelStyle = NSBezelStyle.Rounded;
			closebutton.Target = this;
			closebutton.Action = new Selector("closePanel:");
			closebutton.AutoresizingMask = NSViewResizingMask.MinXMargin;
			webPanel.DefaultButtonCell = closebutton.Cell;
			webPanel.ContentView.AddSubview(closebutton);

			webView.MainFrameUrl = c.Href;
//			Window.BeginSheet(webPanel, (nint) => {
//
//			});
			NSApplication.SharedApplication.BeginSheet(webPanel, Window);

			//NSWorkspace.SharedWorkspace.OpenUrl(new NSUrl(c.Href));
		}
Esempio n. 19
0
		public override void DidFinishLaunching (NSNotification notification)
		{
			mainWindowController = new MainWindowController ();
			mainWindowController.Window.MakeKeyAndOrderFront (this);

			NSProgressIndicator i = new NSProgressIndicator (new CGRect (50, 0, 400, 200));
			i.DoubleValue = 0;
			i.Indeterminate = false;

			double progressValue = 0;
			t = NSTimer.CreateRepeatingScheduledTimer (.5, (timer) => {
				if (!NSThread.Current.IsMainThread)
					throw new System.InvalidOperationException ("NSTimer should invoke on main?");

				if (progressValue >= 100)
					progressValue = 0;
				progressValue += 20;
				i.DoubleValue = progressValue;;
			});

			mainWindowController.Window.ContentView.AddSubview (i);
		}
Esempio n. 20
0
        public SparkleEventLog()
            : base()
        {
            using (var a = new NSAutoreleasePool ())
            {
                Title    = "Recent Changes";
                Delegate = new SparkleEventsDelegate ();

                int min_width  = 480;
                int min_height = 640;
                float x    = (float) (NSScreen.MainScreen.Frame.Width * 0.61);
                float y    = (float) (NSScreen.MainScreen.Frame.Height * 0.5 - (min_height * 0.5));

                SetFrame (
                    new RectangleF (
                        new PointF (x, y),
                        new SizeF (min_width, (int) (NSScreen.MainScreen.Frame.Height * 0.85))),
                    true);

                StyleMask = (NSWindowStyle.Closable | NSWindowStyle.Miniaturizable |
                             NSWindowStyle.Titled | NSWindowStyle.Resizable);

                MinSize        = new SizeF (min_width, min_height);
                HasShadow      = true;
                BackingType    = NSBackingStore.Buffered;
                TitlebarHeight = Frame.Height - ContentView.Frame.Height;

                this.web_view = new WebView (new RectangleF (0, 0, 481, 579), "", "") {
                    Frame = new RectangleF (new PointF (0, 0),
                        new SizeF (ContentView.Frame.Width, ContentView.Frame.Height - 39))
                };

                this.hidden_close_button = new NSButton () {
                    KeyEquivalentModifierMask = NSEventModifierMask.CommandKeyMask,
                    KeyEquivalent = "w"
                };

                this.hidden_close_button.Activated += delegate {
                    Controller.WindowClosed ();
                };

                this.size_label = new NSTextField () {
                    Alignment       = NSTextAlignment.Right,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (
                        new PointF (0, ContentView.Frame.Height - 30),
                        new SizeF (60, 20)),
                    StringValue     = "Size:",
                    Font            = SparkleUI.BoldFont
                };

                this.size_label_value = new NSTextField () {
                    Alignment       = NSTextAlignment.Left,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (
                        new PointF (60, ContentView.Frame.Height - 30),
                        new SizeF (60, 20)),
                    StringValue     = "…",
                    Font            = SparkleUI.Font
                };

                this.history_label = new NSTextField () {
                    Alignment       = NSTextAlignment.Right,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (
                        new PointF (130, ContentView.Frame.Height - 30),
                        new SizeF (60, 20)),
                    StringValue     = "History:",
                    Font            = SparkleUI.BoldFont
                };

                this.history_label_value = new NSTextField () {
                    Alignment       = NSTextAlignment.Left,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (
                        new PointF (190, ContentView.Frame.Height - 30),
                        new SizeF (60, 20)
                    ),
                    StringValue     = "…",
                    Font            = SparkleUI.Font
                };

                this.popup_button = new NSPopUpButton () {
                    Frame = new RectangleF (
                        new PointF (ContentView.Frame.Width - 156 - 12, ContentView.Frame.Height - 33),
                        new SizeF (156, 26)),
                    PullsDown = false
                };

                this.background = new NSBox () {
                    Frame = new RectangleF (
                        new PointF (-1, -1),
                        new SizeF (Frame.Width + 2, this.web_view.Frame.Height + 2)),
                    FillColor = NSColor.White,
                    BorderColor = NSColor.LightGray,
                    BoxType = NSBoxType.NSBoxCustom
                };

                this.progress_indicator = new NSProgressIndicator () {
                    Frame = new RectangleF (
                        new PointF (Frame.Width / 2 - 10, this.web_view.Frame.Height / 2 + 10),
                        new SizeF (20, 20)),
                    Style = NSProgressIndicatorStyle.Spinning
                };

                this.progress_indicator.StartAnimation (this);

                ContentView.AddSubview (this.size_label);
                ContentView.AddSubview (this.size_label_value);
                ContentView.AddSubview (this.history_label);
                ContentView.AddSubview (this.history_label_value);
                ContentView.AddSubview (this.popup_button);
                ContentView.AddSubview (this.progress_indicator);
                ContentView.AddSubview (this.background);
                ContentView.AddSubview (this.hidden_close_button);

                (Delegate as SparkleEventsDelegate).WindowResized += Relayout;
            }

            // Hook up the controller events
            Controller.HideWindowEvent += delegate {
                using (var a = new NSAutoreleasePool ())
                {
                    InvokeOnMainThread (delegate {
                        this.progress_indicator.Hidden = true;
                        PerformClose (this);
                    });
                }
            };

            Controller.ShowWindowEvent += delegate {
                using (var a = new NSAutoreleasePool ())
                {
                    InvokeOnMainThread (delegate {
                        OrderFrontRegardless ();
                    });
                }
            };

            Controller.UpdateChooserEvent += delegate (string [] folders) {
                using (var a = new NSAutoreleasePool ())
                {
                    InvokeOnMainThread (delegate {
                        UpdateChooser (folders);
                    });
                }
            };

            Controller.UpdateChooserEnablementEvent += delegate (bool enabled) {
                using (var a = new NSAutoreleasePool ())
                {
                    InvokeOnMainThread (delegate {
                        this.popup_button.Enabled = enabled;
                    });
                }
            };

            Controller.UpdateContentEvent += delegate (string html) {
                using (var a = new NSAutoreleasePool ())
                {
                    InvokeOnMainThread (delegate {
                        this.progress_indicator.Hidden = true;
                        UpdateContent (html);
                    });
                }
            };

            Controller.ContentLoadingEvent += delegate {
                using (var a = new NSAutoreleasePool ())
                {
                    InvokeOnMainThread (delegate {
                        this.web_view.RemoveFromSuperview ();
                        this.progress_indicator.Hidden = false;

                        this.progress_indicator.StartAnimation (this);
                    });
                }
            };

            Controller.UpdateSizeInfoEvent += delegate (string size, string history_size) {
                using (var a = new NSAutoreleasePool ())
                {
                    InvokeOnMainThread (delegate {
                        this.size_label_value.StringValue    = size;
                        this.history_label_value.StringValue = history_size;
                    });
                }
            };

            Controller.ShowSaveDialogEvent += delegate (string file_name, string target_folder_path) {
                using (var a = new NSAutoreleasePool ())
                {
                    InvokeOnMainThread (() => {
                        // TODO: Make this a sheet
                        NSSavePanel panel = new NSSavePanel () {
                            DirectoryUrl         = new NSUrl (target_folder_path, true),
                            NameFieldStringValue = file_name,
                            ParentWindow         = this,
                            Title                = "Restore from History",
                            PreventsApplicationTerminationWhenModal = false
                        };

                        if ((NSPanelButtonType) panel.RunModal ()== NSPanelButtonType.Ok) {
                            string target_file_path = Path.Combine (panel.DirectoryUrl.RelativePath, panel.NameFieldStringValue);
                            Controller.SaveDialogCompleted (target_file_path);

                        } else {
                            Controller.SaveDialogCancelled ();
                        }
                    });
                }
            };
        }
Esempio n. 21
0
        // TODO: Window needs to be made resizable
        public SparkleEventLog() : base()
        {
            Title    = "Recent Events";
            Delegate = new SparkleEventsDelegate();

            SetFrame(new RectangleF(0, 0, 480, 640), true);
            Center();

            StyleMask = (NSWindowStyle.Closable |
                         NSWindowStyle.Miniaturizable |
                         NSWindowStyle.Titled);

            MaxSize     = new SizeF(480, 640);
            MinSize     = new SizeF(480, 640);
            HasShadow   = true;
            BackingType = NSBackingStore.Buffered;


            this.size_label = new NSTextField()
            {
                Alignment       = NSTextAlignment.Right,
                BackgroundColor = NSColor.WindowBackground,
                Bordered        = false,
                Editable        = false,
                Frame           = new RectangleF(0, 588, 60, 20),
                StringValue     = "Size:",
                Font            = SparkleUI.BoldFont
            };

            this.size_label_value = new NSTextField()
            {
                Alignment       = NSTextAlignment.Left,
                BackgroundColor = NSColor.WindowBackground,
                Bordered        = false,
                Editable        = false,
                Frame           = new RectangleF(60, 588, 75, 20),
                StringValue     = Controller.Size,
                Font            = SparkleUI.Font
            };


            this.history_label = new NSTextField()
            {
                Alignment       = NSTextAlignment.Right,
                BackgroundColor = NSColor.WindowBackground,
                Bordered        = false,
                Editable        = false,
                Frame           = new RectangleF(130, 588, 60, 20),
                StringValue     = "History:",
                Font            = SparkleUI.BoldFont
            };

            this.history_label_value = new NSTextField()
            {
                Alignment       = NSTextAlignment.Left,
                BackgroundColor = NSColor.WindowBackground,
                Bordered        = false,
                Editable        = false,
                Frame           = new RectangleF(190, 588, 75, 20),
                StringValue     = Controller.HistorySize,
                Font            = SparkleUI.Font
            };


            ContentView.AddSubview(this.size_label);
            ContentView.AddSubview(this.size_label_value);
            ContentView.AddSubview(this.history_label);
            ContentView.AddSubview(this.history_label_value);
            ContentView.AddSubview(this.separator);


            this.progress_indicator = new NSProgressIndicator()
            {
                Style = NSProgressIndicatorStyle.Spinning,
                Frame = new RectangleF(this.web_view.Frame.Width / 2 - 10, this.web_view.Frame.Height / 2 + 10, 20, 20)
            };

            this.progress_indicator.StartAnimation(this);
            ContentView.AddSubview(this.progress_indicator);


            UpdateContent(null);
            UpdateChooser(null);
            OrderFrontRegardless();


            // Hook up the controller events
            Controller.UpdateChooserEvent += delegate(string [] folders) {
                InvokeOnMainThread(delegate {
                    UpdateChooser(folders);
                });
            };

            Controller.UpdateContentEvent += delegate(string html) {
                InvokeOnMainThread(delegate {
                    UpdateContent(html);
                });
            };

            Controller.ContentLoadingEvent += delegate {
                InvokeOnMainThread(delegate {
                    if (this.web_view.Superview == ContentView)
                    {
                        this.web_view.RemoveFromSuperview();
                    }

                    ContentView.AddSubview(this.progress_indicator);
                });
            };

            Controller.UpdateSizeInfoEvent += delegate(string size, string history_size) {
                InvokeOnMainThread(delegate {
                    this.size_label_value.StringValue    = size;
                    this.history_label_value.StringValue = history_size;
                });
            };
        }
Esempio n. 22
0
        public SparkleEventLog() : base()
        {
            using (var a = new NSAutoreleasePool())
            {
                Title    = "Recent Changes";
                Delegate = new SparkleEventsDelegate();

                int   min_width  = 480;
                int   min_height = 640;
                float x          = (float)(NSScreen.MainScreen.Frame.Width * 0.61);
                float y          = (float)(NSScreen.MainScreen.Frame.Height * 0.5 - (min_height * 0.5));

                SetFrame(
                    new RectangleF(
                        new PointF(x, y),
                        new SizeF(min_width, (int)(NSScreen.MainScreen.Frame.Height * 0.85))),
                    true);

                StyleMask = (NSWindowStyle.Closable |
                             NSWindowStyle.Miniaturizable |
                             NSWindowStyle.Titled |
                             NSWindowStyle.Resizable);

                MinSize        = new SizeF(min_width, min_height);
                HasShadow      = true;
                BackingType    = NSBackingStore.Buffered;
                TitlebarHeight = Frame.Height - ContentView.Frame.Height;


                this.web_view = new WebView(new RectangleF(0, 0, 481, 579), "", "")
                {
                    Frame = new RectangleF(new PointF(0, 0),
                                           new SizeF(ContentView.Frame.Width, ContentView.Frame.Height - 39))
                };

                this.hidden_close_button = new NSButton()
                {
                    KeyEquivalentModifierMask = NSEventModifierMask.CommandKeyMask,
                    KeyEquivalent             = "w"
                };

                this.hidden_close_button.Activated += delegate {
                    Controller.WindowClosed();
                };


                this.size_label = new NSTextField()
                {
                    Alignment       = NSTextAlignment.Right,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF(
                        new PointF(0, ContentView.Frame.Height - 30),
                        new SizeF(60, 20)),
                    StringValue = "Size:",
                    Font        = SparkleUI.BoldFont
                };

                this.size_label_value = new NSTextField()
                {
                    Alignment       = NSTextAlignment.Left,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF(
                        new PointF(60, ContentView.Frame.Height - 30),
                        new SizeF(60, 20)),
                    StringValue = "…",
                    Font        = SparkleUI.Font
                };


                this.history_label = new NSTextField()
                {
                    Alignment       = NSTextAlignment.Right,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF(
                        new PointF(130, ContentView.Frame.Height - 30),
                        new SizeF(60, 20)),
                    StringValue = "History:",
                    Font        = SparkleUI.BoldFont
                };

                this.history_label_value = new NSTextField()
                {
                    Alignment       = NSTextAlignment.Left,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF(
                        new PointF(190, ContentView.Frame.Height - 30),
                        new SizeF(60, 20)
                        ),
                    StringValue = "…",
                    Font        = SparkleUI.Font
                };

                this.popup_button = new NSPopUpButton()
                {
                    Frame = new RectangleF(
                        new PointF(ContentView.Frame.Width - 156 - 12, ContentView.Frame.Height - 33),
                        new SizeF(156, 26)),
                    PullsDown = false
                };

                this.background = new NSBox()
                {
                    Frame = new RectangleF(
                        new PointF(-1, -1),
                        new SizeF(Frame.Width + 2, this.web_view.Frame.Height + 2)),
                    FillColor   = NSColor.White,
                    BorderColor = NSColor.LightGray,
                    BoxType     = NSBoxType.NSBoxCustom
                };

                this.progress_indicator = new NSProgressIndicator()
                {
                    Frame = new RectangleF(
                        new PointF(Frame.Width / 2 - 10, this.web_view.Frame.Height / 2 + 10),
                        new SizeF(20, 20)),
                    Style = NSProgressIndicatorStyle.Spinning
                };

                this.progress_indicator.StartAnimation(this);

                ContentView.AddSubview(this.size_label);
                ContentView.AddSubview(this.size_label_value);
                ContentView.AddSubview(this.history_label);
                ContentView.AddSubview(this.history_label_value);
                ContentView.AddSubview(this.popup_button);
                ContentView.AddSubview(this.progress_indicator);
                ContentView.AddSubview(this.background);
                ContentView.AddSubview(this.hidden_close_button);

                (Delegate as SparkleEventsDelegate).WindowResized += Relayout;
            }


            // Hook up the controller events
            Controller.HideWindowEvent += delegate {
                using (var a = new NSAutoreleasePool())
                {
                    InvokeOnMainThread(delegate {
                        PerformClose(this);

                        if (this.web_view.Superview == ContentView)
                        {
                            this.web_view.RemoveFromSuperview();
                        }
                    });
                }
            };

            Controller.ShowWindowEvent += delegate {
                using (var a = new NSAutoreleasePool())
                {
                    InvokeOnMainThread(delegate {
                        OrderFrontRegardless();
                    });
                }
            };

            Controller.UpdateChooserEvent += delegate(string [] folders) {
                using (var a = new NSAutoreleasePool())
                {
                    InvokeOnMainThread(delegate {
                        UpdateChooser(folders);
                    });
                }
            };

            Controller.UpdateContentEvent += delegate(string html) {
                using (var a = new NSAutoreleasePool())
                {
                    InvokeOnMainThread(delegate {
                        UpdateContent(html);
                    });
                }
            };

            Controller.ContentLoadingEvent += delegate {
                using (var a = new NSAutoreleasePool())
                {
                    InvokeOnMainThread(delegate {
                        if (this.web_view.Superview == ContentView)
                        {
                            this.web_view.RemoveFromSuperview();
                        }

                        if (this.progress_indicator.Superview != ContentView)
                        {
                            ContentView.AddSubview(this.progress_indicator);
                        }

                        this.progress_indicator.StartAnimation(this);
                    });
                }
            };

            Controller.UpdateSizeInfoEvent += delegate(string size, string history_size) {
                using (var a = new NSAutoreleasePool())
                {
                    InvokeOnMainThread(delegate {
                        this.size_label_value.StringValue    = size;
                        this.history_label_value.StringValue = history_size;
                    });
                }
            };
        }
Esempio n. 23
0
        public SparkleSetup() : base()
        {
            Controller.ChangePageEvent += delegate(PageType type, string [] warnings) {
                InvokeOnMainThread(delegate {
                    Reset();

                    switch (type)
                    {
                    case PageType.Setup: {
                        Header      = "Welcome to SparkleShare!";
                        Description = "We'll need some info to mark your changes in the event log. " +
                                      "Don't worry, this stays between you and your peers.";


                        FullNameLabel = new NSTextField()
                        {
                            Alignment       = NSTextAlignment.Right,
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            Editable        = false,
                            Frame           = new RectangleF(165, Frame.Height - 234, 160, 17),
                            StringValue     = "Full Name:",
                            Font            = SparkleUI.Font
                        };

                        FullNameTextField = new NSTextField()
                        {
                            Frame       = new RectangleF(330, Frame.Height - 238, 196, 22),
                            StringValue = Controller.GuessedUserName,
                            Delegate    = new SparkleTextFieldDelegate()
                        };

                        EmailLabel = new NSTextField()
                        {
                            Alignment       = NSTextAlignment.Right,
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            Editable        = false,
                            Frame           = new RectangleF(165, Frame.Height - 264, 160, 17),
                            StringValue     = "Email:",
                            Font            = SparkleUI.Font
                        };

                        EmailTextField = new NSTextField()
                        {
                            Frame       = new RectangleF(330, Frame.Height - 268, 196, 22),
                            StringValue = Controller.GuessedUserEmail,
                            Delegate    = new SparkleTextFieldDelegate()
                        };


                        (FullNameTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                            Controller.CheckSetupPage(
                                FullNameTextField.StringValue,
                                EmailTextField.StringValue
                                );
                        };

                        (EmailTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                            Controller.CheckSetupPage(
                                FullNameTextField.StringValue,
                                EmailTextField.StringValue
                                );
                        };


                        ContinueButton = new NSButton()
                        {
                            Title   = "Continue",
                            Enabled = false
                        };

                        ContinueButton.Activated += delegate {
                            string full_name = FullNameTextField.StringValue.Trim();
                            string email     = EmailTextField.StringValue.Trim();

                            Controller.SetupPageCompleted(full_name, email);
                        };

                        Controller.UpdateSetupContinueButtonEvent += delegate(bool button_enabled) {
                            InvokeOnMainThread(delegate {
                                    ContinueButton.Enabled = button_enabled;
                                });
                        };


                        ContentView.AddSubview(FullNameLabel);
                        ContentView.AddSubview(FullNameTextField);
                        ContentView.AddSubview(EmailLabel);
                        ContentView.AddSubview(EmailTextField);

                        Buttons.Add(ContinueButton);

                        Controller.CheckSetupPage(
                            FullNameTextField.StringValue,
                            EmailTextField.StringValue
                            );

                        break;
                    }

                    case PageType.Add: {
                        Header      = "Where's your project hosted?";
                        Description = "";

                        AddressLabel = new NSTextField()
                        {
                            Alignment       = NSTextAlignment.Left,
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            Editable        = false,
                            Frame           = new RectangleF(190, Frame.Height - 308, 160, 17),
                            StringValue     = "Address:",
                            Font            = SparkleUI.Font
                        };

                        AddressTextField = new NSTextField()
                        {
                            Frame       = new RectangleF(190, Frame.Height - 336, 196, 22),
                            Font        = SparkleUI.Font,
                            StringValue = Controller.PreviousAddress,
                            Enabled     = (Controller.SelectedPlugin.Address == null),
                            Delegate    = new SparkleTextFieldDelegate()
                        };


                        PathLabel = new NSTextField()
                        {
                            Alignment       = NSTextAlignment.Left,
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            Editable        = false,
                            Frame           = new RectangleF(190 + 196 + 16, Frame.Height - 308, 160, 17),
                            StringValue     = "Remote Path:",
                            Font            = SparkleUI.Font
                        };

                        PathTextField = new NSTextField()
                        {
                            Frame       = new RectangleF(190 + 196 + 16, Frame.Height - 336, 196, 22),
                            StringValue = Controller.PreviousPath,
                            Enabled     = (Controller.SelectedPlugin.Path == null),
                            Delegate    = new SparkleTextFieldDelegate()
                        };


                        AddressTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;
                        PathTextField.Cell.LineBreakMode    = NSLineBreakMode.TruncatingTail;


                        PathHelpLabel = new NSTextField()
                        {
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            TextColor       = NSColor.DisabledControlText,
                            Editable        = false,
                            Frame           = new RectangleF(190 + 196 + 16, Frame.Height - 355, 204, 17),
                            StringValue     = "e.g. ‘rupert/website-design’",
                            Font            = NSFontManager.SharedFontManager.FontWithFamily
                                                  ("Lucida Grande", NSFontTraitMask.Condensed, 0, 11)
                        };


                        TableView = new NSTableView()
                        {
                            Frame            = new RectangleF(0, 0, 0, 0),
                            RowHeight        = 30,
                            IntercellSpacing = new SizeF(0, 12),
                            HeaderView       = null,
                            Delegate         = new SparkleTableViewDelegate()
                        };

                        ScrollView = new NSScrollView()
                        {
                            Frame               = new RectangleF(190, Frame.Height - 280, 408, 175),
                            DocumentView        = TableView,
                            HasVerticalScroller = true,
                            BorderType          = NSBorderType.BezelBorder
                        };

                        IconColumn = new NSTableColumn(new NSImage())
                        {
                            Width         = 42,
                            HeaderToolTip = "Icon",
                            DataCell      = new NSImageCell()
                        };

                        DescriptionColumn = new NSTableColumn()
                        {
                            Width         = 350,
                            HeaderToolTip = "Description",
                            Editable      = false
                        };

                        DescriptionColumn.DataCell.Font =
                            NSFontManager.SharedFontManager.FontWithFamily(
                                "Lucida Grande", NSFontTraitMask.Condensed, 0, 11);

                        TableView.AddColumn(IconColumn);
                        TableView.AddColumn(DescriptionColumn);

                        DataSource = new SparkleDataSource();

                        foreach (SparklePlugin plugin in Controller.Plugins)
                        {
                            DataSource.Items.Add(plugin);
                        }

                        TableView.DataSource = DataSource;
                        TableView.ReloadData();


                        Controller.ChangeAddressFieldEvent += delegate(string text,
                                                                       string example_text, FieldState state) {
                            InvokeOnMainThread(delegate {
                                    AddressTextField.StringValue = text;
                                    AddressTextField.Enabled     = (state == FieldState.Enabled);
                                });
                        };


                        Controller.ChangePathFieldEvent += delegate(string text,
                                                                    string example_text, FieldState state) {
                            InvokeOnMainThread(delegate {
                                    PathTextField.StringValue = text;
                                    PathTextField.Enabled     = (state == FieldState.Enabled);

                                    if (!string.IsNullOrEmpty(example_text))
                                    {
                                        PathHelpLabel.StringValue = "e.g. " + example_text;
                                    }
                                });
                        };


                        TableView.SelectRow(Controller.SelectedPluginIndex, false);


                        (AddressTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                            Controller.CheckAddPage(
                                AddressTextField.StringValue,
                                PathTextField.StringValue,
                                TableView.SelectedRow
                                );
                        };

                        (PathTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                            Controller.CheckAddPage(
                                AddressTextField.StringValue,
                                PathTextField.StringValue,
                                TableView.SelectedRow
                                );
                        };

                        (TableView.Delegate as SparkleTableViewDelegate).SelectionChanged += delegate {
                            Controller.SelectedPluginChanged(TableView.SelectedRow);

                            Controller.CheckAddPage(
                                AddressTextField.StringValue,
                                PathTextField.StringValue,
                                TableView.SelectedRow
                                );
                        };


                        Controller.UpdateAddProjectButtonEvent += delegate(bool button_enabled) {
                            InvokeOnMainThread(delegate {
                                    SyncButton.Enabled = button_enabled;
                                });
                        };


                        ContentView.AddSubview(ScrollView);
                        ContentView.AddSubview(AddressLabel);
                        ContentView.AddSubview(AddressTextField);
                        ContentView.AddSubview(PathLabel);
                        ContentView.AddSubview(PathTextField);
                        ContentView.AddSubview(PathHelpLabel);

                        SyncButton = new NSButton()
                        {
                            Title   = "Add",
                            Enabled = false
                        };

                        SyncButton.Activated += delegate {
                            Controller.AddPageCompleted(
                                AddressTextField.StringValue,
                                PathTextField.StringValue
                                );
                        };

                        Buttons.Add(SyncButton);

                        CancelButton = new NSButton()
                        {
                            Title = "Cancel"
                        };

                        CancelButton.Activated += delegate {
                            InvokeOnMainThread(delegate {
                                    PerformClose(this);
                                });
                        };

                        Buttons.Add(CancelButton);

                        Controller.CheckAddPage(
                            AddressTextField.StringValue,
                            PathTextField.StringValue,
                            TableView.SelectedRow
                            );


                        break;
                    }

                    case PageType.Syncing: {
                        Header      = "Adding project ‘" + Controller.SyncingFolder + "’…";
                        Description = "This may take a while.\n" +
                                      "Are you sure it’s not coffee o'clock?";

                        ProgressIndicator = new NSProgressIndicator()
                        {
                            Frame         = new RectangleF(190, Frame.Height - 200, 640 - 150 - 80, 20),
                            Style         = NSProgressIndicatorStyle.Bar,
                            MinValue      = 0.0,
                            MaxValue      = 100.0,
                            Indeterminate = false,
                            DoubleValue   = 1.0
                        };

                        ProgressIndicator.StartAnimation(this);

                        Controller.UpdateProgressBarEvent += delegate(double percentage) {
                            InvokeOnMainThread(delegate {
                                    ProgressIndicator.DoubleValue = percentage;
                                });
                        };

                        ContentView.AddSubview(ProgressIndicator);

                        FinishButton = new NSButton()
                        {
                            Title   = "Finish",
                            Enabled = false
                        };

                        CancelButton = new NSButton()
                        {
                            Title = "Cancel"
                        };

                        CancelButton.Activated += delegate {
                            Controller.SyncingCancelled();
                        };

                        Buttons.Add(FinishButton);
                        Buttons.Add(CancelButton);

                        break;
                    }

                    case PageType.Error: {
                        Header      = "Something went wrong…";
                        Description = "Please check the following:";

                        // Displaying marked up text with Cocoa is
                        // a pain, so we just use a webview instead
                        WebView web_view = new WebView();
                        web_view.Frame   = new RectangleF(190, Frame.Height - 525, 375, 400);

                        string html = "<style>" +
                                      "* {" +
                                      "  font-family: 'Lucida Grande';" +
                                      "  font-size: 12px; cursor: default;" +
                                      "}" +
                                      "body {" +
                                      "  -webkit-user-select: none;" +
                                      "  margin: 0;" +
                                      "  padding: 3px;" +
                                      "}" +
                                      "li {" +
                                      "  margin-bottom: 16px;" +
                                      "  margin-left: 0;" +
                                      "  padding-left: 0;" +
                                      "  line-height: 20px;" +
                                      "}" +
                                      "ul {" +
                                      "  padding-left: 24px;" +
                                      "}" +
                                      "</style>" +
                                      "<ul>" +
                                      "  <li>First, have you tried turning it off and on again?</li>" +
                                      "  <li><b>" + Controller.PreviousUrl + "</b> is the address we've compiled. Does this look alright?</li>" +
                                      "  <li>The host needs to know who you are. Did you upload the key that's in your SparkleShare folder?</li>" +
                                      "</ul>";

                        web_view.MainFrame.LoadHtmlString(html, new NSUrl(""));
                        web_view.DrawsBackground = false;

                        ContentView.AddSubview(web_view);

                        TryAgainButton = new NSButton()
                        {
                            Title = "Try again…"
                        };

                        TryAgainButton.Activated += delegate {
                            Controller.ErrorPageCompleted();
                        };

                        Buttons.Add(TryAgainButton);

                        break;
                    }

                    case PageType.Finished: {
                        Header      = "Project succesfully added!";
                        Description = "Now you can access the files from " +
                                      "‘" + Controller.SyncingFolder + "’ in " +
                                      "your SparkleShare folder.";

                        if (warnings != null)
                        {
                            WarningImage      = NSImage.ImageNamed("NSCaution");
                            WarningImage.Size = new SizeF(24, 24);

                            WarningImageView = new NSImageView()
                            {
                                Image = WarningImage,
                                Frame = new RectangleF(190, Frame.Height - 175, 24, 24)
                            };

                            WarningTextField = new NSTextField()
                            {
                                Frame           = new RectangleF(230, Frame.Height - 245, 325, 100),
                                StringValue     = warnings [0],
                                BackgroundColor = NSColor.WindowBackground,
                                Bordered        = false,
                                Editable        = false,
                                Font            = SparkleUI.Font
                            };

                            ContentView.AddSubview(WarningImageView);
                            ContentView.AddSubview(WarningTextField);
                        }

                        FinishButton = new NSButton()
                        {
                            Title = "Finish"
                        };

                        FinishButton.Activated += delegate {
                            InvokeOnMainThread(delegate {
                                    Controller.FinishedPageCompleted();
                                    PerformClose(this);
                                });
                        };

                        OpenFolderButton = new NSButton()
                        {
                            Title = "Open Folder"
                        };

                        OpenFolderButton.Activated += delegate {
                            Program.Controller.OpenSparkleShareFolder(Controller.SyncingFolder);
                        };

                        Buttons.Add(FinishButton);
                        Buttons.Add(OpenFolderButton);

                        NSApplication.SharedApplication.RequestUserAttention
                            (NSRequestUserAttentionType.CriticalRequest);

                        NSSound.FromName("Glass").Play();

                        break;
                    }

                    case PageType.Tutorial: {
                        switch (Controller.TutorialPageNumber)
                        {
                        case 1: {
                            Header      = "What's happening next?";
                            Description = "SparkleShare creates a special folder in your personal folder " +
                                          "that will keep track of your projects.";

                            SkipTutorialButton = new NSButton()
                            {
                                Title = "Skip Tutorial"
                            };

                            SkipTutorialButton.Activated += delegate {
                                Controller.TutorialSkipped();
                            };

                            ContinueButton = new NSButton()
                            {
                                Title = "Continue"
                            };

                            ContinueButton.Activated += delegate {
                                Controller.TutorialPageCompleted();
                            };

                            string slide_image_path = Path.Combine(NSBundle.MainBundle.ResourcePath,
                                                                   "Pixmaps", "tutorial-slide-1-mac.png");

                            SlideImage = new NSImage(slide_image_path)
                            {
                                Size = new SizeF(350, 200)
                            };

                            SlideImageView = new NSImageView()
                            {
                                Image = SlideImage,
                                Frame = new RectangleF(215, Frame.Height - 350, 350, 200)
                            };

                            ContentView.AddSubview(SlideImageView);
                            Buttons.Add(ContinueButton);
                            Buttons.Add(SkipTutorialButton);

                            break;
                        }

                        case 2: {
                            Header      = "Sharing files with others";
                            Description = "All files added to your project folders are synced with the host " +
                                          "automatically, as well as with your collaborators.";

                            ContinueButton = new NSButton()
                            {
                                Title = "Continue"
                            };

                            ContinueButton.Activated += delegate {
                                Controller.TutorialPageCompleted();
                            };

                            string slide_image_path = Path.Combine(NSBundle.MainBundle.ResourcePath,
                                                                   "Pixmaps", "tutorial-slide-2-mac.png");

                            SlideImage = new NSImage(slide_image_path)
                            {
                                Size = new SizeF(350, 200)
                            };

                            SlideImageView = new NSImageView()
                            {
                                Image = SlideImage,
                                Frame = new RectangleF(215, Frame.Height - 350, 350, 200)
                            };

                            ContentView.AddSubview(SlideImageView);
                            Buttons.Add(ContinueButton);

                            break;
                        }

                        case 3: {
                            Header      = "The status icon is here to help";
                            Description = "It shows the syncing process status, " +
                                          "and contains links to your projects and the event log.";

                            ContinueButton = new NSButton()
                            {
                                Title = "Continue"
                            };

                            ContinueButton.Activated += delegate {
                                Controller.TutorialPageCompleted();
                            };

                            string slide_image_path = Path.Combine(NSBundle.MainBundle.ResourcePath,
                                                                   "Pixmaps", "tutorial-slide-3-mac.png");

                            SlideImage = new NSImage(slide_image_path)
                            {
                                Size = new SizeF(350, 200)
                            };

                            SlideImageView = new NSImageView()
                            {
                                Image = SlideImage,
                                Frame = new RectangleF(215, Frame.Height - 350, 350, 200)
                            };

                            ContentView.AddSubview(SlideImageView);
                            Buttons.Add(ContinueButton);

                            break;
                        }

                        case 4: {
                            Header      = "Adding projects to SparkleShare";
                            Description = "Just click this button when you see it on the web, and " +
                                          "the project will be automatically added:";

                            AddProjectTextField = new NSTextField()
                            {
                                Frame           = new RectangleF(190, Frame.Height - 290, 640 - 240, 44),
                                BackgroundColor = NSColor.WindowBackground,
                                Bordered        = false,
                                Editable        = false,
                                Font            = SparkleUI.Font,
                                StringValue     = "…or select ‘Add Hosted Project…’ from the status icon menu " +
                                                  "to add one by hand."
                            };

                            FinishButton = new NSButton()
                            {
                                Title = "Finish"
                            };

                            FinishButton.Activated += delegate {
                                InvokeOnMainThread(delegate {
                                            PerformClose(this);
                                        });
                            };

                            string slide_image_path = Path.Combine(NSBundle.MainBundle.ResourcePath,
                                                                   "Pixmaps", "tutorial-slide-4.png");

                            SlideImage = new NSImage(slide_image_path)
                            {
                                Size = new SizeF(350, 64)
                            };

                            SlideImageView = new NSImageView()
                            {
                                Image = SlideImage,
                                Frame = new RectangleF(215, Frame.Height - 215, 350, 64)
                            };

                            ContentView.AddSubview(SlideImageView);
                            ContentView.AddSubview(AddProjectTextField);
                            Buttons.Add(FinishButton);

                            break;
                        }
                        }

                        break;
                    }
                    }

                    ShowAll();
                });
            };
        }
Esempio n. 24
0
        public void ShowPage(PageType type, string [] warnings)
        {
            if (type == PageType.Setup)
            {
                Header      = "Welcome to SparkleShare!";
                Description = "First off, what's your name and email?\n(visible only to team members)";


                FullNameLabel = new NSTextField()
                {
                    Alignment       = NSTextAlignment.Right,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF(165, Frame.Height - 234, 160, 17),
                    StringValue     = "Full Name:",
                    Font            = SparkleUI.Font
                };

                FullNameTextField = new NSTextField()
                {
                    Frame       = new RectangleF(330, Frame.Height - 238, 196, 22),
                    StringValue = UnixUserInfo.GetRealUser().RealName,
                    Delegate    = new SparkleTextFieldDelegate()
                };

                EmailLabel = new NSTextField()
                {
                    Alignment       = NSTextAlignment.Right,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF(165, Frame.Height - 264, 160, 17),
                    StringValue     = "Email:",
                    Font            = SparkleUI.Font
                };

                EmailTextField = new NSTextField()
                {
                    Frame    = new RectangleF(330, Frame.Height - 268, 196, 22),
                    Delegate = new SparkleTextFieldDelegate()
                };

                EmailHelpLabel = new NSTextField()
                {
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    TextColor       = NSColor.DisabledControlText,
                    Editable        = false,
                    Frame           = new RectangleF(330, Frame.Height - 290, 204, 17),
                    Font            = NSFontManager.SharedFontManager.FontWithFamily("Lucida Grande",
                                                                                     NSFontTraitMask.Condensed, 0, 11),
                    StringValue = "(used to find your Gravatar)"
                };



                CancelButton = new NSButton()
                {
                    Title = "Cancel"
                };

                ContinueButton = new NSButton()
                {
                    Title   = "Continue",
                    Enabled = false
                };


                (FullNameTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckSetupPage(FullNameTextField.StringValue, EmailTextField.StringValue);
                };

                (EmailTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckSetupPage(FullNameTextField.StringValue, EmailTextField.StringValue);
                };

                ContinueButton.Activated += delegate {
                    string full_name = FullNameTextField.StringValue.Trim();
                    string email     = EmailTextField.StringValue.Trim();

                    Controller.SetupPageCompleted(full_name, email);
                };

                CancelButton.Activated += delegate {
                    Controller.SetupPageCancelled();
                };

                Controller.UpdateSetupContinueButtonEvent += delegate(bool button_enabled) {
                    InvokeOnMainThread(delegate {
                        ContinueButton.Enabled = button_enabled;
                    });
                };


                ContentView.AddSubview(FullNameLabel);
                ContentView.AddSubview(FullNameTextField);
                ContentView.AddSubview(EmailLabel);
                ContentView.AddSubview(EmailTextField);
                ContentView.AddSubview(EmailHelpLabel);

                Buttons.Add(ContinueButton);
                Buttons.Add(CancelButton);

                Controller.CheckSetupPage(FullNameTextField.StringValue, EmailTextField.StringValue);
            }

            if (type == PageType.Invite)
            {
                Header      = "You've received an invite!";
                Description = "Do you want to add this project to SparkleShare?";


                AddressLabel = new NSTextField()
                {
                    Alignment       = NSTextAlignment.Right,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF(165, Frame.Height - 240, 160, 17),
                    StringValue     = "Address:",
                    Font            = SparkleUI.Font
                };

                PathLabel = new NSTextField()
                {
                    Alignment       = NSTextAlignment.Right,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF(165, Frame.Height - 264, 160, 17),
                    StringValue     = "Remote Path:",
                    Font            = SparkleUI.Font
                };

                AddressTextField = new NSTextField()
                {
                    Alignment       = NSTextAlignment.Left,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF(330, Frame.Height - 240, 260, 17),
                    StringValue     = Controller.PendingInvite.Address,
                    Font            = SparkleUI.BoldFont
                };

                PathTextField = new NSTextField()
                {
                    Alignment       = NSTextAlignment.Left,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF(330, Frame.Height - 264, 260, 17),
                    StringValue     = Controller.PendingInvite.RemotePath,
                    Font            = SparkleUI.BoldFont
                };

                CancelButton = new NSButton()
                {
                    Title = "Cancel"
                };

                AddButton = new NSButton()
                {
                    Title = "Add"
                };


                CancelButton.Activated += delegate {
                    Controller.PageCancelled();
                };

                AddButton.Activated += delegate {
                    Controller.InvitePageCompleted();
                };


                ContentView.AddSubview(AddressLabel);
                ContentView.AddSubview(PathLabel);
                ContentView.AddSubview(AddressTextField);
                ContentView.AddSubview(PathTextField);

                Buttons.Add(AddButton);
                Buttons.Add(CancelButton);
            }

            if (type == PageType.Add)
            {
                Header      = "Where's your project hosted?";
                Description = "";


                AddressLabel = new NSTextField()
                {
                    Alignment       = NSTextAlignment.Left,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF(190, Frame.Height - 308, 160, 17),
                    StringValue     = "Address:",
                    Font            = SparkleUI.BoldFont
                };

                AddressTextField = new NSTextField()
                {
                    Frame       = new RectangleF(190, Frame.Height - 336, 196, 22),
                    Font        = SparkleUI.Font,
                    Enabled     = (Controller.SelectedPlugin.Address == null),
                    Delegate    = new SparkleTextFieldDelegate(),
                    StringValue = "" + Controller.PreviousAddress
                };

                AddressTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;

                PathLabel = new NSTextField()
                {
                    Alignment       = NSTextAlignment.Left,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF(190 + 196 + 16, Frame.Height - 308, 160, 17),
                    StringValue     = "Remote Path:",
                    Font            = SparkleUI.BoldFont
                };

                PathTextField = new NSTextField()
                {
                    Frame       = new RectangleF(190 + 196 + 16, Frame.Height - 336, 196, 22),
                    Enabled     = (Controller.SelectedPlugin.Path == null),
                    Delegate    = new SparkleTextFieldDelegate(),
                    StringValue = "" + Controller.PreviousPath
                };

                PathTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;

                PathHelpLabel = new NSTextField()
                {
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    TextColor       = NSColor.DisabledControlText,
                    Editable        = false,
                    Frame           = new RectangleF(190 + 196 + 16, Frame.Height - 355, 204, 17),
                    Font            = NSFontManager.SharedFontManager.FontWithFamily("Lucida Grande",
                                                                                     NSFontTraitMask.Condensed, 0, 11),
                    StringValue = "" + Controller.SelectedPlugin.PathExample
                };

                AddressHelpLabel = new NSTextField()
                {
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    TextColor       = NSColor.DisabledControlText,
                    Editable        = false,
                    Frame           = new RectangleF(190, Frame.Height - 355, 204, 17),
                    Font            = NSFontManager.SharedFontManager.FontWithFamily("Lucida Grande",
                                                                                     NSFontTraitMask.Condensed, 0, 11),
                    StringValue = "" + Controller.SelectedPlugin.AddressExample
                };

                TableView = new NSTableView()
                {
                    Frame            = new RectangleF(0, 0, 0, 0),
                    RowHeight        = 34,
                    IntercellSpacing = new SizeF(8, 12),
                    HeaderView       = null,
                    Delegate         = new SparkleTableViewDelegate()
                };

                ScrollView = new NSScrollView()
                {
                    Frame               = new RectangleF(190, Frame.Height - 280, 408, 185),
                    DocumentView        = TableView,
                    HasVerticalScroller = true,
                    BorderType          = NSBorderType.BezelBorder
                };

                IconColumn = new NSTableColumn(new NSImage())
                {
                    Width         = 36,
                    HeaderToolTip = "Icon",
                    DataCell      = new NSImageCell()
                    {
                        ImageAlignment = NSImageAlignment.Right
                    }
                };

                DescriptionColumn = new NSTableColumn()
                {
                    Width         = 350,
                    HeaderToolTip = "Description",
                    Editable      = false
                };

                DescriptionColumn.DataCell.Font = NSFontManager.SharedFontManager.FontWithFamily("Lucida Grande",
                                                                                                 NSFontTraitMask.Condensed, 0, 11);

                TableView.AddColumn(IconColumn);
                TableView.AddColumn(DescriptionColumn);

                DataSource = new SparkleDataSource(Controller.Plugins);

                TableView.DataSource = DataSource;
                TableView.ReloadData();

                HistoryCheckButton = new NSButton()
                {
                    Frame = new RectangleF(190, Frame.Height - 400, 300, 18),
                    Title = "Fetch prior revisions"
                };

                if (Controller.FetchPriorHistory)
                {
                    HistoryCheckButton.State = NSCellStateValue.On;
                }

                HistoryCheckButton.SetButtonType(NSButtonType.Switch);

                AddButton = new NSButton()
                {
                    Title   = "Add",
                    Enabled = false
                };

                CancelButton = new NSButton()
                {
                    Title = "Cancel"
                };


                Controller.ChangeAddressFieldEvent += delegate(string text,
                                                               string example_text, FieldState state) {
                    InvokeOnMainThread(delegate {
                        AddressTextField.StringValue = text;
                        AddressTextField.Enabled     = (state == FieldState.Enabled);
                        AddressHelpLabel.StringValue = example_text;
                    });
                };

                Controller.ChangePathFieldEvent += delegate(string text,
                                                            string example_text, FieldState state) {
                    InvokeOnMainThread(delegate {
                        PathTextField.StringValue = text;
                        PathTextField.Enabled     = (state == FieldState.Enabled);
                        PathHelpLabel.StringValue = example_text;
                    });
                };

                TableView.SelectRow(Controller.SelectedPluginIndex, false);
                TableView.ScrollRowToVisible(Controller.SelectedPluginIndex);

                (AddressTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckAddPage(AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
                };

                (PathTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckAddPage(AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
                };

                (TableView.Delegate as SparkleTableViewDelegate).SelectionChanged += delegate {
                    Controller.SelectedPluginChanged(TableView.SelectedRow);
                    Controller.CheckAddPage(AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
                };

                HistoryCheckButton.Activated += delegate {
                    Controller.HistoryItemChanged(HistoryCheckButton.State == NSCellStateValue.On);
                };

                AddButton.Activated += delegate {
                    Controller.AddPageCompleted(AddressTextField.StringValue, PathTextField.StringValue);
                };

                CancelButton.Activated += delegate {
                    Controller.PageCancelled();
                };

                Controller.UpdateAddProjectButtonEvent += delegate(bool button_enabled) {
                    InvokeOnMainThread(delegate {
                        AddButton.Enabled = button_enabled;
                    });
                };


                ContentView.AddSubview(ScrollView);
                ContentView.AddSubview(AddressLabel);
                ContentView.AddSubview(AddressTextField);
                ContentView.AddSubview(AddressHelpLabel);
                ContentView.AddSubview(PathLabel);
                ContentView.AddSubview(PathTextField);
                ContentView.AddSubview(PathHelpLabel);
                ContentView.AddSubview(HistoryCheckButton);

                Buttons.Add(AddButton);
                Buttons.Add(CancelButton);

                Controller.CheckAddPage(AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
            }

            if (type == PageType.Syncing)
            {
                Header      = "Adding project ‘" + Controller.SyncingFolder + "’…";
                Description = "This may take a while for large projects.\nIsn't it coffee-o'clock?";


                ProgressIndicator = new NSProgressIndicator()
                {
                    Frame         = new RectangleF(190, Frame.Height - 200, 640 - 150 - 80, 20),
                    Style         = NSProgressIndicatorStyle.Bar,
                    MinValue      = 0.0,
                    MaxValue      = 100.0,
                    Indeterminate = false,
                    DoubleValue   = Controller.ProgressBarPercentage
                };

                ProgressIndicator.StartAnimation(this);

                CancelButton = new NSButton()
                {
                    Title = "Cancel"
                };

                FinishButton = new NSButton()
                {
                    Title   = "Finish",
                    Enabled = false
                };


                Controller.UpdateProgressBarEvent += delegate(double percentage) {
                    InvokeOnMainThread(() => {
                        ProgressIndicator.DoubleValue = percentage;
                    });
                };

                CancelButton.Activated += delegate {
                    Controller.SyncingCancelled();
                };


                ContentView.AddSubview(ProgressIndicator);

                Buttons.Add(FinishButton);
                Buttons.Add(CancelButton);
            }

            if (type == PageType.Error)
            {
                Header      = "Oops! Something went wrong…";
                Description = "Please check the following:";


                // Displaying marked up text with Cocoa is
                // a pain, so we just use a webview instead
                WebView web_view = new WebView();
                web_view.Frame = new RectangleF(190, Frame.Height - 525, 375, 400);

                string html = "<style>" +
                              "* {" +
                              "  font-family: 'Lucida Grande';" +
                              "  font-size: 12px; cursor: default;" +
                              "}" +
                              "body {" +
                              "  -webkit-user-select: none;" +
                              "  margin: 0;" +
                              "  padding: 3px;" +
                              "}" +
                              "li {" +
                              "  margin-bottom: 16px;" +
                              "  margin-left: 0;" +
                              "  padding-left: 0;" +
                              "  line-height: 20px;" +
                              "}" +
                              "ul {" +
                              "  padding-left: 24px;" +
                              "}" +
                              "</style>" +
                              "<ul>" +
                              "  <li><b>" + Controller.PreviousUrl + "</b> is the address we've compiled. Does this look alright?</li>" +
                              "  <li>Do you have access rights to this remote project?</li>" +
                              "</ul>";

                if (warnings.Length > 0)
                {
                    string warnings_markup = "";

                    foreach (string warning in warnings)
                    {
                        warnings_markup += "<br><b>" + warning + "</b>";
                    }

                    html = html.Replace("</ul>", "<li>Here's the raw error message: " + warnings_markup + "</li></ul>");
                }

                web_view.MainFrame.LoadHtmlString(html, new NSUrl(""));
                web_view.DrawsBackground = false;

                CancelButton = new NSButton()
                {
                    Title = "Cancel"
                };

                TryAgainButton = new NSButton()
                {
                    Title = "Try again…"
                };


                CancelButton.Activated += delegate {
                    Controller.PageCancelled();
                };

                TryAgainButton.Activated += delegate {
                    Controller.ErrorPageCompleted();
                };


                ContentView.AddSubview(web_view);

                Buttons.Add(TryAgainButton);
                Buttons.Add(CancelButton);
            }

            if (type == PageType.CryptoSetup)
            {
                Header      = "Set up file encryption";
                Description = "This project is supposed to be encrypted, but it doesn't yet have a password set. Please provide one below:";


                PasswordLabel = new NSTextField()
                {
                    Alignment       = NSTextAlignment.Right,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF(155, Frame.Height - 204, 160, 17),
                    StringValue     = "Password:"******"Show password",
                    State = NSCellStateValue.Off
                };

                ShowPasswordCheckButton.SetButtonType(NSButtonType.Switch);

                WarningImage      = NSImage.ImageNamed("NSInfo");
                WarningImage.Size = new SizeF(24, 24);

                WarningImageView = new NSImageView()
                {
                    Image = WarningImage,
                    Frame = new RectangleF(200, Frame.Height - 320, 24, 24)
                };

                WarningTextField = new NSTextField()
                {
                    Frame           = new RectangleF(235, Frame.Height - 390, 325, 100),
                    StringValue     = "This password can't be changed later, and your files can't be recovered if it's forgotten.",
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Font            = SparkleUI.Font
                };

                CancelButton = new NSButton()
                {
                    Title = "Cancel"
                };

                ContinueButton = new NSButton()
                {
                    Title   = "Continue",
                    Enabled = false
                };


                ShowPasswordCheckButton.Activated += delegate {
                    if (PasswordTextField.Superview == ContentView)
                    {
                        PasswordTextField.RemoveFromSuperview();
                        ContentView.AddSubview(VisiblePasswordTextField);
                    }
                    else
                    {
                        VisiblePasswordTextField.RemoveFromSuperview();
                        ContentView.AddSubview(PasswordTextField);
                    }
                };

                (PasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    VisiblePasswordTextField.StringValue = PasswordTextField.StringValue;
                    Controller.CheckCryptoSetupPage(PasswordTextField.StringValue);
                };

                (VisiblePasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    PasswordTextField.StringValue = VisiblePasswordTextField.StringValue;
                    Controller.CheckCryptoSetupPage(PasswordTextField.StringValue);
                };


                Controller.UpdateCryptoSetupContinueButtonEvent += delegate(bool button_enabled) {
                    InvokeOnMainThread(() => {
                        ContinueButton.Enabled = button_enabled;
                    });
                };

                ContinueButton.Activated += delegate {
                    Controller.CryptoSetupPageCompleted(PasswordTextField.StringValue);
                };

                CancelButton.Activated += delegate {
                    Controller.CryptoPageCancelled();
                };


                ContentView.AddSubview(PasswordLabel);
                ContentView.AddSubview(PasswordTextField);
                ContentView.AddSubview(ShowPasswordCheckButton);
                ContentView.AddSubview(WarningImageView);
                ContentView.AddSubview(WarningTextField);

                Buttons.Add(ContinueButton);
                Buttons.Add(CancelButton);

                NSApplication.SharedApplication.RequestUserAttention(NSRequestUserAttentionType.CriticalRequest);
            }

            if (type == PageType.CryptoPassword)
            {
                Header      = "This project contains encrypted files";
                Description = "Please enter the password to see their contents.";

                PasswordLabel = new NSTextField()
                {
                    Alignment       = NSTextAlignment.Right,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF(155, Frame.Height - 224, 160, 17),
                    StringValue     = "Password:"******"Show password",
                    State = NSCellStateValue.Off
                };

                ShowPasswordCheckButton.SetButtonType(NSButtonType.Switch);

                CancelButton = new NSButton()
                {
                    Title = "Cancel"
                };

                ContinueButton = new NSButton()
                {
                    Title   = "Continue",
                    Enabled = false
                };


                Controller.UpdateCryptoPasswordContinueButtonEvent += delegate(bool button_enabled) {
                    InvokeOnMainThread(() => {
                        ContinueButton.Enabled = button_enabled;
                    });
                };

                ShowPasswordCheckButton.Activated += delegate {
                    if (PasswordTextField.Superview == ContentView)
                    {
                        PasswordTextField.RemoveFromSuperview();
                        ContentView.AddSubview(VisiblePasswordTextField);
                    }
                    else
                    {
                        VisiblePasswordTextField.RemoveFromSuperview();
                        ContentView.AddSubview(PasswordTextField);
                    }
                };

                (PasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    VisiblePasswordTextField.StringValue = PasswordTextField.StringValue;
                    Controller.CheckCryptoPasswordPage(PasswordTextField.StringValue);
                };

                (VisiblePasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    PasswordTextField.StringValue = VisiblePasswordTextField.StringValue;
                    Controller.CheckCryptoPasswordPage(PasswordTextField.StringValue);
                };

                ContinueButton.Activated += delegate {
                    Controller.CryptoPasswordPageCompleted(PasswordTextField.StringValue);
                };

                CancelButton.Activated += delegate {
                    Controller.CryptoPageCancelled();
                };


                ContentView.AddSubview(PasswordLabel);
                ContentView.AddSubview(PasswordTextField);
                ContentView.AddSubview(ShowPasswordCheckButton);

                Buttons.Add(ContinueButton);
                Buttons.Add(CancelButton);

                NSApplication.SharedApplication.RequestUserAttention(NSRequestUserAttentionType.CriticalRequest);
            }


            if (type == PageType.Finished)
            {
                Header      = "Your shared project is ready!";
                Description = "You can find the files in your SparkleShare folder.";


                if (warnings.Length > 0)
                {
                    WarningImage      = NSImage.ImageNamed("NSInfo");
                    WarningImage.Size = new SizeF(24, 24);

                    WarningImageView = new NSImageView()
                    {
                        Image = WarningImage,
                        Frame = new RectangleF(200, Frame.Height - 175, 24, 24)
                    };

                    WarningTextField = new NSTextField()
                    {
                        Frame           = new RectangleF(235, Frame.Height - 245, 325, 100),
                        StringValue     = warnings [0],
                        BackgroundColor = NSColor.WindowBackground,
                        Bordered        = false,
                        Editable        = false,
                        Font            = SparkleUI.Font
                    };

                    ContentView.AddSubview(WarningImageView);
                    ContentView.AddSubview(WarningTextField);
                }


                OpenFolderButton = new NSButton()
                {
                    Title = "Show folder"
                };

                FinishButton = new NSButton()
                {
                    Title = "Finish"
                };


                OpenFolderButton.Activated += delegate {
                    Controller.OpenFolderClicked();
                };

                FinishButton.Activated += delegate {
                    Controller.FinishPageCompleted();
                };


                Buttons.Add(FinishButton);
                Buttons.Add(OpenFolderButton);

                NSApplication.SharedApplication.RequestUserAttention(NSRequestUserAttentionType.CriticalRequest);
            }

            if (type == PageType.Tutorial)
            {
                string slide_image_path = Path.Combine(NSBundle.MainBundle.ResourcePath,
                                                       "Pixmaps", "tutorial-slide-" + Controller.TutorialPageNumber + ".png");

                SlideImage = new NSImage(slide_image_path)
                {
                    Size = new SizeF(350, 200)
                };

                SlideImageView = new NSImageView()
                {
                    Image = SlideImage,
                    Frame = new RectangleF(215, Frame.Height - 350, 350, 200)
                };

                ContentView.AddSubview(SlideImageView);


                switch (Controller.TutorialPageNumber)
                {
                case 1: {
                    Header      = "What's happening next?";
                    Description = "SparkleShare creates a special folder on your computer " +
                                  "that will keep track of your projects.";


                    SkipTutorialButton = new NSButton()
                    {
                        Title = "Skip Tutorial"
                    };

                    ContinueButton = new NSButton()
                    {
                        Title = "Continue"
                    };


                    SkipTutorialButton.Activated += delegate {
                        Controller.TutorialSkipped();
                    };

                    ContinueButton.Activated += delegate {
                        Controller.TutorialPageCompleted();
                    };


                    ContentView.AddSubview(SlideImageView);

                    Buttons.Add(ContinueButton);
                    Buttons.Add(SkipTutorialButton);

                    break;
                }

                case 2: {
                    Header      = "Sharing files with others";
                    Description = "All files added to your project folders are synced automatically with " +
                                  "the host and your team members.";

                    ContinueButton = new NSButton()
                    {
                        Title = "Continue"
                    };

                    ContinueButton.Activated += delegate {
                        Controller.TutorialPageCompleted();
                    };

                    Buttons.Add(ContinueButton);

                    break;
                }

                case 3: {
                    Header      = "The status icon is here to help";
                    Description = "It shows the syncing progress, provides easy access to " +
                                  "your projects and let's you view recent changes.";

                    ContinueButton = new NSButton()
                    {
                        Title = "Continue"
                    };

                    ContinueButton.Activated += delegate {
                        Controller.TutorialPageCompleted();
                    };

                    Buttons.Add(ContinueButton);

                    break;
                }

                case 4: {
                    Header      = "Adding projects to SparkleShare";
                    Description = "You can do this through the status icon menu, or by clicking " +
                                  "magic buttons on webpages that look like this:";


                    StartupCheckButton = new NSButton()
                    {
                        Frame = new RectangleF(190, Frame.Height - 400, 300, 18),
                        Title = "Add SparkleShare to startup items",
                        State = NSCellStateValue.On
                    };

                    StartupCheckButton.SetButtonType(NSButtonType.Switch);

                    FinishButton = new NSButton()
                    {
                        Title = "Finish"
                    };

                    SlideImage.Size = new SizeF(350, 64);


                    StartupCheckButton.Activated += delegate {
                        Controller.StartupItemChanged(StartupCheckButton.State == NSCellStateValue.On);
                    };

                    FinishButton.Activated += delegate {
                        Controller.TutorialPageCompleted();
                    };


                    ContentView.AddSubview(StartupCheckButton);
                    Buttons.Add(FinishButton);

                    break;
                }
                }
            }
        }
Esempio n. 25
0
        public void ShowPage(PageType type, string [] warnings)
        {
            if (type == PageType.Setup) {
                Header      = "Welcome to SparkleShare!";
                Description = "First off, what's your name and email?\n(visible only to team members)";

                FullNameLabel = new NSTextField () {
                    Alignment       = NSTextAlignment.Right,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (165, Frame.Height - 234, 160, 17),
                    StringValue     = "Full Name:",
                    Font            = SparkleUI.Font
                };

                FullNameTextField = new NSTextField () {
                    Frame       = new RectangleF (330, Frame.Height - 238, 196, 22),
                    StringValue = UnixUserInfo.GetRealUser ().RealName,
                    Delegate    = new SparkleTextFieldDelegate ()
                };

                EmailLabel = new NSTextField () {
                    Alignment       = NSTextAlignment.Right,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (165, Frame.Height - 264, 160, 17),
                    StringValue     = "Email:",
                    Font            = SparkleUI.Font
                };

                EmailTextField = new NSTextField () {
                    Frame       = new RectangleF (330, Frame.Height - 268, 196, 22),
                    Delegate    = new SparkleTextFieldDelegate ()
                };

                CancelButton = new NSButton () {
                    Title = "Cancel"
                };

                ContinueButton = new NSButton () {
                    Title    = "Continue",
                    Enabled  = false
                };

                (FullNameTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckSetupPage (FullNameTextField.StringValue, EmailTextField.StringValue);
                };

                (EmailTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckSetupPage (FullNameTextField.StringValue, EmailTextField.StringValue);
                };

                ContinueButton.Activated += delegate {
                    string full_name = FullNameTextField.StringValue.Trim ();
                    string email     = EmailTextField.StringValue.Trim ();

                    Controller.SetupPageCompleted (full_name, email);
                };

                CancelButton.Activated += delegate {
                    Controller.SetupPageCancelled ();
                };

                Controller.UpdateSetupContinueButtonEvent += delegate (bool button_enabled) {
                    InvokeOnMainThread (delegate {
                        ContinueButton.Enabled = button_enabled;
                    });
                };

                ContentView.AddSubview (FullNameLabel);
                ContentView.AddSubview (FullNameTextField);
                ContentView.AddSubview (EmailLabel);
                ContentView.AddSubview (EmailTextField);

                Buttons.Add (ContinueButton);
                Buttons.Add (CancelButton);

                Controller.CheckSetupPage (FullNameTextField.StringValue, EmailTextField.StringValue);
            }

            if (type == PageType.Invite) {
                Header      = "You've received an invite!";
                Description = "Do you want to add this project to SparkleShare?";

                AddressLabel = new NSTextField () {
                    Alignment       = NSTextAlignment.Right,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (165, Frame.Height - 240, 160, 17),
                    StringValue     = "Address:",
                    Font            = SparkleUI.Font
                };

                PathLabel = new NSTextField () {
                    Alignment       = NSTextAlignment.Right,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (165, Frame.Height - 264, 160, 17),
                    StringValue     = "Remote Path:",
                    Font            = SparkleUI.Font
                };

                AddressTextField = new NSTextField () {
                    Alignment       = NSTextAlignment.Left,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (330, Frame.Height - 240, 260, 17),
                    StringValue     = Controller.PendingInvite.Address,
                    Font            = SparkleUI.BoldFont
                };

                PathTextField = new NSTextField () {
                    Alignment       = NSTextAlignment.Left,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (330, Frame.Height - 264, 260, 17),
                    StringValue     = Controller.PendingInvite.RemotePath,
                    Font            = SparkleUI.BoldFont
                };

                CancelButton = new NSButton () {
                    Title = "Cancel"
                };

                AddButton = new NSButton () {
                    Title = "Add"
                };

                CancelButton.Activated += delegate {
                    Controller.PageCancelled ();
                };

                AddButton.Activated += delegate {
                    Controller.InvitePageCompleted ();
                };

                ContentView.AddSubview (AddressLabel);
                ContentView.AddSubview (PathLabel);
                ContentView.AddSubview (AddressTextField);
                ContentView.AddSubview (PathTextField);

                Buttons.Add (AddButton);
                Buttons.Add (CancelButton);
            }

            if (type == PageType.Add) {
                Header      = "Where's your project hosted?";
                Description = "";

                AddressLabel = new NSTextField () {
                    Alignment       = NSTextAlignment.Left,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (190, Frame.Height - 308, 160, 17),
                    StringValue     = "Address:",
                    Font            = SparkleUI.BoldFont
                };

                AddressTextField = new NSTextField () {
                    Frame       = new RectangleF (190, Frame.Height - 336, 196, 22),
                    Font        = SparkleUI.Font,
                    Enabled     = (Controller.SelectedPlugin.Address == null),
                    Delegate    = new SparkleTextFieldDelegate (),
                    StringValue = "" + Controller.PreviousAddress
                };

                AddressTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;

                PathLabel = new NSTextField () {
                    Alignment       = NSTextAlignment.Left,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (190 + 196 + 16, Frame.Height - 308, 160, 17),
                    StringValue     = "Remote Path:",
                    Font            = SparkleUI.BoldFont
                };

                PathTextField = new NSTextField () {
                    Frame       = new RectangleF (190 + 196 + 16, Frame.Height - 336, 196, 22),
                    Enabled     = (Controller.SelectedPlugin.Path == null),
                    Delegate    = new SparkleTextFieldDelegate (),
                    StringValue = "" + Controller.PreviousPath
                };

                PathTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;

                PathHelpLabel = new NSTextField () {
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    TextColor       = NSColor.DisabledControlText,
                    Editable        = false,
                    Frame           = new RectangleF (190 + 196 + 16, Frame.Height - 355, 204, 17),
                    Font            = NSFontManager.SharedFontManager.FontWithFamily ("Lucida Grande",
                        NSFontTraitMask.Condensed, 0, 11),
                    StringValue = "" + Controller.SelectedPlugin.PathExample
                };

                AddressHelpLabel = new NSTextField () {
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    TextColor       = NSColor.DisabledControlText,
                    Editable        = false,
                    Frame           = new RectangleF (190, Frame.Height - 355, 204, 17),
                    Font            = NSFontManager.SharedFontManager.FontWithFamily ("Lucida Grande",
                        NSFontTraitMask.Condensed, 0, 11),
                    StringValue = "" + Controller.SelectedPlugin.AddressExample
                };

                TableView = new NSTableView () {
                    Frame            = new RectangleF (0, 0, 0, 0),
                    RowHeight        = 34,
                    IntercellSpacing = new SizeF (8, 12),
                    HeaderView       = null,
                    Delegate         = new SparkleTableViewDelegate ()
                };

                ScrollView = new NSScrollView () {
                    Frame               = new RectangleF (190, Frame.Height - 280, 408, 185),
                    DocumentView        = TableView,
                    HasVerticalScroller = true,
                    BorderType          = NSBorderType.BezelBorder
                };

                IconColumn = new NSTableColumn (new NSImage ()) {
                    Width = 36,
                    HeaderToolTip = "Icon",
                    DataCell = new NSImageCell () {
                        ImageAlignment = NSImageAlignment.Right
                    }
                };

                DescriptionColumn = new NSTableColumn () {
                    Width         = 350,
                    HeaderToolTip = "Description",
                    Editable      = false
                };

                DescriptionColumn.DataCell.Font = NSFontManager.SharedFontManager.FontWithFamily ("Lucida Grande",
                    NSFontTraitMask.Condensed, 0, 11);

                TableView.AddColumn (IconColumn);
                TableView.AddColumn (DescriptionColumn);

                DataSource = new SparkleDataSource (Controller.Plugins);

                TableView.DataSource = DataSource;
                TableView.ReloadData ();

                HistoryCheckButton = new NSButton () {
                    Frame = new RectangleF (190, Frame.Height - 400, 300, 18),
                    Title = "Fetch prior revisions"
                };

                if (Controller.FetchPriorHistory)
                    HistoryCheckButton.State = NSCellStateValue.On;

                HistoryCheckButton.SetButtonType (NSButtonType.Switch);

                AddButton = new NSButton () {
                    Title = "Add",
                    Enabled = false
                };

                CancelButton = new NSButton () {
                    Title = "Cancel"
                };

                Controller.ChangeAddressFieldEvent += delegate (string text,
                    string example_text, FieldState state) {

                    InvokeOnMainThread (delegate {
                        AddressTextField.StringValue = text;
                        AddressTextField.Enabled     = (state == FieldState.Enabled);
                        AddressHelpLabel.StringValue = example_text;
                    });
                };

                Controller.ChangePathFieldEvent += delegate (string text,
                    string example_text, FieldState state) {

                    InvokeOnMainThread (delegate {
                        PathTextField.StringValue = text;
                        PathTextField.Enabled     = (state == FieldState.Enabled);
                        PathHelpLabel.StringValue = example_text;
                    });
                };

                TableView.SelectRow (Controller.SelectedPluginIndex, false);
                TableView.ScrollRowToVisible (Controller.SelectedPluginIndex);

                (AddressTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckAddPage (AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
                };

                 (PathTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckAddPage (AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
                };

                (TableView.Delegate as SparkleTableViewDelegate).SelectionChanged += delegate {
                    Controller.SelectedPluginChanged (TableView.SelectedRow);
                    Controller.CheckAddPage (AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
                };

                HistoryCheckButton.Activated += delegate {
                    Controller.HistoryItemChanged (HistoryCheckButton.State == NSCellStateValue.On);
                };

                AddButton.Activated += delegate {
                    Controller.AddPageCompleted (AddressTextField.StringValue, PathTextField.StringValue);
                };

                CancelButton.Activated += delegate {
                    Controller.PageCancelled ();
                };

                Controller.UpdateAddProjectButtonEvent += delegate (bool button_enabled) {
                    InvokeOnMainThread (delegate {
                        AddButton.Enabled = button_enabled;
                    });
                };

                ContentView.AddSubview (ScrollView);
                ContentView.AddSubview (AddressLabel);
                ContentView.AddSubview (AddressTextField);
                ContentView.AddSubview (AddressHelpLabel);
                ContentView.AddSubview (PathLabel);
                ContentView.AddSubview (PathTextField);
                ContentView.AddSubview (PathHelpLabel);
                ContentView.AddSubview (HistoryCheckButton);

                Buttons.Add (AddButton);
                Buttons.Add (CancelButton);

                Controller.CheckAddPage (AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
            }

            if (type == PageType.Syncing) {
                Header      = "Adding project ‘" + Controller.SyncingFolder + "’…";
                Description = "This may take a while on big projects. Isn't it coffee-o'clock?";

                ProgressIndicator = new NSProgressIndicator () {
                    Frame         = new RectangleF (190, Frame.Height - 200, 640 - 150 - 80, 20),
                    Style         = NSProgressIndicatorStyle.Bar,
                    MinValue      = 0.0,
                    MaxValue      = 100.0,
                    Indeterminate = false,
                    DoubleValue   = Controller.ProgressBarPercentage
                };

                ProgressIndicator.StartAnimation (this);

                CancelButton = new NSButton () {
                    Title = "Cancel"
                };

                FinishButton = new NSButton () {
                    Title = "Finish",
                    Enabled = false
                };

                Controller.UpdateProgressBarEvent += delegate (double percentage) {
                    InvokeOnMainThread (() => {
                        ProgressIndicator.DoubleValue = percentage;
                    });
                };

                CancelButton.Activated += delegate {
                    Controller.SyncingCancelled ();
                };

                ContentView.AddSubview (ProgressIndicator);

                Buttons.Add (FinishButton);
                Buttons.Add (CancelButton);
            }

            if (type == PageType.Error) {
                Header      = "Oops! Something went wrong…";
                Description = "Please check the following:";

                // Displaying marked up text with Cocoa is
                // a pain, so we just use a webview instead
                WebView web_view = new WebView ();
                web_view.Frame   = new RectangleF (190, Frame.Height - 525, 375, 400);

                string html = "<style>" +
                    "* {" +
                    "  font-family: 'Lucida Grande';" +
                    "  font-size: 12px; cursor: default;" +
                    "}" +
                    "body {" +
                    "  -webkit-user-select: none;" +
                    "  margin: 0;" +
                    "  padding: 3px;" +
                    "}" +
                    "li {" +
                    "  margin-bottom: 16px;" +
                    "  margin-left: 0;" +
                    "  padding-left: 0;" +
                    "  line-height: 20px;" +
                    "}" +
                    "ul {" +
                    "  padding-left: 24px;" +
                    "}" +
                    "</style>" +
                    "<ul>" +
                    "  <li><b>" + Controller.PreviousUrl + "</b> is the address we've compiled. Does this look alright?</li>" +
                    "  <li>Do you have access rights to this remote project?</li>" +
                    "</ul>";

                if (warnings.Length > 0) {
                    string warnings_markup = "";

                    foreach (string warning in warnings)
                        warnings_markup += "<br><b>" + warning + "</b>";

                    html = html.Replace ("</ul>", "<li>Here's the raw error message: " + warnings_markup + "</li></ul>");
                }

                web_view.MainFrame.LoadHtmlString (html, new NSUrl (""));
                web_view.DrawsBackground = false;

                CancelButton = new NSButton () {
                    Title = "Cancel"
                };

                TryAgainButton = new NSButton () {
                    Title = "Try again…"
                };

                CancelButton.Activated += delegate {
                    Controller.PageCancelled ();
                };

                TryAgainButton.Activated += delegate {
                    Controller.ErrorPageCompleted ();
                };

                ContentView.AddSubview (web_view);

                Buttons.Add (TryAgainButton);
                Buttons.Add (CancelButton);
            }

            if (type == PageType.CryptoSetup) {
                Header      = "Set up file encryption";
                Description = "This project is supposed to be encrypted, but it doesn't yet have a password set. Please provide one below:";

                PasswordLabel = new NSTextField () {
                    Alignment       = NSTextAlignment.Right,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (155, Frame.Height - 204, 160, 17),
                    StringValue     = "Password:"******"Show password",
                    State = NSCellStateValue.Off
                };

                ShowPasswordCheckButton.SetButtonType (NSButtonType.Switch);

                WarningImage = NSImage.ImageNamed ("NSInfo");
                WarningImage.Size = new SizeF (24, 24);

                WarningImageView = new NSImageView () {
                    Image = WarningImage,
                    Frame = new RectangleF (200, Frame.Height - 320, 24, 24)
                };

                WarningTextField = new NSTextField () {
                    Frame           = new RectangleF (235, Frame.Height - 390, 325, 100),
                    StringValue     = "This password can't be changed later, and your files can't be recovered if it's forgotten.",
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Font            = SparkleUI.Font
                };

                CancelButton = new NSButton () {
                    Title = "Cancel"
                };

                ContinueButton = new NSButton () {
                    Title    = "Continue",
                    Enabled  = false
                };

                ShowPasswordCheckButton.Activated += delegate {
                    if (PasswordTextField.Superview == ContentView) {
                        PasswordTextField.RemoveFromSuperview ();
                        ContentView.AddSubview (VisiblePasswordTextField);

                    } else {
                        VisiblePasswordTextField.RemoveFromSuperview ();
                        ContentView.AddSubview (PasswordTextField);
                    }
                };

                (PasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    VisiblePasswordTextField.StringValue = PasswordTextField.StringValue;
                    Controller.CheckCryptoSetupPage (PasswordTextField.StringValue);
                };

                (VisiblePasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    PasswordTextField.StringValue = VisiblePasswordTextField.StringValue;
                    Controller.CheckCryptoSetupPage (PasswordTextField.StringValue);
                };

                Controller.UpdateCryptoSetupContinueButtonEvent += delegate (bool button_enabled) {
                    InvokeOnMainThread (() => {
                        ContinueButton.Enabled = button_enabled;
                    });
                };

                ContinueButton.Activated += delegate {
                   Controller.CryptoSetupPageCompleted (PasswordTextField.StringValue);
                };

                CancelButton.Activated += delegate {
                    Controller.CryptoPageCancelled ();
                };

                ContentView.AddSubview (PasswordLabel);
                ContentView.AddSubview (PasswordTextField);
                ContentView.AddSubview (ShowPasswordCheckButton);
                ContentView.AddSubview (WarningImageView);
                ContentView.AddSubview (WarningTextField);

                Buttons.Add (ContinueButton);
                Buttons.Add (CancelButton);

                NSApplication.SharedApplication.RequestUserAttention (NSRequestUserAttentionType.CriticalRequest);
            }

            if (type == PageType.CryptoPassword) {
                Header      = "This project contains encrypted files";
                Description = "Please enter the password to see their contents.";

                PasswordLabel = new NSTextField () {
                    Alignment       = NSTextAlignment.Right,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (155, Frame.Height - 224, 160, 17),
                    StringValue     = "Password:"******"Show password",
                    State = NSCellStateValue.Off
                };

                ShowPasswordCheckButton.SetButtonType (NSButtonType.Switch);

                CancelButton = new NSButton () {
                    Title = "Cancel"
                };

                ContinueButton = new NSButton () {
                    Title    = "Continue",
                    Enabled  = false
                };

                Controller.UpdateCryptoPasswordContinueButtonEvent += delegate (bool button_enabled) {
                    InvokeOnMainThread (() => {
                        ContinueButton.Enabled = button_enabled;
                    });
                };

                ShowPasswordCheckButton.Activated += delegate {
                    if (PasswordTextField.Superview == ContentView) {
                        PasswordTextField.RemoveFromSuperview ();
                        ContentView.AddSubview (VisiblePasswordTextField);

                    } else {
                        VisiblePasswordTextField.RemoveFromSuperview ();
                        ContentView.AddSubview (PasswordTextField);
                    }
                };

                (PasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    VisiblePasswordTextField.StringValue = PasswordTextField.StringValue;
                    Controller.CheckCryptoPasswordPage (PasswordTextField.StringValue);
                };

                (VisiblePasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    PasswordTextField.StringValue = VisiblePasswordTextField.StringValue;
                    Controller.CheckCryptoPasswordPage (PasswordTextField.StringValue);
                };

                ContinueButton.Activated += delegate {
                   Controller.CryptoPasswordPageCompleted (PasswordTextField.StringValue);
                };

                CancelButton.Activated += delegate {
                    Controller.CryptoPageCancelled ();
                };

                ContentView.AddSubview (PasswordLabel);
                ContentView.AddSubview (PasswordTextField);
                ContentView.AddSubview (ShowPasswordCheckButton);

                Buttons.Add (ContinueButton);
                Buttons.Add (CancelButton);

                NSApplication.SharedApplication.RequestUserAttention (NSRequestUserAttentionType.CriticalRequest);
            }

            if (type == PageType.Finished) {
                Header      = "Your shared project is ready!";
                Description = "You can find the files in your SparkleShare folder.";

                if (warnings.Length > 0) {
                    WarningImage = NSImage.ImageNamed ("NSInfo");
                    WarningImage.Size = new SizeF (24, 24);

                    WarningImageView = new NSImageView () {
                        Image = WarningImage,
                        Frame = new RectangleF (200, Frame.Height - 175, 24, 24)
                    };

                    WarningTextField = new NSTextField () {
                        Frame           = new RectangleF (235, Frame.Height - 245, 325, 100),
                        StringValue     = warnings [0],
                        BackgroundColor = NSColor.WindowBackground,
                        Bordered        = false,
                        Editable        = false,
                        Font            = SparkleUI.Font
                    };

                    ContentView.AddSubview (WarningImageView);
                    ContentView.AddSubview (WarningTextField);
                }

                OpenFolderButton = new NSButton () {
                    Title = string.Format ("Open {0}", Path.GetFileName (Controller.PreviousPath))
                };

                FinishButton = new NSButton () {
                    Title = "Finish"
                };

                OpenFolderButton.Activated += delegate {
                    Controller.OpenFolderClicked ();
                };

                FinishButton.Activated += delegate {
                    Controller.FinishPageCompleted ();
                };

                Buttons.Add (FinishButton);
                Buttons.Add (OpenFolderButton);

                NSApplication.SharedApplication.RequestUserAttention (NSRequestUserAttentionType.CriticalRequest);
            }

            if (type == PageType.Tutorial) {
                string slide_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath,
                    "Pixmaps", "tutorial-slide-" + Controller.TutorialPageNumber + ".png");

                SlideImage = new NSImage (slide_image_path) {
                    Size = new SizeF (350, 200)
                };

                SlideImageView = new NSImageView () {
                    Image = SlideImage,
                    Frame = new RectangleF (215, Frame.Height - 350, 350, 200)
                };

                ContentView.AddSubview (SlideImageView);

                switch (Controller.TutorialPageNumber) {

                    case 1: {
                        Header      = "What's happening next?";
                        Description = "SparkleShare creates a special folder on your computer " +
                            "that will keep track of your projects.";

                        SkipTutorialButton = new NSButton () {
                            Title = "Skip Tutorial"
                        };

                        ContinueButton = new NSButton () {
                            Title = "Continue"
                        };

                        SkipTutorialButton.Activated += delegate {
                            Controller.TutorialSkipped ();
                        };

                        ContinueButton.Activated += delegate {
                            Controller.TutorialPageCompleted ();
                        };

                        ContentView.AddSubview (SlideImageView);

                        Buttons.Add (ContinueButton);
                        Buttons.Add (SkipTutorialButton);

                        break;
                    }

                    case 2: {
                        Header      = "Sharing files with others";
                        Description = "All files added to your project folders are synced automatically with " +
                            "the host and your team members.";

                        ContinueButton = new NSButton () {
                            Title = "Continue"
                        };

                        ContinueButton.Activated += delegate {
                            Controller.TutorialPageCompleted ();
                        };

                        Buttons.Add (ContinueButton);

                        break;
                    }

                    case 3: {
                        Header      = "The status icon is here to help";
                        Description = "It shows the syncing progress, provides easy access to " +
                            "your projects and let's you view recent changes.";

                        ContinueButton = new NSButton () {
                            Title = "Continue"
                        };

                        ContinueButton.Activated += delegate {
                            Controller.TutorialPageCompleted ();
                        };

                        Buttons.Add (ContinueButton);

                        break;
                    }

                    case 4: {
                        Header      = "Adding projects to SparkleShare";
                        Description = "You can do this through the status icon menu, or by clicking " +
                            "magic buttons on webpages that look like this:";

                        StartupCheckButton = new NSButton () {
                            Frame = new RectangleF (190, Frame.Height - 400, 300, 18),
                            Title = "Add SparkleShare to startup items",
                            State = NSCellStateValue.On
                        };

                        StartupCheckButton.SetButtonType (NSButtonType.Switch);

                        FinishButton = new NSButton () {
                            Title = "Finish"
                        };

                        SlideImage.Size = new SizeF (350, 64);

                        StartupCheckButton.Activated += delegate {
                            Controller.StartupItemChanged (StartupCheckButton.State == NSCellStateValue.On);
                        };

                        FinishButton.Activated += delegate {
                            Controller.TutorialPageCompleted ();
                        };

                        ContentView.AddSubview (StartupCheckButton);
                        Buttons.Add (FinishButton);

                        break;
                    }
                }
            }
        }
Esempio n. 26
0
        public SparkleSetup()
            : base()
        {
            Controller.HideWindowEvent += delegate {
                InvokeOnMainThread (delegate {
                    PerformClose (this);
                });
            };

            Controller.ShowWindowEvent += delegate {
                InvokeOnMainThread (delegate {
                    OrderFrontRegardless ();
                });
            };

            Controller.ChangePageEvent += delegate (PageType type, string [] warnings) {
                using (var a = new NSAutoreleasePool ())
                {
                    InvokeOnMainThread (delegate {
                        Reset ();

                        switch (type) {
                        case PageType.Setup: {

                            Header       = "Welcome to SparkleShare!";
                            Description  = "Before we get started, what's your name and email?\n" +
                                "Don't worry, this information will only visible to any team members.";

                            FullNameLabel = new NSTextField () {
                                Alignment       = NSTextAlignment.Right,
                                BackgroundColor = NSColor.WindowBackground,
                                Bordered        = false,
                                Editable        = false,
                                Frame           = new RectangleF (165, Frame.Height - 234, 160, 17),
                                StringValue     = "Full Name:",
                                Font            = SparkleUI.Font
                            };

                            FullNameTextField = new NSTextField () {
                                Frame       = new RectangleF (330, Frame.Height - 238, 196, 22),
                                StringValue = Controller.GuessedUserName,
                                Delegate    = new SparkleTextFieldDelegate ()
                            };

                            EmailLabel = new NSTextField () {
                                Alignment       = NSTextAlignment.Right,
                                BackgroundColor = NSColor.WindowBackground,
                                Bordered        = false,
                                Editable        = false,
                                Frame           = new RectangleF (165, Frame.Height - 264, 160, 17),
                                StringValue     = "Email:",
                                Font            = SparkleUI.Font
                            };

                            EmailTextField = new NSTextField () {
                                Frame       = new RectangleF (330, Frame.Height - 268, 196, 22),
                                StringValue = Controller.GuessedUserEmail,
                                Delegate    = new SparkleTextFieldDelegate ()
                            };

                            (FullNameTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                                Controller.CheckSetupPage (
                                    FullNameTextField.StringValue,
                                    EmailTextField.StringValue
                                );
                            };

                            (EmailTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                                Controller.CheckSetupPage (
                                    FullNameTextField.StringValue,
                                    EmailTextField.StringValue
                                );
                            };

                            ContinueButton = new NSButton () {
                                Title    = "Continue",
                                Enabled  = false
                            };

                            ContinueButton.Activated += delegate {
                                string full_name = FullNameTextField.StringValue.Trim ();
                                string email     = EmailTextField.StringValue.Trim ();

                                Controller.SetupPageCompleted (full_name, email);
                            };

                            CancelButton = new NSButton () {
                                Title = "Cancel"
                            };

                            CancelButton.Activated += delegate {
                                Controller.SetupPageCancelled ();
                            };

                            Controller.UpdateSetupContinueButtonEvent += delegate (bool button_enabled) {
                                InvokeOnMainThread (delegate {
                                    ContinueButton.Enabled = button_enabled;
                                });
                            };

                            ContentView.AddSubview (FullNameLabel);
                            ContentView.AddSubview (FullNameTextField);
                            ContentView.AddSubview (EmailLabel);
                            ContentView.AddSubview (EmailTextField);

                            Buttons.Add (ContinueButton);
                            Buttons.Add (CancelButton);

                            Controller.CheckSetupPage (
                                FullNameTextField.StringValue,
                                EmailTextField.StringValue
                            );

                            break;
                        }

                        case PageType.Invite: {

                            Header      = "You've received an invite!";
                            Description = "Do you want to add this project to SparkleShare?";

                            AddressLabel = new NSTextField () {
                                Alignment       = NSTextAlignment.Right,
                                BackgroundColor = NSColor.WindowBackground,
                                Bordered        = false,
                                Editable        = false,
                                Frame           = new RectangleF (165, Frame.Height - 240, 160, 17),
                                StringValue     = "Address:",
                                Font            = SparkleUI.Font
                            };

                            PathLabel = new NSTextField () {
                                Alignment       = NSTextAlignment.Right,
                                BackgroundColor = NSColor.WindowBackground,
                                Bordered        = false,
                                Editable        = false,
                                Frame           = new RectangleF (165, Frame.Height - 264, 160, 17),
                                StringValue     = "Remote Path:",
                                Font            = SparkleUI.Font
                            };

                            AddressTextField = new NSTextField () {
                                Alignment       = NSTextAlignment.Left,
                                BackgroundColor = NSColor.WindowBackground,
                                Bordered        = false,
                                Editable        = false,
                                Frame           = new RectangleF (330, Frame.Height - 240, 260, 17),
                                StringValue     = Controller.PendingInvite.Address,
                                Font            = SparkleUI.BoldFont
                            };

                            PathTextField = new NSTextField () {
                                Alignment       = NSTextAlignment.Left,
                                BackgroundColor = NSColor.WindowBackground,
                                Bordered        = false,
                                Editable        = false,
                                Frame           = new RectangleF (330, Frame.Height - 264, 260, 17),
                                StringValue     = Controller.PendingInvite.RemotePath,
                                Font            = SparkleUI.BoldFont
                            };

                            ContentView.AddSubview (AddressLabel);
                            ContentView.AddSubview (PathLabel);
                            ContentView.AddSubview (AddressTextField);
                            ContentView.AddSubview (PathTextField);

                            CancelButton = new NSButton () {
                                    Title = "Cancel"
                            };

                                CancelButton.Activated += delegate {
                                    Controller.PageCancelled ();
                                };

                            AddButton = new NSButton () {
                                 Title = "Add"
                            };

                                AddButton.Activated += delegate {
                                    Controller.InvitePageCompleted ();
                                };

                            Buttons.Add (AddButton);
                            Buttons.Add (CancelButton);

                            break;
                        }

                        case PageType.Add: {

                            Header      = "Where's your project hosted?";
                            Description = "";

                            AddressLabel = new NSTextField () {
                                Alignment       = NSTextAlignment.Left,
                                BackgroundColor = NSColor.WindowBackground,
                                Bordered        = false,
                                Editable        = false,
                                Frame           = new RectangleF (190, Frame.Height - 308, 160, 17),
                                StringValue     = "Address:",
                                Font            = SparkleUI.BoldFont
                            };

                            AddressTextField = new NSTextField () {
                                Frame       = new RectangleF (190, Frame.Height - 336, 196, 22),
                                Font        = SparkleUI.Font,
                                Enabled     = (Controller.SelectedPlugin.Address == null),
                                Delegate    = new SparkleTextFieldDelegate ()
                            };

                            if (Controller.PreviousAddress != null)
                                AddressTextField.StringValue = Controller.PreviousAddress;

                            PathLabel = new NSTextField () {
                                Alignment       = NSTextAlignment.Left,
                                BackgroundColor = NSColor.WindowBackground,
                                Bordered        = false,
                                Editable        = false,
                                Frame           = new RectangleF (190 + 196 + 16, Frame.Height - 308, 160, 17),
                                StringValue     = "Remote Path:",
                                Font            = SparkleUI.BoldFont
                            };

                            PathTextField = new NSTextField () {
                                Frame           = new RectangleF (190 + 196 + 16, Frame.Height - 336, 196, 22),
                                Enabled         = (Controller.SelectedPlugin.Path == null),
                                Delegate        = new SparkleTextFieldDelegate ()
                            };

                            if (Controller.PreviousPath != null)
                                PathTextField.StringValue = Controller.PreviousPath;

                            AddressTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;
                            PathTextField.Cell.LineBreakMode    = NSLineBreakMode.TruncatingTail;

                            PathHelpLabel = new NSTextField () {
                                BackgroundColor = NSColor.WindowBackground,
                                Bordered        = false,
                                TextColor       = NSColor.DisabledControlText,
                                Editable        = false,
                                Frame           = new RectangleF (190 + 196 + 16, Frame.Height - 355, 204, 17),
                                Font            = NSFontManager.SharedFontManager.FontWithFamily
                                                      ("Lucida Grande", NSFontTraitMask.Condensed, 0, 11)
                            };

                            if (Controller.SelectedPlugin.PathExample != null)
                                PathHelpLabel.StringValue = Controller.SelectedPlugin.PathExample;

                            AddressHelpLabel = new NSTextField () {
                                BackgroundColor = NSColor.WindowBackground,
                                Bordered        = false,
                                TextColor       = NSColor.DisabledControlText,
                                Editable        = false,
                                Frame           = new RectangleF (190, Frame.Height - 355, 204, 17),
                                Font            = NSFontManager.SharedFontManager.FontWithFamily
                                                      ("Lucida Grande", NSFontTraitMask.Condensed, 0, 11)
                            };

                            if (Controller.SelectedPlugin.AddressExample != null)
                                AddressHelpLabel.StringValue = Controller.SelectedPlugin.AddressExample;

                            TableView = new NSTableView () {
                                Frame            = new RectangleF (0, 0, 0, 0),
                                RowHeight        = 34,
                                IntercellSpacing = new SizeF (8, 12),
                                HeaderView       = null,
                                Delegate         = new SparkleTableViewDelegate ()
                            };

                            ScrollView = new NSScrollView () {
                                Frame               = new RectangleF (190, Frame.Height - 280, 408, 175),
                                DocumentView        = TableView,
                                HasVerticalScroller = true,
                                BorderType          = NSBorderType.BezelBorder
                            };

                            IconColumn = new NSTableColumn (new NSImage ()) {
                                Width = 36,
                                HeaderToolTip = "Icon",
                                DataCell = new NSImageCell () {
                                    ImageAlignment = NSImageAlignment.Right
                                }
                            };

                            DescriptionColumn = new NSTableColumn () {
                                Width         = 350,
                                HeaderToolTip = "Description",
                                Editable      = false
                            };

                            DescriptionColumn.DataCell.Font =
                                NSFontManager.SharedFontManager.FontWithFamily (
                                    "Lucida Grande", NSFontTraitMask.Condensed, 0, 11);

                            TableView.AddColumn (IconColumn);
                            TableView.AddColumn (DescriptionColumn);

                            DataSource = new SparkleDataSource (Controller.Plugins);

                            TableView.DataSource = DataSource;
                            TableView.ReloadData ();

                            HistoryCheckButton = new NSButton () {
                                Frame = new RectangleF (190, Frame.Height - 400, 300, 18),
                                Title = "Fetch prior revisions"
                            };

                            if (Controller.FetchPriorHistory)
                                HistoryCheckButton.State = NSCellStateValue.On;

                            HistoryCheckButton.SetButtonType (NSButtonType.Switch);

                            HistoryCheckButton.Activated += delegate {
                                Controller.HistoryItemChanged (HistoryCheckButton.State == NSCellStateValue.On);
                            };

                            ContentView.AddSubview (HistoryCheckButton);

                            Controller.ChangeAddressFieldEvent += delegate (string text,
                                string example_text, FieldState state) {

                                InvokeOnMainThread (delegate {
                                    AddressTextField.StringValue = text;
                                    AddressTextField.Enabled     = (state == FieldState.Enabled);
                                    AddressHelpLabel.StringValue = example_text;
                                });
                            };

                            Controller.ChangePathFieldEvent += delegate (string text,
                                string example_text, FieldState state) {

                                InvokeOnMainThread (delegate {
                                    PathTextField.StringValue = text;
                                    PathTextField.Enabled     = (state == FieldState.Enabled);
                                    PathHelpLabel.StringValue = example_text;
                                });
                            };

                            TableView.SelectRow (Controller.SelectedPluginIndex, false);

                            (AddressTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                                Controller.CheckAddPage (
                                    AddressTextField.StringValue,
                                    PathTextField.StringValue,
                                    TableView.SelectedRow
                                );
                            };

                             (PathTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                                Controller.CheckAddPage (
                                    AddressTextField.StringValue,
                                    PathTextField.StringValue,
                                    TableView.SelectedRow
                                );
                            };

                            (TableView.Delegate as SparkleTableViewDelegate).SelectionChanged += delegate {
                                Controller.SelectedPluginChanged (TableView.SelectedRow);

                                Controller.CheckAddPage (
                                    AddressTextField.StringValue,
                                    PathTextField.StringValue,
                                    TableView.SelectedRow
                                );
                            };

                            Controller.UpdateAddProjectButtonEvent += delegate (bool button_enabled) {
                                InvokeOnMainThread (delegate {
                                    AddButton.Enabled = button_enabled;
                                });
                            };

                            ContentView.AddSubview (ScrollView);
                            ContentView.AddSubview (AddressLabel);
                            ContentView.AddSubview (AddressTextField);
                            ContentView.AddSubview (AddressHelpLabel);
                            ContentView.AddSubview (PathLabel);
                            ContentView.AddSubview (PathTextField);
                            ContentView.AddSubview (PathHelpLabel);

                            AddButton = new NSButton () {
                                Title = "Add",
                                Enabled = false
                            };

                                AddButton.Activated += delegate {
                                    Controller.AddPageCompleted (
                                        AddressTextField.StringValue,
                                        PathTextField.StringValue
                                    );
                                };

                            Buttons.Add (AddButton);

                                CancelButton = new NSButton () {
                                    Title = "Cancel"
                                };

                                CancelButton.Activated += delegate {
                                    Controller.PageCancelled ();
                                };

                            Buttons.Add (CancelButton);

                            Controller.CheckAddPage (
                                AddressTextField.StringValue,
                                PathTextField.StringValue,
                                TableView.SelectedRow
                            );

                            break;
                        }

                        case PageType.Syncing: {

                            Header      = "Adding project ‘" + Controller.SyncingFolder + "’…";
                            Description = "This may take a while.\n" +
                                          "Are you sure it’s not coffee o'clock?";

                            ProgressIndicator = new NSProgressIndicator () {
                                Frame    = new RectangleF (190, Frame.Height - 200, 640 - 150 - 80, 20),
                                Style    = NSProgressIndicatorStyle.Bar,
                                MinValue = 0.0,
                                MaxValue = 100.0,
                                Indeterminate = false,
                                DoubleValue = 1.0
                            };

                            ProgressIndicator.StartAnimation (this);

                            Controller.UpdateProgressBarEvent += delegate (double percentage) {
                                InvokeOnMainThread (delegate {
                                    ProgressIndicator.DoubleValue = percentage;
                                });
                            };

                            ContentView.AddSubview (ProgressIndicator);

                            FinishButton = new NSButton () {
                                Title = "Finish",
                                Enabled = false
                            };

                            CancelButton = new NSButton () {
                                Title = "Cancel"
                            };

                            CancelButton.Activated += delegate {
                                Controller.SyncingCancelled ();
                            };

                            Buttons.Add (FinishButton);
                            Buttons.Add (CancelButton);

                            break;
                        }

                        case PageType.Error: {

                            Header      = "Something went wrong…";
                            Description = "Please check the following:";

                            // Displaying marked up text with Cocoa is
                            // a pain, so we just use a webview instead
                            WebView web_view = new WebView ();
                            web_view.Frame = new RectangleF (190, Frame.Height - 525, 375, 400);

                            string html = "<style>" +
                                "* {" +
                                "  font-family: 'Lucida Grande';" +
                                "  font-size: 12px; cursor: default;" +
                                "}" +
                                "body {" +
                                "  -webkit-user-select: none;" +
                                "  margin: 0;" +
                                "  padding: 3px;" +
                                "}" +
                                "li {" +
                                "  margin-bottom: 16px;" +
                                "  margin-left: 0;" +
                                "  padding-left: 0;" +
                                "  line-height: 20px;" +
                                "}" +
                                "ul {" +
                                "  padding-left: 24px;" +
                                "}" +
                                "</style>" +
                                "<ul>" +
                                "  <li>Is the host online?</li>" +
                                "  <li><b>" + Controller.PreviousUrl + "</b> is the address we've compiled. Does this look alright?</li>" +
                                "  <li>The host needs to know who you are. Did you upload the key that's in your SparkleShare folder?</li>" +
                                "</ul>";

                            web_view.MainFrame.LoadHtmlString (html, new NSUrl (""));
                            web_view.DrawsBackground = false;

                            ContentView.AddSubview (web_view);

                            TryAgainButton = new NSButton () {
                                Title = "Try again…"
                            };

                            TryAgainButton.Activated += delegate {
                                Controller.ErrorPageCompleted ();
                            };

                            CancelButton = new NSButton () {
                                Title = "Cancel"
                            };

                            CancelButton.Activated += delegate {
                                Controller.PageCancelled ();
                            };

                            Buttons.Add (TryAgainButton);
                            Buttons.Add (CancelButton);

                            break;
                        }

                        case PageType.Finished: {

                            Header      = "Your shared project is ready!";
                            Description = "You can find it in your SparkleShare folder";

                            if (warnings.Length > 0) {
                                WarningImage = NSImage.ImageNamed ("NSInfo");
                                WarningImage.Size = new SizeF (24, 24);

                                WarningImageView = new NSImageView () {
                                    Image = WarningImage,
                                    Frame = new RectangleF (190, Frame.Height - 175, 24, 24)
                                };

                                WarningTextField = new NSTextField () {
                                    Frame           = new RectangleF (225, Frame.Height - 245, 325, 100),
                                    StringValue     = warnings [0],
                                    BackgroundColor = NSColor.WindowBackground,
                                    Bordered        = false,
                                    Editable        = false,
                                    Font            = SparkleUI.Font
                                };

                                ContentView.AddSubview (WarningImageView);
                                ContentView.AddSubview (WarningTextField);
                            }

                            FinishButton = new NSButton () {
                                Title = "Finish"
                            };

                            FinishButton.Activated += delegate {
                                Controller.FinishPageCompleted ();
                            };

                            OpenFolderButton = new NSButton () {
                                Title = string.Format ("Open {0}", Path.GetFileName (Controller.PreviousPath))
                            };

                            OpenFolderButton.Activated += delegate {
                                Controller.OpenFolderClicked ();
                            };

                            Buttons.Add (FinishButton);
                            Buttons.Add (OpenFolderButton);

                            NSApplication.SharedApplication.RequestUserAttention
                                (NSRequestUserAttentionType.CriticalRequest);

                            NSSound.FromName ("Glass").Play ();

                            break;
                        }

                        case PageType.Tutorial: {

                            switch (Controller.TutorialPageNumber) {
                            case 1: {
                                Header      = "What's happening next?";
                                Description = "SparkleShare creates a special folder on your computer " +
                                    "that will keep track of your projects.";

                                SkipTutorialButton = new NSButton () {
                                    Title = "Skip Tutorial"
                                };

                                SkipTutorialButton.Activated += delegate {
                                    Controller.TutorialSkipped ();
                                };

                                ContinueButton = new NSButton () {
                                    Title = "Continue"
                                };

                                ContinueButton.Activated += delegate {
                                    Controller.TutorialPageCompleted ();
                                };

                                string slide_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath,
                                    "Pixmaps", "tutorial-slide-1-mac.png");

                                SlideImage = new NSImage (slide_image_path) {
                                    Size = new SizeF (350, 200)
                                };

                                SlideImageView = new NSImageView () {
                                    Image = SlideImage,
                                    Frame = new RectangleF (215, Frame.Height - 350, 350, 200)
                                };

                                ContentView.AddSubview (SlideImageView);
                                Buttons.Add (ContinueButton);
                                Buttons.Add (SkipTutorialButton);

                                break;
                            }

                            case 2: {
                                Header      = "Sharing files with others";
                                Description = "All files added to your project folders are synced automatically with " +
                                    "the host and your team members.";

                                ContinueButton = new NSButton () {
                                    Title = "Continue"
                                };

                                ContinueButton.Activated += delegate {
                                    Controller.TutorialPageCompleted ();
                                };

                                string slide_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath,
                                    "Pixmaps", "tutorial-slide-2-mac.png");

                                SlideImage = new NSImage (slide_image_path) {
                                    Size = new SizeF (350, 200)
                                };

                                SlideImageView = new NSImageView () {
                                    Image = SlideImage,
                                    Frame = new RectangleF (215, Frame.Height - 350, 350, 200)
                                };

                                ContentView.AddSubview (SlideImageView);
                                Buttons.Add (ContinueButton);

                                break;
                            }

                            case 3: {
                                Header      = "The status icon is here to help";
                                Description = "It shows the syncing progress, provides easy access to " +
                                    "your projects and let's you view recent changes.";

                                ContinueButton = new NSButton () {
                                    Title = "Continue"
                                };

                                ContinueButton.Activated += delegate {
                                    Controller.TutorialPageCompleted ();
                                };

                                string slide_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath,
                                    "Pixmaps", "tutorial-slide-3-mac.png");

                                SlideImage = new NSImage (slide_image_path) {
                                    Size = new SizeF (350, 200)
                                };

                                SlideImageView = new NSImageView () {
                                    Image = SlideImage,
                                    Frame = new RectangleF (215, Frame.Height - 350, 350, 200)
                                };

                                ContentView.AddSubview (SlideImageView);
                                Buttons.Add (ContinueButton);

                                break;
                            }

                            case 4: {
                                Header      = "Adding projects to SparkleShare";
                                Description = "You can do this through the status icon menu, or by clicking " +
                                    "magic buttons on webpages that look like this:";

                                StartupCheckButton = new NSButton () {
                                    Frame = new RectangleF (190, Frame.Height - 400, 300, 18),
                                    Title = "Add SparkleShare to startup items",
                                    State = NSCellStateValue.On
                                };

                                StartupCheckButton.SetButtonType (NSButtonType.Switch);

                                StartupCheckButton.Activated += delegate {
                                    Controller.StartupItemChanged (StartupCheckButton.State == NSCellStateValue.On);
                                };

                                FinishButton = new NSButton () {
                                    Title = "Finish"
                                };

                                FinishButton.Activated += delegate {
                                    Controller.TutorialPageCompleted ();
                                };

                                string slide_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath,
                                    "Pixmaps", "tutorial-slide-4.png");

                                SlideImage = new NSImage (slide_image_path) {
                                    Size = new SizeF (350, 64)
                                };

                                SlideImageView = new NSImageView () {
                                    Image = SlideImage,
                                    Frame = new RectangleF (215, Frame.Height - 215, 350, 64)
                                };

                                ContentView.AddSubview (SlideImageView);
                                ContentView.AddSubview (StartupCheckButton);
                                Buttons.Add (FinishButton);

                                break;
                            }
                            }

                            break;
                        }
                        }

                        ShowAll ();
                    });
                }
            };
        }
Esempio n. 27
0
        public SparkleSetup()
            : base()
        {
            Controller.ChangePageEvent += delegate (PageType type, string [] warnings) {
                InvokeOnMainThread (delegate {
                    Reset ();

                    switch (type) {
                    case PageType.Setup: {

                        Header       = "Welcome to SparkleShare!";
                        Description  = "Before we can create a SparkleShare folder on this " +
                                       "computer, we need some information from you.";

                        FullNameLabel = new NSTextField () {
                            Alignment       = NSTextAlignment.Right,
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            Editable        = false,
                            Frame           = new RectangleF (165, Frame.Height - 234, 160, 17),
                            StringValue     = "Full Name:",
                            Font            = SparkleUI.Font
                        };

                        FullNameTextField = new NSTextField () {
                            Frame       = new RectangleF (330, Frame.Height - 238, 196, 22),
                            StringValue = Controller.GuessedUserName,
                            Delegate    = new SparkleTextFieldDelegate ()
                        };

                        EmailLabel = new NSTextField () {
                            Alignment       = NSTextAlignment.Right,
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            Editable        = false,
                            Frame           = new RectangleF (165, Frame.Height - 264, 160, 17),
                            StringValue     = "Email:",
                            Font            = SparkleUI.Font
                        };

                        EmailTextField = new NSTextField () {
                            Frame       = new RectangleF (330, Frame.Height - 268, 196, 22),
                            StringValue = Controller.GuessedUserEmail,
                            Delegate    = new SparkleTextFieldDelegate ()
                        };

                        (FullNameTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                            Controller.CheckSetupPage (
                                FullNameTextField.StringValue,
                                EmailTextField.StringValue
                            );
                        };

                        (EmailTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                            Controller.CheckSetupPage (
                                FullNameTextField.StringValue,
                                EmailTextField.StringValue
                            );
                        };

                        ContinueButton = new NSButton () {
                            Title    = "Continue",
                            Enabled  = false
                        };

                        ContinueButton.Activated += delegate {
                            string full_name = FullNameTextField.StringValue.Trim ();
                            string email     = EmailTextField.StringValue.Trim ();

                            Controller.SetupPageCompleted (full_name, email);
                        };

                        Controller.UpdateSetupContinueButtonEvent += delegate (bool button_enabled) {
                            InvokeOnMainThread (delegate {
                                ContinueButton.Enabled = button_enabled;
                            });
                        };

                        ContentView.AddSubview (FullNameLabel);
                        ContentView.AddSubview (FullNameTextField);
                        ContentView.AddSubview (EmailLabel);
                        ContentView.AddSubview (EmailTextField);

                        Buttons.Add (ContinueButton);

                        break;
                    }

                    case PageType.Add: {

                        Header       = "Where's your project hosted?";
                        Description  = "";

                        AddressLabel = new NSTextField () {
                            Alignment       = NSTextAlignment.Left,
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            Editable        = false,
                            Frame           = new RectangleF (190, Frame.Height - 308, 160, 17),
                            StringValue     = "Address:",
                            Font            = SparkleUI.Font
                        };

                        AddressTextField = new NSTextField () {
                            Frame       = new RectangleF (190, Frame.Height - 336, 196, 22),
                            Font        = SparkleUI.Font,
                            StringValue = Controller.PreviousAddress,
                            Enabled     = (Controller.SelectedPlugin.Address == null),
                            Delegate    = new SparkleTextFieldDelegate ()
                        };

                        PathLabel = new NSTextField () {
                            Alignment       = NSTextAlignment.Left,
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            Editable        = false,
                            Frame           = new RectangleF (190 + 196 + 16, Frame.Height - 308, 160, 17),
                            StringValue     = "Remote Path:",
                            Font            = SparkleUI.Font
                        };

                        PathTextField = new NSTextField () {
                            Frame           = new RectangleF (190 + 196 + 16, Frame.Height - 336, 196, 22),
                            StringValue     = Controller.PreviousPath,
                            Enabled         = (Controller.SelectedPlugin.Path == null),
                            Delegate        = new SparkleTextFieldDelegate ()
                        };

                        AddressTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;
                        PathTextField.Cell.LineBreakMode    = NSLineBreakMode.TruncatingTail;

                        PathHelpLabel = new NSTextField () {
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            TextColor       = NSColor.DisabledControlText,
                            Editable        = false,
                            Frame           = new RectangleF (190 + 196 + 16, Frame.Height - 355, 204, 17),
                            StringValue     = "e.g. ‘rupert/website-design’",
                            Font            = NSFontManager.SharedFontManager.FontWithFamily
                                                  ("Lucida Grande", NSFontTraitMask.Condensed, 0, 11)
                        };

                        TableView = new NSTableView () {
                            Frame            = new RectangleF (0, 0, 0, 0),
                            RowHeight        = 30,
                            IntercellSpacing = new SizeF (0, 12),
                            HeaderView       = null,
                            Delegate         = new SparkleTableViewDelegate ()
                        };

                        ScrollView = new NSScrollView () {
                            Frame               = new RectangleF (190, Frame.Height - 280, 408, 175),
                            DocumentView        = TableView,
                            HasVerticalScroller = true,
                            BorderType          = NSBorderType.BezelBorder
                        };

                        IconColumn = new NSTableColumn (new NSImage ()) {
                            Width = 42,
                            HeaderToolTip = "Icon",
                            DataCell = new NSImageCell ()
                        };

                        DescriptionColumn = new NSTableColumn () {
                            Width         = 350,
                            HeaderToolTip = "Description",
                            Editable      = false
                        };

                        DescriptionColumn.DataCell.Font =
                            NSFontManager.SharedFontManager.FontWithFamily (
                                "Lucida Grande", NSFontTraitMask.Condensed, 0, 11);

                        TableView.AddColumn (IconColumn);
                        TableView.AddColumn (DescriptionColumn);

                        DataSource = new SparkleDataSource ();

                        foreach (SparklePlugin plugin in Controller.Plugins)
                            DataSource.Items.Add (plugin);

                        TableView.DataSource = DataSource;
                        TableView.ReloadData ();

                        Controller.ChangeAddressFieldEvent += delegate (string text,
                            string example_text, FieldState state) {

                            InvokeOnMainThread (delegate {
                                AddressTextField.StringValue = text;
                                AddressTextField.Enabled     = (state == FieldState.Enabled);
                            });
                        };

                        Controller.ChangePathFieldEvent += delegate (string text,
                            string example_text, FieldState state) {

                            InvokeOnMainThread (delegate {
                                PathTextField.StringValue = text;
                                PathTextField.Enabled     = (state == FieldState.Enabled);

                                if (!string.IsNullOrEmpty (example_text))
                                    PathHelpLabel.StringValue = "e.g. " + example_text;
                            });
                        };

                        TableView.SelectRow (Controller.SelectedPluginIndex, false);

                         (AddressTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                            Controller.CheckAddPage (
                                AddressTextField.StringValue,
                                PathTextField.StringValue,
                                TableView.SelectedRow
                            );
                        };

                         (PathTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                            Controller.CheckAddPage (
                                AddressTextField.StringValue,
                                PathTextField.StringValue,
                                TableView.SelectedRow
                            );
                        };

                        (TableView.Delegate as SparkleTableViewDelegate).SelectionChanged += delegate {
                            Controller.SelectedPluginChanged (TableView.SelectedRow);

                            Controller.CheckAddPage (
                                AddressTextField.StringValue,
                                PathTextField.StringValue,
                                TableView.SelectedRow
                            );
                        };

                        Controller.UpdateAddProjectButtonEvent += delegate (bool button_enabled) {
                            InvokeOnMainThread (delegate {
                                SyncButton.Enabled = button_enabled;
                            });
                        };

                        ContentView.AddSubview (ScrollView);
                        ContentView.AddSubview (AddressLabel);
                        ContentView.AddSubview (AddressTextField);
                        ContentView.AddSubview (PathLabel);
                        ContentView.AddSubview (PathTextField);
                        ContentView.AddSubview (PathHelpLabel);

                        SyncButton = new NSButton () {
                            Title = "Add",
                            Enabled = false
                        };

                            SyncButton.Activated += delegate {
                                Controller.AddPageCompleted (
                                    AddressTextField.StringValue,
                                    PathTextField.StringValue
                                );
                            };

                        Buttons.Add (SyncButton);

                            CancelButton = new NSButton () {
                                Title = "Cancel"
                            };

                            CancelButton.Activated += delegate {
                                InvokeOnMainThread (delegate {
                                    PerformClose (this);
                                });
                            };

                        Buttons.Add (CancelButton);

                        break;
                    }

                    case PageType.Syncing: {

                        Header      = "Adding project ‘" + Controller.SyncingFolder + "’…";
                        Description = "This may take a while.\n" +
                                      "Are you sure it’s not coffee o'clock?";

                        ProgressIndicator = new NSProgressIndicator () {
                            Frame    = new RectangleF (190, Frame.Height - 200, 640 - 150 - 80, 20),
                            Style    = NSProgressIndicatorStyle.Bar,
                            MinValue = 0.0,
                            MaxValue = 100.0,
                            Indeterminate = false,
                            DoubleValue = 1.0
                        };

                        ProgressIndicator.StartAnimation (this);

                        Controller.UpdateProgressBarEvent += delegate (double percentage) {
                            InvokeOnMainThread (delegate {
                                ProgressIndicator.DoubleValue = percentage;
                            });
                        };

                        ContentView.AddSubview (ProgressIndicator);

                        FinishButton = new NSButton () {
                            Title = "Finish",
                            Enabled = false
                        };

                        CancelButton = new NSButton () {
                            Title = "Cancel"
                        };

                        CancelButton.Activated += delegate {
                            Controller.SyncingCancelled ();
                        };

                        Buttons.Add (FinishButton);
                        Buttons.Add (CancelButton);

                        break;
                    }

                    case PageType.Error: {

                        Header      = "Something went wrong…";
                        Description = "Please check the following:";

                        // Displaying marked up text with Cocoa is
                        // a pain, so we just use a webview instead
                        WebView web_view = new WebView ();
                        web_view.Frame = new RectangleF (190, Frame.Height - 525, 375, 400);

                        string html = "<style>" +
                            "* {" +
                            "  font-family: 'Lucida Grande';" +
                            "  font-size: 12px; cursor: default;" +
                            "}" +
                            "body {" +
                            "  -webkit-user-select: none;" +
                            "  margin: 0;" +
                            "  padding: 3px;" +
                            "}" +
                            "li {" +
                            "  margin-bottom: 16px;" +
                            "  margin-left: 0;" +
                            "  padding-left: 0;" +
                            "  line-height: 20px;" +
                            "}" +
                            "ul {" +
                            "  padding-left: 24px;" +
                            "}" +
                            "</style>" +
                            "<ul>" +
                            "  <li>First, have you tried turning it off and on again?</li>" +
                            "  <li><b>" + Controller.PreviousUrl + "</b> is the address we've compiled. Does this look alright?</li>" +
                            "  <li>The host needs to know who you are. Did you upload the key that's in your SparkleShare folder?</li>" +
                            "</ul>";

                        web_view.MainFrame.LoadHtmlString (html, new NSUrl (""));
                        web_view.DrawsBackground = false;

                        ContentView.AddSubview (web_view);

                        TryAgainButton = new NSButton () {
                            Title = "Try again…"
                        };

                        TryAgainButton.Activated += delegate {
                            Controller.ErrorPageCompleted ();
                        };

                        Buttons.Add (TryAgainButton);

                        break;
                    }

                    case PageType.Finished: {

                        Header      = "Project succesfully added!";
                        Description = "Now you can access the files from " +
                                      "‘" + Controller.SyncingFolder + "’ in " +
                                      "your SparkleShare folder.";

                        if (warnings != null) {
                            WarningImage = NSImage.ImageNamed ("NSCaution");
                            WarningImage.Size = new SizeF (24, 24);

                            WarningImageView = new NSImageView () {
                                Image = WarningImage,
                                Frame = new RectangleF (190, Frame.Height - 175, 24, 24)
                            };

                            WarningTextField = new NSTextField () {
                                Frame           = new RectangleF (230, Frame.Height - 245, 325, 100),
                                StringValue     = warnings [0],
                                BackgroundColor = NSColor.WindowBackground,
                                Bordered        = false,
                                Editable        = false,
                                Font            = SparkleUI.Font
                            };

                            ContentView.AddSubview (WarningImageView);
                            ContentView.AddSubview (WarningTextField);
                        }

                        FinishButton = new NSButton () {
                            Title = "Finish"
                        };

                        FinishButton.Activated += delegate {
                            InvokeOnMainThread (delegate {
                                Controller.FinishedPageCompleted ();
                                PerformClose (this);
                            });
                        };

                        OpenFolderButton = new NSButton () {
                            Title = "Open Folder"
                        };

                        OpenFolderButton.Activated += delegate {
                            Program.Controller.OpenSparkleShareFolder (Controller.SyncingFolder);
                        };

                        Buttons.Add (FinishButton);
                        Buttons.Add (OpenFolderButton);

                        NSApplication.SharedApplication.RequestUserAttention
                            (NSRequestUserAttentionType.CriticalRequest);

                        NSSound.FromName ("Glass").Play ();

                        break;
                    }

                    case PageType.Tutorial: {

                        switch (Controller.TutorialPageNumber) {
                        case 1: {
                            Header      = "What's happening next?";
                            Description = "SparkleShare creates a special folder in your personal folder " +
                                "that will keep track of your projects.";

                            SkipTutorialButton = new NSButton () {
                                Title = "Skip Tutorial"
                            };

                            SkipTutorialButton.Activated += delegate {
                                Controller.TutorialSkipped ();
                            };

                            ContinueButton = new NSButton () {
                                Title = "Continue"
                            };

                            ContinueButton.Activated += delegate {
                                Controller.TutorialPageCompleted ();
                            };

                            string slide_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath,
                                "Pixmaps", "tutorial-slide-1.png");

                            SlideImage = new NSImage (slide_image_path) {
                                Size = new SizeF (350, 200)
                            };

                            SlideImageView = new NSImageView () {
                                Image = SlideImage,
                                Frame = new RectangleF (215, Frame.Height - 350, 350, 200)
                            };

                            ContentView.AddSubview (SlideImageView);
                            Buttons.Add (ContinueButton);
                            Buttons.Add (SkipTutorialButton);

                            break;
                        }

                        case 2: {
                            Header      = "Sharing files with others";
                            Description = "All files added to your project folders are synced with the host " +
                                "automatically, as well as with your collaborators.";

                            ContinueButton = new NSButton () {
                                Title = "Continue"
                            };

                            ContinueButton.Activated += delegate {
                                Controller.TutorialPageCompleted ();
                            };

                            string slide_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath,
                                "Pixmaps", "tutorial-slide-2.png");

                            SlideImage = new NSImage (slide_image_path) {
                                Size = new SizeF (350, 200)
                            };

                            SlideImageView = new NSImageView () {
                                Image = SlideImage,
                                Frame = new RectangleF (215, Frame.Height - 350, 350, 200)
                            };

                            ContentView.AddSubview (SlideImageView);
                            Buttons.Add (ContinueButton);

                            break;
                        }

                        case 3: {
                            Header      = "The status icon is here to help";
                            Description = "It shows the syncing process status, " +
                                "and contains links to your projects and the event log.";

                            ContinueButton = new NSButton () {
                                Title = "Continue"
                            };

                            ContinueButton.Activated += delegate {
                                Controller.TutorialPageCompleted ();
                            };

                            string slide_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath,
                                "Pixmaps", "tutorial-slide-3.png");

                            SlideImage = new NSImage (slide_image_path) {
                                Size = new SizeF (350, 200)
                            };

                            SlideImageView = new NSImageView () {
                                Image = SlideImage,
                                Frame = new RectangleF (215, Frame.Height - 350, 350, 200)
                            };

                            ContentView.AddSubview (SlideImageView);
                            Buttons.Add (ContinueButton);

                            break;
                        }

                        case 4: {
                            Header      = "Adding projects to SparkleShare";
                            Description = "Just click this button when you see it on the web, and " +
                                "the project will be automatically added:";

                            AddProjectTextField = new NSTextField () {
                                Frame           = new RectangleF (190, Frame.Height - 290, 640 - 240, 44),
                                BackgroundColor = NSColor.WindowBackground,
                                Bordered        = false,
                                Editable        = false,
                                Font            = SparkleUI.Font,
                                StringValue     = "…or select ‘Add Hosted Project…’ from the status icon menu " +
                                "to add one by hand."
                            };

                            FinishButton = new NSButton () {
                                Title = "Finish"
                            };

                            FinishButton.Activated += delegate {
                                InvokeOnMainThread (delegate {
                                    PerformClose (this);
                                });
                            };

                            string slide_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath,
                                "Pixmaps", "tutorial-slide-4.png");

                            SlideImage = new NSImage (slide_image_path) {
                                Size = new SizeF (350, 64)
                            };

                            SlideImageView = new NSImageView () {
                                Image = SlideImage,
                                Frame = new RectangleF (215, Frame.Height - 215, 350, 64)
                            };

                            ContentView.AddSubview (SlideImageView);
                            ContentView.AddSubview (AddProjectTextField);
                            Buttons.Add (FinishButton);

                            break;
                        }
                        }

                        break;
                    }
                    }

                    ShowAll ();
                });
            };
        }
        // TODO: Window needs to be made resizable
        public SparkleEventLog()
            : base()
        {
            Title    = "Recent Events";
            Delegate = new SparkleEventsDelegate ();

            SetFrame (new RectangleF (0, 0, 480, 640), true);
            Center ();

            StyleMask = (NSWindowStyle.Closable |
                         NSWindowStyle.Miniaturizable |
                         NSWindowStyle.Titled);

            MaxSize     = new SizeF (480, 640);
            MinSize     = new SizeF (480, 640);
            HasShadow   = true;
            BackingType = NSBackingStore.Buffered;

            this.size_label = new NSTextField () {
                Alignment       = NSTextAlignment.Right,
                BackgroundColor = NSColor.WindowBackground,
                Bordered        = false,
                Editable        = false,
                Frame           = new RectangleF (0, 588, 60, 20),
                StringValue     = "Size:",
                Font            = SparkleUI.BoldFont
            };

            this.size_label_value = new NSTextField () {
                Alignment       = NSTextAlignment.Left,
                BackgroundColor = NSColor.WindowBackground,
                Bordered        = false,
                Editable        = false,
                Frame           = new RectangleF (60, 588, 75, 20),
                StringValue     = "…",
                Font            = SparkleUI.Font
            };

            this.history_label = new NSTextField () {
                Alignment       = NSTextAlignment.Right,
                BackgroundColor = NSColor.WindowBackground,
                Bordered        = false,
                Editable        = false,
                Frame           = new RectangleF (130, 588, 60, 20),
                StringValue     = "History:",
                Font            = SparkleUI.BoldFont
            };

            this.history_label_value = new NSTextField () {
                Alignment       = NSTextAlignment.Left,
                BackgroundColor = NSColor.WindowBackground,
                Bordered        = false,
                Editable        = false,
                Frame           = new RectangleF (190, 588, 75, 20),
                StringValue     = "…",
                Font            = SparkleUI.Font
            };

            ContentView.AddSubview (this.size_label);
            ContentView.AddSubview (this.size_label_value);
            ContentView.AddSubview (this.history_label);
            ContentView.AddSubview (this.history_label_value);
            ContentView.AddSubview (this.separator);

            this.progress_indicator = new NSProgressIndicator () {
                Style = NSProgressIndicatorStyle.Spinning,
                Frame = new RectangleF (this.web_view.Frame.Width / 2 - 10, this.web_view.Frame.Height / 2 + 10, 20, 20)
            };

            this.progress_indicator.StartAnimation (this);
            ContentView.AddSubview (this.progress_indicator);

            UpdateContent (null);
            UpdateChooser (null);
            OrderFrontRegardless ();

            Program.UI.UpdateDockIconVisibility ();

            // Hook up the controller events
            Controller.UpdateChooserEvent += delegate (string [] folders) {
                InvokeOnMainThread (delegate {
                    UpdateChooser (folders);
                });
            };

            Controller.UpdateContentEvent += delegate (string html) {
                InvokeOnMainThread (delegate {
                    UpdateContent (html);
                });
            };

            Controller.ContentLoadingEvent += delegate {
                InvokeOnMainThread (delegate {
                    if (this.web_view.Superview == ContentView)
                        this.web_view.RemoveFromSuperview ();

                    ContentView.AddSubview (this.progress_indicator);
                });
            };

            Controller.UpdateSizeInfoEvent += delegate (string size, string history_size) {
                InvokeOnMainThread (delegate {
                    this.size_label_value.StringValue = size;
                    this.history_label_value.StringValue = history_size;
                });
            };
        }
        private void Initialize(IHostResourceProvider hostResources, object selectedValue)
        {
            this.selectedValue = selectedValue;
            Frame = new CGRect(10, 35, 630, 305);

            var FrameHeightHalf = (Frame.Height - 32) / 2;
            var FrameWidthHalf  = (Frame.Width - 32) / 2;
            var FrameWidthThird = (Frame.Width - 32) / 3;

            this.progressIndicator = new NSProgressIndicator(new CGRect(FrameWidthThird, FrameHeightHalf, 32, 32))
            {
                Hidden = true,
                Style  = NSProgressIndicatorStyle.Spinning,
                TranslatesAutoresizingMaskIntoConstraints = false,
            };
            AddSubview(this.progressIndicator);

            this.resourceTable = new FirstResponderTableView {
                AutoresizingMask = NSViewResizingMask.WidthSizable,
                HeaderView       = null,
            };

            this.dataSource = new ResourceTableDataSource(viewModel);
            var resourceTableDelegate = new ResourceTableDelegate(hostResources, dataSource);

            resourceTableDelegate.ResourceSelected += (sender, e) => {
                this.previewPanel.SelectedResource = SelectedResource;

                this.selectedValue = BrushPropertyViewModel.GetCommonBrushForResource(SelectedResource);

                ResourceSelected?.Invoke(this, EventArgs.Empty);
            };
            this.resourceTable.Delegate   = resourceTableDelegate;
            this.resourceTable.DataSource = dataSource;

            NSTableColumn resourceImages = new NSTableColumn(ResourceImageColId)
            {
                Title = Properties.Resources.ResourceTableImageColumnTitle, Width = 32
            };

            this.resourceTable.AddColumn(resourceImages);

            NSTableColumn resourceTypes = new NSTableColumn(ResourceTypeColId)
            {
                Title = Properties.Resources.ResourceTableTypeColumnTitle, Width = 150
            };

            this.resourceTable.AddColumn(resourceTypes);

            NSTableColumn resourceName = new NSTableColumn(ResourceNameColId)
            {
                Title = Properties.Resources.ResourceTableNameColumnTitle, Width = 150
            };

            resourceTable.AddColumn(resourceName);

            NSTableColumn resourceValue = new NSTableColumn(ResourceValueColId)
            {
                Title = Properties.Resources.ResourceTableValueColumnTitle, Width = 45
            };

            this.resourceTable.AddColumn(resourceValue);

            this.resourceTable.DoubleClick += (object sender, EventArgs e) => {
                DoubleClicked?.Invoke(this, EventArgs.Empty);
            };

            // create a table view and a scroll view
            this.tableContainer = new NSScrollView(new CGRect(0, 0, resourceTable.TableColumns()[0].Width + resourceTable.TableColumns()[1].Width + resourceTable.TableColumns()[2].Width + 10, Frame.Height))
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
            };

            this.tableContainer.DocumentView = resourceTable;
            AddSubview(this.tableContainer);

            this.previewPanel = new RequestResourcePreviewPanel(hostResources, new CGRect(Frame.Width - FrameWidthThird, 0, FrameWidthThird, Frame.Height));
            AddSubview(this.previewPanel);

            this.AddConstraints(new[] {
                NSLayoutConstraint.Create(this.tableContainer, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -190f),
                NSLayoutConstraint.Create(this.tableContainer, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this, NSLayoutAttribute.Height, 1f, 0f),
            });

            ReloadData();
        }
Esempio n. 30
0
        public SparkleSetup()
            : base()
        {
            Controller.ChangePageEvent += delegate (PageType type) {
                InvokeOnMainThread (delegate {
                    Reset ();

                    switch (type) {
                    case PageType.Setup: {

                        Header       = "Welcome to SparkleShare!";
                        Description  = "Before we can create a SparkleShare folder on this " +
                                       "computer, we need some information from you.";

                        UserInfoForm = new NSForm (new RectangleF (250, Frame.Height - 280, 350, 64));

                        UserInfoForm.AddEntry ("Full Name:");
                        UserInfoForm.AddEntry ("Email Address:");

                        UserInfoForm.CellSize                = new SizeF (280, 22);
                        UserInfoForm.IntercellSpacing        = new SizeF (4, 4);
                        UserInfoForm.Cells [0].LineBreakMode = NSLineBreakMode.TruncatingTail;
                        UserInfoForm.Cells [1].LineBreakMode = NSLineBreakMode.TruncatingTail;

                        UserInfoForm.Cells [0].StringValue   = Controller.GuessedUserName;
                        UserInfoForm.Cells [1].StringValue   = Controller.GuessedUserEmail;

                        // TODO: Ugly hack, do properly with events
                        timer = new Timer () {
                            Interval = 50
                        };

                        ContinueButton = new NSButton () {
                            Title    = "Continue",
                            Enabled  = false
                        };

                        ContinueButton.Activated += delegate {
                            timer.Stop ();
                            timer = null;

                            string full_name = UserInfoForm.Cells [0].StringValue.Trim ();
                            string email = UserInfoForm.Cells [1].StringValue.Trim ();

                            Controller.SetupPageCompleted (full_name, email);
                        };

                        timer.Elapsed += delegate {
                            InvokeOnMainThread (delegate {
                                bool name_is_valid = !UserInfoForm.Cells [0].StringValue.Trim ().Equals ("");

                                bool email_is_valid = Program.Controller.IsValidEmail (
                                    UserInfoForm.Cells [1].StringValue.Trim ());

                                ContinueButton.Enabled = (name_is_valid && email_is_valid);
                            });
                        };

                        timer.Start ();

                        ContentView.AddSubview (UserInfoForm);
                        Buttons.Add (ContinueButton);

                        break;
                    }

                    case PageType.Add: {

                        Header       = "Where is your project?";
                        Description  = "";

                        ServerTypeLabel  = new NSTextField () {
                            Alignment       = NSTextAlignment.Right,
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            Editable        = false,
                            Frame           = new RectangleF (150, Frame.Height - 159 , 160, 17),
                            StringValue     = "Host Type:",
                            Font            = SparkleUI.Font
                        };

                        AddressLabel = new NSTextField () {
                            Alignment       = NSTextAlignment.Right,
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            Editable        = false,
                            Frame           = new RectangleF (150, Frame.Height - 257 , 160, 17),
                            StringValue     = "Address:",
                            Font            = SparkleUI.Font
                        };

                        FolderNameLabel = new NSTextField () {
                            Alignment       = NSTextAlignment.Right,
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            Editable        = false,
                            Frame           = new RectangleF (150, Frame.Height - 284 , 160, 17),
                            StringValue     = "Folder Name:",
                            Font            = SparkleUI.Font
                        };

                        AddressTextField = new NSTextField () {
                            Frame       = new RectangleF (320, Frame.Height - 260 , 256, 22),
                            Font        = SparkleUI.Font,
                            StringValue = Controller.PreviousServer
                        };

                        AddressTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;

                        FolderNameTextField = new NSTextField () {
                            Frame           = new RectangleF (320, Frame.Height - (260 + 22 + 4) , 256, 22),
                            StringValue     = Controller.PreviousFolder
                        };

                        FolderNameTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;

                        FolderNameHelpLabel = new NSTextField () {
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            TextColor       = NSColor.DisabledControlText,
                            Editable        = false,
                            Frame           = new RectangleF (320, Frame.Height - 305 , 200, 17),
                            StringValue     = "e.g. ‘rupert/website-design’"
                        };

                        ServerType = 0;

                        ButtonCellProto = new NSButtonCell ();
                        ButtonCellProto.SetButtonType (NSButtonType.Radio) ;

                        Matrix = new NSMatrix (new RectangleF (315, Frame.Height - 220, 256, 78),
                            NSMatrixMode.Radio, ButtonCellProto, 4, 1);

                        Matrix.CellSize = new SizeF (256, 18);

                        Matrix.Cells [0].Title = "My own server";
                        Matrix.Cells [1].Title = "Github";
                        Matrix.Cells [2].Title = "Gitorious";
                        Matrix.Cells [3].Title = "The GNOME Project";

                        foreach (NSCell cell in Matrix.Cells)
                            cell.Font = SparkleUI.Font;

                        // TODO: Ugly hack, do properly with events
                        timer = new Timer () {
                            Interval = 50
                        };

                        timer.Elapsed += delegate {
                            InvokeOnMainThread (delegate {
                                if (Matrix.SelectedRow != ServerType) {
                                    ServerType = Matrix.SelectedRow;

                                    AddressTextField.Enabled = (ServerType == 0);

                                    switch (ServerType) {
                                    case 0:
                                        AddressTextField.StringValue = "";
                                        FolderNameHelpLabel.StringValue = "e.g. ‘rupert/website-design’";
                                        break;
                                    case 1:
                                        AddressTextField.StringValue = "ssh://[email protected]/";
                                        FolderNameHelpLabel.StringValue = "e.g. ‘rupert/website-design’";
                                        break;
                                    case 2:
                                        AddressTextField.StringValue = "ssh://[email protected]/";
                                        FolderNameHelpLabel.StringValue = "e.g. ‘project/website-design’";
                                        break;
                                    case 3:
                                        AddressTextField.StringValue = "ssh://[email protected]/git/";
                                        FolderNameHelpLabel.StringValue = "e.g. ‘gnome-icon-theme’";
                                        break;
                                    }
                                }

                                if (ServerType == 0 && !AddressTextField.StringValue.Trim ().Equals ("")
                                    && !FolderNameTextField.StringValue.Trim ().Equals ("")) {

                                    SyncButton.Enabled = true;

                                } else if (ServerType != 0 &&
                                           !FolderNameTextField.StringValue.Trim ().Equals ("")) {

                                    SyncButton.Enabled = true;

                                } else {
                                    SyncButton.Enabled = false;
                                }
                            });

                        };

                        timer.Start ();

                        ContentView.AddSubview (ServerTypeLabel);
                        ContentView.AddSubview (Matrix);

                        ContentView.AddSubview (AddressLabel);
                        ContentView.AddSubview (AddressTextField);

                        ContentView.AddSubview (FolderNameLabel);
                        ContentView.AddSubview (FolderNameTextField);
                        ContentView.AddSubview (FolderNameHelpLabel);

                        SyncButton = new NSButton () {
                            Title = "Add",
                            Enabled = false
                        };

                            SyncButton.Activated += delegate {
                                timer.Stop ();
                                timer = null;

                                string folder_name    = FolderNameTextField.StringValue;
                                string server         = AddressTextField.StringValue;
                                Controller.AddPageCompleted (server, folder_name);
                            };

                        Buttons.Add (SyncButton);

                            CancelButton = new NSButton () {
                                Title = "Cancel"
                            };

                            CancelButton.Activated += delegate {
                                InvokeOnMainThread (delegate {
                                    PerformClose (this);
                                });
                            };

                            Buttons.Add (CancelButton);

                        break;
                    }

                    case PageType.Syncing: {

                        Header      = "Adding project ‘" + Controller.SyncingFolder + "’…";
                        Description = "This may take a while.\n" +
                                      "Are you sure it’s not coffee o'clock?";

                        ProgressIndicator = new NSProgressIndicator () {
                            Frame    = new RectangleF (190, Frame.Height - 200, 640 - 150 - 80, 20),
                            Style    = NSProgressIndicatorStyle.Bar,
                            MinValue = 0.0,
                            MaxValue = 100.0,
                            Indeterminate = false,
                            DoubleValue = 1.0
                        };

                        ProgressIndicator.StartAnimation (this);

                        Controller.UpdateProgressBarEvent += delegate (double percentage) {
                            InvokeOnMainThread (delegate {
                                ProgressIndicator.DoubleValue = percentage;
                            });
                        };

                        ContentView.AddSubview (ProgressIndicator);

                        FinishButton = new NSButton () {
                            Title = "Finish",
                            Enabled = false
                        };

                        CancelButton = new NSButton () {
                            Title = "Cancel"
                        };

                        CancelButton.Activated += delegate {
                            Controller.SyncingCancelled ();
                        };

                        Buttons.Add (FinishButton);
                        Buttons.Add (CancelButton);

                        break;
                    }

                    case PageType.Error: {

                        Header      = "Something went wrong…";
                        Description = "";

                        TryAgainButton = new NSButton () {
                            Title = "Try again…"
                        };

                        TryAgainButton.Activated += delegate {
                            Controller.ErrorPageCompleted ();
                        };

                        Buttons.Add (TryAgainButton);

                        break;
                    }

                    case PageType.Finished: {

                        Header      = "Project succesfully added!";
                        Description = "Now you can access the files from " +
                                      "‘" + Controller.SyncingFolder + "’ in " +
                                      "your SparkleShare folder.";

                        FinishButton = new NSButton () {
                            Title = "Finish"
                        };

                        FinishButton.Activated += delegate {
                            InvokeOnMainThread (delegate {
                                Controller.FinishedPageCompleted ();
                                PerformClose (this);
                            });
                        };

                        OpenFolderButton = new NSButton () {
                            Title = "Open Folder"
                        };

                        OpenFolderButton.Activated += delegate {
                            Program.Controller.OpenSparkleShareFolder (Controller.SyncingFolder);
                        };

                        Buttons.Add (FinishButton);
                        Buttons.Add (OpenFolderButton);

                        NSApplication.SharedApplication.RequestUserAttention
                            (NSRequestUserAttentionType.CriticalRequest);

                        NSSound.FromName ("Glass").Play ();

                        break;
                    }

                    case PageType.Tutorial: {

                        switch (Controller.TutorialPageNumber) {
                        case 1: {
                            Header      = "What's happening next?";
                            Description = "SparkleShare creates a special folder in your personal folder " +
                                "that will keep track of your projects.";

                            SkipTutorialButton = new NSButton () {
                                Title = "Skip Tutorial"
                            };

                            SkipTutorialButton.Activated += delegate {
                                Controller.TutorialSkipped ();
                            };

                            ContinueButton = new NSButton () {
                                Title = "Continue"
                            };

                            ContinueButton.Activated += delegate {
                                Controller.TutorialPageCompleted ();
                            };

                            string slide_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath,
                                "Pixmaps", "tutorial-slide-1.png");

                            SlideImage = new NSImage (slide_image_path) {
                                Size = new SizeF (350, 200)
                            };

                            SlideImageView = new NSImageView () {
                                Image = SlideImage,
                                Frame = new RectangleF (215, Frame.Height - 350, 350, 200)
                            };

                            ContentView.AddSubview (SlideImageView);
                            Buttons.Add (ContinueButton);
                            Buttons.Add (SkipTutorialButton);

                            break;
                        }

                        case 2: {
                            Header      = "Sharing files with others";
                            Description = "All files added to your project folders are synced with the host " +
                                "automatically, as well as with your collaborators.";

                            ContinueButton = new NSButton () {
                                Title = "Continue"
                            };

                            ContinueButton.Activated += delegate {
                                Controller.TutorialPageCompleted ();
                            };

                            string slide_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath,
                                "Pixmaps", "tutorial-slide-2.png");

                            SlideImage = new NSImage (slide_image_path) {
                                Size = new SizeF (350, 200)
                            };

                            SlideImageView = new NSImageView () {
                                Image = SlideImage,
                                Frame = new RectangleF (215, Frame.Height - 350, 350, 200)
                            };

                            ContentView.AddSubview (SlideImageView);
                            Buttons.Add (ContinueButton);

                            break;
                        }

                        case 3: {
                            Header      = "The status icon is here to help";
                            Description = "It shows the syncing process status, " +
                                "and contains links to your projects and the event log.";

                            ContinueButton = new NSButton () {
                                Title = "Continue"
                            };

                            ContinueButton.Activated += delegate {
                                Controller.TutorialPageCompleted ();
                            };

                            string slide_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath,
                                "Pixmaps", "tutorial-slide-3.png");

                            SlideImage = new NSImage (slide_image_path) {
                                Size = new SizeF (350, 200)
                            };

                            SlideImageView = new NSImageView () {
                                Image = SlideImage,
                                Frame = new RectangleF (215, Frame.Height - 350, 350, 200)
                            };

                            ContentView.AddSubview (SlideImageView);
                            Buttons.Add (ContinueButton);

                            break;
                        }

                        case 4: {
                            Header      = "Adding projects to SparkleShare";
                            Description = "Just click this button when you see it on the web, and " +
                                "the project will be automatically added:";

                            AddProjectTextField = new NSTextField () {
                                Frame           = new RectangleF (190, Frame.Height - 290, 640 - 240, 44),
                                BackgroundColor = NSColor.WindowBackground,
                                Bordered        = false,
                                Editable        = false,
                                Font            = SparkleUI.Font,
                                StringValue     = "…or select ‘Add Project…’ from the status icon menu " +
                                "to add one by hand."
                            };

                            AddProjectButton = new NSButton () {
                                Title = "Add Project…"
                            };

                            AddProjectButton.Activated += delegate {
                                Controller.TutorialPageCompleted ();
                            };

                            FinishButton = new NSButton () {
                                Title = "Finish"
                            };

                            FinishButton.Activated += delegate {
                                InvokeOnMainThread (delegate {
                                    PerformClose (this);
                                });
                            };

                            string slide_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath,
                                "Pixmaps", "tutorial-slide-4.png");

                            SlideImage = new NSImage (slide_image_path) {
                                Size = new SizeF (350, 64)
                            };

                            SlideImageView = new NSImageView () {
                                Image = SlideImage,
                                Frame = new RectangleF (215, Frame.Height - 215, 350, 64)
                            };

                            ContentView.AddSubview (SlideImageView);
                            ContentView.AddSubview (AddProjectTextField);
                            Buttons.Add (FinishButton);
                            Buttons.Add (AddProjectButton);

                            break;
                        }
                        }

                        break;
                    }
                    }

                    ShowAll ();
                });
            };
        }
Esempio n. 31
0
        public SparkleEventLog() : base()
        {
            using (var a = new NSAutoreleasePool())
            {
                Title    = "Recent Changes";
                Delegate = new SparkleEventsDelegate();
                // TODO: Make window resizable

                int   width  = 480;
                int   height = 640;
                float x      = (float)(NSScreen.MainScreen.Frame.Width * 0.61);
                float y      = (float)(NSScreen.MainScreen.Frame.Height * 0.5 - (height * 0.5));

                SetFrame(new RectangleF(x, y, width, height), true);


                StyleMask = (NSWindowStyle.Closable |
                             NSWindowStyle.Miniaturizable |
                             NSWindowStyle.Titled);

                MaxSize     = new SizeF(480, 640);
                MinSize     = new SizeF(480, 640);
                HasShadow   = true;
                BackingType = NSBackingStore.Buffered;


                this.web_view = new WebView(new RectangleF(0, 0, 481, 579), "", "")
                {
                    PolicyDelegate = new SparkleWebPolicyDelegate()
                };


                this.hidden_close_button = new NSButton()
                {
                    Frame = new RectangleF(0, 0, 0, 0),
                    KeyEquivalentModifierMask = NSEventModifierMask.CommandKeyMask,
                    KeyEquivalent             = "w"
                };

                this.hidden_close_button.Activated += delegate {
                    Controller.WindowClosed();
                };


                this.size_label = new NSTextField()
                {
                    Alignment       = NSTextAlignment.Right,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF(0, 588, 60, 20),
                    StringValue     = "Size:",
                    Font            = SparkleUI.BoldFont
                };

                this.size_label_value = new NSTextField()
                {
                    Alignment       = NSTextAlignment.Left,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF(60, 588, 75, 20),
                    StringValue     = "…",
                    Font            = SparkleUI.Font
                };


                this.history_label = new NSTextField()
                {
                    Alignment       = NSTextAlignment.Right,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF(130, 588, 60, 20),
                    StringValue     = "History:",
                    Font            = SparkleUI.BoldFont
                };

                this.history_label_value = new NSTextField()
                {
                    Alignment       = NSTextAlignment.Left,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF(190, 588, 75, 20),
                    StringValue     = "…",
                    Font            = SparkleUI.Font
                };


                this.separator = new NSBox(new RectangleF(0, 579, 480, 1))
                {
                    BorderColor = NSColor.LightGray,
                    BoxType     = NSBoxType.NSBoxCustom
                };


                this.background = new NSBox(new RectangleF(0, -1, 481, 581))
                {
                    FillColor = NSColor.White,
                    BoxType   = NSBoxType.NSBoxCustom
                };


                this.progress_indicator = new NSProgressIndicator()
                {
                    Style = NSProgressIndicatorStyle.Spinning,
                    Frame = new RectangleF(this.web_view.Frame.Width / 2 - 10,
                                           this.web_view.Frame.Height / 2 + 10, 20, 20)
                };

                this.progress_indicator.StartAnimation(this);


                ContentView.AddSubview(this.size_label);
                ContentView.AddSubview(this.size_label_value);
                ContentView.AddSubview(this.history_label);
                ContentView.AddSubview(this.history_label_value);
                ContentView.AddSubview(this.separator);
                ContentView.AddSubview(this.progress_indicator);
                ContentView.AddSubview(this.background);
                ContentView.AddSubview(this.hidden_close_button);


                (this.web_view.PolicyDelegate as SparkleWebPolicyDelegate).LinkClicked += delegate(string href) {
                    Controller.LinkClicked(href);
                };
            }


            // Hook up the controller events
            Controller.HideWindowEvent += delegate {
                using (var a = new NSAutoreleasePool())
                {
                    InvokeOnMainThread(delegate {
                        PerformClose(this);

                        if (this.web_view.Superview == ContentView)
                        {
                            this.web_view.RemoveFromSuperview();
                        }
                    });
                }
            };

            Controller.ShowWindowEvent += delegate {
                using (var a = new NSAutoreleasePool())
                {
                    InvokeOnMainThread(delegate {
                        OrderFrontRegardless();
                    });
                }
            };

            Controller.UpdateChooserEvent += delegate(string [] folders) {
                using (var a = new NSAutoreleasePool())
                {
                    InvokeOnMainThread(delegate {
                        UpdateChooser(folders);
                    });
                }
            };

            Controller.UpdateContentEvent += delegate(string html) {
                using (var a = new NSAutoreleasePool())
                {
                    InvokeOnMainThread(delegate {
                        UpdateContent(html);
                    });
                }
            };

            Controller.ContentLoadingEvent += delegate {
                using (var a = new NSAutoreleasePool())
                {
                    InvokeOnMainThread(delegate {
                        if (this.web_view.Superview == ContentView)
                        {
                            this.web_view.RemoveFromSuperview();
                        }

                        ContentView.AddSubview(this.progress_indicator);
                    });
                }
            };

            Controller.UpdateSizeInfoEvent += delegate(string size, string history_size) {
                using (var a = new NSAutoreleasePool())
                {
                    InvokeOnMainThread(delegate {
                        this.size_label_value.StringValue    = size;
                        this.history_label_value.StringValue = history_size;
                    });
                }
            };
        }
 public ControlsSet(NSLinkLabel content, NSProgressIndicator progress)
 {
     this.content  = content;
     this.progress = progress;
 }
Esempio n. 33
0
 void ShowSyncingPage()
 {
     Header.StringValue = Properties_Resources.AddingFolder + " ‘" + Controller.SyncingReponame + "’…";
     Description.StringValue = Properties_Resources.MayTakeTime;
     NSProgressIndicator progress = new NSProgressIndicator() {
         Frame = new RectangleF(0, 140, 300, 20),
         Style = NSProgressIndicatorStyle.Bar,
         MinValue = 0.0,
         MaxValue = 100.0,
         Indeterminate = false,
         DoubleValue = Controller.ProgressBarPercentage
     };
     progress.StartAnimation(this);
     Content.ContentView = progress;
 }
Esempio n. 34
0
        public SparkleSetup()
            : base()
        {
            Controller.ChangePageEvent += delegate (PageType type) {
                InvokeOnMainThread (delegate {
                    Reset ();

                    switch (type) {
                    case PageType.Setup:

                        Header       = "Welcome to SparkleShare!";
                        Description  = "Before we can create a SparkleShare folder on this " +
                                       "computer, we need some information from you.";

                        UserInfoForm = new NSForm (new RectangleF (250, 115, 350, 64));

                        UserInfoForm.AddEntry ("Full Name:");
                        UserInfoForm.AddEntry ("Email Address:");

                        UserInfoForm.CellSize                = new SizeF (280, 22);
                        UserInfoForm.IntercellSpacing        = new SizeF (4, 4);
                        UserInfoForm.Cells [0].LineBreakMode = NSLineBreakMode.TruncatingTail;
                        UserInfoForm.Cells [1].LineBreakMode = NSLineBreakMode.TruncatingTail;

                        UserInfoForm.Cells [0].StringValue   = SparkleShare.Controller.UserName;
                        UserInfoForm.Cells [1].StringValue   = SparkleShare.Controller.UserEmail;

                        // TODO: Ugly hack, do properly with events
                        timer = new Timer () {
                            Interval = 50
                        };

                        ContinueButton = new NSButton () {
                            Title    = "Continue",
                            Enabled  = false
                        };

                        ContinueButton.Activated += delegate {
                            timer.Stop ();
                            timer = null;

                            string full_name = UserInfoForm.Cells [0].StringValue.Trim ();
                            string email = UserInfoForm.Cells [1].StringValue.Trim ();

                            Controller.SetupPageCompleted (full_name, email);
                        };

                        timer.Elapsed += delegate {
                            InvokeOnMainThread (delegate {
                                bool name_is_valid = !UserInfoForm.Cells [0].StringValue.Trim ().Equals ("");

                                bool email_is_valid = SparkleShare.Controller.IsValidEmail (
                                    UserInfoForm.Cells [1].StringValue.Trim ());

                                ContinueButton.Enabled = (name_is_valid && email_is_valid);
                            });
                        };

                        timer.Start ();

                        ContentView.AddSubview (UserInfoForm);
                        Buttons.Add (ContinueButton);

                        break;

                    case PageType.Add:

                        Header       = "Where is your remote folder?";
                        Description  = "";

                        ServerTypeLabel  = new NSTextField () {
                            Alignment       = NSTextAlignment.Right,
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            Editable        = false,
                            Frame           = new RectangleF (150, Frame.Height - 139 , 160, 17),
                            StringValue     = "Server Type:",
                            Font            = SparkleUI.Font
                        };

                        AddressLabel = new NSTextField () {
                            Alignment       = NSTextAlignment.Right,
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            Editable        = false,
                            Frame           = new RectangleF (150, Frame.Height - 237 , 160, 17),
                            StringValue     = "Address:",
                            Font            = SparkleUI.Font
                        };

                        FolderNameLabel = new NSTextField () {
                            Alignment       = NSTextAlignment.Right,
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            Editable        = false,
                            Frame           = new RectangleF (150, Frame.Height - 264 , 160, 17),
                            StringValue     = "Folder Name:",
                            Font            = SparkleUI.Font
                        };

                        AddressTextField = new NSTextField () {
                            Frame       = new RectangleF (320, Frame.Height - 240 , 256, 22),
                            Font        = SparkleUI.Font,
                            StringValue = Controller.PreviousServer
                        };

                        AddressTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;

                        FolderNameTextField = new NSTextField () {
                            Frame           = new RectangleF (320, Frame.Height - (240 + 22 + 4) , 256, 22),
                            StringValue     = Controller.PreviousFolder
                        };

                        FolderNameTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;

                        FolderNameHelpLabel = new NSTextField () {
                            BackgroundColor = NSColor.WindowBackground,
                            Bordered        = false,
                            TextColor       = NSColor.DisabledControlText,
                            Editable        = false,
                            Frame           = new RectangleF (320, Frame.Height - 285 , 200, 17),
                            StringValue     = "e.g. ‘rupert/website-design’"
                        };

                        ServerType = 0;

                        ButtonCellProto = new NSButtonCell ();
                        ButtonCellProto.SetButtonType (NSButtonType.Radio) ;

                        Matrix = new NSMatrix (new RectangleF (315, 180, 256, 78),
                            NSMatrixMode.Radio, ButtonCellProto, 4, 1);

                        Matrix.CellSize = new SizeF (256, 18);

                        Matrix.Cells [0].Title = "My own server";
                        Matrix.Cells [1].Title = "Github";
                        Matrix.Cells [2].Title = "Gitorious";
                        Matrix.Cells [3].Title = "The GNOME Project";

                        foreach (NSCell cell in Matrix.Cells)
                            cell.Font = SparkleUI.Font;

                        // TODO: Ugly hack, do properly with events
                        timer = new Timer () {
                            Interval = 50
                        };

                        timer.Elapsed += delegate {
                            InvokeOnMainThread (delegate {
                                if (Matrix.SelectedRow != ServerType) {
                                    ServerType = Matrix.SelectedRow;

                                    AddressTextField.Enabled = (ServerType == 0);

                                    switch (ServerType) {
                                    case 0:
                                        AddressTextField.StringValue = "";
                                        FolderNameHelpLabel.StringValue = "e.g. ‘rupert/website-design’";
                                        break;
                                    case 1:
                                        AddressTextField.StringValue = "ssh://[email protected]/";
                                        FolderNameHelpLabel.StringValue = "e.g. ‘rupert/website-design’";
                                        break;
                                    case 2:
                                        AddressTextField.StringValue = "ssh://[email protected]/";
                                        FolderNameHelpLabel.StringValue = "e.g. ‘project/website-design’";
                                        break;
                                    case 3:
                                        AddressTextField.StringValue = "ssh://[email protected]/git/";
                                        FolderNameHelpLabel.StringValue = "e.g. ‘gnome-icon-theme’";
                                        break;
                                    }
                                }

                                if (ServerType == 0 && !AddressTextField.StringValue.Trim ().Equals ("")
                                    && !FolderNameTextField.StringValue.Trim ().Equals ("")) {

                                    SyncButton.Enabled = true;

                                } else if (ServerType != 0 &&
                                           !FolderNameTextField.StringValue.Trim ().Equals ("")) {

                                    SyncButton.Enabled = true;

                                } else {
                                    SyncButton.Enabled = false;
                                }
                            });

                        };

                        timer.Start ();

                        ContentView.AddSubview (ServerTypeLabel);
                        ContentView.AddSubview (Matrix);

                        ContentView.AddSubview (AddressLabel);
                        ContentView.AddSubview (AddressTextField);

                        ContentView.AddSubview (FolderNameLabel);
                        ContentView.AddSubview (FolderNameTextField);
                        ContentView.AddSubview (FolderNameHelpLabel);

                        SyncButton = new NSButton () {
                            Title = "Sync",
                            Enabled = false
                        };

                            SyncButton.Activated += delegate {
                                timer.Stop ();
                                timer = null;

                                string folder_name    = FolderNameTextField.StringValue;
                                string server         = AddressTextField.StringValue;
                                Controller.AddPageCompleted (server, folder_name);
                            };

                        Buttons.Add (SyncButton);

                            CancelButton = new NSButton () {
                                Title = "Cancel"
                            };

                            CancelButton.Activated += delegate {
                                InvokeOnMainThread (delegate {
                                    PerformClose (this);
                                });
                            };

                            Buttons.Add (CancelButton);

                        break;

                    case PageType.Syncing:

                        Header      = "Syncing folder ‘" + Controller.SyncingFolder + "’…";
                        Description = "This may take a while.\n" +
                                      "Are you sure it’s not coffee o'clock?";

                        ProgressIndicator = new NSProgressIndicator () {
                            Frame = new RectangleF (190, Frame.Height - 200, 640 - 150 - 80, 20),
                            Style = NSProgressIndicatorStyle.Bar
                        };

                        ProgressIndicator.StartAnimation (this);
                        ContentView.AddSubview (ProgressIndicator);

                        FinishButton = new NSButton () {
                            Title = "Finish",
                            Enabled = false
                        };

                        Buttons.Add (FinishButton);

                        break;

                    case PageType.Error:

                        Header      = "Something went wrong…";
                        Description = "";

                        TryAgainButton = new NSButton () {
                            Title = "Try again…"
                        };

                        TryAgainButton.Activated += delegate {
                            Controller.ErrorPageCompleted ();
                        };

                        Buttons.Add (TryAgainButton);

                        break;

                    case PageType.Finished:

                        Header      = "Folder synced succesfully!";
                        Description = "Now you can access the synced files from " +
                                      "‘" + Controller.SyncingFolder + "’ in " +
                                      "your SparkleShare folder.";

                        FinishButton = new NSButton () {
                            Title = "Finish"
                        };

                        FinishButton.Activated += delegate {
                            InvokeOnMainThread (delegate {
                                PerformClose (this);
                            });
                        };

                        OpenFolderButton = new NSButton () {
                            Title = "Open Folder"
                        };

                        OpenFolderButton.Activated += delegate {
                            SparkleShare.Controller.OpenSparkleShareFolder (Controller.SyncingFolder);
                        };

                        Buttons.Add (FinishButton);
                        Buttons.Add (OpenFolderButton);

                        NSApplication.SharedApplication.RequestUserAttention
                            (NSRequestUserAttentionType.CriticalRequest);

                        break;
                    }

                    ShowAll ();
                });
            };
        }
Esempio n. 35
0
        public void ShowPage(PageType type, string [] warnings)
        {
            if (type == PageType.Setup)
            {
                Header      = "Welcome to SparkleShare!";
                Description = "First off, what’s your name and email?\n(visible only to team members)";

                FullNameLabel       = new SparkleLabel("Full Name:", NSTextAlignment.Right);
                FullNameLabel.Frame = new RectangleF(165, Frame.Height - 234, 160, 17);

                FullNameTextField = new NSTextField()
                {
                    Frame       = new RectangleF(330, Frame.Height - 238, 196, 22),
                    StringValue = UnixUserInfo.GetRealUser().RealName,
                    Delegate    = new SparkleTextFieldDelegate()
                };

                EmailLabel       = new SparkleLabel("Email:", NSTextAlignment.Right);
                EmailLabel.Frame = new RectangleF(165, Frame.Height - 264, 160, 17);

                EmailTextField = new NSTextField()
                {
                    Frame    = new RectangleF(330, Frame.Height - 268, 196, 22),
                    Delegate = new SparkleTextFieldDelegate()
                };

                CancelButton = new NSButton()
                {
                    Title = "Cancel"
                };

                ContinueButton = new NSButton()
                {
                    Title   = "Continue",
                    Enabled = false
                };


                (FullNameTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckSetupPage(FullNameTextField.StringValue, EmailTextField.StringValue);
                };

                (EmailTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckSetupPage(FullNameTextField.StringValue, EmailTextField.StringValue);
                };

                ContinueButton.Activated += delegate {
                    string full_name = FullNameTextField.StringValue.Trim();
                    string email     = EmailTextField.StringValue.Trim();

                    Controller.SetupPageCompleted(full_name, email);
                };

                CancelButton.Activated += delegate { Controller.SetupPageCancelled(); };

                Controller.UpdateSetupContinueButtonEvent += delegate(bool button_enabled) {
                    Program.Controller.Invoke(() => {
                        ContinueButton.Enabled = button_enabled;
                    });
                };


                ContentView.AddSubview(FullNameLabel);
                ContentView.AddSubview(FullNameTextField);
                ContentView.AddSubview(EmailLabel);
                ContentView.AddSubview(EmailTextField);

                Buttons.Add(ContinueButton);
                Buttons.Add(CancelButton);

                Controller.CheckSetupPage(FullNameTextField.StringValue, EmailTextField.StringValue);

                if (FullNameTextField.StringValue.Equals(""))
                {
                    MakeFirstResponder((NSResponder)FullNameTextField);
                }
                else
                {
                    MakeFirstResponder((NSResponder)EmailTextField);
                }
            }

            if (type == PageType.Invite)
            {
                Header      = "You’ve received an invite!";
                Description = "Do you want to add this project to SparkleShare?";

                AddressLabel       = new SparkleLabel("Address:", NSTextAlignment.Right);
                AddressLabel.Frame = new RectangleF(165, Frame.Height - 240, 160, 17);

                AddressTextField = new SparkleLabel(Controller.PendingInvite.Address, NSTextAlignment.Left)
                {
                    Frame = new RectangleF(330, Frame.Height - 240, 260, 17),
                    Font  = SparkleUI.BoldFont
                };

                PathLabel       = new SparkleLabel("Remote Path:", NSTextAlignment.Right);
                PathLabel.Frame = new RectangleF(165, Frame.Height - 264, 160, 17);

                PathTextField = new SparkleLabel(Controller.PendingInvite.RemotePath, NSTextAlignment.Left)
                {
                    Frame = new RectangleF(330, Frame.Height - 264, 260, 17),
                    Font  = SparkleUI.BoldFont
                };

                CancelButton = new NSButton()
                {
                    Title = "Cancel"
                };
                AddButton = new NSButton()
                {
                    Title = "Add"
                };


                CancelButton.Activated += delegate { Controller.PageCancelled(); };
                AddButton.Activated    += delegate { Controller.InvitePageCompleted(); };


                ContentView.AddSubview(AddressLabel);
                ContentView.AddSubview(PathLabel);
                ContentView.AddSubview(AddressTextField);
                ContentView.AddSubview(PathTextField);

                Buttons.Add(AddButton);
                Buttons.Add(CancelButton);
            }

            if (type == PageType.Add)
            {
                Header      = "Where’s your project hosted?";
                Description = "";

                AddressLabel = new SparkleLabel("Address:", NSTextAlignment.Left)
                {
                    Frame = new RectangleF(190, Frame.Height - 308, 160, 17),
                    Font  = SparkleUI.BoldFont
                };

                AddressTextField = new NSTextField()
                {
                    Frame       = new RectangleF(190, Frame.Height - 336, 196, 22),
                    Font        = SparkleUI.Font,
                    Enabled     = (Controller.SelectedPlugin.Address == null),
                    Delegate    = new SparkleTextFieldDelegate(),
                    StringValue = "" + Controller.PreviousAddress
                };

                AddressTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;

                PathLabel = new SparkleLabel("Remote Path:", NSTextAlignment.Left)
                {
                    Frame = new RectangleF(190 + 196 + 16, Frame.Height - 308, 160, 17),
                    Font  = SparkleUI.BoldFont
                };

                PathTextField = new NSTextField()
                {
                    Frame       = new RectangleF(190 + 196 + 16, Frame.Height - 336, 196, 22),
                    Enabled     = (Controller.SelectedPlugin.Path == null),
                    Delegate    = new SparkleTextFieldDelegate(),
                    StringValue = "" + Controller.PreviousPath
                };

                PathTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;

                PathHelpLabel = new SparkleLabel(Controller.SelectedPlugin.PathExample, NSTextAlignment.Left)
                {
                    TextColor = NSColor.DisabledControlText,
                    Frame     = new RectangleF(190 + 196 + 16, Frame.Height - 355, 204, 17),
                    Font      = NSFontManager.SharedFontManager.FontWithFamily("Lucida Grande",
                                                                               NSFontTraitMask.Condensed, 0, 11),
                };

                AddressHelpLabel = new SparkleLabel(Controller.SelectedPlugin.AddressExample, NSTextAlignment.Left)
                {
                    TextColor = NSColor.DisabledControlText,
                    Frame     = new RectangleF(190, Frame.Height - 355, 204, 17),
                    Font      = NSFontManager.SharedFontManager.FontWithFamily("Lucida Grande",
                                                                               NSFontTraitMask.Condensed, 0, 11),
                };

                if (TableView == null || TableView.RowCount != Controller.Plugins.Count)
                {
                    TableView = new NSTableView()
                    {
                        Frame            = new RectangleF(0, 0, 0, 0),
                        RowHeight        = 34,
                        IntercellSpacing = new SizeF(8, 12),
                        HeaderView       = null,
                        Delegate         = new SparkleTableViewDelegate()
                    };

                    ScrollView = new NSScrollView()
                    {
                        Frame               = new RectangleF(190, Frame.Height - 280, 408, 185),
                        DocumentView        = TableView,
                        HasVerticalScroller = true,
                        BorderType          = NSBorderType.BezelBorder
                    };

                    IconColumn = new NSTableColumn()
                    {
                        Width         = 36,
                        HeaderToolTip = "Icon",
                        DataCell      = new NSImageCell()
                        {
                            ImageAlignment = NSImageAlignment.Right
                        }
                    };

                    DescriptionColumn = new NSTableColumn()
                    {
                        Width         = 350,
                        HeaderToolTip = "Description",
                        Editable      = false
                    };

                    DescriptionColumn.DataCell.Font = NSFontManager.SharedFontManager.FontWithFamily("Lucida Grande",
                                                                                                     NSFontTraitMask.Condensed, 0, 11);

                    TableView.AddColumn(IconColumn);
                    TableView.AddColumn(DescriptionColumn);

                    // Hi-res display support was added after Snow Leopard
                    if (Environment.OSVersion.Version.Major < 11)
                    {
                        DataSource = new SparkleDataSource(1, Controller.Plugins);
                    }
                    else
                    {
                        DataSource = new SparkleDataSource(BackingScaleFactor, Controller.Plugins);
                    }

                    TableView.DataSource = DataSource;
                    TableView.ReloadData();

                    (TableView.Delegate as SparkleTableViewDelegate).SelectionChanged += delegate {
                        Controller.SelectedPluginChanged(TableView.SelectedRow);
                        Controller.CheckAddPage(AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
                    };
                }

                TableView.SelectRow(Controller.SelectedPluginIndex, false);
                TableView.ScrollRowToVisible(Controller.SelectedPluginIndex);
                MakeFirstResponder((NSResponder)TableView);

                HistoryCheckButton = new NSButton()
                {
                    Frame = new RectangleF(190, Frame.Height - 400, 300, 18),
                    Title = "Fetch prior revisions"
                };

                if (Controller.FetchPriorHistory)
                {
                    HistoryCheckButton.State = NSCellStateValue.On;
                }

                HistoryCheckButton.SetButtonType(NSButtonType.Switch);

                AddButton = new NSButton()
                {
                    Title   = "Add",
                    Enabled = false
                };

                CancelButton = new NSButton()
                {
                    Title = "Cancel"
                };


                Controller.ChangeAddressFieldEvent += delegate(string text, string example_text, FieldState state) {
                    Program.Controller.Invoke(() => {
                        AddressTextField.StringValue = text;
                        AddressTextField.Enabled     = (state == FieldState.Enabled);
                        AddressHelpLabel.StringValue = example_text;
                    });
                };

                Controller.ChangePathFieldEvent += delegate(string text, string example_text, FieldState state) {
                    Program.Controller.Invoke(() => {
                        PathTextField.StringValue = text;
                        PathTextField.Enabled     = (state == FieldState.Enabled);
                        PathHelpLabel.StringValue = example_text;
                    });
                };


                (AddressTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckAddPage(AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
                };

                (PathTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckAddPage(AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
                };


                HistoryCheckButton.Activated += delegate {
                    Controller.HistoryItemChanged(HistoryCheckButton.State == NSCellStateValue.On);
                };

                AddButton.Activated += delegate {
                    Controller.AddPageCompleted(AddressTextField.StringValue, PathTextField.StringValue);
                };

                CancelButton.Activated += delegate { Controller.PageCancelled(); };

                Controller.UpdateAddProjectButtonEvent += delegate(bool button_enabled) {
                    Program.Controller.Invoke(() => {
                        AddButton.Enabled = button_enabled;
                    });
                };

                ContentView.AddSubview(ScrollView);
                ContentView.AddSubview(AddressLabel);
                ContentView.AddSubview(AddressTextField);
                ContentView.AddSubview(AddressHelpLabel);
                ContentView.AddSubview(PathLabel);
                ContentView.AddSubview(PathTextField);
                ContentView.AddSubview(PathHelpLabel);
                ContentView.AddSubview(HistoryCheckButton);

                Buttons.Add(AddButton);
                Buttons.Add(CancelButton);

                Controller.CheckAddPage(AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
            }

            if (type == PageType.Syncing)
            {
                Header      = "Adding project ‘" + Controller.SyncingFolder + "’…";
                Description = "This may take a while for large projects.\nIsn’t it coffee-o’clock?";

                ProgressIndicator = new NSProgressIndicator()
                {
                    Frame         = new RectangleF(190, Frame.Height - 200, 640 - 150 - 80, 20),
                    Style         = NSProgressIndicatorStyle.Bar,
                    MinValue      = 0.0,
                    MaxValue      = 100.0,
                    Indeterminate = false,
                    DoubleValue   = Controller.ProgressBarPercentage
                };

                ProgressIndicator.StartAnimation(this);

                CancelButton = new NSButton()
                {
                    Title = "Cancel"
                };

                FinishButton = new NSButton()
                {
                    Title   = "Finish",
                    Enabled = false
                };

                ProgressLabel       = new SparkleLabel("Preparing to fetch files…", NSTextAlignment.Right);
                ProgressLabel.Frame = new RectangleF(Frame.Width - 40 - 250, 185, 250, 25);


                Controller.UpdateProgressBarEvent += delegate(double percentage, string speed) {
                    Program.Controller.Invoke(() => {
                        ProgressIndicator.DoubleValue = percentage;
                        ProgressLabel.StringValue     = speed;
                    });
                };


                CancelButton.Activated += delegate { Controller.SyncingCancelled(); };


                ContentView.AddSubview(ProgressLabel);
                ContentView.AddSubview(ProgressIndicator);

                Buttons.Add(FinishButton);
                Buttons.Add(CancelButton);
            }

            if (type == PageType.Error)
            {
                Header      = "Oops! Something went wrong…";
                Description = "Please check the following:";

                // Displaying marked up text with Cocoa is
                // a pain, so we just use a webview instead
                WebView web_view = new WebView();
                web_view.Frame = new RectangleF(190, Frame.Height - 525, 375, 400);

                string html = "<style>" +
                              "* {" +
                              "  font-family: 'Lucida Grande';" +
                              "  font-size: 12px; cursor: default;" +
                              "}" +
                              "body {" +
                              "  -webkit-user-select: none;" +
                              "  margin: 0;" +
                              "  padding: 3px;" +
                              "}" +
                              "li {" +
                              "  margin-bottom: 16px;" +
                              "  margin-left: 0;" +
                              "  padding-left: 0;" +
                              "  line-height: 20px;" +
                              "  word-wrap: break-word;" +
                              "}" +
                              "ul {" +
                              "  padding-left: 24px;" +
                              "}" +
                              "</style>" +
                              "<ul>" +
                              "  <li><b>" + Controller.PreviousUrl + "</b> is the address we’ve compiled. Does this look alright?</li>" +
                              "  <li>Is this computer’s Client ID known by the host?</li>" +
                              "</ul>";

                if (warnings.Length > 0)
                {
                    string warnings_markup = "";

                    foreach (string warning in warnings)
                    {
                        warnings_markup += "<br><b>" + warning + "</b>";
                    }

                    html = html.Replace("</ul>", "<li>Here’s the raw error message: " + warnings_markup + "</li></ul>");
                }

                web_view.MainFrame.LoadHtmlString(html, new NSUrl(""));
                web_view.DrawsBackground = false;

                CancelButton = new NSButton()
                {
                    Title = "Cancel"
                };
                TryAgainButton = new NSButton()
                {
                    Title = "Try Again…"
                };


                CancelButton.Activated   += delegate { Controller.PageCancelled(); };
                TryAgainButton.Activated += delegate { Controller.ErrorPageCompleted(); };


                ContentView.AddSubview(web_view);

                Buttons.Add(TryAgainButton);
                Buttons.Add(CancelButton);
            }

            if (type == PageType.CryptoSetup || type == PageType.CryptoPassword)
            {
                if (type == PageType.CryptoSetup)
                {
                    Header      = "Set up file encryption";
                    Description = "Please a provide a strong password that you don’t use elsewhere.";
                }
                else
                {
                    Header      = "This project contains encrypted files";
                    Description = "Please enter the password to see their contents.";
                }

                int extra_pos_y = 0;

                if (type == PageType.CryptoPassword)
                {
                    extra_pos_y = 20;
                }

                PasswordLabel = new SparkleLabel("Password:"******"Show password",
                    State = NSCellStateValue.Off
                };

                ShowPasswordCheckButton.SetButtonType(NSButtonType.Switch);

                WarningImage      = NSImage.ImageNamed("NSInfo");
                WarningImage.Size = new SizeF(24, 24);

                WarningImageView = new NSImageView()
                {
                    Image = WarningImage,
                    Frame = new RectangleF(200, Frame.Height - 320, 24, 24)
                };

                WarningTextField = new SparkleLabel("This password can’t be changed later, and your files can’t be recovered if it’s forgotten.", NSTextAlignment.Left)
                {
                    Frame = new RectangleF(235, Frame.Height - 390, 325, 100),
                };

                CancelButton = new NSButton()
                {
                    Title = "Cancel"
                };

                ContinueButton = new NSButton()
                {
                    Title   = "Continue",
                    Enabled = false
                };


                Controller.UpdateCryptoPasswordContinueButtonEvent += delegate(bool button_enabled) {
                    Program.Controller.Invoke(() => { ContinueButton.Enabled = button_enabled; });
                };

                Controller.UpdateCryptoSetupContinueButtonEvent += delegate(bool button_enabled) {
                    Program.Controller.Invoke(() => { ContinueButton.Enabled = button_enabled; });
                };

                ShowPasswordCheckButton.Activated += delegate {
                    if (PasswordTextField.Superview == ContentView)
                    {
                        PasswordTextField.RemoveFromSuperview();
                        ContentView.AddSubview(VisiblePasswordTextField);
                    }
                    else
                    {
                        VisiblePasswordTextField.RemoveFromSuperview();
                        ContentView.AddSubview(PasswordTextField);
                    }
                };

                (PasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    VisiblePasswordTextField.StringValue = PasswordTextField.StringValue;

                    if (type == PageType.CryptoSetup)
                    {
                        Controller.CheckCryptoSetupPage(PasswordTextField.StringValue);
                    }
                    else
                    {
                        Controller.CheckCryptoPasswordPage(PasswordTextField.StringValue);
                    }
                };

                (VisiblePasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    PasswordTextField.StringValue = VisiblePasswordTextField.StringValue;

                    if (type == PageType.CryptoSetup)
                    {
                        Controller.CheckCryptoSetupPage(PasswordTextField.StringValue);
                    }
                    else
                    {
                        Controller.CheckCryptoPasswordPage(PasswordTextField.StringValue);
                    }
                };

                ContinueButton.Activated += delegate {
                    if (type == PageType.CryptoSetup)
                    {
                        Controller.CryptoSetupPageCompleted(PasswordTextField.StringValue);
                    }
                    else
                    {
                        Controller.CryptoPasswordPageCompleted(PasswordTextField.StringValue);
                    }
                };

                CancelButton.Activated += delegate { Controller.CryptoPageCancelled(); };


                ContentView.AddSubview(PasswordLabel);
                ContentView.AddSubview(PasswordTextField);
                ContentView.AddSubview(ShowPasswordCheckButton);

                if (type == PageType.CryptoSetup)
                {
                    ContentView.AddSubview(WarningImageView);
                    ContentView.AddSubview(WarningTextField);
                }

                Buttons.Add(ContinueButton);
                Buttons.Add(CancelButton);

                MakeFirstResponder((NSResponder)PasswordTextField);
                NSApplication.SharedApplication.RequestUserAttention(NSRequestUserAttentionType.CriticalRequest);
            }


            if (type == PageType.Finished)
            {
                Header      = "Your shared project is ready!";
                Description = "You can find the files in your SparkleShare folder.";

                if (warnings.Length > 0)
                {
                    WarningImage      = NSImage.ImageNamed("NSInfo");
                    WarningImage.Size = new SizeF(24, 24);

                    WarningImageView = new NSImageView()
                    {
                        Image = WarningImage,
                        Frame = new RectangleF(200, Frame.Height - 175, 24, 24)
                    };

                    WarningTextField       = new SparkleLabel(warnings [0], NSTextAlignment.Left);
                    WarningTextField.Frame = new RectangleF(235, Frame.Height - 245, 325, 100);

                    ContentView.AddSubview(WarningImageView);
                    ContentView.AddSubview(WarningTextField);
                }

                ShowFilesButton = new NSButton()
                {
                    Title = "Show Files…"
                };
                FinishButton = new NSButton()
                {
                    Title = "Finish"
                };


                ShowFilesButton.Activated += delegate { Controller.ShowFilesClicked(); };
                FinishButton.Activated    += delegate { Controller.FinishPageCompleted(); };


                Buttons.Add(FinishButton);
                Buttons.Add(ShowFilesButton);

                NSApplication.SharedApplication.RequestUserAttention(NSRequestUserAttentionType.CriticalRequest);
            }

            if (type == PageType.Tutorial)
            {
                SlideImage = NSImage.ImageNamed("tutorial-slide-" + Controller.TutorialPageNumber);
                if (SlideImage != null)
                {
                    SlideImage.Size = new SizeF(324, 200);

                    SlideImageView = new NSImageView()
                    {
                        Image = SlideImage,
                        Frame = new RectangleF(228, Frame.Height - 350, 324, 200)
                    };

                    ContentView.AddSubview(SlideImageView);
                }

                switch (Controller.TutorialPageNumber)
                {
                case 1: {
                    Header      = "What’s happening next?";
                    Description = "SparkleShare creates a special folder on your computer " +
                                  "that will keep track of your projects.";

                    SkipTutorialButton = new NSButton()
                    {
                        Title = "Skip Tutorial"
                    };
                    ContinueButton = new NSButton()
                    {
                        Title = "Continue"
                    };


                    SkipTutorialButton.Activated += delegate { Controller.TutorialSkipped(); };
                    ContinueButton.Activated     += delegate { Controller.TutorialPageCompleted(); };


                    ContentView.AddSubview(SlideImageView);

                    Buttons.Add(ContinueButton);
                    Buttons.Add(SkipTutorialButton);

                    break;
                }

                case 2: {
                    Header      = "Sharing files with others";
                    Description = "All files added to your project folders are synced automatically with " +
                                  "the host and your team members.";

                    ContinueButton = new NSButton()
                    {
                        Title = "Continue"
                    };
                    ContinueButton.Activated += delegate { Controller.TutorialPageCompleted(); };
                    Buttons.Add(ContinueButton);

                    break;
                }

                case 3: {
                    Header      = "The status icon helps you";
                    Description = "It shows the syncing progress, provides easy access to " +
                                  "your projects, and lets you view recent changes.";

                    ContinueButton = new NSButton()
                    {
                        Title = "Continue"
                    };
                    ContinueButton.Activated += delegate { Controller.TutorialPageCompleted(); };
                    Buttons.Add(ContinueButton);

                    break;
                }

                case 4: {
                    Header      = "Here’s your unique Client ID";
                    Description = "You’ll need it whenever you want to link this computer to a host. " +
                                  "You can also find it in the status icon menu.";

                    LinkCodeTextField = new NSTextField()
                    {
                        StringValue = Program.Controller.CurrentUser.PublicKey,
                        Enabled     = false,
                        Selectable  = false,
                        Frame       = new RectangleF(230, Frame.Height - 238, 246, 22)
                    };

                    LinkCodeTextField.Cell.UsesSingleLineMode = true;
                    LinkCodeTextField.Cell.LineBreakMode      = NSLineBreakMode.TruncatingTail;

                    CopyButton = new NSButton()
                    {
                        Title      = "Copy",
                        BezelStyle = NSBezelStyle.RoundRect,
                        Frame      = new RectangleF(480, Frame.Height - 238, 60, 22)
                    };

                    StartupCheckButton = new NSButton()
                    {
                        Frame = new RectangleF(190, Frame.Height - 400, 300, 18),
                        Title = "Add SparkleShare to startup items",
                        State = NSCellStateValue.On
                    };

                    StartupCheckButton.SetButtonType(NSButtonType.Switch);

                    FinishButton = new NSButton()
                    {
                        Title = "Finish"
                    };


                    StartupCheckButton.Activated += delegate {
                        Controller.StartupItemChanged(StartupCheckButton.State == NSCellStateValue.On);
                    };

                    CopyButton.Activated   += delegate { Controller.CopyToClipboardClicked(); };
                    FinishButton.Activated += delegate { Controller.TutorialPageCompleted(); };


                    ContentView.AddSubview(LinkCodeTextField);
                    ContentView.AddSubview(CopyButton);
                    ContentView.AddSubview(StartupCheckButton);

                    Buttons.Add(FinishButton);

                    break;
                }
                }
            }
        }
Esempio n. 36
0
        public EventLog()
        {
            Title    = "Recent Changes";
            Delegate = new SparkleEventsDelegate();

            int min_width  = 480;
            int min_height = 640;
            int height     = (int)(NSScreen.MainScreen.Frame.Height * 0.85);

            float x = (float)(NSScreen.MainScreen.Frame.Width * 0.61);
            float y = (float)(NSScreen.MainScreen.Frame.Height * 0.5 - (height * 0.5));

            SetFrame(
                new CGRect(
                    new CGPoint(x, y),
                    new CGSize(min_width, height)),
                true);

            StyleMask = (NSWindowStyle.Closable | NSWindowStyle.Miniaturizable |
                         NSWindowStyle.Titled | NSWindowStyle.Resizable);

            MinSize        = new CGSize(min_width, min_height);
            HasShadow      = true;
            IsOpaque       = false;
            BackingType    = NSBackingStore.Buffered;
            TitlebarHeight = (float)(Frame.Height - ContentView.Frame.Height);
            Level          = NSWindowLevel.Floating;


            this.web_view = new WebView(new CGRect(0, 0, 481, 579), "", "")
            {
                Frame = new CGRect(new CGPoint(0, 0),
                                   new CGSize(ContentView.Frame.Width, ContentView.Frame.Height - 39))
            };

            this.web_view.Preferences.PlugInsEnabled = false;

            this.cover = new NSBox()
            {
                Frame = new CGRect(
                    new CGPoint(-1, -1),
                    new CGSize(Frame.Width + 2, this.web_view.Frame.Height + 1)),
                FillColor        = NSColor.White,
                BorderType       = NSBorderType.NoBorder,
                BoxType          = NSBoxType.NSBoxCustom,
                AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.HeightSizable
            };

            this.hidden_close_button = new NSButton()
            {
                KeyEquivalentModifierMask = NSEventModifierMask.CommandKeyMask,
                KeyEquivalent             = "w"
            };

            this.hidden_close_button.Activated += delegate {
                Controller.WindowClosed();
            };


            this.size_label = new NSTextField()
            {
                Alignment       = NSTextAlignment.Right,
                BackgroundColor = NSColor.WindowBackground,
                Bordered        = false,
                Editable        = false,
                Frame           = new CGRect(
                    new CGPoint(0, ContentView.Frame.Height - 31),
                    new CGSize(60, 20)),
                StringValue      = "Size:",
                AutoresizingMask = NSViewResizingMask.MaxXMargin | NSViewResizingMask.MinYMargin
            };

            this.size_label_value = new NSTextField()
            {
                Alignment       = NSTextAlignment.Left,
                BackgroundColor = NSColor.WindowBackground,
                Bordered        = false,
                Editable        = false,
                Frame           = new CGRect(
                    new CGPoint(60, ContentView.Frame.Height - 31),
                    new CGSize(60, 20)),
                StringValue      = "…",
                Font             = NSFont.BoldSystemFontOfSize(12),
                AutoresizingMask = NSViewResizingMask.MaxXMargin | NSViewResizingMask.MinYMargin
            };

            this.history_label = new NSTextField()
            {
                Alignment       = NSTextAlignment.Right,
                BackgroundColor = NSColor.WindowBackground,
                Bordered        = false,
                Editable        = false,
                Frame           = new CGRect(
                    new CGPoint(130, ContentView.Frame.Height - 31),
                    new CGSize(60, 20)),
                StringValue      = "History:",
                AutoresizingMask = NSViewResizingMask.MaxXMargin | NSViewResizingMask.MinYMargin
            };

            this.history_label_value = new NSTextField()
            {
                Alignment       = NSTextAlignment.Left,
                BackgroundColor = NSColor.WindowBackground,
                Bordered        = false,
                Editable        = false,
                Frame           = new CGRect(
                    new CGPoint(190, ContentView.Frame.Height - 31),
                    new CGSize(60, 20)
                    ),
                StringValue      = "…",
                Font             = NSFont.BoldSystemFontOfSize(12),
                AutoresizingMask = NSViewResizingMask.MaxXMargin | NSViewResizingMask.MinYMargin
            };

            this.popup_button = new NSPopUpButton()
            {
                Frame = new CGRect(
                    new CGPoint(ContentView.Frame.Width - 156 - 12, ContentView.Frame.Height - 33),
                    new CGSize(156, 26)),
                PullsDown        = false,
                AutoresizingMask = NSViewResizingMask.MinXMargin | NSViewResizingMask.MinYMargin
            };

            this.background = new NSBox()
            {
                Frame = new CGRect(
                    new CGPoint(-1, -1),
                    new CGSize(Frame.Width + 2, this.web_view.Frame.Height + 2)),
                FillColor        = NSColor.White,
                BorderColor      = NSColor.LightGray,
                BoxType          = NSBoxType.NSBoxCustom,
                AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.HeightSizable
            };

            this.progress_indicator = new NSProgressIndicator()
            {
                Frame = new CGRect(
                    new CGPoint(Frame.Width / 2 - 10, this.web_view.Frame.Height / 2 + 10),
                    new CGSize(20, 20)),
                Style            = NSProgressIndicatorStyle.Spinning,
                AutoresizingMask = NSViewResizingMask.MinXMargin | NSViewResizingMask.MaxXMargin |
                                   NSViewResizingMask.MinYMargin | NSViewResizingMask.MaxYMargin
            };

            this.progress_indicator.StartAnimation(this);


            ContentView.AddSubview(this.size_label);
            ContentView.AddSubview(this.size_label_value);
            ContentView.AddSubview(this.history_label);
            ContentView.AddSubview(this.history_label_value);
            ContentView.AddSubview(this.popup_button);
            ContentView.AddSubview(this.progress_indicator);
            ContentView.AddSubview(this.background);
            ContentView.AddSubview(this.hidden_close_button);


            Controller.HideWindowEvent     += HideWindowEventDelegate;
            Controller.ShowWindowEvent     += ShowWindowEventDelegate;
            Controller.ShowSaveDialogEvent += ShowSaveDialogEventDelegate;

            Controller.UpdateChooserEvent           += UpdateChooserEventDelegate;
            Controller.UpdateChooserEnablementEvent += UpdateChooserEnablementEventDelegate;
            Controller.UpdateContentEvent           += UpdateContentEventDelegate;
            Controller.UpdateSizeInfoEvent          += UpdateSizeInfoEventDelegate;

            Controller.ContentLoadingEvent += ContentLoadingEventDelegate;
        }
Esempio n. 37
0
        public void ShowPage(PageType type, string [] warnings)
        {
            if (type == PageType.Setup)
            {
                Header      = "Welcome to SparkleShare!";
                Description = "First off, what’s your name and email?\n(visible only to team members)";

                FullNameLabel       = new SparkleLabel("Full Name:", NSTextAlignment.Right);
                FullNameLabel.Frame = new CGRect(165, Frame.Height - 234, 160, 17);

                FullNameTextField = new NSTextField()
                {
                    Frame       = new CGRect(330, Frame.Height - 238, 196, 22),
                    StringValue = new NSProcessInfo().GetFullUserName(),
                    Delegate    = new SparkleTextFieldDelegate()
                };

                EmailLabel       = new SparkleLabel("Email:", NSTextAlignment.Right);
                EmailLabel.Frame = new CGRect(165, Frame.Height - 264, 160, 17);

                EmailTextField = new NSTextField()
                {
                    Frame    = new CGRect(330, Frame.Height - 268, 196, 22),
                    Delegate = new SparkleTextFieldDelegate()
                };

                CancelButton = new NSButton()
                {
                    Title = "Cancel"
                };

                ContinueButton = new NSButton()
                {
                    Title   = "Continue",
                    Enabled = false
                };


                (FullNameTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckSetupPage(FullNameTextField.StringValue, EmailTextField.StringValue);
                };

                (EmailTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckSetupPage(FullNameTextField.StringValue, EmailTextField.StringValue);
                };

                ContinueButton.Activated += delegate {
                    string full_name = FullNameTextField.StringValue.Trim();
                    string email     = EmailTextField.StringValue.Trim();

                    Controller.SetupPageCompleted(full_name, email);
                };

                CancelButton.Activated += delegate { Controller.SetupPageCancelled(); };

                Controller.UpdateSetupContinueButtonEvent += delegate(bool button_enabled) {
                    SparkleShare.Controller.Invoke(() => {
                        ContinueButton.Enabled = button_enabled;
                    });
                };


                ContentView.AddSubview(FullNameLabel);
                ContentView.AddSubview(FullNameTextField);
                ContentView.AddSubview(EmailLabel);
                ContentView.AddSubview(EmailTextField);

                Buttons.Add(ContinueButton);
                Buttons.Add(CancelButton);

                Controller.CheckSetupPage(FullNameTextField.StringValue, EmailTextField.StringValue);

                if (FullNameTextField.StringValue.Equals(""))
                {
                    MakeFirstResponder((NSResponder)FullNameTextField);
                }
                else
                {
                    MakeFirstResponder((NSResponder)EmailTextField);
                }
            }

            if (type == PageType.Invite)
            {
                Header      = "You’ve received an invite!";
                Description = "Do you want to add this project to SparkleShare?";

                AddressLabel       = new SparkleLabel("Address:", NSTextAlignment.Right);
                AddressLabel.Frame = new CGRect(165, Frame.Height - 238, 160, 17);
                AddressLabel.Font  = NSFont.BoldSystemFontOfSize(12);

                AddressTextField = new SparkleLabel(Controller.PendingInvite.Address, NSTextAlignment.Left)
                {
                    Frame = new CGRect(330, Frame.Height - 240, 260, 17)
                };

                PathLabel       = new SparkleLabel("Remote Path:", NSTextAlignment.Right);
                PathLabel.Frame = new CGRect(165, Frame.Height - 262, 160, 17);
                PathLabel.Font  = NSFont.BoldSystemFontOfSize(12);

                PathTextField = new SparkleLabel(Controller.PendingInvite.RemotePath, NSTextAlignment.Left)
                {
                    Frame = new CGRect(330, Frame.Height - 264, 260, 17)
                };

                CancelButton = new NSButton()
                {
                    Title = "Cancel"
                };
                AddButton = new NSButton()
                {
                    Title = "Add"
                };


                CancelButton.Activated += delegate { Controller.PageCancelled(); };
                AddButton.Activated    += delegate { Controller.InvitePageCompleted(); };


                ContentView.AddSubview(AddressLabel);
                ContentView.AddSubview(PathLabel);
                ContentView.AddSubview(AddressTextField);
                ContentView.AddSubview(PathTextField);

                Buttons.Add(AddButton);
                Buttons.Add(CancelButton);
            }

            if (type == PageType.Add)
            {
                Header      = "Where’s your project hosted?";
                Description = "";

                AddressLabel = new SparkleLabel("Address:", NSTextAlignment.Left)
                {
                    Frame = new CGRect(190, Frame.Height - 310, 160, 17),
                    Font  = NSFont.BoldSystemFontOfSize(12)
                };

                AddressTextField = new NSTextField()
                {
                    Frame       = new CGRect(190, Frame.Height - 336, 196, 22),
                    Enabled     = (Controller.SelectedPreset.Address == null),
                    Delegate    = new SparkleTextFieldDelegate(),
                    StringValue = "" + Controller.PreviousAddress
                };

                AddressTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;

                PathLabel = new SparkleLabel("Remote Path:", NSTextAlignment.Left)
                {
                    Frame = new CGRect(190 + 196 + 16, Frame.Height - 310, 160, 17),
                    Font  = NSFont.BoldSystemFontOfSize(12)
                };

                PathTextField = new NSTextField()
                {
                    Frame       = new CGRect(190 + 196 + 16, Frame.Height - 336, 196, 22),
                    Enabled     = (Controller.SelectedPreset.Path == null),
                    Delegate    = new SparkleTextFieldDelegate(),
                    StringValue = "" + Controller.PreviousPath
                };

                PathTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;

                PathHelpLabel = new SparkleLabel(Controller.SelectedPreset.PathExample, NSTextAlignment.Left)
                {
                    TextColor = NSColor.DisabledControlText,
                    Frame     = new CGRect(190 + 196 + 16, Frame.Height - 358, 204, 19)
                };

                AddressHelpLabel = new SparkleLabel(Controller.SelectedPreset.AddressExample, NSTextAlignment.Left)
                {
                    TextColor = NSColor.DisabledControlText,
                    Frame     = new CGRect(190, Frame.Height - 358, 204, 19)
                };

                if (TableView == null || TableView.RowCount != Controller.Presets.Count)
                {
                    TableView = new NSTableView()
                    {
                        Frame            = new CGRect(0, 0, 0, 0),
                        RowHeight        = 38,
                        IntercellSpacing = new CGSize(8, 12),
                        HeaderView       = null,
                        Delegate         = new SparkleTableViewDelegate()
                    };

                    ScrollView = new NSScrollView()
                    {
                        Frame               = new CGRect(190, Frame.Height - 280, 408, 185),
                        DocumentView        = TableView,
                        HasVerticalScroller = true,
                        BorderType          = NSBorderType.BezelBorder
                    };

                    IconColumn = new NSTableColumn()
                    {
                        Width         = 36,
                        HeaderToolTip = "Icon",
                        DataCell      = new NSImageCell()
                        {
                            ImageAlignment = NSImageAlignment.Right
                        }
                    };

                    DescriptionColumn = new NSTableColumn()
                    {
                        Width         = 350,
                        HeaderToolTip = "Description",
                        Editable      = false
                    };

                    TableView.AddColumn(IconColumn);
                    TableView.AddColumn(DescriptionColumn);

                    // Hi-res display support was added after Snow Leopard
                    if (Environment.OSVersion.Version.Major < 11)
                    {
                        DataSource = new SparkleDataSource(1, Controller.Presets);
                    }
                    else
                    {
                        DataSource = new SparkleDataSource((float)BackingScaleFactor, Controller.Presets);
                    }

                    TableView.DataSource = DataSource;
                    TableView.ReloadData();

                    (TableView.Delegate as SparkleTableViewDelegate).SelectionChanged += delegate {
                        Controller.SelectedPresetChanged((int)TableView.SelectedRow);
                        Controller.CheckAddPage(AddressTextField.StringValue, PathTextField.StringValue, (int)TableView.SelectedRow);
                    };
                }

                TableView.SelectRow(Controller.SelectedPresetIndex, byExtendingSelection: false);
                TableView.ScrollRowToVisible(Controller.SelectedPresetIndex);
                MakeFirstResponder((NSResponder)TableView);

                HistoryCheckButton = new NSButton()
                {
                    Frame = new CGRect(190, Frame.Height - 400, 300, 18),
                    Title = "Fetch prior revisions"
                };

                if (Controller.FetchPriorHistory)
                {
                    HistoryCheckButton.State = NSCellStateValue.On;
                }

                HistoryCheckButton.SetButtonType(NSButtonType.Switch);

                AddButton = new NSButton()
                {
                    Title   = "Add",
                    Enabled = false
                };

                CancelButton = new NSButton()
                {
                    Title = "Cancel"
                };


                Controller.ChangeAddressFieldEvent += delegate(string text, string example_text, FieldState state) {
                    SparkleShare.Controller.Invoke(() => {
                        AddressTextField.StringValue = text;
                        AddressTextField.Enabled     = (state == FieldState.Enabled);
                        AddressHelpLabel.StringValue = example_text;
                    });
                };

                Controller.ChangePathFieldEvent += delegate(string text, string example_text, FieldState state) {
                    SparkleShare.Controller.Invoke(() => {
                        PathTextField.StringValue = text;
                        PathTextField.Enabled     = (state == FieldState.Enabled);
                        PathHelpLabel.StringValue = example_text;
                    });
                };


                (AddressTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckAddPage(AddressTextField.StringValue, PathTextField.StringValue, (int)TableView.SelectedRow);
                };

                (PathTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckAddPage(AddressTextField.StringValue, PathTextField.StringValue, (int)TableView.SelectedRow);
                };


                HistoryCheckButton.Activated += delegate {
                    Controller.HistoryItemChanged(HistoryCheckButton.State == NSCellStateValue.On);
                };

                AddButton.Activated += delegate {
                    Controller.AddPageCompleted(AddressTextField.StringValue, PathTextField.StringValue);
                };

                CancelButton.Activated += delegate { Controller.PageCancelled(); };

                Controller.UpdateAddProjectButtonEvent += delegate(bool button_enabled) {
                    SparkleShare.Controller.Invoke(() => {
                        AddButton.Enabled = button_enabled;
                    });
                };

                ContentView.AddSubview(ScrollView);
                ContentView.AddSubview(AddressLabel);
                ContentView.AddSubview(AddressTextField);
                ContentView.AddSubview(AddressHelpLabel);
                ContentView.AddSubview(PathLabel);
                ContentView.AddSubview(PathTextField);
                ContentView.AddSubview(PathHelpLabel);
                ContentView.AddSubview(HistoryCheckButton);

                Buttons.Add(AddButton);
                Buttons.Add(CancelButton);

                Controller.CheckAddPage(AddressTextField.StringValue, PathTextField.StringValue, (int)TableView.SelectedRow);
            }

            if (type == PageType.Syncing)
            {
                Header      = "Adding project ‘" + Controller.SyncingFolder + "’…";
                Description = "This may take a while for large projects.\nIsn’t it coffee-o’clock?";

                ProgressIndicator = new NSProgressIndicator()
                {
                    Frame         = new CGRect(190, Frame.Height - 200, 640 - 150 - 80, 20),
                    Style         = NSProgressIndicatorStyle.Bar,
                    MinValue      = 0.0,
                    MaxValue      = 100.0,
                    Indeterminate = false,
                    DoubleValue   = Controller.ProgressBarPercentage
                };

                ProgressIndicator.StartAnimation(this);

                CancelButton = new NSButton()
                {
                    Title = "Cancel"
                };

                FinishButton = new NSButton()
                {
                    Title   = "Finish",
                    Enabled = false
                };

                ProgressLabel       = new SparkleLabel("Preparing to fetch files…", NSTextAlignment.Right);
                ProgressLabel.Frame = new CGRect(Frame.Width - 40 - 250, 185, 250, 25);


                Controller.UpdateProgressBarEvent += delegate(double percentage, string speed) {
                    SparkleShare.Controller.Invoke(() => {
                        ProgressIndicator.DoubleValue = percentage;
                        ProgressLabel.StringValue     = speed;
                    });
                };


                CancelButton.Activated += delegate { Controller.SyncingCancelled(); };


                ContentView.AddSubview(ProgressLabel);
                ContentView.AddSubview(ProgressIndicator);

                Buttons.Add(FinishButton);
                Buttons.Add(CancelButton);
            }

            if (type == PageType.Error)
            {
                Header      = "Oops! Something went wrong…";
                Description = "Please check the following:";

                // Displaying marked up text with Cocoa is
                // a pain, so we just use a webview instead
                WebView web_view = new WebView();
                web_view.Frame = new CGRect(190, Frame.Height - 525, 375, 400);

                string html = "<style>" +
                              "* {" +
                              "  font-family: -apple-system, '" + UserInterface.FontName + "';" +
                              "  font-size: 12px; cursor: default;" +
                              "}" +
                              "body {" +
                              "  -webkit-user-select: none;" +
                              "  margin: 0;" +
                              "  padding: 3px;" +
                              "}" +
                              "li {" +
                              "  margin-bottom: 16px;" +
                              "  margin-left: 0;" +
                              "  padding-left: 0;" +
                              "  line-height: 20px;" +
                              "  word-wrap: break-word;" +
                              "}" +
                              "ul {" +
                              "  padding-left: 24px;" +
                              "}" +
                              "</style>" +
                              "<ul>" +
                              "  <li><b>" + Controller.PreviousUrl + "</b> is the address we’ve compiled. Does this look alright?</li>" +
                              "  <li>Is this computer’s Client ID known by the host?</li>" +
                              "</ul>";

                if (warnings.Length > 0)
                {
                    string warnings_markup = "";

                    foreach (string warning in warnings)
                    {
                        warnings_markup += "<br><b>" + warning + "</b>";
                    }

                    html = html.Replace("</ul>", "<li>Here’s the raw error message: " + warnings_markup + "</li></ul>");
                }

                web_view.MainFrame.LoadHtmlString(html, new NSUrl(""));
                web_view.DrawsBackground = false;

                CancelButton = new NSButton()
                {
                    Title = "Cancel"
                };
                TryAgainButton = new NSButton()
                {
                    Title = "Retry"
                };


                CancelButton.Activated   += delegate { Controller.PageCancelled(); };
                TryAgainButton.Activated += delegate { Controller.ErrorPageCompleted(); };


                ContentView.AddSubview(web_view);

                Buttons.Add(TryAgainButton);
                Buttons.Add(CancelButton);
            }

            if (type == PageType.StorageSetup)
            {
                Header      = string.Format("Storage type for ‘{0}’", Controller.SyncingFolder);
                Description = "What type of storage would you like to use?";


                storage_type_descriptions = new List <NSTextField> ();

                ButtonCellProto = new NSButtonCell();
                ButtonCellProto.SetButtonType(NSButtonType.Radio);
                ButtonCellProto.Font = NSFont.BoldSystemFontOfSize(12);

                Matrix = new NSMatrix(new CGRect(202, Frame.Height - 256 - 128, 256, 256), NSMatrixMode.Radio,
                                      ButtonCellProto, SparkleShare.Controller.FetcherAvailableStorageTypes.Count, 1);

                Matrix.CellSize         = new CGSize(256, 36);
                Matrix.IntercellSpacing = new CGSize(32, 32);

                int i = 0;
                foreach (StorageTypeInfo storage_type in SparkleShare.Controller.FetcherAvailableStorageTypes)
                {
                    Matrix.Cells [i].Title = " " + storage_type.Name;

                    NSTextField storage_type_description = new SparkleLabel(storage_type.Description, NSTextAlignment.Left)
                    {
                        TextColor = NSColor.DisabledControlText,
                        Frame     = new CGRect(223, Frame.Height - 190 - (68 * i), 256, 32)
                    };

                    storage_type_descriptions.Add(storage_type_description);
                    ContentView.AddSubview(storage_type_description);

                    i++;
                }

                ContentView.AddSubview(Matrix);


                CancelButton = new NSButton()
                {
                    Title = "Cancel"
                };
                ContinueButton = new NSButton()
                {
                    Title = "Continue"
                };

                ContinueButton.Activated += delegate {
                    StorageTypeInfo selected_storage_type = SparkleShare.Controller.FetcherAvailableStorageTypes [(int)Matrix.SelectedRow];
                    Controller.StoragePageCompleted(selected_storage_type.Type);
                };

                CancelButton.Activated += delegate { Controller.SyncingCancelled(); };

                Buttons.Add(ContinueButton);
                Buttons.Add(CancelButton);


                NSApplication.SharedApplication.RequestUserAttention(NSRequestUserAttentionType.CriticalRequest);
            }

            if (type == PageType.CryptoSetup || type == PageType.CryptoPassword)
            {
                if (type == PageType.CryptoSetup)
                {
                    Header      = "Set up file encryption";
                    Description = "Please a provide a strong password that you don’t use elsewhere.";
                }
                else
                {
                    Header      = "This project contains encrypted files";
                    Description = "Please enter the password to see their contents.";
                }

                int extra_pos_y = 0;

                if (type == PageType.CryptoPassword)
                {
                    extra_pos_y = 20;
                }

                PasswordLabel = new SparkleLabel("Password:"******"Show password",
                    State = NSCellStateValue.Off
                };

                ShowPasswordCheckButton.SetButtonType(NSButtonType.Switch);

                WarningImage      = NSImage.ImageNamed("NSInfo");
                WarningImage.Size = new CGSize(24, 24);

                WarningImageView = new NSImageView()
                {
                    Image = WarningImage,
                    Frame = new CGRect(200, Frame.Height - 320, 24, 24)
                };

                WarningTextField = new SparkleLabel("This password can’t be changed later, and your files can’t be recovered if it’s forgotten.", NSTextAlignment.Left)
                {
                    Frame = new CGRect(235, Frame.Height - 390, 325, 100),
                };

                CancelButton = new NSButton()
                {
                    Title = "Cancel"
                };

                ContinueButton = new NSButton()
                {
                    Title   = "Continue",
                    Enabled = false
                };


                Controller.UpdateCryptoPasswordContinueButtonEvent += delegate(bool button_enabled) {
                    SparkleShare.Controller.Invoke(() => { ContinueButton.Enabled = button_enabled; });
                };

                Controller.UpdateCryptoSetupContinueButtonEvent += delegate(bool button_enabled) {
                    SparkleShare.Controller.Invoke(() => { ContinueButton.Enabled = button_enabled; });
                };

                ShowPasswordCheckButton.Activated += delegate {
                    if (PasswordTextField.Superview == ContentView)
                    {
                        PasswordTextField.RemoveFromSuperview();
                        ContentView.AddSubview(VisiblePasswordTextField);
                    }
                    else
                    {
                        VisiblePasswordTextField.RemoveFromSuperview();
                        ContentView.AddSubview(PasswordTextField);
                    }
                };

                (PasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    VisiblePasswordTextField.StringValue = PasswordTextField.StringValue;

                    if (type == PageType.CryptoSetup)
                    {
                        Controller.CheckCryptoSetupPage(PasswordTextField.StringValue);
                    }
                    else
                    {
                        Controller.CheckCryptoPasswordPage(PasswordTextField.StringValue);
                    }
                };

                (VisiblePasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    PasswordTextField.StringValue = VisiblePasswordTextField.StringValue;

                    if (type == PageType.CryptoSetup)
                    {
                        Controller.CheckCryptoSetupPage(PasswordTextField.StringValue);
                    }
                    else
                    {
                        Controller.CheckCryptoPasswordPage(PasswordTextField.StringValue);
                    }
                };

                ContinueButton.Activated += delegate {
                    if (type == PageType.CryptoSetup)
                    {
                        Controller.CryptoSetupPageCompleted(PasswordTextField.StringValue);
                    }
                    else
                    {
                        Controller.CryptoPasswordPageCompleted(PasswordTextField.StringValue);
                    }
                };

                CancelButton.Activated += delegate { Controller.CryptoPageCancelled(); };


                ContentView.AddSubview(PasswordLabel);
                ContentView.AddSubview(PasswordTextField);
                ContentView.AddSubview(ShowPasswordCheckButton);

                if (type == PageType.CryptoSetup)
                {
                    ContentView.AddSubview(WarningImageView);
                    ContentView.AddSubview(WarningTextField);
                }

                Buttons.Add(ContinueButton);
                Buttons.Add(CancelButton);

                MakeFirstResponder((NSResponder)PasswordTextField);
                NSApplication.SharedApplication.RequestUserAttention(NSRequestUserAttentionType.CriticalRequest);
            }


            if (type == PageType.Finished)
            {
                Header      = "Your shared project is ready!";
                Description = "You can find the files in your SparkleShare folder.";

                if (warnings.Length > 0)
                {
                    WarningImage      = NSImage.ImageNamed("NSInfo");
                    WarningImage.Size = new CGSize(24, 24);

                    WarningImageView = new NSImageView()
                    {
                        Image = WarningImage,
                        Frame = new CGRect(200, Frame.Height - 175, 24, 24)
                    };

                    WarningTextField       = new SparkleLabel(warnings [0], NSTextAlignment.Left);
                    WarningTextField.Frame = new CGRect(235, Frame.Height - 245, 325, 100);

                    ContentView.AddSubview(WarningImageView);
                    ContentView.AddSubview(WarningTextField);
                }

                ShowFilesButton = new NSButton()
                {
                    Title = "Show Files"
                };
                FinishButton = new NSButton()
                {
                    Title = "Finish"
                };


                ShowFilesButton.Activated += delegate { Controller.ShowFilesClicked(); };
                FinishButton.Activated    += delegate { Controller.FinishPageCompleted(); };


                Buttons.Add(FinishButton);
                Buttons.Add(ShowFilesButton);

                NSApplication.SharedApplication.RequestUserAttention(NSRequestUserAttentionType.CriticalRequest);
            }
        }
Esempio n. 38
0
        public void ShowPage (PageType type, string [] warnings)
        {
            if (type == PageType.Setup) {
                Header      = "Welcome to SparkleShare!";
                Description = "First off, what’s your name and email?\n(visible only to team members)";

                FullNameLabel       = new SparkleLabel ("Full Name:", NSTextAlignment.Right);
                FullNameLabel.Frame = new RectangleF (165, Frame.Height - 234, 160, 17);

                FullNameTextField = new NSTextField () {
                    Frame       = new RectangleF (330, Frame.Height - 238, 196, 22),
                    StringValue = UnixUserInfo.GetRealUser ().RealName,
                    Delegate    = new SparkleTextFieldDelegate ()
                };

                EmailLabel       = new SparkleLabel ("Email:", NSTextAlignment.Right);
                EmailLabel.Frame = new RectangleF (165, Frame.Height - 264, 160, 17);
                    
                EmailTextField = new NSTextField () {
                    Frame       = new RectangleF (330, Frame.Height - 268, 196, 22),
                    Delegate    = new SparkleTextFieldDelegate ()
                };

                CancelButton = new NSButton () { Title = "Cancel" };

                ContinueButton = new NSButton () {
                    Title    = "Continue",
                    Enabled  = false
                };


                (FullNameTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckSetupPage (FullNameTextField.StringValue, EmailTextField.StringValue);
                };

                (EmailTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckSetupPage (FullNameTextField.StringValue, EmailTextField.StringValue);
                };

                ContinueButton.Activated += delegate {
                    string full_name = FullNameTextField.StringValue.Trim ();
                    string email     = EmailTextField.StringValue.Trim ();

                    Controller.SetupPageCompleted (full_name, email);
                };

                CancelButton.Activated += delegate { Controller.SetupPageCancelled (); };

                Controller.UpdateSetupContinueButtonEvent += delegate (bool button_enabled) {
                    SparkleShare.Controller.Invoke (() => {
                        ContinueButton.Enabled = button_enabled;
                    });
                };


                ContentView.AddSubview (FullNameLabel);
                ContentView.AddSubview (FullNameTextField);
                ContentView.AddSubview (EmailLabel);
                ContentView.AddSubview (EmailTextField);

                Buttons.Add (ContinueButton);
                Buttons.Add (CancelButton);

                Controller.CheckSetupPage (FullNameTextField.StringValue, EmailTextField.StringValue);

                if (FullNameTextField.StringValue.Equals (""))
                    MakeFirstResponder ((NSResponder) FullNameTextField);
                else
                    MakeFirstResponder ((NSResponder) EmailTextField);
            }

            if (type == PageType.Invite) {
                Header      = "You’ve received an invite!";
                Description = "Do you want to add this project to SparkleShare?";

                AddressLabel       = new SparkleLabel ("Address:", NSTextAlignment.Right);
                AddressLabel.Frame = new RectangleF (165, Frame.Height - 238, 160, 17);
                AddressLabel.Font  = NSFont.FromFontName (UserInterface.FontName + " Bold", NSFont.SystemFontSize);
     
                AddressTextField = new SparkleLabel (Controller.PendingInvite.Address, NSTextAlignment.Left) {
                    Frame = new RectangleF (330, Frame.Height - 240, 260, 17)
                };

                PathLabel       = new SparkleLabel ("Remote Path:", NSTextAlignment.Right);
                PathLabel.Frame = new RectangleF (165, Frame.Height - 262, 160, 17);
                PathLabel.Font  = NSFont.FromFontName (UserInterface.FontName + " Bold", NSFont.SystemFontSize);


                PathTextField = new SparkleLabel (Controller.PendingInvite.RemotePath, NSTextAlignment.Left) {
                    Frame = new RectangleF (330, Frame.Height - 264, 260, 17)
                };

                CancelButton = new NSButton () { Title = "Cancel" };
                AddButton = new NSButton () { Title = "Add" };


                CancelButton.Activated += delegate { Controller.PageCancelled (); };
                AddButton.Activated += delegate { Controller.InvitePageCompleted (); };


                ContentView.AddSubview (AddressLabel);
                ContentView.AddSubview (PathLabel);
                ContentView.AddSubview (AddressTextField);
                ContentView.AddSubview (PathTextField);

                Buttons.Add (AddButton);
                Buttons.Add (CancelButton);
            }

            if (type == PageType.Add) {
                Header      = "Where’s your project hosted?";
                Description = "";

                AddressLabel = new SparkleLabel ("Address:", NSTextAlignment.Left) {
                    Frame = new RectangleF (190, Frame.Height - 308, 160, 17),
                    Font  = NSFont.FromFontName (UserInterface.FontName + " Bold", NSFont.SystemFontSize)
                };

                AddressTextField = new NSTextField () {
                    Frame       = new RectangleF (190, Frame.Height - 336, 196, 22),
                    Enabled     = (Controller.SelectedPreset.Address == null),
                    Delegate    = new SparkleTextFieldDelegate (),
                    StringValue = "" + Controller.PreviousAddress
                };

                AddressTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;

                PathLabel = new SparkleLabel ("Remote Path:", NSTextAlignment.Left) {
                    Frame = new RectangleF (190 + 196 + 16, Frame.Height - 308, 160, 17),
                    Font  = NSFont.FromFontName (UserInterface.FontName + " Bold", NSFont.SystemFontSize)
                };

                PathTextField = new NSTextField () {
                    Frame       = new RectangleF (190 + 196 + 16, Frame.Height - 336, 196, 22),
                    Enabled     = (Controller.SelectedPreset.Path == null),
                    Delegate    = new SparkleTextFieldDelegate (),
                    StringValue = "" + Controller.PreviousPath
                };

                PathTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;

                PathHelpLabel = new SparkleLabel (Controller.SelectedPreset.PathExample, NSTextAlignment.Left) {
                    TextColor = NSColor.DisabledControlText,
                    Frame     = new RectangleF (190 + 196 + 16, Frame.Height - 358, 204, 19)
                };

                AddressHelpLabel = new SparkleLabel (Controller.SelectedPreset.AddressExample, NSTextAlignment.Left) {
                    TextColor = NSColor.DisabledControlText,
                    Frame     = new RectangleF (190, Frame.Height - 358, 204, 19)
                };

                if (TableView == null || TableView.RowCount != Controller.Presets.Count) {
                    TableView = new NSTableView () {
                        Frame            = new RectangleF (0, 0, 0, 0),
                        RowHeight        = 38,
                        IntercellSpacing = new SizeF (8, 12),
                        HeaderView       = null,
                        Delegate         = new SparkleTableViewDelegate ()
                    };

                    ScrollView = new NSScrollView () {
                        Frame               = new RectangleF (190, Frame.Height - 280, 408, 185),
                        DocumentView        = TableView,
                        HasVerticalScroller = true,
                        BorderType          = NSBorderType.BezelBorder
                    };

                    IconColumn = new NSTableColumn () {
                        Width         = 36,
                        HeaderToolTip = "Icon",
                        DataCell      = new NSImageCell () { ImageAlignment = NSImageAlignment.Right }
                    };

                    DescriptionColumn = new NSTableColumn () {
                        Width         = 350,
                        HeaderToolTip = "Description",
                        Editable      = false
                    };

                    DescriptionColumn.DataCell.Font = NSFontManager.SharedFontManager.FontWithFamily (
                        UserInterface.FontName, NSFontTraitMask.Condensed, 0, 11);

                    TableView.AddColumn (IconColumn);
                    TableView.AddColumn (DescriptionColumn);

                    // Hi-res display support was added after Snow Leopard
                    if (Environment.OSVersion.Version.Major < 11)
                        DataSource = new SparkleDataSource (1, Controller.Presets);
                    else
                        DataSource = new SparkleDataSource (BackingScaleFactor, Controller.Presets);

                    TableView.DataSource = DataSource;
                    TableView.ReloadData ();
                    
                    (TableView.Delegate as SparkleTableViewDelegate).SelectionChanged += delegate {
                        Controller.SelectedPresetChanged (TableView.SelectedRow);
                        Controller.CheckAddPage (AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
                    };
                }
                
                TableView.SelectRow (Controller.SelectedPresetIndex, false);
                TableView.ScrollRowToVisible (Controller.SelectedPresetIndex);
                MakeFirstResponder ((NSResponder) TableView);

                HistoryCheckButton = new NSButton () {
                    Frame = new RectangleF (190, Frame.Height - 400, 300, 18),
                    Title = "Fetch prior revisions"
                };

                if (Controller.FetchPriorHistory)
                    HistoryCheckButton.State = NSCellStateValue.On;

                HistoryCheckButton.SetButtonType (NSButtonType.Switch);

                AddButton = new NSButton () {
                    Title = "Add",
                    Enabled = false
                };

                CancelButton = new NSButton () { Title = "Cancel" };


                Controller.ChangeAddressFieldEvent += delegate (string text, string example_text, FieldState state) {
                    SparkleShare.Controller.Invoke (() => {
                        AddressTextField.StringValue = text;
                        AddressTextField.Enabled     = (state == FieldState.Enabled);
                        AddressHelpLabel.StringValue = example_text;
                    });
                };

                Controller.ChangePathFieldEvent += delegate (string text, string example_text, FieldState state) {
                    SparkleShare.Controller.Invoke (() => {
                        PathTextField.StringValue = text;
                        PathTextField.Enabled     = (state == FieldState.Enabled);
                        PathHelpLabel.StringValue = example_text;
                    });
                };


                (AddressTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckAddPage (AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
                };

                 (PathTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckAddPage (AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
                };


                HistoryCheckButton.Activated += delegate {
                    Controller.HistoryItemChanged (HistoryCheckButton.State == NSCellStateValue.On);
                };

                AddButton.Activated += delegate {
                    Controller.AddPageCompleted (AddressTextField.StringValue, PathTextField.StringValue);
                };

                CancelButton.Activated += delegate { Controller.PageCancelled (); };

                Controller.UpdateAddProjectButtonEvent += delegate (bool button_enabled) {
                    SparkleShare.Controller.Invoke (() => {
                        AddButton.Enabled = button_enabled;
                    });
                };

                ContentView.AddSubview (ScrollView);
                ContentView.AddSubview (AddressLabel);
                ContentView.AddSubview (AddressTextField);
                ContentView.AddSubview (AddressHelpLabel);
                ContentView.AddSubview (PathLabel);
                ContentView.AddSubview (PathTextField);
                ContentView.AddSubview (PathHelpLabel);
                ContentView.AddSubview (HistoryCheckButton);

                Buttons.Add (AddButton);
                Buttons.Add (CancelButton);

                Controller.CheckAddPage (AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
            }

            if (type == PageType.Syncing) {
                Header      = "Adding project ‘" + Controller.SyncingFolder + "’…";
                Description = "This may take a while for large projects.\nIsn’t it coffee-o’clock?";

                ProgressIndicator = new NSProgressIndicator () {
                    Frame         = new RectangleF (190, Frame.Height - 200, 640 - 150 - 80, 20),
                    Style         = NSProgressIndicatorStyle.Bar,
                    MinValue      = 0.0,
                    MaxValue      = 100.0,
                    Indeterminate = false,
                    DoubleValue   = Controller.ProgressBarPercentage
                };

                ProgressIndicator.StartAnimation (this);

                CancelButton = new NSButton () { Title = "Cancel" };

                FinishButton = new NSButton () {
                    Title = "Finish",
                    Enabled = false
                };

                ProgressLabel       = new SparkleLabel ("Preparing to fetch files…", NSTextAlignment.Right);
                ProgressLabel.Frame = new RectangleF (Frame.Width - 40 - 250, 185, 250, 25);


                Controller.UpdateProgressBarEvent += delegate (double percentage, string speed) {
                    SparkleShare.Controller.Invoke (() => {
                        ProgressIndicator.DoubleValue = percentage;
                        ProgressLabel.StringValue     = speed;
                    });
                };


                CancelButton.Activated += delegate { Controller.SyncingCancelled (); };


                ContentView.AddSubview (ProgressLabel);
                ContentView.AddSubview (ProgressIndicator);

                Buttons.Add (FinishButton);
                Buttons.Add (CancelButton);
            }

            if (type == PageType.Error) {
                Header      = "Oops! Something went wrong…";
                Description = "Please check the following:";

                // Displaying marked up text with Cocoa is
                // a pain, so we just use a webview instead
                WebView web_view = new WebView ();
                web_view.Frame   = new RectangleF (190, Frame.Height - 525, 375, 400);

                string html = "<style>" +
                    "* {" +
                    "  font-family: '" + UserInterface.FontName + "';" +
                    "  font-size: 12px; cursor: default;" +
                    "}" +
                    "body {" +
                    "  -webkit-user-select: none;" +
                    "  margin: 0;" +
                    "  padding: 3px;" +
                    "}" +
                    "li {" +
                    "  margin-bottom: 16px;" +
                    "  margin-left: 0;" +
                    "  padding-left: 0;" +
                    "  line-height: 20px;" +
                    "  word-wrap: break-word;" +
                    "}" +
                    "ul {" +
                    "  padding-left: 24px;" +
                    "}" +
                    "</style>" +
                    "<ul>" +
                    "  <li><b>" + Controller.PreviousUrl + "</b> is the address we’ve compiled. Does this look alright?</li>" +
                    "  <li>Is this computer’s Client ID known by the host?</li>" +
                    "</ul>";

                if (warnings.Length > 0) {
                    string warnings_markup = "";

                    foreach (string warning in warnings)
                        warnings_markup += "<br><b>" + warning + "</b>";

                    html = html.Replace ("</ul>", "<li>Here’s the raw error message: " + warnings_markup + "</li></ul>");
                }

                web_view.MainFrame.LoadHtmlString (html, new NSUrl (""));
                web_view.DrawsBackground = false;

                CancelButton = new NSButton () { Title = "Cancel" };
                TryAgainButton = new NSButton () { Title = "Retry" };


                CancelButton.Activated += delegate { Controller.PageCancelled (); };
                TryAgainButton.Activated += delegate { Controller.ErrorPageCompleted (); };


                ContentView.AddSubview (web_view);

                Buttons.Add (TryAgainButton);
                Buttons.Add (CancelButton);
            }

            if (type == PageType.StorageSetup) {
                Header = string.Format ("Storage type for ‘{0}’", Controller.SyncingFolder);
                Description = "What type of storage would you like to use?";


                storage_type_descriptions = new List<NSTextField> ();

                ButtonCellProto = new NSButtonCell ();
                ButtonCellProto.SetButtonType (NSButtonType.Radio);
                ButtonCellProto.Font = NSFont.FromFontName (UserInterface.FontName + " Bold", NSFont.SystemFontSize);

                Matrix = new NSMatrix (new RectangleF (202, Frame.Height - 256 - 128, 256, 256), NSMatrixMode.Radio,
                    ButtonCellProto, SparkleShare.Controller.FetcherAvailableStorageTypes.Count, 1);

                Matrix.CellSize = new SizeF (256, 36);
                Matrix.IntercellSpacing = new SizeF (32, 32);

                int i = 0;
                foreach (StorageTypeInfo storage_type in SparkleShare.Controller.FetcherAvailableStorageTypes) {
                    Matrix.Cells [i].Title = " " + storage_type.Name;

                    NSTextField storage_type_description = new SparkleLabel (storage_type.Description, NSTextAlignment.Left) {
                        TextColor = NSColor.DisabledControlText,
                        Frame = new RectangleF (223, Frame.Height - 190 - (68 * i), 256, 32)
                    };

                    storage_type_descriptions.Add (storage_type_description);
                    ContentView.AddSubview (storage_type_description);

                    i++;
                }

                ContentView.AddSubview (Matrix);


                CancelButton = new NSButton () { Title = "Cancel" };
                ContinueButton = new NSButton () { Title = "Continue" };

                ContinueButton.Activated += delegate {
                    StorageTypeInfo selected_storage_type = SparkleShare.Controller.FetcherAvailableStorageTypes [Matrix.SelectedRow];
                    Controller.StoragePageCompleted (selected_storage_type.Type);
                };

                CancelButton.Activated += delegate { Controller.SyncingCancelled (); };

                Buttons.Add (ContinueButton);
                Buttons.Add (CancelButton);


                NSApplication.SharedApplication.RequestUserAttention (NSRequestUserAttentionType.CriticalRequest);
            }

            if (type == PageType.CryptoSetup || type == PageType.CryptoPassword) {
                if (type == PageType.CryptoSetup) {
                    Header      = "Set up file encryption";
                    Description = "Please a provide a strong password that you don’t use elsewhere.";
                
                } else {
                    Header      = "This project contains encrypted files";
                    Description = "Please enter the password to see their contents.";
                }

                int extra_pos_y = 0;

                if (type == PageType.CryptoPassword)
                    extra_pos_y = 20;
  
                PasswordLabel = new SparkleLabel ("Password:"******" Bold", NSFont.SystemFontSize)
                };

                PasswordTextField = new NSSecureTextField () {
                    Frame       = new RectangleF (320, Frame.Height - 208 - extra_pos_y, 196, 22),
                    Delegate    = new SparkleTextFieldDelegate ()
                };

                VisiblePasswordTextField = new NSTextField () {
                    Frame       = new RectangleF (320, Frame.Height - 208 - extra_pos_y, 196, 22),
                    Delegate    = new SparkleTextFieldDelegate ()
                };

                ShowPasswordCheckButton = new NSButton () {
                    Frame = new RectangleF (318, Frame.Height - 235 - extra_pos_y, 300, 18),
                    Title = "Show password",
                    State = NSCellStateValue.Off
                };

                ShowPasswordCheckButton.SetButtonType (NSButtonType.Switch);

                WarningImage = NSImage.ImageNamed ("NSInfo");
                WarningImage.Size = new SizeF (24, 24);

                WarningImageView = new NSImageView () {
                    Image = WarningImage,
                    Frame = new RectangleF (200, Frame.Height - 320, 24, 24)
                };

                WarningTextField = new SparkleLabel ("This password can’t be changed later, and your files can’t be recovered if it’s forgotten.", NSTextAlignment.Left) {
                    Frame = new RectangleF (235, Frame.Height - 390, 325, 100),
                };

                CancelButton = new NSButton () { Title = "Cancel" };

                ContinueButton = new NSButton () {
                    Title    = "Continue",
                    Enabled  = false
                };


                Controller.UpdateCryptoPasswordContinueButtonEvent += delegate (bool button_enabled) {
                    SparkleShare.Controller.Invoke (() => { ContinueButton.Enabled = button_enabled; });
                };

                Controller.UpdateCryptoSetupContinueButtonEvent += delegate (bool button_enabled) {
                    SparkleShare.Controller.Invoke (() => { ContinueButton.Enabled = button_enabled; });
                };
                
                ShowPasswordCheckButton.Activated += delegate {
                    if (PasswordTextField.Superview == ContentView) {
                        PasswordTextField.RemoveFromSuperview ();
                        ContentView.AddSubview (VisiblePasswordTextField);

                    } else {
                        VisiblePasswordTextField.RemoveFromSuperview ();
                        ContentView.AddSubview (PasswordTextField);
                    }
                };

                (PasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    VisiblePasswordTextField.StringValue = PasswordTextField.StringValue;

                    if (type == PageType.CryptoSetup)
                        Controller.CheckCryptoSetupPage (PasswordTextField.StringValue);
                    else
                        Controller.CheckCryptoPasswordPage (PasswordTextField.StringValue);
                };

                (VisiblePasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    PasswordTextField.StringValue = VisiblePasswordTextField.StringValue;
                    
                    if (type == PageType.CryptoSetup)
                        Controller.CheckCryptoSetupPage (PasswordTextField.StringValue);
                    else
                        Controller.CheckCryptoPasswordPage (PasswordTextField.StringValue);
                };

                ContinueButton.Activated += delegate {
                    if (type == PageType.CryptoSetup)
                        Controller.CryptoSetupPageCompleted (PasswordTextField.StringValue);
                    else
                        Controller.CryptoPasswordPageCompleted (PasswordTextField.StringValue);
                };

                CancelButton.Activated += delegate { Controller.CryptoPageCancelled (); };


                ContentView.AddSubview (PasswordLabel);
                ContentView.AddSubview (PasswordTextField);
                ContentView.AddSubview (ShowPasswordCheckButton);

                if (type == PageType.CryptoSetup) {
                    ContentView.AddSubview (WarningImageView);
                    ContentView.AddSubview (WarningTextField);
                }

                Buttons.Add (ContinueButton);
                Buttons.Add (CancelButton);

                MakeFirstResponder ((NSResponder) PasswordTextField);
                NSApplication.SharedApplication.RequestUserAttention (NSRequestUserAttentionType.CriticalRequest);
            }


            if (type == PageType.Finished) {
                Header      = "Your shared project is ready!";
                Description = "You can find the files in your SparkleShare folder.";

                if (warnings.Length > 0) {
                    WarningImage = NSImage.ImageNamed ("NSInfo");
                    WarningImage.Size = new SizeF (24, 24);

                    WarningImageView = new NSImageView () {
                        Image = WarningImage,
                        Frame = new RectangleF (200, Frame.Height - 175, 24, 24)
                    };

                    WarningTextField = new SparkleLabel (warnings [0], NSTextAlignment.Left);
                    WarningTextField.Frame       = new RectangleF (235, Frame.Height - 245, 325, 100);

                    ContentView.AddSubview (WarningImageView);
                    ContentView.AddSubview (WarningTextField);
                }

                ShowFilesButton = new NSButton () { Title = "Show Files" };
                FinishButton    = new NSButton () { Title = "Finish" };


                ShowFilesButton.Activated += delegate { Controller.ShowFilesClicked (); };
                FinishButton.Activated += delegate { Controller.FinishPageCompleted (); };


                Buttons.Add (FinishButton);
                Buttons.Add (ShowFilesButton);

                NSApplication.SharedApplication.RequestUserAttention (NSRequestUserAttentionType.CriticalRequest);
            }
        }
Esempio n. 39
0
        // TODO: Window needs to be made resizable
        public SparkleEventLog()
            : base()
        {
            Title    = "Recent Events";

            Delegate = new SparkleEventsDelegate ();

            SetFrame (new RectangleF (0, 0, 480, 640), true);
            Center ();

            StyleMask = (NSWindowStyle.Closable |
                         NSWindowStyle.Miniaturizable |
                         NSWindowStyle.Titled);

            MaxSize     = new SizeF (480, 640);
            MinSize     = new SizeF (480, 640);
            HasShadow   = true;
            BackingType = NSBackingStore.Buffered;

            this.hidden_close_button = new NSButton () {
                Frame                     = new RectangleF (0, 0, 0, 0),
                KeyEquivalentModifierMask = NSEventModifierMask.CommandKeyMask,
                KeyEquivalent             = "w"
            };

            this.hidden_close_button.Activated += delegate {
                Controller.WindowClosed ();
            };

            ContentView.AddSubview (this.hidden_close_button);

            this.size_label = new NSTextField () {
                Alignment       = NSTextAlignment.Right,
                BackgroundColor = NSColor.WindowBackground,
                Bordered        = false,
                Editable        = false,
                Frame           = new RectangleF (0, 588, 60, 20),
                StringValue     = "Size:",
                Font            = SparkleUI.BoldFont
            };

            this.size_label_value = new NSTextField () {
                Alignment       = NSTextAlignment.Left,
                BackgroundColor = NSColor.WindowBackground,
                Bordered        = false,
                Editable        = false,
                Frame           = new RectangleF (60, 588, 75, 20),
                StringValue     = "…",
                Font            = SparkleUI.Font
            };

            this.history_label = new NSTextField () {
                Alignment       = NSTextAlignment.Right,
                BackgroundColor = NSColor.WindowBackground,
                Bordered        = false,
                Editable        = false,
                Frame           = new RectangleF (130, 588, 60, 20),
                StringValue     = "History:",
                Font            = SparkleUI.BoldFont
            };

            this.history_label_value = new NSTextField () {
                Alignment       = NSTextAlignment.Left,
                BackgroundColor = NSColor.WindowBackground,
                Bordered        = false,
                Editable        = false,
                Frame           = new RectangleF (190, 588, 75, 20),
                StringValue     = "…",
                Font            = SparkleUI.Font
            };

            ContentView.AddSubview (this.size_label);
            ContentView.AddSubview (this.size_label_value);
            ContentView.AddSubview (this.history_label);
            ContentView.AddSubview (this.history_label_value);
            ContentView.AddSubview (this.separator);

            this.progress_indicator = new NSProgressIndicator () {
                Style = NSProgressIndicatorStyle.Spinning,
                Frame = new RectangleF (this.web_view.Frame.Width / 2 - 10,
                    this.web_view.Frame.Height / 2 + 10, 20, 20)
            };

            this.progress_indicator.StartAnimation (this);
            ContentView.AddSubview (this.progress_indicator);

            (this.web_view.PolicyDelegate as SparkleWebPolicyDelegate)
                .LinkClicked += delegate (string href) {
                    Controller.LinkClicked (href);
                };

            // Hook up the controller events
            Controller.HideWindowEvent += delegate {
                InvokeOnMainThread (delegate {
                    PerformClose (this);
                });
            };

            Controller.ShowWindowEvent += delegate {
                InvokeOnMainThread (delegate {
                    OrderFrontRegardless ();

                    UpdateContent (null);
                    UpdateChooser (null);
                });
            };

            Controller.UpdateChooserEvent += delegate (string [] folders) {
                InvokeOnMainThread (delegate {
                    UpdateChooser (folders);
                });
            };

            Controller.UpdateContentEvent += delegate (string html) {
                InvokeOnMainThread (delegate {
                    UpdateContent (html);
                });
            };

            Controller.ContentLoadingEvent += delegate {
                InvokeOnMainThread (delegate {
                    if (this.web_view.Superview == ContentView)
                        this.web_view.RemoveFromSuperview ();

                    ContentView.AddSubview (this.progress_indicator);
                });
            };

            Controller.UpdateSizeInfoEvent += delegate (string size, string history_size) {
                InvokeOnMainThread (delegate {
                    this.size_label_value.StringValue = size;
                    this.history_label_value.StringValue = history_size;
                });
            };
        }
Esempio n. 40
0
        private void CreateEvents()
        {
            Separator = new NSBox (new RectangleF (0, 579, 480, 1)) {
                BorderColor = NSColor.LightGray,
                BoxType = NSBoxType.NSBoxCustom
            };

            ContentView.AddSubview (Separator);

            WebView = new WebView (new RectangleF (0, 0, 480, 579), "", "") {
                PolicyDelegate = new SparkleWebPolicyDelegate ()
            };

            ProgressIndicator = new NSProgressIndicator () {
                Style = NSProgressIndicatorStyle.Spinning,
                Frame = new RectangleF (WebView.Frame.Width / 2 - 10, WebView.Frame.Height / 2 + 10, 20, 20)
            };

            ProgressIndicator.StartAnimation (this);
            Update ();
        }
Esempio n. 41
0
        private void ShowSyncingPage(string name)
        {
            Reset ();

                Header      = "Syncing folder ‘" + name + "’…";
                Description = "This may take a while.\n" +
                              "Are you sure it’s not coffee o'clock?";

                ProgressIndicator = new NSProgressIndicator () {
                    Frame = new RectangleF (190, Frame.Height - 200, 640 - 150 - 80, 20),
                    Style = NSProgressIndicatorStyle.Bar
                };

                ProgressIndicator.StartAnimation (this);

                ContentView.AddSubview (ProgressIndicator);

                FinishButton = new NSButton () {
                    Title = "Finish",
                    Enabled = false
                };

                Buttons.Add (FinishButton);

            ShowAll ();
        }
Esempio n. 42
0
        public OrangeEventLog()
            : base()
        {
            using (var a = new NSAutoreleasePool ())
            {
                Title    = "Recent Changes";
                Delegate = new OrangeEventsDelegate ();
                // TODO: Make window resizable

                int width  = 480;
                int height = 640;
                float x    = (float) (NSScreen.MainScreen.Frame.Width * 0.61);
                float y    = (float) (NSScreen.MainScreen.Frame.Height * 0.5 - (height * 0.5));

                SetFrame (new RectangleF (x, y, width, height), true);

                StyleMask = (NSWindowStyle.Closable |
                             NSWindowStyle.Miniaturizable |
                             NSWindowStyle.Titled);

                MaxSize     = new SizeF (480, 640);
                MinSize     = new SizeF (480, 640);
                HasShadow   = true;
                BackingType = NSBackingStore.Buffered;

                this.web_view = new WebView (new RectangleF (0, 0, 481, 579), "", "") {
                    PolicyDelegate = new OrangeWebPolicyDelegate ()
                };

                this.hidden_close_button = new NSButton () {
                    Frame                     = new RectangleF (0, 0, 0, 0),
                    KeyEquivalentModifierMask = NSEventModifierMask.CommandKeyMask,
                    KeyEquivalent             = "w"
                };

                this.hidden_close_button.Activated += delegate {
                    Controller.WindowClosed ();
                };

                this.size_label = new NSTextField () {
                    Alignment       = NSTextAlignment.Right,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (0, 588, 60, 20),
                    StringValue     = "Size:",
                    Font            = OrangeUI.BoldFont
                };

                this.size_label_value = new NSTextField () {
                    Alignment       = NSTextAlignment.Left,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (60, 588, 75, 20),
                    StringValue     = "…",
                    Font            = OrangeUI.Font
                };

                this.history_label = new NSTextField () {
                    Alignment       = NSTextAlignment.Right,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (130, 588, 60, 20),
                    StringValue     = "History:",
                    Font            = OrangeUI.BoldFont
                };

                this.history_label_value = new NSTextField () {
                    Alignment       = NSTextAlignment.Left,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (190, 588, 75, 20),
                    StringValue     = "…",
                    Font            = OrangeUI.Font
                };

                this.separator = new NSBox (new RectangleF (0, 579, 480, 1)) {
                    BorderColor = NSColor.LightGray,
                    BoxType = NSBoxType.NSBoxCustom
                };

                this.background = new NSBox (new RectangleF (0, -1, 481, 581)) {
                    FillColor = NSColor.White,
                    BoxType = NSBoxType.NSBoxCustom
                };

                this.progress_indicator = new NSProgressIndicator () {
                    Style = NSProgressIndicatorStyle.Spinning,
                    Frame = new RectangleF (this.web_view.Frame.Width / 2 - 10,
                        this.web_view.Frame.Height / 2 + 10, 20, 20)
                };

                this.progress_indicator.StartAnimation (this);

                ContentView.AddSubview (this.size_label);
                ContentView.AddSubview (this.size_label_value);
                ContentView.AddSubview (this.history_label);
                ContentView.AddSubview (this.history_label_value);
                ContentView.AddSubview (this.separator);
                ContentView.AddSubview (this.progress_indicator);
                ContentView.AddSubview (this.background);
                ContentView.AddSubview (this.hidden_close_button);

                (this.web_view.PolicyDelegate as OrangeWebPolicyDelegate).LinkClicked += delegate (string href) {
                    Controller.LinkClicked (href);
                };
            }

            // Hook up the controller events
            Controller.HideWindowEvent += delegate {
                using (var a = new NSAutoreleasePool ())
                {
                    InvokeOnMainThread (delegate {
                        PerformClose (this);

                        if (this.web_view.Superview == ContentView)
                            this.web_view.RemoveFromSuperview ();
                    });
                }
            };

            Controller.ShowWindowEvent += delegate {
                using (var a = new NSAutoreleasePool ())
                {
                    InvokeOnMainThread (delegate {
                        OrderFrontRegardless ();
                    });
                }
            };

            Controller.UpdateChooserEvent += delegate (string [] folders) {
                using (var a = new NSAutoreleasePool ())
                {
                    InvokeOnMainThread (delegate {
                        UpdateChooser (folders);
                    });
                }
            };

            Controller.UpdateContentEvent += delegate (string html) {
                using (var a = new NSAutoreleasePool ())
                {
                    InvokeOnMainThread (delegate {
                        UpdateContent (html);
                    });
                }
            };

            Controller.ContentLoadingEvent += delegate {
                using (var a = new NSAutoreleasePool ())
                {
                    InvokeOnMainThread (delegate {
                        if (this.web_view.Superview == ContentView)
                            this.web_view.RemoveFromSuperview ();

                        ContentView.AddSubview (this.progress_indicator);
                    });
                }
            };

            Controller.UpdateSizeInfoEvent += delegate (string size, string history_size) {
                using (var a = new NSAutoreleasePool ())
                {
                    InvokeOnMainThread (delegate {
                        this.size_label_value.StringValue    = size;
                        this.history_label_value.StringValue = history_size;
                    });
                }
            };
        }
Esempio n. 43
0
        public void ShowPage (PageType type, string [] warnings)
        {
            if (type == PageType.Setup) {
                Header      = "Welcome to SparkleShare!";
                Description = "First off, what’s your name and email?\n(visible only to team members)";

                FullNameLabel       = new SparkleLabel ("Full Name:", NSTextAlignment.Right);
                FullNameLabel.Frame = new RectangleF (165, Frame.Height - 234, 160, 17);

                FullNameTextField = new NSTextField () {
                    Frame       = new RectangleF (330, Frame.Height - 238, 196, 22),
                    StringValue = UnixUserInfo.GetRealUser ().RealName,
                    Delegate    = new SparkleTextFieldDelegate ()
                };

                EmailLabel       = new SparkleLabel ("Email:", NSTextAlignment.Right);
                EmailLabel.Frame = new RectangleF (165, Frame.Height - 264, 160, 17);
                    
                EmailTextField = new NSTextField () {
                    Frame       = new RectangleF (330, Frame.Height - 268, 196, 22),
                    Delegate    = new SparkleTextFieldDelegate ()
                };

                CancelButton = new NSButton () { Title = "Cancel" };

                ContinueButton = new NSButton () {
                    Title    = "Continue",
                    Enabled  = false
                };


                (FullNameTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckSetupPage (FullNameTextField.StringValue, EmailTextField.StringValue);
                };

                (EmailTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckSetupPage (FullNameTextField.StringValue, EmailTextField.StringValue);
                };

                ContinueButton.Activated += delegate {
                    string full_name = FullNameTextField.StringValue.Trim ();
                    string email     = EmailTextField.StringValue.Trim ();

                    Controller.SetupPageCompleted (full_name, email);
                };

                CancelButton.Activated += delegate { Controller.SetupPageCancelled (); };

                Controller.UpdateSetupContinueButtonEvent += delegate (bool button_enabled) {
                    Program.Controller.Invoke (() => {
                        ContinueButton.Enabled = button_enabled;
                    });
                };


                ContentView.AddSubview (FullNameLabel);
                ContentView.AddSubview (FullNameTextField);
                ContentView.AddSubview (EmailLabel);
                ContentView.AddSubview (EmailTextField);

                Buttons.Add (ContinueButton);
                Buttons.Add (CancelButton);

                Controller.CheckSetupPage (FullNameTextField.StringValue, EmailTextField.StringValue);
            }

            if (type == PageType.Invite) {
                Header      = "You’ve received an invite!";
                Description = "Do you want to add this project to SparkleShare?";

                AddressLabel       = new SparkleLabel ("Address:", NSTextAlignment.Right);
                AddressLabel.Frame = new RectangleF (165, Frame.Height - 240, 160, 17);
     
                AddressTextField = new SparkleLabel (Controller.PendingInvite.Address, NSTextAlignment.Left) {
                    Frame = new RectangleF (330, Frame.Height - 240, 260, 17),
                    Font  = SparkleUI.BoldFont
                };

                PathLabel       = new SparkleLabel ("Remote Path:", NSTextAlignment.Right);
                PathLabel.Frame = new RectangleF (165, Frame.Height - 264, 160, 17);

                PathTextField = new SparkleLabel (Controller.PendingInvite.RemotePath, NSTextAlignment.Left) {
                    Frame = new RectangleF (330, Frame.Height - 264, 260, 17),
                    Font  = SparkleUI.BoldFont
                };

                CancelButton = new NSButton () { Title = "Cancel" };
                AddButton = new NSButton () { Title = "Add" };


                CancelButton.Activated += delegate { Controller.PageCancelled (); };
                AddButton.Activated += delegate { Controller.InvitePageCompleted (); };


                ContentView.AddSubview (AddressLabel);
                ContentView.AddSubview (PathLabel);
                ContentView.AddSubview (AddressTextField);
                ContentView.AddSubview (PathTextField);

                Buttons.Add (AddButton);
                Buttons.Add (CancelButton);
            }

            if (type == PageType.Add) {
                Header      = "Where’s your project hosted?";
                Description = "";

                AddressLabel = new SparkleLabel ("Address:", NSTextAlignment.Left) {
                    Frame = new RectangleF (190, Frame.Height - 308, 160, 17),
                    Font  = SparkleUI.BoldFont
                };

                AddressTextField = new NSTextField () {
                    Frame       = new RectangleF (190, Frame.Height - 336, 196, 22),
                    Font        = SparkleUI.Font,
                    Enabled     = (Controller.SelectedPlugin.Address == null),
                    Delegate    = new SparkleTextFieldDelegate (),
                    StringValue = "" + Controller.PreviousAddress
                };

                AddressTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;

                PathLabel = new SparkleLabel ("Remote Path:", NSTextAlignment.Left) {
                    Frame = new RectangleF (190 + 196 + 16, Frame.Height - 308, 160, 17),
                    Font  = SparkleUI.BoldFont
                };

                PathTextField = new NSTextField () {
                    Frame       = new RectangleF (190 + 196 + 16, Frame.Height - 336, 196, 22),
                    Enabled     = (Controller.SelectedPlugin.Path == null),
                    Delegate    = new SparkleTextFieldDelegate (),
                    StringValue = "" + Controller.PreviousPath
                };

                PathTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;

                PathHelpLabel = new SparkleLabel (Controller.SelectedPlugin.PathExample, NSTextAlignment.Left) {
                    TextColor       = NSColor.DisabledControlText,
                    Frame           = new RectangleF (190 + 196 + 16, Frame.Height - 355, 204, 17),
                    Font            = NSFontManager.SharedFontManager.FontWithFamily ("Lucida Grande",
                        NSFontTraitMask.Condensed, 0, 11),
                };

                AddressHelpLabel = new SparkleLabel (Controller.SelectedPlugin.AddressExample, NSTextAlignment.Left) {
                    TextColor       = NSColor.DisabledControlText,
                    Frame           = new RectangleF (190, Frame.Height - 355, 204, 17),
                    Font            = NSFontManager.SharedFontManager.FontWithFamily ("Lucida Grande",
                        NSFontTraitMask.Condensed, 0, 11),
                };

                if (TableView == null || TableView.RowCount != Controller.Plugins.Count) {
                    TableView = new NSTableView () {
                        Frame            = new RectangleF (0, 0, 0, 0),
                        RowHeight        = 34,
                        IntercellSpacing = new SizeF (8, 12),
                        HeaderView       = null,
                        Delegate         = new SparkleTableViewDelegate ()
                    };

                    ScrollView = new NSScrollView () {
                        Frame               = new RectangleF (190, Frame.Height - 280, 408, 185),
                        DocumentView        = TableView,
                        HasVerticalScroller = true,
                        BorderType          = NSBorderType.BezelBorder
                    };

                    IconColumn = new NSTableColumn () {
                        Width         = 36,
                        HeaderToolTip = "Icon",
                        DataCell      = new NSImageCell () { ImageAlignment = NSImageAlignment.Right }
                    };

                    DescriptionColumn = new NSTableColumn () {
                        Width         = 350,
                        HeaderToolTip = "Description",
                        Editable      = false
                    };

                    DescriptionColumn.DataCell.Font = NSFontManager.SharedFontManager.FontWithFamily ("Lucida Grande",
                        NSFontTraitMask.Condensed, 0, 11);

                    TableView.AddColumn (IconColumn);
                    TableView.AddColumn (DescriptionColumn);

                    // Hi-res display support was added after Snow Leopard
                    if (Environment.OSVersion.Version.Major < 11)
                        DataSource = new SparkleDataSource (1, Controller.Plugins);
                    else
                        DataSource = new SparkleDataSource (BackingScaleFactor, Controller.Plugins);

                    TableView.DataSource = DataSource;
                    TableView.ReloadData ();
                    
                    (TableView.Delegate as SparkleTableViewDelegate).SelectionChanged += delegate {
                        Controller.SelectedPluginChanged (TableView.SelectedRow);
                        Controller.CheckAddPage (AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
                    };
                }
                
                TableView.SelectRow (Controller.SelectedPluginIndex, false);
                TableView.ScrollRowToVisible (Controller.SelectedPluginIndex);

                HistoryCheckButton = new NSButton () {
                    Frame = new RectangleF (190, Frame.Height - 400, 300, 18),
                    Title = "Fetch prior revisions"
                };

                if (Controller.FetchPriorHistory)
                    HistoryCheckButton.State = NSCellStateValue.On;

                HistoryCheckButton.SetButtonType (NSButtonType.Switch);

                AddButton = new NSButton () {
                    Title = "Add",
                    Enabled = false
                };

                CancelButton = new NSButton () { Title = "Cancel" };


                Controller.ChangeAddressFieldEvent += delegate (string text, string example_text, FieldState state) {
                    Program.Controller.Invoke (() => {
                        AddressTextField.StringValue = text;
                        AddressTextField.Enabled     = (state == FieldState.Enabled);
                        AddressHelpLabel.StringValue = example_text;
                    });
                };

                Controller.ChangePathFieldEvent += delegate (string text, string example_text, FieldState state) {
                    Program.Controller.Invoke (() => {
                        PathTextField.StringValue = text;
                        PathTextField.Enabled     = (state == FieldState.Enabled);
                        PathHelpLabel.StringValue = example_text;
                    });
                };


                (AddressTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckAddPage (AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
                };

                 (PathTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    Controller.CheckAddPage (AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
                };


                HistoryCheckButton.Activated += delegate {
                    Controller.HistoryItemChanged (HistoryCheckButton.State == NSCellStateValue.On);
                };

                AddButton.Activated += delegate {
                    Controller.AddPageCompleted (AddressTextField.StringValue, PathTextField.StringValue);
                };

                CancelButton.Activated += delegate { Controller.PageCancelled (); };

                Controller.UpdateAddProjectButtonEvent += delegate (bool button_enabled) {
                    Program.Controller.Invoke (() => {
                        AddButton.Enabled = button_enabled;
                    });
                };

                ContentView.AddSubview (ScrollView);
                ContentView.AddSubview (AddressLabel);
                ContentView.AddSubview (AddressTextField);
                ContentView.AddSubview (AddressHelpLabel);
                ContentView.AddSubview (PathLabel);
                ContentView.AddSubview (PathTextField);
                ContentView.AddSubview (PathHelpLabel);
                ContentView.AddSubview (HistoryCheckButton);

                Buttons.Add (AddButton);
                Buttons.Add (CancelButton);

                Controller.CheckAddPage (AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow);
            }

            if (type == PageType.Syncing) {
                Header      = "Adding project ‘" + Controller.SyncingFolder + "’…";
                Description = "This may take a while for large projects.\nIsn’t it coffee-o’clock?";

                ProgressIndicator = new NSProgressIndicator () {
                    Frame         = new RectangleF (190, Frame.Height - 200, 640 - 150 - 80, 20),
                    Style         = NSProgressIndicatorStyle.Bar,
                    MinValue      = 0.0,
                    MaxValue      = 100.0,
                    Indeterminate = false,
                    DoubleValue   = Controller.ProgressBarPercentage
                };

                ProgressIndicator.StartAnimation (this);

                CancelButton = new NSButton () { Title = "Cancel" };

                FinishButton = new NSButton () {
                    Title = "Finish",
                    Enabled = false
                };


                Controller.UpdateProgressBarEvent += delegate (double percentage) {
                    Program.Controller.Invoke (() => {
                        ProgressIndicator.DoubleValue = percentage;
                    });
                };

                CancelButton.Activated += delegate { Controller.SyncingCancelled (); };


                ContentView.AddSubview (ProgressIndicator);

                Buttons.Add (FinishButton);
                Buttons.Add (CancelButton);
            }

            if (type == PageType.Error) {
                Header      = "Oops! Something went wrong…";
                Description = "Please check the following:";

                // Displaying marked up text with Cocoa is
                // a pain, so we just use a webview instead
                WebView web_view = new WebView ();
                web_view.Frame   = new RectangleF (190, Frame.Height - 525, 375, 400);

                string html = "<style>" +
                    "* {" +
                    "  font-family: 'Lucida Grande';" +
                    "  font-size: 12px; cursor: default;" +
                    "}" +
                    "body {" +
                    "  -webkit-user-select: none;" +
                    "  margin: 0;" +
                    "  padding: 3px;" +
                    "}" +
                    "li {" +
                    "  margin-bottom: 16px;" +
                    "  margin-left: 0;" +
                    "  padding-left: 0;" +
                    "  line-height: 20px;" +
                    "  word-wrap: break-word;" +
                    "}" +
                    "ul {" +
                    "  padding-left: 24px;" +
                    "}" +
                    "</style>" +
                    "<ul>" +
                    "  <li><b>" + Controller.PreviousUrl + "</b> is the address we’ve compiled. Does this look alright?</li>" +
                    "  <li>Is this computer’s Client ID known by the host?</li>" +
                    "</ul>";

                if (warnings.Length > 0) {
                    string warnings_markup = "";

                    foreach (string warning in warnings)
                        warnings_markup += "<br><b>" + warning + "</b>";

                    html = html.Replace ("</ul>", "<li>Here’s the raw error message: " + warnings_markup + "</li></ul>");
                }

                web_view.MainFrame.LoadHtmlString (html, new NSUrl (""));
                web_view.DrawsBackground = false;

                CancelButton = new NSButton () { Title = "Cancel" };
                TryAgainButton = new NSButton () { Title = "Try Again…" };


                CancelButton.Activated += delegate { Controller.PageCancelled (); };
                TryAgainButton.Activated += delegate { Controller.ErrorPageCompleted (); };


                ContentView.AddSubview (web_view);

                Buttons.Add (TryAgainButton);
                Buttons.Add (CancelButton);
            }

            if (type == PageType.CryptoSetup || type == PageType.CryptoPassword) {
                if (type == PageType.CryptoSetup) {
                    Header      = "Set up file encryption";
                    Description = "Please a provide a strong password that you don’t use elsewhere.";
                
                } else {
                    Header      = "This project contains encrypted files";
                    Description = "Please enter the password to see their contents.";
                }

                int extra_pos_y = 0;

                if (type == PageType.CryptoPassword)
                    extra_pos_y = 20;
  
                PasswordLabel = new SparkleLabel ("Password:"******"Show password",
                    State = NSCellStateValue.Off
                };

                ShowPasswordCheckButton.SetButtonType (NSButtonType.Switch);

                WarningImage = NSImage.ImageNamed ("NSInfo");
                WarningImage.Size = new SizeF (24, 24);

                WarningImageView = new NSImageView () {
                    Image = WarningImage,
                    Frame = new RectangleF (200, Frame.Height - 320, 24, 24)
                };

                WarningTextField = new SparkleLabel ("This password can’t be changed later, and your files can’t be recovered if it’s forgotten.", NSTextAlignment.Left) {
                    Frame = new RectangleF (235, Frame.Height - 390, 325, 100),
                };

                CancelButton = new NSButton () { Title = "Cancel" };

                ContinueButton = new NSButton () {
                    Title    = "Continue",
                    Enabled  = false
                };


                Controller.UpdateCryptoPasswordContinueButtonEvent += delegate (bool button_enabled) {
                    Program.Controller.Invoke (() => { ContinueButton.Enabled = button_enabled; });
                };

                Controller.UpdateCryptoSetupContinueButtonEvent += delegate (bool button_enabled) {
                    Program.Controller.Invoke (() => { ContinueButton.Enabled = button_enabled; });
                };
                
                ShowPasswordCheckButton.Activated += delegate {
                    if (PasswordTextField.Superview == ContentView) {
                        PasswordTextField.RemoveFromSuperview ();
                        ContentView.AddSubview (VisiblePasswordTextField);

                    } else {
                        VisiblePasswordTextField.RemoveFromSuperview ();
                        ContentView.AddSubview (PasswordTextField);
                    }
                };

                (PasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    VisiblePasswordTextField.StringValue = PasswordTextField.StringValue;

                    if (type == PageType.CryptoSetup)
                        Controller.CheckCryptoSetupPage (PasswordTextField.StringValue);
                    else
                        Controller.CheckCryptoPasswordPage (PasswordTextField.StringValue);
                };

                (VisiblePasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
                    PasswordTextField.StringValue = VisiblePasswordTextField.StringValue;
                    
                    if (type == PageType.CryptoSetup)
                        Controller.CheckCryptoSetupPage (PasswordTextField.StringValue);
                    else
                        Controller.CheckCryptoPasswordPage (PasswordTextField.StringValue);
                };

                ContinueButton.Activated += delegate {
                    if (type == PageType.CryptoSetup)
                        Controller.CryptoSetupPageCompleted (PasswordTextField.StringValue);
                    else
                        Controller.CryptoPasswordPageCompleted (PasswordTextField.StringValue);
                };

                CancelButton.Activated += delegate { Controller.CryptoPageCancelled (); };


                ContentView.AddSubview (PasswordLabel);
                ContentView.AddSubview (PasswordTextField);
                ContentView.AddSubview (ShowPasswordCheckButton);

                if (type == PageType.CryptoSetup) {
                    ContentView.AddSubview (WarningImageView);
                    ContentView.AddSubview (WarningTextField);
                }

                Buttons.Add (ContinueButton);
                Buttons.Add (CancelButton);

                NSApplication.SharedApplication.RequestUserAttention (NSRequestUserAttentionType.CriticalRequest);
            }


            if (type == PageType.Finished) {
                Header      = "Your shared project is ready!";
                Description = "You can find the files in your SparkleShare folder.";

                if (warnings.Length > 0) {
                    WarningImage = NSImage.ImageNamed ("NSInfo");
                    WarningImage.Size = new SizeF (24, 24);

                    WarningImageView = new NSImageView () {
                        Image = WarningImage,
                        Frame = new RectangleF (200, Frame.Height - 175, 24, 24)
                    };

                    WarningTextField = new SparkleLabel (warnings [0], NSTextAlignment.Left);
                    WarningTextField.Frame       = new RectangleF (235, Frame.Height - 245, 325, 100);

                    ContentView.AddSubview (WarningImageView);
                    ContentView.AddSubview (WarningTextField);
                }

                ShowFilesButton = new NSButton () { Title = "Show Files…" };
                FinishButton    = new NSButton () { Title = "Finish" };


                ShowFilesButton.Activated += delegate { Controller.ShowFilesClicked (); };
                FinishButton.Activated += delegate { Controller.FinishPageCompleted (); };


                Buttons.Add (FinishButton);
                Buttons.Add (ShowFilesButton);

                NSApplication.SharedApplication.RequestUserAttention (NSRequestUserAttentionType.CriticalRequest);
            }

            if (type == PageType.Tutorial) {
                SlideImage = NSImage.ImageNamed ("tutorial-slide-" + Controller.TutorialPageNumber);
                if (SlideImage != null) {
                    SlideImage.Size = new SizeF (324, 200);

                    SlideImageView = new NSImageView () {
                        Image = SlideImage,
                        Frame = new RectangleF (228, Frame.Height - 350, 324, 200)
                    };

                    ContentView.AddSubview (SlideImageView);
                }

                switch (Controller.TutorialPageNumber) {
                    case 1: {
                        Header      = "What’s happening next?";
                        Description = "SparkleShare creates a special folder on your computer " +
                            "that will keep track of your projects.";

                        SkipTutorialButton = new NSButton () { Title = "Skip Tutorial" };
                        ContinueButton     = new NSButton () { Title = "Continue" };


                        SkipTutorialButton.Activated += delegate { Controller.TutorialSkipped (); };
                        ContinueButton.Activated     += delegate { Controller.TutorialPageCompleted (); };


                        ContentView.AddSubview (SlideImageView);

                        Buttons.Add (ContinueButton);
                        Buttons.Add (SkipTutorialButton);

                        break;
                    }

                    case 2: {
                        Header      = "Sharing files with others";
                        Description = "All files added to your project folders are synced automatically with " +
                            "the host and your team members.";

                        ContinueButton = new NSButton () { Title = "Continue" };
                        ContinueButton.Activated += delegate { Controller.TutorialPageCompleted (); };
                        Buttons.Add (ContinueButton);

                        break;
                    }

                    case 3: {
                        Header      = "The status icon helps you";
                        Description = "It shows the syncing progress, provides easy access to " +
                            "your projects, and lets you view recent changes.";

                        ContinueButton = new NSButton () { Title = "Continue" };
                        ContinueButton.Activated += delegate { Controller.TutorialPageCompleted (); };
                        Buttons.Add (ContinueButton);

                        break;
                    }

                    case 4: {
                        Header      = "Here’s your unique Client ID";
                        Description = "You’ll need it whenever you want to link this computer to a host. " +
                            "You can also find it in the status icon menu.";

                        LinkCodeTextField = new NSTextField () {
                            StringValue = Program.Controller.CurrentUser.PublicKey,
                            Enabled     = false,
                            Selectable  = false,
                            Frame       = new RectangleF (230, Frame.Height - 238, 246, 22)
                        };

                        LinkCodeTextField.Cell.UsesSingleLineMode = true;
                        LinkCodeTextField.Cell.LineBreakMode      = NSLineBreakMode.TruncatingTail;
                        
                        CopyButton = new NSButton () {
                            Title      = "Copy",
                            BezelStyle = NSBezelStyle.RoundRect,
                            Frame      = new RectangleF (480, Frame.Height - 238, 60, 22)
                        };
                        
                        StartupCheckButton = new NSButton () {
                            Frame = new RectangleF (190, Frame.Height - 400, 300, 18),
                            Title = "Add SparkleShare to startup items",
                            State = NSCellStateValue.On
                        };

                        StartupCheckButton.SetButtonType (NSButtonType.Switch);

                        FinishButton = new NSButton () { Title = "Finish" };


                        StartupCheckButton.Activated += delegate {
                            Controller.StartupItemChanged (StartupCheckButton.State == NSCellStateValue.On);
                        };

                        CopyButton.Activated += delegate { Controller.CopyToClipboardClicked (); };
                        FinishButton.Activated += delegate { Controller.TutorialPageCompleted (); };


                        ContentView.AddSubview (LinkCodeTextField);
                        ContentView.AddSubview (CopyButton);
                        ContentView.AddSubview (StartupCheckButton);

                        Buttons.Add (FinishButton);

                        break;
                    }
                }
            }
        }
Esempio n. 44
0
        void InvokeWithProgress(Action <ProgressContext, Action <string, ProgressContext> > action, NSProgressIndicator indicator)
        {
            ProgressContext progress = new ProgressContext();

            progress.Progressing += (sender, eventArgs) => {
                if (eventArgs.Percent < 100)
                {
                    indicator.StartAnimation(this);
                }
                else
                {
                    indicator.StopAnimation(this);
                }
            };
            action(progress, (message, context) => InvokeOnMainThread((NSAction) delegate {
                indicator.StopAnimation(this);
                AppController.OperationFailureHandler(message, context);
            }));
        }
Esempio n. 45
0
        public SparkleEventLog()
            : base()
        {
            using (var a = new NSAutoreleasePool ())
            {
                Title    = "Recent Changes";
                Delegate = new SparkleEventsDelegate ();

                int min_width  = 480;
                int min_height = 640;
                float x    = (float) (NSScreen.MainScreen.Frame.Width * 0.61);
                float y    = (float) (NSScreen.MainScreen.Frame.Height * 0.5 - (min_height * 0.5));

                SetFrame (
                    new RectangleF (
                        new PointF (x, y),
                        new SizeF (min_width, (int) (NSScreen.MainScreen.Frame.Height * 0.85))),
                    true);

                StyleMask = (NSWindowStyle.Closable |
                             NSWindowStyle.Miniaturizable |
                             NSWindowStyle.Titled |
                             NSWindowStyle.Resizable);

                MinSize        = new SizeF (min_width, min_height);
                HasShadow      = true;
                BackingType    = NSBackingStore.Buffered;
                TitlebarHeight = Frame.Height - ContentView.Frame.Height;

                this.web_view = new WebView (new RectangleF (0, 0, 481, 579), "", "") {
                    PolicyDelegate = new SparkleWebPolicyDelegate (),
                    Frame = new RectangleF (new PointF (0, 0),
                        new SizeF (ContentView.Frame.Width, ContentView.Frame.Height - 39))
                };

                this.hidden_close_button = new NSButton () {
                    KeyEquivalentModifierMask = NSEventModifierMask.CommandKeyMask,
                    KeyEquivalent = "w"
                };

                this.hidden_close_button.Activated += delegate {
                    Controller.WindowClosed ();
                };

                this.size_label = new NSTextField () {
                    Alignment       = NSTextAlignment.Right,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (
                        new PointF (0, ContentView.Frame.Height - 30),
                        new SizeF (60, 20)),
                    StringValue     = "Size:",
                    Font            = SparkleUI.BoldFont
                };

                this.size_label_value = new NSTextField () {
                    Alignment       = NSTextAlignment.Left,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (
                        new PointF (60, ContentView.Frame.Height - 30),
                        new SizeF (60, 20)),
                    StringValue     = "…",
                    Font            = SparkleUI.Font
                };

                this.history_label = new NSTextField () {
                    Alignment       = NSTextAlignment.Right,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (
                        new PointF (130, ContentView.Frame.Height - 30),
                        new SizeF (60, 20)),
                    StringValue     = "History:",
                    Font            = SparkleUI.BoldFont
                };

                this.history_label_value = new NSTextField () {
                    Alignment       = NSTextAlignment.Left,
                    BackgroundColor = NSColor.WindowBackground,
                    Bordered        = false,
                    Editable        = false,
                    Frame           = new RectangleF (
                        new PointF (190, ContentView.Frame.Height - 30),
                        new SizeF (60, 20)
                    ),
                    StringValue     = "…",
                    Font            = SparkleUI.Font
                };

                this.popup_button = new NSPopUpButton () {
                    Frame = new RectangleF (
                        new PointF (ContentView.Frame.Width - 156 - 12, ContentView.Frame.Height - 33),
                        new SizeF (156, 26)),
                    PullsDown = false
                };

                this.background = new NSBox () {
                    Frame = new RectangleF (
                        new PointF (-1, -1),
                        new SizeF (Frame.Width + 2, this.web_view.Frame.Height + 2)),
                    FillColor = NSColor.White,
                    BorderColor = NSColor.LightGray,
                    BoxType = NSBoxType.NSBoxCustom
                };

                this.progress_indicator = new NSProgressIndicator () {
                    Frame = new RectangleF (
                        new PointF (Frame.Width / 2 - 10, this.web_view.Frame.Height / 2 + 10),
                        new SizeF (20, 20)),
                    Style = NSProgressIndicatorStyle.Spinning
                };

                this.progress_indicator.StartAnimation (this);

                ContentView.AddSubview (this.size_label);
                ContentView.AddSubview (this.size_label_value);
                ContentView.AddSubview (this.history_label);
                ContentView.AddSubview (this.history_label_value);
                ContentView.AddSubview (this.popup_button);
                ContentView.AddSubview (this.progress_indicator);
                ContentView.AddSubview (this.background);
                ContentView.AddSubview (this.hidden_close_button);

                (this.web_view.PolicyDelegate as SparkleWebPolicyDelegate).LinkClicked += delegate (string href) {
                    Controller.LinkClicked (href);
                };

                (Delegate as SparkleEventsDelegate).WindowResized += Relayout;
            }

            // Hook up the controller events
            Controller.HideWindowEvent += delegate {
                using (var a = new NSAutoreleasePool ())
                {
                    InvokeOnMainThread (delegate {
                        PerformClose (this);

                        if (this.web_view.Superview == ContentView)
                            this.web_view.RemoveFromSuperview ();
                    });
                }
            };

            Controller.ShowWindowEvent += delegate {
                using (var a = new NSAutoreleasePool ())
                {
                    InvokeOnMainThread (delegate {
                        OrderFrontRegardless ();
                    });
                }
            };

            Controller.UpdateChooserEvent += delegate (string [] folders) {
                using (var a = new NSAutoreleasePool ())
                {
                    InvokeOnMainThread (delegate {
                        UpdateChooser (folders);
                    });
                }
            };

            Controller.UpdateContentEvent += delegate (string html) {
                using (var a = new NSAutoreleasePool ())
                {
                    InvokeOnMainThread (delegate {
                        UpdateContent (html);
                    });
                }
            };

            Controller.ContentLoadingEvent += delegate {
                using (var a = new NSAutoreleasePool ())
                {
                    InvokeOnMainThread (delegate {
                        if (this.web_view.Superview == ContentView)
                            this.web_view.RemoveFromSuperview ();

                        ContentView.AddSubview (this.progress_indicator);
                    });
                }
            };

            Controller.UpdateSizeInfoEvent += delegate (string size, string history_size) {
                using (var a = new NSAutoreleasePool ())
                {
                    InvokeOnMainThread (delegate {
                        this.size_label_value.StringValue    = size;
                        this.history_label_value.StringValue = history_size;
                    });
                }
            };
        }
Esempio n. 46
0
        private void CreateEventLog()
        {
            OpenFolderButton = new NSButton (new RectangleF (16, 12, 120, 32)) {
                Title = "Open Folder",
                BezelStyle = NSBezelStyle.Rounded   ,
                Font = SparkleUI.Font
            };

                OpenFolderButton.Activated += delegate {
                    SparkleShare.Controller.OpenSparkleShareFolder (LocalPath);
                };

            ContentView.AddSubview (OpenFolderButton);

            CloseButton = new NSButton (new RectangleF (480 - 120 - 16, 12, 120, 32)) {
                Title = "Close",
                BezelStyle = NSBezelStyle.Rounded,
                Font = SparkleUI.Font
            };

                CloseButton.Activated += delegate {
                    InvokeOnMainThread (delegate {
                        PerformClose (this);
                    });
                };

            ContentView.AddSubview (CloseButton);

            string name = Path.GetFileName (LocalPath);
            Title = String.Format ("Events in ‘{0}’", name);

            Separator = new NSBox (new RectangleF (0, 58, 480, 1)) {
                BorderColor = NSColor.LightGray,
                BoxType = NSBoxType.NSBoxCustom
            };

            ContentView.AddSubview (Separator);

            ProgressIndicator = new NSProgressIndicator () {
                Style = NSProgressIndicatorStyle.Spinning,
                Frame = new RectangleF (Frame.Width / 2 - 10, Frame.Height / 2 + 10, 20, 20)
            };

            ProgressIndicator.StartAnimation (this);

            WebView = new WebView (new RectangleF (0, 59, 480, 559), "", ""){
                PolicyDelegate = new SparkleWebPolicyDelegate ()
            };

            Update ();
        }
Esempio n. 47
0
        /*
        void ShowFolderSeletionPage()
        {
            Header = Properties_Resources.Which;
            Description = "";
            bool firstRepo = true;
            Repositories = new List<RootFolder>();
            Loader = new Dictionary<string,AsyncNodeLoader> ();
            foreach (KeyValuePair<String, String> repository in Controller.repositories)
            {
                RootFolder repo = new RootFolder() {
                    Name = repository.Value,
                    Id = repository.Key,
                    Address = Controller.saved_address.ToString()
                };
                Repositories.Add(repo);
                if (firstRepo)
                {
                    repo.Selected = true;
                    firstRepo = false;
                }
                else
                {
                    repo.Selected = false;
                }
                CmisRepoCredentials cred = new CmisRepoCredentials()
                {
                    UserName = Controller.saved_user,
                    Password = Controller.saved_password,
                    Address = Controller.saved_address,
                    RepoId = repository.Key
                };
                AsyncNodeLoader asyncLoader = new AsyncNodeLoader(repo, cred, PredefinedNodeLoader.LoadSubFolderDelegate, PredefinedNodeLoader.CheckSubFolderDelegate);
                asyncLoader.UpdateNodeEvent += delegate {
                    InvokeOnMainThread(delegate {
                        DataSource.UpdateCmisTree(repo);
                        NSOutlineView view = OutlineController.OutlineView();
                        for (int i = 0; i < view.RowCount; ++i) {
                            view.ReloadItem(view.ItemAtRow(i));
                        }
                    });
                };
                asyncLoader.Load(repo);
                Loader.Add(repo.Id, asyncLoader);
            }
            DataSource = new CmisTree.CmisTreeDataSource(Repositories);
            DataSource.SelectedEvent += delegate (NSCmisTree cmis, int selected) {
                InvokeOnMainThread(delegate {
                    RootFolder selectedRoot = null;
                    foreach (RootFolder root in Repositories) {
                        Node node = cmis.GetNode(root);
                        if (node != null) {
                            if (node.Parent == null && node.Selected == false) {
                                selectedRoot = root;
                            }
                            node.Selected = (selected != 0);
                            DataSource.UpdateCmisTree(root);
                        }
                    }

                    NSOutlineView view = OutlineController.OutlineView();
                    if (selectedRoot != null) {
                        foreach (RootFolder root in Repositories) {
                            if (root != selectedRoot) {
                                root.Selected = false;
                                DataSource.UpdateCmisTree(root);
                            }
                        }
                        view.ReloadData();
                    } else {
                        for (int i = 0; i < view.RowCount; ++i) {
                            view.ReloadItem(view.ItemAtRow(i));
                        }
                    }
                });
            };
            DataDelegate = new OutlineViewDelegate ();
            OutlineController = new CmisOutlineController (DataSource,DataDelegate);
            ContinueButton = new NSButton() {
                Title = Properties_Resources.Continue,
                Enabled = (Repositories.Count > 0)
            };
            CancelButton = new NSButton() {
                Title = Properties_Resources.Cancel
            };
            NSButton BackButton = new NSButton() {
                Title = Properties_Resources.Back
            };
//            DataDelegate.SelectionChanged += delegate
//            {
//                InvokeOnMainThread(delegate {
//                    NSOutlineView view = OutlineController.OutlineView();
//                    if (view.SelectedRow >= 0) {
//                        ContinueButton.Enabled = true;
//                    } else {
//                        ContinueButton.Enabled = false;
//                    }
//                });
//            };
            DataDelegate.ItemExpanded += delegate(NSNotification notification)
            {
                InvokeOnMainThread(delegate {
                    NSCmisTree cmis = notification.UserInfo["NSObject"] as NSCmisTree;
                    if (cmis == null) {
                        Console.WriteLine("ItemExpanded Error");
                        return;
                    }

                    NSCmisTree cmisRoot = cmis;
                    while (cmisRoot.Parent != null) {
                        cmisRoot = cmisRoot.Parent;
                    }
                    RootFolder root = Repositories.Find(x=>x.Name.Equals(cmisRoot.Name));
                    if (root == null) {
                        Console.WriteLine("ItemExpanded find root Error");
                        return;
                    }

                    Node node = cmis.GetNode(root);
                    if (node == null) {
                        Console.WriteLine("ItemExpanded find node Error");
                        return;
                    }
                    Loader[root.Id].Load(node);
                });
            };
            ContinueButton.Activated += delegate
            {
                InvokeOnMainThread(delegate {
                    NSOutlineView view = OutlineController.OutlineView();
//                    NSCmisTree cmis = (NSCmisTree)(view.ItemAtRow(view.SelectedRow));
//                    while (cmis.Parent != null)
//                        cmis = cmis.Parent;
//                    RootFolder root = Repositories.Find(x=>x.Name.Equals(cmis.Name));
                    RootFolder root = Repositories.Find(x=>(x.Selected != false));
                    if (root != null)
                    {
                        foreach (AsyncNodeLoader task in Loader.Values)
                            task.Cancel();
                        Controller.saved_repository = root.Id;
                        List<string> ignored = NodeModelUtils.GetIgnoredFolder(root);
                        List<string> selected = NodeModelUtils.GetSelectedFolder(root);
                        Controller.Add2PageCompleted(root.Id, root.Path, ignored.ToArray(), selected.ToArray());
                    }
                });
            };
            CancelButton.Activated += delegate
            {
                InvokeOnMainThread(delegate
                {
                    foreach (AsyncNodeLoader task in Loader.Values)
                        task.Cancel();
                    Controller.PageCancelled();
                });
            };
            BackButton.Activated += delegate
            {
                InvokeOnMainThread(delegate
                {
                    foreach (AsyncNodeLoader task in Loader.Values)
                        task.Cancel();
                    Controller.BackToPage1();
                });
            };

            OutlineController.View.Frame = new RectangleF (190, 60, 400, 240);
            ContentView.AddSubview(OutlineController.View);
            Buttons.Add(ContinueButton);
            Buttons.Add(BackButton);
            Buttons.Add(CancelButton);
        } */

        void ShowSyncingPage()
        {
            Header = Properties_Resources.AddingFolder + " ‘" + Controller.SyncingReponame + "’…";
            Description = Properties_Resources.MayTakeTime;
            ProgressIndicator = new NSProgressIndicator() {
                Frame = new RectangleF(190, Frame.Height - 200, 640 - 150 - 80, 20),
                Style = NSProgressIndicatorStyle.Bar,
                MinValue = 0.0,
                MaxValue = 100.0,
                Indeterminate = false,
                DoubleValue = Controller.ProgressBarPercentage
            };
            ProgressIndicator.StartAnimation(this);
            ContentView.AddSubview(ProgressIndicator);
        }
Esempio n. 48
0
        NSView BuildComponents()
        {
            NSView result = new NSView();

            NSButton browseButton = new NSButton();

            browseButton.Title      = "Browse...";
            browseButton.BezelStyle = NSBezelStyle.Rounded;
            browseButton.Activated += BrowseButton_Activated;

            NSButton oneToOneButton = new NSButton();

            oneToOneButton.Title      = "Zoom 1 to 1";
            oneToOneButton.BezelStyle = NSBezelStyle.Rounded;
            oneToOneButton.Activated += OneToOneButton_Activated;

            NSButton fitButton = new NSButton();

            fitButton.Title      = "Zoom to fit";
            fitButton.BezelStyle = NSBezelStyle.Rounded;
            fitButton.Activated += FitButton_Activated;

            NSButton zoomOutButton = new NSButton();

            zoomOutButton.Title      = "Zoom out";
            zoomOutButton.Image      = NSImage.ImageNamed(NSImageName.RemoveTemplate);
            zoomOutButton.BezelStyle = NSBezelStyle.Rounded;
            zoomOutButton.Activated += ZoomOutButton_Activated;

            NSButton zoomInButton = new NSButton();

            zoomInButton.Title      = "Zoom in";
            zoomInButton.Image      = NSImage.ImageNamed(NSImageName.AddTemplate);
            zoomInButton.BezelStyle = NSBezelStyle.Rounded;
            zoomInButton.Activated += ZoomInButton_Activated;

            mImageDiffView = new ImageContentView();

            mSpinner             = new NSProgressIndicator();
            mSpinner.Style       = NSProgressIndicatorStyle.Spinning;
            mSpinner.ControlSize = NSControlSize.Small;
            mSpinner.Hidden      = true;

            ControlPacker.AddControls(
                result, new string[] {
                "H:|-20-[browseButton]-5-[oneToOneButton]-5-[fitButton]-5-[zoomOutButton]-5-[zoomInButton]-8-[spinner(16)]",
                "H:|-20-[imageView]-20-|",
                "V:|-20-[browseButton]-10-[imageView]-20-|",
                "V:|-20-[oneToOneButton]",
                "V:|-20-[fitButton]",
                "V:|-20-[zoomOutButton]",
                "V:|-20-[zoomInButton]",
                "V:|-23-[spinner(16)]"
            },
                new NSDictionary(
                    "browseButton", browseButton,
                    "oneToOneButton", oneToOneButton,
                    "fitButton", fitButton,
                    "zoomOutButton", zoomOutButton,
                    "zoomInButton", zoomInButton,
                    "imageView", mImageDiffView,
                    "spinner", mSpinner));

            return(result);
        }
Esempio n. 49
0
        public ProgressDialog(ProgressDialogConfig config)
        {
            this.config     = config;
            this.title      = config.Title;
            this.mainWindow = NSApplication.SharedApplication.KeyWindow;

            progressPanel = new NSPanel(new CGRect(0, 0, 100, 140), NSWindowStyle.DocModal, NSBackingStore.Buffered, true)
            {
                BackgroundColor = NSColor.White
            };

            var view = new NSView();

            txtTitle = new NSTextField
            {
                Editable  = false,
                Hidden    = string.IsNullOrEmpty(this.title),
                Alignment = NSTextAlignment.Center
            };

            progressIndicator = new NSProgressIndicator
            {
                Style         = NSProgressIndicatorStyle.Spinning,
                Indeterminate = !config.IsDeterministic,
                MinValue      = 0,
                DoubleValue   = 0,
                MaxValue      = 100
            };

            view.AggregateSubviews(txtTitle, progressIndicator);

            NSButton cancelButton = null;

            if (config.OnCancel != null)
            {
                cancelButton = new NSButton
                {
                    Title = config.CancelText
                };
                cancelButton.Activated += (sender, e) =>
                {
                    Hide(true);
                };

                view.AggregateSubviews(cancelButton);
            }

            txtTitle.TopAnchor.ConstraintEqualToAnchor(view.TopAnchor).Active           = true;
            txtTitle.LeadingAnchor.ConstraintEqualToAnchor(view.LeadingAnchor).Active   = true;
            txtTitle.TrailingAnchor.ConstraintEqualToAnchor(view.TrailingAnchor).Active = true;

            progressIndicator.TopAnchor.ConstraintEqualToAnchor(txtTitle.BottomAnchor, 2).Active = true;
            progressIndicator.LeadingAnchor.ConstraintEqualToAnchor(view.LeadingAnchor).Active   = true;
            progressIndicator.TrailingAnchor.ConstraintEqualToAnchor(view.TrailingAnchor).Active = true;
            progressIndicator.HeightAnchor.ConstraintEqualToConstant(100).Active = true;
            progressIndicator.WidthAnchor.ConstraintEqualToConstant(100).Active  = true;

            if (cancelButton == null)
            {
                progressIndicator.BottomAnchor.ConstraintLessThanOrEqualToAnchor(view.BottomAnchor).Active = true;
            }
            else
            {
                cancelButton.TopAnchor.ConstraintEqualToAnchor(progressIndicator.BottomAnchor, 2).Active = true;
                cancelButton.CenterXAnchor.ConstraintEqualToAnchor(view.CenterXAnchor).Active            = true;
                cancelButton.BottomAnchor.ConstraintLessThanOrEqualToAnchor(view.BottomAnchor).Active    = true;
            }

            progressPanel.ContentView = view;
        }
Esempio n. 50
0
        public SparkleEventLog() : base()
        {
            Title    = "Recent Changes";
            Delegate = new SparkleEventsDelegate();

            int min_width  = 480;
            int min_height = 640;
            int height     = (int)(NSScreen.MainScreen.Frame.Height * 0.85);

            float x = (float)(NSScreen.MainScreen.Frame.Width * 0.61);
            float y = (float)(NSScreen.MainScreen.Frame.Height * 0.5 - (height * 0.5));

            SetFrame(
                new RectangleF(
                    new PointF(x, y),
                    new SizeF(min_width, height)),
                true);

            StyleMask = (NSWindowStyle.Closable | NSWindowStyle.Miniaturizable |
                         NSWindowStyle.Titled | NSWindowStyle.Resizable);

            MinSize        = new SizeF(min_width, min_height);
            HasShadow      = true;
            BackingType    = NSBackingStore.Buffered;
            TitlebarHeight = Frame.Height - ContentView.Frame.Height;
            Level          = NSWindowLevel.Floating;


            this.web_view = new WebView(new RectangleF(0, 0, 481, 579), "", "")
            {
                Frame = new RectangleF(new PointF(0, 0),
                                       new SizeF(ContentView.Frame.Width, ContentView.Frame.Height - 39))
            };

            this.web_view.Preferences.PlugInsEnabled = false;

            this.cover = new NSBox()
            {
                Frame = new RectangleF(
                    new PointF(-1, -1),
                    new SizeF(Frame.Width + 2, this.web_view.Frame.Height + 1)),
                FillColor  = NSColor.White,
                BorderType = NSBorderType.NoBorder,
                BoxType    = NSBoxType.NSBoxCustom
            };

            this.hidden_close_button = new NSButton()
            {
                KeyEquivalentModifierMask = NSEventModifierMask.CommandKeyMask,
                KeyEquivalent             = "w"
            };

            this.hidden_close_button.Activated += delegate {
                Controller.WindowClosed();
            };


            this.size_label = new NSTextField()
            {
                Alignment       = NSTextAlignment.Right,
                BackgroundColor = NSColor.WindowBackground,
                Bordered        = false,
                Editable        = false,
                Frame           = new RectangleF(
                    new PointF(0, ContentView.Frame.Height - 31),
                    new SizeF(60, 20)),
                StringValue = "Size:"
            };

            this.size_label_value = new NSTextField()
            {
                Alignment       = NSTextAlignment.Left,
                BackgroundColor = NSColor.WindowBackground,
                Bordered        = false,
                Editable        = false,
                Frame           = new RectangleF(
                    new PointF(60, ContentView.Frame.Height - 27),
                    new SizeF(60, 20)),
                StringValue = "…",
                Font        = NSFont.FromFontName(SparkleUI.FontName + " Bold", NSFont.SystemFontSize)
            };


            this.history_label = new NSTextField()
            {
                Alignment       = NSTextAlignment.Right,
                BackgroundColor = NSColor.WindowBackground,
                Bordered        = false,
                Editable        = false,
                Frame           = new RectangleF(
                    new PointF(130, ContentView.Frame.Height - 31),
                    new SizeF(60, 20)),
                StringValue = "History:"
            };

            this.history_label_value = new NSTextField()
            {
                Alignment       = NSTextAlignment.Left,
                BackgroundColor = NSColor.WindowBackground,
                Bordered        = false,
                Editable        = false,
                Frame           = new RectangleF(
                    new PointF(190, ContentView.Frame.Height - 27),
                    new SizeF(60, 20)
                    ),
                StringValue = "…",
                Font        = NSFont.FromFontName(SparkleUI.FontName + " Bold", NSFont.SystemFontSize)
            };

            this.popup_button = new NSPopUpButton()
            {
                Frame = new RectangleF(
                    new PointF(ContentView.Frame.Width - 156 - 12, ContentView.Frame.Height - 33),
                    new SizeF(156, 26)),
                PullsDown = false
            };

            this.background = new NSBox()
            {
                Frame = new RectangleF(
                    new PointF(-1, -1),
                    new SizeF(Frame.Width + 2, this.web_view.Frame.Height + 2)),
                FillColor   = NSColor.White,
                BorderColor = NSColor.LightGray,
                BoxType     = NSBoxType.NSBoxCustom
            };

            this.progress_indicator = new NSProgressIndicator()
            {
                Frame = new RectangleF(
                    new PointF(Frame.Width / 2 - 10, this.web_view.Frame.Height / 2 + 10),
                    new SizeF(20, 20)),
                Style = NSProgressIndicatorStyle.Spinning
            };

            this.progress_indicator.StartAnimation(this);

            ContentView.AddSubview(this.size_label);
            ContentView.AddSubview(this.size_label_value);
            ContentView.AddSubview(this.history_label);
            ContentView.AddSubview(this.history_label_value);
            ContentView.AddSubview(this.popup_button);
            ContentView.AddSubview(this.progress_indicator);
            ContentView.AddSubview(this.background);
            ContentView.AddSubview(this.hidden_close_button);

            (Delegate as SparkleEventsDelegate).WindowResized += delegate(SizeF new_window_size) {
                Program.Controller.Invoke(() => Relayout(new_window_size));
            };


            // Hook up the controller events
            Controller.HideWindowEvent += delegate {
                Program.Controller.Invoke(() => {
                    this.progress_indicator.Hidden = true;
                    PerformClose(this);
                });
            };

            Controller.ShowWindowEvent += delegate {
                Program.Controller.Invoke(() => OrderFrontRegardless());
            };

            Controller.UpdateChooserEvent += delegate(string [] folders) {
                Program.Controller.Invoke(() => UpdateChooser(folders));
            };

            Controller.UpdateChooserEnablementEvent += delegate(bool enabled) {
                Program.Controller.Invoke(() => { this.popup_button.Enabled = enabled; });
            };

            Controller.UpdateContentEvent += delegate(string html) {
                Program.Controller.Invoke(() => {
                    this.cover.RemoveFromSuperview();
                    this.progress_indicator.Hidden = true;
                    UpdateContent(html);
                });
            };

            Controller.ContentLoadingEvent += delegate {
                Program.Controller.Invoke(() => {
                    this.web_view.RemoveFromSuperview();
                    // FIXME: Hack to hide that the WebView sometimes doesn't disappear
                    ContentView.AddSubview(this.cover);
                    this.progress_indicator.Hidden = false;
                    this.progress_indicator.StartAnimation(this);
                });
            };

            Controller.UpdateSizeInfoEvent += delegate(string size, string history_size) {
                Program.Controller.Invoke(() => {
                    this.size_label_value.StringValue    = size;
                    this.history_label_value.StringValue = history_size;
                });
            };

            Controller.ShowSaveDialogEvent += delegate(string file_name, string target_folder_path) {
                Program.Controller.Invoke(() => {
                    NSSavePanel panel = new NSSavePanel()
                    {
                        DirectoryUrl         = new NSUrl(target_folder_path, true),
                        NameFieldStringValue = file_name,
                        ParentWindow         = this,
                        Title = "Restore from History",
                        PreventsApplicationTerminationWhenModal = false
                    };

                    if ((NSPanelButtonType)panel.RunModal() == NSPanelButtonType.Ok)
                    {
                        string target_file_path = Path.Combine(panel.DirectoryUrl.RelativePath, panel.NameFieldStringValue);
                        Controller.SaveDialogCompleted(target_file_path);
                    }
                    else
                    {
                        Controller.SaveDialogCancelled();
                    }
                });
            };
        }