Esempio n. 1
0
        public SettingsStorage([NotNull] IReadAndStoreFilePacks filePacksRepository, [NotNull] ISerialize <FilePack> packsSerializer)
        {
            Debug.Assert(filePacksRepository != null, nameof(filePacksRepository) + " != null");
            Debug.Assert(packsSerializer != null, nameof(packsSerializer) + " != null");

            m_filePacksRepository = filePacksRepository;
            m_packsSerializer     = packsSerializer;
            m_filePacksRepository.ClipboardFilePacksUpdated += FilePacksRepoChanged;
        }
Esempio n. 2
0
        private void App_OnStartup(object sender, StartupEventArgs e)
        {
            WcfMutexSingleInstanceRunner instanceRunner = new WcfMutexSingleInstanceRunner("8E756836-F0DE-490E-AEA5-EDAADF9C5FF8");

            if (!instanceRunner.Run(e))
            {
                instanceRunner.Dispose();
                Shutdown(0);
            }
            m_dispatcher = new DispatcherWrapper(Dispatcher.CurrentDispatcher);
            instanceRunner.SecondInstanceStarted += CreateSettingsWindow;


            #region Upgrade settings
            if (!HandMeAFile.Properties.Settings.Default.Updated)
            {
                HandMeAFile.Properties.Settings.Default.Updated = true;
                HandMeAFile.Properties.Settings.Default.Upgrade();
                HandMeAFile.Properties.Settings.Default.Save();
            }
            #endregion

            IClipboard clipboard = new ClipboardWrapper();
            m_packsRepository = new ClipboardFilesRepository(new ClipboardNotifier(), clipboard);
            m_settings        = new SettingsStorage(m_packsRepository, new FilePackSerializer(new XDocumentProvider()));
            m_packsRepository.Init(m_settings.FilePacks.Select(p => p.SetCount((p.ClipboardCount + 1) / 2)).ToArray());


            IProvideContextMenu contextMenuProvider = new ContextMenuProvider();

            IContextMenu     contextMenu      = contextMenuProvider.Provide(new IMenuItem[0]);
            IProvideMenuItem menuItemProvider = new MenuItemProvider();
            IMenuItem        settingsMenuItem = menuItemProvider.Provide("Settings");
            IMenuItem        exitMenuItem     = menuItemProvider.Provide("Exit");
            contextMenu.Add(menuItemProvider.Provide("-"));
            contextMenu.Add(settingsMenuItem);
            contextMenu.Add(exitMenuItem);
            settingsMenuItem.Click += CreateSettingsWindow;
            exitMenuItem.Click     += (senderObj, args) => Shutdown(0);
            m_contextUpdater        = new ContextMenuUpdater(m_packsRepository, contextMenu, menuItemProvider, clipboard);


            IRunTheTrayApp trayApplication = new TrayApplication(contextMenu,
                                                                 new ApplicationWrapper(this),
                                                                 new NotifyIconProvider(),
                                                                 new StaticIconProvider(new IconWrapper(HandMeAFile.Properties.Resources.HandMeAFile)),
                                                                 doubleClickAction: CreateSettingsWindow);
            trayApplication.Run();
        }
        public ContextMenuUpdater([NotNull] IReadAndStoreFilePacks filePacksRepository,
                                  [NotNull] IContextMenu contextMenu,
                                  [NotNull] IProvideMenuItem menuItemProvider,
                                  [NotNull] IClipboard clipboard)
        {
            Debug.Assert(filePacksRepository != null, nameof(filePacksRepository) + " != null");
            Debug.Assert(contextMenu != null, nameof(contextMenu) + " != null");
            Debug.Assert(menuItemProvider != null, nameof(menuItemProvider) + " != null");
            Debug.Assert(clipboard != null, nameof(clipboard) + " != null");


            m_filePacksRepository = filePacksRepository;
            m_contextMenu         = contextMenu;
            m_menuItemProvider    = menuItemProvider;
            m_clipboard           = clipboard;
            m_defaultContextItems = contextMenu.MenuItems;
            UpdateContextMenu();
            m_filePacksRepository.ClipboardFilePacksUpdated += FilePacksRepositoryOnClipboardFilePacksUpdated;
        }