StyledEdit: choose lowest unused number for Untitled documents
Fixes #8556. Change-Id: I8825008f45f2549e233be2c7adad13c8993f003d Reviewed-on: https://review.haiku-os.org/c/haiku/+/2273 Tested-by: Commit checker robot <[email protected]> Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
@@ -130,7 +130,6 @@ StyledEditApp::StyledEditApp()
|
|||||||
fOpenPanelEncodingMenu = NULL;
|
fOpenPanelEncodingMenu = NULL;
|
||||||
|
|
||||||
fWindowCount = 0;
|
fWindowCount = 0;
|
||||||
fNextUntitledWindow = 1;
|
|
||||||
fBadArguments = false;
|
fBadArguments = false;
|
||||||
|
|
||||||
float factor = be_plain_font->Size() / 12.0f;
|
float factor = be_plain_font->Size() / 12.0f;
|
||||||
@@ -179,10 +178,31 @@ StyledEditApp::MessageReceived(BMessage* message)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int32
|
||||||
|
GetNextUntitled()
|
||||||
|
{
|
||||||
|
int nextUntitled = 1;
|
||||||
|
|
||||||
|
BString title;
|
||||||
|
const char* untitledFormat = B_TRANSLATE_CONTEXT("Untitled %d", "Window title");
|
||||||
|
title.SetToFormat(untitledFormat, (int)nextUntitled);
|
||||||
|
|
||||||
|
int32 numWindows = be_app->CountWindows();
|
||||||
|
for (int32 i = 0; i < numWindows; i++) {
|
||||||
|
if (be_app->WindowAt(i)->Title() == title)
|
||||||
|
{
|
||||||
|
title.SetToFormat(untitledFormat, (int)++nextUntitled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nextUntitled;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
StyledEditApp::OpenDocument()
|
StyledEditApp::OpenDocument()
|
||||||
{
|
{
|
||||||
new StyledEditWindow(sWindowRect, fNextUntitledWindow++, fOpenAsEncoding);
|
new StyledEditWindow(sWindowRect, GetNextUntitled(), fOpenAsEncoding);
|
||||||
cascade();
|
cascade();
|
||||||
fWindowCount++;
|
fWindowCount++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ private:
|
|||||||
BMenu* fOpenPanelEncodingMenu;
|
BMenu* fOpenPanelEncodingMenu;
|
||||||
uint32 fOpenAsEncoding;
|
uint32 fOpenAsEncoding;
|
||||||
int32 fWindowCount;
|
int32 fWindowCount;
|
||||||
int32 fNextUntitledWindow;
|
|
||||||
bool fBadArguments;
|
bool fBadArguments;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -91,9 +91,9 @@ StyledEditWindow::StyledEditWindow(BRect frame, int32 id, uint32 encoding)
|
|||||||
fReplaceWindow(NULL)
|
fReplaceWindow(NULL)
|
||||||
{
|
{
|
||||||
_InitWindow(encoding);
|
_InitWindow(encoding);
|
||||||
BString unTitled(B_TRANSLATE("Untitled "));
|
BString untitled;
|
||||||
unTitled << id;
|
untitled.SetToFormat(B_TRANSLATE_CONTEXT("Untitled %d", "Window title"), (int)id);
|
||||||
SetTitle(unTitled.String());
|
SetTitle(untitled.String());
|
||||||
fSaveItem->SetEnabled(true);
|
fSaveItem->SetEnabled(true);
|
||||||
// allow saving empty files
|
// allow saving empty files
|
||||||
Show();
|
Show();
|
||||||
|
|||||||
Reference in New Issue
Block a user