예제 #1
0
        /// <summary>
        /// This method expands the ItemExplorers TreeViewItems from a start container down to a given item.
        /// </summary>
        /// <param name="containerItem">The starter container for the search.</param>
        /// <param name="searchItem">The item to be found. This item is also expanded if found (and selected).</param>
        /// <param name="callback">This function will be called on the item if found. Null is allowed if no additional action is wanted.</param>
        /// <returns>Returns true if the item was found.</returns>
        private bool ExpandTo(TreeViewItem containerItem, IListableItem searchItem, Action <IListableItem> callback)
        {
            IListableItem containerListable = containerItem.Tag as IListableItem;

            if (containerListable == searchItem)
            {
                containerItem.IsSelected = true;
                containerItem.IsExpanded = true;
                if (callback != null)
                {
                    callback(searchItem);
                }
                //currentContextItem = searchItem;
                //Open(currentContextItem);
                return(true);
            }
            else if (containerListable is IItemContainer)             //possibility that it's in a subitem
            {
                foreach (TreeViewItem subItem in containerItem.Items) //repeat search for each subitem
                {
                    if (ExpandTo(subItem, searchItem, callback))
                    {
                        containerItem.IsExpanded = true;
                        return(true);
                    }
                }
            }
            return(false);
        }
예제 #2
0
 /// <summary>
 /// This method refreshes the projects (local only)
 /// </summary>
 /// <param name="itemToOpen">The item to open, when the projects are reloaded. If this is null, the top project will be opened.</param>
 private void RefreshLocalProjects(IListableItem itemToOpen = null)
 {
     //Using controllers APM to load the projects into the Item Explorer
     controller.BeginGetProjects("local", (iar) =>
                                 Refresh(controller.EndGetProjects(iar), itemToOpen)
                                 , null);
 }
예제 #3
0
 /// <summary>
 /// Returns whether or not this item is/has a merged document
 /// </summary>
 /// <param name="item">The IListableItem this method is invoked on.</param>
 /// <returns>True if the item is/has a merged document.</returns>
 private static bool hasConflict(this IListableItem item)
 {
     //If this is a document and is set as merged
     if (item is Document)
     {
         return((item as Document).IsMerged);
     }
     else   //or if it's a folder containing a document set as merged
     {
         foreach (Document subDoc in (item as IItemContainer).GetDocuments())
         {
             if (subDoc.IsMerged)
             {
                 return(true);
             }
         }
         //or if it contains a folder set as merged (recursively)
         foreach (IListableItem subFolder in (item as IItemContainer).GetFolders())
         {
             if (subFolder.hasConflict())
             {
                 return(true);
             }
         }
         return(false);
     }
 }
예제 #4
0
        /// <summary>
        /// This method creates a ListViewItem based on a given IListableItem
        /// </summary>
        /// <param name="item">The item to generate a ListViewItem for.</param>
        /// <returns>The created ListViewItem.</returns>
        private ListViewItem CreateListViewItem(IListableItem item)
        {
            StackPanel sp = new StackPanel()
            {
                Width = 50, Height = 50, Orientation = Orientation.Vertical, IsHitTestVisible = false
            };

            sp.Children.Add(new Image()
            {
                Source = item.GetIcon(), Width = 24, Height = 24
            });
            sp.Children.Add(new Label()
            {
                Content = item.Title, MaxWidth = 50, HorizontalAlignment = HorizontalAlignment.Center
            });
            ListViewItem listViewItem = new ListViewItem()
            {
                Margin = new Thickness(2)
            };

            listViewItem.Content           = sp;
            listViewItem.Tag               = item;
            listViewItem.MouseDoubleClick += new MouseButtonEventHandler(
                (sender, e) => OnItemDoubleClicked(new ListableItemEventArgs((sender as ListViewItem).Tag as IListableItem)) //fire own event
                );
            return(listViewItem);
        }
