コード例 #1
0
		public override void NeedsUpdate (NSMenu menu)
		{
			// Get list of menu items
			NSMenuItem[] Items = menu.ItemArray ();

			// Get the key window and determine if the required images are available
			var window = NSApplication.SharedApplication.KeyWindow as MainWindow;
			var hasImage = (window != null) && (window.Image != null);
			var hasImageOnPasteboard = (window != null) && window.Document.ImageAvailableOnPasteboard;

			// Process every item in the menu
			foreach(NSMenuItem item in Items) {
				// Take action based on the menu title
				switch (item.Title) {
				case "Cut":
				case "Copy":
				case "Delete":
					// Only enable if there is an image in the view
					item.Enabled = hasImage;
					break;
				case "Paste":
					// Only enable if there is an image on the pasteboard
					item.Enabled = hasImageOnPasteboard;
					break;
				default:
					// Only enable the item if it has a sub menu
					item.Enabled = item.HasSubmenu;
					break;
				}
			}
		}
コード例 #2
0
        public override void NeedsUpdate(NSMenu menu)
        {
            // Get list of menu items
            NSMenuItem[] Items = menu.ItemArray();

            // Get the key window and determine if the required images are available
            var window               = NSApplication.SharedApplication.KeyWindow as MainWindow;
            var hasImage             = (window == null) ? false : (window.Image != null);
            var hasImageOnPasteboard = (window == null) ? false : window.Document.ImageAvailableOnPasteboard;

            // Process every item in the menu
            foreach (NSMenuItem item in Items)
            {
                // Take action based on the menu title
                switch (item.Title)
                {
                case "Cut":
                case "Copy":
                case "Delete":
                    // Only enable if there is an image in the view
                    item.Enabled = hasImage;
                    break;

                case "Paste":
                    // Only enable if there is an image on the pasteboard
                    item.Enabled = hasImageOnPasteboard;
                    break;

                default:
                    // Only enable the item if it has a sub menu
                    item.Enabled = item.HasSubmenu;
                    break;
                }
            }
        }
コード例 #3
0
            /// <inheritdoc/>
            public override void MenuWillOpen(NSMenu menu)
            {
                var groups = GetCommandGroups();

#if __UNIFIED__
                var items = menu.Items.Where(i => (i.RepresentedObject as NSObjectWrapper <ICommand>) != null);
#else
                var items = menu.ItemArray().Where(i => (i.RepresentedObject as NSObjectWrapper <ICommand>) != null);
#endif // __UNIFIED__
                foreach (var item in items)
                {
                    var commandWrapper = item.RepresentedObject as NSObjectWrapper <ICommand>;
                    var command        = commandWrapper.WrappedObject;
                    var group          = GetGroupForCommand(command, groups);
                    if (group != null)
                    {
                        group.UpdateCanExecute(command);
                    }
                }
            }
