Example #1
0
 private void TextBox_To_Btn(System.Windows.Controls.TextBox txt_from, System.Windows.Controls.Button btn_to)
 {
     txt_from.IsEnabled  = false;
     txt_from.Background = System.Windows.Media.Brushes.White;
     btn_to.IsEnabled    = true;
     btn_to.Focus();
 }
        public override void OnApplyTemplate()
        {
            FloatingWindow parent = this.Parent as FloatingWindow;
            if (parent != null)
            {
                parent.KeyDown -= MessageBoxDialogParent_KeyDown;
            }

            if (btnOK != null)
                btnOK.Click -= button_Click;

            if (btnCancel != null)
                btnCancel.Click -= button_Click;

            base.OnApplyTemplate();

            btnOK = GetTemplateChild(OK_BUTTON_NAME) as Button;
            if (btnOK != null)
            {
                btnOK.Click += button_Click;
                btnOK.Focus();
            }
            btnCancel = GetTemplateChild(CANCEL_BUTTON_NAME) as Button;
            if (btnCancel != null)
                btnCancel.Click += button_Click;

            parent = this.Parent as FloatingWindow;
            if (parent != null)
            {
                parent.KeyDown -= MessageBoxDialogParent_KeyDown;
                parent.KeyDown += MessageBoxDialogParent_KeyDown;
            }
        }
        /// <summary>
        /// Layout all the buttons.
        /// </summary>
        private void _AddButtons()
        {
            Hashtable _buttonsTable = new Hashtable();

            foreach (MessageBoxExButton button in _buttons)
            {
                if (!_buttonsTable.ContainsKey(button))
                {
                    SysControls.Button buttonCtrl = _CreateButton(button);

                    // Move keyboard focus to "Yes" or "Ok" button.
                    if (button.Value == MessageBoxExButtonType.Ok ||
                        button.Value == MessageBoxExButtonType.Yes)
                    {
                        buttonCtrl.Focus();
                    }

                    _buttonsTable[button] = buttonCtrl;
                    _buttonsWrapPanel.Children.Add(buttonCtrl);
                }
            }
        }
        private void LoadControl(Button actionButton)
        {
            if (_currentButton != null)
                _currentButton.FontWeight = FontWeights.Normal;
            _currentButton = actionButton;
            _currentButton.FontWeight = FontWeights.Bold;

            SetDefaultAlignments();

            actionButton.Focus();

            object uc = _navButtonRegistry[actionButton];

            // Convert from a Type to an instance of the type
            if (!(uc is UserControl))
            {
                uc = (UserControl) Activator.CreateInstance((Type) uc);
                _navButtonRegistry[actionButton] = uc;
            }

            contentMain.Content = uc;

            var configUserControl = ((ActionUserControl) uc);
            MyViewModel.ConfigTitle = configUserControl.ConfigTitle;

            DoApplyChanges(false);
        }
