Esempio n. 1
0
 public void StartGame(Config config)
 {
     game = new Game (this.createBoard (config.Width, config.Height));
     game.GameWon += delegate(object sender, EventArgs e) {
         MessageDialog dialog = new MessageDialog (
             this,
          DialogFlags.Modal,
          MessageType.Info,
          ButtonsType.None,
          "Úroveň dokončena! Abyste zvládli víc nepřátel, dostanete další život."
         );
         dialog.AddButton ("Další kolo", ResponseType.Accept);
         dialog.AddButton ("Konec hry", ResponseType.Cancel);
         dialog.Response += delegate(object o, ResponseArgs args) {
             if (args.ResponseId == ResponseType.Accept) {
                 NextLevel (config);
             } else {
                 Application.Quit ();
             }
         };
         dialog.Run ();
         dialog.Destroy ();
     };
     game.GameLost += delegate(object sender, EventArgs e) {
         MessageDialog dialog = new MessageDialog (
             this,
          DialogFlags.Modal,
          MessageType.Info,
          ButtonsType.None,
          "Konec hry"
         );
         dialog.AddButton ("Nová hra", ResponseType.Accept);
         dialog.AddButton ("Konec", ResponseType.Close);
         dialog.Response += delegate(object o, ResponseArgs args) {
             if (args.ResponseId == ResponseType.Accept) {
                 MainClass.ShowLauncher ();
                 this.Destroy ();
             } else {
                 Application.Quit ();
             }
         };
         dialog.Run ();
         dialog.Destroy ();
     };
     game.FilledAreaChanged += delegate(object sender, int value) {
         fillCounter.Text = String.Format ("Zaplněno: {0}%", value);
     };
     game.LivesChanged += delegate(object sender, int value) {
         lifeCounter.Text = String.Format ("Životy: {0}", value);
     };
     game.RemainingTimeChanged += delegate(object sender, int value) {
         remainingTimeCounter.Text = string.Format ("Zbývající čas: {0} sekund", value);
     };
     game.Start (config);
     level = 1;
     updateLevelCounter ();
 }
Esempio n. 2
0
    static Settings()
    {
        String SettingsPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Constants.PACKAGE_NAME);
        SettingsFile = System.IO.Path.Combine(SettingsPath, "settings.xml");

        StreamReader reader = null;
        try {
            Console.WriteLine("Using configfile: " + SettingsFile);
            reader = new StreamReader(SettingsFile);
            Instance = (Settings) settingsSerializer.Deserialize(reader);
        } catch(Exception e) {
            Console.WriteLine("Couldn't load configfile: " + e.Message);
            Instance = new Settings();
        } finally {
            if(reader != null)
                reader.Close();
        }

        if(!Instance.SupertuxData.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString())) {
            Instance.SupertuxData += System.IO.Path.DirectorySeparatorChar;
        }

        Console.WriteLine("Supertux is run as: " + Instance.SupertuxExe);
        Console.WriteLine("Data files are in: " + Instance.SupertuxData);

        // if data path does not exist, prompt user to change it before we try continue initializing
        if (!new DirectoryInfo(System.IO.Path.GetDirectoryName(Instance.SupertuxData)).Exists) {
            Console.WriteLine("Data path does not exist.");
            MessageDialog md = new MessageDialog(null, DialogFlags.DestroyWithParent, MessageType.Warning, ButtonsType.None, "The current data path, \"" + Instance.SupertuxData + "\", does not exist.\n\nEdit the settings to set a valid data path.");
            md.AddButton(Gtk.Stock.No, ResponseType.No);
            md.AddButton(Gtk.Stock.Edit, ResponseType.Yes);
            if (md.Run() == (int)ResponseType.Yes) {
                new SettingsDialog(true);
            }
            md.Destroy();
        }

        Resources.ResourceManager.Instance = new Resources.DefaultResourceManager(Instance.SupertuxData + "/");
    }
