UPD: Make each FileView update tab caption by itself. Make the Rename Tab function actually remember the title.

This commit is contained in:
cobines 2012-04-22 07:45:06 +00:00
commit a3381d91d0
5 changed files with 163 additions and 130 deletions

View file

@ -893,15 +893,12 @@ begin
// Add new tab for search results.
Notebook := frmMain.ActiveNotebook;
if tb_open_new_near_current in gDirTabOptions then
NewPage := Notebook.InsertPage(Notebook.PageIndex + 1)
else
NewPage := Notebook.AddPage;
NewPage := Notebook.NewEmptyPage;
NewPage.PermanentTitle := rsSearchResult;
// Hard-coded Columns file view for now (later user will be able to change default view).
FileView := TColumnsFileView.Create(NewPage, SearchResultFS, SearchResultFS.GetRootDir);
frmMain.AssignEvents(FileView);
NewPage.UpdateCaption(rsSearchResult);
NewPage.MakeActive;
Close;

View file

@ -3208,9 +3208,8 @@ begin
begin
ANoteBook := Page.Notebook;
// Create same type
NewPage := ANoteBook.AddPage;
Page.FileView.Clone(NewPage);
// Open in a new page, cloned view.
NewPage := ANotebook.NewPage(Page.FileView);
NewPage.FileView.AddFileSource(NewFileSource, NewPath);
NewPage.MakeActive;
end;
@ -3229,9 +3228,6 @@ begin
Page := FileView.NotebookPage as TFileViewPage;
ANoteBook := Page.Notebook;
if Page.LockState = tlsNormal then // if not locked tab
Page.UpdateCaption(GetLastDir(FileView.CurrentPath));
if Page.IsActive then
begin
if Assigned(FileView.FileSource) then
@ -3509,7 +3505,7 @@ var
sIndex,
TabsSection: String;
sCurrentDir,
sPath, sCaption: String;
sPath: String;
iActiveTab: Integer;
Page: TFileViewPage;
AFileView: TFileView;
@ -3531,27 +3527,11 @@ begin
sPath:= gIni.ReadString(TabsSection, sIndex + '_path', sCurrentDir);
while True do
begin
if mbDirectoryExists(sPath) then
begin
sCaption:= gIni.ReadString(TabsSection, sIndex + '_caption', EmptyStr);
if sCaption = EmptyStr then
sCaption:= GetLastDir(sPath);
end
else
begin // find exists directory
repeat
sPath:= GetParentDir(sPath);
if sPath = EmptyStr then
sPath:= sCurrentDir;
until mbDirectoryExists(sPath);
sCaption:= GetLastDir(sPath);
end;
sPath := GetDeepestExistingPath(sPath);
if sPath = EmptyStr then
sPath := sCurrentDir;
if sCaption <> '' then
if (tb_text_length_limit in gDirTabOptions) and (Length(sCaption) > gDirTabLimit) then
sCaption := Copy(sCaption, 1, gDirTabLimit) + '...';
Page := ANoteBook.AddPage(sCaption);
Page := ANoteBook.AddPage;
aFileSource := TFileSystemFileSource.GetFileSource;
@ -3563,8 +3543,7 @@ begin
end;
Page.LockState := TTabLockState(gIni.ReadInteger(TabsSection, sIndex + '_options', Integer(tlsNormal)));
if Page.LockState = tlsPathResets then // if locked tab with directory change
Page.LockPath := sPath;
Page.LockPath := sPath;
AFileView.AddFileSource(aFileSource, sPath);
// Assign events after loading file source.
@ -3588,7 +3567,7 @@ end;
procedure TfrmMain.LoadTabsXml(ANoteBook: TFileViewNotebook);
var
sPath, sCaption, sViewType: String;
sPath, sViewType: String;
iActiveTab: Integer;
Page: TFileViewPage;
AFileView: TFileView;
@ -3617,7 +3596,7 @@ begin
// File view has its own configuration.
if gConfig.TryGetAttr(ViewNode, 'Type', sViewType) then
begin
Page := ANoteBook.AddPage(EmptyStr);
Page := ANoteBook.AddPage;
AFileView := CreateFileView(sViewType, Page, gConfig, ViewNode);
end
else
@ -3629,7 +3608,7 @@ begin
sPath := GetDeepestExistingPath(sPath);
if sPath <> EmptyStr then
begin
Page := ANoteBook.AddPage(EmptyStr);
Page := ANoteBook.AddPage;
AFileView := CreateFileView('columns', Page, gConfig, TabNode);
AFileView.AddFileSource(TFileSystemFileSource.GetFileSource, sPath);
end;
@ -3646,13 +3625,8 @@ begin
else
begin
Page.LockState := TTabLockState(gConfig.GetValue(TabNode, 'Options', Integer(tlsNormal)));
if Page.LockState = tlsPathResets then // if locked tab with directory change
Page.LockPath := gConfig.GetValue(TabNode, 'LockPath', AFileView.CurrentPath);
sCaption := gConfig.GetValue(TabNode, 'Caption', EmptyStr);
if sCaption = EmptyStr then
sCaption := GetLastDir(AFileView.CurrentPath);
Page.UpdateCaption(sCaption);
Page.LockPath := gConfig.GetValue(TabNode, 'LockPath', AFileView.CurrentPath);
Page.PermanentTitle := gConfig.GetValue(TabNode, 'Title', EmptyStr);
// Assign events after loading file source.
AssignEvents(AFileView);
@ -3666,15 +3640,13 @@ begin
// Create at least one tab.
if ANoteBook.PageCount = 0 then
begin
sPath := mbGetCurrentDir;
Page := ANoteBook.AddPage(EmptyStr);
Page.UpdateCaption(GetLastDir(sPath));
Page := ANoteBook.AddPage;
aFileSource := TFileSystemFileSource.GetFileSource;
if gDelayLoadingTabs then
AFileViewFlags := [fvfDelayLoadingFiles]
else
AFileViewFlags := [];
AFileView := TColumnsFileView.Create(Page, aFileSource, sPath, AFileViewFlags);
AFileView := TColumnsFileView.Create(Page, aFileSource, mbGetCurrentDir, AFileViewFlags);
AssignEvents(AFileView);
end
else if Assigned(RootNode) then
@ -3722,7 +3694,6 @@ begin
sPath := Page.FileView.CurrentPath;
gIni.WriteString(TabsSection, sIndex + '_path', sPath);
gIni.WriteString(TabsSection, sIndex + '_caption', Page.Caption);
gIni.WriteInteger(TabsSection, sIndex + '_options', Integer(Page.LockState));
Page.FileView.SaveConfiguration(TabsSection, I);
@ -3755,10 +3726,10 @@ begin
Page := ANoteBook.Page[I];
gConfig.AddValue(TabNode, 'Caption', Page.Caption);
gConfig.AddValueDef(TabNode, 'Title', Page.PermanentTitle, '');
gConfig.AddValue(TabNode, 'Options', Integer(Page.LockState));
if Page.LockState = tlsPathResets then // if locked tab with directory change
gConfig.AddValue(TabNode, 'LockPath', Page.LockPath);
gConfig.AddValueDef(TabNode, 'LockPath', Page.LockPath, '');
Page.FileView.SaveConfiguration(gConfig, ViewNode);
end;
@ -3883,15 +3854,7 @@ procedure TfrmMain.UpdateWindowView;
end;
for I := 0 to NoteBook.PageCount - 1 do // change on all tabs
begin
if NoteBook.Page[I].LockState = tlsNormal then
NoteBook.Page[I].UpdateCaption(GetLastDir(NoteBook.View[I].CurrentPath));
{
else
NoteBook.Page[I].UpdateCaption(GetLastDir(NoteBook.Page[I].LockPath));
}
NoteBook.View[I].UpdateView;
end;
end;
procedure AnchorHorizontalBetween(AControl, ALeftSibling, ARightSibling: TControl);
@ -4484,8 +4447,7 @@ procedure TfrmMain.LoadTabsCommandLine(Params: TCommandLineParams);
AFileViewFlags: TFileViewFlags;
aFileSource: IFileSource;
begin
Page := ANoteBook.AddPage(EmptyStr);
Page.UpdateCaption(GetLastDir(aPath));
Page := ANoteBook.AddPage;
aFileSource := TFileSystemFileSource.GetFileSource;
if gDelayLoadingTabs then
AFileViewFlags := [fvfDelayLoadingFiles]

