public override void AwakeFromNib()
        {
            base.AwakeFromNib();

            Window.Title = Constants.Name + " - " + Messages.WindowsSettingsTitle;

            TableTabsController = new TableTabsController(TableTabs, TabMain);

            ChkNetLock.Activated += (object sender, EventArgs e) =>
            {
                if (GuiUtils.GetCheck(ChkNetLock))
                {
                    if ((Engine.Instance as UI.Cocoa.Osx.Engine).MainWindow.NetworkLockKnowledge() == false)
                    {
                        GuiUtils.SetCheck(ChkNetLock, false);
                    }
                }
            };

            TableRoutes.Delegate = new TableRoutingDelegate(this);

            LblDnsServers.StringValue = Messages.WindowsSettingsDnsServers;
            TableDnsServers.Delegate  = new TableDnsServersDelegate(this);

            TableAdvancedEvents.Delegate = new TableAdvancedEventsDelegate(this);

            LblLoggingHelp.StringValue = Messages.WindowsSettingsLoggingHelp;

            TableRoutingController        = new TableRoutingController(this.TableRoutes);
            TableDnsServersController     = new TableDnsServersController(this.TableDnsServers);
            TableAdvancedEventsController = new TableAdvancedEventsController(this.TableAdvancedEvents);

            CmdSave.Activated += (object sender, EventArgs e) =>
            {
                try
                {
                    if (Check())
                    {
                        SaveOptions();
                        Close();
                    }
                }
                catch (Exception ex)
                {
                    Core.Engine.Instance.Logs.Log(LogType.Fatal, ex);
                }
            };

            CmdCancel.Activated += (object sender, EventArgs e) =>
            {
                Close();
            };

            // General

            CmdGeneralTos.Activated += (object sender, EventArgs e) =>
            {
                WindowTosController tos = new WindowTosController();
                tos.Window.ReleasedWhenClosed = true;
                NSApplication.SharedApplication.RunModalForWindow(tos.Window);
                tos.Window.Close();
            };

            CmdResetToDefault.Activated += (object sender, EventArgs e) =>
            {
                if (Engine.Instance.OnAskYesNo(Messages.ResetSettingsConfirm))
                {
                    Engine.Instance.Storage.ResetAll(false);
                    ReadOptions();
                    GuiUtils.MessageBoxInfo(Messages.ResetSettingsDone);
                }
            };

            // UI

            CboUiUnit.RemoveAllItems();
            CboUiUnit.AddItem(Messages.WindowsSettingsUiUnit0);
            CboUiUnit.AddItem(Messages.WindowsSettingsUiUnit1);
            CboUiUnit.AddItem(Messages.WindowsSettingsUiUnit2);

            // Protocols

            CmdProtocolsHelp1.Activated += (object sender, EventArgs e) =>
            {
                Engine.Instance.Command("ui.show.docs.protocols");
            };

            CmdProtocolsHelp2.Activated += (object sender, EventArgs e) =>
            {
                Engine.Instance.Command("ui.show.docs.udp_vs_tcp");
            };

            ChkProtocolsAutomatic.Activated += (object sender, EventArgs e) =>
            {
                EnableIde();
            };

            TableProtocols.Delegate  = new TableProtocolsDelegate(this);
            TableProtocolsController = new TableProtocolsController(this.TableProtocols);

            // Proxy
            CboProxyType.RemoveAllItems();
            CboProxyType.AddItem("None");
            CboProxyType.AddItem("Http");
            CboProxyType.AddItem("Socks");
            CboProxyType.AddItem("Tor");
            CboProxyWhen.RemoveAllItems();
            CboProxyWhen.AddItem(Messages.WindowsSettingsProxyWhenAlways);
            CboProxyWhen.AddItem(Messages.WindowsSettingsProxyWhenWeb);
            CboProxyWhen.AddItem(Messages.WindowsSettingsProxyWhenOpenVPN);
            CboProxyWhen.AddItem(Messages.WindowsSettingsProxyWhenNone);

            CmdProxyTorHelp.Activated += (object sender, EventArgs e) =>
            {
                Engine.Instance.Command("ui.show.docs.tor");
            };
            CboProxyType.Activated += (object sender, EventArgs e) =>
            {
                EnableIde();

                if (GuiUtils.GetSelected(CboProxyType) == "Tor")
                {
                    TxtProxyPort.StringValue = "9150";
                }
                else
                {
                    TxtProxyPort.StringValue = "8080";
                }
            };
            CboProxyAuthentication.Activated += (object sender, EventArgs e) =>
            {
                EnableIde();
            };
            CmdProxyTorTest.Activated += (object sender, EventArgs e) =>
            {
                string result = TorControl.Test(TxtProxyHost.StringValue, Conversions.ToInt32(TxtProxyTorControlPort.StringValue), TxtProxyTorControlPassword.StringValue);
                GuiUtils.MessageBoxInfo(result);
            };

            // Routes
            CboRoutesOtherwise.RemoveAllItems();
            CboRoutesOtherwise.AddItem(RouteDirectionToDescription("in"));
            CboRoutesOtherwise.AddItem(RouteDirectionToDescription("out"));
            CboRoutesOtherwise.Activated += (object sender, EventArgs e) =>
            {
                EnableIde();
            };

            TableRoutes.DoubleClick += (object sender, EventArgs e) =>
            {
                RouteEdit();
            };

            CmdRouteAdd.Activated += (object sender, EventArgs e) =>
            {
                RouteAdd();
            };

            CmdRouteRemove.Activated += (object sender, EventArgs e) =>
            {
                RouteRemove();
            };

            CmdRouteEdit.Activated += (object sender, EventArgs e) =>
            {
                RouteEdit();
            };

            // Advanced - General

            CmdAdvancedHelp.Activated += (object sender, EventArgs e) =>
            {
                Engine.Instance.Command("ui.show.docs.advanced");
            };

            CboIpV6.RemoveAllItems();
            CboIpV6.AddItem("None");
            CboIpV6.AddItem("Disable");

            CboAdvancedManifestRefresh.RemoveAllItems();
            CboAdvancedManifestRefresh.AddItem("Automatic");
            CboAdvancedManifestRefresh.AddItem("Never");
            CboAdvancedManifestRefresh.AddItem("Every minute");
            CboAdvancedManifestRefresh.AddItem("Every ten minute");
            CboAdvancedManifestRefresh.AddItem("Every one hour");

            LblOpenVpnRcvBuf.StringValue = Messages.WindowsSettingsOpenVpnRcvBuf + ":";
            LblOpenVpnSndBuf.StringValue = Messages.WindowsSettingsOpenVpnSndBuf + ":";
            CboOpenVpnRcvBuf.RemoveAllItems();
            CboOpenVpnRcvBuf.AddItem(Messages.Automatic);
            CboOpenVpnRcvBuf.AddItem(Messages.WindowsSettingsOpenVpnDefault);
            CboOpenVpnRcvBuf.AddItem("8 KB");
            CboOpenVpnRcvBuf.AddItem("16 KB");
            CboOpenVpnRcvBuf.AddItem("32 KB");
            CboOpenVpnRcvBuf.AddItem("64 KB");
            CboOpenVpnRcvBuf.AddItem("128 KB");
            CboOpenVpnRcvBuf.AddItem("256 KB");
            CboOpenVpnRcvBuf.AddItem("512 KB");
            CboOpenVpnSndBuf.RemoveAllItems();
            CboOpenVpnSndBuf.AddItem(Messages.Automatic);
            CboOpenVpnSndBuf.AddItem(Messages.WindowsSettingsOpenVpnDefault);
            CboOpenVpnSndBuf.AddItem("8 KB");
            CboOpenVpnSndBuf.AddItem("16 KB");
            CboOpenVpnSndBuf.AddItem("32 KB");
            CboOpenVpnSndBuf.AddItem("64 KB");
            CboOpenVpnSndBuf.AddItem("128 KB");
            CboOpenVpnSndBuf.AddItem("256 KB");
            CboOpenVpnSndBuf.AddItem("512 KB");

            CmdAdvancedOpenVpnPath.Activated += (object sender, EventArgs e) =>
            {
                GuiUtils.SelectFile(this.Window, TxtAdvancedOpenVpnPath);
            };


            // Advanced - DNS
            TableDnsServers.DoubleClick += (object sender, EventArgs e) =>
            {
                DnsServersEdit();
            };

            CmdDnsAdd.Activated += (object sender, EventArgs e) =>
            {
                DnsServersAdd();
            };

            CmdDnsRemove.Activated += (object sender, EventArgs e) =>
            {
                DnsServersRemove();
            };

            CmdDnsEdit.Activated += (object sender, EventArgs e) =>
            {
                DnsServersEdit();
            };

            // Advanced - Net Lock
            CmdLockHelp.Activated += (object sender, EventArgs e) =>
            {
                Engine.Instance.Command("ui.show.docs.lock");
            };
            CboLockMode.RemoveAllItems();
            CboLockMode.AddItem("None");
            CboLockMode.AddItem("Automatic");
            foreach (NetworkLockPlugin lockPlugin in Engine.Instance.NetworkLockManager.Modes)
            {
                CboLockMode.AddItem(lockPlugin.GetName());
            }

            LblRoutesNetworkLockWarning.StringValue = Messages.WindowsSettingsRouteLockHelp;
            LblLockRoutingOutWarning.StringValue    = Messages.NetworkLockNotAvailableWithRouteOut;

            // Advanced - Logging

            TxtLoggingPath.Changed += (object sender, EventArgs e) =>
            {
                RefreshLogPreview();
            };

            CmdLoggingOpen.Activated += (object sender, EventArgs e) =>
            {
                List <string> paths = Engine.Instance.Logs.ParseLogFilePath(TxtLoggingPath.StringValue);
                foreach (string path in paths)
                {
                    if (Core.Platform.Instance.OpenDirectoryInFileManager(path) == false)
                    {
                        GuiUtils.MessageBoxError(MessagesFormatter.Format(Messages.WindowsSettingsLogsCannotOpenDirectory, path));
                    }
                }
            };

            // Directives
            CboOpenVpnDirectivesSkipDefault.RemoveAllItems();
            CboOpenVpnDirectivesSkipDefault.AddItem(Messages.WindowsSettingsOpenVpnDirectivesDefaultSkip1);
            CboOpenVpnDirectivesSkipDefault.AddItem(Messages.WindowsSettingsOpenVpnDirectivesDefaultSkip2);
            CmdOpenVpnDirectivesHelp.Activated += (object sender, EventArgs e) =>
            {
                Engine.Instance.Command("ui.show.docs.directives");
            };
            CmdOpenVpnDirectivesCustomPathBrowse.Activated += (object sender, EventArgs e) =>
            {
                GuiUtils.SelectFile(this.Window, TxtOpenVpnDirectivesCustomPath);
            };

            // Advanced - Events

            TableAdvancedEvents.DoubleClick += (object sender, EventArgs e) =>
            {
                AdvancedEventEdit();
            };

            CmdAdvancedEventsEdit.Activated += (object sender, EventArgs e) =>
            {
                AdvancedEventEdit();
            };

            CmdAdvancedEventsClear.Activated += (object sender, EventArgs e) =>
            {
                AdvancedEventClear();
            };

            ReadOptions();

            EnableIde();

            RefreshLogPreview();
        }
        public override void AwakeFromNib()
        {
            base.AwakeFromNib ();

            Window.Title = Constants.Name + " - " + Messages.WindowsSettingsTitle;

            TableTabsController = new TableTabsController (TableTabs, TabMain);

            ChkNetLock.Activated += (object sender, EventArgs e) => {
                if (GuiUtils.GetCheck (ChkNetLock)) {
                    if ((Engine.Instance as UI.Cocoa.Osx.Engine).MainWindow.NetworkLockKnowledge () == false)
                        GuiUtils.SetCheck (ChkNetLock, false);
                }
            };

            TableRoutes.Delegate = new TableRoutingDelegate (this);

            LblDnsServers.StringValue = Messages.WindowsSettingsDnsServers;
            TableDnsServers.Delegate = new TableDnsServersDelegate (this);

            TableAdvancedEvents.Delegate = new TableAdvancedEventsDelegate (this);

            LblLoggingHelp.StringValue = Messages.WindowsSettingsLoggingHelp;

            TableRoutingController = new TableRoutingController (this.TableRoutes);
            TableDnsServersController = new TableDnsServersController (this.TableDnsServers);
            TableAdvancedEventsController = new TableAdvancedEventsController (this.TableAdvancedEvents);

            CmdSave.Activated += (object sender, EventArgs e) => {
                if(Check())
                {
                    SaveOptions ();
                    Close ();
                }
            };

            CmdCancel.Activated += (object sender, EventArgs e) => {
                Close ();
            };

            // General

            CmdGeneralTos.Activated += (object sender, EventArgs e) => {
                WindowTosController tos = new WindowTosController ();
                tos.Window.ReleasedWhenClosed = true;
                NSApplication.SharedApplication.RunModalForWindow (tos.Window);
                tos.Window.Close ();
            };

            CmdResetToDefault.Activated += (object sender, EventArgs e) => {
                if(Engine.Instance.OnAskYesNo(Messages.ResetSettingsConfirm))
                {
                    Engine.Instance.Storage.ResetAll(false);
                    ReadOptions();
                    Engine.Instance.OnMessageInfo(Messages.ResetSettingsDone);
                }
            };

            // UI

            CboUiUnit.RemoveAllItems ();
            CboUiUnit.AddItem (Messages.WindowsSettingsUiUnit0);
            CboUiUnit.AddItem (Messages.WindowsSettingsUiUnit1);
            CboUiUnit.AddItem (Messages.WindowsSettingsUiUnit2);

            // Protocols

            CmdProtocolsHelp1.Activated += (object sender, EventArgs e) => {
                Engine.Instance.Command ("ui.show.docs.protocols");
            };

            CmdProtocolsHelp2.Activated += (object sender, EventArgs e) => {
                Engine.Instance.Command ("ui.show.docs.udp_vs_tcp");
            };

            ChkProtocolsAutomatic.Activated += (object sender, EventArgs e) => {
                EnableIde();
            };

            TableProtocols.Delegate = new TableProtocolsDelegate (this);
            TableProtocolsController = new TableProtocolsController (this.TableProtocols);

            // Proxy
            CboProxyType.RemoveAllItems ();
            CboProxyType.AddItem ("None");
            CboProxyType.AddItem ("Detect");
            CboProxyType.AddItem ("Http");
            CboProxyType.AddItem ("Socks");
            CboProxyType.AddItem ("Tor");

            CmdProxyTorHelp.Activated += (object sender, EventArgs e) => {
                Engine.Instance.Command ("ui.show.docs.tor");
            };
            CboProxyType.Activated += (object sender, EventArgs e) => {
                EnableIde();

                if(GuiUtils.GetSelected(CboProxyType) == "Tor")
                    TxtProxyPort.StringValue = "9150";
                else
                    TxtProxyPort.StringValue = "8080";
            };
            CboProxyAuthentication.Activated += (object sender, EventArgs e) => {
                EnableIde();
            };
            CmdProxyTorTest.Activated += (object sender, EventArgs e) => {
                string result = TorControl.Test(TxtProxyHost.StringValue, Conversions.ToInt32(TxtProxyTorControlPort.StringValue), TxtProxyTorControlPassword.StringValue);
                GuiUtils.MessageBox(result);
            };

            // Routes
            CboRoutesOtherwise.RemoveAllItems();
            CboRoutesOtherwise.AddItem(RouteDirectionToDescription("in"));
            CboRoutesOtherwise.AddItem(RouteDirectionToDescription("out"));
            CboRoutesOtherwise.Activated += (object sender, EventArgs e) => {
                EnableIde ();
            };

            TableRoutes.DoubleClick += (object sender, EventArgs e) => {
                RouteEdit();
            };

            CmdRouteAdd.Activated += (object sender, EventArgs e) => {
                RouteAdd();
            };

            CmdRouteRemove.Activated += (object sender, EventArgs e) => {
                RouteRemove();
            };

            CmdRouteEdit.Activated += (object sender, EventArgs e) => {
                RouteEdit();
            };

            // Advanced - General

            CmdAdvancedHelp.Activated += (object sender, EventArgs e) => {
                Engine.Instance.Command ("ui.show.docs.advanced");
            };

            CboIpV6.RemoveAllItems ();
            CboIpV6.AddItem ("None");
            CboIpV6.AddItem ("Disable");

            CboAdvancedManifestRefresh.RemoveAllItems ();
            CboAdvancedManifestRefresh.AddItem ("Automatic");
            CboAdvancedManifestRefresh.AddItem ("Never");
            CboAdvancedManifestRefresh.AddItem ("Every minute");
            CboAdvancedManifestRefresh.AddItem ("Every ten minute");
            CboAdvancedManifestRefresh.AddItem ("Every one hour");

            LblOpenVpnRcvBuf.StringValue = Messages.WindowsSettingsOpenVpnRcvBuf + ":";
            LblOpenVpnSndBuf.StringValue = Messages.WindowsSettingsOpenVpnSndBuf + ":";
            CboOpenVpnRcvBuf.RemoveAllItems();
            CboOpenVpnRcvBuf.AddItem(Messages.Automatic);
            CboOpenVpnRcvBuf.AddItem(Messages.WindowsSettingsOpenVpnDefault);
            CboOpenVpnRcvBuf.AddItem("8 KB");
            CboOpenVpnRcvBuf.AddItem("16 KB");
            CboOpenVpnRcvBuf.AddItem("32 KB");
            CboOpenVpnRcvBuf.AddItem("64 KB");
            CboOpenVpnRcvBuf.AddItem("128 KB");
            CboOpenVpnRcvBuf.AddItem("256 KB");
            CboOpenVpnRcvBuf.AddItem("512 KB");
            CboOpenVpnSndBuf.RemoveAllItems();
            CboOpenVpnSndBuf.AddItem(Messages.Automatic);
            CboOpenVpnSndBuf.AddItem(Messages.WindowsSettingsOpenVpnDefault);
            CboOpenVpnSndBuf.AddItem("8 KB");
            CboOpenVpnSndBuf.AddItem("16 KB");
            CboOpenVpnSndBuf.AddItem("32 KB");
            CboOpenVpnSndBuf.AddItem("64 KB");
            CboOpenVpnSndBuf.AddItem("128 KB");
            CboOpenVpnSndBuf.AddItem("256 KB");
            CboOpenVpnSndBuf.AddItem("512 KB");

            CmdAdvancedOpenVpnPath.Activated += (object sender, EventArgs e) => {
                GuiUtils.SelectFile(this.Window, TxtAdvancedOpenVpnPath);
            };

            // Advanced - DNS
            TableDnsServers.DoubleClick += (object sender, EventArgs e) =>
            {
                DnsServersEdit();
            };

            CmdDnsAdd.Activated += (object sender, EventArgs e) =>
            {
                DnsServersAdd();
            };

            CmdDnsRemove.Activated += (object sender, EventArgs e) =>
            {
                DnsServersRemove();
            };

            CmdDnsEdit.Activated += (object sender, EventArgs e) =>
            {
                DnsServersEdit();
            };

            // Advanced - Net Lock
            CmdLockHelp.Activated += (object sender, EventArgs e) => {
                Engine.Instance.Command ("ui.show.docs.lock");
            };
            CboLockMode.RemoveAllItems ();
            CboLockMode.AddItem ("None");
            CboLockMode.AddItem ("Automatic");
            foreach (NetworkLockPlugin lockPlugin in Engine.Instance.NetworkLockManager.Modes) {
                CboLockMode.AddItem (lockPlugin.GetName ());
            }

            LblRoutesNetworkLockWarning.StringValue = Messages.WindowsSettingsRouteLockHelp;
            LblLockRoutingOutWarning.StringValue = Messages.NetworkLockNotAvailableWithRouteOut;

            // Advanced - Logging

            TxtLoggingPath.Changed += (object sender, EventArgs e) => {
                RefreshLogPreview();
            };

            CmdLoggingOpen.Activated += (object sender, EventArgs e) =>
            {
                List<string> paths = Engine.Instance.Logs.ParseLogFilePath(TxtLoggingPath.StringValue);
                foreach (string path in paths)
                {
                    if (Platform.Instance.OpenDirectoryInFileManager(path) == false)
                        Engine.Instance.OnMessageError(MessagesFormatter.Format(Messages.WindowsSettingsLogsCannotOpenDirectory, path));
                }
            };

            // Directives
            CboOpenVpnDirectivesSkipDefault.RemoveAllItems ();
            CboOpenVpnDirectivesSkipDefault.AddItem (Messages.WindowsSettingsOpenVpnDirectivesDefaultSkip1);
            CboOpenVpnDirectivesSkipDefault.AddItem (Messages.WindowsSettingsOpenVpnDirectivesDefaultSkip2);
            CmdOpenVpnDirectivesHelp.Activated += (object sender, EventArgs e) => {
                Engine.Instance.Command ("ui.show.docs.directives");
            };

            // Advanced - Events

            TableAdvancedEvents.DoubleClick += (object sender, EventArgs e) => {
                AdvancedEventEdit();
            };

            CmdAdvancedEventsEdit.Activated += (object sender, EventArgs e) => {
                AdvancedEventEdit();
            };

            CmdAdvancedEventsClear.Activated += (object sender, EventArgs e) => {
                AdvancedEventClear();

            };

            ReadOptions ();

            EnableIde ();

            RefreshLogPreview ();
        }