Esempio n. 3
0
        private void ClipboardEmptyError()
        {
            var primary   = Catalog.GetString("Paste cancelled");
            var secondary = Catalog.GetString("The clipboard does not contain an image");
            var markup    = "<span weight=\"bold\" size=\"larger\">{0}</span>\n\n{1}\n";

            markup = string.Format(markup, primary, secondary);

            var md = new MessageDialog(PintaCore.Chrome.MainWindow, DialogFlags.Modal,
                                       MessageType.Error, ButtonsType.None, true,
                                       markup);

            md.AddButton(Stock.Ok, ResponseType.Yes);

            md.Run();
            md.Destroy();
        }
Esempio n. 4
0
        protected bool CloseDialog(CloseSource source, bool AskSave)
        {
            if (TabParent.CheckClosingSlaveTabs(this as ITdiTab))
            {
                return(false);
            }

            if (ActiveDialog is ITdiDialog dlg)
            {
                if (AskSave && dlg.HasChanges)
                {
                    string        Message = "Объект изменён. Сохранить изменения перед закрытием?";
                    MessageDialog md      = new MessageDialog((Window)this.Toplevel, DialogFlags.Modal,
                                                              MessageType.Question,
                                                              ButtonsType.YesNo,
                                                              Message);
                    md.AddButton("Отмена", ResponseType.Cancel);
                    int result = md.Run();
                    md.Destroy();
                    if (result == (int)ResponseType.Cancel || result == (int)ResponseType.DeleteEvent)
                    {
                        return(false);
                    }
                    if (result == (int)ResponseType.Yes)
                    {
                        if (!dlg.Save())
                        {
                            logger.Warn("Объект не сохранён. Отмена закрытия...");
                            return(false);
                        }
                    }
                }
            }
            var oldTab = ActiveDialog;

            ActiveDialog.OnTabClosed();
            ActiveDialog = null;
            activeGlgWidget.Destroy();
            (TabParent as TdiNotebook)?.OnSliderTabClosed(this, oldTab, source);
            OnSliderTabChanged();
            return(true);
        }
Esempio n. 5
0
        public override WindowResponse Show(object parent, string message, string title, MessageWindowType type, MessageWindowButtons bType)
        {
            Window      p = (Window)parent;
            MessageType t = GtkHelper.GetWinType(type);

            MessageDialog md = new MessageDialog(p, DialogFlags.Modal, t, ButtonsType.None, message);

            md.Title = title;
            if (p != null && p.Icon != null)
            {
                md.Icon = p.Icon;
            }
            md.WindowPosition = WindowPosition.CenterOnParent;

            if (bType == MessageWindowButtons.Ok || bType == MessageWindowButtons.OkCancel)
            {
                md.AddButton(Message.GetString("Ok"), ResponseType.Ok);
            }
            if (bType == MessageWindowButtons.Close)
            {
                md.AddButton(Message.GetString("Close"), ResponseType.Close);
            }
            if (bType == MessageWindowButtons.YesNo || bType == MessageWindowButtons.YesNoCancel)
            {
                md.AddButton(Message.GetString("Yes"), ResponseType.Yes); md.AddButton(Message.GetString("No"), ResponseType.No);
            }
            if (bType == MessageWindowButtons.AbortRetryIgnore || bType == MessageWindowButtons.RetryCancel)
            {
                md.AddButton(Message.GetString("Retry"), ResponseType.Accept);
            }
            if (bType == MessageWindowButtons.AbortRetryIgnore)
            {
                md.AddButton(Message.GetString("Ignore"), ResponseType.Reject);
            }
            if (bType == MessageWindowButtons.Cancel || bType == MessageWindowButtons.OkCancel || bType == MessageWindowButtons.RetryCancel || bType == MessageWindowButtons.YesNoCancel || bType == MessageWindowButtons.AbortRetryIgnore)
            {
                md.AddButton(Message.GetString("Cancel"), ResponseType.Cancel);
            }

            ResponseType result = (ResponseType)md.Run();

            md.Destroy();
            return(GtkHelper.GetResponse(result));
        }
        private void OnMirageDuplicateSearchHandler(object sender, EventArgs args)
        {
            MessageDialog md = new MessageDialog(null, DialogFlags.Modal, MessageType.Question,
                                                 ButtonsType.Cancel, AddinManager.CurrentLocalizer.GetString(
                                                     "<b>Mirage can search your music library for duplicate music pieces.</b>\n\n" +
                                                     "· To do so, your music library needs to be analyzed completely from Mirage.\n" +
                                                     "· This process will take a long time depending on the size of your library."));

            md.AddButton(AddinManager.CurrentLocalizer.GetString("Scan for Duplicates"), ResponseType.Yes);
            ResponseType result = (ResponseType)md.Run();

            md.Destroy();

            if (result == ResponseType.Yes)
            {
                try {
                    DuplicateSearch();
                } catch (Exception) {
                    Log.Warning("Mirage - Error scanning for duplicates.");
                }
            }
        }
