Exemplo n.º 1
0
        private void AddNewShutickyWindow(ShutickySetting shutickySetting)
        {
            if (shutickySetting == null)
            {
                return;
            }

            //他の付箋と左上角の座標が重ならないように新規座標を計算
            //ただし、画面外に行ってしまわないように、
            var newPos = GetNewPositionTuple(shutickySetting.Position_X, shutickySetting.Position_Y);

            shutickySetting.Position_X = newPos.x;
            shutickySetting.Position_Y = newPos.y;

            var newShutickyWindow = new ShutickyWindow(shutickySetting);

            //イベントハンドラをセット
            AddEventHandlersToShutickyWindow(newShutickyWindow);
            //付箋ウィンドウのリストに登録
            _shutickyWindows.Add(newShutickyWindow);

            //セッティングファイルを書き込み
            WriteShutickySettingListXML(_shutickySettingFilePath);

            //RTFを作成。
            newShutickyWindow.SaveRTF();
        }
Exemplo n.º 2
0
        private void ContextMenuItem_New_Clicked(object sender, EventArgs e)
        {
            var newRtfPath         = Path.Combine(_shutickyNoteApplicationFolderPath, $"{GenerateNewTitle(_defaultShutickyName)}.rtf");
            var newShutickySetting = new ShutickySetting(newRtfPath);

            AddNewShutickyWindow(newShutickySetting);
        }
Exemplo n.º 3
0
        private void ShutickyWindowNewButtonClicked(object sender, EventArgs e)
        {
            var newRtfPath         = Path.Combine(_shutickyNoteApplicationFolderPath, $"{GenerateNewTitle(_defaultShutickyName)}.rtf");
            var newShutickySetting = new ShutickySetting(newRtfPath);

            //新規付箋ボタンが押されたWindowから少しずらした位置に表示させる
            var senderWindow  = sender as ShutickyWindow;
            var senderSetting = senderWindow.GetShutickySetting();

            newShutickySetting.Position_X = senderSetting.Position_X + _positionIncrementX;
            newShutickySetting.Position_Y = senderSetting.Position_Y + _positionIncrementY;

            AddNewShutickyWindow(newShutickySetting);
        }
Exemplo n.º 4
0
        private void ContextMenuItem_TrashedRtf_Clicked(object sender, EventArgs e)
        {
            var senderContextMenu  = (System.Windows.Forms.ToolStripMenuItem)sender;
            var trashedRtfFileName = $"{senderContextMenu.Text}.rtf";
            var trashedRtfFilePath = Path.Combine(_shutickyTrashcanFolderPath, trashedRtfFileName);
            var rtfFileName        = $"{GenerateNewTitle(senderContextMenu.Text)}.rtf";
            var rtfFilePath        = Path.Combine(_shutickyNoteApplicationFolderPath, rtfFileName);

            File.Move(trashedRtfFilePath, rtfFilePath);//アプリのゴミ箱からRTFを戻す。
            //そして開く。
            var shutickySetting = new ShutickySetting(rtfFilePath);

            AddNewShutickyWindow(shutickySetting);

            //コンテキストメニューから削除する。
            _notifyIcon.toolStripMenuItem_Trash.DropDownItems.Remove(senderContextMenu);
        }
Exemplo n.º 5
0
        public ShutickyWindow(ShutickySetting shutickySetting)
        {
            InitializeComponent();

            _shutickySetting = shutickySetting;

            LoadRTF(_shutickySetting.FilePath);

            this.textBox_Title.Text = _shutickySetting.Title;
            this.Title  = this.textBox_Title.Text;//こちらはWindowコントロールのタイトル。
            this.Height = _shutickySetting.Size_Height;
            this.Width  = _shutickySetting.Size_Width;
            this.Top    = _shutickySetting.Position_Y;
            this.Left   = _shutickySetting.Position_X;

            SetPinStatus(_shutickySetting.IsPinned);
            SetShutickyColor(_shutickySetting.ColorNumber);

            SetDisplayStatus(_shutickySetting.DisplayStatus);

            this.Reminders = ExtractRemindDatas();
        }
Exemplo n.º 6
0
        private void AddExistShutickyWindow(ShutickySetting shutickySetting)
        {
            if (shutickySetting == null)
            {
                return;
            }

            //付箋が画面外にある場合は現在のウィンドウ内に収まるように調整
            var newPos = AdjustWindowPositionTuple(shutickySetting.Position_X, shutickySetting.Position_Y);

            shutickySetting.Position_X = newPos.x;
            shutickySetting.Position_Y = newPos.y;

            //付箋ウィンドウをインスタンス化
            var shutickyWindow = new ShutickyWindow(shutickySetting);

            //イベントハンドラを登録
            AddEventHandlersToShutickyWindow(shutickyWindow);
            //付箋ウィンドウのリストに登録
            _shutickyWindows.Add(shutickyWindow);

            //セッティングファイルを書き込み
            WriteShutickySettingListXML(_shutickySettingFilePath);
        }
