From 01285fbfbcdd989a8da5a8e3a868c55aeb58b6d0 Mon Sep 17 00:00:00 2001 From: harrybharry Date: Sat, 14 Jun 2008 17:36:57 +0000 Subject: [PATCH] attachDefaultDoc now in Scintilla::init(). (fix crash on startup because buffer == NULL) git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@233 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/Notepad_plus.cpp | 11 +++++------ PowerEditor/src/ScitillaComponent/Buffer.cpp | 5 +++-- PowerEditor/src/ScitillaComponent/Buffer.h | 5 ++++- .../src/ScitillaComponent/ScintillaEditView.cpp | 5 +++-- PowerEditor/src/ScitillaComponent/ScintillaEditView.h | 4 ++-- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 43d1f58e..3318df87 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -5533,6 +5533,9 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa } case WM_CREATE: { + _fileEditView.init(_hInst, hwnd); + MainFileManager->init(this, &_fileEditView); //get it up and running asap. + pNppParam->setFontList(hwnd); NppGUI & nppGUI = (NppGUI &)pNppParam->getNppGUI(); @@ -5553,9 +5556,6 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa _mainEditView.init(_hInst, hwnd); _subEditView.init(_hInst, hwnd); - _fileEditView.init(_hInst, hwnd); - - MainFileManager->init(this, &_fileEditView); //get it up and running asap. int tabBarStatus = nppGUI._tabStatus; _toReduceTabBar = ((tabBarStatus & TAB_REDUCE) != 0); @@ -5678,7 +5678,6 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa _dockingManager.init(_hInst, hwnd, &_pMainWindow); //dynamicCheckMenuAndTB(); - _mainEditView.defineDocType(L_TXT); if (nppGUI._isMinimizedToTray) _pTrayIco = new trayIconControler(_hSelf, IDI_M30ICON, IDC_MINIMIZED_TRAY, ::LoadIcon(_hInst, MAKEINTRESOURCE(IDI_M30ICON)), ""); @@ -5955,8 +5954,8 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa } //Load initial docs into doctab - loadBufferIntoView(_mainEditView.attachDefaultDoc(), MAIN_VIEW); - loadBufferIntoView(_subEditView.attachDefaultDoc(), SUB_VIEW); + loadBufferIntoView(_mainEditView.getCurrentBufferID(), MAIN_VIEW); + loadBufferIntoView(_subEditView.getCurrentBufferID(), SUB_VIEW); MainFileManager->increaseDocNr(); //so next doc starts at 2 ::SetFocus(_mainEditView.getHSelf()); diff --git a/PowerEditor/src/ScitillaComponent/Buffer.cpp b/PowerEditor/src/ScitillaComponent/Buffer.cpp index 4adc3e55..19be43c3 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScitillaComponent/Buffer.cpp @@ -485,11 +485,12 @@ BufferID FileManager::newEmptyDocument() { return id; } -BufferID FileManager::bufferFromDocument(Document doc, bool dontIncrease) { +BufferID FileManager::bufferFromDocument(Document doc, bool dontIncrease, bool dontRef) { char newTitle[10]; strcpy(newTitle, UNTITLED_STR); itoa(_nextNewNumber, newTitle+4, 10); - _pscratchTilla->execute(SCI_ADDREFDOCUMENT, 0, doc); //set reference for FileManager + if (!dontRef) + _pscratchTilla->execute(SCI_ADDREFDOCUMENT, 0, doc); //set reference for FileManager Buffer * newBuf = new Buffer(this, _nextBufferID, doc, DOC_UNNAMED, newTitle); BufferID id = (BufferID)newBuf; newBuf->_id = id; diff --git a/PowerEditor/src/ScitillaComponent/Buffer.h b/PowerEditor/src/ScitillaComponent/Buffer.h index f311fea9..099ee3cd 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.h +++ b/PowerEditor/src/ScitillaComponent/Buffer.h @@ -76,7 +76,10 @@ public: BufferID loadFile(const char * filename, Document doc = NULL); //ID == BUFFER_INVALID on failure. If Doc == NULL, a new file is created, otherwise data is loaded in given document BufferID newEmptyDocument(); - BufferID bufferFromDocument(Document doc, bool dontIncrease = false); //create Buffer from existing Scintilla, used from new Scintillas. If dontIncrease = true, then the new document number isnt increased afterwards. usefull for temporary but neccesary docs + //create Buffer from existing Scintilla, used from new Scintillas. If dontIncrease = true, then the new document number isnt increased afterwards. + //usefull for temporary but neccesary docs + //If dontRef = false, then no extra reference is added for the doc. Its the responsibility of the caller to do so + BufferID bufferFromDocument(Document doc, bool dontIncrease = false, bool dontRef = false); BufferID getBufferFromName(const char * name); diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp index 4fb2d86e..a999cb17 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp @@ -196,7 +196,7 @@ void ScintillaEditView::init(HINSTANCE hInst, HWND hPere) } //Get the startup document and make a buffer for it so it can be accessed like a file - //attachDefaultDoc(); //Let Notepad_plus do it + attachDefaultDoc(); } LRESULT ScintillaEditView::scintillaNew_Proc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) @@ -946,7 +946,8 @@ BufferID ScintillaEditView::attachDefaultDoc() { // get the doc pointer attached (by default) on the view Scintilla Document doc = execute(SCI_GETDOCPOINTER, 0, 0); - BufferID id = MainFileManager->bufferFromDocument(doc, false);//true); //keep counter on 1 + execute(SCI_ADDREFDOCUMENT, 0, doc); + BufferID id = MainFileManager->bufferFromDocument(doc, false, true);//true, true); //keep counter on 1 Buffer * buf = MainFileManager->getBufferByID(id); MainFileManager->addBufferReference(id, this); //add a reference. Notepad only shows the buffer in tabbar diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h index ca40a7da..316fe5a0 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h @@ -173,8 +173,6 @@ public: defineDocType(L_USER); };*/ - BufferID attachDefaultDoc(); - void getText(char *dest, int start, int end) const; void saveCurrentPos(); @@ -538,6 +536,8 @@ protected: static WNDPROC _scintillaDefaultProc; CallWindowProcFunc _callWindowProc; + BufferID attachDefaultDoc(); + //Store the current buffer so it can be retrieved later BufferID _currentBufferID; Buffer * _currentBuffer;