Developer forums (C::B DEVELOPMENT STRICTLY!) > Development

Improvement in TabSwitcher

<< < (2/10) > >>

Feneck91:
To have a change to figure into official Code::Blocks IDE, I have patch your source code :
Change some variable name (Added type, long name).
And I have added a new menu entry into view menu : Switch tabs stack.
Now, the user can choose between current way change to edited file or new one with Switch tabs stack.
This new menu entry is now into shortcut too: The user can change CTRL+TAB shortcut to new Switch tabs stack.
I hope you have correctly tested your source code because I don't test it (new / delete), its seem work fine.
I'll use it intensively for 2 months with 2 developpers for a professionnal project.
We must work together to make your patch into official Code::Blocks IDE : it is awful to work without this patch, its seems very important to me.

Patch :
--- Code: ---Index: src/include/editormanager.h
===================================================================
--- src/include/editormanager.h (revision 6077)
+++ src/include/editormanager.h (working copy)
@@ -45,6 +45,20 @@
 struct cbFindReplaceData;
 
 /*
+ * Struct for store tabs stack info
+ */
+struct cbNotebookStack
+{
+    cbNotebookStack(wxWindow* a_pWindow = NULL)
+        : m_pWindow (a_pWindow),
+          m_pNextNotebookStack (NULL)
+    {}
+
+    wxWindow*           m_pWindow;
+    cbNotebookStack*    m_pNextNotebookStack;
+};
+
+/*
  * No description
  */
 class DLLIMPORT EditorManager : public Mgr<EditorManager>, public wxEvtHandler
@@ -59,6 +73,7 @@
         virtual void operator=(const EditorManager& rhs){ cbThrow(_T("Can't assign an EditorManager* !!!")); }
 
         wxAuiNotebook* GetNotebook(){ return m_pNotebook; }
+        cbNotebookStack* GetNotebookStack();
         void CreateMenu(wxMenuBar* menuBar);
         void ReleaseMenu(wxMenuBar* menuBar);
         void Configure();
@@ -174,6 +189,9 @@
         wxFileName FindHeaderSource(const wxArrayString& candidateFilesArray, const wxFileName& activeFile, bool& isCandidate);
 
         wxAuiNotebook* m_pNotebook;
+        cbNotebookStack* m_pNotebookStackHead;
+        cbNotebookStack* m_pNotebookStackTail;
+        size_t m_nNotebookStackSize;
         cbFindReplaceData* m_LastFindReplaceData;
         EditorColourSet* m_Theme;
         ListCtrlLogger* m_pSearchLog;
Index: src/sdk/editormanager.cpp
===================================================================
--- src/sdk/editormanager.cpp (revision 6077)
+++ src/sdk/editormanager.cpp (working copy)
@@ -156,6 +156,9 @@
 
 EditorManager::EditorManager()
         : m_pNotebook(0L),
+        m_pNotebookStackHead(new cbNotebookStack),
+        m_pNotebookStackTail(m_pNotebookStackHead),
+        m_nNotebookStackSize(0),
         m_LastFindReplaceData(0L),
         m_pSearchLog(0),
         m_SearchLogIndex(-1),
@@ -192,6 +195,55 @@
     Manager::Get()->GetConfigManager(_T("editor"))->Write(_T("/zoom"), m_zoom);
 }
 
