StyledEditWindow.cpp revision e056d320
131139022SAxel Dörfler/*
20cc8d8abSSiarzhuk Zharski * Copyright 2002-2012, Haiku, Inc. All Rights Reserved.
331139022SAxel Dörfler * Distributed under the terms of the MIT License.
431139022SAxel Dörfler *
531139022SAxel Dörfler * Authors:
631139022SAxel Dörfler *		Mattias Sundblad
731139022SAxel Dörfler *		Andrew Bachmann
812483e3cSPhilippe Saint-Pierre *		Philippe Saint-Pierre
913e9a630SJonas Sundström *		Jonas Sundstr��m
105d67e2baSRyan Leavengood *		Ryan Leavengood
110cc8d8abSSiarzhuk Zharski *		Vlad Slepukhin
120cc8d8abSSiarzhuk Zharski *		Sarzhuk Zharski
1331139022SAxel Dörfler */
1431139022SAxel Dörfler
15a723b3d4SAxel Dörfler
1631139022SAxel Dörfler#include "ColorMenuItem.h"
170f4985d8SVlad Slepukhin#include "Constants.h"
1831139022SAxel Dörfler#include "FindWindow.h"
1931139022SAxel Dörfler#include "ReplaceWindow.h"
200f4985d8SVlad Slepukhin#include "StatusView.h"
2131139022SAxel Dörfler#include "StyledEditApp.h"
2231139022SAxel Dörfler#include "StyledEditView.h"
2331139022SAxel Dörfler#include "StyledEditWindow.h"
24f7afd44bSPhil Greenway
25f7afd44bSPhil Greenway#include <Alert.h>
26ed48868fSshatty#include <Autolock.h>
27f0da038eSAdrien Destugues#include <Catalog.h>
28f303cd6cSRyan Leavengood#include <CharacterSet.h>
29f303cd6cSRyan Leavengood#include <CharacterSetRoster.h>
30f7afd44bSPhil Greenway#include <Clipboard.h>
31f303cd6cSRyan Leavengood#include <Debug.h>
32f7afd44bSPhil Greenway#include <File.h>
33f303cd6cSRyan Leavengood#include <FilePanel.h>
34a723b3d4SAxel Dörfler#include <fs_attr.h>
35f0da038eSAdrien Destugues#include <Locale.h>
36f7afd44bSPhil Greenway#include <Menu.h>
37f303cd6cSRyan Leavengood#include <MenuBar.h>
38f7afd44bSPhil Greenway#include <MenuItem.h>
390cc8d8abSSiarzhuk Zharski#include <NodeMonitor.h>
4013e9a630SJonas Sundström#include <Path.h>
41f7afd44bSPhil Greenway#include <PrintJob.h>
42e056d320SFreeman Lou#include <RecentItems.h>
43f303cd6cSRyan Leavengood#include <Rect.h>
44b40c9906SRyan Leavengood#include <Roster.h>
459bf722bdSAxel Dörfler#include <Screen.h>
46f7afd44bSPhil Greenway#include <ScrollView.h>
47844ea151Sshatty#include <TextControl.h>
48f303cd6cSRyan Leavengood#include <TextView.h>
49f7afd44bSPhil Greenway#include <TranslationUtils.h>
5015d26d2cSAxel Dörfler#include <UnicodeChar.h>
51f8668ab4SSiarzhuk Zharski#include <UTF8.h>
5242cb481fSSiarzhuk Zharski#include <Volume.h>
53f7afd44bSPhil Greenway
549bf722bdSAxel Dörfler
5546555d8fSshattyusing namespace BPrivate;
5646555d8fSshatty
57ff99f481SAxel Dörfler
588e26769cSRene Gollentconst float kLineViewWidth = 30.0;
59c92efcc0SAxel Dörflerconst char* kInfoAttributeName = "StyledEdit-info";
6031139022SAxel Dörfler
61a723b3d4SAxel Dörfler
62546208a5SOliver Tappe#undef B_TRANSLATION_CONTEXT
63546208a5SOliver Tappe#define B_TRANSLATION_CONTEXT "StyledEditWindow"
64ff99f481SAxel Dörfler
65a723b3d4SAxel Dörfler
669bf722bdSAxel Dörfler// This is a temporary solution for building BString with printf like format.
679bf722bdSAxel Dörfler// will be removed in the future.
689bf722bdSAxel Dörflerstatic void
699bf722bdSAxel Dörflerbs_printf(BString* string, const char* format, ...)
709bf722bdSAxel Dörfler{
719bf722bdSAxel Dörfler	va_list ap;
729bf722bdSAxel Dörfler	va_start(ap, format);
739bf722bdSAxel Dörfler	char* buf;
749bf722bdSAxel Dörfler	vasprintf(&buf, format, ap);
759bf722bdSAxel Dörfler	string->SetTo(buf);
769bf722bdSAxel Dörfler	free(buf);
779bf722bdSAxel Dörfler	va_end(ap);
789bf722bdSAxel Dörfler}
799bf722bdSAxel Dörfler
809bf722bdSAxel Dörfler
819bf722bdSAxel Dörfler// #pragma mark -
829bf722bdSAxel Dörfler
839bf722bdSAxel Dörfler
84670567f9SshattyStyledEditWindow::StyledEditWindow(BRect frame, int32 id, uint32 encoding)
8556a7c23dSAxel Dörfler	: BWindow(frame, "untitled", B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS)
86ed48868fSshatty{
875188c282SAxel Dörfler	_InitWindow(encoding);
88906db303SMatt Madia	BString unTitled(B_TRANSLATE("Untitled "));
89ed48868fSshatty	unTitled << id;
90ed48868fSshatty	SetTitle(unTitled.String());
9131139022SAxel Dörfler	fSaveItem->SetEnabled(true);
9231139022SAxel Dörfler		// allow saving empty files
93ed48868fSshatty	Show();
9431139022SAxel Dörfler}
9531139022SAxel Dörfler
96f7afd44bSPhil Greenway
97f0da038eSAdrien DestuguesStyledEditWindow::StyledEditWindow(BRect frame, entry_ref* ref, uint32 encoding)
9856a7c23dSAxel Dörfler	: BWindow(frame, "untitled", B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS)
99ed48868fSshatty{
1005188c282SAxel Dörfler	_InitWindow(encoding);
101ed48868fSshatty	OpenFile(ref);
102ed48868fSshatty	Show();
10331139022SAxel Dörfler}
10431139022SAxel Dörfler
10531139022SAxel Dörfler
106ed48868fSshattyStyledEditWindow::~StyledEditWindow()
107ed48868fSshatty{
108d727a85bSshatty	delete fSaveMessage;
109d727a85bSshatty	delete fPrintSettings;
110f7afd44bSPhil Greenway	delete fSavePanel;
11131139022SAxel Dörfler}
11231139022SAxel Dörfler
11331139022SAxel Dörfler
1145188c282SAxel Dörflervoid
1155188c282SAxel DörflerStyledEditWindow::Quit()
1165188c282SAxel Dörfler{
1170cc8d8abSSiarzhuk Zharski	_SwitchNodeMonitor(false);
1180cc8d8abSSiarzhuk Zharski
1195188c282SAxel Dörfler	_SaveAttrs();
1205188c282SAxel Dörfler	if (StyledEditApp* app = dynamic_cast<StyledEditApp*>(be_app))
1215188c282SAxel Dörfler		app->CloseDocument();
1225188c282SAxel Dörfler	BWindow::Quit();
1235188c282SAxel Dörfler}
1245188c282SAxel Dörfler
1255188c282SAxel Dörfler
126546208a5SOliver Tappe#undef B_TRANSLATION_CONTEXT
127546208a5SOliver Tappe#define B_TRANSLATION_CONTEXT "QuitAlert"
128f0da038eSAdrien Destugues
129a723b3d4SAxel Dörfler
1305188c282SAxel Dörflerbool
1315188c282SAxel DörflerStyledEditWindow::QuitRequested()
132ed48868fSshatty{
1335188c282SAxel Dörfler	if (fClean)
1345188c282SAxel Dörfler		return true;
13531139022SAxel Dörfler
1360cc8d8abSSiarzhuk Zharski	if (fTextView->TextLength() == 0 && fSaveMessage == NULL)
1370cc8d8abSSiarzhuk Zharski		return true;
1380cc8d8abSSiarzhuk Zharski
1395188c282SAxel Dörfler	BString alertText;
1405188c282SAxel Dörfler	bs_printf(&alertText,
1415188c282SAxel Dörfler		B_TRANSLATE("Save changes to the document \"%s\"? "), Title());
14231139022SAxel Dörfler
1435188c282SAxel Dörfler	int32 index = _ShowAlert(alertText, B_TRANSLATE("Cancel"),
1445188c282SAxel Dörfler		B_TRANSLATE("Don't save"), B_TRANSLATE("Save"),	B_WARNING_ALERT);
14531139022SAxel Dörfler
1465188c282SAxel Dörfler	if (index == 0)
1475188c282SAxel Dörfler		return false;	// "cancel": dont save, dont close the window
14831139022SAxel Dörfler
1495188c282SAxel Dörfler	if (index == 1)
1505188c282SAxel Dörfler		return true;	// "don't save": just close the window
151f7afd44bSPhil Greenway
1525188c282SAxel Dörfler	if (!fSaveMessage) {
1535188c282SAxel Dörfler		SaveAs(new BMessage(SAVE_THEN_QUIT));
1545188c282SAxel Dörfler		return false;
1555188c282SAxel Dörfler	}
15631139022SAxel Dörfler
1575188c282SAxel Dörfler	return Save() == B_OK;
1585188c282SAxel Dörfler}
15914ea5e5eSKarsten Heimrich
16031139022SAxel Dörfler
1615188c282SAxel Dörflervoid
1625188c282SAxel DörflerStyledEditWindow::MessageReceived(BMessage* message)
1635188c282SAxel Dörfler{
1645188c282SAxel Dörfler	if (message->WasDropped()) {
1655188c282SAxel Dörfler		entry_ref ref;
1665188c282SAxel Dörfler		if (message->FindRef("refs", 0, &ref)==B_OK) {
1675188c282SAxel Dörfler			message->what = B_REFS_RECEIVED;
1685188c282SAxel Dörfler			be_app->PostMessage(message);
1695188c282SAxel Dörfler		}
1705188c282SAxel Dörfler	}
17131139022SAxel Dörfler
1725188c282SAxel Dörfler	switch (message->what) {
1735188c282SAxel Dörfler		// File menu
1745188c282SAxel Dörfler		case MENU_SAVE:
1755188c282SAxel Dörfler			if (!fSaveMessage)
1765188c282SAxel Dörfler				SaveAs();
1775188c282SAxel Dörfler			else
1785188c282SAxel Dörfler				Save(fSaveMessage);
1795188c282SAxel Dörfler			break;
180a723b3d4SAxel Dörfler
1815188c282SAxel Dörfler		case MENU_SAVEAS:
1825188c282SAxel Dörfler			SaveAs();
1835188c282SAxel Dörfler			break;
18431139022SAxel Dörfler
1855188c282SAxel Dörfler		case B_SAVE_REQUESTED:
1865188c282SAxel Dörfler			Save(message);
1875188c282SAxel Dörfler			break;
18814ea5e5eSKarsten Heimrich
1895188c282SAxel Dörfler		case SAVE_THEN_QUIT:
1905188c282SAxel Dörfler			if (Save(message) == B_OK)
1915188c282SAxel Dörfler				Quit();
1925188c282SAxel Dörfler			break;
19331139022SAxel Dörfler
1940cc8d8abSSiarzhuk Zharski		case MENU_RELOAD:
1950cc8d8abSSiarzhuk Zharski			_ReloadDocument(message);
1965188c282SAxel Dörfler			break;
19731139022SAxel Dörfler
1985188c282SAxel Dörfler		case MENU_CLOSE:
1995188c282SAxel Dörfler			if (QuitRequested())
2005188c282SAxel Dörfler				Quit();
2015188c282SAxel Dörfler			break;
20231139022SAxel Dörfler
2035188c282SAxel Dörfler		case MENU_PAGESETUP:
2045188c282SAxel Dörfler			PageSetup(fTextView->Window()->Title());
2055188c282SAxel Dörfler			break;
2065188c282SAxel Dörfler		case MENU_PRINT:
2075188c282SAxel Dörfler			Print(fTextView->Window()->Title());
2085188c282SAxel Dörfler			break;
2095188c282SAxel Dörfler		case MENU_QUIT:
2105188c282SAxel Dörfler			be_app->PostMessage(B_QUIT_REQUESTED);
2115188c282SAxel Dörfler			break;
21231139022SAxel Dörfler
2135188c282SAxel Dörfler		// Edit menu
21431139022SAxel Dörfler
2155188c282SAxel Dörfler		case B_UNDO:
2165188c282SAxel Dörfler			ASSERT(fCanUndo || fCanRedo);
2175188c282SAxel Dörfler			ASSERT(!(fCanUndo && fCanRedo));
2185188c282SAxel Dörfler			if (fCanUndo)
2195188c282SAxel Dörfler				fUndoFlag = true;
2205188c282SAxel Dörfler			if (fCanRedo)
2215188c282SAxel Dörfler				fRedoFlag = true;
22231139022SAxel Dörfler
2235188c282SAxel Dörfler			fTextView->Undo(be_clipboard);
2245188c282SAxel Dörfler			break;
2255188c282SAxel Dörfler		case B_CUT:
2265188c282SAxel Dörfler			fTextView->Cut(be_clipboard);
2275188c282SAxel Dörfler			break;
2285188c282SAxel Dörfler		case B_COPY:
2295188c282SAxel Dörfler			fTextView->Copy(be_clipboard);
2305188c282SAxel Dörfler			break;
2315188c282SAxel Dörfler		case B_PASTE:
2325188c282SAxel Dörfler			fTextView->Paste(be_clipboard);
2335188c282SAxel Dörfler			break;
2345188c282SAxel Dörfler		case MENU_CLEAR:
2355188c282SAxel Dörfler			fTextView->Clear();
2365188c282SAxel Dörfler			break;
2375188c282SAxel Dörfler		case MENU_FIND:
2385188c282SAxel Dörfler		{
2395188c282SAxel Dörfler			BRect findWindowFrame(100, 100, 400, 235);
2405188c282SAxel Dörfler			BWindow* window = new FindWindow(findWindowFrame, this,
2415188c282SAxel Dörfler				&fStringToFind, fCaseSensitive, fWrapAround, fBackSearch);
2425188c282SAxel Dörfler			window->Show();
2435188c282SAxel Dörfler			break;
2445188c282SAxel Dörfler		}
2455188c282SAxel Dörfler		case MSG_SEARCH:
2465188c282SAxel Dörfler			message->FindString("findtext", &fStringToFind);
2475188c282SAxel Dörfler			fFindAgainItem->SetEnabled(true);
2485188c282SAxel Dörfler			message->FindBool("casesens", &fCaseSensitive);
2495188c282SAxel Dörfler			message->FindBool("wrap", &fWrapAround);
2505188c282SAxel Dörfler			message->FindBool("backsearch", &fBackSearch);
25131139022SAxel Dörfler
2525188c282SAxel Dörfler			_Search(fStringToFind, fCaseSensitive, fWrapAround, fBackSearch);
2535188c282SAxel Dörfler			break;
2545188c282SAxel Dörfler		case MENU_FIND_AGAIN:
2555188c282SAxel Dörfler			_Search(fStringToFind, fCaseSensitive, fWrapAround, fBackSearch);
2565188c282SAxel Dörfler			break;
2575188c282SAxel Dörfler		case MENU_FIND_SELECTION:
2585188c282SAxel Dörfler			_FindSelection();
2595188c282SAxel Dörfler			break;
2605188c282SAxel Dörfler		case MENU_REPLACE:
2615188c282SAxel Dörfler		{
2625188c282SAxel Dörfler			BRect replaceWindowFrame(100, 100, 400, 284);
2635188c282SAxel Dörfler			BWindow* window = new ReplaceWindow(replaceWindowFrame, this,
2645188c282SAxel Dörfler				&fStringToFind, &fReplaceString, fCaseSensitive, fWrapAround,
2655188c282SAxel Dörfler				fBackSearch);
2665188c282SAxel Dörfler			window->Show();
2675188c282SAxel Dörfler			break;
2685188c282SAxel Dörfler		}
2695188c282SAxel Dörfler		case MSG_REPLACE:
2705188c282SAxel Dörfler		{
2715188c282SAxel Dörfler			message->FindBool("casesens", &fCaseSensitive);
2725188c282SAxel Dörfler			message->FindBool("wrap", &fWrapAround);
2735188c282SAxel Dörfler			message->FindBool("backsearch", &fBackSearch);
274f7afd44bSPhil Greenway
2755188c282SAxel Dörfler			message->FindString("FindText", &fStringToFind);
2765188c282SAxel Dörfler			message->FindString("ReplaceText", &fReplaceString);
277f7afd44bSPhil Greenway
2785188c282SAxel Dörfler			fFindAgainItem->SetEnabled(true);
2795188c282SAxel Dörfler			fReplaceSameItem->SetEnabled(true);
28031139022SAxel Dörfler
2815188c282SAxel Dörfler			_Replace(fStringToFind, fReplaceString, fCaseSensitive, fWrapAround,
2825188c282SAxel Dörfler				fBackSearch);
2835188c282SAxel Dörfler			break;
2845188c282SAxel Dörfler		}
2855188c282SAxel Dörfler		case MENU_REPLACE_SAME:
2865188c282SAxel Dörfler			_Replace(fStringToFind, fReplaceString, fCaseSensitive, fWrapAround,
2875188c282SAxel Dörfler				fBackSearch);
2885188c282SAxel Dörfler			break;
28931139022SAxel Dörfler
2905188c282SAxel Dörfler		case MSG_REPLACE_ALL:
2915188c282SAxel Dörfler		{
2925188c282SAxel Dörfler			message->FindBool("casesens", &fCaseSensitive);
2938a85cd4cSSiarzhuk Zharski			message->FindString("FindText", &fStringToFind);
2948a85cd4cSSiarzhuk Zharski			message->FindString("ReplaceText", &fReplaceString);
29531139022SAxel Dörfler
2965188c282SAxel Dörfler			bool allWindows;
2975188c282SAxel Dörfler			message->FindBool("allwindows", &allWindows);
29831139022SAxel Dörfler
2995188c282SAxel Dörfler			fFindAgainItem->SetEnabled(true);
3005188c282SAxel Dörfler			fReplaceSameItem->SetEnabled(true);
30131139022SAxel Dörfler
3025188c282SAxel Dörfler			if (allWindows)
3035188c282SAxel Dörfler				SearchAllWindows(fStringToFind, fReplaceString, fCaseSensitive);
3045188c282SAxel Dörfler			else
3055188c282SAxel Dörfler				_ReplaceAll(fStringToFind, fReplaceString, fCaseSensitive);
3065188c282SAxel Dörfler			break;
3075188c282SAxel Dörfler		}
30831139022SAxel Dörfler
3090cc8d8abSSiarzhuk Zharski		case B_NODE_MONITOR:
3100cc8d8abSSiarzhuk Zharski			_HandleNodeMonitorEvent(message);
3110cc8d8abSSiarzhuk Zharski			break;
3120cc8d8abSSiarzhuk Zharski
3135188c282SAxel Dörfler		// Font menu
31414ea5e5eSKarsten Heimrich
3155188c282SAxel Dörfler		case FONT_SIZE:
3165188c282SAxel Dörfler		{
3175188c282SAxel Dörfler			float fontSize;
3185188c282SAxel Dörfler			if (message->FindFloat("size", &fontSize) == B_OK)
3195188c282SAxel Dörfler				_SetFontSize(fontSize);
3205188c282SAxel Dörfler			break;
3215188c282SAxel Dörfler		}
3225188c282SAxel Dörfler		case FONT_FAMILY:
3235188c282SAxel Dörfler		{
3245188c282SAxel Dörfler			const char* fontFamily = NULL;
3255188c282SAxel Dörfler			const char* fontStyle = NULL;
3265188c282SAxel Dörfler			void* ptr;
3275188c282SAxel Dörfler			if (message->FindPointer("source", &ptr) == B_OK) {
3285188c282SAxel Dörfler				BMenuItem* item = static_cast<BMenuItem*>(ptr);
3295188c282SAxel Dörfler				fontFamily = item->Label();
3305188c282SAxel Dörfler			}
331d2ff9616SAxel Dörfler
332d2ff9616SAxel Dörfler			BFont font;
333d2ff9616SAxel Dörfler			font.SetFamilyAndStyle(fontFamily, fontStyle);
334d2ff9616SAxel Dörfler			fItalicItem->SetMarked((font.Face() & B_ITALIC_FACE) != 0);
335d2ff9616SAxel Dörfler			fBoldItem->SetMarked((font.Face() & B_BOLD_FACE) != 0);
336d2ff9616SAxel Dörfler
3375188c282SAxel Dörfler			_SetFontStyle(fontFamily, fontStyle);
3385188c282SAxel Dörfler			break;
3395188c282SAxel Dörfler		}
3405188c282SAxel Dörfler		case FONT_STYLE:
3415188c282SAxel Dörfler		{
3425188c282SAxel Dörfler			const char* fontFamily = NULL;
3435188c282SAxel Dörfler			const char* fontStyle = NULL;
3445188c282SAxel Dörfler			void* ptr;
3455188c282SAxel Dörfler			if (message->FindPointer("source", &ptr) == B_OK) {
3465188c282SAxel Dörfler				BMenuItem* item = static_cast<BMenuItem*>(ptr);
3475188c282SAxel Dörfler				fontStyle = item->Label();
3485188c282SAxel Dörfler				BMenu* menu = item->Menu();
3495188c282SAxel Dörfler				if (menu != NULL) {
3505188c282SAxel Dörfler					BMenuItem* super_item = menu->Superitem();
3515188c282SAxel Dörfler					if (super_item != NULL)
3525188c282SAxel Dörfler						fontFamily = super_item->Label();
3535188c282SAxel Dörfler				}
3545188c282SAxel Dörfler			}
355d2ff9616SAxel Dörfler
356d2ff9616SAxel Dörfler			BFont font;
357d2ff9616SAxel Dörfler			font.SetFamilyAndStyle(fontFamily, fontStyle);
358d2ff9616SAxel Dörfler			fItalicItem->SetMarked((font.Face() & B_ITALIC_FACE) != 0);
359d2ff9616SAxel Dörfler			fBoldItem->SetMarked((font.Face() & B_BOLD_FACE) != 0);
360d2ff9616SAxel Dörfler
3615188c282SAxel Dörfler			_SetFontStyle(fontFamily, fontStyle);
3625188c282SAxel Dörfler			break;
3635188c282SAxel Dörfler		}
364d2ff9616SAxel Dörfler		case kMsgSetItalic:
365d2ff9616SAxel Dörfler		{
366d2ff9616SAxel Dörfler			uint32 sameProperties;
367d2ff9616SAxel Dörfler			BFont font;
368d2ff9616SAxel Dörfler			fTextView->GetFontAndColor(&font, &sameProperties);
369d2ff9616SAxel Dörfler
370d2ff9616SAxel Dörfler			if (fItalicItem->IsMarked())
371d2ff9616SAxel Dörfler				font.SetFace(B_REGULAR_FACE);
372d2ff9616SAxel Dörfler			fItalicItem->SetMarked(!fItalicItem->IsMarked());
373d2ff9616SAxel Dörfler
374d2ff9616SAxel Dörfler			font_family family;
375d2ff9616SAxel Dörfler			font_style style;
376d2ff9616SAxel Dörfler			font.GetFamilyAndStyle(&family, &style);
377d2ff9616SAxel Dörfler
378d2ff9616SAxel Dörfler			_SetFontStyle(family, style);
379d2ff9616SAxel Dörfler			break;
380d2ff9616SAxel Dörfler		}
381d2ff9616SAxel Dörfler		case kMsgSetBold:
382d2ff9616SAxel Dörfler		{
383d2ff9616SAxel Dörfler			uint32 sameProperties;
384d2ff9616SAxel Dörfler			BFont font;
385d2ff9616SAxel Dörfler			fTextView->GetFontAndColor(&font, &sameProperties);
386d2ff9616SAxel Dörfler
387d2ff9616SAxel Dörfler			if (fBoldItem->IsMarked())
388d2ff9616SAxel Dörfler				font.SetFace(B_REGULAR_FACE);
389d2ff9616SAxel Dörfler			fBoldItem->SetMarked(!fBoldItem->IsMarked());
390d2ff9616SAxel Dörfler
391d2ff9616SAxel Dörfler			font_family family;
392d2ff9616SAxel Dörfler			font_style style;
393d2ff9616SAxel Dörfler			font.GetFamilyAndStyle(&family, &style);
394d2ff9616SAxel Dörfler
395d2ff9616SAxel Dörfler			_SetFontStyle(family, style);
396d2ff9616SAxel Dörfler			break;
397d2ff9616SAxel Dörfler		}
3985188c282SAxel Dörfler		case FONT_COLOR:
3995188c282SAxel Dörfler		{
4005188c282SAxel Dörfler			void* ptr;
4015188c282SAxel Dörfler			if (message->FindPointer("source", &ptr) == B_OK) {
4025188c282SAxel Dörfler				if (ptr == fBlackItem)
4035188c282SAxel Dörfler					_SetFontColor(&BLACK);
4045188c282SAxel Dörfler				else if (ptr == fRedItem)
4055188c282SAxel Dörfler					_SetFontColor(&RED);
4065188c282SAxel Dörfler				else if (ptr == fGreenItem)
4075188c282SAxel Dörfler					_SetFontColor(&GREEN);
4085188c282SAxel Dörfler				else if (ptr == fBlueItem)
4095188c282SAxel Dörfler					_SetFontColor(&BLUE);
4105188c282SAxel Dörfler				else if (ptr == fCyanItem)
4115188c282SAxel Dörfler					_SetFontColor(&CYAN);
4125188c282SAxel Dörfler				else if (ptr == fMagentaItem)
4135188c282SAxel Dörfler					_SetFontColor(&MAGENTA);
4145188c282SAxel Dörfler				else if (ptr == fYellowItem)
4155188c282SAxel Dörfler					_SetFontColor(&YELLOW);
4165188c282SAxel Dörfler			}
4175188c282SAxel Dörfler			break;
4185188c282SAxel Dörfler		}
41931139022SAxel Dörfler
4205188c282SAxel Dörfler		// Document menu
4215188c282SAxel Dörfler
4225188c282SAxel Dörfler		case ALIGN_LEFT:
4235188c282SAxel Dörfler			fTextView->SetAlignment(B_ALIGN_LEFT);
4245188c282SAxel Dörfler			_UpdateCleanUndoRedoSaveRevert();
4255188c282SAxel Dörfler			break;
4265188c282SAxel Dörfler		case ALIGN_CENTER:
4275188c282SAxel Dörfler			fTextView->SetAlignment(B_ALIGN_CENTER);
4285188c282SAxel Dörfler			_UpdateCleanUndoRedoSaveRevert();
4295188c282SAxel Dörfler			break;
4305188c282SAxel Dörfler		case ALIGN_RIGHT:
4315188c282SAxel Dörfler			fTextView->SetAlignment(B_ALIGN_RIGHT);
4325188c282SAxel Dörfler			_UpdateCleanUndoRedoSaveRevert();
4335188c282SAxel Dörfler			break;
4345188c282SAxel Dörfler		case WRAP_LINES:
4355188c282SAxel Dörfler		{
4365188c282SAxel Dörfler			BRect textRect(fTextView->Bounds());
4375188c282SAxel Dörfler			textRect.OffsetTo(B_ORIGIN);
4385188c282SAxel Dörfler			textRect.InsetBy(TEXT_INSET, TEXT_INSET);
4395188c282SAxel Dörfler			if (fTextView->DoesWordWrap()) {
4405188c282SAxel Dörfler				fTextView->SetWordWrap(false);
4415188c282SAxel Dörfler				fWrapItem->SetMarked(false);
4425188c282SAxel Dörfler				// the width comes from stylededit R5. TODO: find a better way
4435188c282SAxel Dörfler				textRect.SetRightBottom(BPoint(1500.0, textRect.RightBottom().y));
4445188c282SAxel Dörfler			} else {
4455188c282SAxel Dörfler				fTextView->SetWordWrap(true);
4465188c282SAxel Dörfler				fWrapItem->SetMarked(true);
4475188c282SAxel Dörfler			}
4485188c282SAxel Dörfler			fTextView->SetTextRect(textRect);
4495188c282SAxel Dörfler
4505188c282SAxel Dörfler			_UpdateCleanUndoRedoSaveRevert();
4515188c282SAxel Dörfler			break;
4525188c282SAxel Dörfler		}
4535188c282SAxel Dörfler		case SHOW_STATISTICS:
4545188c282SAxel Dörfler			_ShowStatistics();
4555188c282SAxel Dörfler			break;
4565188c282SAxel Dörfler		case ENABLE_ITEMS:
4575188c282SAxel Dörfler			fCutItem->SetEnabled(true);
4585188c282SAxel Dörfler			fCopyItem->SetEnabled(true);
4595188c282SAxel Dörfler			break;
4605188c282SAxel Dörfler		case DISABLE_ITEMS:
4615188c282SAxel Dörfler			fCutItem->SetEnabled(false);
4625188c282SAxel Dörfler			fCopyItem->SetEnabled(false);
4635188c282SAxel Dörfler			break;
4645188c282SAxel Dörfler		case TEXT_CHANGED:
4655188c282SAxel Dörfler			if (fUndoFlag) {
4665188c282SAxel Dörfler				if (fUndoCleans) {
4675188c282SAxel Dörfler					// we cleaned!
4685188c282SAxel Dörfler					fClean = true;
4695188c282SAxel Dörfler					fUndoCleans = false;
4705188c282SAxel Dörfler				} else if (fClean) {
4715188c282SAxel Dörfler					// if we were clean
4725188c282SAxel Dörfler					// then a redo will make us clean again
4735188c282SAxel Dörfler					fRedoCleans = true;
4745188c282SAxel Dörfler					fClean = false;
4755188c282SAxel Dörfler				}
4765188c282SAxel Dörfler				// set mode
4775188c282SAxel Dörfler				fCanUndo = false;
4785188c282SAxel Dörfler				fCanRedo = true;
4795188c282SAxel Dörfler				fUndoItem->SetLabel(B_TRANSLATE("Redo typing"));
4805188c282SAxel Dörfler				fUndoItem->SetEnabled(true);
4815188c282SAxel Dörfler				fUndoFlag = false;
4825188c282SAxel Dörfler			} else {
4835188c282SAxel Dörfler				if (fRedoFlag && fRedoCleans) {
4845188c282SAxel Dörfler					// we cleaned!
4855188c282SAxel Dörfler					fClean = true;
4865188c282SAxel Dörfler					fRedoCleans = false;
4875188c282SAxel Dörfler				} else if (fClean) {
4885188c282SAxel Dörfler					// if we were clean
4895188c282SAxel Dörfler					// then an undo will make us clean again
4905188c282SAxel Dörfler					fUndoCleans = true;
4915188c282SAxel Dörfler					fClean = false;
4925188c282SAxel Dörfler				} else {
4935188c282SAxel Dörfler					// no more cleaning from undo now...
4945188c282SAxel Dörfler					fUndoCleans = false;
4955188c282SAxel Dörfler				}
4965188c282SAxel Dörfler				// set mode
4975188c282SAxel Dörfler				fCanUndo = true;
4985188c282SAxel Dörfler				fCanRedo = false;
4995188c282SAxel Dörfler				fUndoItem->SetLabel(B_TRANSLATE("Undo typing"));
5005188c282SAxel Dörfler				fUndoItem->SetEnabled(true);
5015188c282SAxel Dörfler				fRedoFlag = false;
5025188c282SAxel Dörfler			}
5035188c282SAxel Dörfler			if (fClean) {
5045188c282SAxel Dörfler				fSaveItem->SetEnabled(fSaveMessage == NULL);
5055188c282SAxel Dörfler			} else {
5065188c282SAxel Dörfler				fSaveItem->SetEnabled(true);
5075188c282SAxel Dörfler			}
5080cc8d8abSSiarzhuk Zharski			fReloadItem->SetEnabled(fSaveMessage != NULL);
5090cc8d8abSSiarzhuk Zharski			fEncodingItem->SetEnabled(fSaveMessage != NULL);
5105188c282SAxel Dörfler			break;
5115188c282SAxel Dörfler
5125188c282SAxel Dörfler		case SAVE_AS_ENCODING:
5135188c282SAxel Dörfler			void* ptr;
5145188c282SAxel Dörfler			if (message->FindPointer("source", &ptr) == B_OK
5155188c282SAxel Dörfler				&& fSavePanelEncodingMenu != NULL) {
5165188c282SAxel Dörfler				fTextView->SetEncoding(
5175188c282SAxel Dörfler					(uint32)fSavePanelEncodingMenu->IndexOf((BMenuItem*)ptr));
5185188c282SAxel Dörfler			}
5195188c282SAxel Dörfler			break;
5205188c282SAxel Dörfler
5210f4985d8SVlad Slepukhin		case UPDATE_STATUS:
52242cb481fSSiarzhuk Zharski		{
5230f4985d8SVlad Slepukhin			message->AddBool("modified", !fClean);
52442cb481fSSiarzhuk Zharski			bool readOnly = !fTextView->IsEditable();
52542cb481fSSiarzhuk Zharski			message->AddBool("readOnly", readOnly);
52642cb481fSSiarzhuk Zharski			if (readOnly) {
52742cb481fSSiarzhuk Zharski				BVolume volume(fNodeRef.device);
52842cb481fSSiarzhuk Zharski				message->AddBool("canUnlock", !volume.IsReadOnly());
52942cb481fSSiarzhuk Zharski			}
5300f4985d8SVlad Slepukhin			fStatusView->SetStatus(message);
5310f4985d8SVlad Slepukhin			break;
53242cb481fSSiarzhuk Zharski		}
5330f4985d8SVlad Slepukhin
5340f4985d8SVlad Slepukhin		case UNLOCK_FILE:
5350f4985d8SVlad Slepukhin		{
5360f4985d8SVlad Slepukhin			status_t status = _UnlockFile();
5370f4985d8SVlad Slepukhin			if (status != B_OK) {
5380f4985d8SVlad Slepukhin				BString text;
5390f4985d8SVlad Slepukhin				bs_printf(&text,
5400f4985d8SVlad Slepukhin					B_TRANSLATE("Unable to unlock file\n\t%s"),
5410f4985d8SVlad Slepukhin					strerror(status));
5420f4985d8SVlad Slepukhin				_ShowAlert(text, B_TRANSLATE("OK"), "", "", B_STOP_ALERT);
5430f4985d8SVlad Slepukhin			}
5440f4985d8SVlad Slepukhin			PostMessage(UPDATE_STATUS);
5450f4985d8SVlad Slepukhin			break;
5460f4985d8SVlad Slepukhin		}
5470f4985d8SVlad Slepukhin
548c7087c91SSiarzhuk Zharski		case UPDATE_LINE_SELECTION:
54946f1daffSVlad Slepukhin		{
55046f1daffSVlad Slepukhin			int32 line;
55146f1daffSVlad Slepukhin			if (message->FindInt32("be:line", &line) == B_OK) {
55246f1daffSVlad Slepukhin				fTextView->GoToLine(line);
55346f1daffSVlad Slepukhin				fTextView->ScrollToSelection();
55446f1daffSVlad Slepukhin			}
55546f1daffSVlad Slepukhin
55646f1daffSVlad Slepukhin			int32 start, length;
55746f1daffSVlad Slepukhin			if (message->FindInt32("be:selection_offset", &start) == B_OK) {
55846f1daffSVlad Slepukhin				if (message->FindInt32("be:selection_length", &length) != B_OK)
55946f1daffSVlad Slepukhin					length = 0;
56046f1daffSVlad Slepukhin
56146f1daffSVlad Slepukhin				fTextView->Select(start, start + length);
56246f1daffSVlad Slepukhin				fTextView->ScrollToOffset(start);
56346f1daffSVlad Slepukhin			}
56446f1daffSVlad Slepukhin			break;
56546f1daffSVlad Slepukhin		}
5665188c282SAxel Dörfler		default:
5675188c282SAxel Dörfler			BWindow::MessageReceived(message);
5685188c282SAxel Dörfler			break;
56931139022SAxel Dörfler	}
5705188c282SAxel Dörfler}
57114ea5e5eSKarsten Heimrich
57214ea5e5eSKarsten Heimrich
5735188c282SAxel Dörflervoid
5745188c282SAxel DörflerStyledEditWindow::MenusBeginning()
5755188c282SAxel Dörfler{
5765188c282SAxel Dörfler	// update the font menu
5775188c282SAxel Dörfler	// unselect the old values
5785188c282SAxel Dörfler	if (fCurrentFontItem != NULL) {
5795188c282SAxel Dörfler		fCurrentFontItem->SetMarked(false);
5805188c282SAxel Dörfler		BMenu* menu = fCurrentFontItem->Submenu();
5815188c282SAxel Dörfler		if (menu != NULL) {
5825188c282SAxel Dörfler			BMenuItem* item = menu->FindMarked();
5832cfeb3caSJohn Scipione			if (item != NULL)
5845188c282SAxel Dörfler				item->SetMarked(false);
5855188c282SAxel Dörfler		}
5865188c282SAxel Dörfler	}
58731139022SAxel Dörfler
5885188c282SAxel Dörfler	if (fCurrentStyleItem != NULL) {
5895188c282SAxel Dörfler		fCurrentStyleItem->SetMarked(false);
5905188c282SAxel Dörfler	}
5915188c282SAxel Dörfler
5925188c282SAxel Dörfler	BMenuItem* oldColorItem = fFontColorMenu->FindMarked();
5935188c282SAxel Dörfler	if (oldColorItem != NULL)
5945188c282SAxel Dörfler		oldColorItem->SetMarked(false);
5955188c282SAxel Dörfler
5965188c282SAxel Dörfler	BMenuItem* oldSizeItem = fFontSizeMenu->FindMarked();
5975188c282SAxel Dörfler	if (oldSizeItem != NULL)
5985188c282SAxel Dörfler		oldSizeItem->SetMarked(false);
5995188c282SAxel Dörfler
6005188c282SAxel Dörfler	// find the current font, color, size
6015188c282SAxel Dörfler	BFont font;
6025188c282SAxel Dörfler	uint32 sameProperties;
6035188c282SAxel Dörfler	rgb_color color = BLACK;
6045188c282SAxel Dörfler	bool sameColor;
6055188c282SAxel Dörfler	fTextView->GetFontAndColor(&font, &sameProperties, &color, &sameColor);
6062cfeb3caSJohn Scipione	color.alpha = 255;
6075188c282SAxel Dörfler
6082cfeb3caSJohn Scipione	if (sameColor) {
6092cfeb3caSJohn Scipione		// mark the menu according to the current color
6105188c282SAxel Dörfler		if (color.red == 0) {
6115188c282SAxel Dörfler			if (color.green == 0) {
6125188c282SAxel Dörfler				if (color.blue == 0) {
6135188c282SAxel Dörfler					fBlackItem->SetMarked(true);
6145188c282SAxel Dörfler				} else if (color.blue == 255) {
6155188c282SAxel Dörfler					fBlueItem->SetMarked(true);
6165188c282SAxel Dörfler				}
6175188c282SAxel Dörfler			} else if (color.green == 255) {
6185188c282SAxel Dörfler				if (color.blue == 0) {
6195188c282SAxel Dörfler					fGreenItem->SetMarked(true);
6205188c282SAxel Dörfler				} else if (color.blue == 255) {
6215188c282SAxel Dörfler					fCyanItem->SetMarked(true);
6225188c282SAxel Dörfler				}
6235188c282SAxel Dörfler			}
6245188c282SAxel Dörfler		} else if (color.red == 255) {
6255188c282SAxel Dörfler			if (color.green == 0) {
6265188c282SAxel Dörfler				if (color.blue == 0) {
6275188c282SAxel Dörfler					fRedItem->SetMarked(true);
6285188c282SAxel Dörfler				} else if (color.blue == 255) {
6295188c282SAxel Dörfler					fMagentaItem->SetMarked(true);
6305188c282SAxel Dörfler				}
6315188c282SAxel Dörfler			} else if (color.green == 255) {
6325188c282SAxel Dörfler				if (color.blue == 0) {
6335188c282SAxel Dörfler					fYellowItem->SetMarked(true);
634f7afd44bSPhil Greenway				}
635f7afd44bSPhil Greenway			}
636f7afd44bSPhil Greenway		}
63731139022SAxel Dörfler	}
63831139022SAxel Dörfler
6395188c282SAxel Dörfler	if (sameProperties & B_FONT_SIZE) {
6405188c282SAxel Dörfler		if ((int)font.Size() == font.Size()) {
6415188c282SAxel Dörfler			// select the current font size
6425188c282SAxel Dörfler			char fontSizeStr[16];
6435188c282SAxel Dörfler			snprintf(fontSizeStr, 15, "%i", (int)font.Size());
6445188c282SAxel Dörfler			BMenuItem* item = fFontSizeMenu->FindItem(fontSizeStr);
6455188c282SAxel Dörfler			if (item != NULL)
6465188c282SAxel Dörfler				item->SetMarked(true);
6475188c282SAxel Dörfler		}
6485188c282SAxel Dörfler	}
6495188c282SAxel Dörfler
6505188c282SAxel Dörfler	font_family family;
6515188c282SAxel Dörfler	font_style style;
6525188c282SAxel Dörfler	font.GetFamilyAndStyle(&family, &style);
6535188c282SAxel Dörfler
6545188c282SAxel Dörfler	fCurrentFontItem = fFontMenu->FindItem(family);
6555188c282SAxel Dörfler
6565188c282SAxel Dörfler	if (fCurrentFontItem != NULL) {
6575188c282SAxel Dörfler		fCurrentFontItem->SetMarked(true);
6585188c282SAxel Dörfler		BMenu* menu = fCurrentFontItem->Submenu();
6595188c282SAxel Dörfler		if (menu != NULL) {
6605188c282SAxel Dörfler			BMenuItem* item = menu->FindItem(style);
6615188c282SAxel Dörfler			fCurrentStyleItem = item;
662d2ff9616SAxel Dörfler			if (fCurrentStyleItem != NULL)
6635188c282SAxel Dörfler				item->SetMarked(true);
6645188c282SAxel Dörfler		}
6655188c282SAxel Dörfler	}
6665188c282SAxel Dörfler
667d2ff9616SAxel Dörfler	fBoldItem->SetMarked((font.Face() & B_BOLD_FACE) != 0);
668d2ff9616SAxel Dörfler	fItalicItem->SetMarked((font.Face() & B_ITALIC_FACE) != 0);
669d2ff9616SAxel Dörfler
6705188c282SAxel Dörfler	switch (fTextView->Alignment()) {
6715188c282SAxel Dörfler		case B_ALIGN_LEFT:
6725188c282SAxel Dörfler		default:
6735188c282SAxel Dörfler			fAlignLeft->SetMarked(true);
6745188c282SAxel Dörfler			break;
6755188c282SAxel Dörfler		case B_ALIGN_CENTER:
6765188c282SAxel Dörfler			fAlignCenter->SetMarked(true);
6775188c282SAxel Dörfler			break;
6785188c282SAxel Dörfler		case B_ALIGN_RIGHT:
6795188c282SAxel Dörfler			fAlignRight->SetMarked(true);
6805188c282SAxel Dörfler			break;
6815188c282SAxel Dörfler	}
6820cc8d8abSSiarzhuk Zharski
6830cc8d8abSSiarzhuk Zharski	// text encoding
6840cc8d8abSSiarzhuk Zharski	const BCharacterSet* charset
6850cc8d8abSSiarzhuk Zharski		= BCharacterSetRoster::GetCharacterSetByFontID(fTextView->GetEncoding());
6860cc8d8abSSiarzhuk Zharski	BMenu* encodingMenu = fEncodingItem->Submenu();
6870cc8d8abSSiarzhuk Zharski	if (charset != NULL && encodingMenu != NULL) {
6880cc8d8abSSiarzhuk Zharski		const char* mime = charset->GetMIMEName();
6890cc8d8abSSiarzhuk Zharski		BString name(charset->GetPrintName());
6900cc8d8abSSiarzhuk Zharski		if (mime)
6910cc8d8abSSiarzhuk Zharski			name << " (" << mime << ")";
6920cc8d8abSSiarzhuk Zharski
6930cc8d8abSSiarzhuk Zharski		BMenuItem* item = encodingMenu->FindItem(name);
6940cc8d8abSSiarzhuk Zharski		if (item != NULL)
6950cc8d8abSSiarzhuk Zharski			item->SetMarked(true);
6960cc8d8abSSiarzhuk Zharski	}
6975188c282SAxel Dörfler}
6985188c282SAxel Dörfler
6995188c282SAxel Dörfler
700546208a5SOliver Tappe#undef B_TRANSLATION_CONTEXT
701546208a5SOliver Tappe#define B_TRANSLATION_CONTEXT "SaveAlert"
7025188c282SAxel Dörfler
7035188c282SAxel Dörfler
7045188c282SAxel Dörflerstatus_t
7055188c282SAxel DörflerStyledEditWindow::Save(BMessage* message)
7065188c282SAxel Dörfler{
7070cc8d8abSSiarzhuk Zharski	_NodeMonitorSuspender nodeMonitorSuspender(this);
7080cc8d8abSSiarzhuk Zharski
7095188c282SAxel Dörfler	if (!message)
7105188c282SAxel Dörfler		message = fSaveMessage;
7115188c282SAxel Dörfler
7125188c282SAxel Dörfler	if (!message)
7135188c282SAxel Dörfler		return B_ERROR;
7145188c282SAxel Dörfler
7155188c282SAxel Dörfler	entry_ref dirRef;
7165188c282SAxel Dörfler	const char* name;
7175188c282SAxel Dörfler	if (message->FindRef("directory", &dirRef) != B_OK
7185188c282SAxel Dörfler		|| message->FindString("name", &name) != B_OK)
7195188c282SAxel Dörfler		return B_BAD_VALUE;
7205188c282SAxel Dörfler
7215188c282SAxel Dörfler	BDirectory dir(&dirRef);
7225188c282SAxel Dörfler	BEntry entry(&dir, name);
7235188c282SAxel Dörfler
7245188c282SAxel Dörfler	status_t status = B_ERROR;
7255188c282SAxel Dörfler	if (dir.InitCheck() == B_OK && entry.InitCheck() == B_OK) {
7265188c282SAxel Dörfler		struct stat st;
7275188c282SAxel Dörfler		BFile file(&entry, B_READ_WRITE | B_CREATE_FILE);
7285188c282SAxel Dörfler		if (file.InitCheck() == B_OK
7295188c282SAxel Dörfler			&& (status = file.GetStat(&st)) == B_OK) {
7305188c282SAxel Dörfler			// check the file permissions
7315188c282SAxel Dörfler			if (!((getuid() == st.st_uid && (S_IWUSR & st.st_mode))
7325188c282SAxel Dörfler				|| (getgid() == st.st_gid && (S_IWGRP & st.st_mode))
7335188c282SAxel Dörfler				|| (S_IWOTH & st.st_mode))) {
7345188c282SAxel Dörfler				BString alertText;
7355188c282SAxel Dörfler				bs_printf(&alertText, B_TRANSLATE("This file is marked "
736776c58b2SHumdinger					"read-only. Save changes to the document \"%s\"? "), name);
7375188c282SAxel Dörfler				switch (_ShowAlert(alertText, B_TRANSLATE("Cancel"),
7385188c282SAxel Dörfler						B_TRANSLATE("Don't save"),
7395188c282SAxel Dörfler						B_TRANSLATE("Save"), B_WARNING_ALERT)) {
7405188c282SAxel Dörfler					case 0:
7415188c282SAxel Dörfler						return B_CANCELED;
7425188c282SAxel Dörfler					case 1:
7435188c282SAxel Dörfler						return B_OK;
7445188c282SAxel Dörfler					default:
7455188c282SAxel Dörfler						break;
7465188c282SAxel Dörfler				}
7475188c282SAxel Dörfler			}
7485188c282SAxel Dörfler
7495188c282SAxel Dörfler			status = fTextView->WriteStyledEditFile(&file);
7505188c282SAxel Dörfler		}
7515188c282SAxel Dörfler	}
7525188c282SAxel Dörfler
7535188c282SAxel Dörfler	if (status != B_OK) {
7545188c282SAxel Dörfler		BString alertText;
7555188c282SAxel Dörfler		bs_printf(&alertText, B_TRANSLATE("Error saving \"%s\":\n%s"), name,
7565188c282SAxel Dörfler			strerror(status));
75731139022SAxel Dörfler
7585188c282SAxel Dörfler		_ShowAlert(alertText, B_TRANSLATE("OK"), "", "", B_STOP_ALERT);
7595188c282SAxel Dörfler		return status;
7605188c282SAxel Dörfler	}
7610b46ec98Sshatty
7625188c282SAxel Dörfler	SetTitle(name);
76331139022SAxel Dörfler
7645188c282SAxel Dörfler	if (fSaveMessage != message) {
7655188c282SAxel Dörfler		delete fSaveMessage;
7665188c282SAxel Dörfler		fSaveMessage = new BMessage(*message);
7675188c282SAxel Dörfler	}
76831139022SAxel Dörfler
7695188c282SAxel Dörfler	// clear clean modes
7705188c282SAxel Dörfler	fSaveItem->SetEnabled(false);
7715188c282SAxel Dörfler	fUndoCleans = false;
7725188c282SAxel Dörfler	fRedoCleans = false;
7735188c282SAxel Dörfler	fClean = true;
7740cc8d8abSSiarzhuk Zharski	fNagOnNodeChange = true;
7750cc8d8abSSiarzhuk Zharski
77641d5d7c8SSiarzhuk Zharski	PostMessage(UPDATE_STATUS);
7775188c282SAxel Dörfler	return status;
77831139022SAxel Dörfler}
77931139022SAxel Dörfler
7808f63353bSshatty
781546208a5SOliver Tappe#undef B_TRANSLATION_CONTEXT
782546208a5SOliver Tappe#define B_TRANSLATION_CONTEXT "Open_and_SaveAsPanel"
783a723b3d4SAxel Dörfler
784a723b3d4SAxel Dörfler
7855188c282SAxel Dörflerstatus_t
7865188c282SAxel DörflerStyledEditWindow::SaveAs(BMessage* message)
7875188c282SAxel Dörfler{
7885188c282SAxel Dörfler	if (fSavePanel == NULL) {
7895188c282SAxel Dörfler		entry_ref* directory = NULL;
7905b9003c7SRyan Leavengood		entry_ref dirRef;
7915188c282SAxel Dörfler		if (fSaveMessage != NULL) {
7925188c282SAxel Dörfler			if (fSaveMessage->FindRef("directory", &dirRef) == B_OK)
7935188c282SAxel Dörfler				directory = &dirRef;
7945188c282SAxel Dörfler		}
795a723b3d4SAxel Dörfler
7965188c282SAxel Dörfler		BMessenger target(this);
7975188c282SAxel Dörfler		fSavePanel = new BFilePanel(B_SAVE_PANEL, &target,
798