Esempio n. 7
0
        static public int ButtonsMessage(Widget parent, string question, List <string> textButtons, int?focusIndex, string title = null)
        {
            Window toplevel;

            if (parent != null)
            {
                toplevel = parent.Toplevel as Window;
            }
            else
            {
                toplevel = null;
            }

            MessageDialog md = new MessageDialog(toplevel, DialogFlags.Modal,
                                                 MessageType.Question, ButtonsType.None,
                                                 question);

            md.Icon  = Misc.LoadIcon(App.Current.SoftwareIconName, IconSize.Button, 0);
            md.Title = title;

            for (int i = 0; i < textButtons.Count; i++)
            {
                var buttonText = textButtons [i];

                var t = md.AddButton(buttonText, i + 1);

                if (focusIndex.HasValue && focusIndex.Value == i)
                {
                    md.Focus = t;
                }
            }

            var res = md.Run();

            md.Destroy();
            return(res);
        }
Esempio n. 8
0
        protected void OnDialogClose(object sender, TdiTabCloseEventArgs arg)
        {
            if (TabParent.CheckClosingSlaveTabs(this as ITdiTab))
            {
                return;
            }

            ITdiDialog dlg = sender as ITdiDialog;

            if (arg.AskSave && dlg.HasChanges)
            {
                string        Message = "Объект изменён. Сохранить изменения перед закрытием?";
                MessageDialog md      = new MessageDialog((Window)this.Toplevel, DialogFlags.Modal,
                                                          MessageType.Question,
                                                          ButtonsType.YesNo,
                                                          Message);
                md.AddButton("Отмена", ResponseType.Cancel);
                int result = md.Run();
                md.Destroy();
                if (result == (int)ResponseType.Cancel)
                {
                    return;
                }
                if (result == (int)ResponseType.Yes)
                {
                    if (!dlg.Save())
                    {
                        logger.Warn("Объект не сохранён. Отмена закрытия...");
                        return;
                    }
                }
            }
            ActiveDialog = null;
            (dlg as Widget).Destroy();
            OnSladerTabChanged();
        }
Esempio n. 9
0
        public static ResponseType Show(string message, MessageType type, ButtonsType bType, bool AddCancel)
        {
            MessageDialog md = new MessageDialog(null, DialogFlags.Modal, type, bType, message);

            switch (type)
            {
            case MessageType.Error:
                md.Title = "Error";
                break;

            case MessageType.Info:
                md.Title = "Info";
                break;

            case MessageType.Other:
                md.Title = "Message";
                break;

            case MessageType.Question:
                md.Title = "Question";
                break;

            case MessageType.Warning:
                md.Title = "Warning";
                break;
            }
            if (AddCancel)
            {
                md.AddButton("Cancel", ResponseType.Cancel);
            }
            md.WindowPosition = WindowPosition.CenterOnParent;
            ResponseType result = (ResponseType)md.Run();

            md.Destroy();
            return(result);
        }