+cbNotebookStack* EditorManager::GetNotebookStack()
+{
+    bool bFounded = false;
+    wxWindow* pWindow;
+    cbNotebookStack* pNotebookStack;
+    cbNotebookStack* pPrevNotebookStack;
+
+    while(m_nNotebookStackSize != m_pNotebook->GetPageCount()) //Sync stack with Notebook
+    {
+        if(m_nNotebookStackSize < m_pNotebook->GetPageCount())
+        {
+            for(size_t i = 0; i<m_pNotebook->GetPageCount(); ++i)
+            {
+                pWindow = m_pNotebook->GetPage(i);
+                bFounded = false;
+                for (pNotebookStack = m_pNotebookStackHead->m_pNextNotebookStack; pNotebookStack != NULL; pNotebookStack = pNotebookStack->m_pNextNotebookStack)
+                {
+                    if(pWindow == pNotebookStack->m_pWindow)
+                    {
+                        bFounded = true;
+                        break;
+                    }
+                }
+                if(!bFounded)
+                {
+                    m_pNotebookStackTail->m_pNextNotebookStack = new cbNotebookStack(pWindow);
+                    m_pNotebookStackTail = m_pNotebookStackTail->m_pNextNotebookStack;
+                    ++m_nNotebookStackSize;
+                }
+            }
+        }
+        if(m_nNotebookStackSize > m_pNotebook->GetPageCount())
+        {
+            for (pPrevNotebookStack = m_pNotebookStackHead, pNotebookStack = pPrevNotebookStack->m_pNextNotebookStack; pNotebookStack != NULL; pPrevNotebookStack = pNotebookStack, pNotebookStack = pNotebookStack->m_pNextNotebookStack)
+            {
+                if(m_pNotebook->GetPageIndex(pNotebookStack->m_pWindow) == wxNOT_FOUND)
+                {
+                    pPrevNotebookStack->m_pNextNotebookStack = pNotebookStack->m_pNextNotebookStack;
+                    delete pNotebookStack;
+                    --m_nNotebookStackSize;
+                    pNotebookStack = pPrevNotebookStack;
+                }
+            }
+        }
+    }
+
+    return m_pNotebookStackHead->m_pNextNotebookStack;
+}
+
 void EditorManager::CreateMenu(wxMenuBar* menuBar)
 {
 }
@@ -2510,6 +2562,32 @@
     CodeBlocksEvent evt(cbEVT_EDITOR_ACTIVATED, -1, 0, eb);
     Manager::Get()->GetPluginManager()->NotifyPlugins(evt);
 
+    wxWindow* pWindow;
+    cbNotebookStack* pNotebookStack;
+    cbNotebookStack* pPrevNotebookStack;
+    pWindow = m_pNotebook->GetPage(event.GetSelection());
+    for (pPrevNotebookStack = m_pNotebookStackHead, pNotebookStack = pPrevNotebookStack->m_pNextNotebookStack; pNotebookStack != NULL; pPrevNotebookStack = pNotebookStack, pNotebookStack = pNotebookStack->m_pNextNotebookStack)
+    {
+        if(pWindow == pNotebookStack->m_pWindow)
+        {
+            if(m_pNotebookStackTail == pNotebookStack)
+            {
+                m_pNotebookStackTail = pPrevNotebookStack;
+            }
+            pPrevNotebookStack->m_pNextNotebookStack = pNotebookStack->m_pNextNotebookStack;
+            pNotebookStack->m_pNextNotebookStack = m_pNotebookStackHead->m_pNextNotebookStack;
+            m_pNotebookStackHead->m_pNextNotebookStack = pNotebookStack;
+            break;
+        }
+    }
+    if((m_pNotebookStackHead->m_pNextNotebookStack == NULL)||(pWindow != m_pNotebookStackHead->m_pNextNotebookStack->m_pWindow))
+    {
+        pNotebookStack = new cbNotebookStack(pWindow);
+        pNotebookStack->m_pNextNotebookStack = m_pNotebookStackHead->m_pNextNotebookStack;
+        m_pNotebookStackHead->m_pNextNotebookStack = pNotebookStack;
+        ++m_nNotebookStackSize;
+    }
+
     // focus editor on next update event
     m_pData->m_SetFocusFlag = true;
 
@@ -2539,6 +2617,21 @@
         if (!QueryClose(eb))
             event.Veto();
     }
