Esempio n. 1
0
        /* ----------------------------------------------------------------- */
        ///
        /// OnDragDrop
        ///
        /// <summary>
        /// ファイルがドロップされた時に実行されるハンドラです。
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        protected override void OnDragDrop(DragEventArgs e)
        {
            base.OnDragDrop(e);
            var files = e.Data.GetData(DataFormats.FileDrop, false) as string[];

            OnOpen(ValueEventArgs.Create(files));
        }
Esempio n. 2
0
        public void Create_ValueCancelEventArgs <T>(T value, bool cancel)
        {
            var args = ValueEventArgs.Create(value, cancel);

            Assert.That(args.Value, Is.EqualTo(value));
            Assert.That(args.Cancel, Is.EqualTo(cancel));
        }
Esempio n. 3
0
        /* ----------------------------------------------------------------- */
        ///
        /// TagSettings_Handle
        ///
        /// <summary>
        /// タグ設定画面を表示する時に実行されるハンドラです。
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        private async void TagSettings_Handle()
        {
            var tags = SyncWait(() =>
            {
                var dialog = Dialogs.TagSettings(View.FindForm(), Model.Tags, Settings.User);
                dialog.ShowDialog();
                return(dialog.DialogResult == DialogResult.Cancel ?
                       new KeyValuePair <Tag[], Tag[]>(null, null) :
                       new KeyValuePair <Tag[], Tag[]>(
                           dialog.NewTags.ToArray(),
                           dialog.RemoveTags.ToArray()
                           ));
            });

            if (tags.Key == null || tags.Value == null)
            {
                return;
            }

            await Async(() =>
            {
                foreach (var tag in tags.Key)
                {
                    Events.NewTag.Publish(ValueEventArgs.Create(tag));
                }
                foreach (var tag in tags.Value)
                {
                    Events.RemoveTag.Publish(ValueEventArgs.Create(tag));
                }
            });
        }
Esempio n. 4
0
        public void Create_ValueChangedEventArgs <T>(T before, T after)
        {
            var args = ValueEventArgs.Create(before, after);

            Assert.That(args.OldValue, Is.EqualTo(before));
            Assert.That(args.NewValue, Is.EqualTo(after));
        }
Esempio n. 5
0
        /* ----------------------------------------------------------------- */
        ///
        /// OnDragDrop
        ///
        /// <summary>
        /// 項目がドロップされた時に実行されます。
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        protected override void OnDragDrop(DragEventArgs e)
        {
            base.OnDragDrop(e);

            var item = e.Data.GetData(typeof(ListViewItem)) as ListViewItem;

            if (item == null)
            {
                return;
            }

            var src = Items.IndexOf(item);

            if (src == -1)
            {
                return;
            }

            var point = PointToClient(new Point(e.X, e.Y));
            int dest  = Items.IndexOf(GetItemAt(point.X, point.Y));

            if (dest == -1)
            {
                dest = Items.Count - 1;
            }

            Aggregator?.Move.Publish(ValueEventArgs.Create(dest - src));
        }
