예제 #1
0
    //SetAllFilesPreviewBehaviourToSkipEntryPage 1.1
    public static void Main()
    {
        if (Program.ProjectShells.Count == 0)
        {
            return;                                                     //no project open
        }
        if (IsBackupAvailable() == false)
        {
            return;                                                             //user wants to backup his/her project first
        }
        int counter = 0;

        try
        {
            List <Reference>             references    = Program.ActiveProjectShell.PrimaryMainForm.GetFilteredReferences();
            SwissAcademic.Citavi.Project activeProject = Program.ActiveProjectShell.Project;

            List <Location> filesToShowImmediately = new List <Location>();

            foreach (Reference reference in references)
            {
                foreach (Location location in reference.Locations)
                {
                    //first we collect all files that are not set to be shown immediately yet
                    if (location.LocationType == LocationType.ElectronicAddress)
                    {
                        switch (location.AddressUri.AddressInfo)
                        {
                        case ElectronicAddressInfo.RemoteUri:
                        case ElectronicAddressInfo.AbsoluteFileUri:
                        case ElectronicAddressInfo.RelativeFileUri:
                        case ElectronicAddressInfo.CitaviFiles:
                        {
                            //MessageBox.Show(string.Format("Location:{0}\n\rPreview Behaviour:{1}\n\rLocal Path:{2}", location.ToString(), location.PreviewBehaviour.ToString(), location.AddressUri.AbsoluteUri.LocalPath.ToString()));
                            if (location.PreviewBehaviour != PreviewBehaviour.SkipEntryPage)
                            {
                                filesToShowImmediately.Add(location);
                            }
                            //if(location.AddressUri.AbsoluteUri.LocalPath == DriveType.Network) filesToShowImmediately.Add(location);
                        }
                        break;
                        }
                    }
                }
            }


            //now we change the PreviewBehaviour on all the collected files
            foreach (Location location in filesToShowImmediately)
            {
                if (location.PreviewBehaviour != PreviewBehaviour.SkipEntryPage)
                {
                    location.PreviewBehaviour = PreviewBehaviour.SkipEntryPage;
                    counter++;
                }
            }

            activeProject.Save(TrackPriority.Immediate);
        }         //end try

        finally
        {
            MessageBox.Show(string.Format("Macro has finished execution.\r\n{0} changes were made.", counter.ToString()), "Citavi", MessageBoxButtons.OK, MessageBoxIcon.Information);
        } //end finally
    }     //end main()
    public static void Main()
    {
        if (Program.ProjectShells.Count == 0)
        {
            return;                                                     //no project open
        }
        if (IsBackupAvailable() == false)
        {
            return;                                                             //user wants to backup his/her project first
        }
        int counter = 0;

        try
        {
            //IMPORTANT: We need a List<Reference>, NOT the internal ProjectReferenceCollection, because the latter would trigger erratic errors of the kind
            //"collection was modified, enumeration operation may not execute"

            //if this macro should ALWAYS affect all titles in active project, choose first option
            //if this macro should affect just filtered rows if there is a filter applied and ALL if not, choose second option

            //List<Reference> references = CollectionUtility.ToList<Reference>(Program.ActiveProjectShell.Project.References);
            List <Reference> references = Program.ActiveProjectShell.PrimaryMainForm.GetFilteredReferences();

            //if we need a ref to the active project
            SwissAcademic.Citavi.Project activeProject = Program.ActiveProjectShell.Project;

            List <Location> filesToShowImmediately = new List <Location>();

            foreach (Reference reference in references)
            {
                foreach (Location location in reference.Locations)
                {
                    //first we collect all files that are not set to be shown immediately yet
                    if (location.LocationType == LocationType.ElectronicAddress)
                    {
                        switch (location.AddressUri.AddressInfo)
                        {
                        case ElectronicAddressInfo.RemoteUri:
                        case ElectronicAddressInfo.AbsoluteFileUri:
                        case ElectronicAddressInfo.RelativeFileUri:
                        case ElectronicAddressInfo.Attachment:
                        {
                            //MessageBox.Show(string.Format("Location:{0}\n\rPreview Behaviour:{1}\n\rLocal Path:{2}", location.ToString(), location.PreviewBehaviour.ToString(), location.AddressUri.AbsoluteUri.LocalPath.ToString()));
                            if (location.PreviewBehaviour != PreviewBehaviour.ShowEntryPage)
                            {
                                filesToShowImmediately.Add(location);
                            }
                            //if(location.AddressUri.AbsoluteUri.LocalPath == DriveType.Network) filesToShowImmediately.Add(location);
                        }
                        break;
                        }
                    }
                }
            }


            //now we change the PreviewBehaviour on all the collected files
            foreach (Location location in filesToShowImmediately)
            {
                if (location.PreviewBehaviour != PreviewBehaviour.ShowEntryPage)
                {
                    location.PreviewBehaviour = PreviewBehaviour.ShowEntryPage;
                    counter++;
                }
            }

            activeProject.Save();
        }         //end try

        finally
        {
            MessageBox.Show(string.Format("Macro has finished execution.\r\n{0} changes were made.", counter.ToString()), "Citavi", MessageBoxButtons.OK, MessageBoxIcon.Information);
        } //end finally
    }     //end main()
예제 #3
0
    public static void Main()
    {
        char splitter = ',';            //if you have any other separating character, like '|' or '/' you can adjust this here



        if (!Program.ProjectShells.Any())
        {
            return;                                                     //no project open
        }
        if (IsBackupAvailable() == false)
        {
            return;                                                     //user wants to backup his/her project first
        }
        SwissAcademic.Citavi.Project activeProject = Program.ActiveProjectShell.Project;
        activeProject.Save();

        //collect all keywords to be separated
        List <Keyword> keywordsToBeSplit = new List <Keyword>();

        foreach (Keyword keyword in activeProject.Keywords)
        {
            if (keyword.Name.Contains(splitter))
            {
                keywordsToBeSplit.Add(keyword);
            }
        }

        if (keywordsToBeSplit.Count == 0)
        {
            MessageBox.Show("No keywords to be split.");
            return;
        }


        foreach (Keyword keyword in keywordsToBeSplit)
        {
            //get references and knowledge items that need to be "tagged" with the "fractions"
            List <Reference> referencesToBeTagged = new List <Reference>();
            foreach (Reference reference in keyword.References)
            {
                referencesToBeTagged.Add(reference);
            }

            List <KnowledgeItem> knowledgeItemsToBeTagged = new List <KnowledgeItem>();
            foreach (KnowledgeItem knowledgeItem in keyword.KnowledgeItems)
            {
                knowledgeItemsToBeTagged.Add(knowledgeItem);
            }


            List <string>  keywordStringFragments = keyword.Name.Split(new char[] { splitter }, StringSplitOptions.RemoveEmptyEntries).ToList();
            List <Keyword> fragmentKeywords       = new List <Keyword>();
            //make sure the fragment strings exist as keywords
            foreach (string keywordStringFragment in keywordStringFragments)
            {
                fragmentKeywords.Add(activeProject.Keywords.Add(keywordStringFragment.Trim()));
            }


            //assign keyword fragment to reference-to-be-tagged
            foreach (Reference reference in referencesToBeTagged)
            {
                reference.Keywords.AddRange(fragmentKeywords);
            }


            //assign keyword fragment to knowledge-item-to-be-tagged
            foreach (KnowledgeItem knowledgeItem in knowledgeItemsToBeTagged)
            {
                knowledgeItem.Keywords.AddRange(fragmentKeywords);
            }
        }

        //finally we could delete the old "mega-keywords"
        activeProject.Keywords.RemoveRange(keywordsToBeSplit);
        activeProject.Save();

        MessageBox.Show("Done");
    }