Esempio n. 10
0
 /// <summary>
 /// Queries the user if he or she wants to save the current map before continuing. Pressing "cancel" invokes no delegates, while answering "yes" or "no" invokes an action.
 /// </summary>
 /// <param name="yes">
 /// The delegate to be invoked if the user answers yes
 /// </param>
 /// <param name="no">
 /// The delegate to be invoked if the user answers no
 /// </para>
 private void QuerySave(VoidDelegate yes, VoidDelegate no)
 {
     MessageDialog dlg = new MessageDialog(this, DialogFlags.DestroyWithParent | DialogFlags.Modal, MessageType.Question, ButtonsType.YesNo, true,"The current map has been modified. Would you like to save before continuing?");
     dlg.AddButton("Cancel", ResponseType.Cancel);
     dlg.Response += delegate(object o, ResponseArgs args) {
         switch (args.ResponseId)
         {
         case ResponseType.Yes:
             yes();
             break;
         case ResponseType.No:
             no();
             break;
         }
     };
     dlg.Run();
     dlg.Destroy();
 }
Esempio n. 11
0
 public void StartGame(Config config)
 {
     game          = new Game(this.createBoard(config.Width, config.Height));
     game.GameWon += delegate(object sender, EventArgs e) {
         MessageDialog dialog = new MessageDialog(
             this,
             DialogFlags.Modal,
             MessageType.Info,
             ButtonsType.None,
             "Úroveň dokončena! Abyste zvládli víc nepřátel, dostanete další život."
             );
         dialog.AddButton("Další kolo", ResponseType.Accept);
         dialog.AddButton("Konec hry", ResponseType.Cancel);
         dialog.Response += delegate(object o, ResponseArgs args) {
             if (args.ResponseId == ResponseType.Accept)
             {
                 NextLevel(config);
             }
             else
             {
                 Application.Quit();
             }
         };
         dialog.Run();
         dialog.Destroy();
     };
     game.GameLost += delegate(object sender, EventArgs e) {
         MessageDialog dialog = new MessageDialog(
             this,
             DialogFlags.Modal,
             MessageType.Info,
             ButtonsType.None,
             "Konec hry"
             );
         dialog.AddButton("Nová hra", ResponseType.Accept);
         dialog.AddButton("Konec", ResponseType.Close);
         dialog.Response += delegate(object o, ResponseArgs args) {
             if (args.ResponseId == ResponseType.Accept)
             {
                 MainClass.ShowLauncher();
                 this.Destroy();
             }
             else
             {
                 Application.Quit();
             }
         };
         dialog.Run();
         dialog.Destroy();
     };
     game.FilledAreaChanged += delegate(object sender, int value) {
         fillCounter.Text = String.Format("Zaplněno: {0}%", value);
     };
     game.LivesChanged += delegate(object sender, int value) {
         lifeCounter.Text = String.Format("Životy: {0}", value);
     };
     game.RemainingTimeChanged += delegate(object sender, int value) {
         remainingTimeCounter.Text = string.Format("Zbývající čas: {0} sekund", value);
     };
     game.Start(config);
     level = 1;
     updateLevelCounter();
 }
