Patch #3293 2012-05-26 22:34

alpha0010

Tabs: tidy context menus
Download
3293-Tabs_tidy_cont.patch (5.8 KB)
Category
Application::Refinement
Status
Accepted
Close date
2012-06-16 06:56
Assigned to
mortenmacfly
Index: src/sdk/editormanager.cpp
===================================================================
--- src/sdk/editormanager.cpp    (revision 8050)
+++ src/sdk/editormanager.cpp    (working copy)
@@ -2808,36 +2808,63 @@
         pop->Append(idNBTabCloseAll, _("Close all"));
         pop->Append(idNBTabCloseAllOthers, _("Close all others"));
     }
+
+    int any_modified = 0;
+    for (int i = 0; i < GetEditorsCount(); ++i)
+    {
+        EditorBase* ed = GetEditor(i);
+        if (ed && ed->GetModified())
+        {
+            if(++any_modified > 1)
+                break;
+        }
+    }
+    if (any_modified > 0)
+    {
+        pop->AppendSeparator();
+        if (GetEditor(event.GetSelection())->GetModified())
+            pop->Append(idNBTabSave, _("Save"));
+        if (any_modified > 1 || !GetEditor(event.GetSelection())->GetModified())
+            pop->Append(idNBTabSaveAll, _("Save all"));
+    }
+
     pop->AppendSeparator();
-    pop->Append(idNBTabSave, _("Save"));
-    pop->Append(idNBTabSaveAll, _("Save all"));
-    pop->AppendSeparator();
-    pop->Append(idNBSwapHeaderSource, _("Swap header/source"));
-    pop->Append(idNBTabOpenContainingFolder, _("Open containing folder"));
-    pop->AppendSeparator();
-    pop->Append(idNBTabTop, _("Tabs at top"));
-    pop->Append(idNBTabBottom, _("Tabs at bottom"));
+    wxString name = GetEditor(event.GetSelection())->GetFilename().Lower();
+    if (name.EndsWith(FileFilters::C_DOT_EXT)    ||
+        name.EndsWith(FileFilters::CPP_DOT_EXT)  ||
+        name.EndsWith(FileFilters::CC_DOT_EXT)   ||
+        name.EndsWith(FileFilters::CXX_DOT_EXT)  ||
+        name.EndsWith(FileFilters::CPLPL_DOT_EXT))
+    {
+        pop->Append(idNBSwapHeaderSource, _("Switch to header"));
+    }
+    else if (FileTypeOf(name) == ftHeader)
+        pop->Append(idNBSwapHeaderSource, _("Switch to source"));
+    cbEditor* ed = GetBuiltinEditor(event.GetSelection());
+    if (ed)
+    {
+        pop->Append(idNBTabOpenContainingFolder, _("Open containing folder"));
+        pop->Append(idNBProperties, _("Properties..."));
+        pop->AppendSeparator();
+    }
+
     if (Manager::Get()->GetConfigManager(_T("app"))->ReadBool(_T("/environment/editor_tabs_bottom"), false))
-        pop->FindItem(idNBTabBottom)->Enable(false);
+        pop->Append(idNBTabTop, _("Tabs at top"));
     else
-        pop->FindItem(idNBTabTop)->Enable(false);
+        pop->Append(idNBTabBottom, _("Tabs at bottom"));
 
-    cbEditor* ed = GetBuiltinEditor(event.GetSelection());
     if (ed)
     {
-        pop->AppendSeparator();
-        pop->Append(idNBProperties, _("Properties..."));
-
         wxMenu* splitMenu = new wxMenu;
-        splitMenu->Append(idNBTabSplitHorz, _("Horizontally"));
-        splitMenu->Append(idNBTabSplitVert, _("Vertically"));
-        splitMenu->AppendSeparator();
-        splitMenu->Append(idNBTabUnsplit, _("Unsplit"));
-        splitMenu->Enable(idNBTabSplitHorz, ed->GetSplitType() != cbEditor::stHorizontal);
-        splitMenu->Enable(idNBTabSplitVert, ed->GetSplitType() != cbEditor::stVertical);
-        splitMenu->Enable(idNBTabUnsplit, ed->GetSplitType() != cbEditor::stNoSplit);
-
-        pop->AppendSeparator();
+        if (ed->GetSplitType() != cbEditor::stHorizontal)
+            splitMenu->Append(idNBTabSplitHorz, _("Horizontally"));
+        if (ed->GetSplitType() != cbEditor::stVertical)
+            splitMenu->Append(idNBTabSplitVert, _("Vertically"));
+        if (ed->GetSplitType() != cbEditor::stNoSplit)
+        {
+            splitMenu->AppendSeparator();
+            splitMenu->Append(idNBTabUnsplit, _("Unsplit"));
+        }
         pop->Append(-1, _("Split view"), splitMenu);
 
         if (Manager::Get()->GetProjectManager()->GetActiveProject()) // project must be open
@@ -2855,21 +2882,6 @@
         }
     }
 
-    bool any_modified = false;
-
-    for (int i = 0; i < GetEditorsCount(); ++i)
-    {
-        EditorBase* ed = GetEditor(i);
-        if (ed && ed->GetModified())
-        {
-            any_modified = true;
-            break;
-        }
-    }
-
-    pop->Enable(idNBTabSave, GetEditor(event.GetSelection())->GetModified());
-    pop->Enable(idNBTabSaveAll, any_modified );
-
     // allow plugins to use this menu
     Manager::Get()->GetPluginManager()->AskPluginsForModuleMenu(mtEditorTab, pop);
 
Index: src/sdk/projectmanager.cpp
===================================================================
--- src/sdk/projectmanager.cpp    (revision 8050)
+++ src/sdk/projectmanager.cpp    (working copy)
@@ -1948,12 +1948,10 @@
 void ProjectManager::OnTabContextMenu(wxAuiNotebookEvent& /*event*/)
 {
     wxMenu* NBmenu = new wxMenu();
-    NBmenu->Append(idNB_TabTop, _("Tabs at top"));
-    NBmenu->Append(idNB_TabBottom, _("Tabs at bottom"));
     if (Manager::Get()->GetConfigManager(_T("app"))->ReadBool(_T("/environment/project_tabs_bottom"), false))
-        NBmenu->FindItem(idNB_TabBottom)->Enable(false);
+        NBmenu->Append(idN
download for full patch...
alpha0010 2012-05-26 22:35

Hides irrelevant options and reorganizes more logically.

mortenmacfly 2012-05-27 08:36

Nice one! Will try and commit it there are no errors...

mortenmacfly 2012-05-29 10:02

Ok, we had some discussion about this patch between the devs, can I contact you in the forums via PM?

alpha0010 2012-05-29 20:00

Sure.

mortenmacfly 2012-05-30 10:17

Ok, and the nick-name there is...?! ;-)

alpha0010 2012-05-30 20:13

Oh, sorry; it is "Alpha" (of course).

alpha0010 2012-06-15 19:41

Small revision: don't show "Save all" when it would have the same effect as "Save".

mortenmacfly 2012-06-16 06:56

Partially applied in SVN.

After discussion with the devs, the other changes are mis-leading and not intuitive to do.