Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow invoking the "Find differences" mode from the command line. #85

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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