Esempio n. 6
0
        /* ----------------------------------------------------------------- */
        ///
        /// RssSubscriber
        ///
        /// <summary>
        /// オブジェクトを初期化します。
        /// </summary>
        ///
        /// <param name="context">同期用オブジェクト</param>
        ///
        /* ----------------------------------------------------------------- */
        public RssSubscriber(SynchronizationContext context)
        {
            _dispose = new OnceAction <bool>(Dispose);
            _context = context;

            _tree = new BindableCollection <IRssEntry> {
                Context = context
            };
            _tree.CollectionChanged += (s, e) =>
            {
                AutoSaveCore();
                CollectionChanged?.Invoke(this, e);
            };

            _monitors[0] = new RssMonitor {
                Interval = TimeSpan.FromHours(1)
            };
            _monitors[0].Subscribe(e => Received?.Invoke(this, ValueEventArgs.Create(e)));

            _monitors[1] = new RssMonitor {
                Interval = TimeSpan.FromHours(24)
            };
            _monitors[1].Subscribe(e => Received?.Invoke(this, ValueEventArgs.Create(e)));

            _monitors[2] = new RssMonitor(); // for RssCheckFrequency.None
            _monitors[2].Subscribe(e => Received?.Invoke(this, ValueEventArgs.Create(e)));

            _autosaver.AutoReset = false;
            _autosaver.Interval  = 1000.0;
            _autosaver.Elapsed  += WhenAutoSaved;
        }
 /* ----------------------------------------------------------------- */
 ///
 /// RaiseMailRequested
 ///
 /// <summary>
 /// MailRequested イベントを発生させます。
 /// </summary>
 ///
 /* ----------------------------------------------------------------- */
 private void RaiseMailRequested()
 {
     if (!Request.Mail)
     {
         return;
     }
     MailRequested?.Invoke(this, ValueEventArgs.Create(Destination));
 }
Esempio n. 8
0
        /* ----------------------------------------------------------------- */
        ///
        /// ProgressFacade
        ///
        /// <summary>
        /// オブジェクトを初期化します。
        /// </summary>
        ///
        /// <param name="request">リクエストオブジェクト</param>
        /// <param name="settings">設定情報</param>
        ///
        /* ----------------------------------------------------------------- */
        protected ProgressFacade(Request request, SettingsFolder settings)
        {
            Request  = request;
            Settings = settings;

            IO.Failed      += WhenFailed;
            _timer.Elapsed += (s, e) => OnProgress(ValueEventArgs.Create(Report));
        }
Esempio n. 9
0
        public void WhenValueNotEquals_ThenArgsNotEqual()
        {
            var arg1 = ValueEventArgs.Create("foo");
            var arg2 = ValueEventArgs.Create("bar");

            Assert.False(arg1.Equals(arg2));
            Assert.NotEqual(arg1.GetHashCode(), arg2.GetHashCode());
        }
Esempio n. 10
0
 /* ----------------------------------------------------------------- */
 ///
 /// Google_Handle
 ///
 /// <summary>
 /// インターネットで検索時に実行されるハンドラです。
 /// </summary>
 ///
 /* ----------------------------------------------------------------- */
 private void Google_Handle(ValueEventArgs <string> e)
 {
     if (string.IsNullOrEmpty(e.Value))
     {
         return;
     }
     Events.Web.Publish(ValueEventArgs.Create(Settings.User.SearchQuery + e.Value));
 }
Esempio n. 11
0
        public void WhenValueEquals_ThenArgsEquals()
        {
            var arg1 = ValueEventArgs.Create("foo");
            var arg2 = ValueEventArgs.Create("foo");

            Assert.True(arg1.Equals(arg2));
            Assert.Equal(arg1.GetHashCode(), arg2.GetHashCode());
        }
Esempio n. 12
0
        /* ----------------------------------------------------------------- */
        ///
        /// ItemListControl
        ///
        /// <summary>
        /// オブジェクトを初期化します。
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        public PageCollectionControl()
        {
            InitializeComponent();

            NewPageButton.Click += (s, e)
                                   => Aggregator.Get()?.NewPage.Publish(ValueEventArgs.Create(0));

            Pages.AllowDrop = true;
            Pages.KeyDown  += (s, e) => OnKeyDown(e);
        }
Esempio n. 13
0
        public void WhenValueNull_ThenArgsNotEqual()
        {
            Assert.False(
                ValueEventArgs.Create("foo").Equals(
                    ValueEventArgs.Create(default(string))));

            Assert.False(
                ValueEventArgs.Create(default(string)).Equals(
                    ValueEventArgs.Create("foo")));
        }