Esempio n. 12
0
    static Settings()
    {
        String SettingsPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Constants.PACKAGE_NAME);

        SettingsFile = System.IO.Path.Combine(SettingsPath, "settings.xml");

        StreamReader reader = null;

        try {
            LogManager.Log(LogLevel.Info, "Using configfile: " + SettingsFile);
            reader   = new StreamReader(SettingsFile);
            Instance = (Settings)settingsSerializer.Deserialize(reader);
        } catch (Exception e) {
            LogManager.Log(LogLevel.Error, "Couldn't load configfile: " + e.Message);
            LogManager.Log(LogLevel.Info, "Creating new config from scratch");
            Instance = new Settings();
        } finally {
            if (reader != null)
            {
                reader.Close();
            }
        }

        LogManager.Log(LogLevel.Info, "Supertux is run as: " + Instance.SupertuxExe);
        if (Instance.SupertuxData != null)
        {
            LogManager.Log(LogLevel.Info, "Data files are in: " + Instance.SupertuxData);
        }
        else
        {
            LogManager.Log(LogLevel.Info, "Unable to find data files when querying supertux.");
        }

        // If data path does not exist, prompt user to change it before we try continue initializing
        if (Instance.SupertuxData == null ||
            !new DirectoryInfo(System.IO.Path.GetDirectoryName(Instance.SupertuxData)).Exists)
        {
            LogManager.Log(LogLevel.Error, "Data path does not exist.");

            String bad_data_path_msg;
            if (Instance.SupertuxData == null)
            {
                bad_data_path_msg = "The data path could not be calculated." + Environment.NewLine
                                    + Environment.NewLine
                                    + "You must install a newer version of Supertux to use this version of the editor or specify the correct path to the supertux2 binary.";
            }
            else
            {
                bad_data_path_msg = "The current data path, `"
                                    + Instance.SupertuxData + "', does not exist." + Environment.NewLine
                                    + Environment.NewLine
                                    + "This means that your supertux installation (`" + Instance.SupertuxExe + "') is corrupted or incomplete.";
            }

            MessageDialog md = new MessageDialog(null, DialogFlags.DestroyWithParent, MessageType.Warning, ButtonsType.None, bad_data_path_msg);
            md.AddButton(Gtk.Stock.No, ResponseType.No);
            md.AddButton(Gtk.Stock.Edit, ResponseType.Yes);
            if (md.Run() == (int)ResponseType.Yes)
            {
                new SettingsDialog(true);
            }
            md.Destroy();
        }

        Resources.ResourceManager.Instance = new Resources.DefaultResourceManager(Instance.SupertuxData + "/");
    }
Esempio n. 13
0
        private void HandlerPintaCoreActionsEditPasteActivated(object sender, EventArgs e)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            PintaCore.Tools.Commit();

            Gtk.Clipboard cb = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false));

            Path p;

            // Don't dispose this, as we're going to give it to the history
            Gdk.Pixbuf image = cb.WaitForImage();

            if (image == null)
            {
                return;
            }

            Gdk.Size canvas_size = PintaCore.Workspace.ImageSize;

            // If the image being pasted is larger than the canvas size, allow the user to optionally resize the canvas
            if (image.Width > canvas_size.Width || image.Height > canvas_size.Height)
            {
                string message = Catalog.GetString("The image being pasted is larger than the canvas size. What would you like to do?");

                var enlarge_dialog = new MessageDialog(PintaCore.Chrome.MainWindow, DialogFlags.Modal, MessageType.Question, ButtonsType.None, message);
                enlarge_dialog.AddButton(Catalog.GetString("Expand canvas"), ResponseType.Accept);
                enlarge_dialog.AddButton(Catalog.GetString("Don't change canvas size"), ResponseType.Reject);
                enlarge_dialog.AddButton(Stock.Cancel, ResponseType.Cancel);
                enlarge_dialog.DefaultResponse = ResponseType.Accept;

                ResponseType response = (ResponseType)enlarge_dialog.Run();
                enlarge_dialog.Destroy();

                if (response == ResponseType.Accept)
                {
                    PintaCore.Workspace.ResizeCanvas(image.Width, image.Height, Pinta.Core.Anchor.Center);
                    PintaCore.Actions.View.UpdateCanvasScale();
                }
                else if (response == ResponseType.Cancel || response == ResponseType.DeleteEvent)
                {
                    return;
                }
            }

            // Copy the paste to the temp layer
            doc.CreateSelectionLayer();
            doc.ShowSelectionLayer = true;

            using (Cairo.Context g = new Cairo.Context(doc.SelectionLayer.Surface)) {
                g.DrawPixbuf(image, new Cairo.Point(0, 0));
                p = g.CreateRectanglePath(new Rectangle(0, 0, image.Width, image.Height));
            }

            PintaCore.Tools.SetCurrentTool(Catalog.GetString("Move Selected Pixels"));

            Path old_path           = doc.SelectionPath;
            bool old_show_selection = doc.ShowSelection;

            doc.SelectionPath = p;
            doc.ShowSelection = true;

            doc.Workspace.Invalidate();

            doc.History.PushNewItem(new PasteHistoryItem(image, old_path, old_show_selection));
        }
Esempio n. 14
0
    static Settings()
    {
        String SettingsPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Constants.PACKAGE_NAME);
        SettingsFile = System.IO.Path.Combine(SettingsPath, "settings.xml");

        StreamReader reader = null;
        try {
            LogManager.Log(LogLevel.Info, "Using configfile: " + SettingsFile);
            reader = new StreamReader(SettingsFile);
            Instance = (Settings) settingsSerializer.Deserialize(reader);
        } catch(Exception e) {
            LogManager.Log(LogLevel.Error, "Couldn't load configfile: " + e.Message);
            LogManager.Log(LogLevel.Info, "Creating new config from scratch");
            Instance = new Settings();
        } finally {
            if(reader != null)
                reader.Close();
        }

        LogManager.Log(LogLevel.Info, "Supertux is run as: " + Instance.SupertuxExe);
        if (Instance.SupertuxData != null)
            LogManager.Log(LogLevel.Info, "Data files are in: " + Instance.SupertuxData);
        else
            LogManager.Log(LogLevel.Info, "Unable to find data files when querying supertux.");

        // If data path does not exist, prompt user to change it before we try continue initializing
        if (Instance.SupertuxData == null
            || !new DirectoryInfo(System.IO.Path.GetDirectoryName(Instance.SupertuxData)).Exists) {
            LogManager.Log(LogLevel.Error, "Data path does not exist.");

            String bad_data_path_msg;
            if (Instance.SupertuxData == null)
                bad_data_path_msg = "The data path could not be calculated." + Environment.NewLine
                    + Environment.NewLine
                    + "You must install a newer version of Supertux to use this version of the editor or specify the correct path to the supertux2 binary.";
            else
                bad_data_path_msg = "The current data path, `"
                    + Instance.SupertuxData + "', does not exist." + Environment.NewLine
                    + Environment.NewLine
                    + "This means that your supertux installation (`" + Instance.SupertuxExe + "') is corrupted or incomplete.";

            MessageDialog md = new MessageDialog(null, DialogFlags.DestroyWithParent, MessageType.Warning, ButtonsType.None, bad_data_path_msg);
            md.AddButton(Gtk.Stock.No, ResponseType.No);
            md.AddButton(Gtk.Stock.Edit, ResponseType.Yes);
            if (md.Run() == (int)ResponseType.Yes) {
                new SettingsDialog(true);
            }
            md.Destroy();
        }

        Resources.ResourceManager.Instance = new Resources.DefaultResourceManager(Instance.SupertuxData + "/");
    }
Esempio n. 15
0
    /// <summary>
    /// Ask if realy continue if unsaved changes.
    /// </summary>
    /// <param name="act">What we would do ("quit", "close", "open another file" or such)</param>
    /// <returns>True if continue otherwise false</returns>
    private bool ChangeConfirm(string act)
    {
        if( modified ) {
            MessageDialog md = new MessageDialog (MainWindow,
                                                  DialogFlags.DestroyWithParent,
                                                  MessageType.Warning,
                                                  ButtonsType.None, "Continue without saving changes?\n\nIf you " + act + " without saving, changes since the last save will be discarded.");
            md.AddButton(Gtk.Stock.Cancel, Gtk.ResponseType.Cancel);
            md.AddButton("Discard Changes", Gtk.ResponseType.Yes);

            ResponseType result = (ResponseType)md.Run ();
            md.Destroy();
            if (result != ResponseType.Yes){
                return false;
            }
        }
        return true;
    }