예제 #5
0
 /// <summary>
 /// This method expands the ItemExplorers items down to a given item.
 /// </summary>
 /// <param name="item">The item to be found. This item is also expanded if found (and selected).</param>
 /// <param name="callback">This function will be called on the item if found. Null is allowed if no additional action is wanted.</param>
 public void ExpandTo(IListableItem item, Action <IListableItem> callback)
 {
     foreach (TreeViewItem project in treeView.Items)
     {
         if (ExpandTo(project, item, callback))
         {
             return;                                    //return when found
         }
     }
 }
 /// <summary>
 /// This method creates a ListViewItem based on a given IListableItem
 /// </summary>
 /// <param name="item">The item to generate a ListViewItem for.</param>
 /// <returns>The created ListViewItem.</returns>
 private ListViewItem CreateListViewItem(IListableItem item)
 {
     StackPanel sp = new StackPanel() { Width = 50, Height = 50, Orientation = Orientation.Vertical, IsHitTestVisible = false };
     sp.Children.Add(new Image() { Source = item.GetIcon(), Width = 24, Height = 24 });
     sp.Children.Add(new Label() { Content = item.Title, MaxWidth = 50, HorizontalAlignment = HorizontalAlignment.Center });
     ListViewItem listViewItem = new ListViewItem() { Margin = new Thickness(2) };
     listViewItem.Content = sp;
     listViewItem.Tag = item;
     listViewItem.MouseDoubleClick += new MouseButtonEventHandler(
         (sender, e) => OnItemDoubleClicked(new ListableItemEventArgs((sender as ListViewItem).Tag as IListableItem)) //fire own event
     );
     return listViewItem;
 }
예제 #7
0
 /// <summary>
 /// Fills the MainContent with useful information for the specific item
 /// </summary>
 /// <param name="item">The item which mainContent will use as a context.</param>
 private void Open(IListableItem item)
 {
     currentContextItem = item;
     if (item is IItemContainer)
     {
         containerContentView.ItemContainer = item as IItemContainer;
         mainContent.Content = containerContentViewWrapper;
     }
     else
     {
         textEditor.Document = item as Document;
         mainContent.Content = textEditorWrapper;
     }
 }
예제 #8
0
 /// <summary>
 /// This method refreshes the ui based on projects.
 /// </summary>
 /// <param name="projects">The projects to update the ui with</param>
 /// <param name="itemToOpen">The item to open, when the projects are reloaded. If this is null, the top project will be opened.</param>
 private void Refresh(IEnumerable <Project> projects, IListableItem itemToOpen = null)
 {
     //Callback posted in UI-context
     CallOnUIThread(() => {
         itemExplorer.Projects = projects;
         if (itemToOpen != null)
         {
             itemExplorer.ExpandTo(itemToOpen, Open);
         }
         else
         {
             itemExplorer.CallbackSelected(Open);
         }
     });
 }
예제 #9
0
 /// <summary>
 /// Returns the icon for this IListabeItem
 /// </summary>
 /// <param name="item">The IListableItem this method is invoked on.</param>
 /// <returns>The icon of the item</returns>
 public static BitmapImage GetIcon(this IListableItem item)
 {
     if (item is Project)
     {
         return(item.hasConflict() ? projectConflictIcon : projectIcon);
     }
     else if (item is Folder)
     {
         return(item.hasConflict() ? folderConflictIcon : folderIcon);
     }
     else
     {
         return(item.hasConflict()? documentConflictIcon : documentIcon);
     }
 }
예제 #10
0
 /// <summary>
 /// This generates a suitable context menu for a given listable item
 /// </summary>
 /// <param name="item">The item to show a context menu for.</param>
 /// <returns>The context menu</returns>
 private ContextMenu GetContextMenu(IListableItem item)
 {
     if (item is Project)
     {
         return(projectContextMenu);
     }
     else if (item is Folder)
     {
         return(folderContextMenu);
     }
     else
     {
         return(documentContextMenu);
     }
 }
예제 #11
0
 /// <summary>
 /// This method refreshes the ui based on projects.
 /// </summary>
 /// <param name="projects">The projects to update the ui with</param>
 /// <param name="itemToOpen">The item to open, when the projects are reloaded. If this is null, the top project will be opened.</param>
 private void Refresh(IEnumerable<Project> projects, IListableItem itemToOpen = null)
 {
     //Callback posted in UI-context
     CallOnUIThread(() => {
         itemExplorer.Projects = projects;
         if (itemToOpen != null) {
             itemExplorer.ExpandTo(itemToOpen, Open);
         }
         else {
             itemExplorer.CallbackSelected(Open);
         }
     });
 }
