CN104199856B - Method for presenting file and file presenting device - Google Patents
Method for presenting file and file presenting device Download PDFInfo
- Publication number
- CN104199856B CN104199856B CN201410398501.XA CN201410398501A CN104199856B CN 104199856 B CN104199856 B CN 104199856B CN 201410398501 A CN201410398501 A CN 201410398501A CN 104199856 B CN104199856 B CN 104199856B
- Authority
- CN
- China
- Prior art keywords
- file
- file block
- block
- area
- presented
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/10—File systems; File servers
- G06F16/16—File or folder operations, e.g. details of user interfaces specifically adapted to file systems
- G06F16/168—Details of user interfaces specifically adapted to file systems, e.g. browsing and visualisation, 2d or 3d GUIs
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Data Mining & Analysis (AREA)
- Databases & Information Systems (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Human Computer Interaction (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The invention discloses a method for presenting files and a file presenting device, comprising the following steps: dividing a file to be presented into a plurality of file blocks, wherein the contents of adjacent file blocks are partially overlapped; loading a first file block into a memory, and presenting the first file block, wherein the first file block is a file block which needs to be presented currently; judging whether the currently presented display area is located in a preset area of the first file block; and if the currently presented display area is located in the preset area of the first file block, moving the first file block out of the memory, and loading the file block adjacent to the first file block into the memory for presentation. Through the mode, the method and the device can effectively reduce the occupation of system memory resources when the large-capacity text file is presented on the premise of not influencing user experience.
Description
Technical Field
The present invention relates to the field of file processing, and in particular, to a method for presenting a file and a file presenting apparatus.
Background
A conventional text editor runs on an operating system, and when editing a text file, the conventional text editor needs to load all contents of the text file into a memory and then edit the text file. When the capacity of the text file is large, loading all the contents of the text file into the memory occupies a large amount of memory resources, thereby affecting the operation of the operating system.
To solve the above problem, as shown in fig. 1, in the prior art, for example, text editing software Gedit provided by the Ubuntu system itself uses: the method loads the content of a part of text files at intervals and immediately presents the content of the text files loaded into the memory to a user in an 'loading and displaying' mode. This approach can reduce the waiting time of the user by breaking up the large text loading time into zero. However, after a period of time has elapsed, the entire contents of the text file are still loaded into the memory, and a large amount of memory resources are still occupied.
Other file presentation systems in the prior art do not perform targeted optimization on the large-capacity text files, or only perform partial optimization on the loading time of the large-capacity text files, and do not fundamentally stop a large amount of memory occupation which may occur when the files are presented.
Nowadays, electronic devices are increasingly developed towards miniaturization and light weight, and the memory capacity equipped by the electronic devices is often limited, so that the occupation amount of memory resources must be controlled within a reasonable range when files are presented, so as to avoid influencing the normal operation of the electronic devices.
Disclosure of Invention
The technical problem to be solved by the invention is to provide a method and a device for presenting files, which can effectively reduce the occupation of system memory resources when presenting large-capacity files on the premise of not influencing user experience.
In order to solve the above technical problem, the present invention provides a method for presenting a file, comprising:
dividing a file to be presented into a plurality of file blocks, wherein the contents of adjacent file blocks are partially overlapped;
loading a first file block into a memory, and presenting the first file block, wherein the first file block is a file block which needs to be presented currently;
judging whether the currently presented display area is located in a preset area of the first file block;
and if the currently presented display area is located in the preset area of the first file block, moving the first file block out of the memory, and loading the file block adjacent to the first file block into the memory for presentation.
The method comprises the following steps of dividing a file to be presented into a plurality of file blocks, wherein the content parts of adjacent file blocks are overlapped:
dividing the file into a plurality of file blocks according to the preset file block size, wherein the file content of the front 1/N area of the next file block is the same as the file content of the rear 1/N area of the previous file block; n is a predetermined constant.
If the currently presented display area is located in the predetermined area of the first file block, the step of moving the first file block out of the memory and loading the file block adjacent to the first file block into the memory for presentation comprises:
if the currently presented display area is located in the front 1/M area of the first file block, the first file block is moved out of the memory, and the front file block is loaded into the memory and presented;
if the currently presented display area is located in the rear 1/L area of the first file block, the first file block is moved out of the memory, and the rear file block is loaded into the memory and presented;
wherein 1/N is greater than or equal to 1/M + 1/L.
Wherein judging whether the currently presented display area is located in a predetermined area of the first file block comprises:
and judging whether the cursor position input by the user is positioned in a preset area of the first file block.
Wherein the file is an editable file;
if the cursor position is located in the predetermined area of the first file block, before moving the first file block out of the memory and loading and presenting the file blocks adjacent to the first file block into the memory, the method further comprises:
judging whether the file content of the first file block is changed or not;
if the file content of the first file block is changed, prompting a user whether to store the changed file content of the first file block;
receiving an instruction which is input by a user and indicates to save or indicates to abandon the saving;
and saving the file content of the first file block changed according to an instruction input by a user and instructing to save, or restoring the original content of the first file block according to an instruction input by the user and instructing to abandon the saving.
The step of saving the file content of the first file block which is changed specifically comprises the following steps:
creating a blank temporary file under the same directory of the file to be presented;
writing first text content which is not loaded into a memory of a file to be presented from the beginning of the file to the initial position of a first file block in the file to be presented into a temporary file;
writing the file content of the first file block changed into a temporary file so as to enable the file content of the first file block changed to be sequentially connected with the first text content in the temporary file;
writing a second text content of the file to be presented, which is not loaded into the memory, from the end position of the first file block in the file to be presented to the tail of the file into the temporary file, so that the second text content is sequentially connected with the file content of the first file block, which is changed, in the temporary file;
deleting the file to be presented after recording the file name of the file to be presented;
and naming the temporary file by the file name of the file to be presented.
In order to solve the above technical problem, the present invention further provides a file presenting apparatus, including:
the device comprises a dividing module, a display module and a display module, wherein the dividing module is used for dividing a file to be presented into a plurality of file blocks, and the content parts of adjacent file blocks are overlapped;
the presentation module is used for loading the first file block into the memory and presenting the first file block, wherein the first file block is a file block which needs to be presented currently;
the first judging module is used for judging whether the currently presented display area is positioned in a preset area of the first file block;
and the switching module is used for moving the first file block out of the memory and loading and presenting the file block adjacent to the first file block into the memory if the currently presented display area is located in the preset area of the first file block.
The dividing module is used for dividing the file into a plurality of file blocks according to the preset file block size, wherein the file content of the front 1/N area of the next file block is the same as the file content of the rear 1/N area of the previous file block; n is a predetermined constant.
Wherein the switching module is configured to:
if the currently presented display area is located in the front 1/M area of the first file block, the first file block is moved out of the memory, and the front file block is loaded into the memory and presented;
if the currently presented display area is located in the rear 1/L area of the first file block, the first file block is moved out of the memory, and the rear file block is loaded into the memory and presented;
wherein 1/N is greater than or equal to 1/M + 1/L.
The first judging module is used for judging whether the cursor position input by the user is located in the preset area of the first file block.
Wherein the file is an editable file; the file presentation apparatus further includes:
the second judgment module is used for judging whether the file content of the first file block changes or not before the first file block is moved out of the memory and the file blocks adjacent to the first file block are loaded into the memory and displayed if the cursor position is located in the preset area of the first file block;
a saving module for changing the file content of the first file block
Prompting a user whether to save the file content of the first file block changed;
receiving an instruction which is input by a user and indicates to save or indicates to abandon the saving;
and saving the file content of the first file block changed according to an instruction input by a user and instructing to save, or restoring the original content of the first file block according to an instruction input by the user and instructing to abandon the saving.
Wherein, the save module is used for:
creating a blank temporary file under the same directory of the file to be presented;
writing first text content which is not loaded into a memory of a file to be presented from the beginning of the file to the initial position of a first file block in the file to be presented into a temporary file;
writing the file content of the first file block changed into a temporary file so as to enable the file content of the first file block changed to be sequentially connected with the first text content in the temporary file;
writing a second text content of the file to be presented, which is not loaded into the memory, from the end position of the first file block in the file to be presented to the tail of the file into the temporary file, so that the second text content is sequentially connected with the file content of the first file block, which is changed, in the temporary file;
deleting the file to be presented after recording the file name of the file to be presented;
the temporary file is named with the file name of the file to be presented.
Through the scheme, the invention has the beneficial effects that: the file to be presented is divided into a plurality of file blocks, and only one of the file blocks is loaded and presented, so that the occupation of system memory resources when a large-capacity file is presented can be effectively reduced, and smooth switching of adjacent file blocks can be realized due to partial overlapping of the adjacent file blocks, and the user experience is improved.
Drawings
FIG. 1 is a schematic diagram of a prior art method of rendering a file;
FIG. 2 is a flowchart illustrating a method for presenting files according to a first embodiment of the present invention;
FIG. 3 is a schematic diagram of file division in a first embodiment of the present invention;
FIG. 4 is a diagram illustrating loading of file blocks into a memory according to a first embodiment of the present invention;
FIG. 5 is a diagram illustrating file block switching in the first embodiment of the present invention;
FIG. 6 is a flowchart of file saving according to the first embodiment of the present invention;
fig. 7 is a schematic structural diagram of a file presentation apparatus according to a first embodiment of the present invention.
Detailed Description
Please refer to fig. 2, which is a flowchart illustrating a method for presenting a file according to a first embodiment of the present invention. As shown in fig. 2, the method of presenting a file of the first embodiment includes:
s10: a file to be rendered is divided into a plurality of file blocks, wherein the content of adjacent file blocks partially overlap.
In S10, the file to be presented may be divided into a plurality of file blocks with the same size, or may be file blocks with different sizes, where the same size means that the file areas occupied by the divided file blocks are the same size, that is, the file is divided into a plurality of file blocks with the same area size according to the same size.
S11: and loading the first file block into the memory, and presenting the first file block, wherein the first file block is a file block which needs to be presented currently.
In this embodiment, only one file block may be loaded into the memory at a time and presented to the user. Before loading a file block into the memory, the file block that has been loaded into the memory and is being presented to the user needs to be removed from the memory.
S12: and judging whether the currently presented display area is positioned in a preset area of the first file block.
The first file block may have a plurality of predetermined areas, and different operations are performed when the currently presented display area is located in different predetermined areas.
S13: and if the currently presented display area is located in the preset area of the first file block, moving the first file block out of the memory, and loading the file block adjacent to the first file block into the memory for presentation.
In S13, according to different predetermined areas, the file blocks adjacent to the first file block and located before the first file may be loaded into the memory and presented, or the file blocks adjacent to the first file block and located before the first file may be loaded into the memory and presented. Therefore, when the capacity of the file to be presented is too large, the occupation of system memory resources when presenting a large-capacity file can be effectively reduced on the premise of not influencing user experience.
In a more specific embodiment, in S10, the file may be divided into a plurality of file blocks according to a predetermined file block size, wherein the file content of the first 1/N area of the subsequent file block is the same as the file content of the second 1/N area of the previous file block; n is a predetermined constant. The size of the content overlapping part of the adjacent file blocks can be adjusted according to the needs, but is not too large, that is, the predetermined constant N is not too small, so as to avoid the inefficiency of dividing the file to be presented into a plurality of text blocks. For example, the file content of the front 2/3 area of the next file block is the same as the file content of the rear 2/3 area of the previous file block to ensure a smooth transition when switching between file blocks. Specifically, when a new file block is divided, the file area of the new file block can be obtained by translating 1/3 the area backwards only by keeping the area size of the previous file block unchanged. As shown in fig. 3, the file block n +1 is obtained by shifting 1/3 the area backwards on the basis of the file block n in the direction of the bold arrow in the figure while keeping the size of the file area unchanged. The file block n and the file block n +1 overlap by 2/3 areas, specifically, the rear 2/3 area of the file block n is the same as the front 2/3 area of the file block n + 1. Therefore, due to the fact that the adjacent file blocks are partially overlapped, smooth switching of the adjacent file blocks can be achieved, and user experience is improved.
In S11, only one file block is loaded into memory at a time and presented to the user. Before loading a file block into the memory, the file block that has been loaded into the memory and is being presented to the user needs to be removed from the memory. As shown in fig. 4, a file to be presented is divided into n file blocks with the same area size, where n is a positive integer. To load file block 2 into memory and present it to the user, file block 1, which was originally loaded into memory, needs to be moved out of memory.
If the file is an editable file, the currently presented display area may be a cursor position input by the user. That is, in S12, it is determined whether the cursor position input by the user is located in a predetermined area of the first file block. The cursor position input by the user indicates a position where the user performs a touch screen or a key operation, and the key operation may include related keys for performing file editing, such as pressing up, down, left, and right direction keys, pressing pageup or pagedown keys, and the like. When a user performs key operation or touch screen operation on a file block loaded into a memory, the current position of a cursor is detected while key values of keys of the keys are received.
Each file block is divided into different area ranges in advance, and the preset area of the file block to be presented refers to a certain area range which is relatively close to an adjacent file block in the different area ranges divided aiming at the file block loaded into the memory. In this embodiment, if the currently presented display area is located in the first 1/M area of the first file block, the first file block is removed from the memory, and the previous file block is loaded into the memory and presented; and if the currently presented display area is located in the rear 1/L area of the first file block, moving the first file block out of the memory, and loading the rear file block into the memory for presentation. The first 1/M area of the first file block and the last 1/L area of the first file block are both predetermined areas of the first file block, wherein 1/N is greater than or equal to 1/M + 1/L. Specifically, if the area a is defined as a predetermined area for switching a file block to be presented to a previous file block, the area B is defined as a predetermined area for switching a file block to be presented to a subsequent file block, the area C is an overlapping area of adjacent file blocks, and the area S is a maximum range in which a cursor is caused to move once. The area A and the area B are both larger than or equal to the area S, so that the problem of inaccurate positioning of a file cursor after the file blocks are switched due to the fact that the moving range of the cursor exceeds the accommodating range of the current file block is solved; however, the ranges of the areas a and B should not be too large, so as to avoid the dilemma of frequent switching of file blocks due to too small area that does not trigger switching of file blocks. The area C needs to be larger than or equal to the area A + the area B, so that the situation that the cursor is positioned in the area A or the area B of the new file block after the new file block is switched is avoided; however, the area C should not be too large, otherwise the file block division efficiency is too low. Specifically, for example, if the entire area of the file block to be presented is set to 1, the areas a and B may take the following values: 1/10, 1/8, 1/6, 1/4, 1/3 and the like, the corresponding region C is 1/5, 1/4, 1/3, 1/2, 2/3 and the like, and it is only necessary that both the region a and the region B are greater than or equal to the region S, and the region C is greater than or equal to the region a + the region B. It can be seen that in the present embodiment, the predetermined area is associated with the maximum range of the cursor movable due to single-time pressing, and the maximum range of the cursor movable due to single-time pressing differs according to the types of the keys. Generally, because the moving range of the PageUp and PageDown keys is large, for example, the PageUp and PageDown keys can move more than ten rows at a time, the size of the maximum range in which the cursor can move due to a single key press is often determined by the range of the cursor which can be moved by the PageUp and PageDown keys at a time. For example, in the case of displaying a scroll bar, 15 lines of codes may be displayed per page, and since the cursor is moved by a single time by the PageUp and PageDown keys, S may be defined as an area of approximately 15 lines of codes.
For example, in the embodiment of the present invention, preferably, one file block may be divided into three parts: a front 1/3 area, a middle 1/3 area, and a rear 1/3 area, the predetermined area refers to a front 1/3 area or a rear 1/3 area of a file chunk to be presented (i.e., when M ═ L ═ 3). If the cursor is positioned in the front 1/3 area of the file block to be presented, moving the file block to be presented out of the memory, loading the previous file block into the memory and presenting the previous file block to the user; if the cursor is located in the rear 1/3 area of the file block to be edited, the file block to be presented is moved out of the memory and the next file block is loaded into the memory and presented to the user. If the file is an editable file, as shown in fig. 5, X represents a cursor, and the current file block is the file block to be presented that has been loaded into the memory. The user performs key operation, namely when editing the current file block, if the cursor X is positioned in the front 1/3 area of the current file block, the current file block is moved out of the memory, and the previous file block is loaded into the memory and presented to the user; if the cursor X is located in the rear 1/3 area of the current file block, the current file block is moved out of the memory and the next file block is loaded into the memory and presented to the user. Before switching file blocks, recording the current position of a cursor X and the offset of the cursor X caused by switching the file blocks; after the file block switching is completed, the position of the cursor X in the file is restored according to the position of the cursor X recorded before and the offset of the cursor X, so that the position of the cursor in the whole file before and after the switching is kept unchanged. Therefore, the user does not see that the cursor position before and after the file block is switched is changed, so that the user can obtain the user experience which is completely the same as the scheme of loading the full file into the memory at one time when the user switches from the current file block to the previous file block or the next file block.
In S12, if the cursor position is located in the predetermined area of the first file block, before the first file block is moved out of the memory and the file blocks adjacent to the first file block are loaded into the memory and presented, it is determined whether the file content of the first file block is changed. And if the file content of the first file block is changed, prompting a user whether to save the changed file content of the first file block. Receiving an instruction which is input by a user and indicates to save or indicates to abandon the saving; and saving the file content of the first file block changed according to an instruction input by a user and instructing to save, or restoring the original content of the first file block according to an instruction input by the user and instructing to abandon the saving.
In the embodiment of the invention, all modifications of the current file by the user are carried out aiming at the file blocks to be presented, which are loaded into the memory currently, so that the full file can be saved only by covering the file content of the corresponding area of the original file with the file content of the file blocks to be presented, which is loaded into the memory currently. This requires that it must be ensured that the file blocks to be presented that have been loaded into the memory after being modified and the file portions that have not been loaded into the memory cannot be misaligned when being spliced, which would otherwise result in the loss of file information. Therefore, it is necessary to accurately locate the boundary of the corresponding area of the file block currently loaded into the memory in the original file when the file is saved.
When a file block to be presented is loaded into the memory, the Start Position (Start Position) and the end Position (Stop Position) of the file block to be presented are recorded. As shown in fig. 5, the current file block is the file block to be presented that has been loaded into the memory. The starting position is the position of the starting point of the current file block in the full file text, namely the offset generated by moving the file pointer from the beginning of the file to the starting point of the current file block. The ending position is the position of the ending point of the current file block in the full file, namely the offset generated when the file pointer moves from the beginning of the file to the ending point of the current file block. When the file is saved, the boundary of the corresponding area of the current file block in the original file is accurately positioned by calling the starting position and the ending position recorded before, and the file content of the corresponding area in the original file is covered by the file content of the current file block, so that the large-capacity file can be saved.
In this embodiment of the present invention, as shown in fig. 6, saving the file content of which the first file block is changed includes:
s140: a blank temporary file is created under the same directory as the file to be rendered.
S141: and writing the first text content of the file to be presented, which is not loaded into the memory, from the beginning of the file to the initial position of the first file block in the file to be presented into the temporary file.
S142: and writing the file content of the first file block changed into the temporary file so as to ensure that the file content of the first file block changed and the first text content are sequentially connected in the temporary file.
S143: and writing second text contents, which are not loaded into the memory, of the file to be presented from the end position of the first file block in the file to be presented to the tail of the file into the temporary file, so that the second text contents and the text contents changed by the first file block are sequentially connected in the temporary file.
For example, if all the file contents of the first file block that have been changed are deleted, the saving process means that the text contents of the first file block that have been changed are empty, the first text contents of the file that are not loaded into the memory from the beginning to the beginning of the file are directly linked with the second text contents of the file that are not loaded into the memory from the end to the end of the file, and the beginning and end positions coincide with each other to form a point after the saving process is completed.
S144: and deleting the file to be presented after recording the file name of the file to be presented.
S145: and naming the temporary file by the file name of the file to be presented.
At this point, the operation of saving the large-capacity file is completed. Therefore, the modified file blocks to be presented, which are loaded into the memory, are spliced with the file parts which are not loaded into the memory without any dislocation, and the text information is not lost.
In the embodiment of the invention, the file to be presented is divided into a plurality of file blocks, wherein the contents of adjacent file blocks are partially overlapped; loading a first file block into a memory, and presenting the first file block, wherein the first file block is a file block which needs to be presented currently; judging whether the currently presented display area is located in a preset area of the first file block; if the currently presented display area is located in the preset area of the first file block, the first file block is moved out of the memory, and the file blocks adjacent to the first file block are loaded into the memory and presented, so that the occupation of system memory resources when large-capacity text files are presented can be effectively reduced on the premise of not influencing user experience.
Referring to fig. 7, fig. 7 is a schematic structural diagram of a file presenting device according to a first embodiment of the present invention. As shown in fig. 7, the document presenting apparatus 10 includes a dividing module 11, a presenting module 12, a first judging module 13, a switching module 14, a second judging module 15, and a saving module 16.
In the embodiment of the present invention, the dividing module 11 is configured to divide the file to be presented into a plurality of file blocks, where contents of adjacent file blocks partially overlap. The presentation module 12 is connected to the dividing module 11, and is configured to load the first file block into the memory and present the first file block, where the first file block is a file block that needs to be presented currently. The first judging module 13 is connected to the presenting module 12, and is configured to judge whether the currently presented display area is located in a predetermined area of the first file block. The switching module 14 is connected to the first determining module 13, and configured to, if the currently presented display area is located in the predetermined area of the first file block, remove the first file block from the memory, and load and present a file block adjacent to the first file block into the memory. The second determining module 15 is connected to the switching module 14, and is configured to determine whether the file content of the first file block changes before the first file block is moved out of the memory and the file block adjacent to the first file block is loaded into the memory and presented if the cursor position is located in the predetermined area of the first file block. The saving module 16 is connected to the second determining module 15, and configured to, if the file content of the first file block changes: prompting a user whether to save the file content of the first file block changed; and receiving an instruction which is input by a user and indicates to save or instruct to abandon the saving, and saving the file content of the first file block changed according to the instruction which is input by the user and indicates to save, or restoring the original content of the first file block according to the instruction which is input by the user and indicates to abandon the saving.
For example, in the embodiment of the present invention, the dividing module 11 may divide the file to be presented into a plurality of file blocks with the same capacity, or may divide the file blocks with different capacities. The same capacity means that the file areas occupied by the divided file blocks have the same size, that is, the file is divided into a plurality of file blocks with the same area size according to the same capacity.
For example, the dividing module 11 also divides the file into a plurality of file blocks according to a predetermined file block size, wherein the file content of the first 1/N area of the next file block is the same as the file content of the second 1/N area of the previous file block; n is a predetermined constant. The dividing module 1 divides the file into a plurality of file blocks, and the size of the content overlapping part of the adjacent file blocks can be adjusted according to the needs, but is not too large so as to avoid the low efficiency of dividing the file into a plurality of file blocks. Preferably, N may be 3/2, and the file content of the front 2/3 area of the next file block is the same as the file content of the rear 2/3 area of the previous file block. Specifically, when a new file block is divided, the file area of the new file block can be obtained by translating 1/3 the area of the text area of the previous file block backwards only by keeping the size of the text area of the previous file block unchanged. Therefore, due to the fact that the adjacent file blocks are partially overlapped, smooth switching of the adjacent file blocks can be achieved, and user experience is improved.
In the embodiment of the present invention, if the file is an editable file, the currently presented display area may be a cursor position input by the user. The first judging module 13 is configured to judge whether a cursor position input by a user is located in a predetermined area of the first file block. The cursor position input by the user indicates a position where the user performs a touch screen or a key operation, and the key operation may include related keys for performing file editing, such as pressing up, down, left, and right direction keys, pressing pageup or pagedown keys, and the like. When a user performs key operation or touch screen operation on a file block loaded into a memory, the current position of a cursor is detected while key values of keys of the keys are received. In this embodiment, if the currently presented display area is located in the first 1/M area of the first file block, the first file block is removed from the memory, and the previous file block is loaded into the memory and presented; and if the currently presented display area is located in the rear 1/L area of the first file block, moving the first file block out of the memory, and loading the rear file block into the memory for presentation. The first 1/M area of the first file block and the last 1/L area of the first file block are both predetermined areas of the first file block, wherein 1/N is greater than or equal to 1/M + 1/L. Specifically, if the area a is defined as a predetermined area for switching a file block to be edited to a previous file block, the area B is defined as a predetermined area for switching a file block to be edited to a subsequent file block, the area C is an overlapping area of adjacent file blocks, and the area S is a maximum range in which a cursor is caused to move once. The area A and the area B are both larger than or equal to the area S, so that the problem of inaccurate positioning of a file cursor after the file blocks are switched due to the fact that the moving range of the cursor exceeds the accommodating range of the current file block is solved; however, the ranges of the areas a and B should not be too large, so as to avoid the dilemma of frequent switching of file blocks due to too small area that does not trigger switching of file blocks. The area C needs to be larger than or equal to the area A + the area B, so that the situation that the cursor is positioned in the area A or the area B of the new file block after the new file block is switched is avoided; however, the area C should not be too large, otherwise the file block division efficiency is too low. Specifically, for example, if the entire area of the file block to be edited is set to 1, the areas a and B may take the following values: 1/10, 1/8, 1/6, 1/4, 1/3 and the like, the corresponding region C is 1/5, 1/4, 1/3, 1/2, 2/3 and the like, and it is only necessary that both the region a and the region B are greater than or equal to the region S, and the region C is greater than or equal to the region a + the region B. It can be seen that in the present embodiment, the predetermined area is associated with the maximum range of the cursor movable due to single-time pressing, and the maximum range of the cursor movable due to single-time pressing differs according to the types of the keys. Generally, because the moving range of the PageUp and PageDown keys is large, for example, the PageUp and PageDown keys can move more than ten rows at a time, the size of the maximum range in which the cursor can move due to a single key press is often determined by the range of the cursor which can be moved by the PageUp and PageDown keys at a time. For example, in the case of displaying a scroll bar, 15 lines of codes may be displayed per page, and since the cursor is moved by a single time by the PageUp and PageDown keys, S may be defined as an area of approximately 15 lines of codes.
For example, in the embodiment of the present invention, preferably, one file block may be divided into three parts: a front 1/3 area, a middle 1/3 area, and a rear 1/3 area, the predetermined area refers to a front 1/3 area or a rear 1/3 area of a file chunk to be presented (when M ═ L ═ 3). If the cursor is positioned in the front 1/3 area of the file block to be presented, moving the file block to be presented out of the memory, loading the previous file block into the memory and presenting the previous file block to the user; if the cursor is located in the rear 1/3 area of the file block to be presented, the file block to be presented is moved out of the memory and the next file block is loaded into the memory and presented to the user.
If the file is an editable file, the second determination module 15 determines whether the file content of the first file block is changed before the first file block is moved out of the memory and the file block adjacent to the first file block is loaded into the memory and presented, if the cursor position is located in the predetermined area of the first file block. If the file content of the first file block changes, the saving module 16 prompts the user whether to save the changed file content of the first file block; receiving an instruction which is input by a user and indicates to save or indicates to abandon the saving; and saving the file content of the first file block changed according to an instruction input by a user and instructing to save, or restoring the original content of the first file block according to an instruction input by the user and instructing to abandon the saving.
In the embodiment of the invention, all modifications of the current file by the user are carried out aiming at the file blocks to be presented, which are loaded into the memory currently, so that the full file can be saved only by covering the file content of the corresponding area of the original file with the file content of the file blocks to be presented, which is loaded into the memory currently. This requires that it must be ensured that the file blocks to be presented that have been loaded into the memory after being modified and the file portions that have not been loaded into the memory cannot be misaligned when being spliced, which would otherwise result in the loss of file information. Therefore, it is necessary to accurately locate the boundary of the corresponding area of the file block currently loaded into the memory in the original file when the file is saved. When the file block to be presented is loaded into the memory, the saving module 16 records a Start Position (Start Position) and an end Position (Stop Position) of the file block to be presented. The starting position is the position of the starting point of the current file block in the full file text, namely the offset generated by moving the file pointer from the beginning of the file to the starting point of the current file block. The ending position is the position of the ending point of the current file block in the full file, namely the offset generated when the file pointer moves from the beginning of the file to the ending point of the current file block. When the file is saved, the boundary of the corresponding area of the current file block in the original file is accurately positioned by calling the starting position and the ending position recorded before, and the file content of the corresponding area in the original file is covered by the file content of the current file block, so that the large-capacity file can be saved. Therefore, the user does not see that the cursor position before and after the file block is switched is changed, so that the user can obtain the user experience which is completely the same as the scheme of loading the full file into the memory at one time when the user switches from the current file block to the previous file block or the next file block.
When the saving module 16 saves the file content of the first file block, a blank temporary file is created under the same directory of the file to be presented; writing first text content which is not loaded into a memory of a file to be presented from the beginning of the file to the initial position of a first file block in the file to be presented into a temporary file; writing the file content of the first file block changed into a temporary file so as to enable the file content of the first file block changed to be sequentially connected with the first text content in the temporary file; writing a second text content of the file to be presented, which is not loaded into the memory, from the end position of the first file block in the file to be presented to the tail of the file into the temporary file, so that the second text content is sequentially connected with the file content of the first file block, which is changed, in the temporary file; deleting the file to be presented after recording the file name of the file to be presented; the temporary file is named with the file name of the file to be presented. At this point, the saving module 16 completes the saving operation of the large-capacity file, so that the modified file block to be presented loaded into the memory is spliced with the file part not loaded into the memory without any dislocation, and the text information is not lost.
After the saving module 16 finishes the operation of saving the file content of the first file block, the presenting module 12 executes the operation of removing the text block to be presented from the memory and loading the text block adjacent to the text block into the memory, so as to perform the subsequent text editing operation.
In summary, by dividing a file to be presented into a plurality of file blocks, contents of adjacent file blocks are partially overlapped; loading a first file block into a memory, and presenting the first file block, wherein the first file block is a file block which needs to be presented currently; judging whether the currently presented display area is located in a preset area of the first file block; if the currently presented display area is located in the preset area of the first file block, the first file block is moved out of the memory, and the file blocks adjacent to the first file block are loaded into the memory and presented, so that the occupation of system memory resources when large-capacity text files are presented can be effectively reduced on the premise of not influencing user experience.
The above description is only an embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes performed by the present specification and drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.
Claims (12)
1. A method of presenting a file, the method comprising:
dividing a file to be presented into a plurality of file blocks along a preset direction, wherein the contents of adjacent file blocks are partially overlapped;
loading a first file block into a memory, and presenting the first file block, wherein the first file block is a file block which needs to be presented currently;
judging whether the currently presented display area is located in a preset area of the first file block;
if the currently presented display area is located in the first 1/M area of the first file block, moving the first file block out of the memory, loading the previous file block into the memory and presenting the previous file block, and taking the previous file block as the first file block;
if the currently presented display area is located in the rear 1/L area of the first file block, moving the first file block out of the memory, and loading and presenting the rear file block into the memory;
the overlapping area of the first file block and the previous file block comprises a front 1/M area of the first file block, the overlapping area of the first file block and the next file block comprises a back 1/L area of the first file block, the 1/M is the proportion of the front part area of the first file block in the first file block, and the 1/L is the proportion of the back part area of the first file block in the first file block.
2. The method according to claim 1, wherein the step of dividing the file to be presented into a plurality of file blocks, wherein the content parts of adjacent file blocks overlap specifically comprises:
dividing the file into a plurality of file blocks according to the size of a preset file block, wherein the file content of the front 1/N area of the next file block is the same as the file content of the rear 1/N area of the previous file block;
wherein, the 1/N is the proportion of the overlapping area of the file block and the adjacent file block in the file block, and the N is a preset constant.
3. The method of claim 2,
wherein 1/N is greater than or equal to 1/M + 1/L.
4. The method according to any one of claims 1-3, wherein the determining whether the currently presented display area is located in a predetermined area of the first file block comprises:
and judging whether the cursor position input by the user is positioned in a preset area of the first file block.
5. The method of claim 4, wherein the file is an editable file;
if the currently presented display area is located in the first 1/M area of the first file block, moving the first file block out of the memory, loading the previous file block into the memory and presenting the previous file block, and taking the previous file block as the first file block; and if the currently presented display area is located in the rear 1/L area of the first file block, before moving the first file block out of the memory and loading the latter file block into the memory and presenting the latter file block, the method further comprises:
judging whether the file content of the first file block is changed or not;
if the file content of the first file block is changed, prompting a user whether to store the changed file content of the first file block;
receiving an instruction which is input by a user and indicates to save or indicates to abandon the saving;
and saving the file content of the first file block changed according to an instruction for indicating saving input by a user, or recovering the original content of the first file block according to an instruction for giving up saving input by the user.
6. The method according to claim 5, wherein the step of saving the file content of the changed first file block specifically comprises:
creating a blank temporary file under the same directory of the file to be presented;
writing first text content, which is not loaded into a memory, of the file to be presented from the beginning of the file to the initial position of the first file block in the file to be presented into the temporary file;
writing the changed file content of the first file block into the temporary file so as to enable the changed file content of the first file block to be sequentially connected with the first text content in the temporary file;
writing second text contents, which are not loaded into a memory, of the file to be presented from the end position of the first file block in the file to be presented to the file tail into the temporary file, so that the second text contents are sequentially connected with the file contents changed by the first file block in the temporary file;
deleting the file to be presented after recording the file name of the file to be presented;
naming the temporary file with the file name of the file to be presented.
7. A file presentation apparatus, characterized in that the file presentation apparatus comprises:
the device comprises a dividing module, a display module and a display module, wherein the dividing module is used for dividing a file to be presented into a plurality of file blocks along a preset direction, and the content parts of adjacent file blocks are overlapped;
the display module is used for loading a first file block into a memory and displaying the first file block, wherein the first file block is a file block which needs to be displayed currently;
the first judging module is used for judging whether the currently presented display area is positioned in a preset area of the first file block;
the switching module is used for moving the first file block out of the memory and loading and presenting the previous file block into the memory if the currently presented display area is located in the front 1/M area of the first file block, and taking the previous file block as the first file block;
if the currently presented display area is located in the rear 1/L area of the first file block, moving the first file block out of the memory, and loading and presenting the rear file block into the memory;
the overlapping area of the first file block and the previous file block comprises a front 1/M area of the first file block, the overlapping area of the first file block and the next file block comprises a back 1/L area of the first file block, the 1/M is the proportion of the front part area of the first file block in the first file block, and the 1/L is the proportion of the back part area of the first file block in the first file block.
8. The apparatus according to claim 7, wherein the dividing module is configured to divide the file into a plurality of file blocks according to a predetermined file block size, wherein the file content of the first 1/N area of the next file block is the same as the file content of the second 1/N area of the previous file block;
wherein, the 1/N is the proportion of the overlapping area of the file block and the adjacent file block in the file block, and the N is a preset constant.
9. The document presentation apparatus according to claim 8,
wherein 1/N is greater than or equal to 1/M + 1/L.
10. The file presentation apparatus according to any one of claims 7 to 9, wherein the first determination module is configured to determine whether a cursor position input by a user is located in a predetermined area of the first file block.
11. The document presentation device according to claim 10, wherein the document is an editable document; the file presentation apparatus further includes:
the second judgment module is used for moving the first file block out of the memory, loading and presenting the previous file block into the memory and taking the previous file block as the first file block if the currently presented display area is positioned in the front 1/M area of the first file block; if the currently presented display area is located in the rear 1/L area of the first file block, moving the first file block out of the memory, loading the latter file block into the memory and judging whether the file content of the first file block is changed or not before presenting;
a saving module, configured to, if the file content of the first file block changes, save the file in the first file block
Prompting a user whether to save the changed file content of the first file block;
receiving an instruction which is input by a user and indicates to save or indicates to abandon the saving;
and saving the file content of the first file block changed according to an instruction for indicating saving input by a user, or recovering the original content of the first file block according to an instruction for giving up saving input by the user.
12. The document rendering apparatus of claim 11, wherein the save module is configured to:
creating a blank temporary file under the same directory of the file to be presented;
writing first text content, which is not loaded into a memory, of the file to be presented from the beginning of the file to the initial position of the first file block in the file to be presented into the temporary file;
writing the changed file content of the first file block into the temporary file so as to enable the changed file content of the first file block to be sequentially connected with the first text content in the temporary file;
writing second text contents, which are not loaded into a memory, of the file to be presented from the end position of the first file block in the file to be presented to the file tail into the temporary file, so that the second text contents are sequentially connected with the file contents changed by the first file block in the temporary file;
deleting the file to be presented after recording the file name of the file to be presented;
naming the temporary file with the file name of the file to be presented.
Priority Applications (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201410398501.XA CN104199856B (en) | 2014-08-13 | 2014-08-13 | Method for presenting file and file presenting device |
PCT/CN2015/086875 WO2016023509A1 (en) | 2014-08-13 | 2015-08-13 | File display method and file display device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201410398501.XA CN104199856B (en) | 2014-08-13 | 2014-08-13 | Method for presenting file and file presenting device |
Publications (2)
Publication Number | Publication Date |
---|---|
CN104199856A CN104199856A (en) | 2014-12-10 |
CN104199856B true CN104199856B (en) | 2021-04-06 |
Family
ID=52085149
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201410398501.XA Active CN104199856B (en) | 2014-08-13 | 2014-08-13 | Method for presenting file and file presenting device |
Country Status (2)
Country | Link |
---|---|
CN (1) | CN104199856B (en) |
WO (1) | WO2016023509A1 (en) |
Families Citing this family (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN104199856B (en) * | 2014-08-13 | 2021-04-06 | 北京配天技术有限公司 | Method for presenting file and file presenting device |
WO2017113317A1 (en) * | 2015-12-31 | 2017-07-06 | 深圳配天智能技术研究院有限公司 | File editing method and file editor |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1928871A (en) * | 2006-09-07 | 2007-03-14 | 北京优纳科技有限公司 | Big capacity image fast browsing system |
CN1953540A (en) * | 2005-10-21 | 2007-04-25 | 深圳Tcl新技术有限公司 | A method to realize quick search via the dynamic user operation interface of TV |
CN101059949A (en) * | 2007-04-03 | 2007-10-24 | 广东威创日新电子有限公司 | Mass image data compression, storage and display method |
CN101127578A (en) * | 2007-09-14 | 2008-02-20 | 广东威创日新电子有限公司 | A method and system for processing a magnitude of data |
CN101763407A (en) * | 2009-11-19 | 2010-06-30 | 青岛海信移动通信技术股份有限公司 | Txt file reading method based on brew platform and reader thereof |
Family Cites Families (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
FR2829845B1 (en) * | 2001-09-17 | 2003-11-28 | Pierre Schweitzer | METHOD FOR VIEWING A DOCUMENT ON A PORTABLE EQUIPMENT |
CN102567285A (en) * | 2010-12-13 | 2012-07-11 | 汉王科技股份有限公司 | Document loading method and device |
CN102768662B (en) * | 2011-05-05 | 2016-02-10 | 阿里巴巴集团控股有限公司 | A kind of method and apparatus Loaded Image |
CN103176952A (en) * | 2011-12-20 | 2013-06-26 | 北大方正集团有限公司 | Document display method and document display device |
CN104199856B (en) * | 2014-08-13 | 2021-04-06 | 北京配天技术有限公司 | Method for presenting file and file presenting device |
-
2014
- 2014-08-13 CN CN201410398501.XA patent/CN104199856B/en active Active
-
2015
- 2015-08-13 WO PCT/CN2015/086875 patent/WO2016023509A1/en active Application Filing
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1953540A (en) * | 2005-10-21 | 2007-04-25 | 深圳Tcl新技术有限公司 | A method to realize quick search via the dynamic user operation interface of TV |
CN1928871A (en) * | 2006-09-07 | 2007-03-14 | 北京优纳科技有限公司 | Big capacity image fast browsing system |
CN101059949A (en) * | 2007-04-03 | 2007-10-24 | 广东威创日新电子有限公司 | Mass image data compression, storage and display method |
CN101127578A (en) * | 2007-09-14 | 2008-02-20 | 广东威创日新电子有限公司 | A method and system for processing a magnitude of data |
CN101763407A (en) * | 2009-11-19 | 2010-06-30 | 青岛海信移动通信技术股份有限公司 | Txt file reading method based on brew platform and reader thereof |
Also Published As
Publication number | Publication date |
---|---|
WO2016023509A1 (en) | 2016-02-18 |
CN104199856A (en) | 2014-12-10 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
KR101556435B1 (en) | Database backing-up and recovering method and device | |
US20150106766A1 (en) | Method for quickly operating file of smart phone and smart phone | |
CN102981765A (en) | Text processing method and terminal | |
EP4171018A1 (en) | Subtitle generation method and apparatus, and device and storage medium | |
CN104407787A (en) | Terminal | |
CN105183184A (en) | Character processing method and terminal | |
CN107665134A (en) | Page component loading method, device, medium and terminal equipment | |
CN104731364A (en) | Input method and input method system | |
US20180150196A1 (en) | Method and apparatus for switching multiple folders, and computer storage medium | |
WO2017113317A1 (en) | File editing method and file editor | |
CN104199856B (en) | Method for presenting file and file presenting device | |
CN106598926B (en) | Operation revocation method and device | |
CN104834749A (en) | File synchronization method and synchronization system for mobile terminal and PC terminal | |
CN104808959A (en) | Information processing method and electronic device | |
CN114942863B (en) | Cascade snapshot processing method, device, equipment and storage medium | |
US20140337595A1 (en) | Information processing apparatus, and information processing method | |
CN105808519A (en) | Document display method and apparatus | |
CN105320395A (en) | Icon arrangement method and device as well as terminal | |
JP2016148887A (en) | Ladder program edition device enabling edition with gesture operation of touch panel | |
CN112052655B (en) | Page processing method and device, computer storage medium and terminal | |
CN106294571A (en) | The merging method and apparatus of desktop folder | |
CN109144977A (en) | A kind of data migration method, device, equipment and storage medium | |
CN108459713B (en) | Page selection method and device, terminal equipment and storage medium | |
JP2000148562A (en) | Data backup method, data backup device utilizing the method and computer readable recording medium recorded with data backup program | |
CN105159804A (en) | Method, device and equipment for processing data block |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |