Example #1
0
        static bool FillViewers(CustomCommonFileDialogComboBox combo, string fileName)
        {
            combo.Items.Clear();

            if (String.IsNullOrEmpty(fileName) || Directory.Exists(fileName))
            {
                combo.Enabled = false;
                return(false);
            }

            bool hasBench       = false;
            var  projectService = IdeApp.Services.ProjectService;

            if (projectService.IsWorkspaceItemFile(fileName) || projectService.IsSolutionItemFile(fileName))
            {
                hasBench = true;
                combo.Items.Add(new ViewerComboItem(null, GettextCatalog.GetString("Solution Workbench")));
            }

            foreach (var vw in DisplayBindingService.GetFileViewers(fileName, null))
            {
                if (!vw.IsExternal)
                {
                    combo.Items.Add(new ViewerComboItem(vw, vw.Title));
                }
            }

            combo.Enabled = combo.Items.Count >= 1;
            return(hasBench);
        }
Example #2
0
        static void BuildEncodingsCombo(CustomCommonFileDialogComboBox combo, bool showAutoDetected, Encoding selectedEncoding)
        {
            combo.Items.Clear();
            int i = 0;

            if (showAutoDetected)
            {
                combo.Items.Add(new EncodingComboItem(null, GettextCatalog.GetString("Auto Detected")));
                combo.SelectedIndex = 0;
                i = 1;
            }

            foreach (var e in TextEncoding.ConversionEncodings)
            {
                combo.Items.Add(new EncodingComboItem(Encoding.GetEncoding(e.CodePage), string.Format("{0} ({1})", e.Name, e.Id)));
                if (selectedEncoding != null && e.CodePage == selectedEncoding.WindowsCodePage)
                {
                    combo.SelectedIndex = i;
                }
                i++;
            }
            if (combo.SelectedIndex == -1)
            {
                combo.SelectedIndex = 0;
            }
            combo.Items.Add(new EncodingComboItem(null, GettextCatalog.GetString("Add or Remove...")));
        }
Example #3
0
        static void BuildEncodingsCombo(CustomCommonFileDialogComboBox combo, bool showAutoDetected, Encoding selectedEncoding)
        {
            combo.Items.Clear();
            int i = 0;

            if (showAutoDetected)
            {
                combo.Items.Add(new EncodingComboItem(null, GettextCatalog.GetString("Auto Detected")));
                combo.SelectedIndex = 0;
                i = 1;
            }

            var encodings = TextEncoding.ConversionEncodings;

            foreach (var e in encodings)
            {
                var    mdEnc = TextEncoding.SupportedEncodings.FirstOrDefault(t => t.CodePage == e.CodePage);
                string name  = mdEnc != null
                                        ? mdEnc.Name + " (" + mdEnc.Id + ")"
                                        : e.Name + " (" + e.Id + ")";
                var item = new EncodingComboItem(Encoding.GetEncoding(e.CodePage), name);
                combo.Items.Add(item);
                if (e.Equals(selectedEncoding))
                {
                    combo.SelectedIndex = i;
                }
                i++;
            }
            if (combo.SelectedIndex == -1)
            {
                combo.SelectedIndex = 0;
            }
            combo.Items.Add(new EncodingComboItem(null, GettextCatalog.GetString("Add or Remove...")));
        }