Example #5
0
        public SparkleSetup()
        {
            Controller.ShowWindowEvent += delegate {
               Dispatcher.BeginInvoke ((Action) delegate {
                    Show ();
                    Activate ();
                    BringIntoView ();
                });
            };

            Controller.HideWindowEvent += delegate {
                Dispatcher.BeginInvoke ((Action) delegate {
                    Hide ();
                });
            };

            Controller.ChangePageEvent += delegate (PageType type, string [] warnings) {
                Dispatcher.BeginInvoke ((Action) delegate {
                    Reset ();

                    switch (type) {
                    case PageType.Setup: {
                        Header      = "Welcome to CmisSync!";
                        Description = "CmisSync allows you to keep in sync with any CMIS-compatible repository, and use your documents even when offline.\nIt is like Dropbox for Enterprise Content Management!\nAvailable for Linux, Mac, Windows.";

                        Button cancel_button = new Button () {
                            Content = "Cancel"
                        };

                        Button continue_button = new Button () {
                            Content = "Continue",
                            IsEnabled = false
                        };

                        Buttons.Add (continue_button);
                        Buttons.Add (cancel_button);

                        continue_button.Focus();

                        Controller.UpdateSetupContinueButtonEvent += delegate (bool enabled) {
                            Dispatcher.BeginInvoke ((Action) delegate {
                                continue_button.IsEnabled = enabled;
                            });
                        };

                        cancel_button.Click += delegate {
                            Dispatcher.BeginInvoke ((Action) delegate {
                                Program.UI.StatusIcon.Dispose ();
                                Controller.SetupPageCancelled ();
                            });
                        };

                        continue_button.Click += delegate {
                            Controller.SetupPageCompleted ();
                        };

                        Controller.CheckSetupPage ();

                        break;
                    }

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

                        TextBlock address_label = new TextBlock () {
                            Text = "Address:",
                            Width = 150,
                            TextAlignment = TextAlignment.Right
                        };

                        TextBlock address_value = new TextBlock () {
                            Text  = Controller.PendingInvite.Address,
                            Width = 175,
                            FontWeight = FontWeights.Bold
                        };

                        TextBlock path_label = new TextBlock () {
                            Text  = "Remote Path:",
                            Width = 150,
                            TextAlignment = TextAlignment.Right
                        };

                        TextBlock path_value = new TextBlock () {
                            Width = 175,
                            Text = Controller.PendingInvite.RemotePath,
                            FontWeight = FontWeights.Bold
                        };

                        Button cancel_button = new Button () {
                            Content = "Cancel"
                        };

                        Button add_button = new Button () {
                            Content = "Add"
                        };

                        ContentCanvas.Children.Add (address_label);
                        Canvas.SetLeft (address_label, 180);
                        Canvas.SetTop (address_label, 200);

                        ContentCanvas.Children.Add (address_value);
                        Canvas.SetLeft (address_value, 340);
                        Canvas.SetTop (address_value, 200);

                        ContentCanvas.Children.Add (path_label);
                        Canvas.SetLeft (path_label, 180);
                        Canvas.SetTop (path_label, 225);

                        ContentCanvas.Children.Add (path_value);
                        Canvas.SetLeft (path_value, 340);
                        Canvas.SetTop (path_value, 225);

                        Buttons.Add (add_button);
                        Buttons.Add (cancel_button);

                        cancel_button.Click += delegate {
                            Controller.PageCancelled ();
                        };

                        add_button.Click += delegate {
                            Controller.InvitePageCompleted ();
                        };

                        break;
                    }

                    case PageType.Add1: {
                        Header = "Where is your organization's server?";

                        // Address
                        TextBlock address_label = new TextBlock () {
                            Text       = "Enter a Web address where the documents can be seen:",
                            FontWeight = FontWeights.Bold
                        };

                        TextBox address_box = new TextBox () {
                            Width = 420,
                            Text  = Controller.PreviousAddress,
                            IsEnabled = (Controller.SelectedPlugin.Address == null)
                        };

                        TextBlock address_help_label = new TextBlock()
                        {
                            Text = "Help: ",
                            FontSize = 11,
                            Foreground = new SolidColorBrush(Color.FromRgb(128, 128, 128))
                        };
                        Run run = new Run("Where to find this address");
                        Hyperlink link = new Hyperlink(run);
                        link.NavigateUri = new Uri("https://github.com/nicolas-raoul/CmisSync/wiki/What-address");
                        address_help_label.Inlines.Add(link);
                        link.RequestNavigate += (sender, e) =>
                            {
                                System.Diagnostics.Process.Start(e.Uri.ToString());
                            };

                        TextBlock address_error_label = new TextBlock()
                        {
                            FontSize = 11,
                            Foreground = new SolidColorBrush(Color.FromRgb(255, 128, 128)),
                            Visibility = Visibility.Hidden
                        };

                        // User
                        TextBlock user_label = new TextBlock()
                        {
                            Text = "User:"******"Password:"******"Cancel"
                        };

                        Button continue_button = new Button () {
                            Content = "Continue"
                        };

                        // Address
                        ContentCanvas.Children.Add (address_label);
                        Canvas.SetTop (address_label, 160);
                        Canvas.SetLeft (address_label, 185);

                        ContentCanvas.Children.Add (address_box);
                        Canvas.SetTop (address_box, 180);
                        Canvas.SetLeft (address_box, 185);

                        ContentCanvas.Children.Add(address_help_label);
                        Canvas.SetTop(address_help_label, 205);
                        Canvas.SetLeft(address_help_label, 185);

                        ContentCanvas.Children.Add(address_error_label);
                        Canvas.SetTop(address_error_label, 235);
                        Canvas.SetLeft(address_error_label, 185);

                        // User
                        ContentCanvas.Children.Add(user_label);
                        Canvas.SetTop(user_label, 300);
                        Canvas.SetLeft(user_label, 185);

                        ContentCanvas.Children.Add(user_box);
                        Canvas.SetTop(user_box, 330);
                        Canvas.SetLeft(user_box, 185);

                        ContentCanvas.Children.Add(user_help_label);
                        Canvas.SetTop(user_help_label, 355);
                        Canvas.SetLeft(user_help_label, 185);

                        // Password
                        ContentCanvas.Children.Add(password_label);
                        Canvas.SetTop(password_label, 300);
                        Canvas.SetRight(password_label, 30);

                        ContentCanvas.Children.Add(password_box);
                        Canvas.SetTop(password_box, 330);
                        Canvas.SetRight(password_box, 30);

                        ContentCanvas.Children.Add(password_help_label);
                        Canvas.SetTop(password_help_label, 355);
                        Canvas.SetRight(password_help_label, 30);

                        TaskbarItemInfo.ProgressValue = 0.0;
                        TaskbarItemInfo.ProgressState = TaskbarItemProgressState.None;

                        Buttons.Add (continue_button);
                        Buttons.Add (cancel_button);

                        address_box.Focus ();
                        address_box.Select (address_box.Text.Length, 0);

                        Controller.ChangeAddressFieldEvent += delegate (string text,
                            string example_text, FieldState state) {
                            Dispatcher.BeginInvoke ((Action) delegate {
                                address_box.Text        = text;
                                address_box.IsEnabled   = (state == FieldState.Enabled);
                                address_help_label.Text = example_text;
                            });
                        };

                        Controller.ChangeUserFieldEvent += delegate(string text,
                            string example_text, FieldState state) {
                            Dispatcher.BeginInvoke((Action)delegate
                            {
                                user_box.Text = text;
                                user_box.IsEnabled = (state == FieldState.Enabled);
                                user_help_label.Text = example_text;
                            });
                        };

                        Controller.ChangePasswordFieldEvent += delegate(string text,
                            string example_text, FieldState state) {
                            Dispatcher.BeginInvoke((Action)delegate
                            {
                                password_box.Password = text;
                                password_box.IsEnabled = (state == FieldState.Enabled);
                                password_help_label.Text = example_text;
                            });
                        };

                        Controller.UpdateAddProjectButtonEvent += delegate(bool button_enabled)
                        {
                            Dispatcher.BeginInvoke ((Action) delegate {
                                continue_button.IsEnabled = button_enabled;
                            });
                        };

                        Controller.CheckAddPage (address_box.Text);

                        address_box.TextChanged += delegate {
                            Controller.CheckAddPage (address_box.Text);
                        };

                        cancel_button.Click += delegate {
                            Controller.PageCancelled ();
                        };

                        continue_button.Click += delegate {
                            // Show wait cursor
                            System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;

                            // Try to find the CMIS server
                            CmisServer cmisServer = CmisUtils.GetRepositoriesFuzzy(
                                address_box.Text, user_box.Text, password_box.Password);
                            Controller.repositories = cmisServer.repositories;
                            address_box.Text = cmisServer.url;

                            // Hide wait cursor
                            System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;

                            if (Controller.repositories == null)
                            {
                                // Show warning
                                address_error_label.Text = "Sorry, CmisSync can not find a CMIS server at this address.\nPlease check again.\nIf you are sure about the address, open it in a browser and post\nthe resulting XML to the CmisSync forum.";
                                address_error_label.Visibility = Visibility.Visible;
                            }
                            else
                            {
                                // Continue to folder selection
                                Controller.Add1PageCompleted(
                                    address_box.Text, user_box.Text, password_box.Password);
                            }
                        };

                        break;
                    }

                    case PageType.Add2: {
                        Header = "Which remote folder do you want to sync?";

                        System.Windows.Controls.TreeView treeView = new System.Windows.Controls.TreeView();
                        treeView.Width = 410;
                        treeView.Height = 267;
                        foreach (string repository in Controller.repositories)
                        {
                            System.Windows.Controls.TreeViewItem item = new System.Windows.Controls.TreeViewItem();
                            item.Tag = new SelectionTreeItem("/");
                            item.Header = repository;
                            treeView.Items.Add(item);
                        }
                        ContentCanvas.Children.Add(treeView);
                        Canvas.SetTop(treeView, 70);
                        Canvas.SetLeft(treeView, 185);

                        treeView.SelectedItemChanged += delegate
                        {
                            // Identify the selected remote path.
                            TreeViewItem item = (TreeViewItem)treeView.SelectedItem;
                            Controller.saved_remote_path = ((SelectionTreeItem)item.Tag).fullPath;

                            // Identify the selected repository.
                            object cursor = item;
                            while (cursor is TreeViewItem)
                            {
                                TreeViewItem treeViewItem = (TreeViewItem)cursor;
                                cursor = treeViewItem.Parent;
                                if ( ! (cursor is TreeViewItem))
                                {
                                    Controller.saved_repository = (string)treeViewItem.Header;
                                }
                            }

                            // Load sub-folders if it has not been done already.
                            // We use each item's Tag to store metadata: whether this item's subfolders have been loaded or not.
                            if ( ((SelectionTreeItem)item.Tag).childrenLoaded == false)
                            {
                                System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;

                                // Get list of subfolders
                                string[] subfolders = CmisUtils.GetSubfolders(Controller.saved_repository, Controller.saved_remote_path,
                                    Controller.saved_address, Controller.saved_user, Controller.saved_password);

                                // Create a sub-item for each subfolder
                                foreach (string subfolder in subfolders)
                                {
                                    System.Windows.Controls.TreeViewItem subItem =
                                        new System.Windows.Controls.TreeViewItem();
                                    subItem.Tag = new SelectionTreeItem(subfolder);
                                    subItem.Header = Path.GetFileName(subfolder);
                                    item.Items.Add(subItem);
                                }
                                ((SelectionTreeItem)item.Tag).childrenLoaded = true;
                                item.ExpandSubtree();
                                System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
                            }
                        };

                        Button cancel_button = new Button()
                        {
                            Content = "Cancel"
                        };

                        Button add_button = new Button()
                        {
                            Content = "Add"
                        };

                        Buttons.Add(add_button);
                        Buttons.Add(cancel_button);

                        cancel_button.Click += delegate
                        {
                            Controller.PageCancelled();
                        };

                        add_button.Click += delegate
                        {
                            Controller.Add2PageCompleted(
                                Controller.saved_repository, Controller.saved_remote_path);
                        };

                        break;
                    }

                    case PageType.Syncing: {
                        Header      = "Adding folder ‘" + Controller.SyncingFolder + "’…";
                        Description = "This may either take a short or a long time depending on the folder's size.";

                        Button finish_button = new Button () {
                            Content   = "Finish",
                            IsEnabled = false
                        };

                        Button cancel_button = new Button () {
                            Content = "Cancel"
                        };

                        ProgressBar progress_bar = new ProgressBar () {
                            Width  = 414,
                            Height = 15,
                            Value  = Controller.ProgressBarPercentage
                        };

                        ContentCanvas.Children.Add (progress_bar);
                        Canvas.SetLeft (progress_bar, 185);
                        Canvas.SetTop (progress_bar, 150);

                        TaskbarItemInfo.ProgressState = TaskbarItemProgressState.Normal;

                        Buttons.Add (cancel_button);
                        Buttons.Add(finish_button);

                        Controller.UpdateProgressBarEvent += delegate (double percentage) {
                            Dispatcher.BeginInvoke ((Action) delegate {
                                progress_bar.Value = percentage;
                                TaskbarItemInfo.ProgressValue = percentage / 100;
                            });
                        };

                        cancel_button.Click += delegate {
                            Controller.SyncingCancelled ();
                        };

                        break;
                    }

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

                        TextBlock help_block = new TextBlock () {
                            TextWrapping = TextWrapping.Wrap,
                            Width        = 310
                        };

                        TextBlock bullets_block = new TextBlock () {
                            Text = "•\n\n\n•"
                        };

                        help_block.Inlines.Add (new Bold (new Run (Controller.PreviousUrl)));
                        help_block.Inlines.Add (" is the address we've compiled. Does this look alright?\n\n");
                        help_block.Inlines.Add ("Do you have access rights to this remote project?");

                        if (warnings.Length > 0) {
                            bullets_block.Text += "\n\n•";
                            help_block.Inlines.Add ("\n\nHere's the raw error message:");

                            foreach (string warning in warnings) {
                                help_block.Inlines.Add ("\n");
                                help_block.Inlines.Add (new Bold (new Run (warning)));
                            }
                        }

                        Button cancel_button = new Button () {
                            Content = "Cancel"
                        };

                        Button try_again_button = new Button () {
                            Content = "Try again…"
                        };

                        ContentCanvas.Children.Add (bullets_block);
                        Canvas.SetLeft (bullets_block, 195);
                        Canvas.SetTop (bullets_block, 100);

                        ContentCanvas.Children.Add (help_block);
                        Canvas.SetLeft (help_block, 210);
                        Canvas.SetTop (help_block, 100);

                        TaskbarItemInfo.ProgressValue = 1.0;
                        TaskbarItemInfo.ProgressState = TaskbarItemProgressState.Error;

                        Buttons.Add (try_again_button);
                        Buttons.Add (cancel_button);

                        cancel_button.Click += delegate {
                            Controller.PageCancelled ();
                        };

                        try_again_button.Click += delegate {
                            Controller.ErrorPageCompleted ();
                        };

                        break;
                    }

                    case PageType.Finished: {
                        Header      = "Your documents are ready!";
                        Description = "You can find them in your CmisSync folder.";

                        Button finish_button = new Button () {
                            Content = "Finish"
                        };

                        Button open_folder_button = new Button () {
                            Content = string.Format ("Open {0}", Path.GetFileName (Controller.PreviousPath))
                        };

                        if (warnings.Length > 0) {
                            Image warning_image = new Image () {
                                Source = Imaging.CreateBitmapSourceFromHIcon (Drawing.SystemIcons.Information.Handle,
                                    Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions ())
                            };

                            TextBlock warning_block = new TextBlock () {
                                Text         = warnings [0],
                                Width        = 310,
                                TextWrapping = TextWrapping.Wrap
                            };

                            ContentCanvas.Children.Add (warning_image);
                            Canvas.SetLeft (warning_image, 193);
                            Canvas.SetTop (warning_image, 100);

                            ContentCanvas.Children.Add (warning_block);
                            Canvas.SetLeft (warning_block, 240);
                            Canvas.SetTop (warning_block, 100);
                        }

                        TaskbarItemInfo.ProgressValue = 0.0;
                        TaskbarItemInfo.ProgressState = TaskbarItemProgressState.None;

                        Buttons.Add(open_folder_button);
                        Buttons.Add (finish_button);

                        finish_button.Click += delegate {
                            Controller.FinishPageCompleted ();
                        };

                        open_folder_button.Click += delegate {
                            Controller.OpenFolderClicked ();
                        };

                        SystemSounds.Exclamation.Play ();

                        break;
                    }

                    case PageType.Tutorial: {

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

                                WPF.Image slide_image = new WPF.Image () {
                                    Width  = 350,
                                    Height = 200
                                };

                                slide_image.Source = SparkleUIHelpers.GetImageSource ("tutorial-slide-1");

                                Button skip_tutorial_button = new Button () {
                                    Content = "Skip tutorial"
                                };

                                Button continue_button = new Button () {
                                    Content = "Continue"
                                };

                                ContentCanvas.Children.Add (slide_image);
                                Canvas.SetLeft (slide_image, 215);
                                Canvas.SetTop (slide_image, 130);

                                Buttons.Add (continue_button);
                                Buttons.Add (skip_tutorial_button);

                                skip_tutorial_button.Click += delegate {
                                    Controller.TutorialSkipped ();
                                };

                                continue_button.Click += delegate {
                                    Controller.TutorialPageCompleted ();
                                };

                                break;
                            }

                            case 2: {
                                Header      = "Sharing files with others";
                                Description = "All files added to the server are automatically synced to your " +
                                    "local folder.";

                                Button continue_button = new Button () {
                                    Content = "Continue"
                                };

                                WPF.Image slide_image = new WPF.Image () {
                                    Width  = 350,
                                    Height = 200
                                };

                                slide_image.Source = SparkleUIHelpers.GetImageSource ("tutorial-slide-2");

                                ContentCanvas.Children.Add (slide_image);
                                Canvas.SetLeft (slide_image, 215);
                                Canvas.SetTop (slide_image, 130);

                                Buttons.Add (continue_button);

                                continue_button.Click += delegate {
                                    Controller.TutorialPageCompleted ();
                                };

                                break;
                            }

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

                                Button continue_button = new Button () {
                                    Content = "Continue"
                                };

                                WPF.Image slide_image = new WPF.Image () {
                                    Width  = 350,
                                    Height = 200
                                };

                                slide_image.Source = SparkleUIHelpers.GetImageSource ("tutorial-slide-3");

                                ContentCanvas.Children.Add (slide_image);
                                Canvas.SetLeft (slide_image, 215);
                                Canvas.SetTop (slide_image, 130);

                                Buttons.Add (continue_button);

                                continue_button.Click += delegate {
                                    Controller.TutorialPageCompleted ();
                                };

                                break;
                            }

                            case 4: {
                                Header      = "Adding repository folders to CmisSync";
                                Description = "You can easily add a new CMIS folder " +
                                    "at any time.";

                                Button finish_button = new Button () {
                                    Content = "Finish"
                                };

                                WPF.Image slide_image = new WPF.Image () {
                                    Width  = 350,
                                    Height = 200
                                };

                                slide_image.Source = SparkleUIHelpers.GetImageSource ("tutorial-slide-4");

                                CheckBox check_box = new CheckBox () {
                                    Content   = "Add CmisSync to startup items",
                                    IsChecked = true
                                };

                                ContentCanvas.Children.Add (slide_image);
                                Canvas.SetLeft (slide_image, 215);
                                Canvas.SetTop (slide_image, 130);

                                ContentCanvas.Children.Add (check_box);
                                Canvas.SetLeft (check_box, 185);
                                Canvas.SetBottom (check_box, 12);

                                Buttons.Add (finish_button);

                                check_box.Click += delegate {
                                    Controller.StartupItemChanged (check_box.IsChecked.Value);
                                };

                                finish_button.Click += delegate {
                                    Controller.TutorialPageCompleted ();
                                };

                                break;
                            }
                        }
                        break;
                    }
                    }

                    ShowAll ();
                });
            };
        }
