/// <summary> /// Selects contents /// </summary> /// <param name="start">Start</param> /// <param name="length">Length</param> public void Select(int start, int length) { if (textBoxTemplated != null) { textBoxTemplated.Select(start, length); } else { textBox.Select(start, length); } }
public IMyTextBox addPlaceholderText(string placeholderText) { if (string.IsNullOrWhiteSpace(myTextBox_txt.Text)) { myTextBox_txt.Text = placeholderText; } myTextBox_txt.SetResourceReference(Control.ForegroundProperty, myTextBox_txt.Text != placeholderText ? "SystemControlForegroundBaseHighBrush" : "SystemControlForegroundBaseMediumBrush"); var ignoreSelectionChanged = false; myTextBox_txt.SelectionChanged += (sender, args) => { if (ignoreSelectionChanged) { ignoreSelectionChanged = false; return; } if (myTextBox_txt.Text != placeholderText) { return; } ignoreSelectionChanged = true; myTextBox_txt.Select(0, 0); }; var lastText = myTextBox_txt.Text; var ignoreTextChanged = false; myTextBox_txt.TextChanged += (sender, args) => { if (ignoreTextChanged) { ignoreTextChanged = false; return; } if (string.IsNullOrWhiteSpace(myTextBox_txt.Text)) { ignoreTextChanged = true; myTextBox_txt.Text = placeholderText; myTextBox_txt.Select(0, 0); } else if (lastText == placeholderText) { ignoreTextChanged = true; myTextBox_txt.Text = myTextBox_txt.Text.Substring(0, 1); myTextBox_txt.Select(1, 0); } myTextBox_txt.SetResourceReference(Control.ForegroundProperty, myTextBox_txt.Text != placeholderText ? "SystemControlForegroundBaseHighBrush" : "SystemControlForegroundBaseMediumBrush"); lastText = myTextBox_txt.Text; }; return(this); }
/// <summary> /// Texts the box user name text changed. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.Windows.Controls.TextChangedEventArgs"/> instance containing the event data.</param> private void textBoxPort_Changed( object sender, TextChangedEventArgs e) { System.Windows.Controls.TextBox textBox = sender as System.Windows.Controls.TextBox; if (textBox != null) { string port = textBox.Text; int index = 0; while (port.Length > index) { if (!Char.IsNumber(port, index)) { port = port.Remove(index, 1); } else { index++; } } textBox.Text = port; textBox.Select(textBox.Text.Length, 0); } this.SetNextButtonState(); }
/// <summary> /// Selects the highlight as the current highlight when iterating through hits, bringing the control to focus. /// </summary> public override void Select() { System.Windows.Controls.TextBox tb = (BodyAdorner.AdornedElement as System.Windows.Controls.TextBox); tb.Focus();//focusing is very important because not only is it correct user behaviour but it also allows us to track the user moving focus to other controls better tb.Select(Start, End - Start); base.Select(); }
private void DodajText(System.Windows.Controls.TextBox TextBox, string Text, System.Drawing.Color Color) { var StartIndex = TextBox.Text.Length; TextBox.AppendText(Text); var EndIndex = TextBox.Text.Length; TextBox.Select(StartIndex, EndIndex - StartIndex); }
/// <summary> /// When overridden in a derived class, is invoked whenever /// application code or internal processes call ApplyTemplate /// </summary> public override void OnApplyTemplate() { if (textBoxTemplated != null) { textBoxTemplated.PreviewKeyDown -= OnTextBoxTemplatedKeyDown; textBoxTemplated.SelectionChanged -= OnTextBoxTemplatedSelectionChanged; textBoxTemplated.LostFocus -= OnTextBoxTemplatedLostFocus; textBoxTemplated.GotKeyboardFocus -= OnTextBoxTemplatedGotKeyboardFocus; textBoxTemplated.TextChanged -= OnTextBoxTemplatedTextChanged; BindingOperations.ClearAllBindings(textBoxTemplated); } textBoxTemplated = GetTemplateChild("PART_TextBox") as System.Windows.Controls.TextBox; // Check template if (!IsTemplateValid()) { Debug.WriteLine("Template for TextBox control is invalid"); return; } textBoxTemplated.Text = Text; textBoxTemplated.Select(textBox.SelectionStart, textBox.SelectionLength); // Bindings BindingOperations.ClearAllBindings(textBox); Binding binding = new Binding("Text"); binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; binding.Source = this; binding.Mode = BindingMode.TwoWay; textBoxTemplated.SetBinding(System.Windows.Controls.TextBox.TextProperty, binding); Bind(this, textBoxTemplated, "CharacterCasing", System.Windows.Controls.TextBox.CharacterCasingProperty, BindingMode.TwoWay); Bind(this, textBoxTemplated, "MaxLength", System.Windows.Controls.TextBox.MaxLengthProperty, BindingMode.TwoWay); Bind(this, textBoxTemplated, "TextAlignment", System.Windows.Controls.TextBox.TextAlignmentProperty, BindingMode.TwoWay); Bind(this, textBoxTemplated, "TextDecorations", System.Windows.Controls.TextBox.TextDecorationsProperty, BindingMode.TwoWay); Bind(this, textBoxTemplated, "IsUndoEnabled", System.Windows.Controls.TextBox.IsUndoEnabledProperty, BindingMode.TwoWay); Bind(this, textBoxTemplated, "UndoLimit", System.Windows.Controls.TextBox.UndoLimitProperty, BindingMode.TwoWay); Bind(this, textBoxTemplated, "AutoWordSelection", System.Windows.Controls.TextBox.AutoWordSelectionProperty, BindingMode.TwoWay); #if NET35 #else Bind(this, textBoxTemplated, "SelectionBrush", System.Windows.Controls.TextBox.SelectionBrushProperty, BindingMode.TwoWay); Bind(this, textBoxTemplated, "SelectionOpacity", System.Windows.Controls.TextBox.SelectionOpacityProperty, BindingMode.TwoWay); Bind(this, textBoxTemplated, "CaretBrush", System.Windows.Controls.TextBox.CaretBrushProperty, BindingMode.TwoWay); #endif Bind(this, textBoxTemplated, "IsReadOnly", System.Windows.Controls.TextBox.IsReadOnlyProperty, BindingMode.TwoWay); textBoxTemplated.PreviewKeyDown += OnTextBoxTemplatedKeyDown; textBoxTemplated.SelectionChanged += OnTextBoxTemplatedSelectionChanged; textBoxTemplated.LostFocus += OnTextBoxTemplatedLostFocus; textBoxTemplated.GotKeyboardFocus += OnTextBoxTemplatedGotKeyboardFocus; textBoxTemplated.TextChanged += OnTextBoxTemplatedTextChanged; }
private void AppendText(TextBox tb, string text) { // Appends Rightclick-Text from the output text box (parameters) tb.AppendText(text); tb.Select(TxtbxOutputformat.Text.Length, 0); if (tb.ContextMenu != null) { tb.ContextMenu.IsOpen = false; } }
private void AppendText(System.Windows.Controls.TextBox tb, string text) { tb.AppendText(text); tb.Select(this.TxtbxOutputformat.Text.Length, 0); if (tb.ContextMenu == null) { return; } tb.ContextMenu.IsOpen = false; }
public static void OnTextChange(string path, TextBox textBox) { //var textBox = sender ?? throw new NullReferenceException("TextBoxContent is null"); textBox.Text = path; textBox.Focus(); var length = System.IO.Path.GetFileName(path).Length; textBox.Select(path.Length - length, length); textBox.ToolTip = path; }
public static void doMask(bool textBoxChanged,TextBox textb) { if (textBoxChanged) { if (textb.Text.Trim().Length == 0) return; String s = getStringFromMasked(textb.Text); String res = doMaskOnce(s); if (res != "" && textb.Text!=res) { textb.Text = res; textb.Select(textb.Text.Length, 0); } textBoxChanged = false; } }
private void TextBox_TextChanged(object sender, TextChangedEventArgs e) { System.Windows.Controls.TextBox t = (System.Windows.Controls.TextBox)sender; try { if (Convert.ToDouble(t.Text) >= 0) { } } catch { if (t.Text == "-") { t.Text = "-0"; t.Select(1, 1); } else { t.Text = "0"; t.Select(0, 1); } } this.scale = Convert.ToDouble(t.Text); }
private void zongliang_TextChanged(object sender, TextChangedEventArgs e) { System.Windows.Controls.TextBox textBox = sender as System.Windows.Controls.TextBox; TextChange[] change = new TextChange[e.Changes.Count]; e.Changes.CopyTo(change, 0); int offset = change[0].Offset; if (change[0].AddedLength > 0) { double num = 0; if (!Double.TryParse(textBox.Text, out num)) { textBox.Text = textBox.Text.Remove(offset, change[0].AddedLength); textBox.Select(offset, 0); } } }
/// <summary> /// WPFTextBox只能输入数字 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TextBoxR_TextChanged(object sender, TextChangedEventArgs e) { System.Windows.Controls.TextBox temptbox = sender as System.Windows.Controls.TextBox; //此句可能是为保护原框,也可能只是为了用一下sender -.- TextChange[] change = new TextChange[e.Changes.Count]; // e.Changes.CopyTo(change, 0); //得到Change的内容 int offset = change[0].Offset; //得到Change的偏置值(offset) 可理解为变化的起始位置 if (change[0].AddedLength > 0) //如果是内容增加 则执行 { //其实没啥用 但是没这个变量TryParse函数不能用 if (temptbox.Text.IndexOf(' ') != -1 || !double.TryParse(temptbox.Text, out double num)) //Text.IndexOf检测某字符首次出现的位置,此处用来检测是否有空格 //int.TryParse返回是字符串是否转为数字,此处用来检测字符串是纯数字 //float,double应该也有类似的函数,可以用来实现小数检测 { temptbox.Text = temptbox.Text.Remove(offset, change[0].AddedLength);//去除change TaskDialog.Show("输入错误", "只能输入数字,请重新输入!"); Activate(); temptbox.Select(offset, 0); //恢复原状 } } }
private void HeightTextBox_OnTextChanged(object sender, TextChangedEventArgs e) { this.ButtonApply.IsEnabled = true; this.ButtonCancel.IsEnabled = true; //屏蔽中文输入和非法字符粘贴输入 TextBox textBox = sender as TextBox; TextChange[] change = new TextChange[e.Changes.Count]; e.Changes.CopyTo(change, 0); int offset = change[0].Offset; if (change[0].AddedLength > 0) { double num = 0; if (!Double.TryParse(textBox.Text, out num)) { textBox.Text = textBox.Text.Remove(offset, change[0].AddedLength); textBox.Select(offset, 0); } } }
private void ComboBox_TextChanged(object sender, TextChangedEventArgs e) { if (comboBox.Text != "" && comboBox.Text != temptext && 1 == 2) { Newtonsoft.Json.Linq.JArray b = idlist; var d = b.ToList(); var cc = d.FindAll(x => x != null && Regex.Match(x["name"].ToString(), "^" + comboBox.Text, RegexOptions.IgnoreCase).Success); if (cc.Count > 0) { var c = cc.OrderBy(x => x["name"].ToString().Length).Take(10); clearcombo(); foreach (var a in c) { comboBox.Items.Add(a["name"].ToString()); } comboBox.IsDropDownOpen = true; System.Windows.Controls.TextBox tb = (System.Windows.Controls.TextBox)comboBox.Template.FindName("PART_EditableTextBox", comboBox); tb.Select(tb.Text.Length, 0); } else { clearcombo(); } } if (temptext != comboBox.Text) { comboBox.IsDropDownOpen = true; System.Windows.Controls.TextBox tb = (System.Windows.Controls.TextBox)comboBox.Template.FindName("PART_EditableTextBox", comboBox); tb.Select(tb.Text.Length, 0); } loadFromName(); }
public SparkleSetup() { Controller.ShowWindowEvent += delegate { Dispatcher.Invoke ((Action) delegate { Show (); Activate (); BringIntoView (); }); }; Controller.HideWindowEvent += delegate { Dispatcher.Invoke ((Action) delegate { Hide (); }); }; Controller.ChangePageEvent += delegate (PageType type, string [] warnings) { Dispatcher.Invoke ((Action) delegate { Reset (); switch (type) { case PageType.Setup: { Header = "Welcome to SparkleShare!"; Description = "Before we get started, what's your name and email?\n" + "Don't worry, this information will only visible to any team members."; TextBlock name_label = new TextBlock () { Text = "Full Name:", Width = 150, TextAlignment = TextAlignment.Right, FontWeight = FontWeights.Bold }; TextBox name_box = new TextBox () { Text = Controller.GuessedUserName, Width = 175 }; TextBlock email_label = new TextBlock () { Text = "Email:", Width = 150, TextAlignment = TextAlignment.Right, FontWeight = FontWeights.Bold }; TextBox email_box = new TextBox () { Width = 175, Text = Controller.GuessedUserEmail }; Button cancel_button = new Button () { Content = "Cancel" }; Button continue_button = new Button () { Content = "Continue", IsEnabled = false }; ContentCanvas.Children.Add (name_label); Canvas.SetLeft (name_label, 180); Canvas.SetTop (name_label, 200 + 3); ContentCanvas.Children.Add (name_box); Canvas.SetLeft (name_box, 340); Canvas.SetTop (name_box, 200); ContentCanvas.Children.Add (email_label); Canvas.SetLeft (email_label, 180); Canvas.SetTop (email_label, 230 + 3); ContentCanvas.Children.Add (email_box); Canvas.SetLeft (email_box, 340); Canvas.SetTop (email_box, 230); Buttons.Add (continue_button); Buttons.Add (cancel_button); name_box.Focus (); name_box.Select (name_box.Text.Length, 0); Controller.UpdateSetupContinueButtonEvent += delegate (bool enabled) { Dispatcher.Invoke ((Action) delegate { continue_button.IsEnabled = enabled; }); }; name_box.TextChanged += delegate { Controller.CheckSetupPage (name_box.Text, email_box.Text); }; email_box.TextChanged += delegate { Controller.CheckSetupPage (name_box.Text, email_box.Text); }; cancel_button.Click += delegate { Dispatcher.Invoke ((Action) delegate { SparkleUI.StatusIcon.Dispose (); Controller.SetupPageCancelled (); }); }; continue_button.Click += delegate { Controller.SetupPageCompleted (name_box.Text, email_box.Text); }; Controller.CheckSetupPage (name_box.Text, email_box.Text); 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.Add: { Header = "Where's your project hosted?"; ListView list_view = new ListView () { Width = 419, Height = 195, SelectionMode = SelectionMode.Single }; GridView grid_view = new GridView () { AllowsColumnReorder = false }; grid_view.Columns.Add (new GridViewColumn ()); string xaml = "<DataTemplate xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"" + " xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\">" + " <Grid>" + " <StackPanel Orientation=\"Horizontal\">" + " <Image Margin=\"5,0,0,0\" Source=\"{Binding Image}\" Height=\"24\" Width=\"24\"/>" + " <StackPanel>" + " <TextBlock Padding=\"10,4,0,0\" FontWeight=\"Bold\" Text=\"{Binding Name}\">" + " </TextBlock>" + " <TextBlock Padding=\"10,0,0,4\" Opacity=\"0.5\" Text=\"{Binding Description}\">" + " </TextBlock>" + " </StackPanel>" + " </StackPanel>" + " </Grid>" + "</DataTemplate>"; grid_view.Columns [0].CellTemplate = (DataTemplate) XamlReader.Parse (xaml); Style header_style = new Style(typeof (GridViewColumnHeader)); header_style.Setters.Add (new Setter (GridViewColumnHeader.VisibilityProperty, Visibility.Collapsed)); grid_view.ColumnHeaderContainerStyle = header_style; foreach (SparklePlugin plugin in Controller.Plugins) { BitmapFrame image = BitmapFrame.Create ( new Uri (plugin.ImagePath) ); list_view.Items.Add ( new { Name = plugin.Name, Description = plugin.Description, Image = image } ); } list_view.View = grid_view; list_view.SelectedIndex = Controller.SelectedPluginIndex; TextBlock address_label = new TextBlock () { Text = "Address:", FontWeight = FontWeights.Bold }; TextBox address_box = new TextBox () { Width = 200, Text = Controller.PreviousAddress, IsEnabled = (Controller.SelectedPlugin.Address == null) }; TextBlock address_help_label = new TextBlock () { Text = "", FontSize = 11, Foreground = new SolidColorBrush (Color.FromRgb (128, 128, 128)) }; TextBlock path_label = new TextBlock () { Text = "Remote Path:", FontWeight = FontWeights.Bold, Width = 200 }; TextBox path_box = new TextBox () { Width = 200, Text = Controller.PreviousPath, IsEnabled = (Controller.SelectedPlugin.Path == null) }; TextBlock path_help_label = new TextBlock () { Text = "", FontSize = 11, Width = 200, Foreground = new SolidColorBrush (Color.FromRgb (128, 128, 128)) }; Button cancel_button = new Button () { Content = "Cancel" }; Button add_button = new Button () { Content = "Add" }; ContentCanvas.Children.Add (list_view); Canvas.SetTop (list_view, 70); Canvas.SetLeft (list_view, 185); ContentCanvas.Children.Add (address_label); Canvas.SetTop (address_label, 285); Canvas.SetLeft (address_label, 185); ContentCanvas.Children.Add (address_box); Canvas.SetTop (address_box, 305); Canvas.SetLeft (address_box, 185); ContentCanvas.Children.Add (address_help_label); Canvas.SetTop (address_help_label, 330); Canvas.SetLeft (address_help_label, 185); ContentCanvas.Children.Add (path_label); Canvas.SetTop (path_label, 285); Canvas.SetRight (path_label, 30); ContentCanvas.Children.Add (path_box); Canvas.SetTop (path_box, 305); Canvas.SetRight (path_box, 30); ContentCanvas.Children.Add (path_help_label); Canvas.SetTop (path_help_label, 330); Canvas.SetRight (path_help_label, 30); Buttons.Add (add_button); Buttons.Add (cancel_button); address_box.Focus (); address_box.Select (address_box.Text.Length, 0); Controller.ChangeAddressFieldEvent += delegate (string text, string example_text, FieldState state) { Dispatcher.Invoke ((Action) delegate { address_box.Text = text; address_box.IsEnabled = (state == FieldState.Enabled); address_help_label.Text = example_text; }); }; Controller.ChangePathFieldEvent += delegate (string text, string example_text, FieldState state) { Dispatcher.Invoke ((Action) delegate { path_box.Text = text; path_box.IsEnabled = (state == FieldState.Enabled); path_help_label.Text = example_text; }); }; Controller.UpdateAddProjectButtonEvent += delegate (bool button_enabled) { Dispatcher.Invoke ((Action) delegate { add_button.IsEnabled = button_enabled; }); }; list_view.SelectionChanged += delegate { Controller.SelectedPluginChanged (list_view.SelectedIndex); }; list_view.KeyDown += delegate { Controller.SelectedPluginChanged (list_view.SelectedIndex); }; Controller.CheckAddPage (address_box.Text, path_box.Text, list_view.SelectedIndex); address_box.TextChanged += delegate { Controller.CheckAddPage (address_box.Text, path_box.Text, list_view.SelectedIndex); }; path_box.TextChanged += delegate { Controller.CheckAddPage (address_box.Text, path_box.Text, list_view.SelectedIndex); }; cancel_button.Click += delegate { Controller.PageCancelled (); }; add_button.Click += delegate { Controller.AddPageCompleted (address_box.Text, path_box.Text); }; break; } case PageType.Syncing: { Header = "Adding project ‘" + Controller.SyncingFolder + "’…"; Description = "This may take a while.\n" + "Are you sure it’s not coffee o'clock?"; 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 = 1 }; ContentCanvas.Children.Add (progress_bar); Canvas.SetLeft (progress_bar, 185); Canvas.SetTop (progress_bar, 150); Buttons.Add (finish_button); Buttons.Add (cancel_button); Controller.UpdateProgressBarEvent += delegate (double percentage) { Dispatcher.Invoke ((Action) delegate { progress_bar.Value = percentage; }); }; cancel_button.Click += delegate { Controller.SyncingCancelled (); }; break; } case PageType.Error: { Header = "Something went wrong…"; Description = "Please check the following:"; TextBlock help_block = new TextBlock () { TextWrapping = TextWrapping.Wrap, Width = 310 }; help_block.Inlines.Add ("Is the host online?\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 ("The host needs to know who you are. Did you upload the key that's in your SparkleShare folder?"); TextBlock bullets_block = new TextBlock () { Text = "•\n\n•\n\n\n•" }; 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); 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 = "Project ‘" + Path.GetFileName (Controller.PreviousPath) + "’ succesfully added!"; Description = "Access the files from your SparkleShare folder."; Button finish_button = new Button () { Content = "Finish" }; Button open_folder_button = new Button () { Content = "Open folder" }; if (warnings != null) { Image warning_image = new Image () { Source = Imaging.CreateBitmapSourceFromHIcon (Drawing.SystemIcons.Warning.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); } Buttons.Add (finish_button); Buttons.Add (open_folder_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 = "SparkleShare creates a special folder on your computer " + "that will keep track of your projects."; WPF.Image slide_image = new WPF.Image () { Width = 350, Height = 200 }; slide_image.Source = SparkleUIHelpers.GetImageSource ("tutorial-slide-1-windows"); 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 your project folders are synced automatically with " + "the host and your team members."; 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-windows"); ContentCanvas.Children.Add (slide_image); Canvas.SetLeft (slide_image, 215); Canvas.SetTop (slide_image, 130); Buttons.Add (continue_button); continue_button.Click += delegate { Controller.TutorialPageCompleted (); }; break; } case 3: { Header = "The status icon is here to help"; Description = "It shows the syncing progress, provides easy access to " + "your projects and let's you view recent changes."; 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-windows"); ContentCanvas.Children.Add (slide_image); Canvas.SetLeft (slide_image, 215); Canvas.SetTop (slide_image, 130); Buttons.Add (continue_button); continue_button.Click += delegate { Controller.TutorialPageCompleted (); }; break; } case 4: { Header = "Adding projects to SparkleShare"; Description = "You can do this through the status icon menu, or by clicking " + "magic buttons on webpages that look like this:"; Button finish_button = new Button () { Content = "Finish" }; WPF.Image slide_image = new WPF.Image () { Width = 350, Height = 64 }; slide_image.Source = SparkleUIHelpers.GetImageSource ("tutorial-slide-4"); CheckBox check_box = new CheckBox () { Content = "Add SparkleShare 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 (); }); }; }
/// <summary> /// 将textbox中的光标移动到最后 /// </summary> /// <param name="textbox"><see cref="TextBox"/></param> private static void SetSelectTextToEnd(TextBox textbox) { textbox.Select(textbox.Text.Length, textbox.Text.Length); }
private void Suggest(TextBox textBox, Regex matchAndReplace, int offset) { if (ignoreKey || friends == null) return; List<String> currentFriends = new List<string>(); string selectedText = string.Empty; Match matchedText = Match.Empty; if (isInAutocompleteMode) { ignoreKey = true; selectedText = textBox.SelectedText; textBox.SelectedText = string.Empty; ignoreKey = false; } int length = textBox.Text.Length; isInAutocompleteMode = matchAndReplace.IsMatch(textBox.Text); if (!isInAutocompleteMode) { ShowStatus(string.Empty); return; } matchedText = matchAndReplace.Match(textBox.Text); int selectedIndex = 0; if (matchedText.Success) { string userEnteredText = matchedText.Groups[2].Value; { foreach (User friend in friends) { if (friend.ScreenName.StartsWith(userEnteredText, StringComparison.CurrentCultureIgnoreCase) || userEnteredText.Length == 0) currentFriends.Add(friend.ScreenName); } } if (currentFriends.Count != 0) { currentFriends.Sort(); selectedIndex = currentFriends.IndexOf(userEnteredText + selectedText); if (selectedIndex < 0) selectedIndex = 0; selectedIndex += offset; if (selectedIndex < 0) selectedIndex = currentFriends.Count - 1; else if (selectedIndex > (currentFriends.Count - 1)) selectedIndex = 0; ignoreKey = true; textBox.Text = matchAndReplace.Replace(textBox.Text, String.Format("${{1}}{0}", currentFriends[selectedIndex])); textBox.Select(length, textBox.Text.Length - length); ignoreKey = false; ShowStatus(string.Format("{0} matching - [Up/Down] to cycle, [Tab] to select",currentFriends.Count)); } } }
private void LoadAddCustomizeWPF() { string parentFolder = Controller.DefaultRepoPath; // UI elements. Header = Properties_Resources.Customize; System.Uri resourceLocater = new System.Uri("/DataSpaceSync;component/SetupAddCustomizeWPF.xaml", System.UriKind.Relative); UserControl LoadXAML = Application.LoadComponent(resourceLocater) as UserControl; localfolder_label = LoadXAML.FindName("localfolder_label") as TextBlock; localfolder_box = LoadXAML.FindName("localfolder_box") as TextBox; localrepopath_label = LoadXAML.FindName("localrepopath_label") as TextBlock; localrepopath_box = LoadXAML.FindName("localrepopath_box") as TextBox; localfolder_error_label = LoadXAML.FindName("localfolder_error_label") as TextBlock; choose_folder_button = LoadXAML.FindName("choose_folder_button") as Button; back_button = LoadXAML.FindName("back_button") as Button; continue_button = LoadXAML.FindName("continue_button") as Button; cancel_button = LoadXAML.FindName("cancel_button") as Button; // init UI elements. string localfoldername = Controller.saved_address.Host.ToString(); foreach (var repository in Controller.repositories) { if (repository.Id == Controller.saved_repository) { localfoldername += "\\" + repository.Name; break; } } localfolder_box.Text = localfoldername; localrepopath_box.Text = Path.Combine(parentFolder, localfolder_box.Text); ContentCanvas.Children.Add(LoadXAML); localfolder_box.TextChanged += delegate { try { localrepopath_box.Text = Path.Combine(parentFolder, localfolder_box.Text); } catch (Exception) { } }; TaskbarItemInfo.ProgressValue = 0.0; TaskbarItemInfo.ProgressState = TaskbarItemProgressState.None; // Actions. ControllerCustomizeInsertAction(); // Repo path validity. CheckCustomizeInput(localfolder_box, localrepopath_box, localfolder_error_label); localfolder_box.Select(localfolder_box.Text.Length, 0); localfolder_box.Focus(); localfolder_box.TextChanged += delegate { CheckCustomizeInput(localfolder_box, localrepopath_box, localfolder_error_label); }; localrepopath_box.TextChanged += delegate { CheckCustomizeInput(localfolder_box, localrepopath_box, localfolder_error_label); }; // 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 { ControllerCustomizeRemoveAction(); Controller.PageCancelled(); }; back_button.Click += delegate { ControllerCustomizeRemoveAction(); Controller.BackToPage2(); }; continue_button.Click += delegate { ControllerCustomizeRemoveAction(); Controller.CustomizePageCompleted(localfolder_box.Text, localrepopath_box.Text); }; }
private static bool PlaceCaretOnTextBox(TextBox textBox, Point position) { int characterIndex = textBox.GetCharacterIndexFromPoint(position, /* snapToText = */ false); if (characterIndex >= 0) { textBox.Select(characterIndex, 0); return true; } return false; }
public CustomMessageBox( string caption, CustomMessageBoxIcon icon = CustomMessageBoxIcon.Default, CustomMessageBoxButtons buttons = CustomMessageBoxButtons.None, List <string> messageRows = null, string prompt = null, CustomMessageBoxPromptValidation promptValidationMode = CustomMessageBoxPromptValidation.None, CustomMessageBoxFocus controlFocus = CustomMessageBoxFocus.Default) { DataContext = this; InitializeComponent(); if (DesignerProperties.GetIsInDesignMode(this)) { } else { // ToDo: Evil Hack to have the cake (see actual design in design mode) and eat it too (have different styles at runtime) this.Resources = null; } int currentIndex = 0; this.Title = caption; this.promptValidationMode = promptValidationMode; this.controlFocus = controlFocus; var rowCaption = new RowDefinition(); rowCaption.Height = GridLength.Auto; ContentGrid.RowDefinitions.Add(rowCaption); var captionTextBox = new System.Windows.Controls.TextBlock(); var captionStyle = (Style)FindResource("VersionName_TextBox_Style"); if (captionStyle != null) { captionTextBox.Style = captionStyle; } captionTextBox.Text = caption; ContentGrid.InsertAt(captionTextBox, 0, currentIndex); currentIndex++; switch (icon) { case CustomMessageBoxIcon.Information: { var informationStyle = (Style)FindResource("CustomMessageBoxInformationIconStyle"); if (informationStyle != null) { DialogImage.Style = informationStyle; } break; } case CustomMessageBoxIcon.Question: { var questionStyle = (Style)FindResource("CustomMessageBoxQuestionIconStyle"); if (questionStyle != null) { DialogImage.Style = questionStyle; } break; } case CustomMessageBoxIcon.Error: { var errorStyle = (Style)FindResource("CustomMessageBoxErrorIconStyle"); if (errorStyle != null) { DialogImage.Style = errorStyle; } break; } case CustomMessageBoxIcon.Default: { var defaultStyle = (Style)FindResource("CustomMessageBoxDefaultIconStyle"); if (defaultStyle != null) { DialogImage.Style = defaultStyle; } break; } } var textblockStyle = (Style)FindResource("CustomMessageBox_TextBlock_Style"); if (messageRows != null && messageRows.Any()) { foreach (var messgeRow in messageRows) { var rowDefinition = new RowDefinition(); rowDefinition.Height = GridLength.Auto; ContentGrid.RowDefinitions.Add(rowDefinition); var tempTextBox = new System.Windows.Controls.TextBlock(); if (textblockStyle != null) { tempTextBox.Style = textblockStyle; } tempTextBox.Text = messgeRow; ContentGrid.InsertAt(tempTextBox, 0, currentIndex); currentIndex++; } } if (prompt != null) { var promptRow = new RowDefinition(); promptRow.Height = GridLength.Auto; ContentGrid.RowDefinitions.Add(promptRow); promptTextBox = new System.Windows.Controls.TextBox(); var promptStyle = (Style)FindResource("MainWindowTextBoxStyle"); if (promptStyle != null) { promptTextBox.Style = promptStyle; } promptTextBox.Name = "DialogPromptTextBox"; promptTextBox.IsEnabled = true; promptTextBox.IsReadOnly = false; promptTextBox.TextChanged += PromptTextBox_TextChanged; promptTextBox.Text = prompt; ContentGrid.InsertAt(promptTextBox, 0, currentIndex); if (controlFocus == CustomMessageBoxFocus.Prompt) { promptTextBox.Focus(); promptTextBox.Select(0, prompt.Length); } currentIndex++; } if (buttons != CustomMessageBoxButtons.None) { var tempButton = new SvgImageButton1(); var buttonStyle = (Style)FindResource("SvgAcceptButton"); if (buttonStyle != null) { tempButton.Style = buttonStyle; } tempButton.HorizontalAlignment = HorizontalAlignment.Right; tempButton.Click += OkButton_Click; tempButton.IsDefault = true; DialogGrid.InsertAt(tempButton, 1, 3); if (controlFocus == CustomMessageBoxFocus.Ok) { tempButton.Focus(); } if (buttons == CustomMessageBoxButtons.OkAndCancel) { var cancelButton = new SvgImageButton1(); var cancelButtonStyle = (Style)FindResource("SvgCancelButton"); if (cancelButtonStyle != null) { cancelButton.Style = cancelButtonStyle; } cancelButton.HorizontalAlignment = HorizontalAlignment.Left; cancelButton.Click += CancelButton_Click; DialogGrid.InsertAt(cancelButton, 0, 3); if (controlFocus == CustomMessageBoxFocus.Cancel) { cancelButton.Focus(); } } currentIndex++; } }
/// <summary> /// TextBoxの内容が変化したときの処理 /// </summary> /// <param name="textBox"></param> public void SubscribeTextChanged(TextBox textBox) { var textChanged = Observable.FromEvent<TextChangedEventHandler, TextChangedEventArgs> (h => (sender, e) => h(e), h => textBox.TextChanged += h, h => textBox.TextChanged -= h); //カーソルを末尾に移動させる this.TextHistoryIndex .Buffer(textChanged.Where(y => textBox.Text.Length > 0)) .Where(y => y.Count > 0) .Subscribe(y => textBox.Select(textBox.Text.Length, 0)) .AddTo(this.Disposables); textChanged .Where(x => this.TextHistory.ContainsIndex(this.TextHistoryIndex.Value) && textBox.Text != this.TextHistory[this.TextHistoryIndex.Value]) .Subscribe(x => { this.InputText = textBox.Text; this.textEdited = true; //this.TextHistoryIndex.Value = this.TextHistory.Count; }) .AddTo(this.Disposables); }
private void SelectText(TextBox box, bool selectAll, string text) { ControlFocus.GiveFocus(box, delegate { if (selectAll) box.SelectAll(); else if (!string.IsNullOrEmpty(text)) { int pos = box.Text.IndexOf(text); if (pos > 0 && box.Text.Contains(text)) box.Select(pos, text.Length); } }); }
static void Main(string[] args) { var c = new JSCSolutionsNETCarouselCanvas { CloseOnClick = false }; c.HideSattelites(); //c.Container.Effect = new DropShadowEffect(); //c.Container.BitmapEffect = new DropShadowBitmapEffect(); //.MoveTo(0, ImageCarouselCanvas.DefaultHeight - 96).SizeTo(ImageCarouselCanvas.DefaultWidth, 96); var cc = new Canvas(); // http://cloudstore.blogspot.com/2008/05/creating-custom-window-style.html var wcam = new Window(); wcam.Background = Brushes.Transparent; wcam.WindowStyle = WindowStyle.None; wcam.ResizeMode = ResizeMode.NoResize; wcam.SizeTo(200, 200); wcam.AllowsTransparency = true; //wcam.Opacity = 0.5; wcam.ShowInTaskbar = false; wcam.Cursor = Cursors.Hand; wcam.Focusable = false; wcam.Topmost = true; var w = cc.ToWindow(); w.SizeToContent = SizeToContent.Manual; //w.SizeTo(400, 400); //w.ToTransparentWindow(); // http://blog.joachim.at/?p=39 // http://blogs.msdn.com/changov/archive/2009/01/19/webbrowser-control-on-transparent-wpf-window.aspx // http://blogs.interknowlogy.com/johnbowen/archive/2007/06/20/20458.aspx w.AllowsTransparency = true; w.WindowStyle = System.Windows.WindowStyle.None; w.Focusable = false; //w.Background = new SolidColorBrush(Color.FromArgb(0x20, 0, 0, 0)); w.Background = Brushes.Transparent; w.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen; w.Topmost = true; //w.ShowInTaskbar = false; var winfoc = new Canvas(); var winfo = winfoc.ToWindow(); winfo.AllowsTransparency = true; winfo.ShowInTaskbar = false; winfo.WindowStyle = WindowStyle.None; //winfo.Background = Brushes.Transparent; winfo.Background = Brushes.Red; winfo.Opacity = 0.3; winfo.ResizeMode = ResizeMode.NoResize; winfo.SizeToContent = SizeToContent.Manual; winfo.Topmost = true; // http://www.squidoo.com/youtubehd var NextInputModeEnabled = false; var NextInputModeKeyDownEnabled = false; Action <Key> NextInputModeKeyDown = delegate { }; var CommandKeysEnabled = false; #region TopicText var TopicText = new System.Windows.Controls.TextBox { //IsReadOnly = true, Background = Brushes.Transparent, BorderThickness = new System.Windows.Thickness(0), Foreground = Brushes.White, Effect = new DropShadowEffect(), Text = "JSC C# Foo Bar", //TextDecorations = TextDecorations.Underline, FontFamily = new FontFamily("Verdana"), FontSize = 24, TextAlignment = System.Windows.TextAlignment.Right }; #endregion #region KeyDown InterceptKeys.KeyDown += key => { if (key == Key.LeftShift) { //w.Background = new SolidColorBrush(Color.FromArgb(2, 0, 0, 0)); //w.MakeInteractive(true); NextInputModeEnabled = true; } else { if (NextInputModeEnabled || NextInputModeKeyDownEnabled) { NextInputModeKeyDownEnabled = false; NextInputModeKeyDown(key); } NextInputModeEnabled = false; } }; #endregion #region KeyUp InterceptKeys.KeyUp += key => { if (key == Key.CapsLock) { CommandKeysEnabled = !CommandKeysEnabled; TopicText.IsReadOnly = CommandKeysEnabled; TopicText.Select(0, 0); } if (key == Key.LeftShift) { NextInputModeKeyDownEnabled = false; } else { } NextInputModeEnabled = false; }; #endregion var s = 7; var ThumbnailSize = 0.4; var CaptionBackgroundHeight = 24; #region UpdateChildren Action UpdateChildren = delegate { if (w.ActualWidth == 0) { return; } var ss = s; var ss2 = 0; Console.WriteLine( new { w.Left, w.Top }); winfo.MoveTo(w.Left, w.Top).SizeTo(w.ActualWidth, w.ActualHeight); if (ThumbnailSize == 1) { wcam.Background = Brushes.Black; ss = 0; var qw = w.ActualWidth - ss * 2; var qh = w.ActualHeight - ss * 2; // no status bars or menues please :) wcam.MoveTo( w.Left + ss + ss2, w.Top + (w.ActualHeight - qh * ThumbnailSize - ss) - ss2 ).SizeTo( qw * ThumbnailSize, qh * ThumbnailSize ); } else { wcam.Background = Brushes.Transparent; //if (w.WindowState == WindowState.Maximized) //{ // ss2 = s; //} var qw = w.ActualWidth - ss * 2; var qh = w.ActualHeight - ss * 2; wcam.MoveTo(w.Left + ss + ss2, w.Top + (w.ActualHeight - qh * ThumbnailSize - ss) - ss2).SizeTo(qw * ThumbnailSize, qh * ThumbnailSize); } }; #endregion w.LocationChanged += delegate { UpdateChildren(); }; var Borders = Enumerable.Range(1, s * 2).Reverse().Select( Width => new { Width = Width * 2, Left = new Rectangle { Fill = Brushes.Black, Opacity = 0.06 }.MoveTo(0, 0).AttachTo(winfoc), Right = new Rectangle { Fill = Brushes.Black, Opacity = 0.06 }.MoveTo(0, 0).AttachTo(winfoc), Bottom = new Rectangle { Fill = Brushes.Black, Opacity = 0.03 }.MoveTo(0, 0).AttachTo(winfoc), Top = new Rectangle { Fill = Brushes.Black, Opacity = 0.11 }.MoveTo(0, 0).AttachTo(winfoc) } ).ToArray(); var CaptionBackgroundOverlay = new Rectangle { Fill = Brushes.Black, Opacity = 0.02, }.AttachTo(cc); var CaptionSysMenuOverlay = new Rectangle { Fill = Brushes.Black, Opacity = 0.02, }.AttachTo(cc).SizeTo(CaptionBackgroundHeight * 4, CaptionBackgroundHeight); var ExtraBorderTop = new Rectangle { Fill = Brushes.Black, Opacity = 0.0, }.AttachTo(winfoc); var ExtraBorderBottom = new Rectangle { Fill = Brushes.Black, Opacity = 0.0, }.AttachTo(winfoc); var CaptionClose = new TextBox { Foreground = Brushes.Red, FontFamily = new FontFamily("Webdings"), Text = "r", Background = Brushes.Transparent, BorderThickness = new Thickness(0), TextAlignment = System.Windows.TextAlignment.Center, Opacity = 0.5 }.AttachTo(winfoc); var CaptionText = new System.Windows.Controls.TextBox { IsReadOnly = true, Background = Brushes.Transparent, BorderThickness = new System.Windows.Thickness(0), Foreground = Brushes.White, Effect = new System.Windows.Media.Effects.DropShadowEffect(), Text = "jsc-solutions.net", //TextDecorations = TextDecorations.Underline, FontFamily = new FontFamily("Verdana"), FontSize = 16, TextAlignment = System.Windows.TextAlignment.Right } .AttachTo(winfoc); TopicText.AttachTo(winfoc); #region SetCaption Action <string> SetCaption = text => { if (string.IsNullOrEmpty(text)) { CaptionText.Text = "jsc-solutions.net"; } else { CaptionText.Text = text + " | jsc-solutions.net"; } }; #endregion c.AttachContainerTo(winfoc); var ExtraBorderSize = 0.10; var Intro = new PromotionBrandIntro.ApplicationCanvas().AttachTo(winfoc); Intro.Opacity = 0; #region SizeChanged Action SizeChanged = delegate { Intro.SizeTo(w.ActualWidth, w.ActualHeight); //ink.SizeTo(w.ActualWidth, w.ActualHeight - CaptionBackgroundHeight); var CaptionWidth = 200; CaptionBackgroundOverlay.MoveTo(w.ActualWidth - CaptionWidth, 0).SizeTo(CaptionWidth, CaptionBackgroundHeight); ExtraBorderTop.MoveTo(0, 0).SizeTo(w.ActualWidth, w.ActualHeight * ExtraBorderSize); ExtraBorderBottom.MoveTo(0, w.ActualHeight * (1 - ExtraBorderSize)).SizeTo(w.ActualWidth, w.ActualHeight * ExtraBorderSize); TopicText.MoveTo( 0, w.ActualHeight - 48 ).SizeTo(w.ActualWidth - 48, 48); if (c != null) { c.MoveContainerTo(-200 + 42, -200 + 38); } Borders.WithEach(k => k.Left.MoveTo(0, 0).SizeTo(k.Width, w.ActualHeight)); Borders.WithEach(k => k.Right.MoveTo(w.ActualWidth - k.Width, 0).SizeTo(k.Width, w.ActualHeight)); Borders.WithEach(k => k.Bottom.MoveTo(0, w.ActualHeight - k.Width).SizeTo(w.ActualWidth, k.Width)); Borders.WithEach(k => k.Top.MoveTo(0, 0).SizeTo(w.ActualWidth, k.Width)); CaptionText.MoveTo(0, 2).SizeTo(w.ActualWidth - CaptionBackgroundHeight, 32); CaptionClose.MoveTo(w.ActualWidth - CaptionBackgroundHeight, s).SizeTo(CaptionBackgroundHeight - s, CaptionBackgroundHeight - s); UpdateChildren(); }; #endregion w.SizeChanged += delegate { SizeChanged(); }; w.StateChanged += delegate { if (w.WindowState == WindowState.Maximized) { w.WindowState = WindowState.Normal; } SizeChanged(); }; #region GetWindows Func <IEnumerable <Internal.Window> > GetWindows = delegate { var windows = new List <Internal.Window>(); Internal.EnumWindows( (IntPtr hwnd, int lParam) => { if (new WindowInteropHelper(wcam).Handle != hwnd && (Internal.GetWindowLongA(hwnd, Internal.GWL_STYLE) & Internal.TARGETWINDOW) == Internal.TARGETWINDOW ) { StringBuilder sb = new StringBuilder(100); Internal.GetWindowText(hwnd, sb, sb.Capacity); windows.Add( new Internal.Window { Handle = hwnd, Title = sb.ToString() } ); } return(true); //continue enumeration } , 0); return(windows.OrderBy(k => k.Title)); }; #endregion var ResetThumbnailSkip = 0; Func <Internal.Window> GetCurrentThumbnail = () => GetWindows().AsCyclicEnumerable().Skip(ResetThumbnailSkip).First(); #region AnimationCompleted Intro.AnimationCompleted += delegate { if (c == null) { c = new JSCSolutionsNETCarouselCanvas { CloseOnClick = false }.AttachContainerTo(winfoc); c.HideSattelites(); CaptionClose.Show(); SizeChanged(); } }; #endregion wcam.SourceInitialized += delegate { { wcam.MakeInteractive(false); UpdateChildren(); } var thumb = IntPtr.Zero; ResetThumbnailSkip = GetWindows().Where( k => k.Title.Contains("Chrome") || k.Title.Contains("Studio") || k.Title.Contains("Minefield") ).TakeWhile(k => k.Handle != Internal.GetForegroundWindow()).Count(); #region ResetThumbnail Action ResetThumbnail = delegate { GetCurrentThumbnail().With( shadow => { //t.Text = shadow.Title; if (thumb != IntPtr.Zero) { Internal.DwmUnregisterThumbnail(thumb); } int i = Internal.DwmRegisterThumbnail( new WindowInteropHelper(wcam).Handle, shadow.Handle, out thumb); #region UpdateThumbnail Action UpdateThumbnail = delegate { if (thumb != IntPtr.Zero) { Internal.PSIZE size; Internal.DwmQueryThumbnailSourceSize(thumb, out size); Internal.DWM_THUMBNAIL_PROPERTIES props = new Internal.DWM_THUMBNAIL_PROPERTIES(); props.fVisible = true; props.dwFlags = Internal.DWM_TNP_VISIBLE | Internal.DWM_TNP_RECTDESTINATION | Internal.DWM_TNP_OPACITY | Internal.DWM_TNP_SOURCECLIENTAREAONLY; props.opacity = (byte)((byte)(0x7F) + (byte)((0x80) * (ThumbnailSize))); props.rcDestination = new Internal.Rect(0, 0, (int)wcam.ActualWidth, (int)wcam.ActualHeight); props.fSourceClientAreaOnly = true; if (size.x < wcam.ActualWidth) { props.rcDestination.Right = props.rcDestination.Left + size.x; props.rcDestination.Left += ((int)wcam.ActualWidth - size.x) / 2; props.rcDestination.Right += ((int)wcam.ActualWidth - size.x) / 2; } if (size.y < wcam.ActualHeight) { props.rcDestination.Bottom = props.rcDestination.Top + size.y; props.rcDestination.Top += ((int)wcam.ActualHeight - size.y) / 2; props.rcDestination.Bottom += ((int)wcam.ActualHeight - size.y) / 2; } Internal.DwmUpdateThumbnailProperties(thumb, ref props); } }; #endregion (1000 / 15).AtInterval(UpdateThumbnail); wcam.SizeChanged += delegate { UpdateThumbnail(); }; } ); }; #endregion ResetThumbnail(); NextInputModeKeyDown += key => { if (key == Key.RightShift) { NextInputModeKeyDownEnabled = true; if (c != null) { CaptionClose.Hide(); c.AtClose += delegate { c.OrphanizeContainer(); }; c.Close(); c = null; } Intro.Background = Brushes.Transparent; Intro.Overlay.Opacity = 1; Intro.FadeIn( delegate { 2000.AtDelay(Intro.PrepareAnimation()); } ); } if (!CommandKeysEnabled) { if (key == Key.F2) { w.Activate(); TopicText.Focusable = true; TopicText.Focus(); TopicText.SelectAll(); } return; } if (key == Key.Right) { if (w.IsActive) { GetCurrentThumbnail().Activate(); } else { NextInputModeKeyDownEnabled = true; ResetThumbnailSkip = GetWindows().TakeWhile(k => k.Handle != Internal.GetForegroundWindow()).Count(); ResetThumbnail(); } } if (key == Key.Up) { NextInputModeKeyDownEnabled = true; if (ThumbnailSize < 0.3) { ThumbnailSize = 0.3; } else if (ThumbnailSize < 0.5) { ThumbnailSize = 0.5; } else if (ThumbnailSize < 1) { ThumbnailSize = 1; } else { if (c != null) { CaptionClose.Hide(); c.AtClose += delegate { c.OrphanizeContainer(); }; c.Close(); c = null; } } UpdateChildren(); } if (key == Key.Down) { NextInputModeKeyDownEnabled = true; if (c == null) { c = new JSCSolutionsNETCarouselCanvas { CloseOnClick = false }.AttachContainerTo(winfoc); CaptionClose.Show(); } else if (ThumbnailSize > 0.5) { ThumbnailSize = 0.5; } else if (ThumbnailSize > 0.3) { ThumbnailSize = 0.3; } else if (ThumbnailSize == 0.3) { ThumbnailSize = 0; } SizeChanged(); } if (key == Key.Left) { if (w.IsActive) { NextInputModeKeyDownEnabled = true; if (ExtraBorderTop.Opacity == 1) { ExtraBorderTop.Opacity = 0; ExtraBorderBottom.Opacity = 0; } else { ExtraBorderTop.Opacity = 1; ExtraBorderBottom.Opacity = 1; } } } }; }; winfo.SourceInitialized += delegate { winfo.MakeInteractive(false); }; w.SourceInitialized += delegate { // http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/61e93dca-e24c-4953-9719-22ce3f705353 Matrix m = PresentationSource.FromVisual(w).CompositionTarget.TransformToDevice; double dx = m.M11; double dy = m.M22; w.SizeTo(1280 / dx, 768 / dy); w.MoveTo(8, 0); SizeChanged(); wcam.Owner = w; winfo.Owner = w; wcam.Show(); winfo.Show(); HwndSource hwndSource = (HwndSource)HwndSource.FromVisual(w); hwndSource.AddHook( (IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handeled) => { if (msg == 0x0084) // WM_NCHITTEST { //http://agsmith.wordpress.com/2008/09/16/hit-testing-in-wpf/ var p = new { cx = w.ActualWidth - (Internal.LOWORD(lParam) - w.Left), cy = w.ActualHeight - (Internal.HIWORD(lParam) - w.Top), x = Internal.LOWORD(lParam) - w.Left, y = Internal.HIWORD(lParam) - w.Top }; CaptionText.Text = p.ToString(); handeled = true; return((IntPtr)HitTestValues.HTCAPTION); // HTCAPTION if (false) { if (p.x < s) { if (p.y < s) { return((IntPtr)HitTestValues.HTTOPLEFT); // HTCAPTION } } if (p.x < CaptionBackgroundHeight) { if (p.y < CaptionBackgroundHeight) { return((IntPtr)HitTestValues.HTSYSMENU); // HTCAPTION } } if (p.cx < CaptionBackgroundHeight) { if (p.y < CaptionBackgroundHeight) { return((IntPtr)HitTestValues.HTCLOSE); // HTCAPTION } } if (p.cx < s) { if (p.cy < s) { return((IntPtr)HitTestValues.HTBOTTOMRIGHT); // HTCAPTION } } if (p.cx < s) { if (p.y < s) { return((IntPtr)HitTestValues.HTTOPRIGHT); // HTCAPTION } } if (p.x < s) { if (p.cy < s) { return((IntPtr)HitTestValues.HTBOTTOMLEFT); // HTCAPTION } } if (p.x < s) { return((IntPtr)HitTestValues.HTLEFT); // HTCAPTION } if (p.y < s) { return((IntPtr)HitTestValues.HTTOP); // HTCAPTION } if (p.cx < s) { return((IntPtr)HitTestValues.HTRIGHT); // HTCAPTION } if (p.cy < s) { return((IntPtr)HitTestValues.HTBOTTOM); // HTCAPTION } if (p.y < CaptionBackgroundHeight) { return((IntPtr)HitTestValues.HTCAPTION); // HTCAPTION } return((IntPtr)HitTestValues.HTTRANSPARENT); // HTCAPTION } } return(IntPtr.Zero); } ); }; InterceptKeys.InternalMain( Rehook => { w.Deactivated += delegate { TopicText.Focusable = false; }; w.Activated += delegate { //TopicText.Focus(); Rehook(); }; w.ShowDialog(); } ); }
/** * Constructor */ public EditBox() { mEditBox = new System.Windows.Controls.TextBox(); mPasswordBox = new System.Windows.Controls.PasswordBox(); // by default, the password box is not visible mPasswordBox.Visibility = Visibility.Collapsed; createTheEditBoxGrid(); mView = mEditBoxGrid; mIsPasswordMode = false; mIsWatermarkMode = false; mPlaceholderText = ""; // by default, the placeholder font color is gray mWaterMarkBrush = new SolidColorBrush(); mWaterMarkBrush.Color = Colors.Gray; mForegroundColor = mEditBox.Foreground; /** * @brief Sent from the Edit box when it gains focus(the user selects the widget). * The virtual keyboard is shown. * MAW_EVENT_EDIT_BOX_EDITING_DID_BEGIN */ mEditBox.GotFocus += new RoutedEventHandler( delegate(object from, RoutedEventArgs args) { /** * simulating the placeholder/watermark */ // if watermark present and no user char has been entered if (mIsWatermarkMode && mFirstChar) { // move the cursor to the first position mEditBox.Select(0, 0); setWatermarkMode(false); } /** * post the event to MoSync runtime */ Memory eventData = new Memory(8); const int MAWidgetEventData_eventType = 0; const int MAWidgetEventData_widgetHandle = 4; eventData.WriteInt32(MAWidgetEventData_eventType, MoSync.Constants.MAW_EVENT_EDIT_BOX_EDITING_DID_BEGIN); eventData.WriteInt32(MAWidgetEventData_widgetHandle, mHandle); mRuntime.PostCustomEvent(MoSync.Constants.EVENT_TYPE_WIDGET, eventData); } ); // end of mEditBox.GotFocus /** * @brief Sent from the Edit box when it loses focus. * The virtual keyboard is hidden. * MAW_EVENT_EDIT_BOX_EDITING_DID_END */ mEditBox.LostFocus += new RoutedEventHandler( delegate(object from, RoutedEventArgs args) { /** * simulating the placeholder/watermark */ // if no text has been entered by the user than leave the watermark text if (mEditBox.Text.Equals("")) { setWatermarkMode(true); } /** * post the event to MoSync runtime */ Memory eventData = new Memory(8); const int MAWidgetEventData_eventType = 0; const int MAWidgetEventData_widgetHandle = 4; eventData.WriteInt32(MAWidgetEventData_eventType, MoSync.Constants.MAW_EVENT_EDIT_BOX_EDITING_DID_END); eventData.WriteInt32(MAWidgetEventData_widgetHandle, mHandle); mRuntime.PostCustomEvent(MoSync.Constants.EVENT_TYPE_WIDGET, eventData); } ); // end of mEditBox.LostFocus /** * @brief Sent from the Edit box when the text was changed. * MAW_EVENT_EDIT_BOX_TEXT_CHANGED */ mFirstChar = true; mEditBox.TextInputStart += new TextCompositionEventHandler( delegate(object from, TextCompositionEventArgs args) { /** * simulating the placeholder/watermark */ if (mFirstChar) { setWatermarkMode(false); } /** * post the event to MoSync runtime */ Memory eventData = new Memory(8); const int MAWidgetEventData_eventType = 0; const int MAWidgetEventData_widgetHandle = 4; eventData.WriteInt32(MAWidgetEventData_eventType, MoSync.Constants.MAW_EVENT_EDIT_BOX_TEXT_CHANGED); eventData.WriteInt32(MAWidgetEventData_widgetHandle, mHandle); mRuntime.PostCustomEvent(MoSync.Constants.EVENT_TYPE_WIDGET, eventData); } ); // end of TextInputStart /** * @brief Sent from the Password box when it gains focus(the user selects the widget). * The virtual keyboard is shown. * MAW_EVENT_EDIT_BOX_EDITING_DID_BEGIN */ mPasswordBox.GotFocus += new RoutedEventHandler( delegate(object from, RoutedEventArgs args) { /** * post the event to MoSync runtime */ Memory eventData = new Memory(8); const int MAWidgetEventData_eventType = 0; const int MAWidgetEventData_widgetHandle = 4; eventData.WriteInt32(MAWidgetEventData_eventType, MoSync.Constants.MAW_EVENT_EDIT_BOX_EDITING_DID_BEGIN); eventData.WriteInt32(MAWidgetEventData_widgetHandle, mHandle); mRuntime.PostCustomEvent(MoSync.Constants.EVENT_TYPE_WIDGET, eventData); } ); // end of mPasswordBox.GotFocus /** * @brief Sent from the Password box when it loses focus. * The virtual keyboard is hidden. * MAW_EVENT_EDIT_BOX_EDITING_DID_END */ mPasswordBox.LostFocus += new RoutedEventHandler( delegate(object from, RoutedEventArgs args) { /** * post the event to MoSync runtime */ Memory eventData = new Memory(8); const int MAWidgetEventData_eventType = 0; const int MAWidgetEventData_widgetHandle = 4; eventData.WriteInt32(MAWidgetEventData_eventType, MoSync.Constants.MAW_EVENT_EDIT_BOX_EDITING_DID_END); eventData.WriteInt32(MAWidgetEventData_widgetHandle, mHandle); mRuntime.PostCustomEvent(MoSync.Constants.EVENT_TYPE_WIDGET, eventData); } ); // end of mPasswordBox.LostFocus /** * @brief Sent from the Password box when the text was changed. * MAW_EVENT_EDIT_BOX_TEXT_CHANGED */ mPasswordBox.TextInputStart += new TextCompositionEventHandler( delegate(object from, TextCompositionEventArgs args) { /** * post the event to MoSync runtime */ Memory eventData = new Memory(8); const int MAWidgetEventData_eventType = 0; const int MAWidgetEventData_widgetHandle = 4; eventData.WriteInt32(MAWidgetEventData_eventType, MoSync.Constants.MAW_EVENT_EDIT_BOX_TEXT_CHANGED); eventData.WriteInt32(MAWidgetEventData_widgetHandle, mHandle); mRuntime.PostCustomEvent(MoSync.Constants.EVENT_TYPE_WIDGET, eventData); } ); // end of mPasswordBox.TextInputStart /** * @brief Sent from the Edit box when the return button was pressed. * On iphone platform the virtual keyboard is not closed after receiving this event. * EDIT_BOX_RETURN */ // Not available on Windows Phone 7.1 }
private void SetTextAndPos(TextBox tb, string text) { int pos = tb.SelectionStart; tb.Text = text; tb.Select(pos, 0); }
static void Main(string[] args) { var c = new JSCSolutionsNETCarouselCanvas { CloseOnClick = false }; c.HideSattelites(); //c.Container.Effect = new DropShadowEffect(); //c.Container.BitmapEffect = new DropShadowBitmapEffect(); //.MoveTo(0, ImageCarouselCanvas.DefaultHeight - 96).SizeTo(ImageCarouselCanvas.DefaultWidth, 96); var cc = new Canvas(); // http://cloudstore.blogspot.com/2008/05/creating-custom-window-style.html var wcam = new Window(); wcam.Background = Brushes.Transparent; wcam.WindowStyle = WindowStyle.None; wcam.ResizeMode = ResizeMode.NoResize; wcam.SizeTo(200, 200); wcam.AllowsTransparency = true; //wcam.Opacity = 0.5; wcam.ShowInTaskbar = false; wcam.Cursor = Cursors.Hand; wcam.Focusable = false; wcam.Topmost = true; var w = cc.ToWindow(); w.SizeToContent = SizeToContent.Manual; //w.SizeTo(400, 400); //w.ToTransparentWindow(); // http://blog.joachim.at/?p=39 // http://blogs.msdn.com/changov/archive/2009/01/19/webbrowser-control-on-transparent-wpf-window.aspx // http://blogs.interknowlogy.com/johnbowen/archive/2007/06/20/20458.aspx w.AllowsTransparency = true; w.WindowStyle = System.Windows.WindowStyle.None; w.Focusable = false; //w.Background = new SolidColorBrush(Color.FromArgb(0x20, 0, 0, 0)); w.Background = Brushes.Transparent; w.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen; w.Topmost = true; //w.ShowInTaskbar = false; var winfoc = new Canvas(); var winfo = winfoc.ToWindow(); winfo.AllowsTransparency = true; winfo.ShowInTaskbar = false; winfo.WindowStyle = WindowStyle.None; //winfo.Background = Brushes.Transparent; winfo.Background = Brushes.Red; winfo.Opacity = 0.3; winfo.ResizeMode = ResizeMode.NoResize; winfo.SizeToContent = SizeToContent.Manual; winfo.Topmost = true; // http://www.squidoo.com/youtubehd var NextInputModeEnabled = false; var NextInputModeKeyDownEnabled = false; Action<Key> NextInputModeKeyDown = delegate { }; var CommandKeysEnabled = false; #region TopicText var TopicText = new System.Windows.Controls.TextBox { //IsReadOnly = true, Background = Brushes.Transparent, BorderThickness = new System.Windows.Thickness(0), Foreground = Brushes.White, Effect = new DropShadowEffect(), Text = "JSC C# Foo Bar", //TextDecorations = TextDecorations.Underline, FontFamily = new FontFamily("Verdana"), FontSize = 24, TextAlignment = System.Windows.TextAlignment.Right }; #endregion #region KeyDown InterceptKeys.KeyDown += key => { if (key == Key.LeftShift) { //w.Background = new SolidColorBrush(Color.FromArgb(2, 0, 0, 0)); //w.MakeInteractive(true); NextInputModeEnabled = true; } else { if (NextInputModeEnabled || NextInputModeKeyDownEnabled) { NextInputModeKeyDownEnabled = false; NextInputModeKeyDown(key); } NextInputModeEnabled = false; } }; #endregion #region KeyUp InterceptKeys.KeyUp += key => { if (key == Key.CapsLock) { CommandKeysEnabled = !CommandKeysEnabled; TopicText.IsReadOnly = CommandKeysEnabled; TopicText.Select(0, 0); } if (key == Key.LeftShift) { NextInputModeKeyDownEnabled = false; } else { } NextInputModeEnabled = false; }; #endregion var s = 7; var ThumbnailSize = 0.4; var CaptionBackgroundHeight = 24; #region UpdateChildren Action UpdateChildren = delegate { if (w.ActualWidth == 0) return; var ss = s; var ss2 = 0; Console.WriteLine( new { w.Left, w.Top }); winfo.MoveTo(w.Left, w.Top).SizeTo(w.ActualWidth, w.ActualHeight); if (ThumbnailSize == 1) { wcam.Background = Brushes.Black; ss = 0; var qw = w.ActualWidth - ss * 2; var qh = w.ActualHeight - ss * 2; // no status bars or menues please :) wcam.MoveTo( w.Left + ss + ss2, w.Top + (w.ActualHeight - qh * ThumbnailSize - ss) - ss2 ).SizeTo( qw * ThumbnailSize, qh * ThumbnailSize ); } else { wcam.Background = Brushes.Transparent; //if (w.WindowState == WindowState.Maximized) //{ // ss2 = s; //} var qw = w.ActualWidth - ss * 2; var qh = w.ActualHeight - ss * 2; wcam.MoveTo(w.Left + ss + ss2, w.Top + (w.ActualHeight - qh * ThumbnailSize - ss) - ss2).SizeTo(qw * ThumbnailSize, qh * ThumbnailSize); } }; #endregion w.LocationChanged += delegate { UpdateChildren(); }; var Borders = Enumerable.Range(1, s * 2).Reverse().Select( Width => new { Width = Width * 2, Left = new Rectangle { Fill = Brushes.Black, Opacity = 0.06 }.MoveTo(0, 0).AttachTo(winfoc), Right = new Rectangle { Fill = Brushes.Black, Opacity = 0.06 }.MoveTo(0, 0).AttachTo(winfoc), Bottom = new Rectangle { Fill = Brushes.Black, Opacity = 0.03 }.MoveTo(0, 0).AttachTo(winfoc), Top = new Rectangle { Fill = Brushes.Black, Opacity = 0.11 }.MoveTo(0, 0).AttachTo(winfoc) } ).ToArray(); var CaptionBackgroundOverlay = new Rectangle { Fill = Brushes.Black, Opacity = 0.02, }.AttachTo(cc); var CaptionSysMenuOverlay = new Rectangle { Fill = Brushes.Black, Opacity = 0.02, }.AttachTo(cc).SizeTo(CaptionBackgroundHeight * 4, CaptionBackgroundHeight); var ExtraBorderTop = new Rectangle { Fill = Brushes.Black, Opacity = 0.0, }.AttachTo(winfoc); var ExtraBorderBottom = new Rectangle { Fill = Brushes.Black, Opacity = 0.0, }.AttachTo(winfoc); var CaptionClose = new TextBox { Foreground = Brushes.Red, FontFamily = new FontFamily("Webdings"), Text = "r", Background = Brushes.Transparent, BorderThickness = new Thickness(0), TextAlignment = System.Windows.TextAlignment.Center, Opacity = 0.5 }.AttachTo(winfoc); var CaptionText = new System.Windows.Controls.TextBox { IsReadOnly = true, Background = Brushes.Transparent, BorderThickness = new System.Windows.Thickness(0), Foreground = Brushes.White, Effect = new System.Windows.Media.Effects.DropShadowEffect(), Text = "jsc-solutions.net", //TextDecorations = TextDecorations.Underline, FontFamily = new FontFamily("Verdana"), FontSize = 16, TextAlignment = System.Windows.TextAlignment.Right } .AttachTo(winfoc); TopicText.AttachTo(winfoc); #region SetCaption Action<string> SetCaption = text => { if (string.IsNullOrEmpty(text)) CaptionText.Text = "jsc-solutions.net"; else CaptionText.Text = text + " | jsc-solutions.net"; }; #endregion c.AttachContainerTo(winfoc); var ExtraBorderSize = 0.10; var Intro = new PromotionBrandIntro.ApplicationCanvas().AttachTo(winfoc); Intro.Opacity = 0; #region SizeChanged Action SizeChanged = delegate { Intro.SizeTo(w.ActualWidth, w.ActualHeight); //ink.SizeTo(w.ActualWidth, w.ActualHeight - CaptionBackgroundHeight); var CaptionWidth = 200; CaptionBackgroundOverlay.MoveTo(w.ActualWidth - CaptionWidth, 0).SizeTo(CaptionWidth, CaptionBackgroundHeight); ExtraBorderTop.MoveTo(0, 0).SizeTo(w.ActualWidth, w.ActualHeight * ExtraBorderSize); ExtraBorderBottom.MoveTo(0, w.ActualHeight * (1 - ExtraBorderSize)).SizeTo(w.ActualWidth, w.ActualHeight * ExtraBorderSize); TopicText.MoveTo( 0, w.ActualHeight - 48 ).SizeTo(w.ActualWidth - 48, 48); if (c != null) c.MoveContainerTo(-200 + 42, -200 + 38); Borders.WithEach(k => k.Left.MoveTo(0, 0).SizeTo(k.Width, w.ActualHeight)); Borders.WithEach(k => k.Right.MoveTo(w.ActualWidth - k.Width, 0).SizeTo(k.Width, w.ActualHeight)); Borders.WithEach(k => k.Bottom.MoveTo(0, w.ActualHeight - k.Width).SizeTo(w.ActualWidth, k.Width)); Borders.WithEach(k => k.Top.MoveTo(0, 0).SizeTo(w.ActualWidth, k.Width)); CaptionText.MoveTo(0, 2).SizeTo(w.ActualWidth - CaptionBackgroundHeight, 32); CaptionClose.MoveTo(w.ActualWidth - CaptionBackgroundHeight, s).SizeTo(CaptionBackgroundHeight - s, CaptionBackgroundHeight - s); UpdateChildren(); }; #endregion w.SizeChanged += delegate { SizeChanged(); }; w.StateChanged += delegate { if (w.WindowState == WindowState.Maximized) w.WindowState = WindowState.Normal; SizeChanged(); }; #region GetWindows Func<IEnumerable<Internal.Window>> GetWindows = delegate { var windows = new List<Internal.Window>(); Internal.EnumWindows( (IntPtr hwnd, int lParam) => { if (new WindowInteropHelper(wcam).Handle != hwnd && (Internal.GetWindowLongA(hwnd, Internal.GWL_STYLE) & Internal.TARGETWINDOW) == Internal.TARGETWINDOW ) { StringBuilder sb = new StringBuilder(100); Internal.GetWindowText(hwnd, sb, sb.Capacity); windows.Add( new Internal.Window { Handle = hwnd, Title = sb.ToString() } ); } return true; //continue enumeration } , 0); return windows.OrderBy(k => k.Title); }; #endregion var ResetThumbnailSkip = 0; Func<Internal.Window> GetCurrentThumbnail = () => GetWindows().AsCyclicEnumerable().Skip(ResetThumbnailSkip).First(); #region AnimationCompleted Intro.AnimationCompleted += delegate { if (c == null) { c = new JSCSolutionsNETCarouselCanvas { CloseOnClick = false }.AttachContainerTo(winfoc); c.HideSattelites(); CaptionClose.Show(); SizeChanged(); } }; #endregion wcam.SourceInitialized += delegate { { wcam.MakeInteractive(false); UpdateChildren(); } var thumb = IntPtr.Zero; ResetThumbnailSkip = GetWindows().Where( k => k.Title.Contains("Chrome") || k.Title.Contains("Studio") || k.Title.Contains("Minefield") ).TakeWhile(k => k.Handle != Internal.GetForegroundWindow()).Count(); #region ResetThumbnail Action ResetThumbnail = delegate { GetCurrentThumbnail().With( shadow => { //t.Text = shadow.Title; if (thumb != IntPtr.Zero) Internal.DwmUnregisterThumbnail(thumb); int i = Internal.DwmRegisterThumbnail( new WindowInteropHelper(wcam).Handle, shadow.Handle, out thumb); #region UpdateThumbnail Action UpdateThumbnail = delegate { if (thumb != IntPtr.Zero) { Internal.PSIZE size; Internal.DwmQueryThumbnailSourceSize(thumb, out size); Internal.DWM_THUMBNAIL_PROPERTIES props = new Internal.DWM_THUMBNAIL_PROPERTIES(); props.fVisible = true; props.dwFlags = Internal.DWM_TNP_VISIBLE | Internal.DWM_TNP_RECTDESTINATION | Internal.DWM_TNP_OPACITY | Internal.DWM_TNP_SOURCECLIENTAREAONLY; props.opacity = (byte)((byte)(0x7F) + (byte)((0x80) * (ThumbnailSize))); props.rcDestination = new Internal.Rect(0, 0, (int)wcam.ActualWidth, (int)wcam.ActualHeight); props.fSourceClientAreaOnly = true; if (size.x < wcam.ActualWidth) { props.rcDestination.Right = props.rcDestination.Left + size.x; props.rcDestination.Left += ((int)wcam.ActualWidth - size.x) / 2; props.rcDestination.Right += ((int)wcam.ActualWidth - size.x) / 2; } if (size.y < wcam.ActualHeight) { props.rcDestination.Bottom = props.rcDestination.Top + size.y; props.rcDestination.Top += ((int)wcam.ActualHeight - size.y) / 2; props.rcDestination.Bottom += ((int)wcam.ActualHeight - size.y) / 2; } Internal.DwmUpdateThumbnailProperties(thumb, ref props); } }; #endregion (1000 / 15).AtInterval(UpdateThumbnail); wcam.SizeChanged += delegate { UpdateThumbnail(); }; } ); }; #endregion ResetThumbnail(); NextInputModeKeyDown += key => { if (key == Key.RightShift) { NextInputModeKeyDownEnabled = true; if (c != null) { CaptionClose.Hide(); c.AtClose += delegate { c.OrphanizeContainer(); }; c.Close(); c = null; } Intro.Background = Brushes.Transparent; Intro.Overlay.Opacity = 1; Intro.FadeIn( delegate { 2000.AtDelay(Intro.PrepareAnimation()); } ); } if (!CommandKeysEnabled) { if (key == Key.F2) { w.Activate(); TopicText.Focusable = true; TopicText.Focus(); TopicText.SelectAll(); } return; } if (key == Key.Right) { if (w.IsActive) { GetCurrentThumbnail().Activate(); } else { NextInputModeKeyDownEnabled = true; ResetThumbnailSkip = GetWindows().TakeWhile(k => k.Handle != Internal.GetForegroundWindow()).Count(); ResetThumbnail(); } } if (key == Key.Up) { NextInputModeKeyDownEnabled = true; if (ThumbnailSize < 0.3) ThumbnailSize = 0.3; else if (ThumbnailSize < 0.5) ThumbnailSize = 0.5; else if (ThumbnailSize < 1) ThumbnailSize = 1; else { if (c != null) { CaptionClose.Hide(); c.AtClose += delegate { c.OrphanizeContainer(); }; c.Close(); c = null; } } UpdateChildren(); } if (key == Key.Down) { NextInputModeKeyDownEnabled = true; if (c == null) { c = new JSCSolutionsNETCarouselCanvas { CloseOnClick = false }.AttachContainerTo(winfoc); CaptionClose.Show(); } else if (ThumbnailSize > 0.5) ThumbnailSize = 0.5; else if (ThumbnailSize > 0.3) ThumbnailSize = 0.3; else if (ThumbnailSize == 0.3) ThumbnailSize = 0; SizeChanged(); } if (key == Key.Left) { if (w.IsActive) { NextInputModeKeyDownEnabled = true; if (ExtraBorderTop.Opacity == 1) { ExtraBorderTop.Opacity = 0; ExtraBorderBottom.Opacity = 0; } else { ExtraBorderTop.Opacity = 1; ExtraBorderBottom.Opacity = 1; } } } }; }; winfo.SourceInitialized += delegate { winfo.MakeInteractive(false); }; w.SourceInitialized += delegate { // http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/61e93dca-e24c-4953-9719-22ce3f705353 Matrix m = PresentationSource.FromVisual(w).CompositionTarget.TransformToDevice; double dx = m.M11; double dy = m.M22; w.SizeTo(1280 / dx, 768 /dy); w.MoveTo(8, 0); SizeChanged(); wcam.Owner = w; winfo.Owner = w; wcam.Show(); winfo.Show(); HwndSource hwndSource = (HwndSource)HwndSource.FromVisual(w); hwndSource.AddHook( (IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handeled) => { if (msg == 0x0084) // WM_NCHITTEST { //http://agsmith.wordpress.com/2008/09/16/hit-testing-in-wpf/ var p = new { cx = w.ActualWidth - (Internal.LOWORD(lParam) - w.Left), cy = w.ActualHeight - (Internal.HIWORD(lParam) - w.Top), x = Internal.LOWORD(lParam) - w.Left, y = Internal.HIWORD(lParam) - w.Top }; CaptionText.Text = p.ToString(); handeled = true; return (IntPtr)HitTestValues.HTCAPTION; // HTCAPTION if (false) { if (p.x < s) if (p.y < s) return (IntPtr)HitTestValues.HTTOPLEFT; // HTCAPTION if (p.x < CaptionBackgroundHeight) if (p.y < CaptionBackgroundHeight) return (IntPtr)HitTestValues.HTSYSMENU; // HTCAPTION if (p.cx < CaptionBackgroundHeight) if (p.y < CaptionBackgroundHeight) return (IntPtr)HitTestValues.HTCLOSE; // HTCAPTION if (p.cx < s) if (p.cy < s) return (IntPtr)HitTestValues.HTBOTTOMRIGHT; // HTCAPTION if (p.cx < s) if (p.y < s) return (IntPtr)HitTestValues.HTTOPRIGHT; // HTCAPTION if (p.x < s) if (p.cy < s) return (IntPtr)HitTestValues.HTBOTTOMLEFT; // HTCAPTION if (p.x < s) return (IntPtr)HitTestValues.HTLEFT; // HTCAPTION if (p.y < s) return (IntPtr)HitTestValues.HTTOP; // HTCAPTION if (p.cx < s) return (IntPtr)HitTestValues.HTRIGHT; // HTCAPTION if (p.cy < s) return (IntPtr)HitTestValues.HTBOTTOM; // HTCAPTION if (p.y < CaptionBackgroundHeight) return (IntPtr)HitTestValues.HTCAPTION; // HTCAPTION return (IntPtr)HitTestValues.HTTRANSPARENT; // HTCAPTION } } return IntPtr.Zero; } ); }; InterceptKeys.InternalMain( Rehook => { w.Deactivated += delegate { TopicText.Focusable = false; }; w.Activated += delegate { //TopicText.Focus(); Rehook(); }; w.ShowDialog(); } ); }
internal void BeginEditTextOnSelected() { ItemLostFocus(); selectedForEditing = (SelectedItem as ExplorerTreeViewItem); if (selectedForEditing == null) return; TextBox tb = new TextBox(); tb.Text = selectedForEditing.Text; tb.LostFocus += tb_LostFocus; tb.KeyDown += tb_KeyDown; tb.Focusable = true; beforeEditingPath = selectedForEditing.FullPath; (selectedForEditing.Header as StackPanel).Children.RemoveAt(1); (selectedForEditing.Header as StackPanel).Children.Add(tb); selectedForEditing.CanDrag = false; tb.Select(0, tb.Text.Length - (System.IO.Path.GetExtension(tb.Text).Length)); tb.Focus(); }
private void LoadAddLoginWPF() { // define UI elements. Header = Properties_Resources.Where; System.Uri resourceLocater = new System.Uri("/DataSpaceSync;component/SetupAddLoginWPF.xaml", System.UriKind.Relative); UserControl LoadAddLoginWPF = Application.LoadComponent(resourceLocater) as UserControl; address_label = LoadAddLoginWPF.FindName("address_label") as TextBlock; address_box = LoadAddLoginWPF.FindName("address_box") as TextBox; address_help_label = LoadAddLoginWPF.FindName("address_help_label") as TextBlock; user_label = LoadAddLoginWPF.FindName("user_label") as TextBlock; user_box = LoadAddLoginWPF.FindName("user_box") as TextBox; user_help_label = LoadAddLoginWPF.FindName("user_help_label") as TextBlock; password_label = LoadAddLoginWPF.FindName("password_label") as TextBlock; password_box = LoadAddLoginWPF.FindName("password_box") as PasswordBox; password_progress = LoadAddLoginWPF.FindName("password_progress") as CircularProgressBar; password_help_label = LoadAddLoginWPF.FindName("password_help_label") as TextBlock; address_error_label = LoadAddLoginWPF.FindName("address_error_label") as TextBox; continue_button = LoadAddLoginWPF.FindName("continue_button") as Button; cancel_button = LoadAddLoginWPF.FindName("cancel_button") as Button; ContentCanvas.Children.Add(LoadAddLoginWPF); address_box.Text = (Controller.PreviousAddress != null) ? Controller.PreviousAddress.ToString() : String.Empty; if (Controller.saved_user == String.Empty || Controller.saved_user == null) { user_box.Text = DefaultEntries.Defaults.Name; } else { user_box.Text = Controller.saved_user; } TaskbarItemInfo.ProgressValue = 0.0; TaskbarItemInfo.ProgressState = TaskbarItemProgressState.None; if (!DefaultEntries.Defaults.CanModifyUrl) { address_box.IsEnabled = false; address_box.Visibility = Visibility.Hidden; address_help_label.Visibility = Visibility.Hidden; address_label.Visibility = Visibility.Hidden; } if (Controller.PreviousAddress == null || Controller.PreviousAddress.ToString() == String.Empty) { address_box.Text = DefaultEntries.Defaults.Url; } else { address_box.Text = Controller.PreviousAddress.ToString(); } address_box.Focus(); address_box.Select(address_box.Text.Length, 0); // Actions. ControllerLoginInsertAction(); 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 { ControllerLoginRemoveAction(); Controller.PageCancelled(); }; string binding = Controller.saved_binding; if (binding == null) { binding = CmisRepoCredentials.BindingBrowser; } continue_button.Click += delegate { // Show wait cursor password_progress.Visibility = Visibility.Visible; System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor; // Try to find the CMIS server (asynchronously) GetRepositoriesDelegate dlgt = new GetRepositoriesDelegate(SetupController.GetRepositories); ServerCredentials credentials = new ServerCredentials() { UserName = user_box.Text, Password = password_box.Password, Address = new Uri(address_box.Text), Binding = binding, }; IAsyncResult ar = dlgt.BeginInvoke(credentials, null, null); while (!ar.AsyncWaitHandle.WaitOne(100)) { System.Windows.Forms.Application.DoEvents(); } var result = dlgt.EndInvoke(ar); Controller.repositories = result.Repositories.WithoutHiddenOnce(); address_box.Text = result.Credentials.Address.ToString(); binding = result.Credentials.Binding; // Hide wait cursor System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default; password_progress.Visibility = Visibility.Hidden; if (Controller.repositories == null) { // Could not retrieve repositories list from server, show warning. string warning = Controller.GetConnectionsProblemWarning(result.FailedException); address_error_label.Text = warning; address_error_label.Visibility = Visibility.Visible; } else { ControllerLoginRemoveAction(); // Continue to next step, which is choosing a particular folder. Controller.Add1PageCompleted( new Uri(address_box.Text), binding, user_box.Text, password_box.Password); } }; }
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 (); }); }; }
/** * Handle the results of an autocomplete query. * Will update the textbox's text value */ void HandleAutoCompleteResult(TextBox textbox, AutoCompleteResult result) { if (!String.IsNullOrEmpty(result.OutputText)) { var currentText = GetUnHighlightedText(textbox); // don't update the textbox if it's changed since autocomplete started if (currentText.Equals(result.InputText)) { textbox.Text = result.OutputText; // select/highlight the autocompleted part so the user can easily skip or delete it textbox.Select(result.InputText.Length, result.OutputText.Length - result.InputText.Length); } } }
private void octet1_KeyDown(object sender, KeyEventArgs e) { check(sender); if (e.Key == Key.Back) { if (((System.Windows.Controls.TextBox)sender).SelectionStart == 0) { switch (((System.Windows.Controls.TextBox)sender).Name) { case "octet2": { System.Windows.Controls.TextBox el = octet1; if (el.Text.Length > 0) { el.Text = el.Text.Substring(0, el.Text.Length); } el.Focus(); el.Select(el.Text.Length, 0); } break; case "octet3": { System.Windows.Controls.TextBox el = octet2; if (el.Text.Length > 0) { el.Text = el.Text.Substring(0, el.Text.Length); } el.Focus(); el.Select(el.Text.Length, 0); } break; case "octet4": { System.Windows.Controls.TextBox el = octet3; if (el.Text.Length > 0) { el.Text = el.Text.Substring(0, el.Text.Length); } el.Focus(); el.Select(el.Text.Length, 0); } break; default: break; } } } else { if (((System.Windows.Controls.TextBox)sender).SelectionStart == 3) { switch (((System.Windows.Controls.TextBox)sender).Name) { case "octet1": { TextBox el = octet2; el.Focus(); el.SelectAll(); } break; case "octet2": { TextBox el = octet3; el.Focus(); el.SelectAll(); } break; case "octet3": { TextBox el = octet4; el.Focus(); el.SelectAll(); } break; default: break; } } } }
private void MITabRename_Click(object sender, RoutedEventArgs e) { TabItem CurrentTab = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TabItem; int index = TCWndLines.Items.IndexOf(CurrentTab); TextBox TBRename = new TextBox(); TBRename.Tag = CurrentTab; TBRename.Text = CurrentTab.Header.ToString().Replace("__", "_"); TBRename.LostFocus +=TBRename_LostFocus; TBRename.KeyDown +=TBRename_KeyDown; CurrentTab.Header = TBRename; TBRename.Select(0, TBRename.Text.Length); // тут необходимо передать фокус созданному TextBox }
//文本字符串处理 private void tbstringfun(TextBox TB, int math, string ct) { switch (math) { //插入处理 case 0: selectPos = TB.SelectionStart; TB.Text = TB.Text.Substring(0, selectPos) + ct + TB.Text.Substring(selectPos); selectPos += 1; TB.Focus(); TB.Select(selectPos, 0); break; //替换处理 case 1: selectPos = TB.SelectionStart; TB.Text = TB.Text.Substring(0, selectPos - 1) + ct + TB.Text.Substring(selectPos); TB.Focus(); TB.Select(selectPos, 0); break; //删除一个字符 case 2: if (!string.IsNullOrEmpty(TB.Text)) { selectPos = TB.SelectionStart; if (selectPos != 0) { TB.Text = TB.Text.Substring(0, selectPos - 1) + TB.Text.Substring(selectPos); selectPos -= 1; TB.Focus(); TB.Select(selectPos, 0); } } break; //清除文本 case 3: TB.Clear(); break; } }
private void TabItem_GotFocus(object sender, RoutedEventArgs e) { MainWindow wnd = new MainWindow(); wnd.WndName = "Wnd_#"; Wins.Add(new WindowSource(wnd)); TCWndLines.Items.Insert(TCWndLines.Items.Count - 1,Wins.Last().TIWindow); TCWndLines.SelectedIndex = TCWndLines.Items.Count - 2; //TreeView TempTV = (((TCWndLines.Items[TCWndLines.Items.Count - 2] as TabItem).Content as ScrollViewer).Content as Grid).Children[0] as TreeView; Wins.Last().TVWindow.PreviewMouseLeftButtonDown +=TreeView_PreviewMouseLeftButtonDown; //WndTreeViews.Add(TempTV); int index = TCWndLines.SelectedIndex; TabItem CurrentTab = TCWndLines.Items[index] as TabItem; TextBox TBRename = new TextBox(); TBRename.Tag = CurrentTab; TBRename.KeyDown += TBRename_KeyDown; TBRename.LostFocus += TBRename_LostFocus; TBRename.Text = Wins[index].Name; CurrentTab.Header = TBRename; TBRename.Select(0, TBRename.Text.Length); // тут необходимо передать фокус созданному TextBox }
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 SparkleShare!"; Description = "First off, what's your name and email?\nThis information is only visible to team members."; TextBlock name_label = new TextBlock () { Text = "Full Name:", Width = 150, TextAlignment = TextAlignment.Right, FontWeight = FontWeights.Bold }; string name = System.Security.Principal.WindowsIdentity.GetCurrent ().Name; name = name.Split ("\\".ToCharArray ()) [1]; TextBox name_box = new TextBox () { Text = name, Width = 175 }; TextBlock email_label = new TextBlock () { Text = "Email:", Width = 150, TextAlignment = TextAlignment.Right, FontWeight = FontWeights.Bold }; TextBox email_box = new TextBox () { Width = 175 }; Button cancel_button = new Button () { Content = "Cancel" }; Button continue_button = new Button () { Content = "Continue", IsEnabled = false }; ContentCanvas.Children.Add (name_label); Canvas.SetLeft (name_label, 180); Canvas.SetTop (name_label, 200 + 3); ContentCanvas.Children.Add (name_box); Canvas.SetLeft (name_box, 340); Canvas.SetTop (name_box, 200); ContentCanvas.Children.Add (email_label); Canvas.SetLeft (email_label, 180); Canvas.SetTop (email_label, 230 + 3); ContentCanvas.Children.Add (email_box); Canvas.SetLeft (email_box, 340); Canvas.SetTop (email_box, 230); Buttons.Add (continue_button); Buttons.Add (cancel_button); name_box.Focus (); name_box.Select (name_box.Text.Length, 0); Controller.UpdateSetupContinueButtonEvent += delegate (bool enabled) { Dispatcher.BeginInvoke ((Action) delegate { continue_button.IsEnabled = enabled; }); }; name_box.TextChanged += delegate { Controller.CheckSetupPage (name_box.Text, email_box.Text); }; email_box.TextChanged += delegate { Controller.CheckSetupPage (name_box.Text, email_box.Text); }; cancel_button.Click += delegate { Dispatcher.BeginInvoke ((Action) delegate { Program.UI.StatusIcon.Dispose (); Controller.SetupPageCancelled (); }); }; continue_button.Click += delegate { Controller.SetupPageCompleted (name_box.Text, email_box.Text); }; Controller.CheckSetupPage (name_box.Text, email_box.Text); 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.Add: { Header = "Where's your project hosted?"; ListView list_view = new ListView () { Width = 419, Height = 195, SelectionMode = SelectionMode.Single }; GridView grid_view = new GridView () { AllowsColumnReorder = false }; grid_view.Columns.Add (new GridViewColumn ()); string xaml = "<DataTemplate xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"" + " xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\">" + " <Grid>" + " <StackPanel Orientation=\"Horizontal\">" + " <Image Margin=\"5,0,0,0\" Source=\"{Binding Image}\" Height=\"24\" Width=\"24\"/>" + " <StackPanel>" + " <TextBlock Padding=\"10,4,0,0\" FontWeight=\"Bold\" Text=\"{Binding Name}\">" + " </TextBlock>" + " <TextBlock Padding=\"10,0,0,4\" Opacity=\"0.5\" Text=\"{Binding Description}\">" + " </TextBlock>" + " </StackPanel>" + " </StackPanel>" + " </Grid>" + "</DataTemplate>"; grid_view.Columns [0].CellTemplate = (DataTemplate) XamlReader.Parse (xaml); Style header_style = new Style(typeof (GridViewColumnHeader)); header_style.Setters.Add (new Setter (GridViewColumnHeader.VisibilityProperty, Visibility.Collapsed)); grid_view.ColumnHeaderContainerStyle = header_style; foreach (SparklePlugin plugin in Controller.Plugins) { // FIXME: images are blurry BitmapFrame image = BitmapFrame.Create ( new Uri (plugin.ImagePath) ); list_view.Items.Add ( new { Name = plugin.Name, Description = plugin.Description, Image = image } ); } list_view.View = grid_view; list_view.SelectedIndex = Controller.SelectedPluginIndex; TextBlock address_label = new TextBlock () { Text = "Address:", FontWeight = FontWeights.Bold }; TextBox address_box = new TextBox () { Width = 200, Text = Controller.PreviousAddress, IsEnabled = (Controller.SelectedPlugin.Address == null) }; TextBlock address_help_label = new TextBlock () { Text = Controller.SelectedPlugin.AddressExample, FontSize = 11, Foreground = new SolidColorBrush (Color.FromRgb (128, 128, 128)) }; TextBlock path_label = new TextBlock () { Text = "Remote Path:", FontWeight = FontWeights.Bold, Width = 200 }; TextBox path_box = new TextBox () { Width = 200, Text = Controller.PreviousPath, IsEnabled = (Controller.SelectedPlugin.Path == null) }; TextBlock path_help_label = new TextBlock () { Text = Controller.SelectedPlugin.PathExample, FontSize = 11, Width = 200, Foreground = new SolidColorBrush (Color.FromRgb (128, 128, 128)) }; Button cancel_button = new Button () { Content = "Cancel" }; Button add_button = new Button () { Content = "Add" }; CheckBox history_check_box = new CheckBox () { Content = "Fetch prior revisions", IsChecked = Controller.FetchPriorHistory }; history_check_box.Click += delegate { Controller.HistoryItemChanged (history_check_box.IsChecked.Value); }; ContentCanvas.Children.Add (history_check_box); Canvas.SetLeft (history_check_box, 185); Canvas.SetBottom (history_check_box, 12); ContentCanvas.Children.Add (list_view); Canvas.SetTop (list_view, 70); Canvas.SetLeft (list_view, 185); ContentCanvas.Children.Add (address_label); Canvas.SetTop (address_label, 285); Canvas.SetLeft (address_label, 185); ContentCanvas.Children.Add (address_box); Canvas.SetTop (address_box, 305); Canvas.SetLeft (address_box, 185); ContentCanvas.Children.Add (address_help_label); Canvas.SetTop (address_help_label, 330); Canvas.SetLeft (address_help_label, 185); ContentCanvas.Children.Add (path_label); Canvas.SetTop (path_label, 285); Canvas.SetRight (path_label, 30); ContentCanvas.Children.Add (path_box); Canvas.SetTop (path_box, 305); Canvas.SetRight (path_box, 30); ContentCanvas.Children.Add (path_help_label); Canvas.SetTop (path_help_label, 330); Canvas.SetRight (path_help_label, 30); TaskbarItemInfo.ProgressValue = 0.0; TaskbarItemInfo.ProgressState = TaskbarItemProgressState.None; Buttons.Add (add_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.ChangePathFieldEvent += delegate (string text, string example_text, FieldState state) { Dispatcher.BeginInvoke ((Action) delegate { path_box.Text = text; path_box.IsEnabled = (state == FieldState.Enabled); path_help_label.Text = example_text; }); }; Controller.UpdateAddProjectButtonEvent += delegate (bool button_enabled) { Dispatcher.BeginInvoke ((Action) delegate { add_button.IsEnabled = button_enabled; }); }; list_view.SelectionChanged += delegate { Controller.SelectedPluginChanged (list_view.SelectedIndex); }; list_view.KeyDown += delegate { Controller.SelectedPluginChanged (list_view.SelectedIndex); }; Controller.CheckAddPage (address_box.Text, path_box.Text, list_view.SelectedIndex); address_box.TextChanged += delegate { Controller.CheckAddPage (address_box.Text, path_box.Text, list_view.SelectedIndex); }; path_box.TextChanged += delegate { Controller.CheckAddPage (address_box.Text, path_box.Text, list_view.SelectedIndex); }; cancel_button.Click += delegate { Controller.PageCancelled (); }; add_button.Click += delegate { Controller.AddPageCompleted (address_box.Text, path_box.Text); }; break; } case PageType.Syncing: { Header = "Adding project ‘" + Controller.SyncingFolder + "’…"; Description = "This may take a while for large projects.\nIsn't it coffee-o'clock?"; 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.CryptoSetup: { Header = "Set up file encryption"; Description = "This project is supposed to be encrypted, but it doesn't yet have a password set. Please provide one below."; TextBlock password_label = new TextBlock () { Text = "Password:"******"Show password", IsChecked = false }; TextBlock info_label = new TextBlock () { Text = "This password can't be changed later, and your files can't be recovered if it's forgotten.", TextWrapping = TextWrapping.Wrap, Width = 315 }; Image warning_image = new Image () { Source = Imaging.CreateBitmapSourceFromHIcon (Drawing.SystemIcons.Information.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions ()) }; show_password_checkbox.Checked += delegate { visible_password_box.Text = password_box.Password; visible_password_box.Visibility = Visibility.Visible; password_box.Visibility = Visibility.Hidden; }; show_password_checkbox.Unchecked += delegate { password_box.Password = visible_password_box.Text; password_box.Visibility = Visibility.Visible; visible_password_box.Visibility = Visibility.Hidden; }; password_box.PasswordChanged += delegate { Controller.CheckCryptoSetupPage (password_box.Password); }; visible_password_box.TextChanged += delegate { Controller.CheckCryptoSetupPage (visible_password_box.Text); }; Button continue_button = new Button () { Content = "Continue", IsEnabled = false }; continue_button.Click += delegate { if (show_password_checkbox.IsChecked == true) Controller.CryptoSetupPageCompleted (visible_password_box.Text); else Controller.CryptoSetupPageCompleted (password_box.Password); }; Button cancel_button = new Button () { Content = "Cancel" }; cancel_button.Click += delegate { Controller.CryptoPageCancelled (); }; Controller.UpdateCryptoSetupContinueButtonEvent += delegate (bool button_enabled) { Dispatcher.BeginInvoke ((Action) delegate { continue_button.IsEnabled = button_enabled; }); }; ContentCanvas.Children.Add (password_label); Canvas.SetLeft (password_label, 270); Canvas.SetTop (password_label, 180); ContentCanvas.Children.Add (password_box); Canvas.SetLeft (password_box, 335); Canvas.SetTop (password_box, 180); ContentCanvas.Children.Add (visible_password_box); Canvas.SetLeft (visible_password_box, 335); Canvas.SetTop (visible_password_box, 180); ContentCanvas.Children.Add (show_password_checkbox); Canvas.SetLeft (show_password_checkbox, 338); Canvas.SetTop (show_password_checkbox, 208); ContentCanvas.Children.Add (info_label); Canvas.SetLeft (info_label, 240); Canvas.SetTop (info_label, 300); ContentCanvas.Children.Add (warning_image); Canvas.SetLeft (warning_image, 193); Canvas.SetTop (warning_image, 300); Buttons.Add (continue_button); Buttons.Add (cancel_button); break; } case PageType.CryptoPassword: { Header = "This project contains encrypted files"; Description = "Please enter the password to see their contents."; TextBlock password_label = new TextBlock () { Text = "Password:"******"Show password", IsChecked = false }; show_password_checkbox.Checked += delegate { visible_password_box.Text = password_box.Password; visible_password_box.Visibility = Visibility.Visible; password_box.Visibility = Visibility.Hidden; }; show_password_checkbox.Unchecked += delegate { password_box.Password = visible_password_box.Text; password_box.Visibility = Visibility.Visible; visible_password_box.Visibility = Visibility.Hidden; }; password_box.PasswordChanged += delegate { Controller.CheckCryptoPasswordPage (password_box.Password); }; visible_password_box.TextChanged += delegate { Controller.CheckCryptoPasswordPage (visible_password_box.Text); }; Button continue_button = new Button () { Content = "Continue", IsEnabled = false }; continue_button.Click += delegate { if (show_password_checkbox.IsChecked == true) Controller.CryptoPasswordPageCompleted (visible_password_box.Text); else Controller.CryptoPasswordPageCompleted (password_box.Password); }; Button cancel_button = new Button () { Content = "Cancel" }; cancel_button.Click += delegate { Controller.CryptoPageCancelled (); }; Controller.UpdateCryptoPasswordContinueButtonEvent += delegate (bool button_enabled) { Dispatcher.BeginInvoke ((Action) delegate { continue_button.IsEnabled = button_enabled; }); }; ContentCanvas.Children.Add (password_label); Canvas.SetLeft (password_label, 270); Canvas.SetTop (password_label, 180); ContentCanvas.Children.Add (password_box); Canvas.SetLeft (password_box, 335); Canvas.SetTop (password_box, 180); ContentCanvas.Children.Add (visible_password_box); Canvas.SetLeft (visible_password_box, 335); Canvas.SetTop (visible_password_box, 180); ContentCanvas.Children.Add (show_password_checkbox); Canvas.SetLeft (show_password_checkbox, 338); Canvas.SetTop (show_password_checkbox, 208); Buttons.Add (continue_button); Buttons.Add (cancel_button); break; } case PageType.Finished: { Header = "Your shared project is ready!"; Description = "You can find the files in your SparkleShare folder."; Button finish_button = new Button () { Content = "Finish" }; Button show_files_button = new Button () { Content = "Show files" }; 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 (show_files_button); Buttons.Add (finish_button); finish_button.Click += delegate { Controller.FinishPageCompleted (); }; show_files_button.Click += delegate { Controller.ShowFilesClicked (); }; SystemSounds.Exclamation.Play (); break; } case PageType.Tutorial: { switch (Controller.TutorialPageNumber) { case 1: { Header = "What's happening next?"; Description = "SparkleShare creates a special folder on your computer " + "that will keep track of your projects."; 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 your project folders are synced automatically with " + "the host and your team members."; 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 projects 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 projects to SparkleShare"; Description = "You can do this through the status icon menu, or by clicking " + "magic buttons on webpages that look like this:"; Button finish_button = new Button () { Content = "Finish" }; WPF.Image slide_image = new WPF.Image () { Width = 350, Height = 64 }; slide_image.Source = SparkleUIHelpers.GetImageSource ("tutorial-slide-4"); CheckBox check_box = new CheckBox () { Content = "Add SparkleShare 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 (); }); }; }
/** * Constructor */ public SearchBar() { mSearchBar = new System.Windows.Controls.TextBox(); View = mSearchBar; mIsWatermarkMode = false; mPlaceholderText = ""; // by default, the placeholder font color is gray mWaterMarkBrush = new SolidColorBrush(); mWaterMarkBrush.Color = Colors.Gray; mForegroundColor = mSearchBar.Foreground; /** * @brief Sent from the Search bar when it gains focus(the user selects the widget). * The virtual keyboard is shown. */ mSearchBar.GotFocus += new RoutedEventHandler( delegate(object from, RoutedEventArgs args) { /** * simulating the placeholder/watermark */ // if watermark present and no user char has been entered if (mIsWatermarkMode && mFirstChar) { // move the cursor to the first position mSearchBar.Select(0, 0); } } ); // end of mEditBox.GotFocus /** * @brief Sent from the Search bar when it loses focus. * The virtual keyboard is hidden. */ mSearchBar.LostFocus += new RoutedEventHandler( delegate(object from, RoutedEventArgs args) { /** * simulating the placeholder/watermark */ // if no text has been entered by the user than leave the watermark text if (mSearchBar.Text.Equals("")) { setWatermarkMode(true); } } ); // end of mEditBox.LostFocus /** * @brief Sent from the Search bar when the text was changed. * As the search bar allows searching while the user types, this is * the place where we send the search event (the MAW_EVENT_CLICKED with * the search button click 0 (0 = OK, 1 = CANCEL). * The cancel search is not handled on the windows phone platform. */ mFirstChar = true; mSearchBar.TextInputStart += new TextCompositionEventHandler( delegate(object from, TextCompositionEventArgs args) { /** * simulating the placeholder/watermark */ if (mFirstChar) { setWatermarkMode(false); } /** * post the event to MoSync runtime * MAW_EVENT_CLICKED + search button clicked = 0 (0 = OK, 1 = CANCEL) */ Memory eventData = new Memory(12); const int MAWidgetEventData_eventType = 0; const int MAWidgetEventData_widgetHandle = 4; const int MAWidgetEventData_searchButtonClicked = 8; eventData.WriteInt32(MAWidgetEventData_eventType, MoSync.Constants.MAW_EVENT_CLICKED); eventData.WriteInt32(MAWidgetEventData_widgetHandle, mHandle); eventData.WriteInt32(MAWidgetEventData_searchButtonClicked, 0); mRuntime.PostCustomEvent(MoSync.Constants.EVENT_TYPE_WIDGET, eventData); } ); // end of TextInputStart }
/// <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."); }
internal void BeginEditTextOnSelected() { ItemLostFocus(); selectedForEditing = (SelectedItem as DragDropTreeViewItem); if (selectedForEditing == null) return; TextBox tb = new TextBox(); tb.LostFocus += tb_LostFocus; tb.KeyDown += tb_KeyDown; tb.Text = lastSelectedItem.Tag.ToString(); tb.Focusable = true; (selectedForEditing.Header as StackPanel).Children.RemoveAt(2); (selectedForEditing.Header as StackPanel).Children.Add(tb); selectedForEditing.CanDrag = false; tb.Select(0, tb.Text.Length); tb.Focus(); }