Skip to content

Commit

Permalink
Add "Show in Tracker" button (#2)
Browse files Browse the repository at this point in the history
* Add "Show in Tracker" button to open the command' location

* _CommandIsScript() simply checks if the command's path is valid
  and points to a text file.

* _ShowCommand() opens the current script's location in Tracker and
  selects it.

* Only enable the "Show in Tracker" button, if the command is a text file.
  It stays disabled, e.g. for a simple CLI command like /bin/ls.

* Update user guide

* Mention the new "Show in Tracker" button and drag'n'drop of a script file
  to set the command.
* Updated screenshot.
* Optimized all PNGs.
  • Loading branch information
humdingerb authored Jun 16, 2024
1 parent e37f614 commit 9eef830
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 0 deletions.
Binary file modified Assets/Screenshots/CommandSelectWindow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/Screenshots/TrackRunnerCommands.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/Screenshots/TrackRunnerIconMenu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/Screenshots/TrackRunnerIconPrefs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/Screenshots/TrackRunnerMenu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/Screenshots/TrackRunnerPrefs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions Assets/UserGuide/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ Command Management Window


The command management window allows you to add/edit/remove/sort shortcuts.
You can drag'n'drop a script to replace the currently shown command path.
If the command is a script, the `Show in Tracker` button will open its location in a Tracker window. From there you can rename it or open it in an editor etc.


Command List
Expand Down
78 changes: 78 additions & 0 deletions Source/CommandsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
#include <IconUtils.h>
#include <LayoutBuilder.h>
#include <ListView.h>
#include <NodeInfo.h>
#include <Path.h>
#include <Resources.h>
#include <Roster.h>
#include <ScrollView.h>
#include <StringView.h>
#include <private/shared/ToolBar.h>
Expand All @@ -32,6 +34,7 @@ enum {
kUserGuideAction = 'GiDe',
kListSelectAction = 'LsTs',
kBrowseCommandAction = 'BrWz',
kShowCommandAction = 'SwWz',
kListUpdateAction = 'LsUp'
};

Expand Down Expand Up @@ -81,6 +84,7 @@ CommandsWindow::CommandsWindow(BString& title)
.SetInsets(0)
.Add(fBrowseButton = new BButton("Browse" B_UTF8_ELLIPSIS, new BMessage(kBrowseCommandAction)))
.AddGlue()
.Add(fShowButton = new BButton("Show in Tracker", new BMessage(kShowCommandAction)))
.End()
.Add(fTerminalCheckBox, 1, 3)
.End()
Expand Down Expand Up @@ -122,6 +126,9 @@ CommandsWindow::MessageReceived(BMessage* message)
case kBrowseCommandAction:
_BrowseCommand();
break;
case kShowCommandAction:
_ShowCommand();
break;
case kDeleteCommandAction:
_DeleteCommand();
break;
Expand Down Expand Up @@ -174,6 +181,73 @@ CommandsWindow::_BrowseCommand()
}


void
CommandsWindow::_ShowCommand()
{
BEntry itemEntry(_Deescape(fCommandControl->Text()));
status_t status = itemEntry.InitCheck();
if (status == B_OK) {
BEntry parentDirectory;
status = itemEntry.GetParent(&parentDirectory);
if (status == B_OK) {
entry_ref ref;
status = parentDirectory.GetRef(&ref);
if (status == B_OK) {
node_ref nref;
status = itemEntry.GetNodeRef(&nref);
if (status == B_OK)
_ShowInTracker(ref, &nref);
}
}
}
}


status_t
CommandsWindow::_ShowInTracker(const entry_ref& ref, const node_ref* nref)
{
status_t status = B_ERROR;

BMessenger tracker("application/x-vnd.Be-TRAK");
if (tracker.IsValid()) {
BMessage message(B_REFS_RECEIVED);
message.AddRef("refs", &ref);

if (nref != NULL)
message.AddData("nodeRefToSelect", B_RAW_TYPE, (void*)nref, sizeof(node_ref));

status = tracker.SendMessage(&message);
}
return status;
}


bool
CommandsWindow::_CommandIsScript()
{
BPath path = _Deescape(fCommandControl->Text());
if (path.InitCheck() != B_OK)
return false;

char mimeType[B_MIME_TYPE_LENGTH];
BNode commandNode(path.Path());
BNodeInfo(&commandNode).GetType(mimeType);
if (strncmp("text/", mimeType, 5) == 0)
return true;

return false;
}


const char*
CommandsWindow::_Deescape(const char* path)
{
BString text(path);
text.CharacterDeescape('\\');
return text.String();
}


void
CommandsWindow::_InitNewCommand()
{
Expand Down Expand Up @@ -231,6 +305,7 @@ CommandsWindow::_SelectItem()
fCommandControl->SetEnabled(true);

fBrowseButton->SetEnabled(true);
fShowButton->SetEnabled(true);

fTerminalCheckBox->SetValue(item->UseTerminal());
fTerminalCheckBox->SetEnabled(true);
Expand All @@ -253,6 +328,8 @@ CommandsWindow::_UpdateItem()
fListView->InvalidateItem(fListView->CurrentSelection());
}

fShowButton->SetEnabled(_CommandIsScript());

_SaveCommands();
}

Expand Down Expand Up @@ -320,6 +397,7 @@ CommandsWindow::_InitControls()
fCommandControl->SetEnabled(false);

fBrowseButton->SetEnabled(false);
fShowButton->SetEnabled(false);

fTerminalCheckBox->SetValue(1);
fTerminalCheckBox->SetEnabled(false);
Expand Down
5 changes: 5 additions & 0 deletions Source/CommandsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,17 @@ class CommandsWindow : public BWindow {
void _SelectItem();
void _UpdateItem();
void _BrowseCommand();
void _ShowCommand();
status_t _ShowInTracker(const entry_ref& ref, const node_ref* nref = NULL);
bool _CommandIsScript();
const char* _Deescape(const char* path);
void _RefsReceived(BMessage* message);
status_t _LoadCommands();
status_t _SaveCommands();
BBitmap* _ResourceBitmap(const char* name, float width, float height);

BButton* fBrowseButton;
BButton* fShowButton;
BCheckBox* fTerminalCheckBox;
BListView* fListView;
BFilePanel* fBrowsePanel;
Expand Down

0 comments on commit 9eef830

Please sign in to comment.