Example #4
0
        static bool FillViewers(CustomCommonFileDialogComboBox combo, string fileName)
        {
            combo.Items.Clear();

            if (String.IsNullOrEmpty(fileName) || Directory.Exists(fileName))
            {
                combo.Enabled = false;
                return(false);
            }

            int  selected       = -1;
            int  i              = 0;
            bool hasBench       = false;
            var  projectService = IdeApp.Services.ProjectService;

            if (projectService.IsWorkspaceItemFile(fileName) || projectService.IsSolutionItemFile(fileName))
            {
                hasBench = true;
                combo.Items.Add(new ViewerComboItem(null, GettextCatalog.GetString("Solution Workbench")));
                if (!CanBeOpenedInAssemblyBrowser(fileName))
                {
                    selected = 0;
                }
                i++;
            }

            foreach (var vw in DisplayBindingService.GetFileViewers(fileName, null))
            {
                if (!vw.IsExternal)
                {
                    combo.Items.Add(new ViewerComboItem(vw, vw.Title));

                    if (vw.CanUseAsDefault && selected == -1)
                    {
                        selected = i;
                    }

                    i++;
                }
            }

            if (selected == -1)
            {
                selected = 0;
            }

            combo.Enabled = combo.Items.Count >= 1;
            if (selected > 0)
            {
                // Unable to set SelectedIndex until ApplyControlPropertyChange called for Items
                // which causes the combo box selection to visibly change selection twice. Instead just
                // make the default item the first one in the combo.
                var item = combo.Items[selected];
                combo.Items.RemoveAt(selected);
                combo.Items.Insert(0, item);
            }
            return(hasBench);
        }
		public bool Run (OpenFileDialogData data)
		{
			var parent = data.TransientFor ?? MessageService.RootWindow;
			CommonFileDialog dialog;
			if (data.Action == FileChooserAction.Open)
				dialog = new CustomCommonOpenFileDialog ();
			else
				dialog = new CommonSaveFileDialog ();

			SelectFileDialogHandler.SetCommonFormProperties (data, dialog);

			CustomCommonFileDialogComboBox encodingCombo = null;
			if (data.ShowEncodingSelector) {
				var group = new CommonFileDialogGroupBox ("encoding", "Encoding:");
				encodingCombo = new CustomCommonFileDialogComboBox ();

				BuildEncodingsCombo (encodingCombo, data.Action != FileChooserAction.Save, data.Encoding);
				group.Items.Add (encodingCombo);
				dialog.Controls.Add (group);

				encodingCombo.SelectedIndexChanged += (sender, e) => {
					if (encodingCombo.SelectedIndex == encodingCombo.Items.Count - 1) {
						var dlg = new System.Windows.Window {
							Title = "Choose encodings",
							Content = new SelectEncodingControl(),
							SizeToContent = SizeToContent.WidthAndHeight
						};
						if (dlg.ShowDialog ().Value) {
							BuildEncodingsCombo (encodingCombo, data.Action != FileChooserAction.Save, data.Encoding);
							dialog.ApplyControlPropertyChange ("Items", encodingCombo);
						}
					}
				};
			}

			CustomCommonFileDialogComboBox viewerCombo = null;
			CommonFileDialogCheckBox closeSolution = null;
			if (data.ShowViewerSelector && data.Action == FileChooserAction.Open) {
				var group = new CommonFileDialogGroupBox ("openWith", "Open with:");

				viewerCombo = new CustomCommonFileDialogComboBox {
					Enabled = false
				};
				group.Items.Add (viewerCombo);
				dialog.Controls.Add (group);

				if (IdeApp.Workspace.IsOpen) {
					var group2 = new CommonFileDialogGroupBox ();

					// "Close current workspace" is too long and splits the text on 2 lines.
					closeSolution = new CommonFileDialogCheckBox ("Close workspace", true) {
						Visible = false
					};
					group2.Items.Add (closeSolution);
					dialog.Controls.Add (group2);
				}

				dialog.SelectionChanged += (sender, e) => {
					try {
						var files = GetSelectedItems (dialog);
						var file = files.Count == 0 ? null : files[0];
						bool hasBench = FillViewers (viewerCombo, file);
						if (closeSolution != null)
							closeSolution.Visible = hasBench;
						dialog.ApplyControlPropertyChange ("Items", viewerCombo);
					} catch (Exception ex) {
						LoggingService.LogError (e.ToString ());
					}
				};
			}

			if (!GdkWin32.RunModalWin32Dialog (dialog, parent))
				return false;

			SelectFileDialogHandler.GetCommonFormProperties (data, dialog);
			if (encodingCombo != null)
				data.Encoding = ((EncodingComboItem)encodingCombo.Items [encodingCombo.SelectedIndex]).Encoding;

			if (viewerCombo != null) {
				if (closeSolution != null)
					data.CloseCurrentWorkspace = closeSolution.Visible && closeSolution.IsChecked;
				data.SelectedViewer = ((ViewerComboItem)viewerCombo.Items [viewerCombo.SelectedIndex]).Viewer;
			}

			return true;
		}
		static bool FillViewers (CustomCommonFileDialogComboBox combo, string fileName)
		{
			combo.Items.Clear ();

			if (String.IsNullOrEmpty (fileName) || Directory.Exists (fileName)) {
				combo.Enabled = false;
				return false;
			}

			bool hasBench = false;
			var projectService = IdeApp.Services.ProjectService;
			if (projectService.IsWorkspaceItemFile (fileName) || projectService.IsSolutionItemFile (fileName)) {
				hasBench = true;
				combo.Items.Add (new ViewerComboItem (null, GettextCatalog.GetString ("Solution Workbench")));
			}

			foreach (var vw in DisplayBindingService.GetFileViewers (fileName, null))
				if (!vw.IsExternal)
					combo.Items.Add (new ViewerComboItem (vw, vw.Title));

			combo.Enabled = combo.Items.Count >= 1;
			return hasBench;
		}
		static void BuildEncodingsCombo (CustomCommonFileDialogComboBox combo, bool showAutoDetected, Encoding selectedEncoding)
		{
			combo.Items.Clear ();
			int i = 0;

			if (showAutoDetected) {
				combo.Items.Add (new EncodingComboItem (null, GettextCatalog.GetString ("Auto Detected")));
				combo.SelectedIndex = 0;
				i = 1;
			}

			var encodings = TextEncoding.ConversionEncodings;
			foreach (var e in encodings) {
				var mdEnc = TextEncoding.SupportedEncodings.FirstOrDefault (t => t.CodePage == e.CodePage);
				string name = mdEnc != null
					? mdEnc.Name + " (" + mdEnc.Id + ")"
					: e.Name + " (" + e.Id + ")"; 
				var item = new EncodingComboItem (Encoding.GetEncoding (e.CodePage), name);
				combo.Items.Add (item);
				if (e.Equals (selectedEncoding))
					combo.SelectedIndex = i;
				i++;
			}
			if (combo.SelectedIndex == -1)
				combo.SelectedIndex = 0;
			combo.Items.Add (new EncodingComboItem (null, GettextCatalog.GetString ("Add or Remove...")));
		}