Esempio n. 14
0
        private void OnElementDeleted(object sender, DslModeling.ElementDeletedEventArgs e)
        {
            var element = e.ModelElement as IInstanceBase;

            if (element != null && !this.IsSerializing)
            {
                StoreEventBufferingScope.RaiseOrBufferEvent(() =>
                {
                    var eventArgs = ValueEventArgs.Create(element);
                    this.ElementDeleted(this, eventArgs);
                });
            }
        }
Esempio n. 15
0
        /* ----------------------------------------------------------------- */
        ///
        /// Open
        ///
        /// <summary>
        /// PDF ファイルを読み込みます。
        /// </summary>
        ///
        /// <param name="src">PDF ファイルのパス</param>
        ///
        /* ----------------------------------------------------------------- */
        public void Open(string src)
        {
            while (IsLocked(src))
            {
                var e = ValueEventArgs.Create(src, false);
                OnLocked(e);
                if (e.Cancel)
                {
                    return;
                }
            }

            Close();
            Source = new Cube.Pdf.Itext.DocumentReader(src, "", true, IO);
            Reset();
        }
        /* ----------------------------------------------------------------- */
        ///
        /// Model_CollectionChanged
        ///
        /// <summary>
        /// コレクションの内容に変更があった時に実行されるハンドラです。
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        private void Model_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                Model_Added(sender, e);
                break;

            case NotifyCollectionChangedAction.Remove:
                if (Model.Count <= 0)
                {
                    NewPage_Handle(ValueEventArgs.Create(0));
                }
                break;
            }
        }
Esempio n. 17
0
 /* ----------------------------------------------------------------- */
 ///
 /// InitializeEvents
 ///
 /// <summary>
 /// 項目のイベントを初期化します。
 /// </summary>
 ///
 /* ----------------------------------------------------------------- */
 private void InitializeEvents()
 {
     NewPageMenu.Click += (s, e)
                          => Aggregator.Get()?.NewPage.Publish(EventAggregator.Selected);
     ImportMenu.Click += (s, e)
                         => Aggregator.Get()?.Import.Publish(KeyValueEventArgs.Create(-1, ""));
     ExportMenu.Click += (s, e)
                         => Aggregator.Get()?.Export.Publish(EventAggregator.Selected);
     DuplicateMenu.Click += (s, e)
                            => Aggregator.Get()?.Duplicate.Publish(EventAggregator.Selected);
     RemoveMenu.Click += (s, e)
                         => Aggregator.Get()?.Remove.Publish(EventAggregator.Selected);
     UpMenu.Click += (s, e)
                     => Aggregator.Get()?.Move.Publish(ValueEventArgs.Create(-1));
     DownMenu.Click += (s, e)
                       => Aggregator.Get()?.Move.Publish(ValueEventArgs.Create(1));
     PropertyMenu.Click += (s, e)
                           => Aggregator.Get()?.Property.Publish(EventAggregator.Selected);
 }
        /* ----------------------------------------------------------------- */
        ///
        /// Property_Handled
        ///
        /// <summary>
        /// タグ編集画面を表示する時に実行されるハンドラです。
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        private void Property_Handled(ValueEventArgs <int> e)
        => this.LogWarn(() =>
        {
            var page = Settings.Current.Page;
            if (page == null)
            {
                return;
            }

            var tags = GetTags(page);
            if (tags == null)
            {
                return;
            }

            if (page.Tags.Count == 0)
            {
                Model.Nothing?.Decrement();
            }
            else
            {
                Model.Decrement(page.Tags);
            }
            page.Tags.Clear();

            if (tags.Length == 0)
            {
                Model.Nothing?.Increment();
            }
            else
            {
                foreach (var name in tags)
                {
                    Model.Create(name).Count++;
                    page.Tags.Add(name);
                }
            }

            Events.Edit.Publish(ValueEventArgs.Create(page));
        });
