Author Topic: Question about CTRL+TAB (Switch tabs)  (Read 17002 times)

Offline Feneck91

  • Multiple posting newcomer
  • *
  • Posts: 112
Question about CTRL+TAB (Switch tabs)
« on: January 05, 2010, 06:42:12 am »
First, congratulation for this very useful IDE !

Working with Visual Studio since 15 years, I'm beginning new personnal developpement using Code::Blocks + WxWidgets.
I'm working for a big compagny, I will try to make professional work with this IDE.

One thing, when we press CTRL+TAB the manager swith to the last opened document, CTRL+SHIFT+TAB the previous opened document.
I try to modify it, I don't found any command to change this working.

I would like to have, like Visual Studio or NetBeans IDE, could to swith to the previous/last used document.
Is it existing ? It will be existing ?

Thanks for your reply.
Feneck91

Offline Alatar

  • Multiple posting newcomer
  • *
  • Posts: 61
Re: Question about CTRL+TAB (Switch tabs)
« Reply #1 on: January 06, 2010, 05:49:35 pm »
Try this patch (generated for CodeBlocks r6057)

Code
--- cb\src\src\main.cpp	Wed Jan  6 07:48:06 2010
+++ cb_backup\src\src\main.cpp Tue Dec  1 18:06:13 2009
@@ -4002,6 +4002,59 @@
 
 void MainFrame::OnSwitchTabs(wxCommandEvent& event)
 {
+    size_t index = 0;
+    // Get the notebook from the editormanager:
+    wxAuiNotebook* nb = Manager::Get()->GetEditorManager()->GetNotebook();
+    if (!nb)
+        return;
+    cbNotebookStack* nbs;
+
+    // Create container and add all open editors:
+    wxSwitcherItems items;
+    items.AddGroup(_("Open files"), wxT("editors"));
+    //i < nb->GetPageCount()
+    for (nbs = Manager::Get()->GetEditorManager()->GetNotebookStack() ; nbs != NULL; nbs = nbs->next)
+    {
+        wxWindow* window = nbs->window;
+        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:
+ //   int idx = items.GetIndexForFocus();
+ //   if (idx != wxNOT_FOUND)
+    if(items.GetItemCount() > 2)
+        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();
+        }
+    }
+/*
     // Get the notebook from the editormanager:
     wxAuiNotebook* nb = Manager::Get()->GetEditorManager()->GetNotebook();
     if (!nb)
@@ -4046,6 +4099,7 @@
             win->SetFocus();
         }
     }
+*/
 }
 
 void MainFrame::OnToggleFullScreen(wxCommandEvent& event)


--- cb\src\include\editormanager.h Wed Jan  6 07:47:44 2010
+++ cb_backup\src\include\editormanager.h Tue Jan  5 20:11:28 2010
@@ -45,6 +45,21 @@
 struct cbFindReplaceData;
 
 /*
+ * Struct for store tabs stack info
+ */
+struct cbNotebookStack
+{
+    cbNotebookStack(wxWindow* a_wnd = NULL)
+            : window (a_wnd),
+            next (NULL)
+    {}
+
+//    size_t index;
+    wxWindow* window;
+//    wxString title;
+    cbNotebookStack* next;
+};
+/*
  * No description
  */
 class DLLIMPORT EditorManager : public Mgr<EditorManager>, public wxEvtHandler
@@ -59,6 +74,7 @@
         virtual void operator=(const EditorManager& rhs){ cbThrow(_T("Can't assign an EditorManager* !!!")); }
 
         wxAuiNotebook* GetNotebook(){ return m_pNotebook; }
+        cbNotebookStack* GetNotebookStack();////{ return m_pNotebookStackHead->next; }
         void CreateMenu(wxMenuBar* menuBar);
         void ReleaseMenu(wxMenuBar* menuBar);
         void Configure();
@@ -174,6 +190,9 @@
         wxFileName FindHeaderSource(const wxArrayString& candidateFilesArray, const wxFileName& activeFile, bool& isCandidate);
 
         wxAuiNotebook* m_pNotebook;
+        cbNotebookStack* m_pNotebookStackHead;
+        cbNotebookStack* m_pNotebookStackTail;
+        size_t m_NotebookStackSize;
         cbFindReplaceData* m_LastFindReplaceData;
         EditorColourSet* m_Theme;
         ListCtrlLogger* m_pSearchLog;


--- cb\src\sdk\editormanager.cpp Wed Jan  6 07:43:53 2010
+++ cb_backup\src\sdk\editormanager.cpp Tue Jan  5 20:10:38 2010
@@ -156,6 +156,9 @@
 
 EditorManager::EditorManager()
         : m_pNotebook(0L),
