in

C1 Community

ComponentOne Community is a free source for developers and help authors to collaborate and communicate.

Merging Ribbons

Last post 06-22-2008 11:37 PM by adrian_aviles. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 06-01-2007 11:44 AM

    Merging Ribbons

    Will there soon be a facility to merge ribbons?

    I have an MDI-type application where I'd like to put invisible ribbons on the child forms and have those ribbon contents (QAT, AppMenu, Tabs, Groups and Items) merge/unmerge with the parent form's ribbon as the child form gets activated/deactivated.

    It would work something like the C1Command toolbars and menus in this respect.
  • 06-01-2007 1:50 PM In reply to

    Re: Merging Ribbons

    Merging ribbons is in our TODO list. But I can't promise this feature
    will be realized very soon. It is difficult in implementation and has
    relatively low priority.
     
    Regards,
     
    -Andrey
    <wbradney> wrote in message news:195461@test.componentone.com...
    Will there soon be a facility to merge ribbons?

    I have an MDI-type application where I'd like to put invisible ribbons on the child forms and have those ribbon contents (QAT, AppMenu, Tabs, Groups and Items) merge/unmerge with the parent form's ribbon as the child form gets activated/deactivated.

    It would work something like the C1Command toolbars and menus in this respect.

    http://home.componentone.com/cs/forums/195461/ShowPost.aspx

  • 06-01-2007 2:42 PM In reply to

    Re: Merging Ribbons

    Here's something to get you started. It kinda sucks that the various ribbon container types don't have a common interface:

    private List permanentTabs = new List();
    private List permanentGroups = new List();
    private List permanentItems = new List();

    private void MergeRibbons(C1Ribbon ribbon1, C1Ribbon ribbon2, bool permanent) {
    for (int t2 = 0; t2 < ribbon2.Tabs.Count; t2++) {
    RibbonTab tab2 = ribbon2.Tabs[t2];
    RibbonTab matchTab = null;
    foreach (RibbonTab tab1 in ribbon1.Tabs) {
    if (tab1.ID == tab2.ID) {
    matchTab = tab1;
    }
    }
    if (matchTab != null) {
    MergeRibbonTabs(matchTab, tab2, permanent);
    }
    else {
    AddRibbonTab(ribbon1, tab2, permanent);
    }
    }

    for (int m2 = 0; m2 < ribbon2.ApplicationMenu.LeftPaneItems.Count; m2++) {
    RibbonItem item2 = ribbon2.ApplicationMenu.LeftPaneItems[m2];
    RibbonItem matchItem = null;
    foreach (RibbonItem item1 in ribbon1.ApplicationMenu.LeftPaneItems) {
    if (item1.ID == item2.ID) {
    matchItem = item1;
    }
    }
    if (matchItem != null) {
    MergeRibbonItems(matchItem, item2, permanent);
    }
    else {
    AddRibbonItem(ribbon1.ApplicationMenu.LeftPaneItems, item2, permanent);
    }
    }
    }

    private void MergeRibbonTabs(RibbonTab tab1, RibbonTab tab2, bool permanent) {
    for (int g2 = 0; g2 < tab2.Groups.Count; g2++) {
    RibbonGroup group2 = tab2.Groups[g2];
    RibbonGroup matchGroup = null;
    foreach (RibbonGroup group1 in tab1.Groups) {
    if (group1.ID == group2.ID) {
    matchGroup = group1;
    }
    }
    if (matchGroup != null) {
    MergeRibbonGroups(matchGroup, group2, permanent);
    }
    else {
    AddRibbonGroup(tab1, group2, permanent);
    }
    }
    }

    private void MergeRibbonGroups(RibbonGroup group1, RibbonGroup group2, bool permanent) {
    for (int i2 = 0; i2 < group2.Items.Count; i2++) {
    RibbonItem item2 = group2.Items[i2];
    RibbonItem matchItem = null;
    foreach (RibbonItem item1 in group1.Items) {
    if (item1.ID == item2.ID) {
    matchItem = item1;
    }
    }
    if (matchItem != null) {
    MergeRibbonItems(matchItem, item2, permanent);
    }
    else {
    AddRibbonItem(group1, item2, permanent);
    }
    }
    }

    private void MergeRibbonItems(RibbonItem item1, RibbonItem item2, bool permanent) {
    if (item1 is RibbonItemContainer && item2 is RibbonItemContainer) {
    RibbonItemContainer container1 = (RibbonItemContainer) item1;
    RibbonItemContainer container2 = (RibbonItemContainer) item2;
    for (int i2 = 0; i2 < container2.Items.Count; i2++) {
    RibbonItem subItem2 = container2.Items[i2];
    RibbonItem matchItem = null;
    foreach (RibbonItem subItem1 in container1.Items) {
    if (subItem1.ID == subItem2.ID) {
    matchItem = subItem1;
    }
    }
    if (matchItem != null) {
    MergeRibbonItems(matchItem, subItem2, permanent);
    }
    else {
    AddRibbonItem(container1, subItem2, permanent);
    }
    }
    }
    else if (item1 is RibbonDropDownBase && item2 is RibbonDropDownBase) {
    RibbonDropDownBase dd1 = (RibbonDropDownBase) item1;
    RibbonDropDownBase dd2 = (RibbonDropDownBase) item2;
    for (int i2 = 0; i2 < dd2.Items.Count; i2++) {
    RibbonItem subItem2 = dd2.Items[i2];
    RibbonItem matchItem = null;
    foreach (RibbonItem subItem1 in dd1.Items) {
    if (subItem1.ID == subItem2.ID) {
    matchItem = subItem1;
    }
    }
    if (matchItem != null) {
    MergeRibbonItems(matchItem, subItem2, permanent);
    }
    else {
    AddRibbonItem(dd1, subItem2, permanent);
    }
    }
    }
    else{
    ReplaceRibbonItem(item1, item2, permanent);
    }
    }

    private void ReplaceRibbonItem(RibbonItem item1, RibbonItem item2, bool permanent) {
    RibbonGroup group = item1.Parent as RibbonGroup;
    if (group != null) {
    int idx = group.Items.IndexOf(item1);
    group.Items.Remove(item1);
    group.Items.Insert(idx, item2);
    return;
    }
    RibbonItemContainer container = item1.Parent as RibbonItemContainer;
    if (container != null) {
    int idx = container.Items.IndexOf(item1);
    container.Items.Remove(item1);
    container.Items.Insert(idx, item2);
    }
    RibbonItemCollection collection = item1.Parent as RibbonItemCollection;
    if (collection != null) {
    int idx = collection.IndexOf(item1);
    collection.Remove(item1);
    collection.Insert(idx, item2);
    }
    RibbonDropDownBase dd = item1.Parent as RibbonDropDownBase;
    if (container != null) {
    int idx = dd.Items.IndexOf(item1);
    dd.Items.Remove(item1);
    dd.Items.Insert(idx, item2);
    }
    }

    private void UnmergeRibbons(C1Ribbon ribbon1, C1Ribbon ribbon2) {
    for (int t2 = 0; t2 < ribbon2.Tabs.Count; t2++) {
    RibbonTab tab2 = ribbon2.Tabs[t2];
    RibbonTab matchTab = null;
    foreach (RibbonTab tab1 in ribbon1.Tabs) {
    if (tab1.ID == tab2.ID) {
    matchTab = tab1;
    }
    }
    if (matchTab != null) {
    UnmergeRibbonTabs(matchTab, tab2);
    }
    else {
    if (!permanentTabs.Contains(tab2)) {
    ribbon1.Tabs.Remove(matchTab);
    }
    }
    }
    }

    private void UnmergeRibbonTabs(RibbonTab tab1, RibbonTab tab2) {
    for (int g2 = 0; g2 < tab2.Groups.Count; g2++) {
    RibbonGroup group2 = tab2.Groups[g2];
    RibbonGroup matchGroup = null;
    foreach (RibbonGroup group1 in tab1.Groups) {
    if (group1.ID == group2.ID) {
    matchGroup = group1;
    }
    }
    if (matchGroup != null) {
    UnmergeRibbonGroups(matchGroup, group2);
    }
    else {
    if (!permanentGroups.Contains(group2)) {
    tab1.Groups.Remove(matchGroup);
    }
    }
    }
    }

    private void UnmergeRibbonGroups(RibbonGroup group1, RibbonGroup group2) {
    for (int i2 = 0; i2 < group2.Items.Count; i2++) {
    RibbonItem item2 = group2.Items[i2];
    RibbonItem matchItem = null;
    foreach (RibbonItem item1 in group1.Items) {
    if (item1.ID == item2.ID) {
    matchItem = item1;
    }
    }
    if (matchItem != null) {
    UnmergeRibbonItems(matchItem, item2);
    }
    else {
    if (!permanentItems.Contains(item2)) {
    group1.Items.Remove(matchItem);
    }
    }
    }
    }

    private void UnmergeRibbonItems(RibbonItem item1, RibbonItem item2) {
    if (item1 is RibbonItemContainer && item2 is RibbonItemContainer) {
    RibbonItemContainer container1 = (RibbonItemContainer) item1;
    RibbonItemContainer container2 = (RibbonItemContainer) item2;
    for (int i2 = 0; i2 < container2.Items.Count; i2++) {
    RibbonItem subItem2 = container2.Items[i2];
    RibbonItem matchItem = null;
    foreach (RibbonItem subItem1 in container1.Items) {
    if (subItem1.ID == subItem2.ID) {
    matchItem = subItem1;
    }
    }
    if (matchItem != null) {
    UnmergeRibbonItems(matchItem, subItem2);
    }
    else {
    if (!permanentItems.Contains(subItem2)) {
    container1.Items.Remove(matchItem);
    }
    }
    }
    }
    }

    private RibbonTab AddRibbonTab(C1Ribbon ribbon, RibbonTab tab, bool permanent) {
    RibbonTab retValue = null;
    if (permanent) {
    if (!permanentTabs.Contains(tab)) {
    permanentTabs.Add(tab);
    }
    else {
    tab = null;
    }
    }
    if (tab != null) {
    ribbon.Tabs.Add(tab);
    retValue = tab;
    }
    return retValue;
    }

    private RibbonGroup AddRibbonGroup(RibbonTab tab, RibbonGroup group, bool permanent) {
    RibbonGroup retValue = null;
    if (permanent) {
    if (!permanentGroups.Contains(group)) {
    permanentGroups.Add(group);
    }
    else {
    group = null;
    }
    }
    if (group != null) {
    tab.Groups.Add(group);
    retValue = group;
    }
    return retValue;
    }

    private RibbonItem AddRibbonItem(RibbonGroup group, RibbonItem item, bool permanent) {
    RibbonItem retValue = null;
    if (permanent) {
    if (!permanentItems.Contains(item)) {
    permanentItems.Add(item);
    }
    else {
    item = null;
    }
    }
    if (item != null) {
    group.Items.Add(item);
    retValue = item;
    }
    return retValue;
    }

    private RibbonItem AddRibbonItem(RibbonItemContainer container, RibbonItem item, bool permanent) {
    RibbonItem retValue = null;
    if (permanent) {
    if (!permanentItems.Contains(item)) {
    permanentItems.Add(item);
    }
    else {
    item = null;
    }
    }
    if (item != null) {
    container.Items.Add(item);
    retValue = item;
    }
    return retValue;
    }

    private RibbonItem AddRibbonItem(RibbonItemCollection collection, RibbonItem item, bool permanent) {
    RibbonItem retValue = null;
    if (permanent) {
    if (!permanentItems.Contains(item)) {
    permanentItems.Add(item);
    }
    else {
    item = null;
    }
    }
    if (item != null) {
    collection.Add(item);
    retValue = item;
    }
    return retValue;
    }

    private RibbonItem AddRibbonItem(RibbonDropDownBase dd, RibbonItem item, bool permanent) {
    RibbonItem retValue = null;
    if (permanent) {
    if (!permanentItems.Contains(item)) {
    permanentItems.Add(item);
    }
    else {
    item = null;
    }
    }
    if (item != null) {
    dd.Items.Add(item);
    retValue = item;
    }
    return retValue;
    }

  • 06-01-2007 2:47 PM In reply to

    Re: Merging Ribbons

    OK. Thanks.
     
  • 06-22-2008 11:37 PM In reply to

    Re: Merging Ribbons

    Hi...

    I think it should have a high priority.
    I've been testing C1 products and I think they're really cool but this was the only reason why I decided not to use them.

    I'm developing an MDI application and ribbon merging it's really important, because it would be a pain if I had to write a lot of code to achieve something just close to it.
    With ribbon merging you can separate ribbon commands in every mdi child form, so you don't have all the code in the main form, besides in every child form you focus only on the functionality expected for that form and you forget about code of the rest of the forms, not to mention you don't have to worry about showing and hiding ribbon items or putting them manually into their corresponding page or group.

    I've tested some other tools and they do provide ribbon merging, so I think it's a common scenario and I'm not the only one who was looking forward to hear you say: "Studio Enterprise 2008 v2 New Features: Ribbon Merging".

    In the other hand, the rest of C1 controls/features are great, for example, what a cool feature to provide a built-in image library, so we can really focus on development and not on UI design.

    I hope you'll provide this feature soon.


    Regards...

    Filed under:
Page 1 of 1 (5 items)
Contact ComponentOne: 1.800.858.2739 ©1987-2008 ComponentOne LLC All Rights Reserved.