Esempio n. 16
0
        private void _primaryWindowInstallLinkWindow_Dialog(object o, EventArgs e)
        {
            Gtk.Application.Invoke((sender, args) =>
            {
                var xdg_path = System.IO.Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                                                   "applications");
                var xdg_file = System.IO.Path.Join(xdg_path, "aucapture-opener.desktop");
                string info  = String.Empty;

                var InstallLinkDialogBox = new MessageDialog(this,
                                                             DialogFlags.Modal,
                                                             MessageType.Question,
                                                             ButtonsType.None,
                                                             false,
                                                             String.Empty);

                if (!File.Exists(xdg_file) && !Settings.PersistentSettings.skipHandlerInstall)
                {
                    info +=
                        "Would you like to enable support for AutoMuteUs one-click connection?" +
                        "This will allow you to use the links provided by AutoMuteUs to connect the capture to the bot automatically.\n\n" +
                        "The following operations will be performed:\n\n" +
                        $"- The following .desktop file will be installed: {xdg_file}\n\n" +
                        "- The following command will be run to link the 'aucapture:' URI to the program:\n\n \'xdg-mime default aucapture-opener.desktop x-scheme-handler/aucapture\'" +
                        "\n\nIf you decline, Discord connection links will not be functional." +
                        "\n\nYou can install or manage One-Click support by using the \"One-Click Connection Management\" link in the File menu.";

                    InstallLinkDialogBox.Text  = info;
                    InstallLinkDialogBox.Title = "Enable One-Click Connection?";
                    InstallLinkDialogBox.AddButton("Cancel", ResponseType.Reject);
                    InstallLinkDialogBox.AddButton("Install", ResponseType.Accept);

                    InstallLinkDialogBox.Response += delegate(object o1, ResponseArgs responseArgs)
                    {
                        if (responseArgs.ResponseId == ResponseType.Reject)
                        {
                            // Make sure we have the setting to ignore the dialog box set.
                            Settings.PersistentSettings.skipHandlerInstall = true;
                        }

                        if (responseArgs.ResponseId == ResponseType.Accept)
                        {
                            IPCadapter.getInstance().InstallHandler();
                        }
                    };
                }
                else
                {
                    info += "This menu manages the One-Click Connection link system.\n\n";

                    info += "One-Click Connection Status: ";
                    if (File.Exists(xdg_file))
                    {
                        info += "Enabled\n\n";
                    }
                    else
                    {
                        info += "Disabled\n\n";
                    }

                    info += $"Runner (.desktop) Installation Path: ";
                    if (File.Exists(xdg_file))
                    {
                        info += xdg_file;
                    }
                    else
                    {
                        info += "Not Found";
                    }

                    InstallLinkDialogBox.Text += info;
                    InstallLinkDialogBox.Title = "Manage One-Click Connection";
                    InstallLinkDialogBox.AddButton("Cancel", ResponseType.Close);
                    InstallLinkDialogBox.AddButton("Uninstall", ResponseType.Reject);
                    InstallLinkDialogBox.AddButton("Reinstall", ResponseType.Accept);

                    InstallLinkDialogBox.Response += delegate(object o1, ResponseArgs responseArgs)
                    {
                        if (responseArgs.ResponseId == ResponseType.Reject)
                        {
                            // Make sure we have the setting to ignore the dialog box set.
                            IPCadapter.getInstance().RemoveHandler();
                        }

                        if (responseArgs.ResponseId == ResponseType.Accept)
                        {
                            IPCadapter.getInstance().InstallHandler();
                        }
                    };
                }

                InstallLinkDialogBox.ShowAll();
                InstallLinkDialogBox.Run();
                InstallLinkDialogBox.Dispose();
            });
        }
