Example #1
0
        // 関数:全ての内容を保存する
        public void SaveAll()
        {
            // 現在開いているTextBoxの内容を記憶
            MemoryTextData();

            // 現在のListBoxの内容を1項目ずつ改行して代入
            string s = "";

            foreach (Object obj in listBox1.Items)
            {
                s += obj.ToString() + Environment.NewLine;
            }
            // 内容を項目保存用テキストに書き込み
            File.WriteAllText(
                LISTDATA,
                s,
                ENCODE);

            // 全ての付箋オブジェクトのテキスト内容をテキストファイルに保存
            for (int i = 0; i < listBox1.Items.Count; i++)
            {
                FusenData fdata = (FusenData)listBox1.Items[i];
                File.WriteAllText(
                    TEXTFLD + @"/" + i.ToString() + @".txt",
                    fdata.ftext,
                    ENCODE);
            }

            // Dirtyマークを消す
            dirty = false;
            panelDirty.Visible = false;

            showSaved();
        }
Example #2
0
        // 関数:Texboxの内容を記憶する
        public void MemoryTextData()
        {
            // 選択アイテムの付箋データにアクセスして代入
            FusenData fdata = (FusenData)listBox1.Items[lbSelId];

            fdata.ftext = textBox1.Text;
        }
Example #3
0
        // 関数:ListBoxの選択アイテムの内容をTextBoxに表示
        public void ShowTextData()
        {
            // 選択アイテムの付箋データにアクセスして表示
            FusenData fdata = (FusenData)listBox1.Items[listBox1.SelectedIndex];

            textBox1.Text = fdata.ftext;

            // TextBoxの内容が変化した時のイベントをここでONにする
            textBox1.TextChanged += textBox1_TextChanged;

            // lbSelId更新
            lbSelId = listBox1.SelectedIndex;
        }
Example #4
0
        // 関数:ListBoxの選択アイテムのリネーム
        public void ListReName()
        {
            // アイテムを何も選択していない場合はメッセージを表示
            if (listBox1.SelectedIndex == -1)
            {
                MessageBox.Show("リストを選択してください");
                return;
            }

            // ListBoxの選択Indexが変化した時のイベントをここでOFFにする
            listBox1.SelectedIndexChanged -= listBox1_SelectedIndexChanged;

            // ListBoxの選択アイテムの名前を取得
            lbSelName = listBox1.SelectedItem.ToString();
            // ListBoxの選択アイテムのindexを取得
            lbSelId = listBox1.SelectedIndex;

            // リネームダイアログを開く
            FormReName f = new FormReName();

            // オーナーウィンドウの真ん中に表示
            f.StartPosition = FormStartPosition.CenterParent;
            // オーナーウィンドウにthisを指定する
            f.ShowDialog(this);
            //フォームが必要なくなったところで、Disposeを呼び出す
            f.Dispose();

            /*
             * この間、リネームダイアログでの操作
             */

            // 付箋インスタンスに新しい名前を与えてListBoxに反映させる
            FusenData fdata = (FusenData)listBox1.Items[lbSelId];

            fdata.fname             = lbSelName;
            listBox1.Items[lbSelId] = fdata;

            // ListBoxの選択Indexが変化した時のイベントをここでONにする
            listBox1.SelectedIndexChanged += listBox1_SelectedIndexChanged;
        }
Example #5
0
        // 関数:ListBoxのアイテムを新規追加
        private void ListAdd()
        {
            // ListBoxのアイテム数を調べる( = 新規追加するindex)
            int i = listBox1.Items.Count;

            // n.txtファイルを作成する
            var sw = new StreamWriter(
                TEXTFLD + @"/" + i.ToString() + @".txt",
                false,
                ENCODE);

            sw.Close();

            // ListBoxの選択アイテムの名前を取得
            lbSelName = NEWTITLE;

            // リネームダイアログを開く
            FormReName f = new FormReName();

            // オーナーウィンドウの真ん中に表示
            f.StartPosition = FormStartPosition.CenterParent;
            // オーナーウィンドウにthisを指定する
            f.ShowDialog(this);
            //フォームが必要なくなったところで、Disposeを呼び出す
            f.Dispose();

            /*
             * この間、リネームダイアログでの操作
             */

            // ダイアログで"OK"したかを判定
            if (addDo == true)
            {
                // 付箋オブジェクトを指定した名前で生成
                FusenData fdata = new FusenData(
                    lbSelName,
                    null);
                listBox1.Items.Add(fdata);
            }
        }