Example #6
0
		public void FocusTest3 ()
		{
			// Show that focus is preserved when an element is added/removed from
			// the visual tree
			bool gotfocus = false;
			bool lostfocus = false;
			Button b = new Button ();

			Enqueue (() => {
				TestPanel.Children.Add (b);
				b.Focus ();
			});
			Enqueue (() => {
				Assert.IsFalse (gotfocus, "#1");
				Assert.IsFalse (lostfocus, "#2");

				TestPanel.Children.Clear ();
				Assert.IsNull (FocusManager.GetFocusedElement (), "#3");
			});
			Enqueue (() => {
				Assert.IsFalse (gotfocus, "#4");
				Assert.IsFalse (lostfocus, "#5");

				TestPanel.Children.Add (b);
				Assert.IsNull (FocusManager.GetFocusedElement (), "#6");
			});
			Enqueue (() => {
				Assert.IsFalse (gotfocus, "#7");
				Assert.IsFalse (lostfocus, "#8");
			});
			EnqueueTestComplete ();
		}
Example #7
0
		public void FocusTest2 ()
		{
			// Show that focus is lost when the control is removed from the
			// visual tree
			Button b = new Button ();
			TestPanel.Children.Add (b);
			b.Focus ();
			Assert.AreEqual (b, FocusManager.GetFocusedElement (), "#1");
			TestPanel.Children.Clear ();
			Assert.IsNull (FocusManager.GetFocusedElement (), "#2");
		}
Example #8
0
		public void FocusTest ()
		{
			// Show that Controls can be focused before they are loaded
			bool gotfocus = false;
			Button b = new Button ();
			b.GotFocus += delegate { gotfocus = true; };

			Assert.IsFalse (b.Focus (), "#1");
			TestPanel.Children.Add (b);
			Assert.IsTrue (b.Focus (), "#2");
			Enqueue (() => { });
			Enqueue (() => Assert.IsFalse (gotfocus, "#3"));
			EnqueueTestComplete ();
		}
