Commit b82bc503 authored by Robert Sprowson's avatar Robert Sprowson
Browse files

Pop to top a draw file if already open rather than loading again

As for !Edit and the filer, when asked to open the same thing a second time, just re-present the one already in memory rather than opening a second time.
We borrow the logic from !Edit - the (uncanonicalised) filename must be the same, unmodified, with the same datestamp. If all these are true just pop the existing window (or newest of the views when multiple views exist) to the top.

Draw.c:
Change the boolean expression at line 2191. While previously correct (not wimp_MDATALOAD does include wimp_MDATAOPEN) it subsequently relied on load_file to skip wimp_MDATASAVE.
DrawFileIO.c:
Add check of load/exec/modified/filename. Defer creating a new diag until later on to avoid annoying screen flicker when disposing of the diag (similarly for error cases).
Fix confusion returning FALSE as a pointer.

Version 1.26. Tagged as 'Draw-1_26'
parent 11073f0a
......@@ -11,13 +11,13 @@
GBLS Module_HelpVersion
GBLS Module_ComponentName
GBLS Module_ComponentPath
Module_MajorVersion SETS "1.25"
Module_Version SETA 125
Module_MajorVersion SETS "1.26"
Module_Version SETA 126
Module_MinorVersion SETS ""
Module_Date SETS "31 Jul 2014"
Module_ApplicationDate SETS "31-Jul-14"
Module_Date SETS "09 Aug 2014"
Module_ApplicationDate SETS "09-Aug-14"
Module_ComponentName SETS "Draw"
Module_ComponentPath SETS "castle/RiscOS/Sources/Apps/Draw"
Module_FullVersion SETS "1.25"
Module_HelpVersion SETS "1.25 (31 Jul 2014)"
Module_FullVersion SETS "1.26"
Module_HelpVersion SETS "1.26 (09 Aug 2014)"
END
/* (1.25)
/* (1.26)
*
* This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.1.
*
*/
#define Module_MajorVersion_CMHG 1.25
#define Module_MajorVersion_CMHG 1.26
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 31 Jul 2014
#define Module_Date_CMHG 09 Aug 2014
#define Module_MajorVersion "1.25"
#define Module_Version 125
#define Module_MajorVersion "1.26"
#define Module_Version 126
#define Module_MinorVersion ""
#define Module_Date "31 Jul 2014"
#define Module_Date "09 Aug 2014"
#define Module_ApplicationDate "31-Jul-14"
#define Module_ApplicationDate "09-Aug-14"
#define Module_ComponentName "Draw"
#define Module_ComponentPath "castle/RiscOS/Sources/Apps/Draw"
#define Module_FullVersion "1.25"
#define Module_HelpVersion "1.25 (31 Jul 2014)"
#define Module_LibraryVersionInfo "1:25"
#define Module_FullVersion "1.26"
#define Module_HelpVersion "1.26 (09 Aug 2014)"
#define Module_LibraryVersionInfo "1:26"
......@@ -1549,9 +1549,9 @@ static BOOL check_filename (char *name, char *to, int maxlen)
/*Load operations*/
/*Creates the diagram if it is NULL. vuue should also be NULL if so.*/
/*If insert is TRUE, then data loads are allowed only for draw files*/
/*If dataopen is TRUE, then only allow draw files to be loaded*/
static os_error *load_file (diagrec *diag, viewrec *vuue, draw_objcoord *pt,
BOOL insert)
BOOL dataopen)
{ int estsize, filetype = xferrecv_checkimport (&estsize);
......@@ -1560,9 +1560,6 @@ static os_error *load_file (diagrec *diag, viewrec *vuue, draw_objcoord *pt,
switch (filetype)
{ case FileType_DataExchangeFormat:
/*if (!draw_dxf_setOptions ()) break; can't do this yet - breaks the
data transfer protocol*/
/*fall into general case*/
case FileType_Draw:
#if ALLOW_DFILES
case FileType_EarlyDrawingProgram:
......@@ -1592,15 +1589,12 @@ static os_error *load_file (diagrec *diag, viewrec *vuue, draw_objcoord *pt,
case FileType_Text:
case FileType_DataExchangeFormat:
case FileType_JPEG:
if (insert) break;
if (dataopen) break;
/* else fall through */
case FileType_Draw:
if (check_filename (name, filename, FILENAMEMAX))
{ /*if (filetype == FileType_DataExchangeFormat && !draw_dxf_setOptions ())
break; Can't do this yet - breaks the data transfer
protocol.*/
draw_file_loadfile (diag, vuue, filename, 0, 0, via_FILE, pt);
{ draw_file_loadfile (diag, vuue, filename, 0, 0, via_FILE, pt);
ftracef0 ("sending Message_DataSaveAck\n");
xferrecv_insertfileok (); /*Must respond before putting up
......@@ -1610,7 +1604,7 @@ static os_error *load_file (diagrec *diag, viewrec *vuue, draw_objcoord *pt,
default:
#if REJECTUNKNOWNFILETYPES
if (!insert) return makmsg ("DrawCL");
if (!dataopen) return makmsg ("DrawCL");
#endif
break;
}
......@@ -2191,7 +2185,7 @@ static void draw_bkg_events (wimp_eventstr *e, void *handle)
case wimp_MDATASAVE:
case wimp_MDATALOAD:
case wimp_MDATAOPEN:
err = load_file (NULL, NULL, &zero, msg->hdr.action!=wimp_MDATALOAD);
err = load_file (NULL, NULL, &zero, msg->hdr.action==wimp_MDATAOPEN);
break;
case wimp_SAVEDESK:
......
......@@ -1471,41 +1471,16 @@ diagrec *draw_file_loadfile (diagrec *diag, viewrec *vuue, char *name,
ftracef0 ("draw_file_loadfile\n");
/*Create new diagram if diag is NULL*/
if (diag == NULL)
{ if (wimpt_complain (draw_opennewdiag (&diag, FALSE)) != NULL)
return FALSE;
newdiag = TRUE;
}
ftracef2 ("draw_selection->owner 0x%X, "
"draw_selection->owner->paper 0x%X\n",
draw_selection->owner, draw_selection->owner->paper);
ftracef3 ("at start, solidlimit %d, ghoststart %d, ghostlimit %d\n",
diag->misc->solidlimit, diag->misc->ghoststart, diag->misc->ghostlimit);
cleanpaper = diag->misc->solidstart == diag->misc->solidlimit;
ftracef2 ("draw_selection->owner 0x%X, "
"draw_selection->owner->paper 0x%X\n",
draw_selection->owner, draw_selection->owner->paper);
draw_action_abandon (diag);
ftracef2 ("draw_selection->owner 0x%X, "
"draw_selection->owner->paper 0x%X\n",
draw_selection->owner, draw_selection->owner->paper);
if (commandLine) method = via_FILE;
claim_xferrecv (diag, method);
if (method == via_FILE)
{ os_filestr blk;
ftracef2 ("draw_file_loadfile '%s' into diag 0x%.8X\n",
name, (int) diag);
diagrec *rec;
blk.action = 5; /*Read catalogue info*/
blk.name = name; /*for name*/
if (wimpt_complain (os_file (&blk)) != NULL)
return FALSE;
return NULL;
if (blk.action != 1) /*save two messages by using OS_File 19*/
{ blk.loadaddr = blk.action;
......@@ -1515,28 +1490,68 @@ diagrec *draw_file_loadfile (diagrec *diag, viewrec *vuue, char *name,
#else
wimpt_complain (os_file (&blk));
#endif
/*FIX RP-0310 JRC 30 Oct '91 Don't leave the window hanging around*/
if (newdiag) draw_dispose_diag (diag);
return FALSE;
return NULL;
}
ftracef1 ("Found file, size %d bytes\n",blk.start);
ftracef1 ("draw_file_loadfile found file, size %d bytes\n",blk.start);
loadaddr = blk.loadaddr, execaddr = blk.execaddr;
if ((loadaddr & 0xFFF00000) != 0xFFF00000)
{ Error (0, "FileF2");
/*FIX RP-0310 JRC 30 Oct '91 Don't leave the window hanging around*/
if (newdiag) draw_dispose_diag (diag);
return FALSE;
return NULL;
}
filetype = (loadaddr & 0x000FFF00) >> 8;
filesize = blk.start;
/*See if this is an attempt to load a new file that's already open,
with the same date stamp, that's not modified, called the
same thing*/
for (rec = draw_startdiagchain; rec != NULL; rec = rec->nextdiag)
{ if ((diag == NULL) &&
(rec->misc->options.datestamped && (rec->misc->address.load == loadaddr) &&
(rec->misc->address.exec == execaddr)) &&
!rec->misc->options.modified &&
(strcmp (rec->misc->filename, name) == 0))
{ wimp_wstate state;
/*Pop to top and gain the caret*/
wimp_get_wind_state (rec->view->w, &state);
state.o.behind = -1;
draw_open_wind (&state.o, rec->view);
draw_enter_claim_focus (rec, rec->view);
return rec;
}
}
}
else
/*Filesize is a guess, but we can't allow transfer of zero bytes
{ /*Filesize is a guess, but we can't allow transfer of zero bytes
into zero-sized buffer. 6 Aug 1991*/
if (filesize <= 0) filesize = 1024;
}
/*Create new diagram if diag is NULL*/
if (diag == NULL)
{ if (wimpt_complain (draw_opennewdiag (&diag, FALSE)) != NULL)
return NULL;
newdiag = TRUE;
}
ftracef2 ("draw_selection->owner 0x%X, "
"draw_selection->owner->paper 0x%X\n",
draw_selection->owner, draw_selection->owner->paper);
ftracef3 ("at start, solidlimit %d, ghoststart %d, ghostlimit %d\n",
diag->misc->solidlimit, diag->misc->ghoststart, diag->misc->ghostlimit);
cleanpaper = diag->misc->solidstart == diag->misc->solidlimit;
ftracef2 ("draw_selection->owner 0x%X, "
"draw_selection->owner->paper 0x%X\n",
draw_selection->owner, draw_selection->owner->paper);
draw_action_abandon (diag);
ftracef2 ("draw_selection->owner 0x%X, "
"draw_selection->owner->paper 0x%X\n",
draw_selection->owner, draw_selection->owner->paper);
claim_xferrecv (diag, method);
/*Once the file is loaded, use load_error to dispose of any partially
loaded/processed file*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment