Esempio n. 1
0
        private void ReloadMultimediaPanel(List <MultimediaLink> data)
        {
            JobExecutor.QueueJob(() => {
                _model = new ObservableCollection <MultimediaLinkViewModel>(data.ConvertAll((item) => {
                    MultimediaLinkViewModel viewmodel = null;
                    this.InvokeIfRequired(() => {
                        viewmodel              = new MultimediaLinkViewModel(item);
                        viewmodel.DataChanged += new DataChangedHandler((m) => {
                            RegisterUniquePendingChange(new UpdateMultimediaLinkCommand(viewmodel.Model, CategoryType));
                        });
                    });
                    return(viewmodel);
                }));
                this.InvokeIfRequired(() => {
                    this.thumbList.ItemsSource = _model;
                });

                foreach (MultimediaLinkViewModel item in _model)
                {
                    this.BackgroundInvoke(() => {
                        GenerateThumbnail(item, THUMB_SIZE);
                    });
                }
            });
        }
Esempio n. 2
0
 private void ShowLinkedItems(MultimediaLinkViewModel selected)
 {
     if (selected != null)
     {
         selected.Icon = GraphicsUtils.GenerateThumbnail(selected.TempFilename, 48);
         PluginManager.Instance.AddNonDockableContent(Plugin, new LinkedMultimediaItemsControl(selected), "Items linked to multimedia " + selected.MultimediaID, SizeToContent.Manual);
     }
 }
        public LinkedMultimediaItemsControl(MultimediaLinkViewModel viewModel)
        {
            InitializeComponent();
            this.DataContext = viewModel;

            this.MultimediaID = viewModel.MultimediaID;
            var service = new SupportService(User);

            var mm = service.GetMultimedia(MultimediaID);

            var items = service.ListItemsLinkedToMultimedia(MultimediaID);
            var model = new ObservableCollection <ViewModelBase>();

            foreach (MultimediaLinkedItem item in items)
            {
                if (!string.IsNullOrWhiteSpace(item.CategoryName))
                {
                    LookupType t;
                    if (Enum.TryParse <LookupType>(item.CategoryName, out t))
                    {
                        var vm = PluginManager.Instance.GetViewModel(t, item.IntraCatID);
                        if (vm != null)
                        {
                            model.Add(vm);
                            vm.Tag = t;
                        }
                    }
                }
            }

            lvw.MouseRightButtonUp += new MouseButtonEventHandler(lvw_MouseRightButtonUp);

            ListViewDragHelper.Bind(lvw, (dragged) => {
                if (dragged.Tag is LookupType)
                {
                    var lookupType = (LookupType)dragged.Tag;
                    var plugin     = PluginManager.Instance.GetLookupTypeOwner(lookupType);

                    if (plugin != null)
                    {
                        var data     = new DataObject("Pinnable", dragged);
                        var pinnable = new PinnableObject(plugin.Name, lookupType, dragged.ObjectID.Value);
                        data.SetData(PinnableObject.DRAG_FORMAT_NAME, pinnable);
                        data.SetData(DataFormats.Text, dragged.DisplayLabel);
                        return(data);
                    }
                }
                return(null);
            });

            lvw.ItemsSource = model;
            CollectionView myView = (CollectionView)CollectionViewSource.GetDefaultView(lvw.ItemsSource);

            myView.SortDescriptions.Add(new SortDescription("Tag", ListSortDirection.Ascending));
            myView.SortDescriptions.Add(new SortDescription("DisplayLabel", ListSortDirection.Ascending));

            myView.GroupDescriptions.Add(new LinkedItemGroupDescription());
        }
Esempio n. 4
0
        private void GenerateThumbnail(MultimediaLinkViewModel item, int maxDimension)
        {
            string filename = _tempFileManager.GetContentFileName(item.MultimediaID, item.Extension);

            item.TempFilename = filename;
            this.InvokeIfRequired(() => {
                item.Thumbnail = GraphicsUtils.GenerateThumbnail(filename, maxDimension);
            });
        }
Esempio n. 5
0
        private void SaveAs(MultimediaLinkViewModel selected)
        {
            var dlg      = new Microsoft.Win32.SaveFileDialog();
            var filename = string.Format("{0}.{1}", selected.Name, selected.Extension);

            dlg.FileName = filename;
            if (dlg.ShowDialog() == true)
            {
                var srcFile = _tempFileManager.GetContentFileName(selected.MultimediaID, selected.Extension);
                File.Copy(srcFile, dlg.FileName);
                InfoBox.Show("Item has been saved to " + dlg.FileName, "File saved", this);
            }
        }
Esempio n. 6
0
 private void AddNewLinkFromExternalLink(MultimediaLink externalLink)
 {
     if (externalLink != null)
     {
         // Link to existing multimedia
         var model = new MultimediaLink();
         model.MultimediaID     = externalLink.MultimediaID;
         model.MultimediaLinkID = NewLinkID();
         model.Name             = externalLink.Name;
         model.Extension        = externalLink.Extension;
         var viewModel = new MultimediaLinkViewModel(model);
         GenerateThumbnail(viewModel, THUMB_SIZE);
         _model.Add(viewModel);
         RegisterPendingChange(new InsertMultimediaLinkCommand(model, CategoryType, Owner));
     }
 }
