Пример #1
0
        /// <summary>
        /// Loads gists with progress info
        /// </summary>
        /// <param name="loadOrSaveWindow"></param>
        public void LoadGists(dynamic loadOrSaveWindow)
        {
            ObservableCollection <GistItem> gists;

            if (string.IsNullOrEmpty(GistUsername))
            {
                GistList = new ObservableCollection <GistItem>();
                return;
            }

            dynamic window = loadOrSaveWindow;

            window.ShowStatus("Retrieving Gists from Github...");

            gists = new ObservableCollection <GistItem>(GistClient.ListGistsForUser(GistUsername,
                                                                                    Configuration.GithubUserToken));
            if (gists == null || gists.Count < 1 || gists[0].hasError)
            {
                window.SetStatusIcon(FontAwesomeIcon.Warning, Colors.Orange);
                window.ShowStatus("Failed to retrieve Gists from Github...", 7000);
                return;
            }
            window.ShowStatus("Retrieved Gists from Github.", 5000);

            foreach (var gist in gists)
            {
                if (string.IsNullOrEmpty(gist.description))
                {
                    gist.description = System.IO.Path.GetFileNameWithoutExtension(gist.filename);
                }
            }

            GistList   = gists;
            ActiveItem = gists[0];
        }
Пример #2
0
        private void ButtonDeleteGist_Click(object sender, RoutedEventArgs e)
        {
            var gist = ((Button)sender).DataContext as GistItem;

            if (gist == null)
            {
                return;
            }

            var msg =
                $@"Filename: {gist.filename}
Description: {gist.description}

Are you sure you want to delete this Gist?";

            var res = MessageBox.Show(msg, "Delete Gist", MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (res == MessageBoxResult.No)
            {
                return;
            }

            if (!GistClient.DeleteGist(gist.id))
            {
                ShowStatus("Failed to delete Gist.", 7000);
                SetStatusIcon(FontAwesomeIcon.Warning, Colors.Red);
            }
            else
            {
                Model.GistList.Remove(gist);
                ShowStatus("Gist Deleted.", 7000);
            }
        }
Пример #3
0
        private void ButtonSaveGist_Click(object sender, RoutedEventArgs e)
        {
            Model.ActiveItem.code = Addin.GetMarkdown();

            GistItem gist;

            ShowStatus("Saving Gist...");
            if (!Model.SaveAsNewGist)
            {
                gist = GistClient.UpdateGist(Model.ActiveItem, Model.Configuration.GithubUserToken);
            }
            else
            {
                gist = GistClient.PostGist(Model.ActiveItem, Model.Configuration.GithubUserToken);
            }

            if (gist != null && !gist.hasError)
            {
                ShowStatus("Gist has been saved...", 5000);
                mmFileUtils.ShowExternalBrowser(gist.htmlUrl);
                Close();
            }
            else
            {
                SetStatusIcon(FontAwesomeIcon.Warning, Colors.Orange);
                ShowStatus("Gist was not saved - failed to save as Gist.", 7000);
            }
        }
Пример #4
0
        private void ButtonOpen_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(Model.ActiveItem.id))
            {
                return;
            }

            ShowStatus("Retrieving Gist from Github...");
            var gist = GistClient.GetGistFromServer(Model.ActiveItem.id, Model.Configuration.GithubUserToken);

            if (gist == null || gist.hasError)
            {
                SetStatusIcon(FontAwesomeIcon.Warning, Colors.Orange);
                ShowStatus("Failed to retrieve Gists from Github...", 7000);
                return;
            }
            ShowStatus("Gists retrieved.", 7000);


            var filename = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "Gist_" + gist.id + "_" + gist.filename);

            File.WriteAllText(filename, gist.code, Encoding.UTF8);
            Addin.OpenTab(filename);
            Close();
        }
        private void ButtonSaveGist_Click(object sender, RoutedEventArgs e)
        {
            Model.ActiveItem.code = Addin.GetMarkdown();

            GistItem gist;

            ShowStatus("Saving Gist...");
            if (!Model.SaveAsNewGist)
            {
                gist = GistClient.UpdateGist(Model.ActiveItem, Model.Configuration.GithubUserToken);
            }
            else
            {
                gist = GistClient.PostGist(Model.ActiveItem, Model.Configuration.GithubUserToken);
            }

            if (gist != null && !gist.hasError)
            {
                ShowStatus("Gist has been saved...", 5000);
                mmFileUtils.ShowExternalBrowser(gist.htmlUrl);
                Close();
            }
            else
            {
                mmApp.Log(gist.errorMessage);

                SetStatusIcon(FontAwesomeIcon.ExclamationCircle, Colors.Firebrick);
                ShowStatus("Failed to save as Gist. Refer to error log for more detail.", 7000);
            }
        }
        /// <summary>
        /// Loads gists with progress info
        /// </summary>
        /// <param name="loadOrSaveWindow"></param>
        public async Task LoadGists(dynamic loadOrSaveWindow)
        {
            ObservableCollection <GistItem> gists;

            if (string.IsNullOrEmpty(GistUsername))
            {
                GistList = new ObservableCollection <GistItem>();
                return;
            }

            dynamic window = loadOrSaveWindow;

            window.Status.ShowStatusProgress("Retrieving Gists from Github...");

            gists = new ObservableCollection <GistItem>(await GistClient.ListGistsForUserAsync(GistUsername,
                                                                                               Configuration.GithubUserToken));

            if (gists == null || gists.Count < 1 || gists[0].hasError)
            {
                window.Status.ShowStatusError("Failed to retrieve Gists from Github...");
                return;
            }
            window.Status.ShowStatusSuccess($"Retrieved {gists.Count} Gists from Github for {GistUsername}.");

            foreach (var gist in gists)
            {
                if (string.IsNullOrEmpty(gist.description))
                {
                    gist.description = System.IO.Path.GetFileNameWithoutExtension(gist.filename);
                }
            }

            GistList   = gists;
            ActiveItem = gists[0];
        }