Skip to content

Commit

Permalink
StyledEdit: add navigation menu to status bar.
Browse files Browse the repository at this point in the history
* Fix #12099.
  • Loading branch information
janus2 committed May 30, 2015
1 parent cf9328d commit 8914c88
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/apps/stylededit/Constants.h
Expand Up @@ -82,6 +82,7 @@ const uint32 SAVE_THEN_QUIT = 'FPsq';

// Update StatusView
const uint32 UPDATE_STATUS = 'UPSt';
const uint32 UPDATE_STATUS_REF = 'UPSr';
const uint32 UNLOCK_FILE = 'UNLk';
const uint32 UPDATE_LINE_SELECTION = 'UPls';

Expand Down
6 changes: 5 additions & 1 deletion src/apps/stylededit/Jamfile
@@ -1,7 +1,11 @@
SubDir HAIKU_TOP src apps stylededit ;

UsePrivateHeaders textencoding ;
UsePrivateSystemHeaders ;
UsePrivateHeaders tracker shared ;
UsePublicHeaders [ FDirName be_apps Tracker ] ;
SubDirHdrs $(HAIKU_TOP) src kits tracker ;
UseHeaders [ FDirName $(HAIKU_TOP) src kits tracker ] : false ;

local styled_edit_rsrc =
[ FGristFiles StyledEdit.rsrc ]
Expand All @@ -18,7 +22,7 @@ Application StyledEdit :
StyledEditApp.cpp
StyledEditView.cpp
StyledEditWindow.cpp
: be translation tracker libtextencoding.so localestub
: libshared.a be translation tracker libtextencoding.so localestub
[ TargetLibsupc++ ]
: $(styled_edit_rsrc)
;
Expand Down
39 changes: 39 additions & 0 deletions src/apps/stylededit/StatusView.cpp
Expand Up @@ -25,6 +25,9 @@
#include <StringView.h>
#include <Window.h>

#include <tracker_private.h>
#include "DirMenu.h"

#include "Constants.h"


Expand Down Expand Up @@ -156,6 +159,11 @@ StatusView::Draw(BRect updateRect)
void
StatusView::MouseDown(BPoint where)
{
if (where.x < fCellWidth[kPositionCell]) {
_ShowDirMenu();
return;
}

if (!fReadOnly || !fCanUnlock)
return;

Expand Down Expand Up @@ -228,6 +236,13 @@ StatusView::SetStatus(BMessage* message)
}


void
StatusView::SetRef(const entry_ref& ref)
{
fRef = ref;
}


void
StatusView::_ValidatePreferredSize()
{
Expand Down Expand Up @@ -264,3 +279,27 @@ StatusView::_ValidatePreferredSize()
scrollBar->MoveBy(delta, 0);
}


void
StatusView::_ShowDirMenu()
{
BEntry entry;
status_t status = entry.SetTo(&fRef);

if (status != B_OK || !entry.Exists())
return;

BPrivate::BDirMenu* menu = new BDirMenu(NULL,
BMessenger(kTrackerSignature), B_REFS_RECEIVED);

menu->Populate(&entry, Window(), false, false, true, false, true);

BPoint point = Bounds().LeftBottom();
point.y += 3;
ConvertToScreen(&point);
BRect clickToOpenRect(Bounds());
ConvertToScreen(&clickToOpenRect);
menu->Go(point, true, true, clickToOpenRect);
delete menu;
}

4 changes: 4 additions & 0 deletions src/apps/stylededit/StatusView.h
Expand Up @@ -10,6 +10,7 @@
#define STATUS_VIEW_H


#include <Entry.h>
#include <String.h>
#include <View.h>

Expand All @@ -30,6 +31,7 @@ class StatusView : public BView {
~StatusView();

void SetStatus(BMessage* mesage);
void SetRef(const entry_ref& ref);
virtual void AttachedToWindow();
virtual void GetPreferredSize(float* _width, float* _height);
virtual void ResizeToPreferred();
Expand All @@ -38,6 +40,7 @@ class StatusView : public BView {

private:
void _ValidatePreferredSize();
void _ShowDirMenu();

private:
BScrollView* fScrollView;
Expand All @@ -47,6 +50,7 @@ class StatusView : public BView {
bool fReadOnly;
bool fCanUnlock;
BString fEncoding;
entry_ref fRef;
};

#endif // STATUS_VIEW_H
27 changes: 27 additions & 0 deletions src/apps/stylededit/StyledEditWindow.cpp
Expand Up @@ -558,6 +558,27 @@ StyledEditWindow::MessageReceived(BMessage* message)
break;
}

case UPDATE_STATUS_REF:
{
entry_ref ref;
const char* name;

if (fSaveMessage != NULL
&& fSaveMessage->FindRef("directory", &ref) == B_OK
&& fSaveMessage->FindString("name", &name) == B_OK) {

BDirectory dir(&ref);
status_t status = dir.InitCheck();
BEntry entry;
if (status == B_OK)
status = entry.SetTo(&dir, name);
if (status == B_OK)
status = entry.GetRef(&ref);
}
fStatusView->SetRef(ref);
break;
}

case UNLOCK_FILE:
{
status_t status = _UnlockFile();
Expand Down Expand Up @@ -801,6 +822,8 @@ StyledEditWindow::Save(BMessage* message)
fNagOnNodeChange = true;

PostMessage(UPDATE_STATUS);
PostMessage(UPDATE_STATUS_REF);

return status;
}

Expand Down Expand Up @@ -888,6 +911,8 @@ StyledEditWindow::OpenFile(entry_ref* ref)

_SwitchNodeMonitor(true, ref);

PostMessage(UPDATE_STATUS_REF);

fReloadItem->SetEnabled(fSaveMessage != NULL);
fEncodingItem->SetEnabled(fSaveMessage != NULL);
}
Expand Down Expand Up @@ -2053,6 +2078,7 @@ StyledEditWindow::_HandleNodeMonitorEvent(BMessage *message)
_SwitchNodeMonitor(false);
_SwitchNodeMonitor(true);
}
PostMessage(UPDATE_STATUS_REF);
}
break;

Expand Down Expand Up @@ -2099,6 +2125,7 @@ StyledEditWindow::_HandleNodeMonitorEvent(BMessage *message)
name = "Unknown";

_ShowNodeChangeAlert(name, true);
PostMessage(UPDATE_STATUS_REF);
}
break;

Expand Down

0 comments on commit 8914c88

Please sign in to comment.