Esempio n. 7
0
        private void ShowMultimediaProperties(MultimediaLinkViewModel selected)
        {
            if (selected == null)
            {
                return;
            }
            if (selected.MultimediaID < 0)
            {
                ErrorMessage.Show("You must first apply the changes before editing the details of this item!");
                return;
            }
            var service = new SupportService(User);
            var model   = service.GetMultimedia(selected.MultimediaID);

            if (model != null)
            {
                var detailsControl = new MultimediaDetails(model, User);
                PluginManager.Instance.AddNonDockableContent(Plugin, detailsControl, string.Format("Multimedia details [{0}]", model.MultimediaID), SizeToContent.Manual);
            }
        }
 private void DisplayMultimedia(MultimediaLinkViewModel selected)
 {
     if (selected != null)
     {
         JobExecutor.QueueJob(() => {
             string filename = _tempFileManager.GetContentFileName(selected.MultimediaID, selected.Extension);
             var image       = GraphicsUtils.LoadImageFromFile(filename);
             imgPreview.InvokeIfRequired(() => {
                 imgPreview.Stretch          = Stretch.Uniform;
                 imgPreview.StretchDirection = StretchDirection.DownOnly;
                 imgPreview.Source           = image;
                 gridInfo.DataContext        = image;
                 FileInfo f           = new FileInfo(filename);
                 lblImageInfo.Content = string.Format("{0}x{1}  {2} DPI  {3}", image.PixelWidth, image.PixelHeight, image.DpiX, ByteLengthConverter.FormatBytes(f.Length));
             });
         });
     }
     else
     {
         imgPreview.Source    = null;
         lblImageInfo.Content = "";
     }
 }
 public MultimediaLinkTooltip(MultimediaLinkViewModel viewModel) : base(viewModel.ObjectID.Value, viewModel)
 {
 }
Esempio n. 10
0
        private void AddMultimediaFromFile(string filename)
        {
            if (IsReadOnly)
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(filename))
            {
                return;
            }

            FileInfo finfo = new FileInfo(filename);

            if (finfo.Exists)
            {
                MultimediaLink          model     = null;
                MultimediaLinkViewModel viewModel = null;
                Multimedia duplicate = null;
                var        action    = CheckDuplicate(finfo, out duplicate);
                switch (action)
                {
                case MultimediaDuplicateAction.Cancel:
                    // Do nothing
                    break;

                case MultimediaDuplicateAction.NoDuplicate:
                case MultimediaDuplicateAction.InsertDuplicate:
                    // Insert new multimedia and new link
                    model = new MultimediaLink();
                    model.MultimediaID     = NextNewId();
                    model.MultimediaLinkID = model.MultimediaID;
                    if (finfo.Name.Contains("."))
                    {
                        model.Name      = finfo.Name.Substring(0, finfo.Name.LastIndexOf("."));
                        model.Extension = finfo.Extension.Substring(1);
                    }
                    else
                    {
                        model.Name = finfo.Name;
                    }
                    model.SizeInBytes = (int)finfo.Length;

                    viewModel           = new MultimediaLinkViewModel(model);
                    viewModel.Thumbnail = GraphicsUtils.GenerateThumbnail(filename, THUMB_SIZE);
                    _tempFileManager.CopyToTempFile(viewModel.MultimediaID, filename);
                    _model.Add(viewModel);
                    RegisterPendingChange(new InsertMultimediaCommand(model, _tempFileManager.GetContentFileName(viewModel.MultimediaID, finfo.Extension.Substring(1))));
                    RegisterPendingChange(new InsertMultimediaLinkCommand(model, CategoryType, Owner));
                    break;

                case MultimediaDuplicateAction.UseExisting:
                    // Link to existing multimedia
                    model = new MultimediaLink();
                    model.MultimediaID     = duplicate.MultimediaID;
                    model.MultimediaLinkID = NewLinkID();
                    model.Name             = duplicate.Name;
                    model.Extension        = duplicate.FileExtension;
                    viewModel = new MultimediaLinkViewModel(model);
                    GenerateThumbnail(viewModel, THUMB_SIZE);
                    _model.Add(viewModel);
                    RegisterPendingChange(new InsertMultimediaLinkCommand(model, CategoryType, Owner));
                    break;

                case MultimediaDuplicateAction.ReplaceExisting:
                    // register an update for the multimedia,
                    // and insert a new link
                    // Link to existing multimedia
                    model = new MultimediaLink();
                    model.MultimediaID     = duplicate.MultimediaID;
                    model.MultimediaLinkID = NewLinkID();
                    model.Name             = duplicate.Name;
                    model.Extension        = duplicate.FileExtension;
                    viewModel = new MultimediaLinkViewModel(model);
                    GenerateThumbnail(viewModel, THUMB_SIZE);
                    _model.Add(viewModel);
                    _tempFileManager.CopyToTempFile(viewModel.MultimediaID, filename);
                    RegisterPendingChange(new UpdateMultimediaBytesCommand(model, filename));
                    RegisterPendingChange(new InsertMultimediaLinkCommand(model, CategoryType, Owner));
                    break;
                }

                if (viewModel != null)
                {
                    viewModel.IsSelected   = true;
                    thumbList.SelectedItem = viewModel;
                }
            }
        }