Esempio n. 19
0
        /* ----------------------------------------------------------------- */
        ///
        /// Attach
        ///
        /// <summary>
        /// 新しいファイルを添付します。
        /// </summary>
        ///
        /// <param name="file">添付ファイル</param>
        ///
        /* ----------------------------------------------------------------- */
        public void Attach(string file)
        {
            if (Clips.Any(e => e.RawObject.Source == file))
            {
                return;
            }

            while (IsLocked(file))
            {
                var e = ValueEventArgs.Create(file, false);
                OnLocked(e);
                if (e.Cancel)
                {
                    return;
                }
            }

            Clips.Insert(0, new ClipItem(new Attachment(file, IO))
            {
                Condition = Properties.Resources.ConditionNew
            });
        }
Esempio n. 20
0
        private void OnElementAdded(object sender, DslModeling.ElementAddedEventArgs e)
        {
            var element = e.ModelElement as IInstanceBase;

            if (element != null)
            {
                // ElementCreated is raised always, regardless of how the element was created.
                StoreEventBufferingScope.RaiseOrBufferEvent(() =>
                {
                    var eventArgs = ValueEventArgs.Create(element);
                    this.ElementCreated(this, eventArgs);
                });

                if (!this.IsSerializing)
                {
                    // We only invoke this event if the element has not been marked in the state.
                    // it wants instantiation events (the default is true, see StoreEventBufferingScope ctor).
                    if (ShouldRaiseInstantiate(e.ModelElement))
                    {
                        StoreEventBufferingScope.RaiseOrBufferEvent(() =>
                        {
                            var eventArgs = ValueEventArgs.Create(element);
                            this.ElementInstantiated(this, eventArgs);
                        });
                    }
                }
                else
                {
                    // We're deserializing the element, so we raise the Loaded event.
                    StoreEventBufferingScope.RaiseOrBufferEvent(() =>
                    {
                        var eventArgs = ValueEventArgs.Create(element);
                        this.ElementLoaded(this, eventArgs);
                    });
                }
            }
        }
Esempio n. 21
0
        /* ----------------------------------------------------------------- */
        ///
        /// InitializeTextMenu
        ///
        /// <summary>
        /// コンテキストメニューを初期化します。
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        private void InitializeTextMenu()
        {
            var menu = TextMenu;

            if (menu == null)
            {
                return;
            }

            Settings.Current.PropertyChanged += Settings_CurrentChanged;

            var enabled = View.GetSelectedTextLength() > 0;

            menu.SearchMenu.Click += (s, e) =>
                                     Events.Search.Publish(KeyValueEventArgs.Create(0, View.GetSelectedText()));

            menu.GoogleMenu.Enabled = enabled;
            menu.GoogleMenu.Click  += (s, e)
                                      => Events.Google.Publish(ValueEventArgs.Create(View.GetSelectedText()));

            menu.UndoMenu.Enabled = View.CanUndo;
            menu.UndoMenu.Click  += (s, e) => Events.Undo.Publish();

            menu.RedoMenu.Enabled = View.CanRedo;
            menu.RedoMenu.Click  += (s, e) => Events.Redo.Publish();

            menu.CutMenu.Enabled = enabled;
            menu.CutMenu.Click  += (s, e) => View.Cut();

            menu.CopyMenu.Enabled = enabled;
            menu.CopyMenu.Click  += (s, e) => View.Copy();

            menu.PasteMenu.Enabled = View.CanPaste;
            menu.PasteMenu.Click  += (s, e) => View.Paste();

            menu.SelectAllMenu.Click += (s, e) => View.SelectAll();
        }
Esempio n. 22
0
 /* ----------------------------------------------------------------- */
 ///
 /// View_LogoMenu
 ///
 /// <summary>
 /// ロゴメニューがクリックされた時に実行されるハンドラです。
 /// </summary>
 ///
 /* ----------------------------------------------------------------- */
 private void View_LogoMenu(object sender, EventArgs e)
 => Events.Web.Publish(ValueEventArgs.Create(Properties.Resources.UrlWeb));
