예제 #1
0
        // プロファイルメニュー開いた時
        private void MenuItem_Profile_SubmenuOpened(object sender, RoutedEventArgs e)
        {
            // Xmlからプロファイルをロード
            string xmlDir = Directory.GetParent(System.Reflection.Assembly.GetExecutingAssembly().Location).FullName + "\\Profile";

            if (Directory.Exists(xmlDir))
            {
                string[] xmls = Directory.GetFiles(xmlDir);
                foreach (string xml in xmls)
                {
                    if (System.IO.Path.GetExtension(xml) == ".xml")
                    {
                        // UserProfileListにあるなら、メンバとしてプロファイルを追加、ないなら新たにUserProfileInfoを作成して追加
                        string          relativePath = xml.Replace(xmlDir + "\\", "");
                        UserProfileInfo upi          = Setting.UserProfileList.FirstOrDefault(pl => pl.RelativePath == relativePath);
                        if (upi != null)
                        {
                            if (upi.Profile == null)
                            {
                                Profile pf = UserProfileInfo.LoadProfileFromXmlFile(xml);
                                upi.Profile = pf;
                            }
                        }
                        else
                        {
                            UserProfileInfo newUpi = new UserProfileInfo(relativePath);
                            Profile         pf     = UserProfileInfo.LoadProfileFromXmlFile(xml);
                            newUpi.Profile = pf;
                            Setting.UserProfileList.Add(newUpi);
                        }
                    }
                }
            }

            // xmlファイルからロード出来なかった、UserProfileInfoを全て削除
            Setting.UserProfileList.RemoveAll(pl => pl.Profile == null);

            // イベントの発生元チェック(子要素からのイベントなら無視)
            MenuItem miSrc = e.OriginalSource as MenuItem;

            if (miSrc == null || miSrc.Name != MenuItem_Profile.Name)
            {
                return;
            }

            // プロファイル追加前に削除
            const int basicManuCnt = 1;

            while (MenuItem_Profile.Items.Count > basicManuCnt)
            {
                MenuItem_Profile.Items.RemoveAt(basicManuCnt);
            }

            // プリセットプロファイル追加
            if (Setting.UsePresetProfile)
            {
                MenuItem_Profile.Items.Add(new Separator());
                foreach (Profile ppf in PresetProfile.Items)
                {
                    MenuItem mi = new MenuItem();
                    mi.Header = ppf.Name;
                    if (ppf.Name == "デフォルト")
                    {
                        mi.ToolTip = "デフォルト";
                    }
                    else
                    {
                        mi.ToolTip = ppf.CreateProfileToolTip();
                    }
                    ToolTipService.SetShowDuration(mi, 1000000);
                    mi.Click += (se, ev) => { LoadUserProfile(ppf); };
                    MenuItem_Profile.Items.Add(mi);
                }
            }

            // セパレータ追加
            if (Setting.UserProfileList.Count > 0)
            {
                MenuItem_Profile.Items.Add(new Separator());
            }

            // プロファイル追加
            int num = 1;

            foreach (UserProfileInfo upi in Setting.UserProfileList)
            {
                MenuItem mi = new MenuItem();
                mi.Header  = string.Format("{0:00}", num) + ": " + upi.Profile.Name.Replace("_", "__");
                mi.ToolTip = upi.Profile.CreateProfileToolTip();
                ToolTipService.SetShowDuration(mi, 1000000);
                mi.Click      += (se, ev) => { LoadUserProfile(upi.Profile); };
                mi.ContextMenu = CreateProfileContextMenu(upi);
                MenuItem_Profile.Items.Add(mi);
                num++;
            }

            // リストを編集... を追加
            MenuItem_Profile.Items.Add(new Separator());
            MenuItem ms = new MenuItem();

            ms.Header = "リストを編集...";
            ms.Click += (se, ev) => { ShowProfileListEditDialog(); };
            MenuItem_Profile.Items.Add(ms);
        }
예제 #2
0
        private void InitEvent()
        {
            this.SourceInitialized += (s, e) =>
            {
                // ウインドウ位置復元が正常に行われたかチェック
                Win32.SetWindowPosProperly(new WindowInteropHelper(this).Handle, (int)this.Left, (int)this.Top, true, 0, true);
            };

            this.SizeChanged += (s, e) =>
            {
                // 以下の処理は、ウインドウ枠ドラッグでのサイズ変更時のみ有効
                if (IgnoreResizeEvent)
                {
                    return;
                }

                // 画像拡大パネルのサイズ更新、拡大中ならリセット
                if (TileExpantionPanel.IsShowing)
                {
                    TileExpantionPanel.FitToMainWindow();
                }

                // アス比非固定時
                if (Setting.TempProfile.NonFixAspectRatio.Value)
                {
                    // 現在のプロファイル
                    Profile pf = Setting.TempProfile;

                    // タイルサイズ(アス比)の決定
                    double w         = (this.Width - MainContent.Margin.Left * 2) / pf.NumofMatrix.Col;
                    double h         = (this.Height - MainContent.Margin.Left * 2) / pf.NumofMatrix.Row;
                    double gridRatio = h / w;

                    int gridWidth  = ImgContainer.StandardInnerTileWidth + pf.TilePadding.Value * 2;
                    int gridHeight = (int)(gridWidth * gridRatio);
                    pf.AspectRatio.Value = new int[] { ImgContainer.StandardInnerTileWidth, gridHeight - pf.TilePadding.Value * 2 };

                    // コンテナサイズの決定
                    ImgContainerManager.InitContainerSize();
                    ImgContainerManager.InitWrapPoint(pf.SlideDirection.Value);

                    // BitmapDecodePixelOfTilewを更新
                    ImgContainerManager.InitBitmapDecodePixelOfTile();

                    // 位置を正規化
                    ImgContainerManager.InitContainerPos();
                }

                // アス比固定・非固定に関わらず拡大縮小
                FitMainContentToWindow();
            };

            this.Closing += (s, e) =>
            {
                ShortcutManager.UnhookWindowsHook();
            };

            this.PreviewDragOver += (s, e) =>
            {
                if (e.Data.GetDataPresent(DataFormats.FileDrop, true))
                {
                    e.Effects = DragDropEffects.All;
                }
                else
                {
                    e.Effects = DragDropEffects.None;
                }
                e.Handled = true;
            };

            this.Drop += (s, e) =>
            {
                SaveHistoryItem();

                // メインウインドウをアクティブに
                this.Activate();

                string[] files = e.Data.GetData(DataFormats.FileDrop) as string[];

                if (IsCtrlOrShiftKeyPressed)
                {
                    // 追加読み込み
                    ReadFiles(files, true);
                    var t = ImgContainerManager.InitAllContainer(0);
                }
                else
                {
                    // 通常読み込み
                    DropNewFiles(files);
                }
            };


            // end of method
        }