View file

@ -152,6 +152,7 @@ type
procedure UpdateFile(const FileName, APath: String; NewFilesPosition: TNewFilesPosition; UpdatedFilesPosition: TUpdatedFilesPosition);
procedure UpdatedFilesTimerEvent(Sender: TObject);
procedure UpdatePath(UpdateAddressToo: Boolean);
procedure UpdateTitle;
procedure VisualizeFileUpdate(AFile: TDisplayFile);
{en
Assigns the built lists to the file view and displays new the file list.
@ -275,6 +276,7 @@ type
AFileSource: IFileSource;
APath: String;
AFlags: TFileViewFlags = []); virtual reintroduce;
// Constructor for cloning.
constructor Create(AOwner: TWinControl;
AFileView: TFileView;
AFlags: TFileViewFlags = []); virtual reintroduce;
@ -510,6 +512,15 @@ begin
FFlags := AFlags;
CreateDefault(AOwner);
LoadConfiguration(ASectionName, ATabIndex);
// Update view before making file source file list,
// so that file list isn't unnecessarily displayed twice.
UpdateView;
if FileSourcesCount > 0 then
begin
MakeFileSourceFileList;
end;
end;
constructor TFileView.Create(AOwner: TWinControl; AConfig: TXmlConfig; ANode: TXmlNode; AFlags: TFileViewFlags = []);
@ -546,8 +557,8 @@ begin
inherited Create(AOwner);
Parent := AOwner;
if AOwner is TFileViewPage then
(AOwner as TFileViewPage).OnActivate := @ActivateEvent;
if Parent is TFileViewPage then
(Parent as TFileViewPage).OnActivate := @ActivateEvent;
end;
destructor TFileView.Destroy;
@ -1020,6 +1031,12 @@ begin
UpdateView;
end;
procedure TFileView.UpdateTitle;
begin
if Parent is TFileViewPage then
TFileViewPage(Parent).UpdateTitle;
end;
procedure TFileView.VisualizeFileUpdate(AFile: TDisplayFile);
begin
if gHighlightUpdatedFiles then
@ -1918,6 +1935,7 @@ begin
end;
EnableWatcher(IsFileSystemWatcher);
UpdateTitle;
end;
function TFileView.BeforeChangePath(NewFileSource: IFileSource; NewPath: String): Boolean;
@ -1954,6 +1972,8 @@ begin
if Assigned(OnAfterChangePath) then
OnAfterChangePath(Self);
UpdateTitle;
MakeFileSourceFileList;
end;