Esempio n. 17
0
    protected void OnButtonHitungClicked(object sender, EventArgs e)
    {
        bool isPermutation = radiobuttonP.Active;

        Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss.fff] ") + "OnButtonHitungClicked Event fired");

        //Check for user error
        if (!isPermutation && !radiobuttonC.Active)
        {
            ErrorDialog("Anda belum memilih operasi perhitungan.\nSilahkan pilih operasi Permutasi atau Kombinasi.");
            return;
        }

        int n, r;

        try
        {
            n = Convert.ToInt32(spinN.Text);
            r = Convert.ToInt32(spinR.Text);
            Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss.fff] ") + "Value of N: " + n);
            Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss.fff] ") + "Value of R: " + r);
        }
        catch (System.FormatException)
        {
            ErrorDialog("Hanya bisa memasukkan angka (berupa bilangan bulat).");
            return;
        }
        catch (Exception ex)
        {
            ErrorDialog("Terjadi kesalahan!\n" + ex);
            return;
        }

        if (r > n)
        {
            ErrorDialog("Nilai sub-set (r) tidak bisa lebih besar dari nilai set (n)");
            return;
        }

        if (r < 0 || n < 0)
        {
            ErrorDialog("Anda tidak bisa memasukkan bilangan negatif.");
            return;
        }

        buttonHitung.Sensitive = false;
        buttonHitung.Label     = "Menghitung hasil...";

        string result            = isPermutation ? CountPermutation(n, r).Result.ToString("R") : CountCombination(n, r).Result.ToString("R"); //preserve the whole BigInteger value
        string text              = "Hasil " + (isPermutation ? "permutasi:" : "kombinasi:") + "\n";
        string result_normalized = result;                                                                                                    //long numbers have enter to prevent message dialog width too wide
        bool   lihatRumus        = false;
        int    countLine         = 1;

        for (int i = 200; i < result.Length; i += 200)
        {
            if (countLine > 40)
            {
                result_normalized = result_normalized.Remove(i + 1) + "...\nHasil terlalu panjang. Tekan tombol Copy Hasil untuk mengcopy hasil utuhnya.";
                break;
            }
            result_normalized = result_normalized.Insert(i, "\n");
            countLine++;
        }
        text += result_normalized + "\n\n";

        MessageDialog md = new MessageDialog(this, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.None, text);

        Button b0 = (Button)md.AddButton("Lihat Rumus", 0);
        Button b1 = (Button)md.AddButton("Copy Hasil", 1);
        Button b2 = (Button)md.AddButton("Tutup", 2);

        b0.Clicked     += ButtonDialogRumusClicked;
        b0.WidthRequest = 160;
        b1.Clicked     += ButtonDialogCopyClicked;
        b2.Clicked     += ButtonDialogTutupClicked;

        md.Run();
        buttonHitung.Label = "Hitung";
        Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss.fff] ") + "Result message dialog fired:\n" + text);

        void ButtonDialogRumusClicked(object senderr, EventArgs ee)
        {
            Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss.fff] ") + "ButtonDialogRumusClicked event fired");
            if (!lihatRumus)
            {
                text      += isPermutation ? "n! / (n-r)!" : "n! / (r! * (n-r)!)";
                md.Text    = text;
                lihatRumus = true;
                b0.Label   = "Sembunyikan Rumus";
            }
            else
            {
                text       = isPermutation ? text.Replace("n! / (n-r)!", "") : text.Replace("n! / (r! * (n-r)!)", "");
                md.Text    = text;
                lihatRumus = false;
                b0.Label   = "Lihat Rumus";
            }
        }

        void ButtonDialogCopyClicked(object senderr, EventArgs ee)
        {
            Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss.fff] ") + "ButtonDialogCopyClicked event fired");
            Clipboard clipboard = Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false));

            clipboard.Text = result;
            Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss.fff] ") + "Copied result to clipboard. Value: \n" + result);
        }

        void ButtonDialogTutupClicked(object senderr, EventArgs ee)
        {
            Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss.fff] ") + "ButtonDialogTutupClicked event fired");
            buttonHitung.Sensitive = true;
            md.Destroy();
        }
    }