コード例 #4
0
        public override void NeedsUpdate(NSMenu menu)
        {
            // Get list of menu items
            NSMenuItem[] Items = menu.ItemArray();

            foreach (NSMenuItem item in Items)
            {
                // Take action based on the menu title
                switch (item.Title)
                {
                case "Paste":
                    // Only enable if there is an image on the pasteboard
                    item.Enabled = HasUrlOnPasteboard();
                    break;

                default:
                    item.Enabled = item.HasSubmenu;
                    break;
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Finds the insertion location for a command within a containing menu.
        /// </summary>
        /// <param name="command">The command whose insertion point is desired.</param>
        /// <param name="menu">The menu in which the command is to be inserted.</param>
        /// <returns>The insertion index, or -1 if it should be at the end.</returns>
        public static int FindMenuInsertLocation(this VisualRelayCommand command, NSMenu menu)
        {
            int index = -1;

#if __UNIFIED__
            var items = menu.Items;
#else
            var items = menu.ItemArray();
#endif // __UNIFIED__
            for (int i = 0; i < menu.Count; ++i)
            {
                var item        = items[i];
                var menuCommand = item.RepresentedObject as NSObjectWrapper <ICommand>;
                if (menuCommand != null)
                {
                    if (command.Weight >= ((VisualRelayCommand)menuCommand.WrappedObject).Weight)
                    {
                        index = i + 1;
                    }

                    /*
                     * if (((VisualRelayCommand)menuCommand.WrappedObject).Weight > command.Weight)
                     * {
                     *  index = i;
                     * }
                     * else
                     * {
                     *  index = i + 1;
                     * }
                     */
                }
            }
            if (index < 0)
            {
                index = 0; // default to top of menu
            }
            return(index);
        }
コード例 #6
0
ファイル: AppDelegate.cs プロジェクト: littlefeihu/checktask
        void SetEditMenuStatus()
        {
            NSMenu sysmenu = NSApplication.SharedApplication.MainMenu;

            //Edit menu
            NSMenuItem subMenuItem = sysmenu.ItemAt(2);
            NSMenu     subMenu     = subMenuItem.Submenu;

            NSMenuItem [] itemArray = subMenu.ItemArray();
            for (int i = 0; i < itemArray.Length; i++)
            {
                //Console.WriteLine ("{0}",itemArray [i].Title);
                if (itemArray [i].Title == "Start Dictation…")
                {
                    itemArray [i].Hidden = true;
                }

                if (itemArray [i].Title == "Emoji & Symbols")
                {
                    itemArray [i].Hidden = true;
                }
            }
        }
コード例 #7
0
        public override void FinishedLaunching(NSObject notification)
        {
            // Configure logger
            string path = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), "log4net.config");

            XmlConfigurator.ConfigureAndWatch(new FileInfo(path));
            logger.Info("Ventriliquest 1.0 Starting up...");

            // Get list of available audio out devices
            xamspeech ham = new xamspeech();

            OutputDevices = ham.GetDevices();

            // Setup UI
            statusMenu = new NSMenu();
            statusItem = NSStatusBar.SystemStatusBar.CreateStatusItem(30);

            var outputItem = new NSMenuItem("Output Device",
                                            (a, b) => {
            });

            var deviceList = new NSMenu();

            outputItem.Submenu = deviceList;

            OutputDeviceUID = "Built-in Output";

            foreach (var entry in OutputDevices)
            {
                var test = new NSMenuItem(entry.Key.ToString(),
                                          (a, b) => {
                    foreach (NSMenuItem item in deviceList.ItemArray())
                    {
                        item.State = NSCellStateValue.Off;
                    }
                    NSMenuItem theItem  = (NSMenuItem)a;
                    theItem.State       = NSCellStateValue.On;
                    config.OutputDevice = theItem.Title;
                    foreach (var e in OutputDevices)
                    {
                        if (e.Key.ToString().Equals(theItem.Title))
                        {
                            OutputDeviceUID = e.Value.ToString();
                        }
                    }
                });
                if (entry.Key.ToString().Equals(config.OutputDevice))
                {
                    test.State      = NSCellStateValue.On;
                    OutputDeviceUID = entry.Value.ToString();
                }
                deviceList.AddItem(test);
            }

            var daItem = new NSMenuItem("Local Connections Only",
                                        (a, b) => {
                NSMenuItem theItem = (NSMenuItem)a;
                if (theItem.State == NSCellStateValue.On)
                {
                    config.LocalOnly = false;
                    theItem.State    = NSCellStateValue.Off;
                }
                else
                {
                    config.LocalOnly = true;
                    theItem.State    = NSCellStateValue.On;
                }
            });

            if (config.LocalOnly)
            {
                daItem.State = NSCellStateValue.On;
            }

            var quitItem = new NSMenuItem("Quit",
                                          (a, b) => Shutdown());

            var voiceconfigItem = new NSMenuItem("Voice Configuration",
                                                 (a, b) => Process.Start("http://127.0.0.1:7888/config"));

            statusMenu.AddItem(new NSMenuItem("Version: 1.1"));
            statusMenu.AddItem(outputItem);
            statusMenu.AddItem(daItem);
            statusMenu.AddItem(voiceconfigItem);
            statusMenu.AddItem(quitItem);
            statusItem.Menu           = statusMenu;
            statusItem.Image          = NSImage.ImageNamed("tts-1.png");
            statusItem.AlternateImage = NSImage.ImageNamed("tts-2.png");
            statusItem.HighlightMode  = true;

            speechdelegate.DidComplete += delegate {
                synthesis.Set();
            };
            sounddelegate.DidComplete += delegate {
                playback.Set();
                IsSounding = false;
                IsSpeaking = false;
                sound.Dispose();
            };

            speech.Delegate = speechdelegate;

            queuetimer          = new System.Timers.Timer(250);
            queuetimer.Elapsed += (object sender, ElapsedEventArgs e) => {
                TTSRequest r;
                if (Queue.TryDequeue(out r))
                {
                    if (r.Interrupt)
                    {
                        // stop current TTS
                        NSApplication.SharedApplication.InvokeOnMainThread(delegate {
                            if (IsSpeaking)
                            {
                                speech.StopSpeaking();
                            }
                            if (IsSounding)
                            {
                                sound.Stop();
                            }
                        });
                        // clear queue
                        SpeechQueue.Clear();
                    }
                    if (!r.Reset)
                    {
                        SpeechQueue.Enqueue(r);
                    }
                    RequestCount++;
                }
                var eventdata = new Hashtable();
                eventdata.Add("ProcessedRequests", RequestCount);
                eventdata.Add("QueuedRequests", SpeechQueue.Count);
                eventdata.Add("IsSpeaking", IsSpeaking);
                InstrumentationEvent ev = new InstrumentationEvent();
                ev.EventName = "status";
                ev.Data      = eventdata;
                NotifyGui(ev.EventMessage());
            };

            // when this timer fires, it will pull off of the speech queue and speak it
            // the 1000ms delay also adds a little pause between tts requests.
            speechtimer          = new System.Timers.Timer(250);
            speechtimer.Elapsed += (object sender, ElapsedEventArgs e) => {
                if (IsSpeaking.Equals(false))
                {
                    if (SpeechQueue.Count > 0)
                    {
                        TTSRequest r = SpeechQueue.Dequeue();
                        IsSpeaking          = true;
                        speechtimer.Enabled = false;
                        var oink = Path.Combine(audiopath, "temp.aiff");
                        NSApplication.SharedApplication.InvokeOnMainThread(delegate {
                            ConfigureSpeechEngine(r);
                            speech.StartSpeakingStringtoURL(r.Text, new NSUrl(oink, false));
                        });
                        synthesis.WaitOne();
                        NSApplication.SharedApplication.InvokeOnMainThread(delegate {
                            IsSounding     = true;
                            sound          = new NSSound(Path.Combine(audiopath, "temp.aiff"), false);
                            sound.Delegate = sounddelegate;
                            //if(OutputDeviceUID != "Default") {
                            sound.PlaybackDeviceID = OutputDeviceUID;
                            //}
                            sound.Play();
                        });
                        playback.WaitOne();
                        IsSounding          = false;
                        speechtimer.Enabled = true;
                    }
                }
            };

            queuetimer.Enabled = true;
            queuetimer.Start();
            speechtimer.Enabled = true;
            speechtimer.Start();

            InitHTTPServer();
        }