+        m_pNotebookStackHead(new cbNotebookStack),
+        m_pNotebookStackTail(m_pNotebookStackHead),
+        m_NotebookStackSize(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 founded = false;
+    wxWindow* wnd;
+    cbNotebookStack* nbs;
+    cbNotebookStack* prev_nbs;
+
+    while(m_NotebookStackSize != m_pNotebook->GetPageCount()) //Sync stack with Notebook
+    {
+//Manager::Get()->GetLogManager()->Log(wxString::Format(_T("TabSw: Sync nb=%d , stack=%d"), m_pNotebook->GetPageCount(), m_NotebookStackSize));
+
+        if(m_NotebookStackSize < m_pNotebook->GetPageCount())
+        {
+            for(size_t i = 0; i<m_pNotebook->GetPageCount(); ++i)
+            {
+                wnd = m_pNotebook->GetPage(i);
+                founded = false;
+                for (nbs = m_pNotebookStackHead->next; nbs != NULL; nbs = nbs->next)
+                    if(wnd == nbs->window)
+                    {
+                        founded = true;
+                        break;
+                    }
+                if(!founded)
+                {
+                    m_pNotebookStackTail->next = new cbNotebookStack(wnd);
+                    m_pNotebookStackTail = m_pNotebookStackTail->next;
+                    ++m_NotebookStackSize;
+                }
+            }
+        }
+        if(m_NotebookStackSize > m_pNotebook->GetPageCount())
+        {
+            for (prev_nbs = m_pNotebookStackHead, nbs = prev_nbs->next; nbs != NULL; prev_nbs = nbs, nbs = nbs->next)
+            {
+                if(m_pNotebook->GetPageIndex(nbs->window) == wxNOT_FOUND)
+                {
+                    prev_nbs->next = nbs->next;
+                    delete nbs;
+                    --m_NotebookStackSize;
+                    nbs = prev_nbs/*->next*/;
+                }
+            }
+        }
+    }
+
+    return m_pNotebookStackHead->next;
+}
+
 void EditorManager::CreateMenu(wxMenuBar* menuBar)
 {
 }
@@ -2510,6 +2562,32 @@
     CodeBlocksEvent evt(cbEVT_EDITOR_ACTIVATED, -1, 0, eb);
     Manager::Get()->GetPluginManager()->NotifyPlugins(evt);
 
+//Manager::Get()->GetLogManager()->Log(_T("TabSw: ChTab - ")+m_pNotebook->GetPageText(event.GetSelection()));
+    wxWindow* wnd;
+    cbNotebookStack* nbs;
+    cbNotebookStack* prev_nbs;
+    wnd = m_pNotebook->GetPage(event.GetSelection());
+    for (prev_nbs = m_pNotebookStackHead, nbs = prev_nbs->next; nbs != NULL; prev_nbs = nbs, nbs = nbs->next)
+    {
+        if(wnd == nbs->window)
+        {
+
+            if(m_pNotebookStackTail == nbs)
+                m_pNotebookStackTail = prev_nbs;
+            prev_nbs->next = nbs->next;
+            nbs->next = m_pNotebookStackHead->next;
+            m_pNotebookStackHead->next = nbs;
+            break;
+        }
+    }
+    if((m_pNotebookStackHead->next == NULL)||(wnd != m_pNotebookStackHead->next->window))
+    {
+        nbs = new cbNotebookStack(wnd);
+        nbs->next = m_pNotebookStackHead->next;
+        m_pNotebookStackHead->next = nbs;
+        ++m_NotebookStackSize;
+    }
+
     // focus editor on next update event
     m_pData->m_SetFocusFlag = true;
 
@@ -2538,6 +2616,21 @@
         //    LOGSTREAM << wxString::Format(_T("OnPageClosing(): ed=%p, title=%s\n"), eb, eb ? eb->GetTitle().c_str() : _T(""));
         if (!QueryClose(eb))
             event.Veto();
+    }
+//Manager::Get()->GetLogManager()->Log(_T("TabSw: DelTab - ")+m_pNotebook->GetPageText(event.GetSelection()));
+    wxWindow* wnd;
+    cbNotebookStack* nbs;
+    cbNotebookStack* prev_nbs;
+    wnd = m_pNotebook->GetPage(event.GetSelection());
+    for (prev_nbs = m_pNotebookStackHead, nbs = prev_nbs->next; nbs != NULL; prev_nbs = nbs, nbs = nbs->next)
+    {
+        if(wnd == nbs->window)
+        {
+            prev_nbs->next = nbs->next;
+            delete nbs;
+            --m_NotebookStackSize;
+            break;
+        }
     }
     event.Skip(); // allow others to process it too
 }

Offline Feneck91

  • Multiple posting newcomer
  • *
  • Posts: 112
Re: Question about CTRL+TAB (Switch tabs)
« Reply #2 on: January 06, 2010, 10:34:56 pm »
I use Nightly Build 5911. Is this patch will be present in future nightly Build ? The IDE I use is not compiled, only download NB...
I just win my next work... make a project for a big compagny with WxWidgets + Code::Blocks
« Last Edit: January 09, 2010, 02:34:22 am by Feneck91 »

Offline Alatar

  • Multiple posting newcomer
  • *
  • Posts: 61