View file

@ -32,30 +32,31 @@ type
FSettingCaption: Boolean;
{$ENDIF}
FOnActivate: TNotifyEvent;
FCurrentTitle: String;
FPermanentTitle: String;
{en
Shows or removes the '*' indicator of a locked tab.
}
procedure UpdateTabLockState;
procedure AssignPage(OtherPage: TFileViewPage);
procedure AssignProperties(OtherPage: TFileViewPage);
{en
Retrieves the file view on this page.
}
function GetFileView: TFileView;
{en
Frees current file view and assigns a new one.
}
procedure SetFileView(aFileView: TFileView);
{en
Retrieves notebook on which this page is.
}
function GetNotebook: TFileViewNotebook;
{en
Frees current file view and assigns a new one.
}
procedure SetFileView(aFileView: TFileView);
procedure SetLockState(NewLockState: TTabLockState);
procedure SetPermanentTitle(AValue: String);
procedure DoActivate;
{$IF (DEFINED(LCLQT) and (LCL_FULLVERSION < 093100)) or DEFINED(MSWINDOWS)}
protected
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
{$IF (DEFINED(LCLQT) and (LCL_FULLVERSION < 093100)) or DEFINED(MSWINDOWS)}
procedure RealSetText(const AValue: TCaption); override;
{$ENDIF}
@ -67,12 +68,14 @@ type
{$ENDIF}
function IsActive: Boolean;
procedure MakeActive;
procedure UpdateCaption(NewCaption: String);
procedure UpdateTitle;
property LockState: TTabLockState read FLockState write SetLockState;
property LockPath: String read FLockPath write FLockPath;
property FileView: TFileView read GetFileView write SetFileView;
property Notebook: TFileViewNotebook read GetNotebook;
property PermanentTitle: String read FPermanentTitle write SetPermanentTitle;
property CurrentTitle: String read FCurrentTitle;
property OnActivate: TNotifyEvent read FOnActivate write FOnActivate;
end;
@ -110,8 +113,11 @@ type
constructor Create(ParentControl: TWinControl;
NotebookSide: TFilePanelSelect); reintroduce;
function AddPage(aCaption: String = ''): TFileViewPage;
function InsertPage(Index: Integer; aCaption: String = ''): TFileViewPage; reintroduce;
function AddPage: TFileViewPage;
function InsertPage(Index: Integer): TFileViewPage; reintroduce;
function NewEmptyPage: TFileViewPage;
function NewPage(CloneFromPage: TFileViewPage): TFileViewPage;
function NewPage(CloneFromView: TFileView): TFileViewPage;
procedure RemovePage(Index: Integer); reintroduce;
procedure RemovePage(var aPage: TFileViewPage);
procedure DestroyAllPages;
@ -137,6 +143,7 @@ implementation
uses
LCLProc,
DCStrUtils,
uGlobs
{$IF DEFINED(LCLGTK2)}
, GTK2Globals // for DblClickTime
@ -151,6 +158,21 @@ uses
// -- TFileViewPage -----------------------------------------------------------
procedure TFileViewPage.AssignPage(OtherPage: TFileViewPage);
begin
AssignProperties(OtherPage);
SetFileView(nil); // Remove previous view.
OtherPage.FileView.Clone(Self);
end;
procedure TFileViewPage.AssignProperties(OtherPage: TFileViewPage);
begin
FLockState := OtherPage.FLockState;
FLockPath := OtherPage.FLockPath;
FCurrentTitle := OtherPage.FCurrentTitle;
FPermanentTitle := OtherPage.FPermanentTitle;
end;
constructor TFileViewPage.Create(TheOwner: TComponent);
begin
FLockState := tlsNormal;
@ -218,32 +240,42 @@ begin
end;
end;
procedure TFileViewPage.UpdateCaption(NewCaption: String);
procedure TFileViewPage.Notification(AComponent: TComponent; Operation: TOperation);
begin
if NewCaption <> '' then
begin
if (tb_text_length_limit in gDirTabOptions) and (UTF8Length(NewCaption) > gDirTabLimit) then
Caption := UTF8Copy(NewCaption, 1, gDirTabLimit) + '...'
else
Caption := NewCaption;
UpdateTabLockState;
end;
inherited Notification(AComponent, Operation);
if (Operation = opInsert) and (FileView = AComponent) then
UpdateTitle;
end;
procedure TFileViewPage.UpdateTabLockState;
procedure TFileViewPage.UpdateTitle;
var
NewCaption: String;
begin
if Caption[1] = '*' then
NewCaption := Copy(Caption, 2, Length(Caption) - 1)
else
NewCaption := Caption;
if Assigned(FileView) then
begin
if FPermanentTitle <> '' then
begin
NewCaption := FPermanentTitle;
FCurrentTitle := FPermanentTitle;
end
else
begin
NewCaption := FileView.CurrentPath;
if NewCaption <> '' then
NewCaption := GetLastDir(NewCaption);
FCurrentTitle := NewCaption;
if (FLockState in [tlsPathLocked, tlsPathResets, tlsDirsInNewTab]) and
(tb_show_asterisk_for_locked in gDirTabOptions) then
NewCaption := '*' + NewCaption;
end;
if (tb_text_length_limit in gDirTabOptions) and (UTF8Length(NewCaption) > gDirTabLimit) then
NewCaption := UTF8Copy(NewCaption, 1, gDirTabLimit) + '...';
if (FLockState <> tlsNormal) and (tb_show_asterisk_for_locked in gDirTabOptions) then
Caption := '*' + NewCaption
else
Caption := NewCaption;
end;
end;
function TFileViewPage.GetFileView: TFileView;
@ -279,10 +311,20 @@ end;
procedure TFileViewPage.SetLockState(NewLockState: TTabLockState);
begin
if FLockState = NewLockState then Exit;
FLockState := NewLockState;
if NewLockState = tlsPathResets then
LockPath := FileView.CurrentPath;
UpdateTabLockState;
if NewLockState in [tlsPathLocked, tlsPathResets] then
LockPath := FileView.CurrentPath
else
LockPath := '';
UpdateTitle;
end;
procedure TFileViewPage.SetPermanentTitle(AValue: String);
begin
if FPermanentTitle = AValue then Exit;
FPermanentTitle := AValue;
UpdateTitle;
end;
procedure TFileViewPage.DoActivate;
@ -341,22 +383,48 @@ begin
Result := TFileViewPage(CustomPage(Index));
end;
function TFileViewNotebook.AddPage(aCaption: String): TFileViewPage;
function TFileViewNotebook.AddPage: TFileViewPage;
begin
Result := InsertPage(PageCount, aCaption);
Result := InsertPage(PageCount);
end;
function TFileViewNotebook.InsertPage(Index: Integer; aCaption: String = ''): TFileViewPage;
function TFileViewNotebook.InsertPage(Index: Integer): TFileViewPage;
begin
if aCaption = '' then
aCaption := IntToStr(Index);
Pages.Insert(Index, aCaption);
Pages.Insert(Index, '');
Result := GetPage(Index);
ShowTabs:= ((PageCount > 1) or (tb_always_visible in gDirTabOptions)) and gDirectoryTabs;
end;
function TFileViewNotebook.NewEmptyPage: TFileViewPage;
begin
if tb_open_new_near_current in gDirTabOptions then
Result := InsertPage(PageIndex + 1)
else
Result := InsertPage(PageCount);
end;
function TFileViewNotebook.NewPage(CloneFromPage: TFileViewPage): TFileViewPage;
begin
if Assigned(CloneFromPage) then
begin
Result := NewEmptyPage;
Result.AssignPage(CloneFromPage);
end
else
Result := nil;
end;
function TFileViewNotebook.NewPage(CloneFromView: TFileView): TFileViewPage;
begin
if Assigned(CloneFromView) then
begin
Result := NewEmptyPage;
CloneFromView.Clone(Result);
end
else
Result := nil;
end;
procedure TFileViewNotebook.RemovePage(Index: Integer);
begin
{$IFDEF LCLGTK2}
@ -469,7 +537,7 @@ procedure TFileViewNotebook.DragDropEvent(Sender, Source: TObject; X, Y: Integer
var
SourceNotebook: TFileViewNotebook;
ATabIndex: Integer;
NewPage, DraggedPage: TFileViewPage;
ANewPage, DraggedPage: TFileViewPage;
begin
if (Source is TFileViewNotebook) and (Sender is TFileViewNotebook) then
begin
@ -489,9 +557,9 @@ begin
DraggedPage := SourceNotebook.Page[SourceNotebook.FDraggedPageIndex];
// Create a clone of the page in the panel.
NewPage := InsertPage(ATabIndex, DraggedPage.Caption);
DraggedPage.FileView.Clone(NewPage);
NewPage.MakeActive;
ANewPage := InsertPage(ATabIndex);
ANewPage.AssignPage(DraggedPage);
ANewPage.MakeActive;
if (ssShift in GetKeyShiftState) and (SourceNotebook.PageCount > 1) then
begin

View file

@ -353,13 +353,8 @@ procedure TMainCommands.DoNewTab(Notebook: TFileViewNotebook);
var
NewPage: TFileViewPage;
begin
if tb_open_new_near_current in gDirTabOptions then
NewPage := Notebook.InsertPage(Notebook.PageIndex + 1)
else
NewPage := Notebook.AddPage;
Notebook.ActiveView.Clone(NewPage);
NewPage := Notebook.NewPage(Notebook.ActiveView);
NewPage.MakeActive;
NewPage.UpdateCaption(GetLastDir(ExcludeTrailingPathDelimiter(NewPage.FileView.CurrentPath)));
end;
procedure TMainCommands.DoOpenVirtualFileSystemList(Panel: TFileView);
@ -649,7 +644,6 @@ end;
procedure TMainCommands.cm_OpenDirInNewTab(const Params: array of string);
var
NewPage: TFileViewPage;
NewPath: String;
aFile: TFile;
begin
with FrmMain do
@ -660,10 +654,8 @@ begin
if aFile.IsNameValid and
(aFile.IsDirectory or aFile.IsLinkToDirectory) then
begin
NewPath := ActiveFrame.CurrentPath + aFile.Name;
NewPage := ActiveNotebook.AddPage;
ActiveFrame.Clone(NewPage);
NewPage.FileView.CurrentPath := NewPath;
NewPage := ActiveNotebook.NewPage(ActiveFrame);
NewPage.FileView.CurrentPath := aFile.FullPath;
if tb_open_new_in_foreground in gDirTabOptions then
NewPage.MakeActive;
end;
@ -679,8 +671,6 @@ begin
begin
NotActiveNotebook.ActivePage.FileView := nil;
ActiveFrame.Clone(NotActiveNotebook.ActivePage);
NotActiveNotebook.ActivePage.UpdateCaption(GetLastDir(
ExcludeTrailingPathDelimiter(NotActiveNotebook.ActivePage.FileView.CurrentPath)));
end;
end;
@ -690,7 +680,6 @@ begin
begin
LeftTabs.ActivePage.FileView := nil;
FrameRight.Clone(LeftTabs.ActivePage);
LeftTabs.ActivePage.UpdateCaption(GetLastDir(ExcludeTrailingPathDelimiter(LeftTabs.ActivePage.FileView.CurrentPath)));
// Destroying active view may have caused losing focus. Restore it if needed.
if SelectedPanel = fpLeft then
@ -704,7 +693,6 @@ begin
begin
RightTabs.ActivePage.FileView := nil;
FrameLeft.Clone(RightTabs.ActivePage);
RightTabs.ActivePage.UpdateCaption(GetLastDir(ExcludeTrailingPathDelimiter(RightTabs.ActivePage.FileView.CurrentPath)));
// Destroying active view may have caused losing focus. Restore it if needed.
if SelectedPanel = fpRight then
@ -924,16 +912,14 @@ end;
procedure TMainCommands.cm_RenameTab(const Params: array of string);
var
sCaption: UTF8String;
Page: TFileViewPage;
begin
with frmMain do
begin
sCaption:= ActiveNotebook.Page[ActiveNotebook.PageIndex].Caption;
if (Length(sCaption) > 0) and (sCaption[1] = '*') and
(ActiveNotebook.Page[ActiveNotebook.PageIndex].LockState <> tlsNormal) and
(tb_show_asterisk_for_locked in gDirTabOptions) then
UTF8Delete(sCaption, 1, 1);
Page := ActiveNotebook.ActivePage;
sCaption:= Page.CurrentTitle;
if InputQuery(rsMsgTabRenameCaption, rsMsgTabRenamePrompt, sCaption) then
ActiveNotebook.Page[ActiveNotebook.PageIndex].UpdateCaption(sCaption);
Page.PermanentTitle := sCaption;
end;
end;