Example #9
0
        public AboutDialog(Window owner)
        {
            // Get attributes from assembly.
            // Get this executing assembly to access attributes.
            Assembly asmbly = Assembly.GetExecutingAssembly();

            // Get the AssemblyTitle attribute for the program name.
            AssemblyTitleAttribute title =
                (AssemblyTitleAttribute)asmbly.GetCustomAttributes(
                    typeof(AssemblyTitleAttribute), false)[0];
            string strTitle = title.Title;

            // Get the AssemblyFileVersion attribute.
            AssemblyFileVersionAttribute version =
                (AssemblyFileVersionAttribute)asmbly.GetCustomAttributes(
                    typeof(AssemblyFileVersionAttribute), false)[0];
            string strVersion = version.Version.Substring(0, 3);

            // Get the AssemblyCopyright attribute.
            AssemblyCopyrightAttribute copy =
                (AssemblyCopyrightAttribute)asmbly.GetCustomAttributes(
                    typeof(AssemblyCopyrightAttribute), false)[0];
            string strCopyright = copy.Copyright;

            // Standard window properties for dialog boxes.
            Title = "About " + strTitle;
            ShowInTaskbar = false;
            SizeToContent = SizeToContent.WidthAndHeight;
            ResizeMode = ResizeMode.NoResize;
            Left = owner.Left + 96;
            Top = owner.Top + 96;

            // Create StackPanel as content of window.
            StackPanel stackMain = new StackPanel();
            Content = stackMain;

            // Create TextBlock for program name.
            TextBlock txtblk = new TextBlock();
            txtblk.Text = strTitle + " Version " + strVersion;
            txtblk.FontFamily = new FontFamily("Times New Roman");
            txtblk.FontSize = 32;       // 24 points
            txtblk.FontStyle = FontStyles.Italic;
            txtblk.Margin = new Thickness(24);
            txtblk.HorizontalAlignment = HorizontalAlignment.Center;
            stackMain.Children.Add(txtblk);

            // Create TextBlock for copyright.
            txtblk = new TextBlock();
            txtblk.Text = strCopyright;
            txtblk.FontSize = 20;       // 15 points.
            txtblk.HorizontalAlignment = HorizontalAlignment.Center;
            stackMain.Children.Add(txtblk);

            // Create TextBlock for Web site link.
            Run run = new Run("www.GrapeCity.com");
            Hyperlink link = new Hyperlink(run);
            link.Click += LinkOnClick;
            txtblk = new TextBlock(link);
            txtblk.FontSize = 20;
            txtblk.HorizontalAlignment = HorizontalAlignment.Center;
            stackMain.Children.Add(txtblk);

            // Create OK button.
            Button btn = new Button();
            btn.Content = "OK";
            btn.IsDefault = true;
            btn.IsCancel = true;
            btn.HorizontalAlignment = HorizontalAlignment.Center;
            btn.MinWidth = 48;
            btn.Margin = new Thickness(24);
            btn.Click += OkOnClick;
            stackMain.Children.Add(btn);

            btn.Focus();
        }
Example #10
0
        public virtual void ExpanderButtonFocusActivatesSelection()
        {
            StackPanel root = new StackPanel();
            TreeView view = new TreeView();
            TreeViewItem item = new TreeViewItem { Header = "Item" };
            Button button = new Button { Content = "Button" };
            view.Items.Add(item);
            root.Children.Add(view);
            root.Children.Add(button);
            ToggleButton ExpanderButton = null;

            TestAsync(
                5,
                root,
                () => item.Focus(),
                () => Assert.IsTrue(item.IsSelected, "Item should be selected!"),
                () => Assert.IsTrue(item.IsSelectionActive, "Selection should be active after focusing!"),
                () => button.Focus(),
                () => Assert.IsFalse(item.IsSelectionActive, "Selection should be inactive after focusing on something else!"),
                () => ExpanderButton = item.GetVisualChild("ExpanderButton") as ToggleButton,
                () => Assert.IsNotNull(ExpanderButton, "Failed to find template part ExpanderButton!"),
                () => ExpanderButton.Focus(),
                () => Assert.IsTrue(item.IsSelectionActive, "Selection should be active after focusing ExpanderButton!"));
        }
Example #11
0
        public virtual void SelectionInactiveOnLostFocus()
        {
            StackPanel root = new StackPanel();
            TreeView view = new TreeView();
            TreeViewItem item = new TreeViewItem { Header = "Item" };
            view.Items.Add(item);
            Button other = new Button { Content = "Button" };
            root.Children.Add(view);
            root.Children.Add(other);

            TestAsync(
                root,
                () => Assert.IsFalse(item.IsSelected, "Item should not be selected initially!"),
                () => Assert.IsFalse(item.IsSelectionActive, "Item should not have inactive selection initially!"),
                () => item.Focus(),
                () => Assert.IsTrue(item.IsSelected, "Item should be selected after focus!"),
                () => Assert.IsTrue(item.IsSelectionActive, "Item should not have inactive selection after focus!"),
                () => other.Focus(),
                () => Assert.IsTrue(item.IsSelected, "Item should be selected after focusing another element!"),
                () => Assert.IsFalse(item.IsSelectionActive, "Item should have an inactive selection after focusing another element!"));
        }
Example #12
0
 private void btn_ToLarge(Button btn)
 {
     btn.Focus();
     Launcher launcher = (Launcher)btn.Tag;
     DoubleAnimation anim = AnimButtonSize(btn.Width, launcher.Width * 1.2);
     btn.BeginAnimation(Button.WidthProperty, anim);
     btn.BeginAnimation(Button.HeightProperty, anim);
 }
Example #13
0
 private void SelectButton(System.Windows.Controls.Button button)
 {
     button.Focus();
 }
        public void FocusPropertyObjectChange() {
            TextBox control_1 = new TextBox() { IsReadOnly = false };
            TextBox control_2 = new TextBox() { IsReadOnly = false };
            TestControl controlWithProperty = new TestControl();
            FocusBehavior behavior = new FocusBehavior() { PropertyName = "IsReadOnly", SourceObject = control_1 };
            Interaction.GetBehaviors(controlWithProperty).Add(behavior);
            behavior.FocusDelay = TimeSpan.FromMilliseconds(0);
            Grid grid = new Grid();
            Button button = new Button();
            grid.Children.Add(button);
            grid.Children.Add(controlWithProperty);
            grid.Children.Add(control_1);
            grid.Children.Add(control_2);
            Window.Content = grid;
            EnqueueShowWindow();

            EnqueueCallback(() => {
                CheckUnfocusedElement(controlWithProperty);
                control_1.IsReadOnly = true;
                CheckFocusedElement(controlWithProperty);
                button.Focus();
                behavior.SourceObject = control_2;
                CheckUnfocusedElement(controlWithProperty);
                control_2.IsReadOnly = true;
                CheckFocusedElement(controlWithProperty);
            });
            EnqueueTestComplete();
        }