예제 #12
0
 /// <summary>
 /// Fills the MainContent with useful information for the specific item
 /// </summary>
 /// <param name="item">The item which mainContent will use as a context.</param>
 private void Open(IListableItem item)
 {
     currentContextItem = item;
     if (item is IItemContainer) {
         containerContentView.ItemContainer = item as IItemContainer;
         mainContent.Content = containerContentViewWrapper;
     }
     else {
         textEditor.Document = item as Document;
         mainContent.Content = textEditorWrapper;
     }
 }
예제 #13
0
 /// <summary>
 /// This is the event handler for a right click (up event) in the Item Explorer
 /// </summary>
 /// <param name="sender">The object that send the event.</param>
 /// <param name="e">The event arguments.</param>
 private void ItemExplorerItemMouseRightButtonUp(object sender, ListableItemEventArgs e)
 {
     currentContextItem = e.Item;
     itemExplorer.ShowContextMenuForSelected(GetContextMenu(e.Item));
 }
예제 #14
0
 /// <summary>
 /// This is the event handler for a left click (up event) in the Item Explorer
 /// </summary>
 /// <param name="sender">The sender of the event.</param>
 /// <param name="e">The event arguments.</param>
 private void ItemExplorerItemMouseLeftButtonUp(object sender, ListableItemEventArgs e)
 {
     currentContextItem = e.Item;
     Open(e.Item);
 }
예제 #15
0
 /// <summary>
 /// This is the event handler for an enter key event in the Item Explorer
 /// </summary>
 /// <param name="sender">The object that sent the event.</param>
 /// <param name="e">The event arguments.</param>
 private void ItemExplorerItemEnterKeyUp(object sender, ListableItemEventArgs e)
 {
     currentContextItem = e.Item;
     Open(e.Item);
 }
예제 #16
0
 /// <summary>
 /// This generates a suitable context menu for a given listable item
 /// </summary>
 /// <param name="item">The item to show a context menu for.</param>
 /// <returns>The context menu</returns>
 private ContextMenu GetContextMenu(IListableItem item)
 {
     if (item is Project) {
         return projectContextMenu;
     }
     else if (item is Folder) {
         return folderContextMenu;
     }
     else {
         return documentContextMenu;
     }
 }
예제 #17
0
        /// <summary>
        /// This is a helper method for creating a  item in the item explorer.
        /// </summary>
        /// <param name="item">The IListableItem to associate with the TreeViewItem.</param>
        /// <returns>The created TreeViewItem.</returns>
        private TreeViewItem CreateTreeViewItem(IListableItem item)
        {
            TreeViewItem thisTreeViewItem = new TreeViewItem() { Tag = item };
            //StackPanel for image and text block
            StackPanel sp = new StackPanel() { Orientation = Orientation.Horizontal, IsHitTestVisible = false };
            //Create the image
            Image image = new Image() { Source = item.GetIcon(), Height = 15, Width = 15 };
            sp.Children.Add(image);
            //Create the text block
            TextBlock itemText = new TextBlock() { Text = item.Title, Margin = new Thickness(5, 0, 0, 0), IsHitTestVisible = false };
            sp.Children.Add(itemText);
            thisTreeViewItem.Header = sp;
            //set up event handlers
            thisTreeViewItem.MouseDoubleClick += new MouseButtonEventHandler((sender, e) => e.Handled = true); /*This User Control does not provide any double click behaviour - not even the default of TreeViewItems.
                                                                                                              * This is a design choice. We provide a MouseLeftButtonUp instead - having both would cause conflicting behaviour.
                                                                                                              * (The MouseEventArgs.Count property cannot be used as one would expect, since it's keyUp vs. 2 x keyDown).
                                                                                                              * Similar rejections of event bubbling in this TreeViewItem will be found in the methods below (TreeViewItem has a few unwanted default events)   */

            thisTreeViewItem.MouseLeftButtonUp += new MouseButtonEventHandler((sender, e) => {
                e.Handled = true;
                thisTreeViewItem.IsSelected = true;
                thisTreeViewItem.IsExpanded = true;
                OnItemMouseLeftButtonUp(new ListableItemEventArgs(item));
            });

            thisTreeViewItem.MouseRightButtonDown += new MouseButtonEventHandler((sender, e) => { e.Handled = true; thisTreeViewItem.IsSelected = true; });  //selected for visual feedback in line with our LeftMouseButtonDown.

            thisTreeViewItem.MouseRightButtonUp += new MouseButtonEventHandler((sender, e) => { e.Handled = true; OnItemMouseRightButtonUp(new ListableItemEventArgs(item)); });

            thisTreeViewItem.KeyUp += new KeyEventHandler((sender, e) => {
                if (e.Key.Equals(System.Windows.Input.Key.Enter)) {
                    e.Handled = true;
                    thisTreeViewItem.IsSelected = true;
                    thisTreeViewItem.IsExpanded = true;
                    OnItemEnterKeyUp(new ListableItemEventArgs(item));
                }
            });

            //recursive traversal of structure for Item Containers
            if (item is IItemContainer) {
                //First add folders
                foreach (Folder folder in (item as IItemContainer).GetFolders()) {
                    thisTreeViewItem.Items.Add(CreateTreeViewItem(folder));
                }
                //then documents
                foreach (Document document in (item as IItemContainer).GetDocuments()) {
                    thisTreeViewItem.Items.Add(CreateTreeViewItem(document));
                }
            }
            return thisTreeViewItem;
        }
