StyledEditWindow.cpp revision 0f4985d8
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>
42f303cd6cSRyan Leavengood#include <Rect.h>
43b40c9906SRyan Leavengood#include <Roster.h>
449bf722bdSAxel Dörfler#include <Screen.h>
45f7afd44bSPhil Greenway#include <ScrollView.h>
46844ea151Sshatty#include <TextControl.h>
47f303cd6cSRyan Leavengood#include <TextView.h>
48f7afd44bSPhil Greenway#include <TranslationUtils.h>
4915d26d2cSAxel Dörfler#include <UnicodeChar.h>
50f7afd44bSPhil Greenway
519bf722bdSAxel Dörfler
5246555d8fSshattyusing namespace BPrivate;
5346555d8fSshatty
54ff99f481SAxel Dörfler
558e26769cSRene Gollentconst float kLineViewWidth = 30.0;
56c92efcc0SAxel Dörflerconst char* kInfoAttributeName = "StyledEdit-info";
5731139022SAxel Dörfler
58a723b3d4SAxel Dörfler
59546208a5SOliver Tappe#undef B_TRANSLATION_CONTEXT
60546208a5SOliver Tappe#define B_TRANSLATION_CONTEXT "StyledEditWindow"
61ff99f481SAxel Dörfler
62a723b3d4SAxel Dörfler
639bf722bdSAxel Dörfler// This is a temporary solution for building BString with printf like format.
649bf722bdSAxel Dörfler// will be removed in the future.
659bf722bdSAxel Dörflerstatic void
669bf722bdSAxel Dörflerbs_printf(BString* string, const char* format, ...)
679bf722bdSAxel Dörfler{
689bf722bdSAxel Dörfler	va_list ap;
699bf722bdSAxel Dörfler	va_start(ap, format);
709bf722bdSAxel Dörfler	char* buf;
719bf722bdSAxel Dörfler	vasprintf(&buf, format, ap);
729bf722bdSAxel Dörfler	string->SetTo(buf);
739bf722bdSAxel Dörfler	free(buf);
749bf722bdSAxel Dörfler	va_end(ap);
759bf722bdSAxel Dörfler}
769bf722bdSAxel Dörfler
779bf722bdSAxel Dörfler
789bf722bdSAxel Dörfler// #pragma mark -
799bf722bdSAxel Dörfler
809bf722bdSAxel Dörfler
81670567f9SshattyStyledEditWindow::StyledEditWindow(BRect frame, int32 id, uint32 encoding)
8256a7c23dSAxel Dörfler	: BWindow(frame, "untitled", B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS)
83ed48868fSshatty{
845188c282SAxel Dörfler	_InitWindow(encoding);
85906db303SMatt Madia	BString unTitled(B_TRANSLATE("Untitled "));
86ed48868fSshatty	unTitled << id;
87ed48868fSshatty	SetTitle(unTitled.String());
8831139022SAxel Dörfler	fSaveItem->SetEnabled(true);
8931139022SAxel Dörfler		// allow saving empty files
90ed48868fSshatty	Show();
9131139022SAxel Dörfler}
9231139022SAxel Dörfler
93f7afd44bSPhil Greenway
94f0da038eSAdrien DestuguesStyledEditWindow::StyledEditWindow(BRect frame, entry_ref* ref, uint32 encoding)
9556a7c23dSAxel Dörfler	: BWindow(frame, "untitled", B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS)
96ed48868fSshatty{
975188c282SAxel Dörfler	_InitWindow(encoding);
98ed48868fSshatty	OpenFile(ref);
99ed48868fSshatty	Show();
10031139022SAxel Dörfler}
10131139022SAxel Dörfler
10231139022SAxel Dörfler
103ed48868fSshattyStyledEditWindow::~StyledEditWindow()
104ed48868fSshatty{
105d727a85bSshatty	delete fSaveMessage;
106d727a85bSshatty	delete fPrintSettings;
107f7afd44bSPhil Greenway	delete fSavePanel;
10831139022SAxel Dörfler}
10931139022SAxel Dörfler
11031139022SAxel Dörfler
1115188c282SAxel Dörflervoid
1125188c282SAxel DörflerStyledEditWindow::Quit()
1135188c282SAxel Dörfler{
1140cc8d8abSSiarzhuk Zharski	_SwitchNodeMonitor(false);
1150cc8d8abSSiarzhuk Zharski
1165188c282SAxel Dörfler	_SaveAttrs();
1175188c282SAxel Dörfler	if (StyledEditApp* app = dynamic_cast<StyledEditApp*>(be_app))
1185188c282SAxel Dörfler		app->CloseDocument();
1195188c282SAxel Dörfler	BWindow::Quit();
1205188c282SAxel Dörfler}
1215188c282SAxel Dörfler
1225188c282SAxel Dörfler
123546208a5SOliver Tappe#undef B_TRANSLATION_CONTEXT
124546208a5SOliver Tappe#define B_TRANSLATION_CONTEXT "QuitAlert"
125f0da038eSAdrien Destugues
126a723b3d4SAxel Dörfler
1275188c282SAxel Dörflerbool
1285188c282SAxel DörflerStyledEditWindow::QuitRequested()
129ed48868fSshatty{
1305188c282SAxel Dörfler	if (fClean)
1315188c282SAxel Dörfler		return true;
13231139022SAxel Dörfler
1330cc8d8abSSiarzhuk Zharski	if (fTextView->TextLength() == 0 && fSaveMessage == NULL)
1340cc8d8abSSiarzhuk Zharski		return true;
1350cc8d8abSSiarzhuk Zharski
1365188c282SAxel Dörfler	BString alertText;
1375188c282SAxel Dörfler	bs_printf(&alertText,
1385188c282SAxel Dörfler		B_TRANSLATE("Save changes to the document \"%s\"? "), Title());
13931139022SAxel Dörfler
1405188c282SAxel Dörfler	int32 index = _ShowAlert(alertText, B_TRANSLATE("Cancel"),
1415188c282SAxel Dörfler		B_TRANSLATE("Don't save"), B_TRANSLATE("Save"),	B_WARNING_ALERT);
14231139022SAxel Dörfler
1435188c282SAxel Dörfler	if (index == 0)
1445188c282SAxel Dörfler		return false;	// "cancel": dont save, dont close the window
14531139022SAxel Dörfler
1465188c282SAxel Dörfler	if (index == 1)
1475188c282SAxel Dörfler		return true;	// "don't save": just close the window
148f7afd44bSPhil Greenway
1495188c282SAxel Dörfler	if (!fSaveMessage) {
1505188c282SAxel Dörfler		SaveAs(new BMessage(SAVE_THEN_QUIT));
1515188c282SAxel Dörfler		return false;
1525188c282SAxel Dörfler	}
15331139022SAxel Dörfler
1545188c282SAxel Dörfler	return Save() == B_OK;
1555188c282SAxel Dörfler}
15614ea5e5eSKarsten Heimrich
15731139022SAxel Dörfler
1585188c282SAxel Dörflervoid
1595188c282SAxel DörflerStyledEditWindow::MessageReceived(BMessage* message)
1605188c282SAxel Dörfler{
1615188c282SAxel Dörfler	if (message->WasDropped()) {
1625188c282SAxel Dörfler		entry_ref ref;
1635188c282SAxel Dörfler		if (message->FindRef("refs", 0, &ref)==B_OK) {
1645188c282SAxel Dörfler			message->what = B_REFS_RECEIVED;
1655188c282SAxel Dörfler			be_app->PostMessage(message);
1665188c282SAxel Dörfler		}
1675188c282SAxel Dörfler	}
16831139022SAxel Dörfler
1695188c282SAxel Dörfler	switch (message->what) {
1705188c282SAxel Dörfler		// File menu
1715188c282SAxel Dörfler		case MENU_SAVE:
1725188c282SAxel Dörfler			if (!fSaveMessage)
1735188c282SAxel Dörfler				SaveAs();
1745188c282SAxel Dörfler			else
1755188c282SAxel Dörfler				Save(fSaveMessage);
1765188c282SAxel Dörfler			break;
177a723b3d4SAxel Dörfler
1785188c282SAxel Dörfler		case MENU_SAVEAS:
1795188c282SAxel Dörfler			SaveAs();
1805188c282SAxel Dörfler			break;
18131139022SAxel Dörfler
1825188c282SAxel Dörfler		case B_SAVE_REQUESTED:
1835188c282SAxel Dörfler			Save(message);
1845188c282SAxel Dörfler			break;
18514ea5e5eSKarsten Heimrich
1865188c282SAxel Dörfler		case SAVE_THEN_QUIT:
1875188c282SAxel Dörfler			if (Save(message) == B_OK)
1885188c282SAxel Dörfler				Quit();
1895188c282SAxel Dörfler			break;
19031139022SAxel Dörfler
1910cc8d8abSSiarzhuk Zharski		case MENU_RELOAD:
1920cc8d8abSSiarzhuk Zharski			_ReloadDocument(message);
1935188c282SAxel Dörfler			break;
19431139022SAxel Dörfler
1955188c282SAxel Dörfler		case MENU_CLOSE:
1965188c282SAxel Dörfler			if (QuitRequested())
1975188c282SAxel Dörfler				Quit();
1985188c282SAxel Dörfler			break;
19931139022SAxel Dörfler
2005188c282SAxel Dörfler		case MENU_PAGESETUP:
2015188c282SAxel Dörfler			PageSetup(fTextView->Window()->Title());
2025188c282SAxel Dörfler			break;
2035188c282SAxel Dörfler		case MENU_PRINT:
2045188c282SAxel Dörfler			Print(fTextView->Window()->Title());
2055188c282SAxel Dörfler			break;
2065188c282SAxel Dörfler		case MENU_QUIT:
2075188c282SAxel Dörfler			be_app->PostMessage(B_QUIT_REQUESTED);
2085188c282SAxel Dörfler			break;
20931139022SAxel Dörfler
2105188c282SAxel Dörfler		// Edit menu
21131139022SAxel Dörfler
2125188c282SAxel Dörfler		case B_UNDO:
2135188c282SAxel Dörfler			ASSERT(fCanUndo || fCanRedo);
2145188c282SAxel Dörfler			ASSERT(!(fCanUndo && fCanRedo));
2155188c282SAxel Dörfler			if (fCanUndo)
2165188c282SAxel Dörfler				fUndoFlag = true;
2175188c282SAxel Dörfler			if (fCanRedo)
2185188c282SAxel Dörfler				fRedoFlag = true;
21931139022SAxel Dörfler
2205188c282SAxel Dörfler			fTextView->Undo(be_clipboard);
2215188c282SAxel Dörfler			break;
2225188c282SAxel Dörfler		case B_CUT:
2235188c282SAxel Dörfler			fTextView->Cut(be_clipboard);
2245188c282SAxel Dörfler			break;
2255188c282SAxel Dörfler		case B_COPY:
2265188c282SAxel Dörfler			fTextView->Copy(be_clipboard);
2275188c282SAxel Dörfler			break;
2285188c282SAxel Dörfler		case B_PASTE:
2295188c282SAxel Dörfler			fTextView->Paste(be_clipboard);
2305188c282SAxel Dörfler			break;
2315188c282SAxel Dörfler		case MENU_CLEAR:
2325188c282SAxel Dörfler			fTextView->Clear();
2335188c282SAxel Dörfler			break;
2345188c282SAxel Dörfler		case MENU_FIND:
2355188c282SAxel Dörfler		{
2365188c282SAxel Dörfler			BRect findWindowFrame(100, 100, 400, 235);
2375188c282SAxel Dörfler			BWindow* window = new FindWindow(findWindowFrame, this,
2385188c282SAxel Dörfler				&fStringToFind, fCaseSensitive, fWrapAround, fBackSearch);
2395188c282SAxel Dörfler			window->Show();
2405188c282SAxel Dörfler			break;
2415188c282SAxel Dörfler		}
2425188c282SAxel Dörfler		case MSG_SEARCH:
2435188c282SAxel Dörfler			message->FindString("findtext", &fStringToFind);
2445188c282SAxel Dörfler			fFindAgainItem->SetEnabled(true);
2455188c282SAxel Dörfler			message->FindBool("casesens", &fCaseSensitive);
2465188c282SAxel Dörfler			message->FindBool("wrap", &fWrapAround);
2475188c282SAxel Dörfler			message->FindBool("backsearch", &fBackSearch);
24831139022SAxel Dörfler
2495188c282SAxel Dörfler			_Search(fStringToFind, fCaseSensitive, fWrapAround, fBackSearch);
2505188c282SAxel Dörfler			break;
2515188c282SAxel Dörfler		case MENU_FIND_AGAIN:
2525188c282SAxel Dörfler			_Search(fStringToFind, fCaseSensitive, fWrapAround, fBackSearch);
2535188c282SAxel Dörfler			break;
2545188c282SAxel Dörfler		case MENU_FIND_SELECTION:
2555188c282SAxel Dörfler			_FindSelection();
2565188c282SAxel Dörfler			break;
2575188c282SAxel Dörfler		case MENU_REPLACE:
2585188c282SAxel Dörfler		{
2595188c282SAxel Dörfler			BRect replaceWindowFrame(100, 100, 400, 284);
2605188c282SAxel Dörfler			BWindow* window = new ReplaceWindow(replaceWindowFrame, this,
2615188c282SAxel Dörfler				&fStringToFind, &fReplaceString, fCaseSensitive, fWrapAround,
2625188c282SAxel Dörfler				fBackSearch);
2635188c282SAxel Dörfler			window->Show();
2645188c282SAxel Dörfler			break;
2655188c282SAxel Dörfler		}
2665188c282SAxel Dörfler		case MSG_REPLACE:
2675188c282SAxel Dörfler		{
2685188c282SAxel Dörfler			message->FindBool("casesens", &fCaseSensitive);
2695188c282SAxel Dörfler			message->FindBool("wrap", &fWrapAround);
2705188c282SAxel Dörfler			message->FindBool("backsearch", &fBackSearch);
271f7afd44bSPhil Greenway
2725188c282SAxel Dörfler			message->FindString("FindText", &fStringToFind);
2735188c282SAxel Dörfler			message->FindString("ReplaceText", &fReplaceString);
274f7afd44bSPhil Greenway
2755188c282SAxel Dörfler			fFindAgainItem->SetEnabled(true);
2765188c282SAxel Dörfler			fReplaceSameItem->SetEnabled(true);
27731139022SAxel Dörfler
2785188c282SAxel Dörfler			_Replace(fStringToFind, fReplaceString, fCaseSensitive, fWrapAround,
2795188c282SAxel Dörfler				fBackSearch);
2805188c282SAxel Dörfler			break;
2815188c282SAxel Dörfler		}
2825188c282SAxel Dörfler		case MENU_REPLACE_SAME:
2835188c282SAxel Dörfler			_Replace(fStringToFind, fReplaceString, fCaseSensitive, fWrapAround,
2845188c282SAxel Dörfler				fBackSearch);
2855188c282SAxel Dörfler			break;
28631139022SAxel Dörfler
2875188c282SAxel Dörfler		case MSG_REPLACE_ALL:
2885188c282SAxel Dörfler		{
2895188c282SAxel Dörfler			message->FindBool("casesens", &fCaseSensitive);
2905188c282SAxel Dörfler			message->FindString("FindText",&fStringToFind);
2915188c282SAxel Dörfler			message->FindString("ReplaceText",&fReplaceString);
29231139022SAxel Dörfler
2935188c282SAxel Dörfler			bool allWindows;
2945188c282SAxel Dörfler			message->FindBool("allwindows", &allWindows);
29531139022SAxel Dörfler
2965188c282SAxel Dörfler			fFindAgainItem->SetEnabled(true);
2975188c282SAxel Dörfler			fReplaceSameItem->SetEnabled(true);
29831139022SAxel Dörfler
2995188c282SAxel Dörfler			if (allWindows)
3005188c282SAxel Dörfler				SearchAllWindows(fStringToFind, fReplaceString, fCaseSensitive);
3015188c282SAxel Dörfler			else
3025188c282SAxel Dörfler				_ReplaceAll(fStringToFind, fReplaceString, fCaseSensitive);
3035188c282SAxel Dörfler			break;
3045188c282SAxel Dörfler		}
30531139022SAxel Dörfler
3060cc8d8abSSiarzhuk Zharski		case B_NODE_MONITOR:
3070cc8d8abSSiarzhuk Zharski			_HandleNodeMonitorEvent(message);
3080cc8d8abSSiarzhuk Zharski			break;
3090cc8d8abSSiarzhuk Zharski
3105188c282SAxel Dörfler		// Font menu
31114ea5e5eSKarsten Heimrich
3125188c282SAxel Dörfler		case FONT_SIZE:
3135188c282SAxel Dörfler		{
3145188c282SAxel Dörfler			float fontSize;
3155188c282SAxel Dörfler			if (message->FindFloat("size", &fontSize) == B_OK)
3165188c282SAxel Dörfler				_SetFontSize(fontSize);
3175188c282SAxel Dörfler			break;
3185188c282SAxel Dörfler		}
3195188c282SAxel Dörfler		case FONT_FAMILY:
3205188c282SAxel Dörfler		{
3215188c282SAxel Dörfler			const char* fontFamily = NULL;
3225188c282SAxel Dörfler			const char* fontStyle = NULL;
3235188c282SAxel Dörfler			void* ptr;
3245188c282SAxel Dörfler			if (message->FindPointer("source", &ptr) == B_OK) {
3255188c282SAxel Dörfler				BMenuItem* item = static_cast<BMenuItem*>(ptr);
3265188c282SAxel Dörfler				fontFamily = item->Label();
3275188c282SAxel Dörfler			}
328d2ff9616SAxel Dörfler
329d2ff9616SAxel Dörfler			BFont font;
330d2ff9616SAxel Dörfler			font.SetFamilyAndStyle(fontFamily, fontStyle);
331d2ff9616SAxel Dörfler			fItalicItem->SetMarked((font.Face() & B_ITALIC_FACE) != 0);
332d2ff9616SAxel Dörfler			fBoldItem->SetMarked((font.Face() & B_BOLD_FACE) != 0);
333d2ff9616SAxel Dörfler
3345188c282SAxel Dörfler			_SetFontStyle(fontFamily, fontStyle);
3355188c282SAxel Dörfler			break;
3365188c282SAxel Dörfler		}
3375188c282SAxel Dörfler		case FONT_STYLE:
3385188c282SAxel Dörfler		{
3395188c282SAxel Dörfler			const char* fontFamily = NULL;
3405188c282SAxel Dörfler			const char* fontStyle = NULL;
3415188c282SAxel Dörfler			void* ptr;
3425188c282SAxel Dörfler			if (message->FindPointer("source", &ptr) == B_OK) {
3435188c282SAxel Dörfler				BMenuItem* item = static_cast<BMenuItem*>(ptr);
3445188c282SAxel Dörfler				fontStyle = item->Label();
3455188c282SAxel Dörfler				BMenu* menu = item->Menu();
3465188c282SAxel Dörfler				if (menu != NULL) {
3475188c282SAxel Dörfler					BMenuItem* super_item = menu->Superitem();
3485188c282SAxel Dörfler					if (super_item != NULL)
3495188c282SAxel Dörfler						fontFamily = super_item->Label();
3505188c282SAxel Dörfler				}
3515188c282SAxel Dörfler			}
352d2ff9616SAxel Dörfler
353d2ff9616SAxel Dörfler			BFont font;
354d2ff9616SAxel Dörfler			font.SetFamilyAndStyle(fontFamily, fontStyle);
355d2ff9616SAxel Dörfler			fItalicItem->SetMarked((font.Face() & B_ITALIC_FACE) != 0);
356d2ff9616SAxel Dörfler			fBoldItem->SetMarked((font.Face() & B_BOLD_FACE) != 0);
357d2ff9616SAxel Dörfler
3585188c282SAxel Dörfler			_SetFontStyle(fontFamily, fontStyle);
3595188c282SAxel Dörfler			break;
3605188c282SAxel Dörfler		}
361d2ff9616SAxel Dörfler		case kMsgSetItalic:
362d2ff9616SAxel Dörfler		{
363d2ff9616SAxel Dörfler			uint32 sameProperties;
364d2ff9616SAxel Dörfler			BFont font;
365d2ff9616SAxel Dörfler			fTextView->GetFontAndColor(&font, &sameProperties);
366d2ff9616SAxel Dörfler
367d2ff9616SAxel Dörfler			if (fItalicItem->IsMarked())
368d2ff9616SAxel Dörfler				font.SetFace(B_REGULAR_FACE);
369d2ff9616SAxel Dörfler			fItalicItem->SetMarked(!fItalicItem->IsMarked());
370d2ff9616SAxel Dörfler
371d2ff9616SAxel Dörfler			font_family family;
372d2ff9616SAxel Dörfler			font_style style;
373d2ff9616SAxel Dörfler			font.GetFamilyAndStyle(&family, &style);
374d2ff9616SAxel Dörfler
375d2ff9616SAxel Dörfler			_SetFontStyle(family, style);
376d2ff9616SAxel Dörfler			break;
377d2ff9616SAxel Dörfler		}
378d2ff9616SAxel Dörfler		case kMsgSetBold:
379d2ff9616SAxel Dörfler		{
380d2ff9616SAxel Dörfler			uint32 sameProperties;
381d2ff9616SAxel Dörfler			BFont font;
382d2ff9616SAxel Dörfler			fTextView->GetFontAndColor(&font, &sameProperties);
383d2ff9616SAxel Dörfler
384d2ff9616SAxel Dörfler			if (fBoldItem->IsMarked())
385d2ff9616SAxel Dörfler				font.SetFace(B_REGULAR_FACE);
386d2ff9616SAxel Dörfler			fBoldItem->SetMarked(!fBoldItem->IsMarked());
387d2ff9616SAxel Dörfler
388d2ff9616SAxel Dörfler			font_family family;
389d2ff9616SAxel Dörfler			font_style style;
390d2ff9616SAxel Dörfler			font.GetFamilyAndStyle(&family, &style);
391d2ff9616SAxel Dörfler
392d2ff9616SAxel Dörfler			_SetFontStyle(family, style);
393d2ff9616SAxel Dörfler			break;
394d2ff9616SAxel Dörfler		}
3955188c282SAxel Dörfler		case FONT_COLOR:
3965188c282SAxel Dörfler		{
3975188c282SAxel Dörfler			void* ptr;
3985188c282SAxel Dörfler			if (message->FindPointer("source", &ptr) == B_OK) {
3995188c282SAxel Dörfler				if (ptr == fBlackItem)
4005188c282SAxel Dörfler					_SetFontColor(&BLACK);
4015188c282SAxel Dörfler				else if (ptr == fRedItem)
4025188c282SAxel Dörfler					_SetFontColor(&RED);
4035188c282SAxel Dörfler				else if (ptr == fGreenItem)
4045188c282SAxel Dörfler					_SetFontColor(&GREEN);
4055188c282SAxel Dörfler				else if (ptr == fBlueItem)
4065188c282SAxel Dörfler					_SetFontColor(&BLUE);
4075188c282SAxel Dörfler				else if (ptr == fCyanItem)
4085188c282SAxel Dörfler					_SetFontColor(&CYAN);
4095188c282SAxel Dörfler				else if (ptr == fMagentaItem)
4105188c282SAxel Dörfler					_SetFontColor(&MAGENTA);
4115188c282SAxel Dörfler				else if (ptr == fYellowItem)
4125188c282SAxel Dörfler					_SetFontColor(&YELLOW);
4135188c282SAxel Dörfler			}
4145188c282SAxel Dörfler			break;
4155188c282SAxel Dörfler		}
41631139022SAxel Dörfler
4175188c282SAxel Dörfler		// Document menu
4185188c282SAxel Dörfler
4195188c282SAxel Dörfler		case ALIGN_LEFT:
4205188c282SAxel Dörfler			fTextView->SetAlignment(B_ALIGN_LEFT);
4215188c282SAxel Dörfler			_UpdateCleanUndoRedoSaveRevert();
4225188c282SAxel Dörfler			break;
4235188c282SAxel Dörfler		case ALIGN_CENTER:
4245188c282SAxel Dörfler			fTextView->SetAlignment(B_ALIGN_CENTER);
4255188c282SAxel Dörfler			_UpdateCleanUndoRedoSaveRevert();
4265188c282SAxel Dörfler			break;
4275188c282SAxel Dörfler		case ALIGN_RIGHT:
4285188c282SAxel Dörfler			fTextView->SetAlignment(B_ALIGN_RIGHT);
4295188c282SAxel Dörfler			_UpdateCleanUndoRedoSaveRevert();
4305188c282SAxel Dörfler			break;
4315188c282SAxel Dörfler		case WRAP_LINES:
4325188c282SAxel Dörfler		{
4335188c282SAxel Dörfler			BRect textRect(fTextView->Bounds());
4345188c282SAxel Dörfler			textRect.OffsetTo(B_ORIGIN);
4355188c282SAxel Dörfler			textRect.InsetBy(TEXT_INSET, TEXT_INSET);
4365188c282SAxel Dörfler			if (fTextView->DoesWordWrap()) {
4375188c282SAxel Dörfler				fTextView->SetWordWrap(false);
4385188c282SAxel Dörfler				fWrapItem->SetMarked(false);
4395188c282SAxel Dörfler				// the width comes from stylededit R5. TODO: find a better way
4405188c282SAxel Dörfler				textRect.SetRightBottom(BPoint(1500.0, textRect.RightBottom().y));
4415188c282SAxel Dörfler			} else {
4425188c282SAxel Dörfler				fTextView->SetWordWrap(true);
4435188c282SAxel Dörfler				fWrapItem->SetMarked(true);
4445188c282SAxel Dörfler			}
4455188c282SAxel Dörfler			fTextView->SetTextRect(textRect);
4465188c282SAxel Dörfler
4475188c282SAxel Dörfler			_UpdateCleanUndoRedoSaveRevert();
4485188c282SAxel Dörfler			break;
4495188c282SAxel Dörfler		}
4505188c282SAxel Dörfler		case SHOW_STATISTICS:
4515188c282SAxel Dörfler			_ShowStatistics();
4525188c282SAxel Dörfler			break;
4535188c282SAxel Dörfler		case ENABLE_ITEMS:
4545188c282SAxel Dörfler			fCutItem->SetEnabled(true);
4555188c282SAxel Dörfler			fCopyItem->SetEnabled(true);
4565188c282SAxel Dörfler			break;
4575188c282SAxel Dörfler		case DISABLE_ITEMS:
4585188c282SAxel Dörfler			fCutItem->SetEnabled(false);
4595188c282SAxel Dörfler			fCopyItem->SetEnabled(false);
4605188c282SAxel Dörfler			break;
4615188c282SAxel Dörfler		case TEXT_CHANGED:
4625188c282SAxel Dörfler			if (fUndoFlag) {
4635188c282SAxel Dörfler				if (fUndoCleans) {
4645188c282SAxel Dörfler					// we cleaned!
4655188c282SAxel Dörfler					fClean = true;
4665188c282SAxel Dörfler					fUndoCleans = false;
4675188c282SAxel Dörfler				} else if (fClean) {
4685188c282SAxel Dörfler					// if we were clean
4695188c282SAxel Dörfler					// then a redo will make us clean again
4705188c282SAxel Dörfler					fRedoCleans = true;
4715188c282SAxel Dörfler					fClean = false;
4725188c282SAxel Dörfler				}
4735188c282SAxel Dörfler				// set mode
4745188c282SAxel Dörfler				fCanUndo = false;
4755188c282SAxel Dörfler				fCanRedo = true;
4765188c282SAxel Dörfler				fUndoItem->SetLabel(B_TRANSLATE("Redo typing"));
4775188c282SAxel Dörfler				fUndoItem->SetEnabled(true);
4785188c282SAxel Dörfler				fUndoFlag = false;
4795188c282SAxel Dörfler			} else {
4805188c282SAxel Dörfler				if (fRedoFlag && fRedoCleans) {
4815188c282SAxel Dörfler					// we cleaned!
4825188c282SAxel Dörfler					fClean = true;
4835188c282SAxel Dörfler					fRedoCleans = false;
4845188c282SAxel Dörfler				} else if (fClean) {
4855188c282SAxel Dörfler					// if we were clean
4865188c282SAxel Dörfler					// then an undo will make us clean again
4875188c282SAxel Dörfler					fUndoCleans = true;
4885188c282SAxel Dörfler					fClean = false;
4895188c282SAxel Dörfler				} else {
4905188c282SAxel Dörfler					// no more cleaning from undo now...
4915188c282SAxel Dörfler					fUndoCleans = false;
4925188c282SAxel Dörfler				}
4935188c282SAxel Dörfler				// set mode
4945188c282SAxel Dörfler				fCanUndo = true;
4955188c282SAxel Dörfler				fCanRedo = false;
4965188c282SAxel Dörfler				fUndoItem->SetLabel(B_TRANSLATE("Undo typing"));
4975188c282SAxel Dörfler				fUndoItem->SetEnabled(true);
4985188c282SAxel Dörfler				fRedoFlag = false;
4995188c282SAxel Dörfler			}
5005188c282SAxel Dörfler			if (fClean) {
5015188c282SAxel Dörfler				fSaveItem->SetEnabled(fSaveMessage == NULL);
5025188c282SAxel Dörfler			} else {
5035188c282SAxel Dörfler				fSaveItem->SetEnabled(true);
5045188c282SAxel Dörfler			}
5050cc8d8abSSiarzhuk Zharski			fReloadItem->SetEnabled(fSaveMessage != NULL);
5060cc8d8abSSiarzhuk Zharski			fEncodingItem->SetEnabled(fSaveMessage != NULL);
5075188c282SAxel Dörfler			break;
5085188c282SAxel Dörfler
5095188c282SAxel Dörfler		case SAVE_AS_ENCODING:
5105188c282SAxel Dörfler			void* ptr;
5115188c282SAxel Dörfler			if (message->FindPointer("source", &ptr) == B_OK
5125188c282SAxel Dörfler				&& fSavePanelEncodingMenu != NULL) {
5135188c282SAxel Dörfler				fTextView->SetEncoding(
5145188c282SAxel Dörfler					(uint32)fSavePanelEncodingMenu->IndexOf((BMenuItem*)ptr));
5155188c282SAxel Dörfler			}
5165188c282SAxel Dörfler			break;
5175188c282SAxel Dörfler
5180f4985d8SVlad Slepukhin		case UPDATE_STATUS:
5190f4985d8SVlad Slepukhin			message->AddBool("modified", !fClean);
5200f4985d8SVlad Slepukhin			message->AddBool("readOnly", !fTextView->IsEditable());
5210f4985d8SVlad Slepukhin			fStatusView->SetStatus(message);
5220f4985d8SVlad Slepukhin			break;
5230f4985d8SVlad Slepukhin
5240f4985d8SVlad Slepukhin		case UNLOCK_FILE:
5250f4985d8SVlad Slepukhin		{
5260f4985d8SVlad Slepukhin			status_t status = _UnlockFile();
5270f4985d8SVlad Slepukhin			if (status != B_OK) {
5280f4985d8SVlad Slepukhin				BString text;
5290f4985d8SVlad Slepukhin				bs_printf(&text,
5300f4985d8SVlad Slepukhin					B_TRANSLATE("Unable to unlock file\n\t%s"),
5310f4985d8SVlad Slepukhin					strerror(status));
5320f4985d8SVlad Slepukhin				_ShowAlert(text, B_TRANSLATE("OK"), "", "", B_STOP_ALERT);
5330f4985d8SVlad Slepukhin			}
5340f4985d8SVlad Slepukhin			PostMessage(UPDATE_STATUS);
5350f4985d8SVlad Slepukhin			break;
5360f4985d8SVlad Slepukhin		}
5370f4985d8SVlad Slepukhin
5385188c282SAxel Dörfler		default:
5395188c282SAxel Dörfler			BWindow::MessageReceived(message);
5405188c282SAxel Dörfler			break;
54131139022SAxel Dörfler	}
5425188c282SAxel Dörfler}
54314ea5e5eSKarsten Heimrich
54414ea5e5eSKarsten Heimrich
5455188c282SAxel Dörflervoid
5465188c282SAxel DörflerStyledEditWindow::MenusBeginning()
5475188c282SAxel Dörfler{
5485188c282SAxel Dörfler	// set up the recent documents menu
5495188c282SAxel Dörfler	BMessage documents;
5505188c282SAxel Dörfler	be_roster->GetRecentDocuments(&documents, 9, NULL, APP_SIGNATURE);
551f7afd44bSPhil Greenway
5525188c282SAxel Dörfler	// delete old items..
5535188c282SAxel Dörfler	//    shatty: it would be preferable to keep the old
5545188c282SAxel Dörfler	//            menu around instead of continuously thrashing
5555188c282SAxel Dörfler	//            the menu, but unfortunately there does not
5565188c282SAxel Dörfler	//            seem to be a straightforward way to update it
5575188c282SAxel Dörfler	// going backwards may simplify memory management
5585188c282SAxel Dörfler	for (int i = fRecentMenu->CountItems(); i-- > 0;) {
5595188c282SAxel Dörfler		delete fRecentMenu->RemoveItem(i);
5605188c282SAxel Dörfler	}
56131139022SAxel Dörfler
5625188c282SAxel Dörfler	// add new items
5635188c282SAxel Dörfler	int count = 0;
5645188c282SAxel Dörfler	entry_ref ref;
5655188c282SAxel Dörfler	while (documents.FindRef("refs", count++, &ref) == B_OK) {
5665188c282SAxel Dörfler		if (ref.device != -1 && ref.directory != -1) {
5675188c282SAxel Dörfler			// sanity check passed
5685188c282SAxel Dörfler			BMessage* openRecent = new BMessage(B_REFS_RECEIVED);
5695188c282SAxel Dörfler			openRecent->AddRef("refs", &ref);
5705188c282SAxel Dörfler			BMenuItem* item = new BMenuItem(ref.name, openRecent);
5715188c282SAxel Dörfler			item->SetTarget(be_app);
5725188c282SAxel Dörfler			fRecentMenu->AddItem(item);
5735188c282SAxel Dörfler		}
5745188c282SAxel Dörfler	}
575f7afd44bSPhil Greenway
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();
5835188c282SAxel Dörfler			if (item != NULL) {
5845188c282SAxel Dörfler				item->SetMarked(false);
5855188c282SAxel Dörfler			}
5865188c282SAxel Dörfler		}
5875188c282SAxel Dörfler	}
58831139022SAxel Dörfler
5895188c282SAxel Dörfler	if (fCurrentStyleItem != NULL) {
5905188c282SAxel Dörfler		fCurrentStyleItem->SetMarked(false);
5915188c282SAxel Dörfler	}
5925188c282SAxel Dörfler
5935188c282SAxel Dörfler	BMenuItem* oldColorItem = fFontColorMenu->FindMarked();
5945188c282SAxel Dörfler	if (oldColorItem != NULL)
5955188c282SAxel Dörfler		oldColorItem->SetMarked(false);
5965188c282SAxel Dörfler
5975188c282SAxel Dörfler	BMenuItem* oldSizeItem = fFontSizeMenu->FindMarked();
5985188c282SAxel Dörfler	if (oldSizeItem != NULL)
5995188c282SAxel Dörfler		oldSizeItem->SetMarked(false);
6005188c282SAxel Dörfler
6015188c282SAxel Dörfler	// find the current font, color, size
6025188c282SAxel Dörfler	BFont font;
6035188c282SAxel Dörfler	uint32 sameProperties;
6045188c282SAxel Dörfler	rgb_color color = BLACK;
6055188c282SAxel Dörfler	bool sameColor;
6065188c282SAxel Dörfler	fTextView->GetFontAndColor(&font, &sameProperties, &color, &sameColor);
6075188c282SAxel Dörfler
6085188c282SAxel Dörfler	if (sameColor && color.alpha == 255) {
6095188c282SAxel Dörfler		// select 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 "
7365188c282SAxel Dörfler					"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	entry_ref ref;
7705188c282SAxel Dörfler	if (entry.GetRef(&ref) == B_OK)
7715188c282SAxel Dörfler		be_roster->AddToRecentDocuments(&ref, APP_SIGNATURE);
77215d26d2cSAxel Dörfler
7735188c282SAxel Dörfler	// clear clean modes
7745188c282SAxel Dörfler	fSaveItem->SetEnabled(false);
7755188c282SAxel Dörfler	fUndoCleans = false;
7765188c282SAxel Dörfler	fRedoCleans = false;
7775188c282SAxel Dörfler	fClean = true;
7780cc8d8abSSiarzhuk Zharski	fNagOnNodeChange = true;
7790cc8d8abSSiarzhuk Zharski
7805188c282SAxel Dörfler	return status;
78131139022SAxel Dörfler}
78231139022SAxel Dörfler
7838f63353bSshatty
784546208a5SOliver Tappe#undef B_TRANSLATION_CONTEXT
785546208a5SOliver Tappe#define B_TRANSLATION_CONTEXT "Open_and_SaveAsPanel"
786a723b3d4SAxel Dörfler
787a723b3d4SAxel Dörfler
7885188c282SAxel Dörflerstatus_t
7895188c282SAxel DörflerStyledEditWindow::SaveAs(BMessage* message)
7905188c282SAxel Dörfler{
7915188c282SAxel Dörfler	if (fSavePanel == NULL) {
7925188c282SAxel Dörfler		entry_ref* directory = NULL;
7935b9003c7SRyan Leavengood		entry_ref dirRef;
7945188c282SAxel Dörfler		if (fSaveMessage != NULL) {
7955188c282SAxel Dörfler			if (fSaveMessage->FindRef("directory", &dirRef) == B_OK)
7965188c282SAxel Dörfler				directory = &dirRef;
797