Example #6
0
        // 関数:全ての内容を一括出力する
        public void ExportAll()
        {
            // 現在開いているTextBoxの内容を記憶
            MemoryTextData();

            // 一括出力ダイアログを開く
            FormExport f = new FormExport();

            // オーナーウィンドウの真ん中に表示
            f.StartPosition = FormStartPosition.CenterParent;
            // オーナーウィンドウにthisを指定する
            f.ShowDialog(this);
            //フォームが必要なくなったところで、Disposeを呼び出す
            f.Dispose();

            /*
             * この間、リネームダイアログでの操作
             */

            // 一括出力"する"判定の場合のみ実行
            if (expDo == true)
            {
                //ファイル名に使用できない文字があるかチェック
                char[] invalidChars = Path.GetInvalidFileNameChars();

                for (int i = 0; i < listBox1.Items.Count; i++)
                {
                    string fileName = listBox1.Items[i].ToString();
                    if (fileName.IndexOfAny(invalidChars) >= 0)
                    {
                        MessageBox.Show("リスト内にファイル名に使用できない文字が使われています: " + fileName);
                        return;
                    }
                }

                // 全ての付箋オブジェクトのテキスト内容をテキストファイルに保存
                try
                {
                    for (int i = 0; i < listBox1.Items.Count; i++)
                    {
                        FusenData fdata = (FusenData)listBox1.Items[i];

                        // 2つのパスを結合する(フォルダパス末尾に"\"がある場合と無い場合に対処できる)
                        string mergePath = Path.Combine(expFld, listBox1.Items[i].ToString() + @".txt");

                        File.WriteAllText(
                            mergePath,
                            fdata.ftext,
                            ENCODE);
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("リスト名がファイル名に使用できない可能性があります");
                    MessageBox.Show("出力を中断します");
                    return;
                }

                MessageBox.Show("出力が完了しました");
            }
        }
Example #7
0
        // 起動時にまず実行する内容
        private void Form1_Load(object sender, EventArgs e)
        {
            // 設定パネルから直接Form1のコントロールの値を変更するための準備
            Form1.Form1Instance = this;

            // Form端をドラッグ&ドロップでサイズ変更可能にする
            sizeChanger = new DAndDSizeChanger(this, this, DAndDArea.All, 8);

            // TextBoxの内容が変化した時のイベントをここでOFFにする
            textBox1.TextChanged -= textBox1_TextChanged;

            // 前回終了時のウインドウ位置とサイズを取得する
            if (Properties.Settings.Default.FormSize.Width == 0 || Properties.Settings.Default.FormSize.Height == 0)
            {
                // 初回起動時にはデザイナーウインドウで指定されている大きさになる

                //既定値に戻す
                Properties.Settings.Default.Reset();
                // フォント周りの変数の初期化
                fstyLB = listBox1.Font;
                fcolLB = listBox1.ForeColor;
                fstyTB = textBox1.Font;
                fcolTB = textBox1.ForeColor;
                // パネルのアクセントカラーの初期化
                pcol1 = panelLabel1.BackColor;
                pcol2 = panelLabel2.BackColor;
                // 右端で折り返す設定を前回終了時の設定に復元
                wwrapDo = Properties.Settings.Default.wwrap;
                // オートセーブ周りの設定を前回終了時の設定に復元
                autoSaveDo     = Properties.Settings.Default.autoSave;
                deactiveSaveDo = Properties.Settings.Default.deactiveSave;
                autoSaveTickId = Properties.Settings.Default.autoSaveTId;
                autoSaveTick   = Properties.Settings.Default.autoSaveT;
            }
            else
            {
                // 前回終了時のウインドウ位置とサイズに復元
                this.Location = Properties.Settings.Default.FormLocation;
                this.Size     = Properties.Settings.Default.FormSize;

                // ListBoxとTextBoxのフォント設定を前回終了時の設定に復元
                this.listBox1.Font      = Properties.Settings.Default.listBoxFStyle;
                this.listBox1.ForeColor = Properties.Settings.Default.listBoxFColor;
                this.textBox1.Font      = Properties.Settings.Default.textBoxFStyle;
                this.textBox1.ForeColor = Properties.Settings.Default.textBoxFColor;
                // パネルのアクセントカラー設定を前回終了時の設定に復元
                this.panelLabel1.BackColor = Properties.Settings.Default.panelColor1;
                this.panelLabel2.BackColor = Properties.Settings.Default.panelColor2;
                this.panelLabel3.BackColor = Properties.Settings.Default.panelColor1;

                // フォント周りの変数の初期化
                fstyLB = listBox1.Font;
                fcolLB = listBox1.ForeColor;
                fstyTB = textBox1.Font;
                fcolTB = textBox1.ForeColor;
                // パネルのアクセントカラーの初期化
                pcol1 = panelLabel1.BackColor;
                pcol2 = panelLabel2.BackColor;

                // 右端で折り返す設定を前回終了時の設定に復元
                wwrapDo = Properties.Settings.Default.wwrap;
                // SplitContainerの分割する距離を前回終了時の設定に復元
                this.splitContainer1.SplitterDistance = Properties.Settings.Default.splitDist;
                // オートセーブ周りの設定を前回終了時の設定に復元
                autoSaveDo     = Properties.Settings.Default.autoSave;
                deactiveSaveDo = Properties.Settings.Default.deactiveSave;
                autoSaveTickId = Properties.Settings.Default.autoSaveTId;
                autoSaveTick   = Properties.Settings.Default.autoSaveT;

                if (autoSaveTick == 0)
                {
                    //既定値に戻す
                    Properties.Settings.Default.Reset();
                    // フォント周りの変数の初期化
                    fstyLB = listBox1.Font;
                    fcolLB = listBox1.ForeColor;
                    fstyTB = textBox1.Font;
                    fcolTB = textBox1.ForeColor;
                    // パネルのアクセントカラーの初期化
                    pcol1 = panelLabel1.BackColor;
                    pcol2 = panelLabel2.BackColor;
                    // 右端で折り返す設定を前回終了時の設定に復元
                    wwrapDo = Properties.Settings.Default.wwrap;
                    // オートセーブ周りの設定を前回終了時の設定に復元
                    autoSaveDo     = Properties.Settings.Default.autoSave;
                    deactiveSaveDo = Properties.Settings.Default.deactiveSave;
                    autoSaveTickId = Properties.Settings.Default.autoSaveTId;
                    autoSaveTick   = Properties.Settings.Default.autoSaveT;
                }
            }

            // 右端で折り返す設定を反映
            textBox1.WordWrap = wwrapDo;

            // テキストファイルの保存フォルダがある場合
            if (Directory.Exists(TEXTFLD))
            {
                // ListBoxのアイテム名を保存したファイルがある場合
                if (File.Exists(LISTDATA))
                {
                    // アイテム名を保持したテキストファイルを読み込む
                    StreamReader sr1 = new StreamReader(
                        LISTDATA,
                        ENCODE);
                    // 1行ずつListに格納
                    string line = "";
                    while ((line = sr1.ReadLine()) != null)
                    {
                        listAllName.Add(line);
                    }
                    sr1.Close();

                    // TextBoxに表示するテキストファイルをListに読み込む
                    for (int i = 0; i < listAllName.Count; i++)
                    {
                        StreamReader sr2 = new StreamReader(
                            TEXTFLD + @"/" + i.ToString() + @".txt",
                            ENCODE);
                        listAllText.Add(sr2.ReadToEnd());
                        sr2.Close();
                    }

                    // 読み込んだ内容をListBoxに追加
                    for (int i = 0; i < listAllName.Count; i++)
                    {
                        string ln = listAllName[i];
                        string td = listAllText[i];
                        // 付箋クラスのオブジェクトを生成
                        FusenData fdata = new FusenData(ln, td);
                        listBox1.Items.Add(fdata);
                    }
                }
                // ListBoxの項目を保存したファイルが無い場合
                else
                {
                    // ファイルを作成する
                    var sw = new StreamWriter(
                        LISTDATA,
                        false,
                        ENCODE);
                    sw.WriteLine(NEWTITLE);
                    sw.Close();

                    // ListBoxの新規アイテムを追加
                    ListAdd();
                }
            }
            // テキストファイルの保存フォルダが無い場合
            else
            {
                // フォルダを作成する
                DirectoryInfo di = Directory.CreateDirectory(TEXTFLD);

                // ファイルを作成する
                var sw = new StreamWriter(
                    LISTDATA,
                    false,
                    ENCODE);
                sw.WriteLine(NEWTITLE);
                sw.Close();

                // ListBoxの新規アイテムを追加
                ListAdd();
            }

            SelTop();                   // 先頭のアイテムを選択
            ShowTextData();             // 選択アイテムの中身をTextBoxに表示

            //カレット位置を末尾に移動
            textBox1.SelectionStart = 0;
            //テキストボックスにフォーカスを移動
            textBox1.Focus();
            //カレット位置までスクロール
            textBox1.ScrollToCaret();

            // ListBoxの選択Indexが変化した時のイベントをここでONにする
            listBox1.SelectedIndexChanged += listBox1_SelectedIndexChanged;

            // オートセーブ用のタイマーを開始
            timer          = new Timer();
            timer.Tick    += new EventHandler(doSave);
            timer.Interval = autoSaveTick;    // 実行間隔
            timer.Enabled  = true;            // timer.Start()と同じ
        }