示例#1
0
        private void MenuSaveClick(object sender, EventArgs e)
        {
            // let's first make sure the document content has changed
            var currentTab = tabs.SelectedTab as Noc;

            if (currentTab == null || (!currentTab.Document.IsDraft && !currentTab.ContentHasChanged))
            {
                return;
            }

            // let's stop here if we're already saving the current tab
            if (currentTab.SaveWorkerIsBusy())
            {
                return;
            }

            // make sure we are authenticated
            if (!NocsService.UserIsAuthenticated())
            {
                // user's not authenticated, let's ask for credentials to retrieve items
                var login = new Login();
                if (login.ShowDialog() == DialogResult.OK)
                {
                    RetrieveDocuments();
                }
                return;
            }

            // if current file is not new, let's just save it
            if (!currentTab.Document.IsDraft)
            {
                Status(StatusType.Save, "Saving...");
                currentTab.Save();
            }
            else
            {
                // ask for a name
                var saveResponse = SaveDialog.SaveDialogBox("Enter a name for your file:", "Save", "Untitled");

                if (!string.IsNullOrEmpty(saveResponse.DocumentName))
                {
                    Status(StatusType.Save, "Saving...");
                    currentTab.SaveAs(saveResponse);
                }
            }
        }
示例#2
0
        public static SaveDialogResponse SaveDialogBox(string prompt, string title, string defaultInput)
        {
            // we'll create a new instance of the class and set the given arguments as properties
            var ib = new SaveDialog
            {
                FormPrompt   = prompt,
                FormCaption  = title,
                DefaultValue = defaultInput
            };

            // show the actual dialog
            ib.ShowDialog();

            // retrieve the response string, close the dialog and return the string
            var response = ib.Response;

            ib.Close();
            return(response);
        }
示例#3
0
        private void MenuGoogleAccountClick(object sender, EventArgs e)
        {
            // let's first stop all processing
            _synchronizer.Stop();
            _autoFetchAllEntriesTimer.Stop();

            // let's then find out if any of the open tabs are unsaved
            foreach (Noc tab in tabs.TabPages)
            {
                if (tab.ContentHasChanged && NocsService.UserIsAuthenticated())
                {
                    // display a msg asking the user to save changes or abort
                    var result = MessageBox.Show("Do you want to save the changes to " + tab.Text + "?", "Nocs", MessageBoxButtons.YesNoCancel);

                    if (result == DialogResult.Yes)
                    {
                        // let's stop here if we're already saving the current tab
                        if (tab.SaveWorkerIsBusy())
                        {
                            // re-enable all processing
                            _synchronizer.Start();
                            _autoFetchAllEntriesTimer.Start();
                            return;
                        }

                        // if current file is not new, let's just save it
                        if (!tab.Document.IsDraft)
                        {
                            Status(StatusType.Save, "Saving...");
                            tab.Save();
                        }
                        else
                        {
                            // ask for a name
                            var saveResponse = SaveDialog.SaveDialogBox("Enter a name for your file:", "Save", "Untitled");

                            if (!string.IsNullOrEmpty(saveResponse.DocumentName))
                            {
                                Status(StatusType.Save, "Saving...");
                                tab.SaveAs(saveResponse);
                            }
                        }

                        // re-enable all processing
                        _synchronizer.Start();
                        _autoFetchAllEntriesTimer.Start();
                        return;
                    }

                    if (result == DialogResult.Cancel)
                    {
                        // re-enable all processing
                        _synchronizer.Start();
                        _autoFetchAllEntriesTimer.Start();
                        return;
                    }
                }
            }

            // we're past saving questions, let's show the Login dialog for changing Google account
            var login = new Login();

            login.ShowDialog();

            // let's check if user account was changed once the login window is closed
            if (NocsService.AccountChanged)
            {
                // inform the new user that we are retrieving items
                Status(StatusType.Retrieve, "Synchronizing with Google Docs...");

                // disable menu options for changing google account and opening documents while items are being retrieved
                menuGoogleAccount.Enabled = false;
                menuBrowse.Enabled        = false;
                menuSave.Enabled          = false;

                // reset helping variable
                NocsService.AccountChanged = false;

                // let's reset titlebar, clear tabs, etc.
                SetMainTitle(string.Empty);
                tabs.TabPages.Clear();

                // let's clear synchronizer queues
                _synchronizer.JobQueue.Clear();
                _synchronizer.ErrorQueue.Clear();

                // let's then create a new tab (Noc)
                AddNoc();

                // and finally let's run the backgroundworker to retrieve new items for this account
                BgWorkerGetAllItems.RunWorkerAsync(false);
            }

            // either way, let's re-enable timers
            _synchronizer.Start();
            _autoFetchAllEntriesTimer.Start();
        }
