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
This commit is contained in:
harrybharry 2008-06-14 17:36:57 +00:00
parent 673c2f3097
commit 01285fbfbc
5 changed files with 17 additions and 13 deletions

View File

@ -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());

View File

@ -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;

View File

@ -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);

View File

@ -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

View File

@ -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;