NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
NumeReNotebook.cpp
Go to the documentation of this file.
1#include "../common/CommonHeaders.h"
2#include "NumeReNotebook.h"
3#include "NumeReWindow.h"
5#include "IconManager.h"
6
7#include "../common/vcsmanager.hpp"
8#include "editor/editor.h"
9
10#include <wx/wx.h>
11#include <wx/msgdlg.h>
12#include <wx/notebook.h>
13#include <windows.h>
14#include <commctrl.h>
15
16#include "../common/datastructures.h"
17
18BEGIN_EVENT_TABLE(EditorNotebook, wxAuiNotebook)
19 EVT_AUINOTEBOOK_BUTTON (-1, EditorNotebook::OnButtonClicked)
20 EVT_AUINOTEBOOK_TAB_MIDDLE_UP (-1, EditorNotebook::OnTabMiddleClicked)
21 EVT_AUINOTEBOOK_TAB_RIGHT_UP (-1, EditorNotebook::OnTabRightClicked)
22 EVT_AUINOTEBOOK_DRAG_MOTION (-1, EditorNotebook::OnTabMove)
23 //EVT_RIGHT_UP (EditorNotebook::OnTabRightClicked)
24 //EVT_MOUSEWHEEL (EditorNotebook::OnTabScroll)
25 EVT_ENTER_WINDOW(EditorNotebook::OnEnter)
26 EVT_LEAVE_WINDOW(EditorNotebook::OnLeave)
27 EVT_SIZE (EditorNotebook::OnSize)
28 EVT_SPLITTER_UNSPLIT(-1, EditorNotebook::OnUnsplit)
30
31
42EditorNotebook::EditorNotebook(wxWindow* parent, wxWindowID id, IconManager* icons, const wxPoint& pos, const wxSize& size, long style) : wxAuiNotebook(parent, id, pos, size, style | wxAUI_NB_DEFAULT_STYLE | wxAUI_NB_WINDOWLIST_BUTTON /*, name*/)
43{
44 m_mouseFocus = false;
45 m_top_parent = nullptr;
46 m_showPathsOnTabs = false;
47 m_showIconsOnTabs = false;
48 m_manager = icons;
49 SetImageList(icons->GetImageList());
50}
51
52
57{
58}
59
60
71void EditorNotebook::SetShowPathsOrIconsOnTabs(bool showText, bool showIcons)
72{
73 m_showPathsOnTabs = showText;
74 m_showIconsOnTabs = showIcons;
75
76 for (size_t i = 0; i < GetPageCount(); i++)
77 {
78 NumeReEditor* edit = getEditor(i);
80 }
81
82 Refresh();
83}
84
85
96void EditorNotebook::SetTabText(size_t nTab, const wxString& text)
97{
98 size_t pos = 0;
99 std::string path = replacePathSeparator(text.ToStdString());
100 std::string ext = path.substr(path.find_last_of("/.")+1);
101 std::string filetype = _guilang.get("COMMON_FILETYPE_" + toUpperCase(ext));
102
103 if (filetype == "COMMON_FILETYPE_" + toUpperCase(ext))
104 filetype = _guilang.get("GUI_STATUSBAR_UNKNOWN", toUpperCase(ext));
105
106 SetPageToolTip(nTab, path + "\n" + filetype);
107
109 SetPageImage(nTab, m_manager->GetIconIndex(ext));
110 else
111 SetPageBitmap(nTab, wxNullBitmap);
112
113 std::vector<std::string> vPaths = m_top_parent->getPathDefs();
114
116 {
117 for (int i = LOADPATH; i < PATH_LAST; i++)
118 {
119 if (path.substr(0, vPaths[i].length()) == vPaths[i])
120 {
121 pos = vPaths[i].length();
122
123 while (path[pos] == '/')
124 pos++;
125
126 break;
127 }
128 }
129
130 // Nothing found-must be an absolute path. We will
131 // replace /PATH/ with /../
132 if (!pos)
133 path = shortenFileName(path);
134 }
135 else
136 pos = path.rfind('/')+1;
137
138 SetPageText(nTab, path.substr(pos));
139}
140
141
152{
153 wxSplitterWindow* splitter = new wxSplitterWindow(this, wxID_ANY);
156 splitter->Initialize(editor);
157 AddPage(splitter, text, false);
158 return editor;
159}
160
161
174NumeReEditor* EditorNotebook::getEditor(size_t pageNum, bool secondary)
175{
176 if (pageNum >= GetPageCount())
177 return nullptr;
178
179 wxSplitterWindow* splitter = static_cast<wxSplitterWindow*>(GetPage(pageNum));
180
181 if (secondary && splitter->GetWindow2())
182 return static_cast<NumeReEditor*>(splitter->GetWindow2());
183 else if (secondary)
184 return nullptr;
185
186 return static_cast<NumeReEditor*>(splitter->GetWindow1());
187}
188
189
204{
205 return getEditor(GetSelection(), secondary);
206}
207
208
220{
221 NumeReEditor* first = getCurrentEditor(false);
222 NumeReEditor* second = getCurrentEditor(true);
223
224 if (second && second->HasFocus())
225 return second;
226
227 return first;
228}
229
230
241void EditorNotebook::split(size_t pageNum, bool horizontal)
242{
243 if (pageNum >= GetPageCount())
244 return;
245
246 wxSplitterWindow* splitter = static_cast<wxSplitterWindow*>(GetPage(pageNum));
247
248 if (!splitter->IsSplit())
249 {
250 NumeReEditor* edit = static_cast<NumeReEditor*>(splitter->GetWindow1());
251 NumeReEditor* secEdit = new NumeReEditor(m_top_parent, m_top_parent->getOptions(), splitter,
253 secEdit->SetDocPointer(edit->GetDocPointer());
254 secEdit->SetFilename(edit->GetFileName(), false);
255 secEdit->ToggleSettings(edit->getSettings());
256 secEdit->UpdateSyntaxHighlighting();
257
259 secEdit->FoldAll();
260
261 secEdit->GotoLine(edit->GetCurrentLine());
262 secEdit->EnsureVisible(edit->GetCurrentLine());
263
264 #if wxUSE_DRAG_AND_DROP
265 secEdit->SetDropTarget(new NumeReDropTarget(m_top_parent, secEdit, NumeReDropTarget::EDITOR));
266 #endif
267
268
269 if (horizontal)
270 splitter->SplitHorizontally(splitter->GetWindow1(), secEdit);
271 else
272 splitter->SplitVertically(splitter->GetWindow1(), secEdit);
273
274 splitter->SetSashGravity(0.5);
275 }
276}
277
278
286void EditorNotebook::unsplit(size_t pageNum)
287{
288 if (pageNum >= GetPageCount())
289 return;
290
291 wxSplitterWindow* splitter = static_cast<wxSplitterWindow*>(GetPage(pageNum));
292
293 if (splitter->IsSplit())
294 {
295 wxWindow* sec = splitter->GetWindow2();
296 splitter->Unsplit(sec);
297 Refresh();
298 sec->Destroy();
299 }
300}
301
302
311bool EditorNotebook::isSplit(size_t pageNum) const
312{
313 if (pageNum >= GetPageCount())
314 return false;
315
316 wxSplitterWindow* splitter = static_cast<wxSplitterWindow*>(GetPage(pageNum));
317
318 return splitter->IsSplit();
319}
320
321
330void EditorNotebook::OnUnsplit(wxSplitterEvent& event)
331{
332 event.GetWindowBeingRemoved()->Destroy();
333}
334
335
344void EditorNotebook::OnTabRightClicked(wxAuiNotebookEvent& event)
345{
346 wxPoint pt = wxGetMousePosition();
347 int pageNum = GetTabFromPoint(pt);
348 pt -= GetScreenRect().GetTopLeft();
349
350 if (pageNum < 0)
351 return;
352
353 g_logger.debug("Clicked on page " + toString(pageNum) + " with title " + GetPageText(pageNum).ToStdString());
354
356 wxString filename = getEditor(pageNum)->GetFileNameAndPath();
357
359 wxMenu popupMenu;
360 popupMenu.Append(ID_MENU_CLOSETAB, _guilang.get("GUI_EDITOR_TAB_CLOSE"));
361 popupMenu.Append(ID_MENU_CLOSEALL, _guilang.get("GUI_EDITOR_TAB_CLOSEALL"));
362 popupMenu.Append(ID_MENU_CLOSEOTHERS, _guilang.get("GUI_EDITOR_TAB_CLOSEOTHERS"));
363 popupMenu.AppendSeparator();
364 popupMenu.Append(ID_MENU_OPEN_FOLDER, _guilang.get("GUI_EDITOR_TAB_OPENFOLDER"));
365 popupMenu.AppendSeparator();
366 popupMenu.Append(ID_MENU_RUN_FROM_TAB, _guilang.get("GUI_TB_RUN"));
367 popupMenu.AppendSeparator();
368
369 if (isSplit(pageNum))
370 popupMenu.Append(ID_MENU_UNSPLIT_TAB, _guilang.get("GUI_EDITOR_TAB_UNSPLIT"));
371 else
372 {
373 wxMenu* splitMenu = new wxMenu();
374 splitMenu->Append(ID_MENU_SPLIT_TAB_H, _guilang.get("GUI_EDITOR_TAB_SPLIT_H"));
375 splitMenu->Append(ID_MENU_SPLIT_TAB_V, _guilang.get("GUI_EDITOR_TAB_SPLIT_V"));
376 popupMenu.Append(wxID_ANY, _guilang.get("GUI_EDITOR_TAB_SPLITTING"), splitMenu);
377 }
378
379 // Append the file revision menu, if the file has revisions
380 if (manager.hasRevisions(filename))
381 {
382 popupMenu.AppendSeparator();
383 popupMenu.Append(ID_MENU_SHOW_REVISIONS_FROM_TAB, _guilang.get("GUI_TREE_PUP_SHOWREVISIONS"));
384 }
385
386 PopupMenu(&popupMenu, pt);
387}
388
389
399void EditorNotebook::OnTabMove(wxAuiNotebookEvent& event)
400{
401 int tab = GetTabFromPoint(wxGetMousePosition());
402
403 if (tab != wxNOT_FOUND)
404 ChangeSelection(tab);
405
406 event.Skip();
407}
408
409
419void EditorNotebook::OnTabScroll(wxMouseEvent &event)
420{
421 wxPoint pt;
422 pt.x = event.GetX();
423 pt.y = event.GetY();
424
425 long flags = 0;
426 int pageNum = this->HitTest (pt, &flags);
427
428 if (pageNum < 0 || GetPageCount() <= 1)
429 return;
430
431 size_t currentPage = GetSelection();
432
433 if (event.GetWheelRotation() < 0)
434 {
435 if (currentPage + 1 == GetPageCount())
436 SetSelection(0);
437 else
438 SetSelection(currentPage+1);
439 }
440 else
441 {
442 if (!currentPage)
443 SetSelection(GetPageCount()-1);
444 else
445 SetSelection(currentPage-1);
446 }
447}
448
449
458void EditorNotebook::OnEnter(wxMouseEvent& event)
459{
460 this->SetFocus();
461 m_mouseFocus = true;
462 event.Skip();
463}
464
465
474void EditorNotebook::OnLeave(wxMouseEvent& event)
475{
476 m_mouseFocus = false;
477 event.Skip();
478}
479
480
488void EditorNotebook::OnSize(wxSizeEvent &event)
489{
490 event.Skip();
491}
492
493
505{
506 wxPoint client_pt = ScreenToClient(pt);
507 wxAuiTabCtrl* tabCtrl = GetTabCtrlFromPoint(client_pt);
508
509 if (!tabCtrl)
510 {
511 g_logger.debug("Found page: false (out of bounds)");
512 return wxNOT_FOUND;
513 }
514
515 wxPoint tl = tabCtrl->GetScreenRect().GetTopLeft();
516 wxWindow* win;
517 bool success = tabCtrl->TabHitTest(pt.x-tl.x, pt.y-tl.y, &win);
518 g_logger.debug("Found page: " + toString(success));
519
520 if (!success)
521 return wxNOT_FOUND;
522
523 return m_tabs.GetIdxFromWindow(win);
524}
525
526
537int EditorNotebook::FindPagePosition(wxNotebookPage* page)
538{
539 int nPageCount = GetPageCount();
540 int nPage;
541 for ( nPage = 0; nPage < nPageCount; nPage++ )
542 if (getEditor(nPage) == page)
543 return nPage;
544 return -1;
545}
546
547
557void EditorNotebook::OnButtonClicked(wxAuiNotebookEvent& event)
558{
559 int pageNum = GetTabFromPoint(wxGetMousePosition());
560
561 if (pageNum < 0)
562 return;
563
564 int evId = ID_MENU_CLOSETAB;
565
566 if (wxGetKeyState(WXK_SHIFT))
568
570
571 wxCommandEvent command;
572 command.SetId(evId);
573 command.SetEventType(wxEVT_MENU); //10019//wxEVT_MIDDLE_UP
574 m_top_parent->GetEventHandler()->ProcessEvent(command);
575}
576
577
586void EditorNotebook::OnTabMiddleClicked(wxAuiNotebookEvent& event)
587{
588 int pageNum = GetTabFromPoint(wxGetMousePosition());
589
590 if (pageNum < 0)
591 return;
592
593 int evId = ID_MENU_CLOSETAB;
594
595 if (wxGetKeyState(WXK_SHIFT))
597
599
600 wxCommandEvent command;
601 command.SetId(evId);
602 command.SetEventType(wxEVT_MENU); //10019//wxEVT_MIDDLE_UP
603 m_top_parent->GetEventHandler()->ProcessEvent(command);
604}
605
606
void debug(const std::string &sMessage)
Convenience member function.
Definition: logger.hpp:94
This class represents the notebook containing all editors of one main pane.
void SetTabText(size_t nTab, const wxString &text)
Set a text for the selected editor tab. Note that this function expects a filepath.
void OnTabScroll(wxMouseEvent &event)
Scrolls through the notebook pages, if the user hovers over the tabs and uses the mouse wheel.
void OnSize(wxSizeEvent &event)
Size event handling function.
void OnUnsplit(wxSplitterEvent &event)
Event handler, if the user drags the sash to the outermost edge.
void OnLeave(wxMouseEvent &event)
Deactivates the internal mouse focus state.
void OnTabRightClicked(wxAuiNotebookEvent &event)
Shows the context menu for the current tab.
void split(size_t pageNum, bool horizontal)
Split the current editor horizontally or vertically (depending on the flag), if it is not already spl...
void OnEnter(wxMouseEvent &event)
Focuses the tabs, if the user hovers over them.
bool isSplit(size_t pageNum) const
Check, whether the editor is currently splitted.
void OnButtonClicked(wxAuiNotebookEvent &event)
Executes the closing command, if the user clickes with the middle mouse button on a tab.
void SetShowPathsOrIconsOnTabs(bool showText, bool showIcons)
This member function enables/disables the relative paths or icons on the tab and refreshes the tab te...
void OnTabMiddleClicked(wxAuiNotebookEvent &event)
Executes the closing command, if the user clickes on the button of a tab.
NumeReEditor * getEditor(size_t pageNum, bool secondary=false)
Returns a pointer to the embedded editor instance. Will return the left or top editor pointer or the ...
void unsplit(size_t pageNum)
Remove the splitted view.
NumeReWindow * m_top_parent
NumeReEditor * createEditor(const wxString &text)
Create a new editor and add it to a new tab automatically. The passed text is used for the tab name.
NumeReEditor * getCurrentEditor(bool secondary=false)
Returns a pointer to the current viewed editor in this notebook. Will return the left or top editor o...
~EditorNotebook()
Empty destructor.
int FindPagePosition(wxNotebookPage *page)
void OnTabMove(wxAuiNotebookEvent &event)
This event handler fixes the issue that the control does not correctly update the selected page durin...
int GetTabFromPoint(const wxPoint &pt)
Returns the tab at the defined absolute coordinates. Actually more or less the same than the generic ...
IconManager * m_manager
NumeReEditor * getFocusedEditor()
Returns a pointer to the current focused editor. This will automatically return the secondary editor,...
NumeReSyntax * getSyntax()
Definition: gterm.hpp:145
int GetIconIndex(wxString iconInfo)
std::string get(const std::string &sMessage, const std::vector< std::string > &vTokens) const
This member function returns the language string for the passed language identifier and replaces all ...
Definition: language.cpp:292
The class of the editor window.
Definition: editor.h:53
int getSettings()
Definition: editor.h:232
void ToggleSettings(int _setting)
Enables or disables an editor setting.
Definition: editor.cpp:2835
void FoldAll()
Folds all fold markers.
Definition: editor.cpp:2207
wxFileName GetFileName()
Definition: editor.cpp:4328
void SetFilename(wxFileName filename, bool fileIsRemote)
Definition: editor.cpp:4246
void UpdateSyntaxHighlighting(bool forceUpdate=false)
Definition: editor.cpp:3573
wxString GetFileNameAndPath()
Definition: editor.cpp:4299
void SetIntVar(int variableName, int value)
std::vector< std::string > getPathDefs()
This member function returns the standard path definitions as a vector.
NumeReTerminal * getTerminal()
Definition: NumeReWindow.h:228
Options * getOptions()
Definition: NumeReWindow.h:245
bool GetFoldDuringLoading() const
Definition: Options.h:267
bool hasRevisions(const wxString &currentFile)
This method detects, whether the selected file has revisions.
Definition: vcsmanager.cpp:90
@ LOADPATH
@ PATH_LAST
@ VN_CLICKEDTAB
@ ID_MENU_CLOSETAB
@ ID_MENU_RUN_FROM_TAB
@ ID_MENU_CLOSEALL
@ ID_MENU_CLOSETABFORCE
@ ID_MENU_OPEN_FOLDER
@ ID_MENU_UNSPLIT_TAB
@ ID_MENU_CLOSEOTHERS
@ ID_MENU_SHOW_REVISIONS_FROM_TAB
@ ID_MENU_SPLIT_TAB_H
@ ID_MENU_SPLIT_TAB_V
Language _guilang
std::string replacePathSeparator(const std::string &)
This function replaces the Windows style path sparators to UNIX style.
DetachedLogger g_logger
Definition: logger.cpp:23
std::string toUpperCase(const std::string &sLowerCase)
Converts lowercase letters to uppercase ones.
std::string toString(int)
Converts an integer to a string without the Settings bloat.
std::string shortenFileName(const std::string &sFullFileName)
This function will return a shortened version of the data file name, where each "/Path/" string part ...
Definition: tools.cpp:3953
END_EVENT_TABLE()