Example #8
0
        public bool Run(OpenFileDialogData data)
        {
            var parent = data.TransientFor ?? MessageService.RootWindow;
            CommonFileDialog dialog;

            if (data.Action == FileChooserAction.Open)
            {
                dialog = new CustomCommonOpenFileDialog {
                    EnsureFileExists = true
                };
            }
            else
            {
                dialog = new CustomCommonSaveFileDialog();
            }

            dialog.SetCommonFormProperties(data);

            CustomCommonFileDialogComboBox encodingCombo = null;

            if (data.ShowEncodingSelector)
            {
                var group = new CommonFileDialogGroupBox("encoding", "Encoding:");
                encodingCombo = new CustomCommonFileDialogComboBox();

                BuildEncodingsCombo(encodingCombo, data.Action != FileChooserAction.Save, data.Encoding);
                group.Items.Add(encodingCombo);
                dialog.Controls.Add(group);

                encodingCombo.SelectedIndexChanged += (sender, e) => {
                    if (encodingCombo.SelectedIndex == encodingCombo.Items.Count - 1)
                    {
                        var dlg = new System.Windows.Window {
                            Title         = "Choose encodings",
                            Content       = new SelectEncodingControl(),
                            SizeToContent = SizeToContent.WidthAndHeight
                        };
                        if (dlg.ShowDialog().Value)
                        {
                            BuildEncodingsCombo(encodingCombo, data.Action != FileChooserAction.Save, data.Encoding);
                            dialog.ApplyControlPropertyChange("Items", encodingCombo);
                        }
                    }
                };
            }

            CustomCommonFileDialogComboBox viewerCombo   = null;
            CommonFileDialogCheckBox       closeSolution = null;

            if (data.ShowViewerSelector && data.Action == FileChooserAction.Open)
            {
                var group = new CommonFileDialogGroupBox("openWith", "Open with:");

                viewerCombo = new CustomCommonFileDialogComboBox {
                    Enabled = false
                };
                group.Items.Add(viewerCombo);
                dialog.Controls.Add(group);

                if (encodingCombo != null || IdeApp.Workspace.IsOpen)
                {
                    viewerCombo.SelectedIndexChanged += (o, e) => {
                        bool solutionWorkbenchSelected = ((ViewerComboItem)viewerCombo.Items [viewerCombo.SelectedIndex]).Viewer == null;
                        if (closeSolution != null)
                        {
                            closeSolution.Visible = solutionWorkbenchSelected;
                        }
                        if (encodingCombo != null)
                        {
                            encodingCombo.Enabled = !solutionWorkbenchSelected;
                        }
                    };
                }

                if (IdeApp.Workspace.IsOpen)
                {
                    var group2 = new CommonFileDialogGroupBox();

                    // "Close current workspace" is too long and splits the text on 2 lines.
                    closeSolution = new CommonFileDialogCheckBox("Close workspace", true)
                    {
                        Visible = false
                    };
                    group2.Items.Add(closeSolution);
                    dialog.Controls.Add(group2);
                }

                dialog.SelectionChanged += (sender, e) => {
                    try {
                        var  files    = GetSelectedItems(dialog);
                        var  file     = files.Count == 0 ? null : files[0];
                        bool hasBench = FillViewers(viewerCombo, file);
                        if (closeSolution != null)
                        {
                            closeSolution.Visible = hasBench;
                        }
                        if (encodingCombo != null)
                        {
                            encodingCombo.Enabled = !hasBench;
                        }
                        dialog.ApplyControlPropertyChange("Items", viewerCombo);
                    } catch (Exception ex) {
                        LoggingService.LogInternalError(ex);
                    }
                };
            }

            if (!GdkWin32.RunModalWin32Dialog(dialog, parent))
            {
                return(false);
            }

            dialog.GetCommonFormProperties(data);
            if (encodingCombo != null)
            {
                data.Encoding = ((EncodingComboItem)encodingCombo.Items [encodingCombo.SelectedIndex]).Encoding;
            }

            if (viewerCombo != null)
            {
                if (closeSolution != null)
                {
                    data.CloseCurrentWorkspace = closeSolution.Visible && closeSolution.IsChecked;
                }
                int index = viewerCombo.SelectedIndex;
                if (index != -1)
                {
                    data.SelectedViewer = ((ViewerComboItem)viewerCombo.Items [index]).Viewer;
                }
            }

            return(true);
        }
		static bool FillViewers (CustomCommonFileDialogComboBox combo, string fileName)
		{
			combo.Items.Clear ();

			if (String.IsNullOrEmpty (fileName) || Directory.Exists (fileName)) {
				combo.Enabled = false;
				return false;
			}

			int selected = -1;
			int i = 0;
			bool hasBench = false;
			var projectService = IdeApp.Services.ProjectService;
			if (projectService.IsWorkspaceItemFile (fileName) || projectService.IsSolutionItemFile (fileName)) {
				hasBench = true;
				combo.Items.Add (new ViewerComboItem (null, GettextCatalog.GetString ("Solution Workbench")));
				if (!CanBeOpenedInAssemblyBrowser (fileName))
					selected = 0;
				i++;
			}

			foreach (var vw in DisplayBindingService.GetFileViewers (fileName, null))
				if (!vw.IsExternal) {
					combo.Items.Add (new ViewerComboItem (vw, vw.Title));

					if (vw.CanUseAsDefault && selected == -1)
						selected = i;

					i++;
				}

			if (selected == -1)
				selected = 0;

			combo.Enabled = combo.Items.Count >= 1;
			if (selected > 0) {
				// Unable to set SelectedIndex until ApplyControlPropertyChange called for Items
				// which causes the combo box selection to visibly change selection twice. Instead just
				// make the default item the first one in the combo.
				var item = combo.Items[selected];
				combo.Items.RemoveAt (selected);
				combo.Items.Insert (0, item);
			}
			return hasBench;
		}
		static void BuildEncodingsCombo (CustomCommonFileDialogComboBox combo, bool showAutoDetected, Encoding selectedEncoding)
		{
			combo.Items.Clear ();
			int i = 0;

			if (showAutoDetected) {
				combo.Items.Add (new EncodingComboItem (null, GettextCatalog.GetString ("Auto Detected")));
				combo.SelectedIndex = 0;
				i = 1;
			}

			foreach (var e in TextEncoding.ConversionEncodings) {
				combo.Items.Add (new EncodingComboItem (Encoding.GetEncoding (e.CodePage), string.Format ("{0} ({1})", e.Name, e.Id)));
				if (selectedEncoding != null && e.CodePage == selectedEncoding.WindowsCodePage)
					combo.SelectedIndex = i;
				i++;
			}
			if (combo.SelectedIndex == -1)
				combo.SelectedIndex = 0;
			combo.Items.Add (new EncodingComboItem (null, GettextCatalog.GetString ("Add or Remove...")));
		}