Skip to content

Commit

Permalink
Allow invoking the "Find differences" mode from the command line. (#85)
Browse files Browse the repository at this point in the history
When called as "Pe --diff file1 file2", it automatically opens
the "File differences" dialog for both files, ready to be used.
  • Loading branch information
OscarL authored Mar 18, 2024
1 parent 9dfadcd commit 3d3e414
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
3 changes: 1 addition & 2 deletions Sources/CDiffWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ inline int compare(const char *a, const char *b)

const unsigned long
msg_InvokeScriptItem = 'InvS',
msg_SelectScriptItem = 'SelS',
msg_Add2Files = 'Ad2F';
msg_SelectScriptItem = 'SelS';

class CDiffToolBar : public PToolBar {
public:
Expand Down
34 changes: 30 additions & 4 deletions Sources/PApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,13 +563,17 @@ PDoc* PApp::OpenWorksheet()

static void Usage()
{
fprintf(stderr, "Usage: pe [\"+\"linenr] file1 file2 ...\n");
fprintf(stderr, "Usage: pe [\"+\"linenr] [--diff] file1 file2 ...\n");
} /* Usage */

void PApp::ArgvReceived(int32 argc, const char *argv[], const char * cwd)
{
try
{
// -1 = No, 0 = yes, 1 = got first file, 2 = got second file
int invokeDiff = -1;
entry_ref f1, f2;

int i = 1, lineNr = -1;
char *p;

Expand All @@ -578,12 +582,13 @@ void PApp::ArgvReceived(int32 argc, const char *argv[], const char * cwd)
switch (argv[i][0])
{
case '-':
if (strcmp(argv[i], "-reload_worksheet") == 0)
{
if (strcmp(argv[i], "-reload_worksheet") == 0) {
PDoc *d = OpenWorksheet();
if (d && d->Lock())
d->Quit();
d = OpenWorksheet();
} else if (argc == 4 && strcmp(argv[i], "--diff") == 0) {
invokeDiff = 0;
} else {
Usage();
}
Expand Down Expand Up @@ -611,8 +616,16 @@ void PApp::ArgvReceived(int32 argc, const char *argv[], const char * cwd)
BEntry e;
FailOSErr(e.SetTo(&doc));

if (e.Exists())
if (e.Exists()) {
d = dynamic_cast<CDocWindow*>(OpenWindow(doc));
if (invokeDiff >= 0) {
invokeDiff += 1;
if (invokeDiff == 1)
f1 = doc;
else
f2 = doc;
}
}
else
{
d = NewWindow(NULL);
Expand All @@ -631,6 +644,19 @@ void PApp::ArgvReceived(int32 argc, const char *argv[], const char * cwd)
}
i++;
}

if (invokeDiff == 2) {
// Size doesn't matter here as the window will be resized right away.
BRect r(0, 0, 0, 0);
CDiffWindow *ndw = new CDiffWindow(r, "Differences");

BMessage msg(msg_Add2Files);
msg.AddRef("refs", &f1);
msg.AddRef("refs", &f2);
ndw->PostMessage(&msg);

ndw->PostMessage(msg_RefreshDiffs);
}
}
catch (HErr& e)
{
Expand Down
1 change: 1 addition & 0 deletions Sources/PMessages.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
#define msg_RefreshDiffs 'RfrD'
#define msg_DiffFile1 'Dff1'
#define msg_DiffFile2 'Dff2'
#define msg_Add2Files 'Ad2F'

#define msg_SelectError 'SelE'

Expand Down

0 comments on commit 3d3e414

Please sign in to comment.