예제 #18
0
        /// <summary>
        /// This is a helper method for creating a  item in the item explorer.
        /// </summary>
        /// <param name="item">The IListableItem to associate with the TreeViewItem.</param>
        /// <returns>The created TreeViewItem.</returns>
        private TreeViewItem CreateTreeViewItem(IListableItem item)
        {
            TreeViewItem thisTreeViewItem = new TreeViewItem()
            {
                Tag = item
            };
            //StackPanel for image and text block
            StackPanel sp = new StackPanel()
            {
                Orientation = Orientation.Horizontal, IsHitTestVisible = false
            };
            //Create the image
            Image image = new Image()
            {
                Source = item.GetIcon(), Height = 15, Width = 15
            };

            sp.Children.Add(image);
            //Create the text block
            TextBlock itemText = new TextBlock()
            {
                Text = item.Title, Margin = new Thickness(5, 0, 0, 0), IsHitTestVisible = false
            };

            sp.Children.Add(itemText);
            thisTreeViewItem.Header = sp;
            //set up event handlers
            thisTreeViewItem.MouseDoubleClick += new MouseButtonEventHandler((sender, e) => e.Handled = true); /*This User Control does not provide any double click behaviour - not even the default of TreeViewItems.
                                                                                                                * This is a design choice. We provide a MouseLeftButtonUp instead - having both would cause conflicting behaviour.
                                                                                                                * (The MouseEventArgs.Count property cannot be used as one would expect, since it's keyUp vs. 2 x keyDown).
                                                                                                                * Similar rejections of event bubbling in this TreeViewItem will be found in the methods below (TreeViewItem has a few unwanted default events)   */

            thisTreeViewItem.MouseLeftButtonUp += new MouseButtonEventHandler((sender, e) => {
                e.Handled = true;
                thisTreeViewItem.IsSelected = true;
                thisTreeViewItem.IsExpanded = true;
                OnItemMouseLeftButtonUp(new ListableItemEventArgs(item));
            });

            thisTreeViewItem.MouseRightButtonDown += new MouseButtonEventHandler((sender, e) => { e.Handled = true; thisTreeViewItem.IsSelected = true; });  //selected for visual feedback in line with our LeftMouseButtonDown.

            thisTreeViewItem.MouseRightButtonUp += new MouseButtonEventHandler((sender, e) => { e.Handled = true; OnItemMouseRightButtonUp(new ListableItemEventArgs(item)); });

            thisTreeViewItem.KeyUp += new KeyEventHandler((sender, e) => {
                if (e.Key.Equals(System.Windows.Input.Key.Enter))
                {
                    e.Handled = true;
                    thisTreeViewItem.IsSelected = true;
                    thisTreeViewItem.IsExpanded = true;
                    OnItemEnterKeyUp(new ListableItemEventArgs(item));
                }
            });

            //recursive traversal of structure for Item Containers
            if (item is IItemContainer)
            {
                //First add folders
                foreach (Folder folder in (item as IItemContainer).GetFolders())
                {
                    thisTreeViewItem.Items.Add(CreateTreeViewItem(folder));
                }
                //then documents
                foreach (Document document in (item as IItemContainer).GetDocuments())
                {
                    thisTreeViewItem.Items.Add(CreateTreeViewItem(document));
                }
            }
            return(thisTreeViewItem);
        }