Exemplo n.º 7
0
        protected override void OnStartup(StartupEventArgs e)
        {
            //二重起動防止
            _mutex = new Mutex(false, _applicationName);
            if (!_mutex.WaitOne(0, false))
            {
                //既に起動しているため、終了させる
                _mutex.Close();
                _mutex = null;
                this.Shutdown();
            }

            base.OnStartup(e);

            this.ShutdownMode = ShutdownMode.OnExplicitShutdown;
            this._notifyIcon  = new NotifyIconWrapper();
            this._notifyIcon.ContextMenuItem_Exit_Clicked        += ContextMenuItem_Exit_Clicked;
            this._notifyIcon.ContextMenuItem_New_Clicked         += ContextMenuItem_New_Clicked;
            this._notifyIcon.ContextMenuItem_ShowAll_Clicked     += ContextMenuItem_ShowAll_Clicked;
            this._notifyIcon.ContextMenuItem_MinimizeAll_Clicked += ContextMenuItem_MinimizeAll_Clicked;
            this._notifyIcon.ContextMenuItem_Help_Clicked        += ContextMenuItem_Help_Clicked;
            this._notifyIcon.ContextMenuItem_ClearTrash_Clicked  += ContextMenuItem_ClearTrash_Clicked;

            //インストール先のフォルダにヘルプファイル(html)を配置する
            var asm              = Assembly.GetEntryAssembly();
            var appExeFilePath   = asm.Location;
            var appExeFolderPath = Path.GetDirectoryName(appExeFilePath);

            _helpFilePath = Path.Combine(appExeFolderPath, "help.html");
            File.WriteAllText(_helpFilePath, Shuticky.Properties.Resources.Help);


            //アプリケーション用のフォルダを作成
            try
            {
                //OneDriveのフォルダのパスを取得
                string userRoot = "HKEY_CURRENT_USER";
                string subkey   = @"Software\Microsoft\OneDrive";
                string keyName  = Path.Combine(userRoot, subkey);

                //OneDriveフォルダのパスを取得
                string oneDrivePath = (string)Microsoft.Win32.Registry.GetValue(keyName, "UserFolder", "Return this default if NoSuchName does not exist.");

                //Shuticky用のフォルダを作成。
                if (string.IsNullOrEmpty(oneDrivePath) == false)
                {
                    _shutickyNoteApplicationFolderPath = Path.Combine(oneDrivePath, _onedriveCommonApplicationFolderName, _applicationName);
                }
            }
            catch (Exception)
            {
                //OneDriveフォルダにフォルダを作成できなかった場合、マイドキュメントにフォルダを作る。
                _shutickyNoteApplicationFolderPath = Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.Personal), _applicationName);
            }
            finally
            {
                //Shuticky用のフォルダを作成。
                Directory.CreateDirectory(_shutickyNoteApplicationFolderPath);

                //アプリ用のゴミ箱フォルダを作成
                _shutickyTrashcanFolderPath = Path.Combine(_shutickyNoteApplicationFolderPath, _appTrashcanFolderName);
                Directory.CreateDirectory(_shutickyTrashcanFolderPath);
            }

            //設定ファイルのパスを取得
            _shutickySettingFilePath = Path.Combine(_shutickyNoteApplicationFolderPath, _shutickySettingFileName);

            //設定ファイルを読み込む
            //なければ初期化
            List <ShutickySetting> shutickySettings = null;

            try
            {
                if (File.Exists(_shutickySettingFilePath))
                {
                    //RTFファイルが存在するもののみに絞って。
                    shutickySettings = this.ReadShutickySettingListXML(_shutickySettingFilePath).Where(x => File.Exists(x.FilePath)).ToList();
                }
                else
                {
                    shutickySettings = new List <ShutickySetting>();
                }
            }
            catch
            {
                shutickySettings = new List <ShutickySetting>();
            }


            //RTFファイルのみがフォルダ内に置かれた場合、
            //それらが読み込まれるようにする
            //付箋データファイル(つまりrtfファイル)のパスの一覧を取得
            //ただし、セッティングリストには記載されていないファイルのみを取得
            var newRtfFilePathList = Directory.GetFiles(_shutickyNoteApplicationFolderPath, "*.rtf", SearchOption.TopDirectoryOnly)
                                     .Where(rtfPath => shutickySettings.FindIndex(setting => setting.FilePath == rtfPath) == -1)
                                     .ToList();

            foreach (var rtfPath in newRtfFilePathList)
            {
                try
                {
                    var shutickySetting = new ShutickySetting(rtfPath);

                    shutickySettings.Add(shutickySetting);
                }
                catch
                {
                    continue;
                }
            }

            //TODO:
            //アプリのゴミ箱(Trashフォルダ)内のRTFファイルのリストを作成
            //コンテキストメニューのゴミ箱項目内に追加する
            var trashedRtfFilePaths = Directory.GetFiles(_shutickyTrashcanFolderPath, "*.rtf", SearchOption.TopDirectoryOnly);

            foreach (var trashedRtfFilePath in trashedRtfFilePaths)
            {
                var trashedShutickyTitle = Path.GetFileNameWithoutExtension(trashedRtfFilePath);
                AddContextMenuItem_Trash(trashedShutickyTitle);
            }

            //付箋ウィンドウの生成
            if (shutickySettings.Count > 0)//既存の付箋が1つ以上あった場合。すでにある付箋を開く。
            {
                foreach (var shutickySetting in shutickySettings)
                {
                    try
                    {
                        //既存の付箋の表示
                        AddExistShutickyWindow(shutickySetting);
                    }
                    catch
                    {
                        continue;
                    }
                }
            }
            else//なければ空の付箋ウィンドウを開く
            {
                var newRtfPath         = Path.Combine(_shutickyNoteApplicationFolderPath, $"{GenerateNewTitle(_defaultShutickyName)}.rtf");
                var newShutickySetting = new ShutickySetting(newRtfPath);
                AddNewShutickyWindow(newShutickySetting);
            }



            ////すべてのリマインダを表示
            //ShowAllReminder();

            ////リマインダータイマーをスタート
            //_remindTimer = new DispatcherTimer();
            //_remindTimer.Interval = TimeSpan.FromMinutes(1);
            //_remindTimer.Tick += RemindTimer_Tick;
            //_remindTimer.Start();
        }