示例#4
0
文件: SaveDialog.cs 项目: mikkoj/nocs
        public static SaveDialogResponse SaveDialogBox(string prompt, string title, string defaultInput)
        {
            // we'll create a new instance of the class and set the given arguments as properties
            var ib = new SaveDialog
            {
                FormPrompt = prompt,
                FormCaption = title,
                DefaultValue = defaultInput
            };

            // show the actual dialog
            ib.ShowDialog();

            // retrieve the response string, close the dialog and return the string
            var response = ib.Response;
            ib.Close();
            return response;
        }
示例#5
0
        /// <summary>
        /// Closes a tab with a given index.
        /// </summary>
        /// <param name="tabIndex">Index for the tab to be closed</param>
        private void CloseTab(int tabIndex)
        {
            // let's makes sure the index is valid
            if (tabIndex < 0 || tabIndex > (tabs.TabCount - 1))
            {
                return;
            }

            var tabToBeClosed = tabs.TabPages[tabIndex] as Noc;

            if (tabToBeClosed != null && tabToBeClosed.ContentHasChanged && NocsService.UserIsAuthenticated())
            {
                // let's first stop all processing
                _synchronizer.Stop();
                _autoFetchAllEntriesTimer.Stop();

                var result = MessageBox.Show("Do you want to save the changes to " + tabToBeClosed.Text + "?", "Nocs", MessageBoxButtons.YesNoCancel);

                // display a msg asking the user to save changes or abort
                if (result == DialogResult.Yes)
                {
                    // let's stop here if we're already saving the current tab
                    if (tabToBeClosed.SaveWorkerIsBusy())
                    {
                        // re-enable all processing
                        _synchronizer.Start();
                        _autoFetchAllEntriesTimer.Start();
                        return;
                    }

                    // if current file is not new, let's just save it
                    if (!tabToBeClosed.Document.IsDraft)
                    {
                        Status(StatusType.Save, "Saving...");
                        tabToBeClosed.Save();
                    }
                    else
                    {
                        // ask for a name
                        var saveResponse = SaveDialog.SaveDialogBox("Enter a name for your file:", "Save", "Untitled");

                        if (!string.IsNullOrEmpty(saveResponse.DocumentName))
                        {
                            Status(StatusType.Save, "Saving...");
                            tabToBeClosed.SaveAs(saveResponse);
                        }
                    }

                    // re-enable all processing
                    _synchronizer.Start();
                    _autoFetchAllEntriesTimer.Start();
                    return;
                }

                if (result == DialogResult.Cancel)
                {
                    // re-enable all processing
                    _synchronizer.Start();
                    _autoFetchAllEntriesTimer.Start();
                    return;
                }
            }

            // if selected tab will be removed, let's jump to the one on its left
            var selectedRemoved  = false;
            var newSelectedIndex = 0;

            if (tabIndex == tabs.SelectedIndex)
            {
                selectedRemoved  = true;
                newSelectedIndex = tabIndex - 1;
                if (newSelectedIndex < 0)
                {
                    newSelectedIndex = 0;
                }
            }

            // let's handle the selection changes
            if (selectedRemoved)
            {
                tabs.SelectedIndex = newSelectedIndex;
            }

            // let's get the TabPage for dispose/deactivation purposes
            var tab = tabs.TabPages[tabIndex] as Noc;

            // if get here, we can remove the tab
            tabs.TabPages.RemoveAt(tabIndex);

            // let's handle disposing
            if (tab != null)
            {
                tab.Deactivate();
                SettingsChanged -= tab.SettingsChanged;
                tab.Dispose();
            }

            // if no more tabs left, let's reset the title to "Nocs" and disable saving to file
            if (tabs.TabPages.Count == 0)
            {
                SetMainTitle(string.Empty);
                lblCaretPosition.Text  = string.Empty;
                menuSaveFileAs.Enabled = false;
            }
        }