+
+    wxWindow* pWindow;
+    cbNotebookStack* pNotebookStack;
+    cbNotebookStack* pPrevNotebookStack;
+    pWindow = m_pNotebook->GetPage(event.GetSelection());
+    for (pPrevNotebookStack = m_pNotebookStackHead, pNotebookStack = pPrevNotebookStack->m_pNextNotebookStack; pNotebookStack != NULL; pPrevNotebookStack = pNotebookStack, pNotebookStack = pNotebookStack->m_pNextNotebookStack)
+    {
+        if(pWindow == pNotebookStack->m_pWindow)
+        {
+            pPrevNotebookStack->m_pNextNotebookStack = pNotebookStack->m_pNextNotebookStack;
+            delete pNotebookStack;
+            --m_nNotebookStackSize;
+            break;
+        }
+    }
     event.Skip(); // allow others to process it too
 }
 
Index: src/src/main.cpp
===================================================================
--- src/src/main.cpp (revision 6077)
+++ src/src/main.cpp (working copy)
@@ -211,6 +211,7 @@
 int idViewScriptConsole = XRCID("idViewScriptConsole");
 int idViewFocusEditor = XRCID("idViewFocusEditor");
 int idViewSwitchTabs = XRCID("idViewSwitchTabs");
+int idViewSwitchTabsStack = XRCID("idViewSwitchTabsStack");
 int idViewFullScreen = XRCID("idViewFullScreen");
 
 int idSearchFind = XRCID("idSearchFind");
@@ -431,6 +432,7 @@
     EVT_MENU(idViewScriptConsole, MainFrame::OnViewScriptConsole)
     EVT_MENU(idViewFocusEditor, MainFrame::OnFocusEditor)
     EVT_MENU(idViewSwitchTabs, MainFrame::OnSwitchTabs)
+    EVT_MENU(idViewSwitchTabsStack, MainFrame::OnSwitchTabsStack)
     EVT_MENU(idViewFullScreen, MainFrame::OnToggleFullScreen)
 
     EVT_MENU(idSettingsEnvironment, MainFrame::OnSettingsEnvironment)
@@ -4048,6 +4050,68 @@
     }
 }
 