Example #15
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public Setup()
        {
            Logger.Info("Entering constructor.");

            // Defines how to show the setup window.
            Controller.ShowWindowEvent += delegate
            {
                Dispatcher.BeginInvoke((Action)delegate
                {
                    Logger.Info("Entering ShowWindowEvent.");
                    Show();
                    Activate();
                    BringIntoView();
                    Logger.Info("Exiting ShowWindowEvent.");
                });
            };

            // Defines how to hide the setup windows.
            Controller.HideWindowEvent += delegate
            {
                Dispatcher.BeginInvoke((Action)delegate
                {
                    Hide();
                });
            };

            // Defines what to do when changing page.
            // The remote folder addition wizard has several steps.
            Controller.ChangePageEvent += delegate(PageType type)
            {
                Dispatcher.BeginInvoke((Action)delegate
                {
                    Logger.Info("Entering ChangePageEvent.");
                    Reset();

                    // Show appropriate setup page.
                    switch (type)
                    {
                        // Welcome page that shows up at first run.
                        #region Page Setup
                        case PageType.Setup:
                            {
                                // UI elements.

                                Header = Properties_Resources.Welcome;
                                Description = Properties_Resources.Intro;

                                Button cancel_button = new Button()
                                {
                                    Content = Properties_Resources.Cancel
                                };

                                Button continue_button = new Button()
                                {
                                    Content = Properties_Resources.Continue,
                                    IsEnabled = false
                                };

                                Buttons.Add(continue_button);
                                Buttons.Add(cancel_button);

                                continue_button.Focus();

                                // Actions.

                                Controller.UpdateSetupContinueButtonEvent += delegate(bool enabled)
                                {
                                    Dispatcher.BeginInvoke((Action)delegate
                                    {
                                        continue_button.IsEnabled = enabled;
                                    });
                                };

                                cancel_button.Click += delegate
                                {
                                    Dispatcher.BeginInvoke((Action)delegate
                                    {
                                        Program.UI.StatusIcon.Dispose();
                                        Controller.SetupPageCancelled();
                                    });
                                };

                                continue_button.Click += delegate
                                {
                                    Controller.SetupPageCompleted();
                                };

                                Controller.CheckSetupPage();

                                break;
                            }
                        #endregion

                        #region Page Tutorial
                        case PageType.Tutorial:
                            {
                                switch (Controller.TutorialCurrentPage)
                                {
                                    // First page of the tutorial.
                                    case 1:
                                        {
                                            // UI elements.

                                            Header = Properties_Resources.WhatsNext;
                                            Description = Properties_Resources.CmisSyncCreates;

                                            WPF.Image slide_image = new WPF.Image()
                                            {
                                                Width = 350,
                                                Height = 200
                                            };

                                            slide_image.Source = UIHelpers.GetImageSource("tutorial-slide-1");

                                            Button skip_tutorial_button = new Button()
                                            {
                                                Content = Properties_Resources.SkipTutorial
                                            };

                                            Button continue_button = new Button()
                                            {
                                                Content = Properties_Resources.Continue
                                            };


                                            ContentCanvas.Children.Add(slide_image);
                                            Canvas.SetLeft(slide_image, 215);
                                            Canvas.SetTop(slide_image, 130);

                                            Buttons.Add(continue_button);
                                            Buttons.Add(skip_tutorial_button);

                                            // Actions.

                                            skip_tutorial_button.Click += delegate
                                            {
                                                Controller.TutorialSkipped();
                                            };

                                            continue_button.Click += delegate
                                            {
                                                Controller.TutorialPageCompleted();
                                            };

                                            break;
                                        }

                                    // Second page of the tutorial.
                                    case 2:
                                        {
                                            // UI elements.

                                            Header = Properties_Resources.Synchronization;
                                            Description = Properties_Resources.DocumentsAre;


                                            Button continue_button = new Button()
                                            {
                                                Content = Properties_Resources.Continue
                                            };

                                            WPF.Image slide_image = new WPF.Image()
                                            {
                                                Width = 350,
                                                Height = 200
                                            };

                                            slide_image.Source = UIHelpers.GetImageSource("tutorial-slide-2");


                                            ContentCanvas.Children.Add(slide_image);
                                            Canvas.SetLeft(slide_image, 215);
                                            Canvas.SetTop(slide_image, 130);

                                            Buttons.Add(continue_button);

                                            // Actions.

                                            continue_button.Click += delegate
                                            {
                                                Controller.TutorialPageCompleted();
                                            };

                                            break;
                                        }

                                    // Third page of the tutorial.
                                    case 3:
                                        {
                                            // UI elements.

                                            Header = Properties_Resources.StatusIcon;
                                            Description = Properties_Resources.StatusIconShows;


                                            Button continue_button = new Button()
                                            {
                                                Content = Properties_Resources.Continue
                                            };

                                            WPF.Image slide_image = new WPF.Image()
                                            {
                                                Width = 350,
                                                Height = 200
                                            };

                                            slide_image.Source = UIHelpers.GetImageSource("tutorial-slide-3");


                                            ContentCanvas.Children.Add(slide_image);
                                            Canvas.SetLeft(slide_image, 215);
                                            Canvas.SetTop(slide_image, 130);

                                            Buttons.Add(continue_button);

                                            // Actions.

                                            continue_button.Click += delegate
                                            {
                                                Controller.TutorialPageCompleted();
                                            };

                                            break;
                                        }

                                    // Fourth page of the tutorial.
                                    case 4:
                                        {
                                            // UI elements.

                                            Header = Properties_Resources.AddFolders;
                                            Description = Properties_Resources.YouCan;


                                            Button finish_button = new Button()
                                            {
                                                Content = Properties_Resources.Finish
                                            };

                                            WPF.Image slide_image = new WPF.Image()
                                            {
                                                Width = 350,
                                                Height = 200
                                            };

                                            slide_image.Source = UIHelpers.GetImageSource("tutorial-slide-4");

                                            CheckBox check_box = new CheckBox()
                                            {
                                                Content = Properties_Resources.Startup,
                                                IsChecked = true
                                            };


                                            ContentCanvas.Children.Add(slide_image);
                                            Canvas.SetLeft(slide_image, 215);
                                            Canvas.SetTop(slide_image, 130);

                                            ContentCanvas.Children.Add(check_box);
                                            Canvas.SetLeft(check_box, 185);
                                            Canvas.SetBottom(check_box, 12);

                                            Buttons.Add(finish_button);

                                            // Actions.

                                            check_box.Click += delegate
                                            {
                                                Controller.StartupItemChanged(check_box.IsChecked.Value);
                                            };

                                            finish_button.Click += delegate
                                            {
                                                Controller.TutorialPageCompleted();
                                            };

                                            break;
                                        }
                                }
                                break;
                            }
                        #endregion

                        // First step of the remote folder addition dialog: Specifying the server.
                        #region Page Add1
                        case PageType.Add1:
                            {
                                // UI elements.

                                Header = Properties_Resources.Where;

                                // Address input UI.
                                TextBlock address_label = new TextBlock()
                                {
                                    Text = Properties_Resources.EnterWebAddress,
                                    FontWeight = FontWeights.Bold
                                };

                                TextBox address_box = new TextBox()
                                {
                                    Width = 420,
                                    Text = (Controller.PreviousAddress != null) ? Controller.PreviousAddress.ToString() : ""
                                };

                                TextBlock address_help_label = new TextBlock()
                                {
                                    Text = Properties_Resources.Help + ": ",
                                    FontSize = 11,
                                    Foreground = new SolidColorBrush(Color.FromRgb(128, 128, 128))
                                };
                                Run run = new Run(Properties_Resources.WhereToFind);
                                Hyperlink link = new Hyperlink(run);
                                link.NavigateUri = new Uri("https://github.com/nicolas-raoul/CmisSync/wiki/What-address");
                                address_help_label.Inlines.Add(link);
                                link.RequestNavigate += (sender, e) =>
                                {
                                    System.Diagnostics.Process.Start(e.Uri.ToString());
                                };

                                // Rather than a TextBlock, we use a textBox so that users can copy/paste the error message and Google it.
                                TextBox address_error_label = new TextBox()
                                {
                                    FontSize = 11,
                                    Foreground = new SolidColorBrush(Color.FromRgb(255, 128, 128)),
                                    Visibility = Visibility.Hidden,
                                    IsReadOnly = true,
                                    Background = Brushes.Transparent,
                                    BorderThickness = new Thickness(0),
                                    TextWrapping = TextWrapping.Wrap,
                                    MaxWidth = 420
                                };

                                // User input UI.
                                TextBlock user_label = new TextBlock()
                                {
                                    Text = Properties_Resources.User + ":",
                                    FontWeight = FontWeights.Bold,
                                    Width = 200
                                };

                                TextBox user_box = new TextBox()
                                {
                                    Width = 200
                                };
                                if (Controller.saved_user == String.Empty || Controller.saved_user == null)
                                {
                                    user_box.Text = Environment.UserName;
                                }
                                else
                                {
                                    user_box.Text = Controller.saved_user;
                                }

                                TextBlock user_help_label = new TextBlock()
                                {
                                    FontSize = 11,
                                    Width = 200,
                                    Foreground = new SolidColorBrush(Color.FromRgb(128, 128, 128))
                                };

                                // Password input UI.
                                TextBlock password_label = new TextBlock()
                                {
                                    Text = Properties_Resources.Password + ":",
                                    FontWeight = FontWeights.Bold,
                                    Width = 200
                                };

                                PasswordBox password_box = new PasswordBox()
                                {
                                    Width = 200
                                };

                                TextBlock password_help_label = new TextBlock()
                                {
                                    FontSize = 11,
                                    Width = 200,
                                    Foreground = new SolidColorBrush(Color.FromRgb(128, 128, 128))
                                };

                                // Buttons.
                                Button cancel_button = new Button()
                                {
                                    Content = Properties_Resources.Cancel
                                };

                                Button continue_button = new Button()
                                {
                                    Content = Properties_Resources.Continue
                                };

                                Buttons.Add(continue_button);
                                Buttons.Add(cancel_button);

                                // Address
                                ContentCanvas.Children.Add(address_label);
                                Canvas.SetTop(address_label, 160);
                                Canvas.SetLeft(address_label, 185);

                                ContentCanvas.Children.Add(address_box);
                                Canvas.SetTop(address_box, 180);
                                Canvas.SetLeft(address_box, 185);

                                ContentCanvas.Children.Add(address_help_label);
                                Canvas.SetTop(address_help_label, 205);
                                Canvas.SetLeft(address_help_label, 185);

                                ContentCanvas.Children.Add(address_error_label);
                                Canvas.SetTop(address_error_label, 235);
                                Canvas.SetLeft(address_error_label, 185);

                                // User
                                ContentCanvas.Children.Add(user_label);
                                Canvas.SetTop(user_label, 300);
                                Canvas.SetLeft(user_label, 185);

                                ContentCanvas.Children.Add(user_box);
                                Canvas.SetTop(user_box, 330);
                                Canvas.SetLeft(user_box, 185);

                                ContentCanvas.Children.Add(user_help_label);
                                Canvas.SetTop(user_help_label, 355);
                                Canvas.SetLeft(user_help_label, 185);

                                // Password
                                ContentCanvas.Children.Add(password_label);
                                Canvas.SetTop(password_label, 300);
                                Canvas.SetRight(password_label, 30);

                                ContentCanvas.Children.Add(password_box);
                                Canvas.SetTop(password_box, 330);
                                Canvas.SetRight(password_box, 30);

                                ContentCanvas.Children.Add(password_help_label);
                                Canvas.SetTop(password_help_label, 355);
                                Canvas.SetRight(password_help_label, 30);

                                TaskbarItemInfo.ProgressValue = 0.0;
                                TaskbarItemInfo.ProgressState = TaskbarItemProgressState.None;

                                if (Controller.PreviousAddress == null || Controller.PreviousAddress.ToString() == String.Empty)
                                    address_box.Text = "https://";
                                else
                                    address_box.Text = Controller.PreviousAddress.ToString();
                                address_box.Focus();
                                address_box.Select(address_box.Text.Length, 0);

                                // Actions.

                                Controller.ChangeAddressFieldEvent += delegate(string text,
                                    string example_text)
                                {
                                    Dispatcher.BeginInvoke((Action)delegate
                                    {
                                        address_box.Text = text;
                                        address_help_label.Text = example_text;
                                    });
                                };

                                Controller.ChangeUserFieldEvent += delegate(string text,
                                    string example_text)
                                {
                                    Dispatcher.BeginInvoke((Action)delegate
                                    {
                                        user_box.Text = text;
                                        user_help_label.Text = example_text;
                                    });
                                };

                                Controller.ChangePasswordFieldEvent += delegate(string text,
                                    string example_text)
                                {
                                    Dispatcher.BeginInvoke((Action)delegate
                                    {
                                        password_box.Password = text;
                                        password_help_label.Text = example_text;
                                    });
                                };

                                Controller.UpdateAddProjectButtonEvent += delegate(bool button_enabled)
                                {
                                    Dispatcher.BeginInvoke((Action)delegate
                                    {
                                        continue_button.IsEnabled = button_enabled;
                                    });
                                };

                                Controller.CheckAddPage(address_box.Text);

                                address_box.TextChanged += delegate
                                {
                                    string error = Controller.CheckAddPage(address_box.Text);
                                    if (!String.IsNullOrEmpty(error))
                                    {
                                        address_error_label.Text = Properties_Resources.ResourceManager.GetString(error, CultureInfo.CurrentCulture);
                                        address_error_label.Visibility = Visibility.Visible;
                                    }
                                    else address_error_label.Visibility = Visibility.Hidden;
                                };

                                cancel_button.Click += delegate
                                {
                                    Controller.PageCancelled();
                                };

                                continue_button.Click += delegate
                                {
                                    // Show wait cursor
                                    System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;

                                    // Try to find the CMIS server (asynchronously)
                                    GetRepositoriesFuzzyDelegate dlgt =
                                        new GetRepositoriesFuzzyDelegate(CmisUtils.GetRepositoriesFuzzy);
                                    IAsyncResult ar = dlgt.BeginInvoke(new Uri(address_box.Text), user_box.Text,
                                        password_box.Password, null, null);
                                    while (!ar.AsyncWaitHandle.WaitOne(100))
                                    {
                                        System.Windows.Forms.Application.DoEvents();
                                    }
                                    Tuple<CmisServer, Exception> result = dlgt.EndInvoke(ar);
                                    CmisServer cmisServer = result.Item1;

                                    Controller.repositories = cmisServer != null ? cmisServer.Repositories : null;

                                    address_box.Text = cmisServer.Url.ToString();

                                    // Hide wait cursor
                                    System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;

                                    if (Controller.repositories == null)
                                    {
                                        // Could not retrieve repositories list from server, show warning.
                                        string warning = "";
                                        string message = result.Item2.Message;
                                        Exception e = result.Item2;
                                        if (e is CmisPermissionDeniedException)
                                        {
                                            warning = Properties_Resources.LoginFailedForbidden;
                                        }
                                        else if (e is CmisServerNotFoundException)
                                        {
                                            warning = Properties_Resources.ConnectFailure;
                                        }
                                        else if (e.Message == "SendFailure" && cmisServer.Url.Scheme.StartsWith("https"))
                                        {
                                            warning = Properties_Resources.SendFailureHttps;
                                        }
                                        else if (e.Message == "TrustFailure")
                                        {
                                            warning = Properties_Resources.TrustFailure;
                                        }
                                        else
                                        {
                                            warning = message + Environment.NewLine + Properties_Resources.Sorry;
                                        }
                                        address_error_label.Text = warning;
                                        address_error_label.Visibility = Visibility.Visible;
                                    }
                                    else
                                    {
                                        // Continue to next step, which is choosing a particular folder.
                                        Controller.Add1PageCompleted(
                                            new Uri(address_box.Text), user_box.Text, password_box.Password);
                                    }
                                };
                                break;
                            }
                        #endregion

                        // Second step of the remote folder addition dialog: choosing the folder.
                        #region Page Add2
                        case PageType.Add2:
                            {
                                // UI elements.

                                Header = Properties_Resources.Which;

                                // A tree allowing the user to browse CMIS repositories/folders.
                                /*if(TODO check if OpenDataSpace, and further separate code below)
                                {
                                    System.Uri resourceLocater = new System.Uri("/CmisSync;component/TreeView.xaml", System.UriKind.Relative);
                                    System.Windows.Controls.TreeView treeView = System.Windows.Application.LoadComponent(resourceLocater) as TreeView;
                                    ObservableCollection<CmisRepo> repos = new ObservableCollection<CmisRepo>();
                                */
                                System.Windows.Controls.TreeView treeView = new System.Windows.Controls.TreeView();
                                treeView.Width = 410;
                                treeView.Height = 267;

                                // Some CMIS servers hold several repositories (ex:Nuxeo). Show one root per repository.
                                foreach (KeyValuePair<String, String> repository in Controller.repositories)
                                {
                                    System.Windows.Controls.TreeViewItem item = new System.Windows.Controls.TreeViewItem();
                                    item.Tag = new SelectionTreeItem(repository.Key, "/");
                                    item.Header = repository.Value;
                                    treeView.Items.Add(item);
                                }

                                ContentCanvas.Children.Add(treeView);
                                Canvas.SetTop(treeView, 70);
                                Canvas.SetLeft(treeView, 185);

                                // Action: when an element in the tree is clicked, loads its children and show them.
                                treeView.SelectedItemChanged += delegate
                                {
                                    // Identify the selected remote path.
                                    TreeViewItem item = (TreeViewItem)treeView.SelectedItem;
                                    Controller.saved_remote_path = ((SelectionTreeItem)item.Tag).fullPath;

                                    // Identify the selected repository.
                                    object cursor = item;
                                    while (cursor is TreeViewItem)
                                    {
                                        TreeViewItem treeViewItem = (TreeViewItem)cursor;
                                        cursor = treeViewItem.Parent;
                                        if (!(cursor is TreeViewItem))
                                        {
                                            Controller.saved_repository = ((SelectionTreeItem)treeViewItem.Tag).repository;
                                        }
                                    }

                                    // Load sub-folders if it has not been done already.
                                    // We use each item's Tag to store metadata: whether this item's subfolders have been loaded or not.
                                    if (((SelectionTreeItem)item.Tag).childrenLoaded == false)
                                    {
                                        System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;

                                        // Get list of subfolders (asynchronously)
                                        GetSubfoldersDelegate dlgt = new GetSubfoldersDelegate(CmisUtils.GetSubfolders);
                                        IAsyncResult ar = dlgt.BeginInvoke(Controller.saved_repository,
                                            Controller.saved_remote_path, Controller.saved_address.ToString(),
                                            Controller.saved_user, Controller.saved_password, null, null);
                                        while (!ar.AsyncWaitHandle.WaitOne(100))
                                        {
                                            System.Windows.Forms.Application.DoEvents();
                                        }
                                        string[] subfolders = dlgt.EndInvoke(ar);

                                        // Create a sub-item for each subfolder
                                        foreach (string subfolder in subfolders)
                                        {
                                            System.Windows.Controls.TreeViewItem subItem =
                                                new System.Windows.Controls.TreeViewItem();
                                            subItem.Tag = new SelectionTreeItem(null, subfolder);
                                            subItem.Header = Path.GetFileName(subfolder);
                                            item.Items.Add(subItem);
                                        }
                                        ((SelectionTreeItem)item.Tag).childrenLoaded = true;
                                        item.ExpandSubtree();
                                        System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
                                    }
                                };

                                Button cancel_button = new Button()
                                {
                                    Content = Properties_Resources.Cancel
                                };

                                Button continue_button = new Button()
                                {
                                    Content = CmisSync.Properties_Resources.ResourceManager.GetString("Continue", CultureInfo.CurrentCulture)
                                };

                                Button back_button = new Button()
                                {
                                    Content = Properties_Resources.Back,
                                    IsDefault = false
                                };

                                Buttons.Add(back_button);
                                Buttons.Add(continue_button);
                                Buttons.Add(cancel_button);

                                continue_button.Focus();

                                cancel_button.Click += delegate
                                {
                                    Controller.PageCancelled();
                                };

                                continue_button.Click += delegate
                                {
                                    Controller.Add2PageCompleted(
                                        Controller.saved_repository, Controller.saved_remote_path);
                                };

                                back_button.Click += delegate
                                {
                                    Controller.BackToPage1();
                                };
                                break;
                            }
                        #endregion

                        // Third step of the remote folder addition dialog: Customizing the local folder.
                        #region Page Customize
                        case PageType.Customize:
                            {
                                string parentFolder = Controller.DefaultRepoPath;

                                // UI elements.

                                Header = Properties_Resources.Customize;

                                // Customize local folder name
                                TextBlock localfolder_label = new TextBlock()
                                {
                                    Text = Properties_Resources.EnterLocalFolderName,
                                    FontWeight = FontWeights.Bold,
                                    TextWrapping = TextWrapping.Wrap,
                                    Width = 420
                                };
                                string localfoldername = Controller.saved_address.Host.ToString();
                                foreach (KeyValuePair<String, String> repository in Controller.repositories)
                                {
                                    if (repository.Key == Controller.saved_repository)
                                    {
                                        localfoldername += "\\" + repository.Value;
                                        break;
                                    }
                                }
                                TextBox localfolder_box = new TextBox()
                                {
                                    Width = 420,
                                    Text = localfoldername
                                };

                                TextBlock localrepopath_label = new TextBlock()
                                {
                                    Text = Properties_Resources.ChangeRepoPath,
                                    FontWeight = FontWeights.Bold
                                };

                                TextBox localrepopath_box = new TextBox()
                                {
                                    Width = 375,
                                    Text = Path.Combine(parentFolder, localfolder_box.Text)
                                };

                                localfolder_box.TextChanged += delegate
                                {
                                    localrepopath_box.Text = Path.Combine(parentFolder, localfolder_box.Text);
                                };

                                Button choose_folder_button = new Button()
                                {
                                    Width = 40,
                                    Content = "..."
                                };

                                TextBlock localfolder_error_label = new TextBlock()
                                {
                                    FontSize = 11,
                                    Foreground = new SolidColorBrush(Color.FromRgb(255, 128, 128)),
                                    Visibility = Visibility.Hidden,
                                    TextWrapping = TextWrapping.Wrap
                                };

                                Button cancel_button = new Button()
                                {
                                    Content = Properties_Resources.Cancel
                                };

                                Button add_button = new Button()
                                {
                                    Content = Properties_Resources.Add,
                                    IsDefault = true
                                };

                                Button back_button = new Button()
                                {
                                    Content = Properties_Resources.Back
                                };

                                Buttons.Add(back_button);
                                Buttons.Add(add_button);
                                Buttons.Add(cancel_button);

                                // Local Folder Name
                                ContentCanvas.Children.Add(localfolder_label);
                                Canvas.SetTop(localfolder_label, 160);
                                Canvas.SetLeft(localfolder_label, 185);

                                ContentCanvas.Children.Add(localfolder_box);
                                Canvas.SetTop(localfolder_box, 180);
                                Canvas.SetLeft(localfolder_box, 185);

                                ContentCanvas.Children.Add(localrepopath_label);
                                Canvas.SetTop(localrepopath_label, 200);
                                Canvas.SetLeft(localrepopath_label, 185);

                                ContentCanvas.Children.Add(localrepopath_box);
                                Canvas.SetTop(localrepopath_box, 220);
                                Canvas.SetLeft(localrepopath_box, 185);

                                ContentCanvas.Children.Add(choose_folder_button);
                                Canvas.SetTop(choose_folder_button, 220);
                                Canvas.SetLeft(choose_folder_button, 565);

                                ContentCanvas.Children.Add(localfolder_error_label);
                                Canvas.SetTop(localfolder_error_label, 275);
                                Canvas.SetLeft(localfolder_error_label, 185);

                                TaskbarItemInfo.ProgressValue = 0.0;
                                TaskbarItemInfo.ProgressState = TaskbarItemProgressState.None;

                                localfolder_box.Focus();
                                localfolder_box.Select(localfolder_box.Text.Length, 0);

                                // Actions.

                                Controller.UpdateAddProjectButtonEvent += delegate(bool button_enabled)
                                {
                                    Dispatcher.BeginInvoke((Action)delegate
                                    {
                                        if (add_button.IsEnabled != button_enabled)
                                        {
                                            add_button.IsEnabled = button_enabled;
                                            if (button_enabled)
                                            {
                                                add_button.IsDefault = true;
                                                back_button.IsDefault = false;
                                            }
                                        }
                                    });
                                };

                                // Repo name validity.

                                string error = Controller.CheckRepoPathAndName(localrepopath_box.Text, localfolder_box.Text);

                                if (!String.IsNullOrEmpty(error))
                                {
                                    localfolder_error_label.Text = Properties_Resources.ResourceManager.GetString(error, CultureInfo.CurrentCulture);
                                    localfolder_error_label.Visibility = Visibility.Visible;
                                }
                                else localfolder_error_label.Visibility = Visibility.Hidden;

                                localfolder_box.TextChanged += delegate
                                {
                                    error = Controller.CheckRepoPathAndName(localrepopath_box.Text, localfolder_box.Text);
                                    if (!String.IsNullOrEmpty(error))
                                    {
                                        localfolder_error_label.Text = Properties_Resources.ResourceManager.GetString(error, CultureInfo.CurrentCulture);
                                        localfolder_error_label.Visibility = Visibility.Visible;
                                    }
                                    else localfolder_error_label.Visibility = Visibility.Hidden;
                                };

                                // Repo path validity.

                                error = Controller.CheckRepoPathAndName(localrepopath_box.Text, localfolder_box.Text);
                                if (!String.IsNullOrEmpty(error))
                                {
                                    localfolder_error_label.Text = Properties_Resources.ResourceManager.GetString(error, CultureInfo.CurrentCulture);
                                    localfolder_error_label.Visibility = Visibility.Visible;
                                }
                                else localfolder_error_label.Visibility = Visibility.Hidden;

                                localrepopath_box.TextChanged += delegate
                                {
                                    error = Controller.CheckRepoPathAndName(localrepopath_box.Text, localfolder_box.Text);
                                    if (!String.IsNullOrEmpty(error))
                                    {
                                        localfolder_error_label.Text = Properties_Resources.ResourceManager.GetString(error, CultureInfo.CurrentCulture);
                                        localfolder_error_label.Visibility = Visibility.Visible;

                                    }
                                    else localfolder_error_label.Visibility = Visibility.Hidden;
                                };

                                // Choose a folder.
                                choose_folder_button.Click += delegate
                                {
                                    System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
                                    if (folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                                    {
                                        parentFolder = folderBrowserDialog1.SelectedPath;
                                        localrepopath_box.Text = Path.Combine(parentFolder, localfolder_box.Text);
                                    }
                                };

                                // Other actions.

                                cancel_button.Click += delegate
                                {
                                    Controller.PageCancelled();
                                };

                                back_button.Click += delegate
                                {
                                    Controller.BackToPage2();
                                };

                                add_button.Click += delegate
                                {
                                    Controller.CustomizePageCompleted(localfolder_box.Text, localrepopath_box.Text);
                                };
                                break;
                            }
                        #endregion

                        // Fourth page of the remote folder addition dialog: starting to sync.
                        // TODO: This step should be removed. Now it appears just a brief instant, because sync is asynchronous.
                        #region Page Syncing
                        case PageType.Syncing:
                            {
                                // UI elements.

                                Header = Properties_Resources.AddingFolder + " ‘" + Controller.SyncingReponame + "’…";
                                Description = Properties_Resources.MayTakeTime;

                                Button finish_button = new Button()
                                {
                                    Content = Properties_Resources.Finish,
                                    IsEnabled = false
                                };

                                ProgressBar progress_bar = new ProgressBar()
                                {
                                    Width = 414,
                                    Height = 15,
                                    Value = Controller.ProgressBarPercentage
                                };


                                ContentCanvas.Children.Add(progress_bar);
                                Canvas.SetLeft(progress_bar, 185);
                                Canvas.SetTop(progress_bar, 150);

                                TaskbarItemInfo.ProgressState = TaskbarItemProgressState.Normal;

                                Buttons.Add(finish_button);

                                // Actions.

                                Controller.UpdateProgressBarEvent += delegate(double percentage)
                                {
                                    Dispatcher.BeginInvoke((Action)delegate
                                    {
                                        progress_bar.Value = percentage;
                                        TaskbarItemInfo.ProgressValue = percentage / 100;
                                    });
                                };

                                break;
                            }
                        #endregion

                        // Final page of the remote folder addition dialog: end of the addition wizard.
                        #region Page Finished
                        case PageType.Finished:
                            {
                                // UI elements.

                                Header = Properties_Resources.Ready;
                                Description = Properties_Resources.YouCanFind;

                                Button finish_button = new Button()
                                {
                                    Content = Properties_Resources.Finish
                                };

                                Button open_folder_button = new Button()
                                {
                                    Content = Properties_Resources.OpenFolder
                                };

                                TaskbarItemInfo.ProgressValue = 0.0;
                                TaskbarItemInfo.ProgressState = TaskbarItemProgressState.None;

                                Buttons.Add(open_folder_button);
                                Buttons.Add(finish_button);

                                // Actions.

                                finish_button.Click += delegate
                                {
                                    Controller.FinishPageCompleted();
                                };

                                open_folder_button.Click += delegate
                                {
                                    Controller.OpenFolderClicked();
                                };


                                SystemSounds.Exclamation.Play();

                                break;
                            }
                        #endregion
                    }

                    ShowAll();
                    Logger.Info("Exiting ChangePageEvent.");
                });
            };
            this.Closing += delegate
            {
                Controller.PageCancelled();
            };

            Controller.PageCancelled();
            Logger.Info("Exiting constructor.");
        }
Example #16
0
		public void TagTest2 ()
		{
			Button b = new Button ();
			TestPanel.Children.Add (b);
			b.ApplyTemplate ();
			
			Enqueue (() => {
				TestPanel.Tag = b;
				TestPanel.Tag = null;
				Assert.IsTrue (b.Focus (), "#1");
			});
			EnqueueTestComplete ();
		}
        public AboutDialog(Window owner)
        {
            //어셈블리에서 속성을 구함..  파일 제목 및 버젼 등등 프로그램의 정보를 표시하기 위함임.

            //속성에 접근하기 위해 executing assembly를 구함
            Assembly asmbly = Assembly.GetExecutingAssembly();

            //프로그램 이름을 위해 AssemblyTitle 속성을 구함
            AssemblyTitleAttribute title = (AssemblyTitleAttribute)asmbly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false)[0];
            string strTitle = title.Title;

            //AssemblyFileVersion 속성을 구함(버젼 속성)

            AssemblyFileVersionAttribute version = (AssemblyFileVersionAttribute)asmbly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false)[0];
            string strVersion = version.Version.Substring(0, 3);

            //AssemblyCopyRight 속성을 구함(저작권 관련 속성)
            AssemblyCopyrightAttribute copy = (AssemblyCopyrightAttribute)asmbly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false)[0];
            string strCopyright = copy.Copyright;

            //대화상자의 표준 윈도우 프로퍼티

            Title = "About" + strTitle;                              //Dialog 타이틀바의 내용
            ShowInTaskbar = false;                                  //작업 표시줄에 표현 여부
            SizeToContent = SizeToContent.WidthAndHeight;           //창의 너비와 높이가 콘텐츠의 너비와 높이에 맞게 설정
            ResizeMode = ResizeMode.NoResize;                       //창크기 조정 여부..(조정 불가로 설정 - NoResize)
            Left = owner.Left + 96;
            Top = owner.Top + 96;                                   //다이얼로그 창을 만든 윈도우의 Left 96 Top 96 의 위치에 위치시킴

            //윈도우 Content를 위한 스택 패널 생성
            StackPanel stackMain = new StackPanel();
            Content = stackMain;                                    //해당 다이얼로그와 StackPanel을 연결함.

            //프로그램 명을 위한 텍스트 블록 생성
            TextBlock txtblk = new TextBlock();                      //텍스트 블록 객체 생성
            txtblk.Text = strTitle + "Version : " + strVersion + "\r\n" + strCopyright;         //텍스트 블록 내의 내용
            txtblk.FontFamily = new FontFamily("Times New Roman");   //폰트 설정
            txtblk.FontSize = 32;                                    //24포인트로 폰트 크기 설정
            txtblk.FontStyle = FontStyles.Italic;                    //폰트 스타일 설정
            txtblk.Margin = new Thickness(24);                       //여백 설정
            txtblk.HorizontalAlignment = HorizontalAlignment.Center; //텍스트 블록의 위치

            stackMain.Children.Add(txtblk);                          //StackPanel에 텍스트 블록 추가

            //웹사이트 링크를 위한 텍스트 블록 생성
            Run run = new Run("http://cyworld.com/1988_01_29");      //웹사이트 링크 주소 설정
            Hyperlink link = new Hyperlink(run);                     //하이퍼링크 설정
            link.Click += LinkOnClick;                               //링크를 클릭 했을 때 이벤트 발생!
            txtblk = new TextBlock(link);                            //하이퍼링크를 위한 텍스트 블록 생성
            txtblk.FontSize = 20;                                    //웹사이트 링크의 폰트 사이즈
            txtblk.HorizontalAlignment = HorizontalAlignment.Center; //웹사이트 링크의 위치

            stackMain.Children.Add(txtblk);                          //StackPanel에 추가함

            //OK버튼 생성
            Button btn = new Button();
            btn.Content = "OK";
            btn.IsDefault = true;                                   //기본 단추로 설정
            btn.IsCancel = true;                                    //취소 단추인지 설정.. ESC로도 활성화 가능!
            btn.HorizontalAlignment = HorizontalAlignment.Center;   //정렬은 중앙에
            btn.MinWidth = 48;                                      //최소 48픽셀의 가로 크기를 가진다.
            btn.Margin = new Thickness(24);                         //여백은 24포인트
            btn.Click += OkOnClick;                                 //OK를 클릭 했을 때 설정

            stackMain.Children.Add(btn);                            //스택 메인에 추가함

            btn.Focus();                                            //최초 버튼이 포커스를 가지고 있게 설정함.
        }