/////////////////////////////////////////////////////////////////////////////////////////////////// private void setSearchByProjectEnabled(bool isEnabled) { checkBoxSearchByProject.Enabled = isEnabled; bool wasEnabled = comboBoxProjectName.Enabled; comboBoxProjectName.Enabled = isEnabled; if (!wasEnabled && isEnabled) { DataCache dataCache = getDataCache(EDataCacheType.Live); string[] projectNames = dataCache?.ProjectCache?.GetProjects() .OrderBy(project => project.Path_With_Namespace) .Select(project => project.Path_With_Namespace) .ToArray() ?? Array.Empty <string>(); string selectedProject = (string)comboBoxProjectName.SelectedItem; string previousSelection = selectedProject ?? String.Empty; string defaultProjectName = projectNames.SingleOrDefault(name => name == previousSelection) == null ? getDefaultProjectName() : previousSelection; WinFormsHelpers.FillComboBox(comboBoxProjectName, projectNames, projectName => projectName == defaultProjectName); } updateSearchButtonState(); }
private void setSearchByAuthorEnabled(bool isEnabled, string hostname) { checkBoxSearchByAuthor.Enabled = isEnabled; linkLabelFindMe.Enabled = isEnabled; bool wasEnabled = comboBoxUser.Enabled; comboBoxUser.Enabled = isEnabled; if (!wasEnabled && isEnabled) { DataCache dataCache = getDataCache(EDataCacheType.Live); User[] users = dataCache?.UserCache?.GetUsers() .OrderBy(user => user.Name).ToArray() ?? Array.Empty <User>(); if (!users.Any()) { WinFormsHelpers.FillComboBox(comboBoxUser, users, _ => false); } else { User selectedUser = (User)comboBoxUser.SelectedItem; string previousSelection = selectedUser == null ? String.Empty : selectedUser.Name; bool hasPreviousSelection = users.SingleOrDefault(user => user.Name == previousSelection) != null; User defaultUser = getCurrentUser(hostname) ?? users.First(); string defaultUserFullName = hasPreviousSelection ? previousSelection : defaultUser.Name; WinFormsHelpers.FillComboBox(comboBoxUser, users, user => user.Name == defaultUserFullName); } } updateSearchButtonState(); }
internal void setDiscussionNoteText(Control noteControl, DiscussionNote note) { if (note == null) { // this is possible when noteControl detaches from parent return; } Debug.Assert(noteControl is HtmlPanel); HtmlPanel htmlPanel = noteControl as HtmlPanel; htmlPanel.BaseStylesheet = String.Format( "{0} body div {{ font-size: {1}px; padding-left: 4px; padding-right: {2}px; }}", Properties.Resources.Common_CSS, WinFormsHelpers.GetFontSizeInPixels(noteControl), SystemInformation.VerticalScrollBarWidth * 2); // this is really weird // We need to zero the control size before SetText call to allow HtmlPanel to compute the size int prevWidth = noteControl.Width; noteControl.Width = 0; noteControl.Height = 0; string body = MarkDownUtils.ConvertToHtml(note.Body, _imagePath, _specialDiscussionNoteMarkdownPipeline); noteControl.Text = String.Format(MarkDownUtils.HtmlPageTemplate, addPrefix(body, note, _firstNoteAuthor)); resizeLimitedWidthHtmlPanel(htmlPanel, prevWidth); _htmlDiscussionNoteToolTip.BaseStylesheet = String.Format("{0} body div {{ font-size: {1}px; }}", Properties.Resources.Common_CSS, WinFormsHelpers.GetFontSizeInPixels(noteControl)); _htmlDiscussionNoteToolTip.SetToolTip(noteControl, getNoteTooltipHtml(note)); }
private void setDiffContextText(Control diffContextControl) { double fontSizePx = WinFormsHelpers.GetFontSizeInPixels(diffContextControl); DiscussionNote note = getNoteFromControl(diffContextControl); Debug.Assert(note.Type == "DiffNote"); DiffPosition position = PositionConverter.Convert(note.Position); Debug.Assert(diffContextControl is HtmlPanel); HtmlPanel htmlPanel = diffContextControl as HtmlPanel; // We need to zero the control size before SetText call to allow HtmlPanel to compute the size int prevWidth = htmlPanel.Width; htmlPanel.Width = 0; htmlPanel.Height = 0; string html = getContext(_panelContextMaker, position, _diffContextDepth, fontSizePx, out string css); htmlPanel.BaseStylesheet = css; htmlPanel.Text = html; resizeLimitedWidthHtmlPanel(htmlPanel, prevWidth); string tooltipHtml = getContext(_tooltipContextMaker, position, _tooltipContextDepth, fontSizePx, out string tooltipCSS); _htmlDiffContextToolTip.BaseStylesheet = String.Format("{0} .htmltooltip {{ padding: 1px; }}", tooltipCSS); _htmlDiffContextToolTip.SetToolTip(htmlPanel, tooltipHtml); }
private void mainForm_FormClosing(object sender, FormClosingEventArgs e) { Trace.TraceInformation(String.Format("[MainForm] Requested to close the Main Form. Reason: {0}", e.CloseReason.ToString())); if (e.CloseReason == CloseReason.ApplicationExitCall) { // abnormal exit return; } if (checkBoxMinimizeOnClose.Checked && !_exiting && e.CloseReason == CloseReason.UserClosing) { e.Cancel = true; onHideToTray(); return; } Program.Settings.WasMaximizedBeforeClose = WindowState == FormWindowState.Maximized; setExitingFlag(); Hide(); WinFormsHelpers.CloseAllFormsExceptOne(this); finalizeWork(); }
private void setServiceDiscussionNoteText(Control noteControl, DiscussionNote note) { if (note == null) { Debug.Assert(false); return; } // We need to zero the control size before SetText call to allow HtmlPanel to compute the size noteControl.Width = 0; noteControl.Height = 0; Debug.Assert(noteControl is HtmlPanel); HtmlPanel htmlPanel = noteControl as HtmlPanel; htmlPanel.BaseStylesheet = String.Format("{0} body div {{ font-size: {1}px; }}", Properties.Resources.Common_CSS, WinFormsHelpers.GetFontSizeInPixels(noteControl)); string body = MarkDownUtils.ConvertToHtml(note.Body, _imagePath, _specialDiscussionNoteMarkdownPipeline); noteControl.Text = String.Format(MarkDownUtils.HtmlPageTemplate, body); resizeFullSizeHtmlPanel(noteControl as HtmlPanel); }
private string getContextHtmlText(DiffPosition position, IGitCommandService git, out string stylesheet) { stylesheet = String.Empty; DiffContext?context; try { ContextDepth depth = new ContextDepth(0, 3); IContextMaker textContextMaker = new SimpleContextMaker(git); context = textContextMaker.GetContext(position, depth); } catch (Exception ex) { if (ex is ArgumentException || ex is ContextMakingException) { string errorMessage = "Cannot render HTML context."; ExceptionHandlers.Handle(errorMessage, ex); return(String.Format("<html><body>{0} See logs for details</body></html>", errorMessage)); } throw; } Debug.Assert(context.HasValue); DiffContextFormatter formatter = new DiffContextFormatter(WinFormsHelpers.GetFontSizeInPixels(htmlPanelContext), 2); stylesheet = formatter.GetStylesheet(); return(formatter.GetBody(context.Value)); }
private string getContextHtmlText(DiffPosition position, HtmlPanel htmlPanel, out string stylesheet) { stylesheet = String.Empty; double fontSizePx = WinFormsHelpers.GetFontSizeInPixels(htmlPanel); var getContext = isCurrentNoteNew() ? _getNewDiscussionDiffContext(position) : _getDiffContext(position); return(DiffContextFormatter.GetHtml(getContext, fontSizePx, 2, true)); }
public DiscussionFontSelectionPanel(Action <string> onFontSelectionChanged) { _onFontSelectionChanged = onFontSelectionChanged; InitializeComponent(); WinFormsHelpers.FillComboBox(comboBoxFonts, Constants.DiscussionsWindowFontSizeChoices, Program.Settings.MainWindowFontSizeName); }
/////////////////////////////////////////////////////////////////////////////////////////////////// private void onLiveDataCacheDisconnected() { clearCustomActionControls(); disableLiveTabControls(); stopRedrawTimer(); WinFormsHelpers.CloseAllFormsExceptOne(this); disposeGitHelpers(); disposeLocalGitRepositoryFactory(); unsubscribeFromLiveDataCacheInternalEvents(); }
private void setColumnIndices(Dictionary <string, int> indices) { try { WinFormsHelpers.ReorderListViewColumns(this, indices); } catch (ArgumentException ex) { ExceptionHandlers.Handle("[MainForm] Cannot restore list view column display indices", ex); ConfigurationHelper.SetColumnIndices(Program.Settings, WinFormsHelpers.GetListViewDisplayIndices(this), getIdentity()); } }
private void loadColumnIndices(ListView listView, Dictionary <string, int> storedIndices, Action <Dictionary <string, int> > storeDefaults) { try { WinFormsHelpers.ReorderListViewColumns(listView, storedIndices); } catch (ArgumentException ex) { ExceptionHandlers.Handle("[MainForm] Cannot restore list view column display indices", ex); storeDefaults(WinFormsHelpers.GetListViewDisplayIndices(listView)); } }
private void addIconToCache(Color color) { if (_iconCache.ContainsKey(color)) { return; } Bitmap imageWithoutBorder = WinFormsHelpers.ReplaceColorInBitmap( Properties.Resources.gitlab_icon_stub_16x16, Color.Green, color); Icon iconWithoutBorder = WinFormsHelpers.ConvertToIco(imageWithoutBorder, 16); Bitmap imageWithBorder = WinFormsHelpers.ReplaceColorInBitmap( Properties.Resources.gitlab_icon_stub_16x16_border, Color.Green, color); Icon iconWithBorder = WinFormsHelpers.ConvertToIco(imageWithBorder, 16); _iconCache.Add(color, new IconGroup(iconWithoutBorder, iconWithBorder)); }
private void onDrawListBoxColorSchemeItemSelectorItem(DrawItemEventArgs e) { if (e.Index < 0) { return; } string colorSchemeItemName = listBoxColorSchemeItemSelector.Items[e.Index].ToString(); ColorSchemeItem colorSchemeItem = _colorScheme.GetColor(colorSchemeItemName); if (colorSchemeItem == null) { return; } Color color = colorSchemeItem.Color; bool isSelected = (e.State & DrawItemState.Selected) == DrawItemState.Selected; WinFormsHelpers.FillRectangle(e, e.Bounds, color, isSelected); StringFormat format = new StringFormat { Trimming = StringTrimming.EllipsisCharacter, FormatFlags = StringFormatFlags.NoWrap }; string text = colorSchemeItem.DisplayName; Font font = listBoxColorSchemeItemSelector.Font; if (isSelected) { using (Brush brush = new SolidBrush(color)) { e.Graphics.DrawString(text, font, brush, e.Bounds, format); } } else { e.Graphics.DrawString(text, font, SystemBrushes.ControlText, e.Bounds, format); } }
private void acceptMergeRequest(FullMergeRequestKey item) { DataCache dataCache = getDataCache(EDataCacheType.Live); MergeRequestKey mrk = new MergeRequestKey(item.ProjectKey, item.MergeRequest.IId); bool doesMatchTag(object tag) => tag != null && ((MergeRequestKey)(tag)).Equals(mrk); Form formExisting = WinFormsHelpers.FindFormByTag("AcceptMergeRequestForm", doesMatchTag); if (formExisting != null) { formExisting.Activate(); return; } AcceptMergeRequestForm form = new AcceptMergeRequestForm( mrk, getCommitStorage(mrk.ProjectKey, false)?.Path, () => { addOperationRecord(String.Format("Merge Request !{0} has been merged successfully", mrk.IId)); requestUpdates(EDataCacheType.Live, null, new int[] { Program.Settings.NewOrClosedMergeRequestRefreshListDelayMs }); }, showDiscussionsFormAsync, () => dataCache, async() => { await checkForUpdatesAsync(dataCache, mrk, DataCacheUpdateKind.MergeRequest); return(dataCache); }, () => _shortcuts.GetMergeRequestAccessor(mrk.ProjectKey.ProjectName)) { Tag = mrk }; form.Show(); }
private void recalcRowHeightForMergeRequestListView() { if (Items.Count == 0) { return; } int getMaxRowCountInColumn(string columnName) { int labelsColumnIndex = getColumnByTag(columnName).Index; IEnumerable <string> rows = Items.Cast <ListViewItem>() .Select(item => ((ListViewSubItemInfo)(item.SubItems[labelsColumnIndex].Tag)).Text); IEnumerable <int> rowCounts = rows .Select(thing => thing.Count(y => y == '\n')); return(rowCounts.Max() + 1); } int maxLineCount = Math.Max(getMaxRowCountInColumn("Labels"), getMaxRowCountInColumn("Author")); WinFormsHelpers.SetListViewRowHeight(this, maxLineCount); }
private async void gunaGradientButton1_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(gunaLineTextBox1.Text) && !string.IsNullOrWhiteSpace(gunaLineTextBox1.Text)) // If the textbox isn't null { if (!gunaLineTextBox1.Text.Contains("https://") && !gunaLineTextBox1.Text.Contains("http://")) // If the box doesn't contains https or http { gunaLineTextBox1.Text = "https://" + gunaLineTextBox1.Text; // Add the https } if (await NetworkConnection.IsAvailableTestSiteAsync(gunaLineTextBox1.Text)) // Check if the site is available { gunaLabel2.Text = Language.WebSiteNotDownMessage; // Set the text WinFormsHelpers.CenterControlOnForm(gunaLabel2, this, ControlAlignement.Horizontal); // Center gunaPictureBox2.Image = Properties.Resources.check; // Set the image } else { gunaLabel2.Text = Language.WebSiteDownMessage; // Set the text WinFormsHelpers.CenterControlOnForm(gunaLabel2, this, ControlAlignement.Horizontal); // Center gunaPictureBox2.Image = Properties.Resources.cancel; // Set the image } } }
private void panelScroll_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e) { WinFormsHelpers.ConvertMouseWheelToClick(buttonScrollDown, buttonScrollUp, e.Delta); }
private void setFontFromSettings() { WinFormsHelpers.FillComboBox(comboBoxFonts, Constants.MainWindowFontSizeChoices, name => name == Program.Settings.MainWindowFontSizeName); applyFont(Program.Settings.MainWindowFontSizeName); }
private void setThemeFromSettings() { WinFormsHelpers.FillComboBox(comboBoxThemes, Constants.ThemeNames, name => name == Program.Settings.VisualThemeName); applyTheme(Program.Settings.VisualThemeName); }
private void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e) { WinFormsHelpers.LogScreenResolution(this); }
private void saveColumIndices(int oldIndex, int newIndex) { var indices = WinFormsHelpers.GetListViewDisplayIndicesOnColumnReordered(this, oldIndex, newIndex); ConfigurationHelper.SetColumnIndices(Program.Settings, indices, getIdentity()); }
protected override void OnDrawSubItem(DrawListViewSubItemEventArgs e) { base.OnDrawSubItem(e); if (e.Item.ListView == null) { return; // is being removed } int iidColumnIndex = getColumnByTag("IId").Index; int labelsColumnIndex = getColumnByTag("Labels").Index; int?resolvedCountColumnIndex = getColumnByTag("Resolved")?.Index; int?totalTimeColumnIndex = getColumnByTag("TotalTime")?.Index; int?titleColumnIndex = getColumnByTag("Title")?.Index; int?sourceBranchColumnIndex = getColumnByTag("SourceBranch")?.Index; int?targetBranchColumnIndex = getColumnByTag("TargetBranch")?.Index; int?jiraColumnIndex = getColumnByTag("Jira")?.Index; int?authorColumnIndex = getColumnByTag("Author")?.Index; bool isIIdColumnItem = e.ColumnIndex == iidColumnIndex; bool isLabelsColumnItem = e.ColumnIndex == labelsColumnIndex; bool isResolvedColumnItem = resolvedCountColumnIndex.HasValue && e.ColumnIndex == resolvedCountColumnIndex.Value; bool isTotalTimeColumnItem = totalTimeColumnIndex.HasValue && e.ColumnIndex == totalTimeColumnIndex.Value; bool isTitleColumnItem = titleColumnIndex.HasValue && e.ColumnIndex == titleColumnIndex.Value; bool isSourceBranchColumnItem = sourceBranchColumnIndex.HasValue && e.ColumnIndex == sourceBranchColumnIndex.Value; bool isTargetBranchColumnItem = targetBranchColumnIndex.HasValue && e.ColumnIndex == targetBranchColumnIndex.Value; bool isJiraColumnItem = jiraColumnIndex.HasValue && e.ColumnIndex == jiraColumnIndex.Value; bool isAuthorColumnItem = authorColumnIndex.HasValue && e.ColumnIndex == authorColumnIndex.Value; bool isWrappableColumnItem = isTitleColumnItem || isSourceBranchColumnItem || isTargetBranchColumnItem || isJiraColumnItem || isAuthorColumnItem; bool needWordWrap = isWrappableColumnItem && Program.Settings.WordWrapLongRows; StringFormatFlags formatFlags = needWordWrap ? StringFormatFlags.LineLimit : StringFormatFlags.NoWrap; StringFormat format = new StringFormat { Trimming = StringTrimming.EllipsisCharacter, FormatFlags = formatFlags }; Rectangle bounds = e.Bounds; if (e.ColumnIndex == 0 && e.Item.ListView.Columns[0].DisplayIndex != 0) { bounds = WinFormsHelpers.GetFirstColumnCorrectRectangle(e.Item.ListView, e.Item); } bool isSelected = e.Item.Selected; FullMergeRequestKey fmk = (FullMergeRequestKey)(e.Item.Tag); Color backgroundColor = getMergeRequestColor(fmk, Color.Transparent, true); WinFormsHelpers.FillRectangle(e, bounds, backgroundColor, isSelected); string text = ((ListViewSubItemInfo)(e.SubItem.Tag)).Text; bool isClickable = ((ListViewSubItemInfo)(e.SubItem.Tag)).Clickable; if (isIIdColumnItem) { FontStyle fontStyle = isClickable ? FontStyle.Underline : FontStyle.Regular; using (Font font = new Font(e.Item.ListView.Font, fontStyle)) { e.Graphics.DrawString(text, font, Brushes.Blue, bounds, format); if (isMuted(fmk)) { drawEllipseForIId(e.Graphics, format, bounds, fmk, font); } } } else if (isClickable) { using (Font font = new Font(e.Item.ListView.Font, FontStyle.Underline)) { Brush brush = Brushes.Blue; e.Graphics.DrawString(text, font, brush, bounds, format); } } else if (isSelected && isLabelsColumnItem) { using (Brush brush = new SolidBrush(getMergeRequestColor(fmk, SystemColors.Window, true))) { e.Graphics.DrawString(text, e.Item.ListView.Font, brush, bounds, format); } } else if (isResolvedColumnItem) { using (Brush brush = new SolidBrush(getDiscussionCountColor(fmk, isSelected))) { e.Graphics.DrawString(text, e.Item.ListView.Font, brush, bounds, format); } } else if (isTotalTimeColumnItem) { Brush brush = text == Constants.NotAllowedTimeTrackingText ? Brushes.Gray : Brushes.Black; e.Graphics.DrawString(text, e.Item.ListView.Font, brush, bounds, format); } else { Brush textBrush = isSelected ? SystemBrushes.HighlightText : SystemBrushes.ControlText; e.Graphics.DrawString(text, e.Item.ListView.Font, textBrush, bounds, format); } }
private void updatePreview(HtmlPanel previewPanel, string text) { previewPanel.BaseStylesheet = String.Format("{0} body div {{ font-size: {1}px; }}", Properties.Resources.Common_CSS, WinFormsHelpers.GetFontSizeInPixels(previewPanel)); var pipeline = MarkDownUtils.CreatePipeline(Program.ServiceManager.GetJiraServiceUrl()); string body = MarkDownUtils.ConvertToHtml(text, String.Empty, pipeline); previewPanel.Text = String.Format(MarkDownUtils.HtmlPageTemplate, body); }
private void panelNavigation_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e) { WinFormsHelpers.ConvertMouseWheelToClick(buttonNext, buttonPrev, e.Delta); }
protected void fillProjectListAndSelect(IEnumerable <string> projects, string defaultProjectName) { comboBoxProject.Items.AddRange(projects.OrderBy(x => x).ToArray()); WinFormsHelpers.SelectComboBoxItem(comboBoxProject, String.IsNullOrWhiteSpace(defaultProjectName) ? null : new Func <object, bool>(o => (o as string) == defaultProjectName)); }
protected void fillTargetBranchListAndSelect(IEnumerable <string> branchNames, string defaultTargetBranchName) { comboBoxTargetBranch.Items.AddRange(branchNames.ToArray()); WinFormsHelpers.SelectComboBoxItem(comboBoxTargetBranch, String.IsNullOrWhiteSpace(defaultTargetBranchName) ? null : new Func <object, bool>(o => (o as string) == defaultTargetBranchName)); }
protected void fillSourceBranchListAndSelect(IEnumerable <Branch> branches, string defaultSourceBrachName) { comboBoxSourceBranch.Items.AddRange(branches.ToArray()); WinFormsHelpers.SelectComboBoxItem(comboBoxSourceBranch, String.IsNullOrWhiteSpace(defaultSourceBrachName) ? null : new Func <object, bool>(o => (o as Branch).Name == defaultSourceBrachName)); }
private void tabControlMode_SelectedIndexChanged(object sender, EventArgs e) { if (tabControlMode.SelectedTab == tabPagePreview) { htmlPanelPreview.BaseStylesheet = String.Format("{0} body div {{ font-size: {1}px; }}", Properties.Resources.Common_CSS, WinFormsHelpers.GetFontSizeInPixels(htmlPanelPreview)); Markdig.MarkdownPipeline pipeline = MarkDownUtils.CreatePipeline(Program.ServiceManager.GetJiraServiceUrl()); string body = MarkDownUtils.ConvertToHtml(textBox.Text, _uploadsPrefix, pipeline); htmlPanelPreview.Text = String.Format(MarkDownUtils.HtmlPageTemplate, body); } }
private void groupBoxRelated_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e) { WinFormsHelpers.ConvertMouseWheelToClick(buttonNextRelatedDiscussion, buttonPrevRelatedDiscussion, e.Delta); }