Esempio n. 23
0
 /* ----------------------------------------------------------------- */
 ///
 /// DropForm
 ///
 /// <summary>
 /// オブジェクトを初期化します。
 /// </summary>
 ///
 /* ----------------------------------------------------------------- */
 public DropForm(string[] src)
     : this()
 {
     OnOpen(ValueEventArgs.Create(src));
 }
Esempio n. 24
0
 /* ----------------------------------------------------------------- */
 ///
 /// OnReceived
 ///
 /// <summary>
 /// 他プロセスからデータ受信時に実行されます。
 /// </summary>
 ///
 /* ----------------------------------------------------------------- */
 protected override void OnReceived(EnumerableEventArgs <string> e)
 {
     base.OnReceived(e);
     OnOpen(ValueEventArgs.Create(e.Value.ToArray()));
 }
Esempio n. 25
0
        /* ----------------------------------------------------------------- */
        ///
        /// RunShortcutKeysWithCtrl
        ///
        /// <summary>
        /// Ctrl+Keys のショートカットキーを処理します。
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        private void RunShortcutKeysWithCtrl(KeyEventArgs e)
        {
            var result = true;

            switch (e.KeyCode)
            {
            case Keys.C:
                if (e.Shift)
                {
                    Aggregator.Get().Duplicate.Publish(EventAggregator.Selected);
                }
                else
                {
                    result = false;
                }
                break;

            case Keys.D:
                Aggregator.Get().Remove.Publish(EventAggregator.Selected);
                break;

            case Keys.E:
                Aggregator.Get().Export.Publish(EventAggregator.Selected);
                break;

            case Keys.F:
                RaiseSearch();
                break;

            case Keys.G:
                Aggregator.Get().Google.Publish(ValueEventArgs.Create(SelectedText));
                break;

            case Keys.H:
                SwitchMenu();
                break;

            case Keys.J:
            case Keys.Down:
                Aggregator.Get().Move.Publish(ValueEventArgs.Create(1));
                break;

            case Keys.K:
            case Keys.Up:
                Aggregator.Get().Move.Publish(ValueEventArgs.Create(-1));
                break;

            case Keys.N:
                Aggregator.Get().NewPage.Publish(e.Shift ?
                                                 EventAggregator.Selected :
                                                 EventAggregator.Top
                                                 );
                break;

            case Keys.O:
                Aggregator.Get().Import.Publish(KeyValueEventArgs.Create(0, ""));
                break;

            case Keys.P:
                Aggregator.Get().Print.Publish();
                break;

            case Keys.R:
                if (e.Shift)
                {
                    Aggregator.Get().TagSettings.Publish();
                }
                else
                {
                    Aggregator.Get().Property.Publish(EventAggregator.Selected);
                }
                break;

            case Keys.S:
                if (e.Shift)
                {
                    Aggregator.Get().Export.Publish(EventAggregator.Selected);
                }
                else
                {
                    Aggregator.Get().Save.Publish();
                }
                break;

            case Keys.T:
                Aggregator.Get().Settings.Publish();
                break;

            case Keys.U:
                Aggregator.Get().TagSettings.Publish();
                break;

            default:
                result = false;
                break;
            }
            e.Handled = result;
        }
Esempio n. 26
0
 public void WhenOtherIsDifferentType_ThenArgsNotEqual()
 {
     Assert.False(
         ValueEventArgs.Create("foo").Equals(
             ValueEventArgs.Create(25)));
 }
Esempio n. 27
0
        public void WhenSameReference_ThenAreEqual()
        {
            var arg = ValueEventArgs.Create("foo");

            Assert.True(arg.Equals(arg));
        }
Esempio n. 28
0
 public void WhenOtherIsNull_ThenArgsNotEqual()
 {
     Assert.False(
         ValueEventArgs.Create("foo").Equals(
             default(ValueEventArgs <string>)));
 }
Esempio n. 29
0
        public void Create_ValueEventArgs <T>(T value)
        {
            var args = ValueEventArgs.Create(value);

            Assert.That(args.Value, Is.EqualTo(value));
        }