//ライセンス情報はAgeOnフォルダのLISENCEフォルダを参照してください
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Net;
using System.IO;
using System.Threading;

using nispi.controlclass;
using nispi.Menu;

namespace nispi
{
    class BoardListViewMainMenu
    {
        public ToolStripMenuItemParts menuItemDownloadParts;
        public ToolStripMenuItemParts menuItemAddFavoriteParts;
        public ToolStripMenuItemParts menuItemAlreadyReadParts;
        public ToolStripMenuItemParts menuItemNotReadParts;
        public ToolStripMenuItemParts menuItemCopyURLParts;
        public ToolStripMenuItemParts menuItemCopyTitleParts;
        //public ToolStripMenuItemParts menuItemSelectAllParts;
        public ToolStripMenuItemParts menuItemDeleteLogParts;
        public ToolStripMenuItemParts menuItemSaveHtmlParts;
        public ToolStripMenuItemParts menuItemSaveDatParts;
        public ToolStripMenuItemParts menuItemOpenBrowserParts;
        public ToolStripMenuItemParts menuItemReloadParts;

        public ListViewPartMenuEvent listViewPartMenuEvent;

        public BoardListViewMainMenu(ToolStripMenuItemParts menuItem)
        {
            menuItemDownloadParts = ToolStripMenuItemPartsManager.Pop();
            menuItemAddFavoriteParts = ToolStripMenuItemPartsManager.Pop();
            menuItemAlreadyReadParts = ToolStripMenuItemPartsManager.Pop();
            menuItemNotReadParts = ToolStripMenuItemPartsManager.Pop();
            menuItemCopyURLParts = ToolStripMenuItemPartsManager.Pop();
            menuItemCopyTitleParts = ToolStripMenuItemPartsManager.Pop();
            //menuItemSelectAllParts = ToolStripMenuItemPartsManager.Pop();
            menuItemDeleteLogParts = ToolStripMenuItemPartsManager.Pop();
            menuItemSaveHtmlParts = ToolStripMenuItemPartsManager.Pop();
            menuItemSaveDatParts = ToolStripMenuItemPartsManager.Pop();
            menuItemOpenBrowserParts = ToolStripMenuItemPartsManager.Pop();
            menuItemReloadParts = ToolStripMenuItemPartsManager.Pop();

            //メインメニューの設定
            menuItemDownloadParts.Text = "開く";

            menuItemAddFavoriteParts.Text = "お気に入りに追加する";

            menuItemAlreadyReadParts.Text = "既読にする";

            menuItemNotReadParts.Text = "未読にする";

            menuItemCopyURLParts.Text = "URLをコピー";

            menuItemCopyTitleParts.Text = "名前をコピー";

            //menuItemSelectAllParts.Text = "すべて選択";

            menuItemDeleteLogParts.Text = "ログを削除する";

            menuItemSaveHtmlParts.Text = "HTML形式で保存";

            menuItemSaveDatParts.Text = "DAT形式で保存";

            menuItemOpenBrowserParts.Text = "ブラウザで開く";



            menuItem.DropDownItemsAdd(menuItemDownloadParts);
            menuItem.DropDownItemsAdd(menuItemAddFavoriteParts);
            menuItem.DropDownItemsAdd(menuItemOpenBrowserParts);
            menuItem.DropDownItemsAdd("-");
            menuItem.DropDownItemsAdd(menuItemCopyURLParts);
            menuItem.DropDownItemsAdd(menuItemCopyTitleParts);
            menuItem.DropDownItemsAdd("-");
            menuItem.DropDownItemsAdd(menuItemAlreadyReadParts);
            menuItem.DropDownItemsAdd(menuItemNotReadParts);
            //menuItem.DropDownItemsAdd(menuItemSelectAllParts);
            menuItem.DropDownItemsAdd("-");
            menuItem.DropDownItemsAdd(menuItemDeleteLogParts);
            menuItem.DropDownItemsAdd(menuItemSaveHtmlParts);
            menuItem.DropDownItemsAdd(menuItemSaveDatParts);

            listViewPartMenuEvent = new ListViewPartMenuEvent(this);
        }

        //メインメニューの設定をする
        public void SetMenu()
        {
            int index = Const.form.boardListTabControlParts.SelectedIndex;

            //お気に入りのタブの場合
            if (index == 0)
            {
                if ((MainFormConst.boardListTabMain.view_list[0].boardListControls.listViewParts.FocusedItem != null) &&
                    (MainFormConst.boardListTabMain.view_list[0].boardListControls.listViewParts.FocusedItem_Name.Length > 0))
                {
                    AllTrue();
                    menuItemAddFavoriteParts.Enabled = false;
                    
                }
                //リストのアイテムが選択されていない
                else
                {
                    AllFalse();
                }
            }
            else if (index >= 1)
            {
                //リストのアイテムが選択されている
                if ((MainFormConst.boardListTabMain.view_list[index].boardListControls.listViewParts.FocusedItem != null) &&
                    (MainFormConst.boardListTabMain.view_list[index].boardListControls.listViewParts.FocusedItem_Name.Length > 0))
                {
                    AllTrue();
                }
                //リストのアイテムが選択されていない
                else
                {
                    AllFalse();
                }
            }
        }

        public void AllTrue()
        {
            menuItemDownloadParts.Enabled = true;
            menuItemAddFavoriteParts.Enabled = true;
            menuItemOpenBrowserParts.Enabled = true;
            menuItemCopyURLParts.Enabled = true;
            menuItemCopyTitleParts.Enabled = true;
            menuItemAlreadyReadParts.Enabled = true;
            menuItemNotReadParts.Enabled = true;
            //menuItemSelectAllParts.Enabled = true;
            menuItemDeleteLogParts.Enabled = true;
            menuItemSaveHtmlParts.Enabled = true;
            menuItemSaveDatParts.Enabled = true;
        }

        public void AllFalse()
        {
            menuItemDownloadParts.Enabled = false;
            menuItemAddFavoriteParts.Enabled = false;
            menuItemOpenBrowserParts.Enabled = false;
            menuItemCopyURLParts.Enabled = false;
            menuItemCopyTitleParts.Enabled = false;
            menuItemAlreadyReadParts.Enabled = false;
            menuItemNotReadParts.Enabled = false;
            //menuItemSelectAllParts.Enabled = false;
            menuItemDeleteLogParts.Enabled = false;
            menuItemSaveHtmlParts.Enabled = false;
            menuItemSaveDatParts.Enabled = false;
        }
    }
}