forked from gphilippot/purebasic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RecentFiles.pb
142 lines (105 loc) · 3.96 KB
/
RecentFiles.pb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
;--------------------------------------------------------------------------------------------
; Copyright (c) Fantaisie Software. All rights reserved.
; Dual licensed under the GPL and Fantaisie Software licenses.
; See LICENSE and LICENSE-FANTAISIE in the project root for license information.
;--------------------------------------------------------------------------------------------
Procedure.s RecentFiles_EntryString(Index)
If Index > #MAX_RecentFiles ; its a project
Name$ = ProjectName(RecentFiles(Index))
If Name$ <> ""
Name$ = " (" + Name$ + ")"
EndIf
ProcedureReturn RSet(Str(Index-#MAX_RecentFiles), Len(Str(FilesHistorySize))) + ") " + GetFilePart(RecentFiles(Index)) + Name$
Else ; its a source file
ProcedureReturn RSet(Str(Index), Len(Str(FilesHistorySize))) + ") " + RecentFiles(Index) ; Display full path here, to avoid issue if some files gets same name (ie: main.pb) https://www.purebasic.fr/english/viewtopic.php?f=3&t=60650
EndIf
EndProcedure
Procedure RecentFiles_AddMenuEntries(IsProject)
If IsProject = #False
Offset = 0
Else
Offset = #MAX_RecentFiles
EndIf
Count = 0
For i = 1 To FilesHistorySize
If RecentFiles(Offset+i)
MenuItem(#MENU_RecentFiles_Start+Offset+i-1, ReplaceString(RecentFiles_EntryString(Offset+i), "&", "&&")) ; escape the "menu char"
Count + 1
EndIf
Next i
If IsProject = #False
DisplayedRecentFiles = Count
Else
DisplayedRecentProjects = Count
EndIf
EndProcedure
Procedure RecentFiles_AddFile(FileName$, IsProject)
CompilerIf #CompileWindows
; Also notify the OS of the file usage
; This is useful for the 'recent file' list in the start menu and Windows7 Taskbar
CompilerIf #PB_Compiler_Unicode
#SHARD_PATH = $00000003
CompilerElse
#SHARD_PATH = $00000002
CompilerEndIf
SHAddToRecentDocs_(#SHARD_PATH, @FileName$)
CompilerEndIf
If IsProject = #False
Offset = 0
OldCount = DisplayedRecentFiles
Else
Offset = #MAX_RecentFiles
OldCount = DisplayedRecentProjects
EndIf
If IsEqualFile(FileName$, RecentFiles(Offset+1))
ProcedureReturn ; the file is already at the top of the list, so there is nothing to do
EndIf
; search for the same filename in the list
;
Found = 0
For index = 1 To FilesHistorySize
If RecentFiles(Offset+index) = "" Or IsEqualFile(FileName$, RecentFiles(Offset+index))
Found = 1
Break
EndIf
Next index
If Found = 0
index = FilesHistorySize
EndIf
; now move all other files one index down..
;
For i = index-1 To 1 Step -1
RecentFiles(Offset+i+1) = RecentFiles(Offset+i)
Next i
RecentFiles(Offset+1) = FileName$
; Count the number of entries we have
Count = 0
For i = 1 To FilesHistorySize
If RecentFiles(Offset+i)
Count + 1
EndIf
Next i
If Count = OldCount And Count = FilesHistorySize
; rename the menu items for Recentfiles (no recreation of the whole menu)
For i = 1 To FilesHistorySize
SetMenuItemText(#MENU, #MENU_RecentFiles_Start+Offset+i-1, ReplaceString(RecentFiles_EntryString(Offset+i), "&", "&&"))
Next i
Else
; the count changed.. we must re-create the menu
StartFlickerFix(#WINDOW_Main)
CreateIDEMenu() ; update the menu
StopFlickerFix(#WINDOW_Main, 1)
EndIf
EndProcedure
Procedure RecentFiles_Open(MenuItemID)
If MenuItemID >= #MENU_RecentFiles_Start And MenuItemID <= #MENU_RecentFiles_End
If Trim(RecentFiles(MenuItemID - #MENU_RecentFiles_Start + 1)) <> ""
If MenuItemID < #MENU_RecentFiles_Start+#MAX_RecentFiles ; RecentFiles range
LoadSourceFile(RecentFiles(MenuItemID - #MENU_RecentFiles_Start + 1))
Else ; RecentProjects range
LoadProject(RecentFiles(MenuItemID - #MENU_RecentFiles_Start + 1))
EndIf
; do not add the filename to the beginning of the list, LoadSourceFile()/LoadProject() will do so
EndIf
EndIf
EndProcedure