예제 #19
0
 /// <summary>
 /// This method refreshes the projects (local only)
 /// </summary>
 /// <param name="itemToOpen">The item to open, when the projects are reloaded. If this is null, the top project will be opened.</param>
 private void RefreshLocalProjects(IListableItem itemToOpen = null)
 {
     //Using controllers APM to load the projects into the Item Explorer
     controller.BeginGetProjects("local", (iar) =>
         Refresh(controller.EndGetProjects(iar), itemToOpen)
     , null);
 }
예제 #20
0
 /// <summary>
 /// This method expands the ItemExplorers TreeViewItems from a start container down to a given item.
 /// </summary>
 /// <param name="containerItem">The starter container for the search.</param>
 /// <param name="searchItem">The item to be found. This item is also expanded if found (and selected).</param>
 /// <param name="callback">This function will be called on the item if found. Null is allowed if no additional action is wanted.</param>
 /// <returns>Returns true if the item was found.</returns>
 private bool ExpandTo(TreeViewItem containerItem, IListableItem searchItem, Action<IListableItem> callback)
 {
     IListableItem containerListable = containerItem.Tag as IListableItem;
     if (containerListable == searchItem) {
         containerItem.IsSelected = true;
         containerItem.IsExpanded = true;
         if (callback != null) callback(searchItem);
         //currentContextItem = searchItem;
         //Open(currentContextItem);
         return true;
     }
     else if (containerListable is IItemContainer) { //possibility that it's in a subitem
         foreach (TreeViewItem subItem in containerItem.Items) { //repeat search for each subitem
             if (ExpandTo(subItem, searchItem, callback)) {
                 containerItem.IsExpanded = true;
                 return true;
             }
         }
     }
     return false;
 }
예제 #21
0
 /// <summary>
 /// Constructs the event arguments based on a ListableItem
 /// </summary>
 /// <param name="item">The Listable item to associate with the event</param>
 public ListableItemEventArgs(IListableItem item)
 {
     this.Item = item;
 }
예제 #22
0
 /// <summary>
 /// This is the event handler for a left click (up event) in the Item Explorer
 /// </summary>
 /// <param name="sender">The sender of the event.</param>
 /// <param name="e">The event arguments.</param>
 private void ItemExplorerItemMouseLeftButtonUp(object sender, ListableItemEventArgs e)
 {
     currentContextItem = e.Item;
     Open(e.Item);
 }
예제 #23
0
 /// <summary>
 /// This is the event handler for a right click (up event) in the Item Explorer
 /// </summary>
 /// <param name="sender">The object that send the event.</param>
 /// <param name="e">The event arguments.</param>
 private void ItemExplorerItemMouseRightButtonUp(object sender, ListableItemEventArgs e)
 {
     currentContextItem = e.Item;
     itemExplorer.ShowContextMenuForSelected(GetContextMenu(e.Item));
 }
예제 #24
0
 /// <summary>
 /// Constructs the event arguments based on a ListableItem
 /// </summary>
 /// <param name="item">The Listable item to associate with the event</param>
 public ListableItemEventArgs(IListableItem item)
 {
     this.Item = item;
 }
예제 #25
0
 /// <summary>
 /// This is the event handler for an enter key event in the Item Explorer
 /// </summary>
 /// <param name="sender">The object that sent the event.</param>
 /// <param name="e">The event arguments.</param>
 private void ItemExplorerItemEnterKeyUp(object sender, ListableItemEventArgs e)
 {
     currentContextItem = e.Item;
     Open(e.Item);
 }
예제 #26
0
 /// <summary>
 /// This method expands the ItemExplorers items down to a given item.
 /// </summary>
 /// <param name="item">The item to be found. This item is also expanded if found (and selected).</param>
 /// <param name="callback">This function will be called on the item if found. Null is allowed if no additional action is wanted.</param>
 public void ExpandTo(IListableItem item, Action<IListableItem> callback)
 {
     foreach (TreeViewItem project in treeView.Items) {
         if (ExpandTo(project, item, callback)) return; //return when found
     }
 }