Re: Question about CTRL+TAB (Switch tabs)
« Reply #3 on: January 07, 2010, 09:55:44 am »
Is this patch will be present in future nightly Build ?

I think not. I post this patch 3 months ago (http://forums.codeblocks.org/index.php/topic,11252.0.html) and it still is not in trunk.

Offline Feneck91

  • Multiple posting newcomer
  • *
  • Posts: 112
Re: Question about CTRL+TAB (Switch tabs)
« Reply #4 on: January 07, 2010, 10:23:48 pm »
I'll try your code...
But it's very difficult to find a way to compile code::blocks & wxWidgets for Code::Blocks...
Do you have a simple way to compile ?

Thanks.

Offline Feneck91

  • Multiple posting newcomer
  • *
  • Posts: 112
Re: Question about CTRL+TAB (Switch tabs)
« Reply #5 on: January 07, 2010, 10:45:28 pm »

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: Question about CTRL+TAB (Switch tabs)
« Reply #6 on: January 07, 2010, 11:16:35 pm »

Offline Feneck91

  • Multiple posting newcomer
  • *
  • Posts: 112
Re: Question about CTRL+TAB (Switch tabs)
« Reply #7 on: January 09, 2010, 02:30:01 am »
Thanks for your URL...

I have fully rebuild all projects and plugins for code::blocks...
My SVN version is now 0 !! Why ? It should be 6061
On Help About / Information, it indicate : SVN build rev 0
it is strange.

I have apply your patch. Is a way exists to apply it to source code ? I have apply it by hands, no other ways ?
Rebuilding again and I let a message back to give my feedback about this very cool patch.
Very strange for this very useful IDE that it doesn't contains this kind of option !
Perharps, if it was a new command that we can see by accelerators keys like existing "swith tabs" and new "switch tabs with stack" or something like that !

Offline Feneck91

  • Multiple posting newcomer
  • *
  • Posts: 112
Re: Question about CTRL+TAB (Switch tabs)
« Reply #8 on: January 09, 2010, 02:54:33 am »
Ok, rebuilding is done... SVN version always 0 :-(
and .... YEAHHHHHHHHHHHHHHHHHH !!!!!!!!!!!!!!!!!!!!!!!!!
FANTASTIC !!!!

1> It's work very well, like I want.
2> On displaying all opened files window, takes automatically the second one when switching tabs (not mandatory to make 2 times CTRL+TAB to change to the next window).

Congratulation my friend, very useful patch !

I think it MUST be in official version.
Who decide to apply a patch or not ? I'm with you !

Offline blueshake

  • Regular
  • ***
  • Posts: 458
Re: Question about CTRL+TAB (Switch tabs)
« Reply #9 on: January 09, 2010, 04:04:29 am »
Quote
Ok, rebuilding is done... SVN version always 0 Sad

try to install svn cmd tools.
Keep low and hear the sadness of little dog.
I fall in love with a girl,but I don't dare to tell her.What should I do?

Offline Feneck91

  • Multiple posting newcomer
  • *
  • Posts: 112
Re: Question about CTRL+TAB (Switch tabs)
« Reply #10 on: January 09, 2010, 07:33:18 am »
Quote
Ok, rebuilding is done... SVN version always 0 Sad

try to install svn cmd tools.
Why ? Tortoise SVN doesn't work ? I must get SVN versio in command line ? I don't know how to do !
Your explanation is really short.... Could you explain a little more please ?

Thanks.

Offline autobot

  • Single posting newcomer
  • *
  • Posts: 7
Re: Question about CTRL+TAB (Switch tabs)
« Reply #11 on: January 09, 2010, 08:45:47 am »
Tortoise svn works fine.

Offline Feneck91

  • Multiple posting newcomer
  • *
  • Posts: 112
Re: Question about CTRL+TAB (Switch tabs)
« Reply #12 on: January 09, 2010, 09:25:22 am »
So, why when rebuilding is done... SVN version always 0 ?

I ask this question because i will use wxWidgets + code::block for an industrial projet, and I"ll give to client re-build codeblocks and I need to have correct version number !
« Last Edit: January 09, 2010, 09:30:55 am by Feneck91 »

Offline Alatar

  • Multiple posting newcomer
  • *
  • Posts: 61
Re: Question about CTRL+TAB (Switch tabs)
« Reply #13 on: January 09, 2010, 09:32:28 am »
CLI svn client needs to determine revision number in buildtime. See http://wiki.codeblocks.org/index.php?title=Installing_Code::Blocks_from_source_on_Windows section "svn.exe" for more info. You can download CLI svn client from here - http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=8100 .
For applying patch you can use GNU patch.exe from MSYS/Cygwin/WinAVR/etc

Offline Feneck91

  • Multiple posting newcomer
  • *
  • Posts: 112
Re: Question about CTRL+TAB (Switch tabs)
« Reply #14 on: January 10, 2010, 10:42:16 pm »
Ok, I download / install Setup-Subversion-1.6.6.msi  on link http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=8100
re-build all code::blocks and it's work !