/* * Greenshot - a free and open source screenshot tool * Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom * * For more information see: http://getgreenshot.org/ * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 1 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ using System; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Windows; using System.Windows.Controls; namespace GreenshotConfluencePlugin { /// /// Interaction logic for ConfluenceUpload.xaml /// public partial class ConfluenceUpload : Window { private Page _pickerPage; public Page PickerPage { get { if (_pickerPage == null) { List pages = ConfluenceUtils.GetCurrentPages(); if (pages != null && pages.Count > 0) { _pickerPage = new ConfluencePagePicker(this, pages); } } return _pickerPage; } } private Page _searchPage; public Page SearchPage { get { return _searchPage ??= new ConfluenceSearch(this); } } private Page _browsePage; public Page BrowsePage { get { return _browsePage ??= new ConfluenceTreePicker(this); } } private Confluence.Page _selectedPage; public Confluence.Page SelectedPage { get { return _selectedPage; } set { _selectedPage = value; Upload.IsEnabled = _selectedPage != null; IsOpenPageSelected = false; } } public bool IsOpenPageSelected { get; set; } public string Filename { get; set; } private static DateTime _lastLoad = DateTime.Now; private static IList _spaces; public IList Spaces { get { UpdateSpaces(); while (_spaces == null) { Thread.Sleep(300); } return _spaces; } } public ConfluenceUpload(string filename) { Filename = filename; InitializeComponent(); DataContext = this; UpdateSpaces(); if (PickerPage == null) { PickerTab.Visibility = Visibility.Collapsed; SearchTab.IsSelected = true; } } private void UpdateSpaces() { if (_spaces != null && DateTime.Now.AddMinutes(-60).CompareTo(_lastLoad) > 0) { // Reset _spaces = null; } // Check if load is needed if (_spaces == null) { (new Thread(() => { _spaces = ConfluencePlugin.ConfluenceConnector.GetSpaceSummaries().OrderBy(s => s.Name).ToList(); _lastLoad = DateTime.Now; }) { Name = "Loading spaces for confluence"}).Start(); } } private void Upload_Click(object sender, RoutedEventArgs e) { DialogResult = true; } } }