From 56a7c23d08827465e53e93ac452d436fbaf6ef7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 2 Jun 2006 15:20:18 +0000 Subject: [PATCH] * StyledEditWindow::_LoadFile() now traverses symlinks when opening a file. This fixes bug #593. * No longer opens an empty document for every non existing path - it now only opens a new document if there is none yet. * No longer open an empty document for non existing files - instead, it just passes the ref to StyledEditApp::OpenDocument(). StyledEditWindow::_LoadFile() now treats those files gently as well, so that you can create new documents via StyledEdit as on BeOS without getting annoyed too much. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17699 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/stylededit/StyledEditApp.cpp | 16 ++++++++-------- src/apps/stylededit/StyledEditWindow.cpp | 23 +++++++++++++++++++---- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/apps/stylededit/StyledEditApp.cpp b/src/apps/stylededit/StyledEditApp.cpp index 32680cd342..b29d1e306a 100644 --- a/src/apps/stylededit/StyledEditApp.cpp +++ b/src/apps/stylededit/StyledEditApp.cpp @@ -66,6 +66,9 @@ uncascade() } +// #pragma mark - + + StyledEditApp::StyledEditApp() : BApplication(APP_SIGNATURE) { @@ -216,15 +219,13 @@ StyledEditApp::ArgvReceived(int32 argc, const char* argv[], const char* cwd) } entry_ref ref; - if (get_ref_for_path(path.Path(), &ref) != B_OK) { - fprintf(stderr, "Entry not found: \"%s\".\n", path.Path()); + status_t status = get_ref_for_path(path.Path(), &ref); + if (status != B_OK) { + fprintf(stderr, "Could not open \"%s\": %s.\n", path.Path(), strerror(status)); continue; } - BEntry entry(&ref); - if (entry.IsFile()) - OpenDocument(&ref); - else if (fWindowCount == 0) - OpenDocument(); + + OpenDocument(&ref); } } @@ -241,7 +242,6 @@ int32 StyledEditApp::NumberOfWindows() { return fWindowCount; - } diff --git a/src/apps/stylededit/StyledEditWindow.cpp b/src/apps/stylededit/StyledEditWindow.cpp index 1f8fc70156..51b98a03bd 100644 --- a/src/apps/stylededit/StyledEditWindow.cpp +++ b/src/apps/stylededit/StyledEditWindow.cpp @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -35,12 +34,13 @@ #include #include +#include using namespace BPrivate; StyledEditWindow::StyledEditWindow(BRect frame, int32 id, uint32 encoding) - : BWindow(frame,"untitled",B_DOCUMENT_WINDOW,0) + : BWindow(frame, "untitled", B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS) { InitWindow(encoding); BString unTitled; @@ -54,7 +54,7 @@ StyledEditWindow::StyledEditWindow(BRect frame, int32 id, uint32 encoding) StyledEditWindow::StyledEditWindow(BRect frame, entry_ref *ref, uint32 encoding) - : BWindow(frame,"untitled",B_DOCUMENT_WINDOW,0) + : BWindow(frame, "untitled", B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS) { InitWindow(encoding); OpenFile(ref); @@ -940,12 +940,27 @@ StyledEditWindow::SaveAs(BMessage *message) status_t StyledEditWindow::_LoadFile(entry_ref* ref) { + BEntry entry(ref, true); + // traverse an eventual link + + status_t status = entry.InitCheck(); + if (status == B_OK && entry.IsDirectory()) + status = B_IS_A_DIRECTORY; + BFile file; - status_t status = file.SetTo(ref, B_READ_ONLY); + if (status == B_OK) + status = file.SetTo(&entry, B_READ_ONLY); if (status == B_OK) status = fTextView->GetStyledText(&file); + if (status == B_ENTRY_NOT_FOUND) { + // Treat non-existing files consideratley; we just want to get an + // empty window for them - to create this new document + status = B_OK; + } + if (status != B_OK) { + // If an error occured, bail out and tell the user what happened BEntry entry(ref, true); char name[B_FILE_NAME_LENGTH]; if (entry.GetName(name) != B_OK)