+void MainFrame::OnSwitchTabsStack(wxCommandEvent& event)
+{
+    size_t index = 0;
+    // Get the notebook from the editormanager:
+    wxAuiNotebook* nb = Manager::Get()->GetEditorManager()->GetNotebook();
+    if (!nb)
+        return;
+    cbNotebookStack* pNotebookStack;
+
+    // Create container and add all open editors:
+    wxSwitcherItems items;
+    items.AddGroup(_("Open files"), wxT("editors"));
+    for (pNotebookStack = Manager::Get()->GetEditorManager()->GetNotebookStack() ; pNotebookStack != NULL; pNotebookStack = pNotebookStack->m_pNextNotebookStack)
+    {
+        wxWindow* window = pNotebookStack->m_pWindow;
+        if(nb->GetPageIndex(window) == wxNOT_FOUND)
+            continue;
+        index = nb->GetPageIndex(window);
+        wxString title = nb->GetPageText(index);
+
+        items.AddItem(title, title, index, nb->GetPageBitmap(index)).SetWindow(window);
+    }
+
+    // Select the focused editor:
+    if(items.GetItemCount() > 2)
+    {   // CTRL + TAB directly select the last editor, not the current one
+        items.SetSelection(2);
+    }
+    else
+    {
+        items.SetSelection(items.GetItemCount()-1);
+    }
+
+    // Create the switcher dialog
+    wxSwitcherDialog dlg(items, wxGetApp().GetTopWindow());
+
+    // Ctrl+Tab workaround for non windows platforms:
+    if (platform::cocoa)
+    {
+        dlg.SetModifierKey(WXK_ALT);
+    }
+    else if (platform::gtk)
+    {
+        dlg.SetExtraNavigationKey(wxT(','));
+    }
+
+    // Finally show the dialog:
+    int answer = dlg.ShowModal();
+
+    // If necessary change the selected editor:
+    if ((answer == wxID_OK) && (dlg.GetSelection() != -1))
+    {
+        wxSwitcherItem& item = items.GetItem(dlg.GetSelection());
+        wxWindow* win = item.GetWindow();
+        if(win)
+        {
+            nb->SetSelection(item.GetId());
+            win->SetFocus();
+        }
+    }
+}
+
 void MainFrame::OnToggleFullScreen(wxCommandEvent& event)
 {
     ShowFullScreen( !IsFullScreen(), wxFULLSCREEN_NOTOOLBAR// | wxFULLSCREEN_NOSTATUSBAR
Index: src/src/main.h
===================================================================
--- src/src/main.h (revision 6077)
+++ src/src/main.h (working copy)
@@ -180,6 +180,7 @@
         void OnToggleStatusBar(wxCommandEvent& event);
         void OnFocusEditor(wxCommandEvent& event);
         void OnSwitchTabs(wxCommandEvent& event);
+        void OnSwitchTabsStack(wxCommandEvent& event);
         void OnToggleFullScreen(wxCommandEvent& event);
 
         // plugin events
Index: src/src/resources/main_menu.xrc
===================================================================
--- src/src/resources/main_menu.xrc (revision 6077)
+++ src/src/resources/main_menu.xrc (working copy)
@@ -538,6 +538,10 @@
         <accel>Ctrl+Tab</accel>
         <help>Switch between open editor tabs</help>
       </object>
+      <object class="wxMenuItem" name="idViewSwitchTabsStack">
+        <label>Switch tabs stack</label>
+        <help>Switch between open editor tabs with sorting of previous used documents</help>
+      </object>
     </object>
     <object class="wxMenu" name="menu_search">
       <label>Sea&amp;rch</label>

--- End code ---

How to propose this patch and how to get feed back to know why it is refused and what shall we do to make it accepted ?
This patch has advantage to let the current way of tab changing, just added new one. (yours).

Thanks to give me your feedback.
Feneck91

MortenMacFly:

--- Quote from: Feneck91 on January 12, 2010, 07:53:23 am ---How to propose this patch and how to get feed back to know why it is refused and what shall we do to make it accepted ?

--- End quote ---
Via the patch tracker here:
http://developer.berlios.de/patch/?group_id=5358

The original patch is here:
http://developer.berlios.de/patch/?func=detailpatch&patch_id=2902&group_id=5358

Once it got assigned you will get an email automatically if something changes. You can also subscribe to other patches.

Please post a comment in the original patch and/or update the patch there accordingly (only possible with the help of alatar_).

BTW: You'll need to register with BerliOS to have an account which is needed to post patches / bugs.

Feneck91:
Alastar, are you agree to work together ?
I let you test my patch and accept or refuse it.

MortenMacFly:

--- Quote from: Feneck91 on January 12, 2010, 07:53:23 am ---Change some variable name (Added type, long name).
And I have added a new menu entry into view menu : Switch tabs stack.

--- End quote ---
This is not the default for the CTRL+TAB shortcut. Is this on purpose? I guess it'd be more intuitive if it would. So the other option become an... erm... option.

Feneck91:
I'm french, I don't know what is erm option ... is it means obsolet ?
I don't know why Alatar patch is not validate into Code:Blocks...
So, 3 differents ways :
1> Replace the actual CTRL+TAB with a new one with stack recording. The old way was also not supported. This is the alatar patch.
2> Let the current CTRL+TAB working like it actually works and propose another way, the user can custumize with shortcut and so, replace actual CTRL+TAB working by new one. This is my patch.
3> Let the current CTRL+TAB working like it actually works but remove its shortcut and assign it to new working. If the user want to keep old way of CTRL+TAB, he can custumize shortcut to old way. I can do this patch if you want, but I'm not sure that only modify xrc will work if the user has assign another key to this shortcut.

I thought that if this patch was not into Code::Blocks it was because we should not modify currents working of Code::Blocks, so why I propose the patch (2).

What shall we do ?

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version