示例#6
0
        private void MainFormClosing(object sender, FormClosingEventArgs e)
        {
            // for pinned documents
            var pinnedDocuments = new List <string>();

            // let's first find out if any of the open tabs are unsaved
            foreach (Noc tab in tabs.TabPages)
            {
                // let's also collect potential pinned documents
                if (tab.Pinned)
                {
                    pinnedDocuments.Add(tab.Document.ResourceId);
                }

                if (tab.ContentHasChanged && NocsService.UserIsAuthenticated())
                {
                    // let's first stop all processing
                    if (!_synchronizer.SyncStopped || _autoFetchAllEntriesTimer.Enabled)
                    {
                        _synchronizer.Stop();
                        _autoFetchAllEntriesTimer.Stop();
                    }

                    // ..and display a msg asking the user to save changes or abort
                    var result = MessageBox.Show("Do you want to save the changes to " + tab.Text + "?", "Nocs", MessageBoxButtons.YesNoCancel);

                    if (result == DialogResult.Yes)
                    {
                        // let's cancel the FormClosing-event
                        e.Cancel = true;

                        // let's stop here if we're already saving the current tab
                        if (tab.SaveWorkerIsBusy())
                        {
                            // re-enable all processing and exit
                            _synchronizer.Start();
                            _autoFetchAllEntriesTimer.Start();
                            return;
                        }

                        // if current file is not new, let's just save it
                        if (!tab.Document.IsDraft)
                        {
                            Status(StatusType.Save, "Saving...");
                            tab.Save();
                        }
                        else
                        {
                            // ask for a name
                            var saveResponse = SaveDialog.SaveDialogBox("Enter a name for your file:", "Save", "Untitled");

                            if (!string.IsNullOrEmpty(saveResponse.DocumentName))
                            {
                                Status(StatusType.Save, "Saving...");
                                tab.SaveAs(saveResponse);
                            }
                        }

                        // re-enable all processing and exit
                        _synchronizer.Start();
                        _autoFetchAllEntriesTimer.Start();
                        return;
                    }

                    if (result == DialogResult.Cancel)
                    {
                        e.Cancel = true;
                        // re-enable all processing
                        _synchronizer.Start();
                        _autoFetchAllEntriesTimer.Start();
                        return;
                    }
                }
            }

            // save all current settings just before closing application
            Settings.Default.WindowLocation = Location;
            Settings.Default.WindowSize     = WindowState == FormWindowState.Normal ? Size : RestoreBounds.Size;

            // let's also save pinned documents
            if (pinnedDocuments.Any())
            {
                var pinnedDocumentsJoined = String.Join(";", pinnedDocuments.Where(s => !string.IsNullOrEmpty(s)));
                Settings.Default.PinnedDocuments = pinnedDocumentsJoined;
            }
            else
            {
                Settings.Default.PinnedDocuments = string.Empty;
            }

            Settings.Default.Save();

            // let's flush the trace content to the file
            Trace.Flush();
        }
示例#7
0
文件: Main.cs 项目: mikkoj/nocs
        private void MenuSaveAsClick(object sender, EventArgs e)
        {
            // let's first make sure the document content has changed
            var currentTab = tabs.SelectedTab as Noc;
            if (currentTab == null)
            {
                return;
            }

            // let's stop here if we're already saving the current tab
            if (currentTab.SaveWorkerIsBusy())
            {
                return;
            }

            // make sure we are authenticated
            if (!NocsService.UserIsAuthenticated())
            {
                // user's not authenticated, let's ask for credentials to retrieve items
                var login = new Login();
                if (login.ShowDialog() == DialogResult.OK)
                {
                    RetrieveDocuments();
                }
                return;
            }

            // ask for a name
            var inputName = new SaveDialog();
            var saveResponse = SaveDialog.SaveDialogBox("Enter a name for your file:", "Save", "Untitled");

            if (!string.IsNullOrEmpty(saveResponse.DocumentName))
            {
                Status(StatusType.Save, "Saving...");
                currentTab.SaveAs(saveResponse);
            }
        }