Ticket #8556: untitled_number.patch

File untitled_number.patch, 1.8 KB (added by ejno1, 11 years ago)

Patch to select the lowest unused number for Untitled documents

  • src/apps/stylededit/StyledEditApp.cpp

    From e731f07fb018b898292cd185c7519f7ca9eadbea Mon Sep 17 00:00:00 2001
    From: ejno <none>
    Date: Wed, 26 Jun 2013 08:48:24 +0000
    Subject: [PATCH] choose lowest unused number for Untitled documents
    
    ---
     src/apps/stylededit/StyledEditApp.cpp |   25 +++++++++++++++++++++++--
     src/apps/stylededit/StyledEditApp.h   |    1 -
     2 files changed, 23 insertions(+), 3 deletions(-)
    
    diff --git a/src/apps/stylededit/StyledEditApp.cpp b/src/apps/stylededit/StyledEditApp.cpp
    index 0460af8..4a923bb 100644
    a b StyledEditApp::StyledEditApp()  
    128128        fOpenPanelEncodingMenu = NULL;
    129129
    130130    fWindowCount = 0;
    131     fNextUntitledWindow = 1;
    132131    fBadArguments = false;
    133132}
    134133
    StyledEditApp::MessageReceived(BMessage* message)  
    168167}
    169168
    170169
     170static int32
     171GetNextUntitled()
     172{
     173    int nextUntitled = 1;
     174   
     175    BString untitled(B_TRANSLATE("Untitled "));
     176    BString title = untitled;
     177    title << nextUntitled;
     178
     179    int32 numWindows = be_app->CountWindows();
     180    for (int32 i = 0; i < numWindows; i++) {
     181        if (be_app->WindowAt(i)->Title() == title)
     182        {
     183            title = untitled;
     184            title << ++nextUntitled;
     185        }
     186    }
     187
     188    return nextUntitled;
     189}
     190
     191
    171192void
    172193StyledEditApp::OpenDocument()
    173194{
    174195    cascade();
    175     new StyledEditWindow(gWindowRect, fNextUntitledWindow++, fOpenAsEncoding);
     196    new StyledEditWindow(gWindowRect, GetNextUntitled(), fOpenAsEncoding);
    176197    fWindowCount++;
    177198}
    178199
  • src/apps/stylededit/StyledEditApp.h

    diff --git a/src/apps/stylededit/StyledEditApp.h b/src/apps/stylededit/StyledEditApp.h
    index 71f1f74..0de971f 100644
    a b private:  
    4949            BMenu*              fOpenPanelEncodingMenu;
    5050            uint32              fOpenAsEncoding;
    5151            int32               fWindowCount;
    52             int32               fNextUntitledWindow;
    5352            bool                fBadArguments;
    5453};
    5554