void ClearRecent() { Gtk.MessageDialog md = new Gtk.MessageDialog(null, 0, Gtk.MessageType.Warning, Gtk.ButtonsType.None, "<b><big>" + Catalog.GetString("Clear the Recent Documents list?") + "</big></b>"); md.Title = Catalog.GetString("Clear Recent Documents"); md.Icon = DockServices.Drawing.LoadIcon("docky", 22); md.SecondaryText = Catalog.GetString("If you clear the Recent Documents list, you clear the following:\n" + "\u2022 All items from the Places \u2192 Recent Documents menu item.\n" + "\u2022 All items from the recent documents list in all applications."); md.Modal = false; md.AddButton(Gtk.Stock.Cancel, Gtk.ResponseType.Cancel); md.AddButton(Gtk.Stock.Clear, Gtk.ResponseType.Ok); md.DefaultResponse = Gtk.ResponseType.Ok; md.Response += (o, args) => { if (args.ResponseId != Gtk.ResponseType.Cancel) { Gtk.RecentManager.Default.PurgeItems(); } md.Destroy(); }; md.Show(); }
void EmptyTrash() { if (ConfirmTrashDelete) { Gtk.MessageDialog md = new Gtk.MessageDialog(null, 0, Gtk.MessageType.Warning, Gtk.ButtonsType.None, "<b><big>" + Catalog.GetString("Empty all of the items from the trash?") + "</big></b>"); md.Icon = DockServices.Drawing.LoadIcon("docky", 22); md.SecondaryText = Catalog.GetString("If you choose to empty the trash, all items in it\n" + "will be permanently lost. Please note that you\n" + "can also delete them separately."); md.Modal = false; md.AddButton(Gtk.Stock.Cancel, Gtk.ResponseType.Cancel); md.AddButton(Catalog.GetString("Empty _Trash"), Gtk.ResponseType.Ok); md.DefaultResponse = Gtk.ResponseType.Ok; md.Response += (o, args) => { if (args.ResponseId != Gtk.ResponseType.Cancel) { PerformEmptyTrash(); } md.Destroy(); }; md.Show(); } else { PerformEmptyTrash(); } }
private static OSMessageBoxResult PlatformShowCore(string message, string title, System.Exception exception, OSMessageBoxButton buttons, Dictionary <OSMessageBoxButton, string> customButtonLabels, OSMessageBoxIcon icon, OSMessageBoxResult defaultResult, System.Action <OSMessageBoxResult> onComplete) { var result = OSMessageBoxResult.None; if (onComplete == null) { INTV.Shared.Utility.OSDispatcher.Current.InvokeOnMainDispatcher(() => { var nativeButtons = Gtk.ButtonsType.Ok; switch (buttons) { case OSMessageBoxButton.OK: case OSMessageBoxButton.YesNo: nativeButtons = (Gtk.ButtonsType)buttons; break; case OSMessageBoxButton.YesNoCancel: nativeButtons = Gtk.ButtonsType.None; // we'll add buttons below break; } var parent = Gtk.Window.ListToplevels().FirstOrDefault(w => w.IsActive || w.IsFocus); if (parent == null) { parent = INTV.Shared.Utility.SingleInstanceApplication.Instance.MainWindow; } using (var messageBox = new Gtk.MessageDialog(parent, Gtk.DialogFlags.Modal, (Gtk.MessageType)icon, nativeButtons, "{0}", message)) { messageBox.Title = title; messageBox.MessageType = (Gtk.MessageType)icon; messageBox.DefaultResponse = (Gtk.ResponseType)defaultResult; switch (buttons) { case OSMessageBoxButton.OK: case OSMessageBoxButton.YesNo: break; case OSMessageBoxButton.YesNoCancel: messageBox.AddButton(Resources.Strings.YesButton_Text, Gtk.ResponseType.Yes); messageBox.AddButton(Resources.Strings.NoButton_Text, Gtk.ResponseType.No); messageBox.AddButton(Resources.Strings.CancelButtonText, Gtk.ResponseType.Cancel); break; } result = (OSMessageBoxResult)messageBox.Run(); VisualHelpers.Close(messageBox); } }); } else { INTV.Shared.Utility.SingleInstanceApplication.MainThreadDispatcher.BeginInvoke(() => { result = ShowCore(message, title, exception, null, buttons, customButtonLabels, icon, defaultResult, null); onComplete(result); }); } return(result); }
public DialogResult ShowDialog(Control parent) { Gtk.Window parentWindow = null; if (parent != null && parent.ParentWindow != null) { parentWindow = parent.ParentWindow.ControlObject as Gtk.Window; } control = new Gtk.MessageDialog(parentWindow, Gtk.DialogFlags.Modal, Type.ToGtk(), Buttons.ToGtk(), false, string.Empty); control.Text = Text; control.TypeHint = Gdk.WindowTypeHint.Dialog; var caption = Caption ?? ((parent != null && parent.ParentWindow != null) ? parent.ParentWindow.Title : null); if (!string.IsNullOrEmpty(caption)) { control.Title = caption; } // must add buttons manually for this case if (Buttons == MessageBoxButtons.YesNoCancel) { var bn = (Gtk.Button)control.AddButton(Gtk.Stock.No, (int)Gtk.ResponseType.No); bn.UseStock = true; var bc = (Gtk.Button)control.AddButton(Gtk.Stock.Cancel, (int)Gtk.ResponseType.Cancel); bc.UseStock = true; var by = (Gtk.Button)control.AddButton(Gtk.Stock.Yes, (int)Gtk.ResponseType.Yes); by.UseStock = true; } control.DefaultResponse = DefaultButton.ToGtk(Buttons); int ret = control.Run(); control.Hide(); #if GTKCORE control.Dispose(); #else control.Destroy(); #endif var result = ((Gtk.ResponseType)ret).ToEto(); if (result == DialogResult.None) { switch (Buttons) { case MessageBoxButtons.OK: result = DialogResult.Ok; break; case MessageBoxButtons.YesNo: result = DialogResult.No; break; case MessageBoxButtons.OKCancel: case MessageBoxButtons.YesNoCancel: result = DialogResult.Cancel; break; } } return(result); }
public static void Load() { try { SetDefaultValues(); using (FileStream stream = new FileStream(SettingsPath, FileMode.Open)) { BinaryFormatter bin = new BinaryFormatter(); HelperClass hc = (HelperClass)bin.Deserialize(stream); hc.PushValues(); } } catch (Exception ex) { Gtk.MessageDialog md = new Gtk.MessageDialog(null, Gtk.DialogFlags.DestroyWithParent, Gtk.MessageType.Error, Gtk.ButtonsType.Ok, "Couldn´t read Settings!" + Environment.NewLine + ex.Message); md.Title = "Error"; md.AddButton("Restore Settings?", Gtk.ResponseType.Yes); Gtk.ResponseType result = (Gtk.ResponseType)md.Run(); md.Destroy(); if (result == Gtk.ResponseType.Yes) { Recreate(); } } }
public DialogResult ShowDialog(Control parent, MessageBoxButtons buttons) { Gtk.Widget c = (parent == null) ? null : (Gtk.Widget)parent.ControlObject; while (!(c is Gtk.Window) && c != null) { c = c.Parent; } control = new Gtk.MessageDialog((Gtk.Window)c, Gtk.DialogFlags.Modal, Convert(Type), Convert(buttons), false, Text); control.TypeHint = Gdk.WindowTypeHint.Dialog; var caption = Caption ?? ((parent != null && parent.ParentWindow != null) ? parent.ParentWindow.Title : null); if (!string.IsNullOrEmpty(caption)) { control.Title = caption; } if (buttons == MessageBoxButtons.YesNoCancel) { // must add cancel manually Gtk.Button b = (Gtk.Button)control.AddButton(Gtk.Stock.Cancel, (int)Gtk.ResponseType.Cancel); b.UseStock = true; } int ret = control.Run(); control.Destroy(); return(Generator.Convert((Gtk.ResponseType)ret)); }
public DialogResult ShowDialog(Control parent) { Gtk.Window parentWindow = null; if (parent != null && parent.ParentWindow != null) { parentWindow = parent.ParentWindow.ControlObject as Gtk.Window; } control = new Gtk.MessageDialog(parentWindow, Gtk.DialogFlags.Modal, Type.ToGtk(), Buttons.ToGtk(), false, Text); control.TypeHint = Gdk.WindowTypeHint.Dialog; var caption = Caption ?? ((parent != null && parent.ParentWindow != null) ? parent.ParentWindow.Title : null); if (!string.IsNullOrEmpty(caption)) { control.Title = caption; } if (Buttons == MessageBoxButtons.YesNoCancel) { // must add cancel manually var b = (Gtk.Button)control.AddButton(Gtk.Stock.Cancel, (int)Gtk.ResponseType.Cancel); b.UseStock = true; } control.DefaultResponse = DefaultButton.ToGtk(Buttons); int ret = control.Run(); control.Destroy(); var result = ((Gtk.ResponseType)ret).ToEto(); if (result == DialogResult.None) { switch (Buttons) { case MessageBoxButtons.OK: result = DialogResult.Ok; break; case MessageBoxButtons.YesNo: result = DialogResult.No; break; case MessageBoxButtons.OKCancel: case MessageBoxButtons.YesNoCancel: result = DialogResult.Cancel; break; } } return(result); }
public SaveCheckDialogResult ShowSaveCheckDialog() { Gtk.MessageDialog saveCheckDialog = new Gtk.MessageDialog(null, Gtk.DialogFlags.Modal, Gtk.MessageType.Question, Gtk.ButtonsType.YesNo, false, "The current document has unsaved changes. Do you wish to save those now?"); saveCheckDialog.AddButton("Cancel", Gtk.ResponseType.Cancel); SaveCheckDialogResult result = SaveCheckDialogResult.Cancel; int dialogResult = saveCheckDialog.Run(); if ((int)Gtk.ResponseType.Yes == dialogResult) { result = SaveCheckDialogResult.Save; } else if ((int)Gtk.ResponseType.No == dialogResult) { result = SaveCheckDialogResult.NoSave; } saveCheckDialog.Destroy(); return result; }
public DialogResult ShowDialog(Control parent, MessageBoxButtons buttons) { Gtk.Widget c = (parent == null) ? null : (Gtk.Widget)parent.ControlObject; while (!(c is Gtk.Window) && c != null) { c = c.Parent; } control = new Gtk.MessageDialog((Gtk.Window)c, Gtk.DialogFlags.Modal, Convert (Type), Convert(buttons), false, Text); control.TypeHint = Gdk.WindowTypeHint.Dialog; var caption = Caption ?? ((parent != null && parent.ParentWindow != null) ? parent.ParentWindow.Title : null); if (!string.IsNullOrEmpty(caption)) control.Title = caption; if (buttons == MessageBoxButtons.YesNoCancel) { // must add cancel manually Gtk.Button b = (Gtk.Button)control.AddButton(Gtk.Stock.Cancel, (int)Gtk.ResponseType.Cancel); b.UseStock = true; } int ret = control.Run(); control.Destroy(); return Generator.Convert((Gtk.ResponseType)ret); }
public SaveCheckDialogResult ShowSaveCheckDialog() { Gtk.MessageDialog saveCheckDialog = new Gtk.MessageDialog(null, Gtk.DialogFlags.Modal, Gtk.MessageType.Question, Gtk.ButtonsType.YesNo, false, "The current document has unsaved changes. Do you wish to save those now?"); saveCheckDialog.AddButton("Cancel", Gtk.ResponseType.Cancel); SaveCheckDialogResult result = SaveCheckDialogResult.Cancel; int dialogResult = saveCheckDialog.Run(); if ((int)Gtk.ResponseType.Yes == dialogResult) { result = SaveCheckDialogResult.Save; } else if ((int)Gtk.ResponseType.No == dialogResult) { result = SaveCheckDialogResult.NoSave; } saveCheckDialog.Destroy(); return(result); }
void ClearRecent () { Gtk.MessageDialog md = new Gtk.MessageDialog (null, 0, Gtk.MessageType.Warning, Gtk.ButtonsType.None, "<b><big>" + Catalog.GetString ("Clear the Recent Documents list?") + "</big></b>"); md.Title = Catalog.GetString ("Clear Recent Documents"); md.Icon = DockServices.Drawing.LoadIcon ("docky", 22); md.SecondaryText = Catalog.GetString ("If you clear the Recent Documents list, you clear the following:\n" + "\u2022 All items from the Places \u2192 Recent Documents menu item.\n" + "\u2022 All items from the recent documents list in all applications."); md.Modal = false; md.AddButton (Gtk.Stock.Cancel, Gtk.ResponseType.Cancel); md.AddButton (Gtk.Stock.Clear, Gtk.ResponseType.Ok); md.DefaultResponse = Gtk.ResponseType.Ok; md.Response += (o, args) => { if (args.ResponseId != Gtk.ResponseType.Cancel) Gtk.RecentManager.Default.PurgeItems (); md.Destroy (); }; md.Show (); }
void EmptyTrash () { if (ConfirmTrashDelete) { Gtk.MessageDialog md = new Gtk.MessageDialog (null, 0, Gtk.MessageType.Warning, Gtk.ButtonsType.None, "<b><big>" + Catalog.GetString ("Empty all of the items from the trash?") + "</big></b>"); md.Icon = DockServices.Drawing.LoadIcon ("docky", 22); md.SecondaryText = Catalog.GetString ("If you choose to empty the trash, all items in it\n" + "will be permanently lost. Please note that you\n" + "can also delete them separately."); md.Modal = false; md.AddButton (Gtk.Stock.Cancel, Gtk.ResponseType.Cancel); md.AddButton (Catalog.GetString ("Empty _Trash"), Gtk.ResponseType.Ok); md.DefaultResponse = Gtk.ResponseType.Ok; md.Response += (o, args) => { if (args.ResponseId != Gtk.ResponseType.Cancel) PerformEmptyTrash (); md.Destroy (); }; md.Show (); } else { PerformEmptyTrash (); } }
/// <summary> /// Adds files to a project, potentially asking the user whether to move, copy or link the files. /// </summary> public IList<ProjectFile> AddFilesToProject (Project project, FilePath[] files, FilePath[] targetPaths, string buildAction) { Debug.Assert (project != null); Debug.Assert (files != null); Debug.Assert (targetPaths != null); Debug.Assert (files.Length == targetPaths.Length); int action = -1; IProgressMonitor monitor = null; if (files.Length > 10) { monitor = new MessageDialogProgressMonitor (true); monitor.BeginTask (GettextCatalog.GetString("Adding files..."), files.Length); } var newFileList = new List<ProjectFile> (); //project.AddFile (string) does linear search for duplicate file, so instead we use this HashSet and //and add the ProjectFiles directly. With large project and many files, this should really help perf. //Also, this is a better check because we handle vpaths and links. //FIXME: it would be really nice if project.Files maintained these hashmaps var vpathsInProject = new HashSet<FilePath> (project.Files.Select (pf => pf.ProjectVirtualPath)); var filesInProject = new Dictionary<FilePath,ProjectFile> (); foreach (var pf in project.Files) filesInProject [pf.FilePath] = pf; using (monitor) { for (int i = 0; i < files.Length; i++) { FilePath file = files[i]; if (monitor != null) { monitor.Log.WriteLine (file); monitor.Step (1); } if (FileService.IsDirectory (file)) { //FIXME: warning about skipping? newFileList.Add (null); continue; } FilePath targetPath = targetPaths[i].CanonicalPath; Debug.Assert (targetPath.IsChildPathOf (project.BaseDirectory)); var vpath = targetPath.ToRelative (project.BaseDirectory); if (vpathsInProject.Contains (vpath)) { MessageService.ShowWarning (GettextCatalog.GetString ( "There is a already a file or link in the project with the name '{0}'", vpath)); continue; } string fileBuildAction = buildAction; if (string.IsNullOrEmpty (buildAction)) fileBuildAction = project.GetDefaultBuildAction (file); //files in the target directory get added directly in their current location without moving/copying if (file.CanonicalPath == targetPath) { //FIXME: MD project system doesn't cope with duplicate includes - project save/load will remove the file ProjectFile pf; if (filesInProject.TryGetValue (targetPath, out pf)) { var link = pf.Link; MessageService.ShowWarning (GettextCatalog.GetString ( "The link '{0}' in the project already includes the file '{1}'", link, file)); continue; } pf = new ProjectFile (file, fileBuildAction); vpathsInProject.Add (pf.ProjectVirtualPath); filesInProject [pf.FilePath] = pf; newFileList.Add (pf); continue; } //for files outside the project directory, we ask the user whether to move, copy or link var md = new Gtk.MessageDialog ( IdeApp.Workbench.RootWindow, Gtk.DialogFlags.Modal | Gtk.DialogFlags.DestroyWithParent, Gtk.MessageType.Question, Gtk.ButtonsType.None, GettextCatalog.GetString ("The file {0} is outside the target directory. What would you like to do?", file)); try { Gtk.CheckButton remember = null; if (files.Length > 1) { remember = new Gtk.CheckButton (GettextCatalog.GetString ("Use the same action for all selected files.")); md.VBox.PackStart (remember, false, false, 0); } const int ACTION_LINK = 3; const int ACTION_COPY = 1; const int ACTION_MOVE = 2; md.AddButton (GettextCatalog.GetString ("_Link"), ACTION_LINK); md.AddButton (Gtk.Stock.Copy, ACTION_COPY); md.AddButton (GettextCatalog.GetString ("_Move"), ACTION_MOVE); md.AddButton (Gtk.Stock.Cancel, Gtk.ResponseType.Cancel); md.VBox.ShowAll (); int ret = -1; if (action < 0) { ret = MessageService.RunCustomDialog (md); if (ret < 0) { project.Files.AddRange (newFileList.Where (f => f != null)); return newFileList; } if (remember != null && remember.Active) action = ret; } else { ret = action; } if (ret == ACTION_LINK) { //FIXME: MD project system doesn't cope with duplicate includes - project save/load will remove the file ProjectFile pf; if (filesInProject.TryGetValue (file, out pf)) { var link = pf.Link; MessageService.ShowWarning (GettextCatalog.GetString ( "The link '{0}' in the project already includes the file '{1}'", link, file)); continue; } pf = new ProjectFile (file, fileBuildAction) { Link = vpath }; vpathsInProject.Add (pf.ProjectVirtualPath); filesInProject [pf.FilePath] = pf; newFileList.Add (pf); continue; } try { if (!Directory.Exists (targetPath.ParentDirectory)) FileService.CreateDirectory (targetPath.ParentDirectory); if (MoveCopyFile (file, targetPath, ret == ACTION_MOVE)) { var pf = new ProjectFile (targetPath, fileBuildAction); vpathsInProject.Add (pf.ProjectVirtualPath); filesInProject [pf.FilePath] = pf; newFileList.Add (pf); } else { newFileList.Add (null); } } catch (Exception ex) { MessageService.ShowException (ex, GettextCatalog.GetString ( "An error occurred while attempt to move/copy that file. Please check your permissions.")); newFileList.Add (null); } } finally { md.Destroy (); } } } project.Files.AddRange (newFileList.Where (f => f != null)); return newFileList; }
/// <summary> /// Adds files to a project, potentially asking the user whether to move, copy or link the files. /// </summary> public IList<ProjectFile> AddFilesToProject (Project project, FilePath[] files, FilePath targetDirectory, string buildAction) { int action = -1; IProgressMonitor monitor = null; if (files.Length > 10) { monitor = new MessageDialogProgressMonitor (true); monitor.BeginTask (GettextCatalog.GetString("Adding files..."), files.Length); } var newFileList = new List<ProjectFile> (); using (monitor) { foreach (FilePath file in files) { if (monitor != null) { monitor.Log.WriteLine (file); monitor.Step (1); } if (FileService.IsDirectory (file)) { //FIXME: warning about skipping? newFileList.Add (null); continue; } //files in the project directory get added directly in their current location without moving/copying if (file.IsChildPathOf (project.BaseDirectory)) { newFileList.Add (project.AddFile (file, buildAction)); continue; } //for files outside the project directory, we ask the user whether to move, copy or link var md = new Gtk.MessageDialog ( IdeApp.Workbench.RootWindow, Gtk.DialogFlags.Modal | Gtk.DialogFlags.DestroyWithParent, Gtk.MessageType.Question, Gtk.ButtonsType.None, GettextCatalog.GetString ("The file {0} is outside the project directory. What would you like to do?", file)); try { Gtk.CheckButton remember = null; if (files.Length > 1) { remember = new Gtk.CheckButton (GettextCatalog.GetString ("Use the same action for all selected files.")); md.VBox.PackStart (remember, false, false, 0); } const int ACTION_LINK = 3; const int ACTION_COPY = 1; const int ACTION_MOVE = 2; md.AddButton (GettextCatalog.GetString ("_Link"), ACTION_LINK); md.AddButton (Gtk.Stock.Copy, ACTION_COPY); md.AddButton (GettextCatalog.GetString ("_Move"), ACTION_MOVE); md.AddButton (Gtk.Stock.Cancel, Gtk.ResponseType.Cancel); md.VBox.ShowAll (); int ret = -1; if (action < 0) { ret = MessageService.RunCustomDialog (md); if (ret < 0) return newFileList; if (remember != null && remember.Active) action = ret; } else { ret = action; } var targetName = targetDirectory.Combine (file.FileName); if (ret == ACTION_LINK) { var pf = project.AddFile (file, buildAction); pf.Link = project.GetRelativeChildPath (targetName); newFileList.Add (pf); continue; } try { if (MoveCopyFile (file, targetName, ret == ACTION_MOVE)) newFileList.Add (project.AddFile (targetName, buildAction)); else newFileList.Add (null); } catch (Exception ex) { MessageService.ShowException (ex, GettextCatalog.GetString ( "An error occurred while attempt to move/copy that file. Please check your permissions.")); newFileList.Add (null); } } finally { md.Destroy (); } } } return newFileList; }